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"
()
| 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" |
| 74 | func 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. |