hfs.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. /*
  2. * linux/fs/hfs/hfs.h
  3. *
  4. * Copyright (C) 1995-1997 Paul H. Hargrove
  5. * (C) 2003 Ardis Technologies <roman@ardistech.com>
  6. * This file may be distributed under the terms of the GNU General Public License.
  7. */
  8. #ifndef _HFS_H
  9. #define _HFS_H
  10. /* offsets to various blocks */
  11. #define HFS_DD_BLK 0 /* Driver Descriptor block */
  12. #define HFS_PMAP_BLK 1 /* First block of partition map */
  13. #define HFS_MDB_BLK 2 /* Block (w/i partition) of MDB */
  14. /* magic numbers for various disk blocks */
  15. #define HFS_DRVR_DESC_MAGIC 0x4552 /* "ER": driver descriptor map */
  16. #define HFS_OLD_PMAP_MAGIC 0x5453 /* "TS": old-type partition map */
  17. #define HFS_NEW_PMAP_MAGIC 0x504D /* "PM": new-type partition map */
  18. #define HFS_SUPER_MAGIC 0x4244 /* "BD": HFS MDB (super block) */
  19. #define HFS_MFS_SUPER_MAGIC 0xD2D7 /* MFS MDB (super block) */
  20. /* various FIXED size parameters */
  21. #define HFS_SECTOR_SIZE 512 /* size of an HFS sector */
  22. #define HFS_SECTOR_SIZE_BITS 9 /* log_2(HFS_SECTOR_SIZE) */
  23. #define HFS_NAMELEN 31 /* maximum length of an HFS filename */
  24. #define HFS_MAX_NAMELEN 128
  25. #define HFS_MAX_VALENCE 32767U
  26. /* Meanings of the drAtrb field of the MDB,
  27. * Reference: _Inside Macintosh: Files_ p. 2-61
  28. */
  29. #define HFS_SB_ATTRIB_HLOCK (1 << 7)
  30. #define HFS_SB_ATTRIB_UNMNT (1 << 8)
  31. #define HFS_SB_ATTRIB_SPARED (1 << 9)
  32. #define HFS_SB_ATTRIB_INCNSTNT (1 << 11)
  33. #define HFS_SB_ATTRIB_SLOCK (1 << 15)
  34. /* Some special File ID numbers */
  35. #define HFS_POR_CNID 1 /* Parent Of the Root */
  36. #define HFS_ROOT_CNID 2 /* ROOT directory */
  37. #define HFS_EXT_CNID 3 /* EXTents B-tree */
  38. #define HFS_CAT_CNID 4 /* CATalog B-tree */
  39. #define HFS_BAD_CNID 5 /* BAD blocks file */
  40. #define HFS_ALLOC_CNID 6 /* ALLOCation file (HFS+) */
  41. #define HFS_START_CNID 7 /* STARTup file (HFS+) */
  42. #define HFS_ATTR_CNID 8 /* ATTRibutes file (HFS+) */
  43. #define HFS_EXCH_CNID 15 /* ExchangeFiles temp id */
  44. #define HFS_FIRSTUSER_CNID 16
  45. /* values for hfs_cat_rec.cdrType */
  46. #define HFS_CDR_DIR 0x01 /* folder (directory) */
  47. #define HFS_CDR_FIL 0x02 /* file */
  48. #define HFS_CDR_THD 0x03 /* folder (directory) thread */
  49. #define HFS_CDR_FTH 0x04 /* file thread */
  50. /* legal values for hfs_ext_key.FkType and hfs_file.fork */
  51. #define HFS_FK_DATA 0x00
  52. #define HFS_FK_RSRC 0xFF
  53. /* bits in hfs_fil_entry.Flags */
  54. #define HFS_FIL_LOCK 0x01 /* locked */
  55. #define HFS_FIL_THD 0x02 /* file thread */
  56. #define HFS_FIL_DOPEN 0x04 /* data fork open */
  57. #define HFS_FIL_ROPEN 0x08 /* resource fork open */
  58. #define HFS_FIL_DIR 0x10 /* directory (always clear) */
  59. #define HFS_FIL_NOCOPY 0x40 /* copy-protected file */
  60. #define HFS_FIL_USED 0x80 /* open */
  61. /* bits in hfs_dir_entry.Flags. dirflags is 16 bits. */
  62. #define HFS_DIR_LOCK 0x01 /* locked */
  63. #define HFS_DIR_THD 0x02 /* directory thread */
  64. #define HFS_DIR_INEXPFOLDER 0x04 /* in a shared area */
  65. #define HFS_DIR_MOUNTED 0x08 /* mounted */
  66. #define HFS_DIR_DIR 0x10 /* directory (always set) */
  67. #define HFS_DIR_EXPFOLDER 0x20 /* share point */
  68. /* bits hfs_finfo.fdFlags */
  69. #define HFS_FLG_INITED 0x0100
  70. #define HFS_FLG_LOCKED 0x1000
  71. #define HFS_FLG_INVISIBLE 0x4000
  72. /*======== HFS structures as they appear on the disk ========*/
  73. #define __packed __attribute__ ((packed))
  74. /* Pascal-style string of up to 31 characters */
  75. struct hfs_name {
  76. u8 len;
  77. u8 name[HFS_NAMELEN];
  78. } __packed;
  79. struct hfs_point {
  80. __be16 v;
  81. __be16 h;
  82. } __packed;
  83. struct hfs_rect {
  84. __be16 top;
  85. __be16 left;
  86. __be16 bottom;
  87. __be16 right;
  88. } __packed;
  89. struct hfs_finfo {
  90. __be32 fdType;
  91. __be32 fdCreator;
  92. __be16 fdFlags;
  93. struct hfs_point fdLocation;
  94. __be16 fdFldr;
  95. } __packed;
  96. struct hfs_fxinfo {
  97. __be16 fdIconID;
  98. u8 fdUnused[8];
  99. __be16 fdComment;
  100. __be32 fdPutAway;
  101. } __packed;
  102. struct hfs_dinfo {
  103. struct hfs_rect frRect;
  104. __be16 frFlags;
  105. struct hfs_point frLocation;
  106. __be16 frView;
  107. } __packed;
  108. struct hfs_dxinfo {
  109. struct hfs_point frScroll;
  110. __be32 frOpenChain;
  111. __be16 frUnused;
  112. __be16 frComment;
  113. __be32 frPutAway;
  114. } __packed;
  115. union hfs_finder_info {
  116. struct {
  117. struct hfs_finfo finfo;
  118. struct hfs_fxinfo fxinfo;
  119. } file;
  120. struct {
  121. struct hfs_dinfo dinfo;
  122. struct hfs_dxinfo dxinfo;
  123. } dir;
  124. } __packed;
  125. /* Cast to a pointer to a generic bkey */
  126. #define HFS_BKEY(X) (((void)((X)->KeyLen)), ((struct hfs_bkey *)(X)))
  127. /* The key used in the catalog b-tree: */
  128. struct hfs_cat_key {
  129. u8 key_len; /* number of bytes in the key */
  130. u8 reserved; /* padding */
  131. __be32 ParID; /* CNID of the parent dir */
  132. struct hfs_name CName; /* The filename of the entry */
  133. } __packed;
  134. /* The key used in the extents b-tree: */
  135. struct hfs_ext_key {
  136. u8 key_len; /* number of bytes in the key */
  137. u8 FkType; /* HFS_FK_{DATA,RSRC} */
  138. __be32 FNum; /* The File ID of the file */
  139. __be16 FABN; /* allocation blocks number*/
  140. } __packed;
  141. typedef union hfs_btree_key {
  142. u8 key_len; /* number of bytes in the key */
  143. struct hfs_cat_key cat;
  144. struct hfs_ext_key ext;
  145. } hfs_btree_key;
  146. typedef union hfs_btree_key btree_key;
  147. struct hfs_extent {
  148. __be16 block;
  149. __be16 count;
  150. };
  151. typedef struct hfs_extent hfs_extent_rec[3];
  152. /* The catalog record for a file */
  153. struct hfs_cat_file {
  154. s8 type; /* The type of entry */
  155. u8 reserved;
  156. u8 Flags; /* Flags such as read-only */
  157. s8 Typ; /* file version number = 0 */
  158. struct hfs_finfo UsrWds; /* data used by the Finder */
  159. __be32 FlNum; /* The CNID */
  160. __be16 StBlk; /* obsolete */
  161. __be32 LgLen; /* The logical EOF of the data fork*/
  162. __be32 PyLen; /* The physical EOF of the data fork */
  163. __be16 RStBlk; /* obsolete */
  164. __be32 RLgLen; /* The logical EOF of the rsrc fork */
  165. __be32 RPyLen; /* The physical EOF of the rsrc fork */
  166. __be32 CrDat; /* The creation date */
  167. __be32 MdDat; /* The modified date */
  168. __be32 BkDat; /* The last backup date */
  169. struct hfs_fxinfo FndrInfo; /* more data for the Finder */
  170. __be16 ClpSize; /* number of bytes to allocate
  171. when extending files */
  172. hfs_extent_rec ExtRec; /* first extent record
  173. for the data fork */
  174. hfs_extent_rec RExtRec; /* first extent record
  175. for the resource fork */
  176. u32 Resrv; /* reserved by Apple */
  177. } __packed;
  178. /* the catalog record for a directory */
  179. struct hfs_cat_dir {
  180. s8 type; /* The type of entry */
  181. u8 reserved;
  182. __be16 Flags; /* flags */
  183. __be16 Val; /* Valence: number of files and
  184. dirs in the directory */
  185. __be32 DirID; /* The CNID */
  186. __be32 CrDat; /* The creation date */
  187. __be32 MdDat; /* The modification date */
  188. __be32 BkDat; /* The last backup date */
  189. struct hfs_dinfo UsrInfo; /* data used by the Finder */
  190. struct hfs_dxinfo FndrInfo; /* more data used by Finder */
  191. u8 Resrv[16]; /* reserved by Apple */
  192. } __packed;
  193. /* the catalog record for a thread */
  194. struct hfs_cat_thread {
  195. s8 type; /* The type of entry */
  196. u8 reserved[9]; /* reserved by Apple */
  197. __be32 ParID; /* CNID of parent directory */
  198. struct hfs_name CName; /* The name of this entry */
  199. } __packed;
  200. /* A catalog tree record */
  201. typedef union hfs_cat_rec {
  202. s8 type; /* The type of entry */
  203. struct hfs_cat_file file;
  204. struct hfs_cat_dir dir;
  205. struct hfs_cat_thread thread;
  206. } hfs_cat_rec;
  207. struct hfs_mdb {
  208. __be16 drSigWord; /* Signature word indicating fs type */
  209. __be32 drCrDate; /* fs creation date/time */
  210. __be32 drLsMod; /* fs modification date/time */
  211. __be16 drAtrb; /* fs attributes */
  212. __be16 drNmFls; /* number of files in root directory */
  213. __be16 drVBMSt; /* location (in 512-byte blocks)
  214. of the volume bitmap */
  215. __be16 drAllocPtr; /* location (in allocation blocks)
  216. to begin next allocation search */
  217. __be16 drNmAlBlks; /* number of allocation blocks */
  218. __be32 drAlBlkSiz; /* bytes in an allocation block */
  219. __be32 drClpSiz; /* clumpsize, the number of bytes to
  220. allocate when extending a file */
  221. __be16 drAlBlSt; /* location (in 512-byte blocks)
  222. of the first allocation block */
  223. __be32 drNxtCNID; /* CNID to assign to the next
  224. file or directory created */
  225. __be16 drFreeBks; /* number of free allocation blocks */
  226. u8 drVN[28]; /* the volume label */
  227. __be32 drVolBkUp; /* fs backup date/time */
  228. __be16 drVSeqNum; /* backup sequence number */
  229. __be32 drWrCnt; /* fs write count */
  230. __be32 drXTClpSiz; /* clumpsize for the extents B-tree */
  231. __be32 drCTClpSiz; /* clumpsize for the catalog B-tree */
  232. __be16 drNmRtDirs; /* number of directories in
  233. the root directory */
  234. __be32 drFilCnt; /* number of files in the fs */
  235. __be32 drDirCnt; /* number of directories in the fs */
  236. u8 drFndrInfo[32]; /* data used by the Finder */
  237. __be16 drEmbedSigWord; /* embedded volume signature */
  238. __be32 drEmbedExtent; /* starting block number (xdrStABN)
  239. and number of allocation blocks
  240. (xdrNumABlks) occupied by embedded
  241. volume */
  242. __be32 drXTFlSize; /* bytes in the extents B-tree */
  243. hfs_extent_rec drXTExtRec; /* extents B-tree's first 3 extents */
  244. __be32 drCTFlSize; /* bytes in the catalog B-tree */
  245. hfs_extent_rec drCTExtRec; /* catalog B-tree's first 3 extents */
  246. } __packed;
  247. /*======== Data structures kept in memory ========*/
  248. struct hfs_readdir_data {
  249. struct list_head list;
  250. struct file *file;
  251. struct hfs_cat_key key;
  252. };
  253. #endif