Skip to content

Instantly share code, notes, and snippets.

@kstieger
Last active November 13, 2019 14:23
Show Gist options
  • Save kstieger/3fa5b945a9008de91c974ddd611ab325 to your computer and use it in GitHub Desktop.
Save kstieger/3fa5b945a9008de91c974ddd611ab325 to your computer and use it in GitHub Desktop.
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