dfs_fs.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. +------------------------------------------------------------------------------
  3. | Project : Device Filesystem
  4. +------------------------------------------------------------------------------
  5. | Copyright 2004, 2005 www.fayfayspace.org.
  6. | All rights reserved.
  7. |------------------------------------------------------------------------------
  8. | File : dfs_fs.h, the filesystem related defines of Device FileSystem
  9. |------------------------------------------------------------------------------
  10. | Chang Logs:
  11. | Date Author Notes
  12. | 2005-02-22 ffxz The first version.
  13. +------------------------------------------------------------------------------
  14. */
  15. #ifndef __DFS_FS_H__
  16. #define __DFS_FS_H__
  17. #include <dfs_def.h>
  18. #include <dfs_config.h>
  19. /* Pre-declaration */
  20. struct dfs_filesystem;
  21. struct dfs_fd;
  22. struct dfs_dirent;
  23. /* File system operations struct */
  24. struct dfs_filesystem_operation
  25. {
  26. char name[DFS_FS_NAME_MAX + 1];
  27. int (*mount) (struct dfs_filesystem* fs);
  28. int (*unmount) (struct dfs_filesystem* fs);
  29. int (*open) (struct dfs_fd* fd);
  30. int (*close) (struct dfs_fd* fd);
  31. int (*ioctl) (struct dfs_fd* fd, int cmd, void *args);
  32. int (*read) (struct dfs_fd* fd, void* buf, rt_size_t count);
  33. int (*write) (struct dfs_fd* fd, const void* buf, rt_size_t count);
  34. int (*lseek) (struct dfs_fd* fd, rt_off_t offset);
  35. int (*getdents) (struct dfs_fd* fd, struct dfs_dirent* dirp, rt_uint32_t count);
  36. int (*unlink) (struct dfs_filesystem* fs, const char* pathname);
  37. int (*stat) (struct dfs_filesystem* fs, const char* filename, struct dfs_stat* buf);
  38. int (*rename) (struct dfs_filesystem* fs, const char* oldpath, const char* newpath);
  39. };
  40. /* Mounted file system */
  41. struct dfs_filesystem
  42. {
  43. rt_device_t dev_id; /* Attached device */
  44. char path[DFS_PATH_MAX + 1]; /* File system mount point */
  45. struct dfs_filesystem_operation* ops; /* Operations for file system type */
  46. rt_uint32_t block_id; /* Current block_id on attached device */
  47. void *data; /* Specific file system data */
  48. };
  49. /* file system partition table */
  50. struct dfs_partition
  51. {
  52. rt_uint8_t type; /* file system type */
  53. rt_off_t offset; /* partition start offset */
  54. rt_size_t size; /* partition size */
  55. rt_sem_t lock;
  56. };
  57. int dfs_register(struct dfs_filesystem_operation* ops);
  58. struct dfs_filesystem* dfs_filesystem_lookup(const char *path);
  59. rt_err_t dfs_filesystem_get_partition(struct dfs_partition* part, rt_uint8_t* buf, rt_uint32_t pindex);
  60. int dfs_mount(const char* device_name, const char* path,
  61. const char* filesystemtype, rt_uint32_t rwflag, const
  62. void* data);
  63. int dfs_unmount(const char *specialfile);
  64. /* extern variable */
  65. extern struct dfs_filesystem_operation* filesystem_operation_table[];
  66. extern struct dfs_filesystem filesystem_table[];
  67. extern char working_directory[];
  68. void dfs_lock(void);
  69. void dfs_unlock(void);
  70. #endif