dfs_fs.h 2.8 KB

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