Documentation ¶
Overview ¶
Package diskfs implements methods for creating and manipulating disks and filesystems
methods for creating and manipulating disks and filesystems, whether block devices in /dev or direct disk images. This does **not** mount any disks or filesystems, neither directly locally nor via a VM. Instead, it manipulates the bytes directly.
This is not intended as a replacement for operating system filesystem and disk drivers. Instead, it is intended to make it easy to work with partitions, partition tables and filesystems directly without requiring operating system mounts.
Some examples:
1. Create a disk image of size 10MB with a FAT32 filesystem spanning the entire disk.
import diskfs "github.com/diskfs/go-diskfs" size := 10*1024*1024 // 10 MB diskImg := "/tmp/disk.img" disk := diskfs.Create(diskImg, size, diskfs.Raw) fs, err := disk.CreateFilesystem(0, diskfs.TypeFat32)
Create a disk of size 20MB with an MBR partition table, a single partition beginning at block 2048 (1MB), of size 10MB filled with a FAT32 filesystem.
import diskfs "github.com/diskfs/go-diskfs"
diskSize := 10*1024*1024 // 10 MB
diskImg := "/tmp/disk.img" disk := diskfs.Create(diskImg, size, diskfs.Raw)
table := &mbr.Table{ LogicalSectorSize: 512, PhysicalSectorSize: 512, Partitions: []*mbr.Partition{ { Bootable: false, Type: Linux, Start: 2048, Size: 20480, }, }, }
fs, err := disk.CreateFilesystem(1, diskfs.TypeFat32)
Create a disk of size 20MB with a GPT partition table, a single partition beginning at block 2048 (1MB), of size 10MB, and fill with the contents from the 10MB file "/root/contents.dat"
import diskfs "github.com/diskfs/go-diskfs"
diskSize := 10*1024*1024 // 10 MB
diskImg := "/tmp/disk.img" disk := diskfs.Create(diskImg, size, diskfs.Raw)
table := &gpt.Table{ LogicalSectorSize: 512, PhysicalSectorSize: 512, Partitions: []*gpt.Partition{ { LogicalSectorSize: 512, PhysicalSectorSize: 512, ProtectiveMBR: true, }, }, }
f, err := os.Open("/root/contents.dat") written, err := disk.WritePartitionContents(1, f)
Create a disk of size 20MB with an MBR partition table, a single partition beginning at block 2048 (1MB), of size 10MB filled with a FAT32 filesystem, and create some directories and files in that filesystem.
import diskfs "github.com/diskfs/go-diskfs"
diskSize := 10*1024*1024 // 10 MB
diskImg := "/tmp/disk.img" disk := diskfs.Create(diskImg, size, diskfs.Raw)
table := &mbr.Table{ LogicalSectorSize: 512, PhysicalSectorSize: 512, Partitions: []*mbr.Partition{ { Bootable: false, Type: Linux, Start: 2048, Size: 20480, }, }, }
fs, err := disk.CreateFilesystem(1, diskfs.TypeFat32) err := fs.Mkdir("/FOO/BAR") rw, err := fs.OpenFile("/FOO/BAR/AFILE.EXE", os.O_CREATE|os.O_RDRWR) b := make([]byte, 1024, 1024) rand.Read(b) err := rw.Write(b)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Create ¶
Create a Disk from a path to a device Should pass a path to a block device e.g. /dev/sda or a path to a file /tmp/foo.img The provided device must not exist at the time you call Create()
func Open ¶
Open a Disk from a path to a device in read-write exclusive mode Should pass a path to a block device e.g. /dev/sda or a path to a file /tmp/foo.img The provided device must exist at the time you call Open()
func OpenWithMode ¶
func OpenWithMode(device string, mode OpenModeOption) (*disk.Disk, error)
OpenWithMode open a Disk from a path to a device with a given open mode If the device is open in read-only mode, operations to change disk partitioning will return an error Should pass a path to a block device e.g. /dev/sda or a path to a file /tmp/foo.img The provided device must exist at the time you call OpenWithMode()
Types ¶
type OpenModeOption ¶
type OpenModeOption int
OpenModeOption represents file open modes
const ( // ReadOnly open file in read only mode ReadOnly OpenModeOption = iota // ReadWriteExclusive open file in read-write exclusive mode ReadWriteExclusive )
Directories ¶
Path | Synopsis |
---|---|
Package disk provides utilities for working directly with a disk Most of the provided functions are intelligent wrappers around implementations of github.com/diskfs/go-diskfs/partition and github.com/diskfs/go-diskfs/filesystem
|
Package disk provides utilities for working directly with a disk Most of the provided functions are intelligent wrappers around implementations of github.com/diskfs/go-diskfs/partition and github.com/diskfs/go-diskfs/filesystem |
Package filesystem provides interfaces and constants required for filesystem implementations.
|
Package filesystem provides interfaces and constants required for filesystem implementations. |
fat32
Package fat32 provides utilities to interact with, manipulate and create a FAT32 filesystem on a block device or a disk image.
|
Package fat32 provides utilities to interact with, manipulate and create a FAT32 filesystem on a block device or a disk image. |
iso9660
Package iso9660 provides utilities to interact with, manipulate and create an iso9660 filesystem on a block device or a disk image.
|
Package iso9660 provides utilities to interact with, manipulate and create an iso9660 filesystem on a block device or a disk image. |
Package partition provides ability to work with individual partitions.
|
Package partition provides ability to work with individual partitions. |
gpt
Package gpt provides an interface to GUID Partition Table (GPT) partitioned disks.
|
Package gpt provides an interface to GUID Partition Table (GPT) partitioned disks. |
mbr
Package mbr provides an interface to Master Boot Record (MBR) partitioned disks.
|
Package mbr provides an interface to Master Boot Record (MBR) partitioned disks. |
Package testhelper provides some useful helpers for testing in github.com/diskfs/go-diskfs subpackages
|
Package testhelper provides some useful helpers for testing in github.com/diskfs/go-diskfs subpackages |
Package util common utilities or other elements shared across github.com/diskfs/go-diskfs packages
|
Package util common utilities or other elements shared across github.com/diskfs/go-diskfs packages |