-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
55 lines (49 loc) · 1.24 KB
/
main.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"flag"
"fmt"
"io"
"os"
"github.com/ErrorNoInternet/mkfs.ext2/filesystem"
)
func main() {
var devicePath string
var blockSize, blocks int
flag.StringVar(&devicePath, "device", "", "The device you want to create a filesystem on")
flag.IntVar(&blockSize, "blockSize", 4096, "The size (in bytes) of each block in the filesystem")
flag.IntVar(&blocks, "blocks", 0, "The amount of blocks to create in the filesystem")
flag.Parse()
if devicePath == "" {
flag.Usage()
return
}
if blocks == 0 {
deviceInformation, err := os.Stat(devicePath)
if err != nil {
blocks = 1024 * 256
} else if deviceInformation.Size() == 0 {
device, err := os.Open(devicePath)
if err != nil {
fmt.Printf("unable to open file: %v\n", err)
return
}
position, err := device.Seek(0, io.SeekEnd)
if err != nil {
fmt.Printf("unable to seek to end of file: %v\n", err)
return
}
blocks = int(position / int64(blockSize))
} else {
blocks = int(deviceInformation.Size() / int64(blockSize))
}
}
file, err := os.Create(devicePath)
if err != nil {
fmt.Printf("unable to create file: %v\n", err)
return
}
err = filesystem.Make(file, blockSize, blocks)
if err != nil {
fmt.Printf("error: %v\n", err)
}
}