aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lfvm/CMakeLists.txt1
-rw-r--r--lfvm/disk_show.cc51
2 files changed, 52 insertions, 0 deletions
diff --git a/lfvm/CMakeLists.txt b/lfvm/CMakeLists.txt
index ce53735..02ce262 100644
--- a/lfvm/CMakeLists.txt
+++ b/lfvm/CMakeLists.txt
@@ -14,6 +14,7 @@ target_sources(lfvm PRIVATE
disk_create.cc
disk_list.cc
+ disk_show.cc
)
include(GNUInstallDirs)
diff --git a/lfvm/disk_show.cc b/lfvm/disk_show.cc
new file mode 100644
index 0000000..eef9b79
--- /dev/null
+++ b/lfvm/disk_show.cc
@@ -0,0 +1,51 @@
+/*
+ * This source code is released into the public domain.
+ */
+
+#include <iostream>
+#include <print>
+#include <string>
+
+#include <unistd.h>
+
+import nihil;
+import liblfvm;
+
+namespace {
+
+auto create = nihil::command("disk show", "<disk>",
+[](int argc, char **argv) -> int
+{
+ auto &ctx = lfvm::get_context();
+
+ auto ch = 0;
+ while ((ch = getopt(argc, argv, "")) != -1) {
+ switch (ch) {
+ default:
+ return 1;
+ }
+ }
+ argc -= ::optind;
+ argv += ::optind;
+
+ if (argc != 1)
+ throw nihil::usage_error("expected disk name");
+
+ auto diskname = std::string_view(argv[0]);
+ auto disk = lfvm::disk_load(ctx, diskname);
+ if (!disk) {
+ std::print(std::cerr, "cannot load disk {}: {}\n",
+ diskname, disk.error());
+ return 1;
+ }
+
+ --argc;
+ ++argv;
+
+ std::print("{}:\n", disk->name());
+ std::print("\tbacking file: {}\n", disk->path().string());
+
+ return 0;
+});
+
+} // anonymous namespace