dfs_def.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. /*
  2. * File : dfs_def.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. * 2004-10-01 Beranard The first version.
  13. * 2004-10-14 Beranard Clean up the code.
  14. * 2005-01-22 Beranard Clean up the code, port to MinGW
  15. */
  16. #ifndef __DFS_DEF_H__
  17. #define __DFS_DEF_H__
  18. #include <rtthread.h>
  19. #include <dfs_config.h>
  20. #ifndef __D_FS__
  21. #define __D_FS__
  22. #endif
  23. #define DEVICE_GETGEOME 0
  24. #define DEVICE_GETINFO 1
  25. #define DEVICE_FORMAT 2
  26. #define DEVICE_CLEAN_SECTOR 3
  27. /* File flags */
  28. #define DFS_F_OPEN 0x01000000
  29. #define DFS_F_DIRECTORY 0x02000000
  30. #define DFS_F_EOF 0x04000000
  31. #define DFS_F_ERR 0x08000000
  32. #if defined(RT_USING_NEWLIB)
  33. #include <string.h>
  34. #include <sys/stat.h> /* used for struct stat */
  35. #include <sys/statfs.h> /* used for struct statfs */
  36. #include <sys/errno.h> /* used for error number */
  37. #include <sys/fcntl.h> /* used for operation flags */
  38. #include <sys/unistd.h> /* used for SEEK_SET/CUR/END */
  39. #include <dirent.h> /* used for struct dirent */
  40. /* Device error codes */
  41. #define DFS_STATUS_OK 0 /* no error */
  42. #define DFS_STATUS_ENOENT ENOENT /* No such file or directory */
  43. #define DFS_STATUS_EIO EIO /* I/O error */
  44. #define DFS_STATUS_ENXIO ENXIO /* No such device or address */
  45. #define DFS_STATUS_EBADF EBADF /* Bad file number */
  46. #define DFS_STATUS_EAGAIN EAGAIN /* Try again */
  47. #define DFS_STATUS_ENOMEM ENOMEM /* no memory */
  48. #define DFS_STATUS_EBUSY EBUSY /* Device or resource busy */
  49. #define DFS_STATUS_EEXIST EEXIST /* File exists */
  50. #define DFS_STATUS_EXDEV EXDEV /* Cross-device link */
  51. #define DFS_STATUS_ENODEV ENODEV /* No such device */
  52. #define DFS_STATUS_ENOTDIR ENOTDIR /* Not a directory */
  53. #define DFS_STATUS_EISDIR EISDIR /* Is a directory */
  54. #define DFS_STATUS_EINVAL EINVAL /* Invalid argument */
  55. #define DFS_STATUS_ENOSPC ENOSPC /* No space left on device */
  56. #define DFS_STATUS_EROFS EROFS /* Read-only file system */
  57. #define DFS_STATUS_ENOSYS ENOSYS /* Function not implemented */
  58. #define DFS_STATUS_ENOTEMPTY ENOTEMPTY /* Directory not empty */
  59. /* Operation flags */
  60. #define DFS_O_RDONLY O_RDONLY
  61. #define DFS_O_WRONLY O_WRONLY
  62. #define DFS_O_RDWR O_RDWR
  63. #define DFS_O_ACCMODE O_ACCMODE
  64. #define DFS_O_CREAT O_CREAT
  65. #define DFS_O_EXCL O_EXCL
  66. #define DFS_O_TRUNC O_TRUNC
  67. #define DFS_O_APPEND O_APPEND
  68. #define DFS_O_DIRECTORY O_DIRECTORY
  69. /* Seek flags */
  70. #define DFS_SEEK_SET SEEK_SET
  71. #define DFS_SEEK_CUR SEEK_CUR
  72. #define DFS_SEEK_END SEEK_END
  73. /* Stat codes */
  74. #define DFS_S_IFMT S_IFMT
  75. #define DFS_S_IFSOCK S_IFSOCK
  76. #define DFS_S_IFLNK S_IFLNK
  77. #define DFS_S_IFREG S_IFREG
  78. #define DFS_S_IFBLK S_IFBLK
  79. #define DFS_S_IFDIR S_IFDIR
  80. #define DFS_S_IFCHR S_IFCHR
  81. #define DFS_S_IFIFO S_IFIFO
  82. #define DFS_S_ISUID S_ISUID
  83. #define DFS_S_ISGID S_ISGID
  84. #define DFS_S_ISVTX S_ISVTX
  85. #define DFS_S_ISLNK(m) S_ISLNK(m)
  86. #define DFS_S_ISREG(m) S_ISREG(m)
  87. #define DFS_S_ISDIR(m) S_ISDIR(m)
  88. #define DFS_S_ISCHR(m) S_ISCHR(m)
  89. #define DFS_S_ISBLK(m) S_ISBLK(m)
  90. #define DFS_S_ISFIFO(m) S_ISFIFO(m)
  91. #define DFS_S_ISSOCK(m) S_ISSOCK(m)
  92. #define DFS_S_IRWXU S_IRWXU
  93. #define DFS_S_IRUSR S_IRUSR
  94. #define DFS_S_IWUSR S_IWUSR
  95. #define DFS_S_IXUSR S_IXUSR
  96. #define DFS_S_IRWXG S_IRWXG
  97. #define DFS_S_IRGRP S_IRGRP
  98. #define DFS_S_IWGRP S_IWGRP
  99. #define DFS_S_IXGRP S_IXGRP
  100. #define DFS_S_IRWXO S_IRWXO
  101. #define DFS_S_IROTH S_IROTH
  102. #define DFS_S_IWOTH S_IWOTH
  103. #define DFS_S_IXOTH S_IXOTH
  104. /* Dirent types */
  105. #define DFS_DT_UNKNOWN DT_UNKNOWN
  106. #define DFS_DT_REG DT_REG
  107. #define DFS_DT_DIR DT_DIR
  108. #else
  109. #ifdef RT_USING_MINILIBC
  110. #include <string.h>
  111. #else
  112. typedef long off_t;
  113. typedef int mode_t;
  114. #endif
  115. /* Device error codes */
  116. #define DFS_STATUS_OK 0 /* no error */
  117. #define DFS_STATUS_ENOENT 2 /* No such file or directory */
  118. #define DFS_STATUS_EIO 5 /* I/O error */
  119. #define DFS_STATUS_ENXIO 6 /* No such device or address */
  120. #define DFS_STATUS_EBADF 9 /* Bad file number */
  121. #define DFS_STATUS_EAGIAN 11 /* Try again */
  122. #define DFS_STATUS_ENOMEM 12 /* no memory */
  123. #define DFS_STATUS_EBUSY 16 /* Device or resource busy */
  124. #define DFS_STATUS_EEXIST 17 /* File exists */
  125. #define DFS_STATUS_EXDEV 18 /* Cross-device link */
  126. #define DFS_STATUS_ENODEV 19 /* No such device */
  127. #define DFS_STATUS_ENOTDIR 20 /* Not a directory */
  128. #define DFS_STATUS_EISDIR 21 /* Is a directory */
  129. #define DFS_STATUS_EINVAL 22 /* Invalid argument */
  130. #define DFS_STATUS_ENOSPC 28 /* No space left on device */
  131. #define DFS_STATUS_EROFS 30 /* Read-only file system */
  132. #define DFS_STATUS_ENOSYS 38 /* Function not implemented */
  133. #define DFS_STATUS_ENOTEMPTY 39 /* Directory not empty */
  134. /* Operation flags */
  135. #define DFS_O_RDONLY 0000000
  136. #define DFS_O_WRONLY 0000001
  137. #define DFS_O_RDWR 0000002
  138. #define DFS_O_ACCMODE 0000003
  139. #define DFS_O_CREAT 0000100
  140. #define DFS_O_EXCL 0000200
  141. #define DFS_O_TRUNC 0001000
  142. #define DFS_O_APPEND 0002000
  143. #define DFS_O_DIRECTORY 0200000
  144. /* File flags */
  145. #define DFS_F_OPEN 0x01000000
  146. #define DFS_F_DIRECTORY 0x02000000
  147. #define DFS_F_EOF 0x04000000
  148. #define DFS_F_ERR 0x08000000
  149. /* Seek flags */
  150. #define DFS_SEEK_SET 0
  151. #define DFS_SEEK_CUR 1
  152. #define DFS_SEEK_END 2
  153. /* Stat codes */
  154. #define DFS_S_IFMT 00170000
  155. #define DFS_S_IFSOCK 0140000
  156. #define DFS_S_IFLNK 0120000
  157. #define DFS_S_IFREG 0100000
  158. #define DFS_S_IFBLK 0060000
  159. #define DFS_S_IFDIR 0040000
  160. #define DFS_S_IFCHR 0020000
  161. #define DFS_S_IFIFO 0010000
  162. #define DFS_S_ISUID 0004000
  163. #define DFS_S_ISGID 0002000
  164. #define DFS_S_ISVTX 0001000
  165. #define DFS_S_ISLNK(m) (((m) & DFS_S_IFMT) == DFS_S_IFLNK)
  166. #define DFS_S_ISREG(m) (((m) & DFS_S_IFMT) == DFS_S_IFREG)
  167. #define DFS_S_ISDIR(m) (((m) & DFS_S_IFMT) == DFS_S_IFDIR)
  168. #define DFS_S_ISCHR(m) (((m) & DFS_S_IFMT) == DFS_S_IFCHR)
  169. #define DFS_S_ISBLK(m) (((m) & DFS_S_IFMT) == DFS_S_IFBLK)
  170. #define DFS_S_ISFIFO(m) (((m) & DFS_S_IFMT) == DFS_S_IFIFO)
  171. #define DFS_S_ISSOCK(m) (((m) & DFS_S_IFMT) == DFS_S_IFSOCK)
  172. #define DFS_S_IRWXU 00700
  173. #define DFS_S_IRUSR 00400
  174. #define DFS_S_IWUSR 00200
  175. #define DFS_S_IXUSR 00100
  176. #define DFS_S_IRWXG 00070
  177. #define DFS_S_IRGRP 00040
  178. #define DFS_S_IWGRP 00020
  179. #define DFS_S_IXGRP 00010
  180. #define DFS_S_IRWXO 00007
  181. #define DFS_S_IROTH 00004
  182. #define DFS_S_IWOTH 00002
  183. #define DFS_S_IXOTH 00001
  184. struct stat
  185. {
  186. rt_device_t st_dev;
  187. rt_uint16_t st_mode;
  188. rt_uint32_t st_size;
  189. rt_time_t st_mtime;
  190. rt_uint32_t st_blksize;
  191. };
  192. struct statfs
  193. {
  194. rt_size_t f_bsize; /* block size */
  195. rt_size_t f_blocks; /* total data blocks in file system */
  196. rt_size_t f_bfree; /* free blocks in file system */
  197. };
  198. /* File types */
  199. #define FT_REGULAR 0 /* regular file */
  200. #define FT_SOCKET 1 /* socket file */
  201. #define FT_DIRECTORY 2 /* directory */
  202. #define FT_USER 3 /* user defined */
  203. /* Dirent types */
  204. #define DFS_DT_UNKNOWN 0x00
  205. #define DFS_DT_REG 0x01
  206. #define DFS_DT_DIR 0x02
  207. struct dirent
  208. {
  209. rt_uint8_t d_type; /* The type of the file */
  210. rt_uint8_t d_namlen; /* The length of the not including the terminating null file name */
  211. rt_uint16_t d_reclen; /* length of this record */
  212. char d_name[DFS_PATH_MAX]; /* The null-terminated file name */
  213. };
  214. #endif
  215. /* file descriptor */
  216. struct dfs_fd
  217. {
  218. char* path; /* Name (below mount point) */
  219. int type; /* Type (regular or socket) */
  220. int ref_count; /* Descriptor reference count */
  221. struct dfs_filesystem* fs; /* Resident file system */
  222. rt_uint32_t flags; /* Descriptor flags */
  223. rt_size_t size; /* Size in bytes */
  224. rt_off_t pos; /* Current file position */
  225. void *data; /* Specific file system data */
  226. };
  227. #endif