hfs.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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. typedef union hfs_btree_key btree_key;
  146. struct hfs_extent {
  147. __be16 block;
  148. __be16 count;
  149. };
  150. typedef struct hfs_extent hfs_extent_rec[3];
  151. /* The catalog record for a file */
  152. struct hfs_cat_file {
  153. s8 type; /* The type of entry */
  154. u8 reserved;
  155. u8 Flags; /* Flags such as read-only */
  156. s8 Typ; /* file version number = 0 */
  157. struct hfs_finfo UsrWds; /* data used by the Finder */
  158. __be32 FlNum; /* The CNID */
  159. __be16 StBlk; /* obsolete */
  160. __be32 LgLen; /* The logical EOF of the data fork*/
  161. __be32 PyLen; /* The physical EOF of the data fork */
  162. __be16 RStBlk; /* obsolete */
  163. __be32 RLgLen; /* The logical EOF of the rsrc fork */
  164. __be32 RPyLen; /* The physical EOF of the rsrc fork */
  165. __be32 CrDat; /* The creation date */
  166. __be32 MdDat; /* The modified date */
  167. __be32 BkDat; /* The last backup date */
  168. struct hfs_fxinfo FndrInfo; /* more data for the Finder */
  169. __be16 ClpSize; /* number of bytes to allocate
  170. when extending files */
  171. hfs_extent_rec ExtRec; /* first extent record
  172. for the data fork */
  173. hfs_extent_rec RExtRec; /* first extent record
  174. for the resource fork */
  175. u32 Resrv; /* reserved by Apple */
  176. } __packed;
  177. /* the catalog record for a directory */
  178. struct hfs_cat_dir {
  179. s8 type; /* The type of entry */
  180. u8 reserved;
  181. __be16 Flags; /* flags */
  182. __be16 Val; /* Valence: number of files and
  183. dirs in the directory */
  184. __be32 DirID; /* The CNID */
  185. __be32 CrDat; /* The creation date */
  186. __be32 MdDat; /* The modification date */
  187. __be32 BkDat; /* The last backup date */
  188. struct hfs_dinfo UsrInfo; /* data used by the Finder */
  189. struct hfs_dxinfo FndrInfo; /* more data used by Finder */
  190. u8 Resrv[16]; /* reserved by Apple */
  191. } __packed;
  192. /* the catalog record for a thread */
  193. struct hfs_cat_thread {
  194. s8 type; /* The type of entry */
  195. u8 reserved[9]; /* reserved by Apple */
  196. __be32 ParID; /* CNID of parent directory */
  197. struct hfs_name CName; /* The name of this entry */
  198. } __packed;
  199. /* A catalog tree record */
  200. typedef union hfs_cat_rec {
  201. s8 type; /* The type of entry */
  202. struct hfs_cat_file file;
  203. struct hfs_cat_dir dir;
  204. struct hfs_cat_thread thread;
  205. } hfs_cat_rec;
  206. struct hfs_mdb {
  207. __be16 drSigWord; /* Signature word indicating fs type */
  208. __be32 drCrDate; /* fs creation date/time */
  209. __be32 drLsMod; /* fs modification date/time */
  210. __be16 drAtrb; /* fs attributes */
  211. __be16 drNmFls; /* number of files in root directory */
  212. __be16 drVBMSt; /* location (in 512-byte blocks)
  213. of the volume bitmap */
  214. __be16 drAllocPtr; /* location (in allocation blocks)
  215. to begin next allocation search */
  216. __be16 drNmAlBlks; /* number of allocation blocks */
  217. __be32 drAlBlkSiz; /* bytes in an allocation block */
  218. __be32 drClpSiz; /* clumpsize, the number of bytes to
  219. allocate when extending a file */
  220. __be16 drAlBlSt; /* location (in 512-byte blocks)
  221. of the first allocation block */
  222. __be32 drNxtCNID; /* CNID to assign to the next
  223. file or directory created */
  224. __be16 drFreeBks; /* number of free allocation blocks */
  225. u8 drVN[28]; /* the volume label */
  226. __be32 drVolBkUp; /* fs backup date/time */
  227. __be16 drVSeqNum; /* backup sequence number */
  228. __be32 drWrCnt; /* fs write count */
  229. __be32 drXTClpSiz; /* clumpsize for the extents B-tree */
  230. __be32 drCTClpSiz; /* clumpsize for the catalog B-tree */
  231. __be16 drNmRtDirs; /* number of directories in
  232. the root directory */
  233. __be32 drFilCnt; /* number of files in the fs */
  234. __be32 drDirCnt; /* number of directories in the fs */
  235. u8 drFndrInfo[32]; /* data used by the Finder */
  236. __be16 drEmbedSigWord; /* embedded volume signature */
  237. __be32 drEmbedExtent; /* starting block number (xdrStABN)
  238. and number of allocation blocks
  239. (xdrNumABlks) occupied by embedded
  240. volume */
  241. __be32 drXTFlSize; /* bytes in the extents B-tree */
  242. hfs_extent_rec drXTExtRec; /* extents B-tree's first 3 extents */
  243. __be32 drCTFlSize; /* bytes in the catalog B-tree */
  244. hfs_extent_rec drCTExtRec; /* catalog B-tree's first 3 extents */
  245. } __packed;
  246. /*======== Data structures kept in memory ========*/
  247. struct hfs_readdir_data {
  248. struct list_head list;
  249. struct file *file;
  250. struct hfs_cat_key key;
  251. };
  252. #endif