forked from diskfs/go-diskfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iso_create.go
38 lines (34 loc) · 1.04 KB
/
iso_create.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package examples
import (
"fmt"
"log"
"os"
diskfs "github.com/herrdivad/go-diskfs"
"github.com/herrdivad/go-diskfs/disk"
"github.com/herrdivad/go-diskfs/filesystem"
"github.com/herrdivad/go-diskfs/filesystem/iso9660"
)
func CreateIso(diskImg string) {
if diskImg == "" {
log.Fatal("must have a valid path for diskImg")
}
var diskSize int64 = 10 * 1024 * 1024 // 10 MB
mydisk, err := diskfs.Create(diskImg, diskSize, diskfs.Raw, diskfs.SectorSizeDefault)
check(err)
// the following line is required for an ISO, which may have logical block sizes
// only of 2048, 4096, 8192
mydisk.LogicalBlocksize = 2048
fspec := disk.FilesystemSpec{Partition: 0, FSType: filesystem.TypeISO9660, VolumeLabel: "label"}
fs, err := mydisk.CreateFilesystem(fspec)
check(err)
rw, err := fs.OpenFile("demo.txt", os.O_CREATE|os.O_RDWR)
content := []byte("demo")
_, err = rw.Write(content)
check(err)
iso, ok := fs.(*iso9660.FileSystem)
if !ok {
check(fmt.Errorf("not an iso9660 filesystem"))
}
err = iso.Finalize(iso9660.FinalizeOptions{})
check(err)
}