From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: implicitfield <114500360+implicitfield@users.noreply.github.com>
Date: Mon, 5 Feb 2024 00:55:02 +0400
Subject: [PATCH] Disable unsupported functionality

---
 example/meson.build         | 11 +++++------
 include/fuse_mount_compat.h |  2 ++
 lib/fuse_loop_mt.c          |  4 ++++
 lib/meson.build             |  6 ++++--
 lib/mount_bsd.c             | 19 +++++++++++++++++++
 lib/mount_util.c            |  4 ++++
 meson.build                 |  2 +-
 test/meson.build            |  2 ++
 8 files changed, 41 insertions(+), 9 deletions(-)

diff --git a/example/meson.build b/example/meson.build
index e641543..3ee2630 100644
--- a/example/meson.build
+++ b/example/meson.build
@@ -1,9 +1,8 @@
-examples = [ 'passthrough', 'passthrough_fh',
-             'hello', 'hello_ll', 'hello_ll_uds',
-             'printcap', 'ioctl_client', 'poll_client',
-             'ioctl', 'cuse', 'cuse_client' ]
+examples = [ 'passthrough',
+             'hello', 'hello_ll',
+             'printcap', 'poll_client'  ]
 
-if not platform.endswith('bsd') and platform != 'dragonfly'
+if not platform.endswith('bsd') and platform != 'dragonfly' and platform != 'minerva'
     examples += 'passthrough_ll'
 
     # According to Conrad Meyer <cem@freebsd.org>, FreeBSD doesn't
@@ -31,7 +30,7 @@ foreach ex : threaded_examples
                install: false)
 endforeach
 
-if not platform.endswith('bsd') and platform != 'dragonfly' and add_languages('cpp', required : false)
+if not platform.endswith('bsd') and platform != 'dragonfly' and platform != 'minerva' and add_languages('cpp', required : false)
     executable('passthrough_hp', 'passthrough_hp.cc',
                dependencies: [ thread_dep, libfuse_dep ],
                install: false)
diff --git a/include/fuse_mount_compat.h b/include/fuse_mount_compat.h
index 0142b51..f52b8f5 100644
--- a/include/fuse_mount_compat.h
+++ b/include/fuse_mount_compat.h
@@ -11,7 +11,9 @@
 #ifndef FUSE_MOUNT_COMPAT_H_
 #define FUSE_MOUNT_COMPAT_H_
 
+#ifndef __minerva__
 #include <sys/mount.h>
+#endif
 
 /* Some libc don't define MS_*, so define them manually
  * (values taken from https://elixir.bootlin.com/linux/v4.0.9/source/include/uapi/linux/fs.h#L68 on)
diff --git a/lib/fuse_loop_mt.c b/lib/fuse_loop_mt.c
index 0200d73..edef914 100644
--- a/lib/fuse_loop_mt.c
+++ b/lib/fuse_loop_mt.c
@@ -242,6 +242,7 @@ int fuse_start_thread(pthread_t *thread_id, void *(*func)(void *), void *arg)
 	return 0;
 }
 
+#ifndef __minerva__
 static struct fuse_chan *fuse_clone_chan(struct fuse_mt *mt)
 {
 	int res;
@@ -275,6 +276,7 @@ static struct fuse_chan *fuse_clone_chan(struct fuse_mt *mt)
 
 	return newch;
 }
+#endif
 
 static int fuse_loop_start_thread(struct fuse_mt *mt)
 {
@@ -290,6 +292,7 @@ static int fuse_loop_start_thread(struct fuse_mt *mt)
 	w->mt = mt;
 
 	w->ch = NULL;
+#ifndef __minerva__
 	if (mt->clone_fd) {
 		w->ch = fuse_clone_chan(mt);
 		if(!w->ch) {
@@ -299,6 +302,7 @@ static int fuse_loop_start_thread(struct fuse_mt *mt)
 			mt->clone_fd = 0;
 		}
 	}
+#endif
 
 	res = fuse_start_thread(&w->thread_id, fuse_do_work, w);
 	if (res == -1) {
diff --git a/lib/meson.build b/lib/meson.build
index 9044630..93fecc8 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -28,8 +28,10 @@ if host_machine.system().startswith('netbsd')
    deps += [ cc.find_library('perfuse'),
              cc.find_library('puffs') ]
 else
-   # Required for clock_gettime before glibc 2.17
-   deps += cc.find_library('rt')
+   if host_machine.system() != 'minerva'
+      # Required for clock_gettime before glibc 2.17
+      deps += cc.find_library('rt')
+   endif
 endif
 
 fusermount_path = join_paths(get_option('prefix'), get_option('bindir'))
diff --git a/lib/mount_bsd.c b/lib/mount_bsd.c
index 73abc67..666be7f 100644
--- a/lib/mount_bsd.c
+++ b/lib/mount_bsd.c
@@ -8,7 +8,9 @@
   See the file COPYING.LIB.
 */
 
+#ifndef __minerva__
 #include "config.h"
+#endif
 #include "fuse_i.h"
 #include "fuse_misc.h"
 #include "fuse_opt.h"
@@ -18,8 +20,10 @@
 
 #include <sys/stat.h>
 #include <sys/wait.h>
+#ifndef __minerva__
 #include <sys/sysctl.h>
 #include <sys/user.h>
+#endif
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -115,10 +119,12 @@ static int fuse_mount_opt_proc(void *data, const char *arg, int key,
 	struct mount_opts *mo = data;
 
 	switch (key) {
+#ifndef __minerva__
 	case KEY_RO:
 		arg = "ro";
 		/* fall through */
 
+#endif
 	case KEY_KERN:
 		return fuse_opt_add_opt(&mo->kernel_opts, arg);
 	}
@@ -130,12 +136,19 @@ static int fuse_mount_opt_proc(void *data, const char *arg, int key,
 void fuse_kern_unmount(const char *mountpoint, int fd)
 {
 	close(fd);
+#ifdef __minerva__
+	umount(mountpoint);
+#else
 	unmount(mountpoint, MNT_FORCE);
+#endif
 }
 
 /* Check if kernel is doing init in background */
 static int init_backgrounded(void)
 {
+#ifdef __minerva__
+	return 0;
+#else
 	unsigned ibg;
 	size_t len;
 
@@ -145,6 +158,7 @@ static int init_backgrounded(void)
 		return 0;
 
 	return ibg;
+#endif
 }
 
 
diff --git a/lib/mount_util.c b/lib/mount_util.c
index 8027a2e..cb305da 100644
--- a/lib/mount_util.c
+++ b/lib/mount_util.c
@@ -37,6 +37,10 @@
 #define umount2(mnt, flags) unmount(mnt, ((flags) == 2) ? MNT_FORCE : 0)
 #endif
 
+#if defined(__minerva__)
+#define umount2(mnt, flags) umount(mnt)
+#endif
+
 #ifdef IGNORE_MTAB
 #define mtab_needs_update(mnt) 0
 #else
diff --git a/meson.build b/meson.build
index 042c19c..bfddbb7 100644
--- a/meson.build
+++ b/meson.build
@@ -205,7 +205,7 @@ thread_dep = dependency('threads')
 # Read build files from sub-directories
 #
 subdirs = [ 'lib', 'include']
-if get_option('utils') and not platform.endswith('bsd') and platform != 'dragonfly'
+if get_option('utils') and not platform.endswith('bsd') and platform != 'dragonfly' and platform != 'minerva'
   subdirs += [ 'util', 'doc' ]
 endif
 
diff --git a/test/meson.build b/test/meson.build
index 3d74b9a..cc09527 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -7,9 +7,11 @@ foreach prog: [ 'test_write_cache', 'test_setattr' ]
                      dependencies: thread_dep,
                      install: false)
 endforeach
+if platform != 'minerva'
 td += executable('test_syscalls', 'test_syscalls.c',
                  include_directories: include_dirs,
                  install: false)
+endif
 td += executable('readdir_inode', 'readdir_inode.c',
                  include_directories: include_dirs,
                  install: false)
