diff options
| author | Alejandro Sior <aho@sior.be> | 2022-06-21 15:38:48 +0200 |
|---|---|---|
| committer | Alejandro Sior <aho@sior.be> | 2022-06-21 15:38:48 +0200 |
| commit | f42a480cbe487fc5fb9b3772990e80926201f6e4 (patch) | |
| tree | d6af05ea6942732fafa721c97895b66cd42298b3 /cmd/util.ha | |
| parent | d000a6edf4ad9fcc2302a80080fdbebb23fb7378 (diff) | |
gptman: reorganize commands in a cmd module
Diffstat (limited to 'cmd/util.ha')
| -rw-r--r-- | cmd/util.ha | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/cmd/util.ha b/cmd/util.ha new file mode 100644 index 0000000..832a96f --- /dev/null +++ b/cmd/util.ha @@ -0,0 +1,37 @@ +use fmt; +use fs; +use io; +use os; + +use gpt; + +export fn mkvol(vol: str) io::file = { + return match (os::create(vol, fs::mode::USER_RWX | fs::mode::GROUP_RX | fs::mode::OTHER_RX, fs::flags::RDWR)) { + case let v: io::file => + yield v; + case => + fmt::fatalf("{}: cannot open file {}", os::args[0], vol); + }; +}; + +export fn openvol(vol: str) io::file = { + return match (os::open(vol, fs::flags::RDWR)) { + case let v: io::file => + yield v; + case => + fmt::fatalf("{}: cannot open file {}", os::args[0], vol); + }; +}; + +export fn opengpt(vol: str) *gpt::gpt = { + const vol = openvol(vol); + + return match (gpt::from(vol)) { + case let g: *gpt::gpt => + yield g; + case io::error => + fmt::fatalf("{}: could not properly read disk {}", os::args[0], os::args[1]); + case => + fmt::fatalf("{}: no valid gpt in disk", os::args[0]); + }; +}; |
