dfs_fs.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * File : dfs_fs.h
  3. * This file is part of Device File System in RT-Thread RTOS
  4. * COPYRIGHT (C) 2004-2012, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2005-02-22 Bernard The first version.
  23. */
  24. #ifndef __DFS_FS_H__
  25. #define __DFS_FS_H__
  26. #include <dfs_def.h>
  27. #define DFS_FS_FLAG_DEFAULT 0x00 /* default flag */
  28. #define DFS_FS_FLAG_FULLPATH 0x01 /* set full path to underlaying file system */
  29. /* Pre-declaration */
  30. struct dfs_filesystem;
  31. struct dfs_fd;
  32. /* File system operations struct */
  33. struct dfs_filesystem_operation
  34. {
  35. char *name;
  36. rt_uint32_t flags; /* flags for file system operations */
  37. /* mount and unmount file system */
  38. int (*mount) (struct dfs_filesystem *fs, unsigned long rwflag, const void *data);
  39. int (*unmount) (struct dfs_filesystem *fs);
  40. /* make a file system */
  41. int (*mkfs) (rt_device_t devid);
  42. int (*statfs) (struct dfs_filesystem *fs, struct statfs *buf);
  43. int (*open) (struct dfs_fd *fd);
  44. int (*close) (struct dfs_fd *fd);
  45. int (*ioctl) (struct dfs_fd *fd, int cmd, void *args);
  46. int (*read) (struct dfs_fd *fd, void *buf, rt_size_t count);
  47. int (*write) (struct dfs_fd *fd, const void *buf, rt_size_t count);
  48. int (*flush) (struct dfs_fd *fd);
  49. int (*lseek) (struct dfs_fd *fd, rt_off_t offset);
  50. int (*getdents) (struct dfs_fd *fd, struct dirent *dirp, rt_uint32_t count);
  51. int (*unlink) (struct dfs_filesystem *fs, const char *pathname);
  52. int (*stat) (struct dfs_filesystem *fs, const char *filename, struct stat *buf);
  53. int (*rename) (struct dfs_filesystem *fs, const char *oldpath, const char *newpath);
  54. };
  55. /* Mounted file system */
  56. struct dfs_filesystem
  57. {
  58. rt_device_t dev_id; /* Attached device */
  59. char *path; /* File system mount point */
  60. const struct dfs_filesystem_operation *ops; /* Operations for file system type */
  61. void *data; /* Specific file system data */
  62. };
  63. /* file system partition table */
  64. struct dfs_partition
  65. {
  66. rt_uint8_t type; /* file system type */
  67. rt_off_t offset; /* partition start offset */
  68. rt_size_t size; /* partition size */
  69. rt_sem_t lock;
  70. };
  71. /* mount table */
  72. struct dfs_mount_tbl
  73. {
  74. const char *device_name;
  75. const char *path;
  76. const char *filesystemtype;
  77. unsigned long rwflag;
  78. const void *data;
  79. };
  80. int dfs_register(const struct dfs_filesystem_operation *ops);
  81. struct dfs_filesystem *dfs_filesystem_lookup(const char *path);
  82. const char* dfs_filesystem_get_mounted_path(struct rt_device* device);
  83. rt_err_t dfs_filesystem_get_partition(struct dfs_partition *part,
  84. rt_uint8_t *buf,
  85. rt_uint32_t pindex);
  86. int dfs_mount(const char *device_name,
  87. const char *path,
  88. const char *filesystemtype,
  89. rt_uint32_t rwflag,
  90. const void *data);
  91. int dfs_unmount(const char *specialfile);
  92. /* extern variable */
  93. extern const struct dfs_filesystem_operation *filesystem_operation_table[];
  94. extern struct dfs_filesystem filesystem_table[];
  95. extern const struct dfs_mount_tbl mount_table[];
  96. extern char working_directory[];
  97. void dfs_lock(void);
  98. void dfs_unlock(void);
  99. int dfs_mkfs(const char *fs_name, const char *device_name);
  100. int dfs_statfs(const char *path, struct statfs *buffer);
  101. #endif