phatfs.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. #ifndef FS_PHATFS_H_
  2. #define FS_PHATFS_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/phatfs.h
  36. * \brief PHAT file system.
  37. *
  38. * \verbatim
  39. *
  40. * $Log$
  41. * Revision 1.8 2009/01/17 11:26:47 haraldkipp
  42. * Getting rid of two remaining BSD types in favor of stdint.
  43. * Replaced 'u_int' by 'unsinged int' and 'uptr_t' by 'uintptr_t'.
  44. *
  45. * Revision 1.7 2008/08/11 07:00:19 haraldkipp
  46. * BSD types replaced by stdint types (feature request #1282721).
  47. *
  48. * Revision 1.6 2007/08/29 07:43:54 haraldkipp
  49. * Documentation updated and corrected.
  50. *
  51. * Revision 1.5 2006/10/08 16:42:56 haraldkipp
  52. * Not optimal, but simple and reliable exclusive access implemented.
  53. * Fixes bug #1486539. Furthermore, bug #1567790, which had been rejected,
  54. * had been reported correctly and is now fixed.
  55. *
  56. * Revision 1.4 2006/06/18 16:42:50 haraldkipp
  57. * Support for long filenames (VFAT) added.
  58. *
  59. * Revision 1.3 2006/05/15 11:48:38 haraldkipp
  60. * Added a second PHAT file system instance.
  61. *
  62. * Revision 1.2 2006/01/22 17:44:20 haraldkipp
  63. * ICCAVR failed to find local header files.
  64. *
  65. * Revision 1.1 2006/01/05 16:32:57 haraldkipp
  66. * First check-in.
  67. *
  68. *
  69. * \endverbatim
  70. */
  71. #include <sys/types.h>
  72. #include <sys/file.h>
  73. #include <sys/device.h>
  74. #include <fs/phatdir.h>
  75. /*!
  76. * \addtogroup xgPhatFs
  77. */
  78. /*@{*/
  79. /*!
  80. * \brief PHAT file descriptor structure.
  81. */
  82. typedef struct _PHATFILE {
  83. /*! \brief Current position into the file. */
  84. uint32_t f_pos;
  85. /*! \brief Current cluster. */
  86. uint32_t f_clust;
  87. /*! \brief Sector within the current cluster. */
  88. uint32_t f_clust_pos;
  89. /*! \brief Position within the sector. */
  90. uint32_t f_sect_pos;
  91. /*! \brief Previous cluster used, */
  92. uint32_t f_clust_prv;
  93. /*! \brief File open mode flags. */
  94. uint32_t f_mode;
  95. /*! \brief Directory entry of this file. */
  96. PHATDIRENT f_dirent;
  97. /*! \brief Sector of the directory entry.
  98. *
  99. * For the root directory this value is zero, because the root
  100. * doesn't have any entry in another directory.
  101. */
  102. uint32_t f_de_sect;
  103. /*! \brief Offset into the sector containing the directory entry. */
  104. uint32_t f_de_offs;
  105. /*! \brief Directory entry change marker. */
  106. unsigned int f_de_dirty;
  107. /*! \brief First cluster of the parent directory, low word.
  108. *
  109. * Our directory entry is located in this cluster.
  110. */
  111. uint16_t f_pde_clust;
  112. /*! \brief First cluster of the parent directory, high word. */
  113. uint16_t f_pde_clusthi;
  114. } PHATFILE;
  115. /*! \brief Marks end of cluster chain. */
  116. #define PHATEOC 0x0FFFFFF8
  117. /*!
  118. * \name File attributes.
  119. */
  120. /*@{*/
  121. /*! Read only file. */
  122. #define PHAT_FATTR_RDONLY 0x01
  123. /*! Hidden file. */
  124. #define PHAT_FATTR_HIDDEN 0x02
  125. /*! System file. */
  126. #define PHAT_FATTR_SYSTEM 0x04
  127. /*! No file, but a volume label. */
  128. #define PHAT_FATTR_VOLID 0x08
  129. /*! File contains a subdirectory. */
  130. #define PHAT_FATTR_DIR 0x10
  131. /*! File is not archived. This flag will be set when the file is created
  132. * or modified.
  133. */
  134. #define PHAT_FATTR_ARCHIV 0x20
  135. /*! Long filename entry. */
  136. #define PHAT_FATTR_LFN (PHAT_FATTR_RDONLY | PHAT_FATTR_HIDDEN | PHAT_FATTR_SYSTEM | PHAT_FATTR_VOLID)
  137. /*! Only these flags are allowed for files and directories. */
  138. #define PHAT_FATTR_FILEMASK 0x37
  139. /*@}*/
  140. /*@}*/
  141. #include <fs/phat12.h>
  142. #include <fs/phat16.h>
  143. #include <fs/phat32.h>
  144. extern NUTDEVICE devPhat0;
  145. extern NUTDEVICE devPhat1;
  146. extern uint32_t AllocFirstCluster(NUTFILE * nfp);
  147. extern NUTFILE *PhatFileOpen(NUTDEVICE * dev, const char *path, int mode, int acc);
  148. extern int PhatFileClose(NUTFILE * nfp);
  149. extern int PhatFileWrite(NUTFILE * nfp, const void *buffer, int len);
  150. #ifdef __HARVARD_ARCH__
  151. extern int PhatFileWrite_P(NUTFILE * nfp, PGM_P buffer, int len);
  152. #endif
  153. extern int PhatFileRead(NUTFILE * nfp, void *buffer, int size);
  154. #endif