phatvol.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. #ifndef FS_PHATVOL_H_
  2. #define FS_PHATVOL_H_
  3. /*
  4. * Copyright (C) 2005 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/phatvol.h
  36. * \brief PHAT file system.
  37. *
  38. * \verbatim
  39. *
  40. * $Log$
  41. * Revision 1.6 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.5 2008/08/11 07:00:19 haraldkipp
  46. * BSD types replaced by stdint types (feature request #1282721).
  47. *
  48. * Revision 1.4 2006/10/08 16:42:56 haraldkipp
  49. * Not optimal, but simple and reliable exclusive access implemented.
  50. * Fixes bug #1486539. Furthermore, bug #1567790, which had been rejected,
  51. * had been reported correctly and is now fixed.
  52. *
  53. * Revision 1.3 2006/07/11 12:20:19 haraldkipp
  54. * PHAT file system failed when accessed from multiple threads. A mutual
  55. * exclusion semaphore fixes this.
  56. *
  57. * Revision 1.2 2006/02/23 15:47:18 haraldkipp
  58. * PHAT file system now supports configurable number of sector buffers.
  59. *
  60. * Revision 1.1 2006/01/05 16:33:10 haraldkipp
  61. * First check-in.
  62. *
  63. *
  64. * \endverbatim
  65. */
  66. #include <cfg/fs.h>
  67. #include <sys/types.h>
  68. #include <sys/file.h>
  69. #include <sys/device.h>
  70. /*!
  71. * \addtogroup xgPhatVol
  72. */
  73. /*@{*/
  74. /*!
  75. * \brief Volume boot record.
  76. */
  77. typedef struct NUT_PACKED_TYPE _PHATVBR {
  78. /*! \brief Jump instruction, contains E9xxxx or EBxx90. */
  79. uint8_t boot_jump[3];
  80. /*! \brief OEM name and version. */
  81. uint8_t boot_oem[8];
  82. /*! \brief Bytes per sector.
  83. *
  84. * The BIOS parameter block starts here.
  85. */
  86. uint16_t bios_sectsz;
  87. /*! \brief Sectors per cluster. */
  88. uint8_t bios_clustsz;
  89. /*! \brief Number of reserved sectors.
  90. *
  91. * This includes the boot sector, which is typically the only
  92. * reserved sector with PHAT12/16.
  93. */
  94. uint16_t bios_rsvd_sects;
  95. /*! \brief Number of allocation tables. */
  96. uint8_t bios_ntabs;
  97. /*! \brief Number of root directory entries. */
  98. uint16_t bios_rootsz;
  99. /*! \brief Total number of sectors. */
  100. uint16_t bios_volsz;
  101. /*! \brief Media descriptor. */
  102. uint8_t bios_media;
  103. /*! \brief Number of sectors per allocation table.
  104. *
  105. * If zero, then the value is stored in bios_tabsz_big.
  106. */
  107. uint16_t bios_tabsz;
  108. /*! \brief Number of sectors per track. */
  109. uint16_t bios_sects_p_trk;
  110. /*! \brief Number of heads. */
  111. uint16_t bios_heads;
  112. /*! \brief Number of hidden sectors.
  113. *
  114. * With PHAT12 this field is two bytes only. We ignore it anyway.
  115. */
  116. uint32_t bios_sects_hidd;
  117. /*! \brief Total number of sectors for huge drives.
  118. *
  119. * Valid only if the value in bios_volsz is zero.
  120. */
  121. uint32_t bios_volsz_big;
  122. /*! \brief Number of sectors per allocation table for huge drives.
  123. *
  124. * This and the following 6 fields are available with PHAT32 only.
  125. */
  126. uint32_t bios_tabsz_big;
  127. /*! \brief Extended flags.
  128. *
  129. * If bit 7 is set, then bits 0-3 specify the active allocation table.
  130. * This feature is not yet supported. PHAT32 always updates the first
  131. * two tables.
  132. */
  133. uint16_t bios_xflags;
  134. /*! \brief File system version. */
  135. uint16_t bios_fsver;
  136. /*! \brief First cluster of root directory. */
  137. uint32_t bios_root_clust;
  138. /*! \brief File system info sector. */
  139. uint16_t bios_fsinfo;
  140. /*! \brief Boot backup sector. */
  141. uint16_t bios_boot_bak;
  142. /*! \brief Reserved for future expansion.
  143. *
  144. * End of the BIOS parameter block.
  145. */
  146. uint8_t bios_rsvd32[12];
  147. /*! \brief Logical drive number.
  148. *
  149. * With PHAT12 and PHAT16 this and the following fields
  150. * are at offset 36.
  151. */
  152. uint8_t boot_drive;
  153. /*! \brief Reserved field, used by Windows NT. */
  154. uint8_t boot_rsvd_nt;
  155. /*! \brief Extended signature.
  156. *
  157. * If 0x28 or 0x29, than the following fields are valid.
  158. */
  159. uint8_t boot_xsig;
  160. /*! \brief Volume serial number. */
  161. uint32_t boot_vol_id;
  162. /*! \brief Volume label. */
  163. uint8_t boot_vol_lbl[11];
  164. /*! \brief File system. */
  165. uint8_t boot_vol_fs[8];
  166. } PHATVBR;
  167. /*!
  168. * \brief Sector buffer structure.
  169. */
  170. typedef struct _PHATSECTBUF {
  171. /*! \brief Sector data buffer. */
  172. uint8_t *sect_data;
  173. /*! \brief Sector currently stored in the buffer. */
  174. uint32_t sect_num;
  175. /*! \brief If not zero, buffer needs to be written. */
  176. int sect_dirty;
  177. /*! \brief If not zero, buffer is locked. */
  178. int sect_lock;
  179. } PHATSECTBUF;
  180. /*!
  181. * \brief Volume info structure.
  182. */
  183. typedef struct _PHATVOL {
  184. /*! \brief Type of volume.
  185. *
  186. * Either 12, 16 or 32.
  187. */
  188. int vol_type;
  189. /*! \brief Number of free clusters. */
  190. uint32_t vol_numfree;
  191. /*! \brief Possibly next free cluster. */
  192. uint32_t vol_nxtfree;
  193. /*! \brief Sector buffer of this volume. */
  194. #if PHAT_SECTOR_BUFFERS
  195. PHATSECTBUF vol_buf[PHAT_SECTOR_BUFFERS];
  196. /*! \brief Next buffer to use. Simple round robin scheme. */
  197. int vol_usenext;
  198. #else
  199. PHATSECTBUF vol_buf[1];
  200. #endif
  201. /*! \brief Mutual exclusion filesystem access semaphore. */
  202. HANDLE vol_fsmutex;
  203. /*! \brief Mutual exclusion I/O semaphore. */
  204. HANDLE vol_iomutex;
  205. /*! \brief Bytes per sector. */
  206. unsigned int vol_sectsz;
  207. /*! \brief Sectors per cluster. */
  208. unsigned int vol_clustsz;
  209. /*! \brief Number of sectors per allocation table. */
  210. uint32_t vol_tabsz;
  211. /*! \brief First sector of each allocation table.
  212. *
  213. * We maintain upto two allocation tables.
  214. */
  215. uint32_t vol_tab_sect[2];
  216. /*! \brief Number of sectors used by the root directory. */
  217. unsigned int vol_rootsz;
  218. /*! \brief First sector of the root directory. */
  219. uint32_t vol_root_sect;
  220. /*! \brief First cluster of the root directory. */
  221. uint32_t vol_root_clust;
  222. /*! \brief Last data cluster number.
  223. *
  224. * The first cluster number is 2, so this value is equal to the total
  225. * number of data clusters plus 2.
  226. */
  227. uint32_t vol_last_clust;
  228. /*! \brief First data sector.
  229. *
  230. * The first sector following the root directory.
  231. */
  232. uint32_t vol_data_sect;
  233. } PHATVOL;
  234. /*@}*/
  235. extern int PhatVolMount(NUTDEVICE * dev, NUTFILE * blkmnt, uint8_t part_type);
  236. extern int PhatVolUnmount(NUTDEVICE * dev);
  237. extern uint32_t PhatClusterSector(NUTFILE * nfp, uint32_t clust);
  238. #endif