summaryrefslogtreecommitdiff
path: root/cmd/create
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/create')
-rw-r--r--cmd/create/create.ha41
1 files changed, 41 insertions, 0 deletions
diff --git a/cmd/create/create.ha b/cmd/create/create.ha
new file mode 100644
index 0000000..124d86e
--- /dev/null
+++ b/cmd/create/create.ha
@@ -0,0 +1,41 @@
+use fmt;
+use fs;
+use getopt;
+use io;
+use os;
+use strconv;
+
+use gpt;
+use cmd;
+
+export fn create(vol: str, args: []str) void = {
+ // XXX this is a stub
+
+ const c = getopt::parse(args,
+ "create a volume",
+ ('f', "file", "specify another partition file to fit"),
+ ('l', "length", "specify another length margin")
+ );
+ defer getopt::finish(&c);
+
+ let length = 0z;
+
+ for (let i = 0z; i < len(c.opts); i += 1) {
+ const opt = c.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 = cmd::mkvol(vol);
+ const vol = gpt::create(vol, length);
+ defer {
+ gpt::chksums(vol);
+ gpt::commit(vol)!;
+ gpt::finish(vol);
+ };
+};