dirent_fs.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /****************************************************************************
  2. * include/fs/dirent.h
  3. *
  4. * Copyright (C) 2007, 2009, 2011-2013 Gregory Nutt. All rights reserved.
  5. * Copyright (c) <2014-2015>, <Huawei Technologies Co., Ltd>
  6. * All rights reserved.
  7. *
  8. * Author: Gregory Nutt <gnutt@nuttx.org>
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. *
  14. * 1. Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions and the following disclaimer.
  16. * 2. Redistributions in binary form must reproduce the above copyright
  17. * notice, this list of conditions and the following disclaimer in
  18. * the documentation and/or other materials provided with the
  19. * distribution.
  20. * 3. Neither the name NuttX nor the names of its contributors may be
  21. * used to endorse or promote products derived from this software
  22. * without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  25. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  26. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  27. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  28. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  29. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  30. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  31. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  32. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  33. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  34. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  35. * POSSIBILITY OF SUCH DAMAGE.
  36. *
  37. ****************************************************************************/
  38. /****************************************************************************
  39. * Notice of Export Control Law
  40. * ===============================================
  41. * Huawei LiteOS may be subject to applicable export control laws and regulations,
  42. * which might include those applicable to Huawei LiteOS of U.S. and the country in
  43. * which you are located.
  44. * Import, export and usage of Huawei LiteOS in any manner by you shall be in
  45. * compliance with such applicable export control laws and regulations.
  46. ****************************************************************************/
  47. #ifndef __INCLUDE_FS_DIRENT_H
  48. #define __INCLUDE_FS_DIRENT_H
  49. /****************************************************************************
  50. * Included Files
  51. ****************************************************************************/
  52. #include "vfs_config.h"
  53. #include "sys/types.h"
  54. #include "stdint.h"
  55. #include "dirent.h"
  56. #include "fs/fs.h"
  57. #ifdef __cplusplus
  58. #if __cplusplus
  59. extern "C" {
  60. #endif /* __cplusplus */
  61. #endif /* __cplusplus */
  62. /****************************************************************************
  63. * Public Types
  64. ****************************************************************************/
  65. /* The internal representation of type DIR is just a container for an inode
  66. * reference, a position, a dirent structure, and file-system-specific
  67. * information.
  68. *
  69. * For the root pseudo-file system, we need retain only the 'next' inode
  70. * need for the next readdir() operation. We hold a reference on this
  71. * inode so we know that it will persist until closedir is called.
  72. */
  73. struct fs_pseudodir_s
  74. {
  75. struct inode *fd_next; /* The inode for the next call to readdir() */
  76. };
  77. typedef void *fs_dir_s;
  78. #define DIRENT_MAGIC 0x11CBA828 /* Magic number to express the status of a dirent */
  79. struct fs_dirent_s
  80. {
  81. /* This is the node that was opened by opendir. The type of the inode
  82. * determines the way that the readdir() operations are performed. For the
  83. * pseudo root pseudo-file system, it is also used to support rewind.
  84. *
  85. * We hold a reference on this inode so we know that it will persist until
  86. * closedir() is called (although inodes linked to this inode may change).
  87. */
  88. struct inode *fd_root;
  89. /* At present, only mountpoints require special handling flags */
  90. #ifndef CONFIG_DISABLE_MOUNTPOINT
  91. unsigned int fd_flags;
  92. #endif
  93. /* This keeps track of the current directory position for telldir */
  94. off_t fd_position;
  95. /* Retained control information depends on the type of file system that
  96. * provides is provides the mountpoint. Ideally this information should
  97. * be hidden behind an opaque, file-system-dependent void *, but we put
  98. * the private definitions in line here for now to reduce allocations.
  99. */
  100. struct
  101. {
  102. /* Private data used by the built-in pseudo-file system */
  103. struct fs_pseudodir_s pseudo;
  104. /* Private data used by other file systems */
  105. fs_dir_s fs_dir;
  106. } u;
  107. /* In any event, this the actual struct dirent that is returned by readdir */
  108. struct dirent fd_dir; /* Populated when readdir is called */
  109. int fd_status; /* Express the dirent is been opened or no */
  110. };
  111. /****************************************************************************
  112. * Global Variables
  113. ****************************************************************************/
  114. extern DIR *fdopendir(int);
  115. #ifdef __cplusplus
  116. #if __cplusplus
  117. }
  118. #endif /* __cplusplus */
  119. #endif /* __cplusplus */
  120. #endif /* __INCLUDE_FS_DIRENT_H */