hfs.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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. /* Pascal-style string of up to 31 characters */
  74. struct hfs_name {
  75. u8 len;
  76. u8 name[HFS_NAMELEN];
  77. } __packed;
  78. struct hfs_point {
  79. __be16 v;
  80. __be16 h;
  81. } __packed;
  82. struct hfs_rect {
  83. __be16 top;
  84. __be16 left;
  85. __be16 bottom;
  86. __be16 right;
  87. } __packed;
  88. struct hfs_finfo {
  89. __be32 fdType;
  90. __be32 fdCreator;
  91. __be16 fdFlags;
  92. struct hfs_point fdLocation;
  93. __be16 fdFldr;
  94. } __packed;
  95. struct hfs_fxinfo {
  96. __be16 fdIconID;
  97. u8 fdUnused[8];
  98. __be16 fdComment;
  99. __be32 fdPutAway;
  100. } __packed;
  101. struct hfs_dinfo {
  102. struct hfs_rect frRect;
  103. __be16 frFlags;
  104. struct hfs_point frLocation;
  105. __be16 frView;
  106. } __packed;
  107. struct hfs_dxinfo {
  108. struct hfs_point frScroll;
  109. __be32 frOpenChain;
  110. __be16 frUnused;
  111. __be16 frComment;
  112. __be32 frPutAway;
  113. } __packed;
  114. union hfs_finder_info {
  115. struct {
  116. struct hfs_finfo finfo;
  117. struct hfs_fxinfo fxinfo;
  118. } file;
  119. struct {
  120. struct hfs_dinfo dinfo;
  121. struct hfs_dxinfo dxinfo;
  122. } dir;
  123. } __packed;
  124. /* Cast to a pointer to a generic bkey */
  125. #define HFS_BKEY(X) (((void)((X)->KeyLen)), ((struct hfs_bkey *)(X)))
  126. /* The key used in the catalog b-tree: */
  127. struct hfs_cat_key {
  128. u8 key_len; /* number of bytes in the key */
  129. u8 reserved; /* padding */
  130. __be32 ParID; /* CNID of the parent dir */
  131. struct hfs_name CName; /* The filename of the entry */
  132. } __packed;
  133. /* The key used in the extents b-tree: */
  134. struct hfs_ext_key {
  135. u8 key_len; /* number of bytes in the key */
  136. u8 FkType; /* HFS_FK_{DATA,RSRC} */
  137. __be32 FNum; /* The File ID of the file */
  138. __be16 FABN; /* allocation blocks number*/
  139. } __packed;
  140. typedef union hfs_btree_key {
  141. u8 key_len; /* number of bytes in the key */
  142. struct hfs_cat_key cat;
  143. struct hfs_ext_key ext;
  144. } hfs_btree_key;
  145. #define HFS_MAX_CAT_KEYLEN (sizeof(struct hfs_cat_key) - sizeof(u8))
  146. #define HFS_MAX_EXT_KEYLEN (sizeof(struct hfs_ext_key) - sizeof(u8))
  147. typedef union hfs_btree_key btree_key;
  148. struct hfs_extent {
  149. __be16 block;
  150. __be16 count;
  151. };
  152. typedef struct hfs_extent hfs_extent_rec[3];
  153. /* The catalog record for a file */
  154. struct hfs_cat_file {
  155. s8 type; /* The type of entry */
  156. u8 reserved;
  157. u8 Flags; /* Flags such as read-only */
  158. s8 Typ; /* file version number = 0 */
  159. struct hfs_finfo UsrWds; /* data used by the Finder */
  160. __be32 FlNum; /* The CNID */
  161. __be16 StBlk; /* obsolete */
  162. __be32 LgLen; /* The logical EOF of the data fork*/
  163. __be32 PyLen; /* The physical EOF of the data fork */
  164. __be16 RStBlk; /* obsolete */
  165. __be32 RLgLen; /* The logical EOF of the rsrc fork */
  166. __be32 RPyLen; /* The physical EOF of the rsrc fork */
  167. __be32 CrDat; /* The creation date */
  168. __be32 MdDat; /* The modified date */
  169. __be32 BkDat; /* The last backup date */
  170. struct hfs_fxinfo FndrInfo; /* more data for the Finder */
  171. __be16 ClpSize; /* number of bytes to allocate
  172. when extending files */
  173. hfs_extent_rec ExtRec; /* first extent record
  174. for the data fork */
  175. hfs_extent_rec RExtRec; /* first extent record
  176. for the resource fork */
  177. u32 Resrv; /* reserved by Apple */
  178. } __packed;
  179. /* the catalog record for a directory */
  180. struct hfs_cat_dir {
  181. s8 type; /* The type of entry */
  182. u8 reserved;
  183. __be16 Flags; /* flags */
  184. __be16 Val; /* Valence: number of files and
  185. dirs in the directory */
  186. __be32 DirID; /* The CNID */
  187. __be32 CrDat; /* The creation date */
  188. __be32 MdDat; /* The modification date */
  189. __be32 BkDat; /* The last backup date */
  190. struct hfs_dinfo UsrInfo; /* data used by the Finder */
  191. struct hfs_dxinfo FndrInfo; /* more data used by Finder */
  192. u8 Resrv[16]; /* reserved by Apple */
  193. } __packed;
  194. /* the catalog record for a thread */
  195. struct hfs_cat_thread {
  196. s8 type; /* The type of entry */
  197. u8 reserved[9]; /* reserved by Apple */
  198. __be32 ParID; /* CNID of parent directory */
  199. struct hfs_name CName; /* The name of this entry */
  200. } __packed;
  201. /* A catalog tree record */
  202. typedef union hfs_cat_rec {
  203. s8 type; /* The type of entry */
  204. struct hfs_cat_file file;
  205. struct hfs_cat_dir dir;
  206. struct hfs_cat_thread thread;
  207. } hfs_cat_rec;
  208. struct hfs_mdb {
  209. __be16 drSigWord; /* Signature word indicating fs type */
  210. __be32 drCrDate; /* fs creation date/time */
  211. __be32 drLsMod; /* fs modification date/time */
  212. __be16 drAtrb; /* fs attributes */
  213. __be16 drNmFls; /* number of files in root directory */
  214. __be16 drVBMSt; /* location (in 512-byte blocks)
  215. of the volume bitmap */
  216. __be16 drAllocPtr; /* location (in allocation blocks)
  217. to begin next allocation search */
  218. __be16 drNmAlBlks; /* number of allocation blocks */
  219. __be32 drAlBlkSiz; /* bytes in an allocation block */
  220. __be32 drClpSiz; /* clumpsize, the number of bytes to
  221. allocate when extending a file */
  222. __be16 drAlBlSt; /* location (in 512-byte blocks)
  223. of the first allocation block */
  224. __be32 drNxtCNID; /* CNID to assign to the next
  225. file or directory created */
  226. __be16 drFreeBks; /* number of free allocation blocks */
  227. u8 drVN[28]; /* the volume label */
  228. __be32 drVolBkUp; /* fs backup date/time */
  229. __be16 drVSeqNum; /* backup sequence number */
  230. __be32 drWrCnt; /* fs write count */
  231. __be32 drXTClpSiz; /* clumpsize for the extents B-tree */
  232. __be32 drCTClpSiz; /* clumpsize for the catalog B-tree */
  233. __be16 drNmRtDirs; /* number of directories in
  234. the root directory */
  235. __be32 drFilCnt; /* number of files in the fs */
  236. __be32 drDirCnt; /* number of directories in the fs */
  237. u8 drFndrInfo[32]; /* data used by the Finder */
  238. __be16 drEmbedSigWord; /* embedded volume signature */
  239. __be32 drEmbedExtent; /* starting block number (xdrStABN)
  240. and number of allocation blocks
  241. (xdrNumABlks) occupied by embedded
  242. volume */
  243. __be32 drXTFlSize; /* bytes in the extents B-tree */
  244. hfs_extent_rec drXTExtRec; /* extents B-tree's first 3 extents */
  245. __be32 drCTFlSize; /* bytes in the catalog B-tree */
  246. hfs_extent_rec drCTExtRec; /* catalog B-tree's first 3 extents */
  247. } __packed;
  248. /*======== Data structures kept in memory ========*/
  249. struct hfs_readdir_data {
  250. struct list_head list;
  251. struct file *file;
  252. struct hfs_cat_key key;
  253. };
  254. #endif