dfs_fs.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * File : dfs_fs.h
  3. * This file is part of Device File System in RT-Thread RTOS
  4. * COPYRIGHT (C) 2004-2010, 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. #include <dfs_config.h>
  18. /* Pre-declaration */
  19. struct dfs_filesystem;
  20. struct dfs_fd;
  21. struct dfs_dirent;
  22. /* File system operations struct */
  23. struct dfs_filesystem_operation
  24. {
  25. char *name;
  26. /* mount and unmount file system */
  27. int (*mount) (struct dfs_filesystem* fs, unsigned long rwflag, const void* data);
  28. int (*unmount) (struct dfs_filesystem* fs);
  29. /* make a file system */
  30. int (*mkfs) (const char* device_name);
  31. int (*statfs) (struct dfs_filesystem* fs, struct _statfs *buf);
  32. int (*open) (struct dfs_fd* fd);
  33. int (*close) (struct dfs_fd* fd);
  34. int (*ioctl) (struct dfs_fd* fd, int cmd, void *args);
  35. int (*read) (struct dfs_fd* fd, void* buf, rt_size_t count);
  36. int (*write) (struct dfs_fd* fd, const void* buf, rt_size_t count);
  37. int (*flush) (struct dfs_fd* fd);
  38. int (*lseek) (struct dfs_fd* fd, rt_off_t offset);
  39. int (*getdents) (struct dfs_fd* fd, struct _dirent* dirp, rt_uint32_t count);
  40. int (*unlink) (struct dfs_filesystem* fs, const char* pathname);
  41. int (*stat) (struct dfs_filesystem* fs, const char* filename, struct _stat* buf);
  42. int (*rename) (struct dfs_filesystem* fs, const char* oldpath, const char* newpath);
  43. };
  44. /* Mounted file system */
  45. struct dfs_filesystem
  46. {
  47. rt_device_t dev_id; /* Attached device */
  48. char* path; /* File system mount point */
  49. const struct dfs_filesystem_operation* ops; /* Operations for file system type */
  50. void *data; /* Specific file system data */
  51. };
  52. /* file system partition table */
  53. struct dfs_partition
  54. {
  55. rt_uint8_t type; /* file system type */
  56. rt_off_t offset; /* partition start offset */
  57. rt_size_t size; /* partition size */
  58. rt_sem_t lock;
  59. };
  60. int dfs_register(const struct dfs_filesystem_operation* ops);
  61. struct dfs_filesystem* dfs_filesystem_lookup(const char *path);
  62. rt_err_t dfs_filesystem_get_partition(struct dfs_partition* part, rt_uint8_t* buf, rt_uint32_t pindex);
  63. int dfs_mount(const char* device_name, const char* path,
  64. const char* filesystemtype, rt_uint32_t rwflag, const
  65. void* data);
  66. int dfs_unmount(const char *specialfile);
  67. /* extern variable */
  68. extern const struct dfs_filesystem_operation* filesystem_operation_table[];
  69. extern struct dfs_filesystem filesystem_table[];
  70. extern char working_directory[];
  71. void dfs_lock(void);
  72. void dfs_unlock(void);
  73. int dfs_statfs(const char* path, struct _statfs* buffer);
  74. #endif