phatdir.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. #ifndef FS_PHATDIR_H_
  2. #define FS_PHATDIR_H_
  3. /*
  4. * Copyright (C) 2005-2006 by egnite Software GmbH. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the copyright holders nor the names of
  16. * contributors may be used to endorse or promote products derived
  17. * from this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  22. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  23. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  24. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  25. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  26. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  27. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  29. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. * SUCH DAMAGE.
  31. *
  32. * For additional information see http://www.ethernut.de/
  33. */
  34. /*!
  35. * \file fs/phatdir.h
  36. * \brief PHAT file system.
  37. *
  38. * \verbatim
  39. *
  40. * $Log$
  41. * Revision 1.4 2008/08/11 07:00:19 haraldkipp
  42. * BSD types replaced by stdint types (feature request #1282721).
  43. *
  44. * Revision 1.3 2006/10/08 16:42:56 haraldkipp
  45. * Not optimal, but simple and reliable exclusive access implemented.
  46. * Fixes bug #1486539. Furthermore, bug #1567790, which had been rejected,
  47. * had been reported correctly and is now fixed.
  48. *
  49. * Revision 1.2 2006/06/18 16:41:55 haraldkipp
  50. * Support for long filenames (VFAT) added.
  51. * New function PhatDirReleaseChain() simplifies code.
  52. * Static function PhatDirOpenParentPath() replaced by global
  53. * PhatDirOpenParent().
  54. * Added const attribute to path parameter of PhatDirOpen().
  55. *
  56. * Revision 1.1 2006/01/05 16:32:52 haraldkipp
  57. * First check-in.
  58. *
  59. *
  60. * \endverbatim
  61. */
  62. #include <dirent.h>
  63. #include <sys/stat.h>
  64. /*!
  65. * \addtogroup xgPhatDir
  66. */
  67. /*@{*/
  68. /*!
  69. * \brief Maximum length of a base file name.
  70. */
  71. #ifndef PHAT_MAX_NAMELEN
  72. #define PHAT_MAX_NAMELEN 255
  73. #endif
  74. #define PHAT_REM_DIRENT 0xE5
  75. #define PHAT_REM_NAMENT 0x05
  76. /*!
  77. * \brief Structure of a directory entry.
  78. *
  79. * Once created, this structure will never change if it points
  80. * to another directory. Except if the entry is removed.
  81. */
  82. typedef struct NUT_PACKED_TYPE _PHATDIRENT {
  83. /*! \brief File name, padded with blanks. */
  84. uint8_t dent_name[11];
  85. /*! \brief File attributes.
  86. *
  87. * See PHAT_FATTR_ flags.
  88. */
  89. uint8_t dent_attr;
  90. /*! \brief Reserved byte, possibly used by NT. */
  91. uint8_t dent_rsvdnt;
  92. /*! \brief Hundredth of seconds of file creation time. */
  93. uint8_t dent_ctsecs;
  94. /*! \brief File creation time. */
  95. uint16_t dent_ctime;
  96. /*! \brief File creation date. */
  97. uint16_t dent_cdate;
  98. /*! \brief Last file access date. */
  99. uint16_t dent_adate;
  100. /*! \brief High bytes of first cluster of this file.
  101. *
  102. * If used with the double dot entry, dent_clusthi and dent_clust
  103. * must be zero if the entry points to the root directory.
  104. *
  105. * The same is true when pointing to a normal file with zero
  106. * length.
  107. */
  108. uint16_t dent_clusthi;
  109. /*! \brief Last file modification time. */
  110. uint16_t dent_mtime;
  111. /*! \brief Last file modification date. */
  112. uint16_t dent_mdate;
  113. /*! \brief First cluster used.
  114. *
  115. * This is zero for empty files.
  116. */
  117. uint16_t dent_clust;
  118. /*! \brief Size of the file in bytes.
  119. *
  120. * For directories, this is always zero.
  121. */
  122. uint32_t dent_fsize;
  123. } PHATDIRENT;
  124. /*!
  125. * \brief Structure of an extended directory entry.
  126. *
  127. * Used for long filenames.
  128. */
  129. typedef struct NUT_PACKED_TYPE _PHATXDIRENT {
  130. /*! \brief Sequence number. */
  131. uint8_t xdent_seq;
  132. /*! \brief Unicode characters 1-5. */
  133. uint16_t xdent_uname_1_5[5];
  134. /*! \brief Attribut. */
  135. uint8_t xdent_attr;
  136. /*! \brief Type. */
  137. uint8_t xdent_rsvd;
  138. /*! \brief Checksum. */
  139. uint8_t xdent_cks;
  140. /*! \brief Unicode characters 6-11. */
  141. uint16_t xdent_uname_6_11[6];
  142. /*! \brief Starting cluster. */
  143. uint16_t xdent_clust;
  144. /*! \brief Unicode characters 12-13. */
  145. uint16_t xdent_uname_12_13[2];
  146. } PHATXDIRENT;
  147. typedef struct _PHATFIND {
  148. PHATDIRENT phfind_ent;
  149. uint32_t phfind_pos;
  150. /*! Number of entries used for the long filename. */
  151. int phfind_xcnt;
  152. char phfind_name[PHAT_MAX_NAMELEN];
  153. } PHATFIND;
  154. /*@}*/
  155. extern int PhatDirEntryCreate(NUTFILE * ndp, const char *name, int acc, PHATDIRENT * dirent);
  156. extern int PhatDirEntryUpdate(NUTFILE * ndp);
  157. extern int PhatDirReleaseChain(NUTDEVICE * dev, PHATDIRENT * dent);
  158. extern int PhatDirDelEntry(NUTDEVICE * dev, const char *path, uint32_t flags);
  159. extern int PhatDirRenameEntry(NUTDEVICE * dev, const char *old_path, const char *new_path);
  160. extern NUTFILE *PhatDirOpen(NUTDEVICE * dev, const char *dpath);
  161. extern NUTFILE *PhatDirOpenParent(NUTDEVICE * dev, const char *path, const char **basename);
  162. extern int PhatDirEntryFind(NUTFILE * nfp, const char *spec, uint32_t flags, PHATFIND * srch);
  163. extern int PhatDirRead(DIR * dir);
  164. extern int PhatDirCreate(NUTDEVICE * dev, char *path);
  165. extern int PhatDirRemove(NUTDEVICE * dev, char *path);
  166. extern int PhatDirEntryStatus(NUTDEVICE * dev, const char *path, struct stat *s);
  167. #endif