123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- #include "VFS.h"
- #include <common/kprint.h>
- #include <mm/slab.h>
- static struct vfs_filesystem_type_t vfs_fs = {"filesystem", 0};
- struct vfs_superblock_t *vfs_mount_fs(char *name, void *DPTE, uint8_t DPT_type, void *buf, int8_t ahci_ctrl_num, int8_t ahci_port_num, int8_t part_num)
- {
- struct vfs_filesystem_type_t *p = NULL;
- for (p = &vfs_fs; p; p = p->next)
- {
- if (!strcmp(p->name, name))
- {
- return p->read_superblock(DPTE, DPT_type, buf, ahci_ctrl_num, ahci_port_num, part_num);
- }
- }
- kdebug("unsupported fs: %s", name);
- return NULL;
- }
- uint64_t vfs_register_filesystem(struct vfs_filesystem_type_t *fs)
- {
- struct vfs_filesystem_type_t *p = NULL;
- for (p = &vfs_fs; p; p = p->next)
- {
- if (!strcmp(p->name, fs->name))
- return VFS_E_FS_EXISTED;
- }
- fs->next = vfs_fs.next;
- vfs_fs.next = fs;
- return VFS_SUCCESS;
- }
- uint64_t vfs_unregister_filesystem(struct vfs_filesystem_type_t *fs)
- {
- struct vfs_filesystem_type_t *p = &vfs_fs;
- while (p->next)
- {
- if (p->next == fs)
- {
- p->next = p->next->next;
- fs->next = NULL;
- return VFS_SUCCESS;
- }
- else
- p = p->next;
- }
- return VFS_E_FS_NOT_EXIST;
- }
- struct vfs_dir_entry_t *vfs_path_walk(char *path, uint64_t flags)
- {
- struct vfs_dir_entry_t *parent = vfs_root_sb->root;
-
- while (*path == '/')
- ++path;
- if ((!*path) || (*path == '\0'))
- return parent;
- struct vfs_dir_entry_t *dentry;
- while (true)
- {
-
- char *tmp_path = path;
- while ((*path && *path != '\0') && (*path != '/'))
- ++path;
- int tmp_path_len = path - tmp_path;
- dentry = (struct vfs_dir_entry_t *)kmalloc(sizeof(struct vfs_dir_entry_t), 0);
- memset(dentry, 0, sizeof(struct vfs_dir_entry_t));
-
- dentry->name = (char *)kmalloc(tmp_path_len + 1, 0);
-
-
- memcpy(dentry->name, tmp_path, tmp_path_len);
- dentry->name[tmp_path_len] = '\0';
- dentry->name_length = tmp_path_len;
- if (parent->dir_inode->inode_ops->lookup(parent->dir_inode, dentry) == NULL)
- {
-
- kerror("cannot find the file/dir : %s", dentry->name);
- kfree(dentry->name);
- kfree(dentry);
- return NULL;
- }
-
-
- list_init(&dentry->child_node_list);
- list_init(&dentry->subdirs_list);
- dentry->parent = parent;
- while (*path == '/')
- ++path;
- if ((!*path) || (*path == '\0'))
- {
- if (flags & 1)
- {
- return parent;
- }
- return dentry;
- }
- parent = dentry;
- }
- }
|