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

Function ExampleCreate_mbr

example_test.go:43–71  ·  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.

()

Source from the content-addressed store, hash-verified

41// Create a disk of size 20MB with an MBR partition table, a single partition beginning at block 2048 (1MB),
42// of size 10MB filled with a FAT32 filesystem.
43func ExampleCreate_mbr() {
44 var size int64 = 20 * 1024 * 1024 // 20 MB
45
46 diskImg := "/tmp/disk.img"
47 defer os.Remove(diskImg)
48 theDisk, _ := diskfs.Create(diskImg, size, diskfs.SectorSizeDefault)
49
50 table := &mbr.Table{
51 LogicalSectorSize: 512,
52 PhysicalSectorSize: 512,
53 Partitions: []*mbr.Partition{
54 {
55 Bootable: false,
56 Type: mbr.Linux,
57 Start: 2048,
58 Size: 20480,
59 },
60 },
61 }
62
63 check(theDisk.Partition(table))
64
65 fs, err := theDisk.CreateFilesystem(disk.FilesystemSpec{
66 Partition: 1,
67 FSType: filesystem.TypeFat32,
68 })
69 check(err)
70 unused(fs)
71}
72
73// 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"
74func ExampleCreate_gpt() {

Callers

nothing calls this directly

Calls 5

PartitionMethod · 0.80
CreateFilesystemMethod · 0.80
checkFunction · 0.70
unusedFunction · 0.70
RemoveMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…