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.
()
| 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. |
| 106 | func 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. |
nothing calls this directly
no test coverage detected
searching dependent graphs…