dirent.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. /****************************************************************************
  2. * include/nuttx/fs/dirent.h
  3. *
  4. * Copyright (C) 2007, 2009, 2011-2013, 2015, 2018 Gregory Nutt. All
  5. * rights reserved.
  6. * Author: Gregory Nutt <gnutt@nuttx.org>
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in
  16. * the documentation and/or other materials provided with the
  17. * distribution.
  18. * 3. Neither the name NuttX nor the names of its contributors may be
  19. * used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  23. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  24. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  25. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  26. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  27. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  28. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  29. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  30. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  31. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  32. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  33. * POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. ****************************************************************************/
  36. #ifndef __INCLUDE_NUTTX_FS_DIRENT_H
  37. #define __INCLUDE_NUTTX_FS_DIRENT_H
  38. /****************************************************************************
  39. * Included Files
  40. ****************************************************************************/
  41. #include <nuttx/config.h>
  42. #include <sys/types.h>
  43. #include <stdint.h>
  44. #include <dirent.h>
  45. #include <nuttx/fs/fs.h>
  46. /****************************************************************************
  47. * Pre-processor Definitions
  48. ****************************************************************************/
  49. #ifdef CONFIG_NFS
  50. # define DIRENT_NFS_MAXHANDLE 64 /* Maximum length of an NFSv3 file handle */
  51. # define DIRENT_NFS_VERFLEN 8 /* Length of the copy verifier */
  52. #endif
  53. /****************************************************************************
  54. * Public Types
  55. ****************************************************************************/
  56. /* The internal representation of type DIR is just a container for an inode
  57. * reference, a position, a dirent structure, and file-system-specific
  58. * information.
  59. *
  60. * For the root pseudo-file system, we need retain only the 'next' inode
  61. * need for the next readdir() operation. We hold a reference on this
  62. * inode so we know that it will persist until closedir is called.
  63. */
  64. struct fs_pseudodir_s
  65. {
  66. struct inode *fd_next; /* The inode for the next call to readdir() */
  67. };
  68. #ifndef CONFIG_DISABLE_MOUNTPOINT
  69. #ifdef CONFIG_FS_FAT
  70. /* For fat, we need to return the start cluster, current cluster, current
  71. * sector and current directory index.
  72. */
  73. struct fs_fatdir_s
  74. {
  75. off_t fd_startcluster; /* Start cluster number of the directory */
  76. off_t fd_currcluster; /* Current cluster number being read */
  77. off_t fd_currsector; /* Current sector being read */
  78. unsigned int fd_index; /* Current index of the directory entry to read */
  79. };
  80. #endif /* CONFIG_FS_FAT */
  81. #ifdef CONFIG_FS_ROMFS
  82. /* For ROMFS, we need to return the offset to the current and start positions
  83. * of the directory entry being read
  84. */
  85. struct fs_romfsdir_s
  86. {
  87. off_t fr_firstoffset; /* Offset to the first entry in the directory */
  88. off_t fr_curroffset; /* Current offset into the directory contents */
  89. };
  90. #endif /* CONFIG_FS_ROMFS */
  91. #ifdef CONFIG_FS_CROMFS
  92. /* For CROMFS, we need to return the next compressed node to be examined. */
  93. struct fs_cromfsdir_s
  94. {
  95. uint32_t cr_firstoffset; /* Offset to the first entry in the directory */
  96. uint32_t cr_curroffset; /* Current offset into the directory contents */
  97. };
  98. #endif /* CONFIG_FS_CROMFS */
  99. #ifdef CONFIG_FS_TMPFS
  100. /* For TMPFS, we need the directory object and an index into the directory
  101. * entries.
  102. */
  103. struct tmpfs_directory_s; /* Forward reference */
  104. struct fs_tmpfsdir_s
  105. {
  106. FAR struct tmpfs_directory_s *tf_tdo; /* Directory being enumerated */
  107. unsigned int tf_index; /* Directory index */
  108. };
  109. #endif /* CONFIG_FS_TMPFS */
  110. #ifdef CONFIG_FS_BINFS
  111. /* The apps/ pseudo bin/ directory. The state value is simply an index */
  112. struct fs_binfsdir_s
  113. {
  114. unsigned int fb_index; /* Index to the next named entry point */
  115. };
  116. #endif
  117. #ifdef CONFIG_FS_NXFFS
  118. /* NXFFS is the tiny NuttX wear-leveling FLASH file system. The state value is
  119. * the offset in FLASH memory to the next inode entry.
  120. */
  121. struct fs_nxffsdir_s
  122. {
  123. off_t nx_offset; /* Offset to the next inode */
  124. };
  125. #endif
  126. #ifdef CONFIG_NFS
  127. /* The NFS client file system */
  128. struct nfsdir_s
  129. {
  130. uint8_t nfs_fhsize; /* Length of the file handle */
  131. uint8_t nfs_fhandle[DIRENT_NFS_MAXHANDLE]; /* File handle (max size allocated) */
  132. uint8_t nfs_verifier[DIRENT_NFS_VERFLEN]; /* Cookie verifier */
  133. uint32_t nfs_cookie[2]; /* Cookie */
  134. };
  135. #endif
  136. #ifdef CONFIG_FS_SMARTFS
  137. /* SMARTFS is the Sector Mapped Allocation for Really Tiny FLASH filesystem.
  138. * it is designed to use small sectors on small serial FLASH devices, using
  139. * minimal RAM footprint.
  140. */
  141. struct fs_smartfsdir_s
  142. {
  143. uint16_t fs_firstsector; /* First sector of directory list */
  144. uint16_t fs_currsector; /* Current sector of directory list */
  145. uint16_t fs_curroffset; /* Current offset within current sector */
  146. };
  147. #endif
  148. #ifdef CONFIG_FS_SPIFFS
  149. /* SPIFFS is an SPI-oriented FLASH file system originally by Peter Andersson */
  150. struct fs_spiffsdir_s
  151. {
  152. int16_t block; /* Current block */
  153. int entry; /* Current entry */
  154. };
  155. #endif
  156. #ifdef CONFIG_FS_UNIONFS
  157. /* The Union File System can be used to merge to different mountpoints so
  158. * that they appear as a single merged directory.
  159. */
  160. struct fs_dirent_s; /* Forward reference */
  161. struct fs_unionfsdir_s
  162. {
  163. uint8_t fu_ndx; /* Index of file system being enumerated */
  164. bool fu_eod; /* True: At end of directory */
  165. bool fu_prefix[2]; /* True: Fake directory in prefix */
  166. FAR char *fu_relpath; /* Path being enumerated */
  167. FAR struct fs_dirent_s *fu_lower[2]; /* dirent struct used by contained file system */
  168. };
  169. #endif
  170. #ifdef CONFIG_FS_USERFS
  171. /* The UserFS uses an opaque representation since the actual userspace representation
  172. * of the directory state structure is unknowable.
  173. */
  174. struct fs_userfsdir_s
  175. {
  176. FAR void *fs_dir; /* Opaque pointer to UserFS DIR */
  177. };
  178. #endif
  179. #ifdef CONFIG_FS_HOSTFS
  180. /* HOSTFS provides mapping to directories on the host machine in the
  181. * sim environment.
  182. */
  183. struct fs_hostfsdir_s
  184. {
  185. FAR void *fs_dir; /* Opaque pointer to host DIR */
  186. };
  187. #endif
  188. #endif /* CONFIG_DISABLE_MOUNTPOINT */
  189. struct fs_dirent_s
  190. {
  191. /* This is the node that was opened by opendir. The type of the inode
  192. * determines the way that the readdir() operations are performed. For the
  193. * pseudo root pseudo-file system, it is also used to support rewind.
  194. *
  195. * We hold a reference on this inode so we know that it will persist until
  196. * closedir() is called (although inodes linked to this inode may change).
  197. */
  198. struct inode *fd_root;
  199. /* At present, only mountpoints require special handling flags */
  200. #ifndef CONFIG_DISABLE_MOUNTPOINT
  201. unsigned int fd_flags;
  202. #endif
  203. /* This keeps track of the current directory position for telldir */
  204. off_t fd_position;
  205. /* Retained control information depends on the type of file system that
  206. * provides the mountpoint. Ideally this information should
  207. * be hidden behind an opaque, file-system-dependent void *, but we put
  208. * the private definitions in line here for now to reduce allocations.
  209. */
  210. union
  211. {
  212. /* Private data used by the built-in pseudo-file system */
  213. struct fs_pseudodir_s pseudo;
  214. /* Private data used by other file systems */
  215. #ifndef CONFIG_DISABLE_MOUNTPOINT
  216. #ifdef CONFIG_FS_FAT
  217. struct fs_fatdir_s fat;
  218. #endif
  219. #ifdef CONFIG_FS_ROMFS
  220. struct fs_romfsdir_s romfs;
  221. #endif
  222. #ifdef CONFIG_FS_CROMFS
  223. struct fs_cromfsdir_s cromfs;
  224. #endif
  225. #ifdef CONFIG_FS_TMPFS
  226. struct fs_tmpfsdir_s tmpfs;
  227. #endif
  228. #ifdef CONFIG_FS_BINFS
  229. struct fs_binfsdir_s binfs;
  230. #endif
  231. #ifdef CONFIG_FS_PROCFS
  232. FAR void *procfs;
  233. #endif
  234. #ifdef CONFIG_FS_NXFFS
  235. struct fs_nxffsdir_s nxffs;
  236. #endif
  237. #ifdef CONFIG_NFS
  238. struct nfsdir_s nfs;
  239. #endif
  240. #ifdef CONFIG_FS_SMARTFS
  241. struct fs_smartfsdir_s smartfs;
  242. #endif
  243. #ifdef CONFIG_FS_SPIFFS
  244. struct fs_spiffsdir_s spiffs;
  245. #endif
  246. #ifdef CONFIG_FS_LITTLEFS
  247. FAR void *littlefs;
  248. #endif
  249. #ifdef CONFIG_FS_UNIONFS
  250. struct fs_unionfsdir_s unionfs;
  251. #endif
  252. #ifdef CONFIG_FS_USERFS
  253. struct fs_userfsdir_s userfs;
  254. #endif
  255. #ifdef CONFIG_FS_HOSTFS
  256. struct fs_hostfsdir_s hostfs;
  257. #endif
  258. #endif /* !CONFIG_DISABLE_MOUNTPOINT */
  259. } u;
  260. /* In any event, this the actual struct dirent that is returned by readdir */
  261. struct dirent fd_dir; /* Populated when readdir is called */
  262. };
  263. /****************************************************************************
  264. * Public Data
  265. ****************************************************************************/
  266. /****************************************************************************
  267. * Public Function Prototypes
  268. ****************************************************************************/
  269. #undef EXTERN
  270. #if defined(__cplusplus)
  271. #define EXTERN extern "C"
  272. extern "C"
  273. {
  274. #else
  275. #define EXTERN extern
  276. #endif
  277. #undef EXTERN
  278. #if defined(__cplusplus)
  279. }
  280. #endif
  281. #endif /* __INCLUDE_NUTTX_FS_DIRENT_H */