dfs_fs.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * File : dfs_fs.h
  3. * This file is part of Device File System in RT-Thread RTOS
  4. * COPYRIGHT (C) 2004-2011, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE.
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2005-02-22 Bernard The first version.
  13. */
  14. #ifndef __DFS_FS_H__
  15. #define __DFS_FS_H__
  16. #include <dfs_def.h>
  17. #define DFS_FS_FLAG_DEFAULT 0x00 /* default flag */
  18. #define DFS_FS_FLAG_FULLPATH 0x01 /* set full path to underlaying file system */
  19. /* Pre-declaration */
  20. struct dfs_filesystem;
  21. struct dfs_fd;
  22. /* File system operations struct */
  23. struct dfs_filesystem_operation
  24. {
  25. char *name;
  26. rt_uint32_t flags; /* flags for file system operations */
  27. /* mount and unmount file system */
  28. int (*mount) (struct dfs_filesystem *fs, unsigned long rwflag, const void *data);
  29. int (*unmount) (struct dfs_filesystem *fs);
  30. /* make a file system */
  31. int (*mkfs) (const char *device_name);
  32. int (*statfs) (struct dfs_filesystem *fs, struct statfs *buf);
  33. int (*open) (struct dfs_fd *fd);
  34. int (*close) (struct dfs_fd *fd);
  35. int (*ioctl) (struct dfs_fd *fd, int cmd, void *args);
  36. int (*read) (struct dfs_fd *fd, void *buf, rt_size_t count);
  37. int (*write) (struct dfs_fd *fd, const void *buf, rt_size_t count);
  38. int (*flush) (struct dfs_fd *fd);
  39. int (*lseek) (struct dfs_fd *fd, rt_off_t offset);
  40. int (*getdents) (struct dfs_fd *fd, struct dirent *dirp, rt_uint32_t count);
  41. int (*unlink) (struct dfs_filesystem *fs, const char *pathname);
  42. int (*stat) (struct dfs_filesystem *fs, const char *filename, struct stat *buf);
  43. int (*rename) (struct dfs_filesystem *fs, const char *oldpath, const char *newpath);
  44. };
  45. /* Mounted file system */
  46. struct dfs_filesystem
  47. {
  48. rt_device_t dev_id; /* Attached device */
  49. char *path; /* File system mount point */
  50. const struct dfs_filesystem_operation *ops; /* Operations for file system type */
  51. void *data; /* Specific file system data */
  52. };
  53. /* file system partition table */
  54. struct dfs_partition
  55. {
  56. rt_uint8_t type; /* file system type */
  57. rt_off_t offset; /* partition start offset */
  58. rt_size_t size; /* partition size */
  59. rt_sem_t lock;
  60. };
  61. int dfs_register(const struct dfs_filesystem_operation *ops);
  62. struct dfs_filesystem *dfs_filesystem_lookup(const char *path);
  63. rt_err_t dfs_filesystem_get_partition(struct dfs_partition *part, rt_uint8_t *buf, rt_uint32_t pindex);
  64. int dfs_mount(const char *device_name, const char *path,
  65. const char *filesystemtype, rt_uint32_t rwflag, const
  66. void *data);
  67. int dfs_unmount(const char *specialfile);
  68. /* extern variable */
  69. extern const struct dfs_filesystem_operation *filesystem_operation_table[];
  70. extern struct dfs_filesystem filesystem_table[];
  71. extern char working_directory[];
  72. void dfs_lock(void);
  73. void dfs_unlock(void);
  74. int dfs_statfs(const char *path, struct statfs *buffer);
  75. #endif