dfs_fs.h 2.8 KB

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