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