Last active
November 13, 2019 14:23
-
-
Save kstieger/3fa5b945a9008de91c974ddd611ab325 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
"os" | |
diskfs "github.com/diskfs/go-diskfs" | |
"github.com/diskfs/go-diskfs/disk" | |
"github.com/diskfs/go-diskfs/filesystem" | |
"github.com/diskfs/go-diskfs/partition/mbr" | |
) | |
func check(err error) { | |
if err != nil { | |
log.Fatal(err) | |
} | |
} | |
func main() { | |
var diskSize int64 | |
diskSize = 10 * 1024 * 1024 // 10 MB | |
diskImg := "/tmp/mydisk.iso" | |
mydisk, _ := diskfs.Create(diskImg, diskSize, diskfs.Raw) | |
table := &mbr.Table{ | |
LogicalSectorSize: 512, | |
PhysicalSectorSize: 512, | |
Partitions: []*mbr.Partition{ | |
{ | |
Bootable: false, | |
Type: mbr.Iso9660, | |
Start: 2048, | |
Size: 20480, | |
}, | |
}, | |
} | |
err := mydisk.Partition(table) | |
check(err) | |
fspec := disk.FilesystemSpec{1, filesystem.TypeISO9660, "label"} | |
fs, err := mydisk.CreateFilesystem(fspec) | |
check(err) | |
//err = fs.Mkdir("/demo") | |
rw, err := fs.OpenFile("demo.txt", os.O_CREATE|os.O_RDWR) | |
content := []byte("demo") | |
_, err = rw.Write(content) | |
check(err) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment