VFS.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include "VFS.h"
  2. #include <common/kprint.h>
  3. // 为filesystem_type_t结构体实例化一个链表头
  4. static struct vfs_filesystem_type_t vfs_fs = {"filesystem", 0};
  5. /**
  6. * @brief 挂载文件系统
  7. *
  8. * @param name 文件系统名
  9. * @param DPTE 分区表entry
  10. * @param DPT_type 分区表类型
  11. * @param buf 缓存去
  12. * @return struct vfs_superblock_t*
  13. */
  14. struct vfs_superblock_t *vfs_mount_fs(char *name, void *DPTE, uint8_t DPT_type, void *buf)
  15. {
  16. struct vfs_filesystem_type_t *p = NULL;
  17. for (p = &vfs_fs; p; p = p->next)
  18. {
  19. if (!strcmp(p->name, name)) // 存在符合的文件系统
  20. {
  21. return p->read_superblock(DPTE, DPT_type, buf);
  22. }
  23. }
  24. kdebug("unsupported fs: %s", name);
  25. return NULL;
  26. }
  27. /**
  28. * @brief 在VFS中注册文件系统
  29. *
  30. * @param fs 文件系统类型结构体
  31. * @return uint64_t
  32. */
  33. uint64_t vfs_register_filesystem(struct vfs_filesystem_type_t *fs)
  34. {
  35. struct vfs_filesystem_type_t *p = NULL;
  36. for(p = &vfs_fs; p;p = p->next)
  37. {
  38. if(!strcmp(p->name,fs->name)) // 已经注册相同名称的文件系统
  39. return VFS_E_FS_EXISTED;
  40. }
  41. fs->next = vfs_fs.next;
  42. vfs_fs.next = fs;
  43. return VFS_SUCCESS;
  44. }
  45. uint64_t vfs_unregister_filesystem(struct vfs_filesystem_type_t *fs)
  46. {
  47. struct vfs_filesystem_type_t *p = &vfs_fs;
  48. while(p->next)
  49. {
  50. if(p->next == fs)
  51. {
  52. p->next = p->next->next;
  53. fs->next = NULL;
  54. return VFS_SUCCESS;
  55. }
  56. else p = p->next;
  57. }
  58. return VFS_E_FS_NOT_EXIST;
  59. }