Commit 275f6a8fc7327c46c40123c9610368bab4b19307

Thomas de Grivel 2024-12-31T06:25:38

add option parsing and set fuse version from arguments

diff --git a/fs/OpenBSD/kc3fs.h b/fs/OpenBSD/kc3fs.h
new file mode 100644
index 0000000..939cfa3
--- /dev/null
+++ b/fs/OpenBSD/kc3fs.h
@@ -0,0 +1,48 @@
+/* kc3
+ * Copyright 2022,2023,2024 kmx.io <contact@kmx.io>
+ *
+ * Permission is hereby granted to use this software granted the above
+ * copyright notice and this permission paragraph are included in all
+ * copies and substantial portions of this software.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
+ * PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
+ * AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
+ * THIS SOFTWARE.
+ */
+#ifndef KC3FS_KC3FS_H
+#define KC3FS_KC3FS_H
+
+#if ! defined(_KERNEL) && ! defined(_KMEMUSER)
+# error "not supposed to be exposed to userland"
+#endif
+
+#include <libkc3/types.h>
+
+/* Type definitions. */
+
+typedef struct kc3fs_mem_dirent s_kc3fs_mem_dirent;
+typedef struct kc3fs_mem_node   s_kc3fs_mem_node;
+
+/* Enums. */
+
+typedef enum kc3fs_type {
+  KC3FS_VOID = 0,
+  KC3FS_MEM = 1
+} e_kc3fs_type;
+
+/* 1 */
+
+struct kc3fs_mem_node {
+  u8 type;
+  s_str *name;
+  s_str *content;
+};
+
+struct kc3fs_mem_dirent {
+  u8 type;
+  kc3fs_mem_node *node;
+  s_str *name;
+}
+
+#endif /* KC3_FS_TYPES_H */
diff --git a/fs/fuse/mount_kc3fs.c b/fs/fuse/mount_kc3fs.c
index e562dba..9a37aa9 100644
--- a/fs/fuse/mount_kc3fs.c
+++ b/fs/fuse/mount_kc3fs.c
@@ -12,6 +12,7 @@
  */
 #include <errno.h>
 #include <fuse.h>
+#include <fuse_opt.h>
 #include <string.h>
 #include <libkc3/kc3.h>
 #include "types.h"
@@ -212,10 +213,9 @@ static int fs_init (void)
 
 int main (int argc, char **argv)
 {
-  int argc1;
+  int    argc1;
   char **argv1;
-  int argc2;
-  char *argv2[3] = {0};
+  struct fuse_args args;
   int r = 1;
   argc1 = argc;
   argv1 = argv;
@@ -227,10 +227,19 @@ int main (int argc, char **argv)
   }
   if ((r = fs_init()))
     goto clean;
-  argc2 = 1;
-  argv2[0] = argv[0];
-  argv2[1] = argv[argc];
-  r = fuse_main(argc2, argv2, &g_fsops, NULL);
+  args = (struct fuse_args) FUSE_ARGS_INIT(argc, argv);
+  if (fuse_opt_add_arg(&args, "-o") == -1) {
+    err_puts("mount_kc3fs: fuse_opt_add_arg(-o)");
+    r = 1;
+    goto clean;
+  }
+  if (fuse_opt_add_arg(&args, "fuse_version=2.6") == -1) {
+    err_puts("mount_kc3fs: fuse_opt_add_arg(fuse_version)");
+    r = 1;
+    goto clean;
+  }
+  r = fuse_main(args.argc, args.argv, &g_fsops, NULL);
+  fuse_opt_free_args(&args);
  clean:
   kc3_clean(NULL);
   return r;