forked from diskfs/go-diskfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
squashfs_create.go
35 lines (31 loc) · 931 Bytes
/
squashfs_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
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/squashfs"
)
func CreateSquashfs(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)
fspec := disk.FilesystemSpec{Partition: 0, FSType: filesystem.TypeSquashfs, 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)
sqs, ok := fs.(*squashfs.FileSystem)
if !ok {
check(fmt.Errorf("not a squashfs filesystem"))
}
err = sqs.Finalize(squashfs.FinalizeOptions{})
check(err)
}