Nucleus
Barry Device file system 88d672a (3 years, 3 months ago)
diff --git a/vfs/open.c b/vfs/open.c
index cf03a24..630b675 100644
--- a/vfs/open.c
+++ b/vfs/open.c
@@ -187,3 +187,41 @@ open(const char *name, int flags, ...)
put(inode);
return fd;
}
+
+/* Make a directory */
+int
+mkdir(const char *pathname, mode_t mode)
+{
+ if (!pathname)
+ return -EFAULT;
+ if (!verify_access(pathname, strnlen(pathname, PATH_MAX), PROT_READ))
+ return -EFAULT;
+ int err;
+ ObjectList *custody = create_list(&dirEntryType);
+ Inode *inode = lookup(pathname, custody);
+ if (inode) {
+ err = -EEXIST;
+ goto end;
+ }
+ if (!count(custody)) {
+ err = -ENOENT;
+ goto end;
+ }
+ /* Check write permission */
+ DirEntry *entry = get_nth_item(custody, count(custody) - 2);
+ if (entry)
+ inode = entry->inode;
+ else
+ inode = current->fs->root;
+ if (!permission(inode, PROT_WRITE)) {
+ err = -EACCES;
+ goto end;
+ }
+
+ /* Create directory */
+ err = inode_mkdir(inode, get_nth_item(custody, count(custody) - 1),
+ mode);
+end:
+ destroy_list(custody);
+ return err;
+}