summaryrefslogtreecommitdiff
path: root/fs/vfs.c
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2023-10-23 22:13:19 +0200
committerAnton Kling <anton@kling.gg>2023-10-23 23:36:34 +0200
commite05d72ba8f09866b768f3da7776b807072ed7b9b (patch)
treedc9a1ec45802df7c74ddc9fdd78436b23122e44a /fs/vfs.c
parent6458875860cde6421a06031702788d9969e0a5db (diff)
VFS/libc: Create a syscall for mkdir and add the function to libc
Diffstat (limited to 'fs/vfs.c')
-rw-r--r--fs/vfs.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/fs/vfs.c b/fs/vfs.c
index 9842e11..5f61d89 100644
--- a/fs/vfs.c
+++ b/fs/vfs.c
@@ -30,6 +30,7 @@ vfs_inode_t *vfs_create_inode(
int (*read)(uint8_t *buffer, uint64_t offset, uint64_t len, vfs_fd_t *fd),
int (*write)(uint8_t *buffer, uint64_t offset, uint64_t len, vfs_fd_t *fd),
void (*close)(vfs_fd_t *fd),
+ int (*create_directory)(const char *path, int mode),
vfs_vm_object_t *(*get_vm_object)(uint64_t length, uint64_t offset,
vfs_fd_t *fd)) {
vfs_inode_t *r = kmalloc(sizeof(inode_t));
@@ -45,6 +46,7 @@ vfs_inode_t *vfs_create_inode(
r->read = read;
r->write = write;
r->close = close;
+ r->create_directory = create_directory;
r->get_vm_object = get_vm_object;
return r;
}
@@ -155,6 +157,33 @@ char *vfs_resolve_path(const char *file, char *resolved_path) {
return final;
}
+int vfs_mkdir(const char *path, int mode) {
+ vfs_mounts_t *file_mount = 0;
+ int length = 0;
+ for (int i = 0; i < num_mounts; i++) {
+ int path_len = strlen(mounts[i].path);
+ if (path_len <= length)
+ continue;
+
+ if (isequal_n(mounts[i].path, path, path_len)) {
+ length = path_len;
+ file_mount = &mounts[i];
+ }
+ }
+ if (1 != length)
+ path += length;
+
+ if (!file_mount) {
+ kprintf("vfs_internal_open could not find mounted path for file : %s\n",
+ path);
+ return 0;
+ }
+ assert(file_mount->local_root->create_directory);
+ // TODO: Error checking, don't just assume it is fine
+ file_mount->local_root->create_directory(path, mode);
+ return 0;
+}
+
int vfs_open(const char *file, int flags, int mode) {
char resolved_path[256] = {0};
vfs_resolve_path(file, resolved_path);