phatvol.h 7.5 KB

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