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

Function ExampleCreate_gpt

example_test.go:74–102  ·  view source on GitHub ↗

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"

()

Source from the content-addressed store, hash-verified

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() {
75 var size int64 = 20 * 1024 * 1024 // 20 MB
76
77 diskImg := "/tmp/disk.img"
78 defer os.Remove(diskImg)
79 theDisk, _ := diskfs.Create(diskImg, size, diskfs.SectorSizeDefault)
80
81 table := &gpt.Table{
82 LogicalSectorSize: 512,
83 PhysicalSectorSize: 512,
84 ProtectiveMBR: true,
85 Partitions: []*gpt.Partition{
86 {
87 Start: 1 * 1024 * 1024 / 512,
88 Size: 10 * 1024 * 1024,
89 Type: gpt.MBRPartitionScheme,
90 },
91 },
92 }
93
94 check(theDisk.Partition(table))
95
96 f, err := os.Open("/root/contents.dat")
97 check(err)
98
99 written, err := theDisk.WritePartitionContents(1, f)
100 check(err)
101 unused(written)
102}
103
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.

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…