MCPcopy Create free account
hub / github.com/diskfs/go-diskfs / ExampleCreate_fat32WithDirsAndFiles

Function ExampleCreate_fat32WithDirsAndFiles

example_test.go:106–147  ·  view source on GitHub ↗

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.

()

Source from the content-addressed store, hash-verified

104// Create a disk of size 20MB with an MBR partition table, a single partition beginning at block 2048 (1MB),
105// of size 10MB filled with a FAT32 filesystem, and create some directories and files in that filesystem.
106func ExampleCreate_fat32WithDirsAndFiles() {
107 var size int64 = 20 * 1024 * 1024 // 20 MB
108
109 diskImg := "/tmp/disk.img"
110 defer os.Remove(diskImg)
111 theDisk, _ := diskfs.Create(diskImg, size, diskfs.SectorSizeDefault)
112
113 table := &mbr.Table{
114 LogicalSectorSize: 512,
115 PhysicalSectorSize: 512,
116 Partitions: []*mbr.Partition{
117 {
118 Bootable: false,
119 Type: mbr.Linux,
120 Start: 2048,
121 Size: 20480,
122 },
123 },
124 }
125
126 check(theDisk.Partition(table))
127
128 fs, err := theDisk.CreateFilesystem(disk.FilesystemSpec{
129 Partition: 1,
130 FSType: filesystem.TypeFat32,
131 })
132 check(err)
133
134 err = fs.Mkdir("/FOO/BAR")
135 check(err)
136
137 rw, err := fs.OpenFile("/FOO/BAR/AFILE.EXE", os.O_CREATE|os.O_RDWR)
138 check(err)
139 b := make([]byte, 1024)
140
141 _, err = rand.Read(b)
142 check(err)
143
144 written, err := rw.Write(b)
145 check(err)
146 unused(written)
147}
148
149// Create a disk of size 20MB at provided pathname using backend abstraction.
150// This is a proposed way of usage after factoring out underlying file operations to the backend.

Callers

nothing calls this directly

Calls 9

PartitionMethod · 0.80
CreateFilesystemMethod · 0.80
checkFunction · 0.70
unusedFunction · 0.70
RemoveMethod · 0.65
MkdirMethod · 0.65
OpenFileMethod · 0.65
WriteMethod · 0.65
ReadMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…