phatvol.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. #ifndef FS_PHATVOL_H_
  2. #define FS_PHATVOL_H_
  3. /*
  4. * <MFS> Modified for Streamit
  5. * added provison to avoid counting free clusters untill the first 'write' action
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in the
  15. * documentation and/or other materials provided with the distribution.
  16. * 3. Neither the name of the copyright holders nor the names of
  17. * contributors may be used to endorse or promote products derived
  18. * from this software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH AND CONTRIBUTORS
  21. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  23. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EGNITE
  24. * SOFTWARE GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  25. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  26. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  27. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  28. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  29. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  30. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31. * SUCH DAMAGE.
  32. *
  33. * For additional information see http://www.ethernut.de/
  34. */
  35. /*!
  36. * \file fs/phatvol.h
  37. * \brief PHAT file system.
  38. *
  39. * \verbatim
  40. *
  41. * $Log: phatvol.h,v $
  42. * Revision 1.4 2006/10/08 16:42:56 haraldkipp
  43. * Not optimal, but simple and reliable exclusive access implemented.
  44. * Fixes bug #1486539. Furthermore, bug #1567790, which had been rejected,
  45. * had been reported correctly and is now fixed.
  46. *
  47. * Revision 1.3 2006/07/11 12:20:19 haraldkipp
  48. * PHAT file system failed when accessed from multiple threads. A mutual
  49. * exclusion semaphore fixes this.
  50. *
  51. * Revision 1.2 2006/02/23 15:47:18 haraldkipp
  52. * PHAT file system now supports configurable number of sector buffers.
  53. *
  54. * Revision 1.1 2006/01/05 16:33:10 haraldkipp
  55. * First check-in.
  56. *
  57. *
  58. * \endverbatim
  59. */
  60. #include <cfg/fs.h>
  61. #include <sys/types.h>
  62. #include <sys/file.h>
  63. #include <sys/device.h>
  64. /*!
  65. * \addtogroup xgPhatVol
  66. */
  67. /*@{*/
  68. /*!
  69. * \brief Volume boot record.
  70. */
  71. typedef struct __attribute__ ((packed)) _PHATVBR {
  72. /*! \brief Jump instruction, contains E9xxxx or EBxx90. */
  73. u_char boot_jump[3];
  74. /*! \brief OEM name and version. */
  75. u_char boot_oem[8];
  76. /*! \brief Bytes per sector.
  77. *
  78. * The BIOS parameter block starts here.
  79. */
  80. u_short bios_sectsz;
  81. /*! \brief Sectors per cluster. */
  82. u_char bios_clustsz;
  83. /*! \brief Number of reserved sectors.
  84. *
  85. * This includes the boot sector, which is typically the only
  86. * reserved sector with PHAT12/16.
  87. */
  88. u_short bios_rsvd_sects;
  89. /*! \brief Number of allocation tables. */
  90. u_char bios_ntabs;
  91. /*! \brief Number of root directory entries. */
  92. u_short bios_rootsz;
  93. /*! \brief Total number of sectors. */
  94. u_short bios_volsz;
  95. /*! \brief Media descriptor. */
  96. u_char bios_media;
  97. /*! \brief Number of sectors per allocation table.
  98. *
  99. * If zero, then the value is stored in bios_tabsz_big.
  100. */
  101. u_short bios_tabsz;
  102. /*! \brief Number of sectors per track. */
  103. u_short bios_sects_p_trk;
  104. /*! \brief Number of heads. */
  105. u_short bios_heads;
  106. /*! \brief Number of hidden sectors.
  107. *
  108. * With PHAT12 this field is two bytes only. We ignore it anyway.
  109. */
  110. u_long bios_sects_hidd;
  111. /*! \brief Total number of sectors for huge drives.
  112. *
  113. * Valid only if the value in bios_volsz is zero.
  114. */
  115. u_long bios_volsz_big;
  116. /*! \brief Number of sectors per allocation table for huge drives.
  117. *
  118. * This and the following 6 fields are available with PHAT32 only.
  119. */
  120. u_long bios_tabsz_big;
  121. /*! \brief Extended flags.
  122. *
  123. * If bit 7 is set, then bits 0-3 specify the active allocation table.
  124. * This feature is not yet supported. PHAT32 always updates the first
  125. * two tables.
  126. */
  127. u_short bios_xflags;
  128. /*! \brief File system version. */
  129. u_short bios_fsver;
  130. /*! \brief First cluster of root directory. */
  131. u_long bios_root_clust;
  132. /*! \brief File system info sector. */
  133. u_short bios_fsinfo;
  134. /*! \brief Boot backup sector. */
  135. u_short bios_boot_bak;
  136. /*! \brief Reserved for future expansion.
  137. *
  138. * End of the BIOS parameter block.
  139. */
  140. u_char bios_rsvd32[12];
  141. /*! \brief Logical drive number.
  142. *
  143. * With PHAT12 and PHAT16 this and the following fields
  144. * are at offset 36.
  145. */
  146. u_char boot_drive;
  147. /*! \brief Reserved field, used by Windows NT. */
  148. u_char boot_rsvd_nt;
  149. /*! \brief Extended signature.
  150. *
  151. * If 0x28 or 0x29, than the following fields are valid.
  152. */
  153. u_char boot_xsig;
  154. /*! \brief Volume serial number. */
  155. u_long boot_vol_id;
  156. /*! \brief Volume label. */
  157. u_char boot_vol_lbl[11];
  158. /*! \brief File system. */
  159. u_char boot_vol_fs[8];
  160. } PHATVBR;
  161. /*!
  162. * \brief Sector buffer structure.
  163. */
  164. typedef struct _PHATSECTBUF {
  165. /*! \brief Sector data buffer. */
  166. u_char *sect_data;
  167. /*! \brief Sector currently stored in the buffer. */
  168. u_long sect_num;
  169. /*! \brief If not zero, buffer needs to be written. */
  170. int sect_dirty;
  171. } PHATSECTBUF;
  172. /*!
  173. * \brief Volume info structure.
  174. */
  175. typedef struct _PHATVOL {
  176. /*! \brief Type of volume.
  177. *
  178. * Either 12, 16 or 32.
  179. */
  180. int vol_type;
  181. /*! \brief Number of free clusters. */
  182. u_long vol_numfree;
  183. /*! \brief Possibly next free cluster. */
  184. u_long vol_nxtfree;
  185. /*! \brief Sector buffer of this volume. */
  186. #if PHAT_SECTOR_BUFFERS
  187. PHATSECTBUF vol_buf[PHAT_SECTOR_BUFFERS];
  188. /*! \brief Next buffer to use. Simple round robin scheme. */
  189. int vol_usenext;
  190. #else
  191. PHATSECTBUF vol_buf[1];
  192. #endif
  193. /*! \brief Mutual exclusion filesystem access semaphore. */
  194. HANDLE vol_fsmutex;
  195. /*! \brief Mutual exclusion I/O semaphore. */
  196. HANDLE vol_iomutex;
  197. /*! \brief Bytes per sector. */
  198. u_int vol_sectsz;
  199. /*! \brief Sectors per cluster. */
  200. u_int vol_clustsz;
  201. /*! \brief Number of sectors per allocation table. */
  202. u_long vol_tabsz;
  203. /*! \brief First sector of each allocation table.
  204. *
  205. * We maintain upto two allocation tables.
  206. */
  207. u_long vol_tab_sect[2];
  208. /*! \brief Number of sectors used by the root directory. */
  209. u_int vol_rootsz;
  210. /*! \brief First sector of the root directory. */
  211. u_long vol_root_sect;
  212. /*! \brief First cluster of the root directory. */
  213. u_long vol_root_clust;
  214. /*! \brief Last data cluster number.
  215. *
  216. * The first cluster number is 2, so this value is equal to the total
  217. * number of data clusters plus 2.
  218. */
  219. u_long vol_last_clust;
  220. /*! \brief First data sector.
  221. *
  222. * The first sector following the root directory.
  223. */
  224. u_long vol_data_sect;
  225. /*! \brief indicate if number of free clusters is valid
  226. *
  227. * Flag that indicates if the number of free clusters were counted
  228. */
  229. u_char vol_numfree_valid;
  230. } PHATVOL;
  231. /*@}*/
  232. __BEGIN_DECLS
  233. /* Prototypes */
  234. extern int PhatVolMount(NUTDEVICE * dev, NUTFILE * blkmnt, u_char part_type);
  235. extern int PhatVolUnmount(NUTDEVICE * dev);
  236. extern u_long PhatClusterSector(NUTFILE * nfp, u_long clust);
  237. extern u_long PhatCountFreeClustersFast(NUTDEVICE * dev);
  238. extern u_long PhatCountFreeClusters(NUTDEVICE * dev);
  239. __END_DECLS
  240. /* End of prototypes */
  241. #endif