BarryServer : Git

All the code for all my projects
// BarryServer : Git / Nucleus / commit / d3f787c50eda2dadb77ae216aef1f0bd0a686ae3 / vfs / mount.c

// Related

Nucleus

Barry More VFS functions and structure d3f787c (3 years, 2 months ago)
diff --git a/vfs/mount.c b/vfs/mount.c
index 53bdab2..a321d34 100644
--- a/vfs/mount.c
+++ b/vfs/mount.c
@@ -4,12 +4,14 @@
  */
 
 #include <string.h>
+#include <sys/stat.h>
 #include <errno.h>
 #include <nucleus/memory.h>
 #include <nucleus/task.h>
 #include <nucleus/vfs.h>
 #include "namespace.h"
 
+Inode *lookup(const char *path, ObjectList *newcustody);
 int mount_fstype(const char *name, int flags, const char *src, void *data,
                  Inode **root);
 
@@ -18,6 +20,8 @@ int
 mount(const char *src, const char *target, const char *type,
       unsigned long flags, void *data)
 {
+	if (!src || !type)
+		return -EFAULT;
 	if (!verify_access(src, strnlen(src, PATH_MAX), PROT_READ))
 		return -EFAULT;
 	if (!verify_access(target, strnlen(target, PATH_MAX), PROT_READ))
@@ -39,5 +43,23 @@ mount(const char *src, const char *target, const char *type,
 		return 0;
 	}
 
+	/* Find target's directory entry */
+	ObjectList *custody = create_list(&dirEntryType, LIST_NORMAL);
+	Inode *root = lookup(target, custody);
+	if (!root) {
+		destroy_list(custody);
+		return -ENOENT;
+	}
+	if (!S_ISDIR(root->mode)) {
+		put(root);
+		destroy_list(custody);
+		return -ENOTDIR;
+	}
+	DirEntry *de = get_nth_item(custody, count(custody) - 1);
+	de->mnt = de->inode;
+	de->inode = get(mnt);
+	put(root);
+	destroy_list(custody);
+
 	return 0;
 }