phatfs.h 5.0 KB

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