phatdir.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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 EGNITE SOFTWARE GMBH 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 EGNITE
  23. * SOFTWARE GMBH 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: phatdir.h,v $
  41. * Revision 1.3 2006/10/08 16:42:56 haraldkipp
  42. * Not optimal, but simple and reliable exclusive access implemented.
  43. * Fixes bug #1486539. Furthermore, bug #1567790, which had been rejected,
  44. * had been reported correctly and is now fixed.
  45. *
  46. * Revision 1.2 2006/06/18 16:41:55 haraldkipp
  47. * Support for long filenames (VFAT) added.
  48. * New function PhatDirReleaseChain() simplifies code.
  49. * Static function PhatDirOpenParentPath() replaced by global
  50. * PhatDirOpenParent().
  51. * Added const attribute to path parameter of PhatDirOpen().
  52. *
  53. * Revision 1.1 2006/01/05 16:32:52 haraldkipp
  54. * First check-in.
  55. *
  56. *
  57. * \endverbatim
  58. */
  59. #include <dirent.h>
  60. #include <sys/stat.h>
  61. /*!
  62. * \addtogroup xgPhatDir
  63. */
  64. /*@{*/
  65. /*!
  66. * \brief Maximum length of a base file name.
  67. */
  68. #ifndef PHAT_MAX_NAMELEN
  69. #define PHAT_MAX_NAMELEN 255
  70. #endif
  71. #define PHAT_REM_DIRENT 0xE5
  72. #define PHAT_REM_NAMENT 0x05
  73. /*!
  74. * \brief Structure of a directory entry.
  75. *
  76. * Once created, this structure will never change if it points
  77. * to another directory. Except if the entry is removed.
  78. */
  79. typedef struct __attribute__ ((packed)) _PHATDIRENT {
  80. /*! \brief File name, padded with blanks. */
  81. u_char dent_name[11];
  82. /*! \brief File attributes.
  83. *
  84. * See PHAT_FATTR_ flags.
  85. */
  86. u_char dent_attr;
  87. /*! \brief Reserved byte, possibly used by NT. */
  88. u_char dent_rsvdnt;
  89. /*! \brief Hundredth of seconds of file creation time. */
  90. u_char dent_ctsecs;
  91. /*! \brief File creation time. */
  92. u_short dent_ctime;
  93. /*! \brief File creation date. */
  94. u_short dent_cdate;
  95. /*! \brief Last file access date. */
  96. u_short dent_adate;
  97. /*! \brief High bytes of first cluster of this file.
  98. *
  99. * If used with the double dot entry, dent_clusthi and dent_clust
  100. * must be zero if the entry points to the root directory.
  101. *
  102. * The same is true when pointing to a normal file with zero
  103. * length.
  104. */
  105. u_short dent_clusthi;
  106. /*! \brief Last file modification time. */
  107. u_short dent_mtime;
  108. /*! \brief Last file modification date. */
  109. u_short dent_mdate;
  110. /*! \brief First cluster used.
  111. *
  112. * This is zero for empty files.
  113. */
  114. u_short dent_clust;
  115. /*! \brief Size of the file in bytes.
  116. *
  117. * For directories, this is always zero.
  118. */
  119. u_long dent_fsize;
  120. } PHATDIRENT;
  121. /*!
  122. * \brief Structure of an extended directory entry.
  123. *
  124. * Used for long filenames.
  125. */
  126. typedef struct __attribute__ ((packed)) _PHATXDIRENT {
  127. /*! \brief Sequence number. */
  128. u_char xdent_seq;
  129. /*! \brief Unicode characters 1-5. */
  130. u_short xdent_uname_1_5[5];
  131. /*! \brief Attribut. */
  132. u_char xdent_attr;
  133. /*! \brief Type. */
  134. u_char xdent_rsvd;
  135. /*! \brief Checksum. */
  136. u_char xdent_cks;
  137. /*! \brief Unicode characters 6-11. */
  138. u_short xdent_uname_6_11[6];
  139. /*! \brief Starting cluster. */
  140. u_short xdent_clust;
  141. /*! \brief Unicode characters 12-13. */
  142. u_short xdent_uname_12_13[2];
  143. } PHATXDIRENT;
  144. typedef struct _PHATFIND {
  145. PHATDIRENT phfind_ent;
  146. u_long phfind_pos;
  147. /*! Number of entries used for the long filename. */
  148. int phfind_xcnt;
  149. char phfind_name[PHAT_MAX_NAMELEN];
  150. } PHATFIND;
  151. /*@}*/
  152. __BEGIN_DECLS
  153. /* Prototypes */
  154. extern int PhatDirEntryCreate(NUTFILE * ndp, CONST char *name, int acc, PHATDIRENT * dirent);
  155. extern int PhatDirEntryUpdate(NUTFILE * ndp);
  156. extern int PhatDirReleaseChain(NUTDEVICE * dev, PHATDIRENT * dent);
  157. extern int PhatDirDelEntry(NUTDEVICE * dev, CONST char *path, u_long flags);
  158. extern int PhatDirRenameEntry(NUTDEVICE * dev, CONST char *old_path, CONST char *new_path);
  159. extern NUTFILE *PhatDirOpen(NUTDEVICE * dev, CONST char *dpath);
  160. extern NUTFILE *PhatDirOpenParent(NUTDEVICE * dev, CONST char *path, CONST char **basename);
  161. extern int PhatDirEntryFind(NUTFILE * nfp, CONST char *spec, u_long flags, PHATFIND * srch);
  162. extern int PhatDirRead(DIR * dir);
  163. extern int PhatDirCreate(NUTDEVICE * dev, char *path);
  164. extern int PhatDirRemove(NUTDEVICE * dev, char *path);
  165. extern int PhatDirEntryStatus(NUTDEVICE * dev, CONST char *path, struct stat *s);
  166. __END_DECLS
  167. /* End of prototypes */
  168. #endif