summaryrefslogtreecommitdiff
path: root/create/create.ha
diff options
context:
space:
mode:
Diffstat (limited to 'create/create.ha')
-rw-r--r--create/create.ha30
1 files changed, 28 insertions, 2 deletions
diff --git a/create/create.ha b/create/create.ha
index 2c08eec..b7dc0f7 100644
--- a/create/create.ha
+++ b/create/create.ha
@@ -1,12 +1,38 @@
use fmt;
+use fs;
+use getopt;
use io;
+use os;
+use strconv;
use gpt;
+use volume;
-export fn create(vol: io::file, args: []str) void = {
+export fn create(vol: str, args: []str) void = {
// XXX this is a stub
- const vol = gpt::create(vol, 1000);
+ const cmd = getopt::parse(args,
+ "create a volume",
+ ('f', "file", "specify another partition file to fit"),
+ ('l', "length", "specify another length margin")
+ );
+ defer getopt::finish(&cmd);
+
+ let length = 0z;
+
+ for (let i = 0z; i < len(cmd.opts); i += 1) {
+ const opt = cmd.opts[i];
+ switch (opt.0) {
+ case 'l' =>
+ length += (strconv::stoi(opt.1)! / 512 + 1): size;
+ case 'f' =>
+ const stat = os::stat(opt.1)!;
+ length += stat.sz / 512 + 1;
+ };
+ };
+
+ const vol = volume::mkvol(vol);
+ const vol = gpt::create(vol, length);
defer {
gpt::chksums(vol);
gpt::commit(vol)!;