| 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | /* |
| 3 | * HFS/HFS+ common definitions, inline functions, |
| 4 | * and shared functionality. |
| 5 | */ |
| 6 | |
| 7 | #ifndef _HFS_COMMON_H_ |
| 8 | #define _HFS_COMMON_H_ |
| 9 | |
| 10 | #ifdef pr_fmt |
| 11 | #undef pr_fmt |
| 12 | #endif |
| 13 | |
| 14 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 15 | |
| 16 | #define hfs_dbg(fmt, ...) \ |
| 17 | pr_debug("pid %d:%s:%d %s(): " fmt, \ |
| 18 | current->pid, __FILE__, __LINE__, __func__, ##__VA_ARGS__) \ |
| 19 | |
| 20 | /* |
| 21 | * Format of structures on disk |
| 22 | * Information taken from Apple Technote #1150 (HFS Plus Volume Format) |
| 23 | */ |
| 24 | |
| 25 | /* offsets to various blocks */ |
| 26 | #define HFS_DD_BLK 0 /* Driver Descriptor block */ |
| 27 | #define HFS_PMAP_BLK 1 /* First block of partition map */ |
| 28 | #define HFS_MDB_BLK 2 /* Block (w/i partition) of MDB */ |
| 29 | |
| 30 | /* magic numbers for various disk blocks */ |
| 31 | #define HFS_DRVR_DESC_MAGIC 0x4552 /* "ER": driver descriptor map */ |
| 32 | #define HFS_OLD_PMAP_MAGIC 0x5453 /* "TS": old-type partition map */ |
| 33 | #define HFS_NEW_PMAP_MAGIC 0x504D /* "PM": new-type partition map */ |
| 34 | #define HFS_SUPER_MAGIC 0x4244 /* "BD": HFS MDB (super block) */ |
| 35 | #define HFS_MFS_SUPER_MAGIC 0xD2D7 /* MFS MDB (super block) */ |
| 36 | |
| 37 | #define HFSPLUS_VOLHEAD_SIG 0x482b |
| 38 | #define HFSPLUS_VOLHEAD_SIGX 0x4858 |
| 39 | #define HFSPLUS_SUPER_MAGIC 0x482b |
| 40 | |
| 41 | #define HFSP_WRAP_MAGIC 0x4244 |
| 42 | #define HFSP_WRAP_ATTRIB_SLOCK 0x8000 |
| 43 | #define HFSP_WRAP_ATTRIB_SPARED 0x0200 |
| 44 | |
| 45 | #define HFSP_WRAPOFF_SIG 0x00 |
| 46 | #define HFSP_WRAPOFF_ATTRIB 0x0A |
| 47 | #define HFSP_WRAPOFF_ABLKSIZE 0x14 |
| 48 | #define HFSP_WRAPOFF_ABLKSTART 0x1C |
| 49 | #define HFSP_WRAPOFF_EMBEDSIG 0x7C |
| 50 | #define HFSP_WRAPOFF_EMBEDEXT 0x7E |
| 51 | |
| 52 | #define HFSP_HARDLINK_TYPE 0x686c6e6b /* 'hlnk' */ |
| 53 | #define HFSP_HFSPLUS_CREATOR 0x6866732b /* 'hfs+' */ |
| 54 | |
| 55 | #define HFSP_SYMLINK_TYPE 0x736c6e6b /* 'slnk' */ |
| 56 | #define HFSP_SYMLINK_CREATOR 0x72686170 /* 'rhap' */ |
| 57 | |
| 58 | #define HFSP_MOUNT_VERSION 0x482b4c78 /* 'H+Lx' */ |
| 59 | |
| 60 | #define HFSP_HIDDENDIR_NAME \ |
| 61 | "\xe2\x90\x80\xe2\x90\x80\xe2\x90\x80\xe2\x90\x80HFS+ Private Data" |
| 62 | |
| 63 | /* various FIXED size parameters */ |
| 64 | #define HFS_SECTOR_SIZE 512 /* size of an HFS sector */ |
| 65 | #define HFS_SECTOR_SIZE_BITS 9 /* log_2(HFS_SECTOR_SIZE) */ |
| 66 | #define HFS_MAX_VALENCE 32767U |
| 67 | |
| 68 | #define HFSPLUS_SECTOR_SIZE HFS_SECTOR_SIZE |
| 69 | #define HFSPLUS_SECTOR_SHIFT HFS_SECTOR_SIZE_BITS |
| 70 | #define HFSPLUS_VOLHEAD_SECTOR 2 |
| 71 | #define HFSPLUS_MIN_VERSION 4 |
| 72 | #define HFSPLUS_CURRENT_VERSION 5 |
| 73 | |
| 74 | #define HFS_NAMELEN 31 /* maximum length of an HFS filename */ |
| 75 | #define HFS_MAX_NAMELEN 128 |
| 76 | |
| 77 | #define HFSPLUS_MAX_STRLEN 255 |
| 78 | #define HFSPLUS_ATTR_MAX_STRLEN 127 |
| 79 | |
| 80 | /* Meanings of the drAtrb field of the MDB, |
| 81 | * Reference: _Inside Macintosh: Files_ p. 2-61 |
| 82 | */ |
| 83 | #define HFS_SB_ATTRIB_HLOCK (1 << 7) |
| 84 | #define HFS_SB_ATTRIB_UNMNT (1 << 8) |
| 85 | #define HFS_SB_ATTRIB_SPARED (1 << 9) |
| 86 | #define HFS_SB_ATTRIB_INCNSTNT (1 << 11) |
| 87 | #define HFS_SB_ATTRIB_SLOCK (1 << 15) |
| 88 | |
| 89 | /* values for hfs_cat_rec.cdrType */ |
| 90 | #define HFS_CDR_DIR 0x01 /* folder (directory) */ |
| 91 | #define HFS_CDR_FIL 0x02 /* file */ |
| 92 | #define HFS_CDR_THD 0x03 /* folder (directory) thread */ |
| 93 | #define HFS_CDR_FTH 0x04 /* file thread */ |
| 94 | |
| 95 | /* legal values for hfs_ext_key.FkType and hfs_file.fork */ |
| 96 | #define HFS_FK_DATA 0x00 |
| 97 | #define HFS_FK_RSRC 0xFF |
| 98 | |
| 99 | /* bits in hfs_fil_entry.Flags */ |
| 100 | #define HFS_FIL_LOCK 0x01 /* locked */ |
| 101 | #define HFS_FIL_THD 0x02 /* file thread */ |
| 102 | #define HFS_FIL_DOPEN 0x04 /* data fork open */ |
| 103 | #define HFS_FIL_ROPEN 0x08 /* resource fork open */ |
| 104 | #define HFS_FIL_DIR 0x10 /* directory (always clear) */ |
| 105 | #define HFS_FIL_NOCOPY 0x40 /* copy-protected file */ |
| 106 | #define HFS_FIL_USED 0x80 /* open */ |
| 107 | |
| 108 | /* bits in hfs_dir_entry.Flags. dirflags is 16 bits. */ |
| 109 | #define HFS_DIR_LOCK 0x01 /* locked */ |
| 110 | #define HFS_DIR_THD 0x02 /* directory thread */ |
| 111 | #define HFS_DIR_INEXPFOLDER 0x04 /* in a shared area */ |
| 112 | #define HFS_DIR_MOUNTED 0x08 /* mounted */ |
| 113 | #define HFS_DIR_DIR 0x10 /* directory (always set) */ |
| 114 | #define HFS_DIR_EXPFOLDER 0x20 /* share point */ |
| 115 | |
| 116 | /* bits hfs_finfo.fdFlags */ |
| 117 | #define HFS_FLG_INITED 0x0100 |
| 118 | #define HFS_FLG_LOCKED 0x1000 |
| 119 | #define HFS_FLG_INVISIBLE 0x4000 |
| 120 | |
| 121 | /* Some special File ID numbers */ |
| 122 | #define HFS_POR_CNID 1 /* Parent Of the Root */ |
| 123 | #define HFSPLUS_POR_CNID HFS_POR_CNID |
| 124 | #define HFS_ROOT_CNID 2 /* ROOT directory */ |
| 125 | #define HFSPLUS_ROOT_CNID HFS_ROOT_CNID |
| 126 | #define HFS_EXT_CNID 3 /* EXTents B-tree */ |
| 127 | #define HFSPLUS_EXT_CNID HFS_EXT_CNID |
| 128 | #define HFS_CAT_CNID 4 /* CATalog B-tree */ |
| 129 | #define HFSPLUS_CAT_CNID HFS_CAT_CNID |
| 130 | #define HFS_BAD_CNID 5 /* BAD blocks file */ |
| 131 | #define HFSPLUS_BAD_CNID HFS_BAD_CNID |
| 132 | #define HFS_ALLOC_CNID 6 /* ALLOCation file (HFS+) */ |
| 133 | #define HFSPLUS_ALLOC_CNID HFS_ALLOC_CNID |
| 134 | #define HFS_START_CNID 7 /* STARTup file (HFS+) */ |
| 135 | #define HFSPLUS_START_CNID HFS_START_CNID |
| 136 | #define HFS_ATTR_CNID 8 /* ATTRibutes file (HFS+) */ |
| 137 | #define HFSPLUS_ATTR_CNID HFS_ATTR_CNID |
| 138 | #define HFS_EXCH_CNID 15 /* ExchangeFiles temp id */ |
| 139 | #define HFSPLUS_EXCH_CNID HFS_EXCH_CNID |
| 140 | #define HFS_FIRSTUSER_CNID 16 /* first available user id */ |
| 141 | #define HFSPLUS_FIRSTUSER_CNID HFS_FIRSTUSER_CNID |
| 142 | |
| 143 | /*======== HFS/HFS+ structures as they appear on the disk ========*/ |
| 144 | |
| 145 | typedef __be32 hfsplus_cnid; |
| 146 | typedef __be16 hfsplus_unichr; |
| 147 | |
| 148 | /* Pascal-style string of up to 31 characters */ |
| 149 | struct hfs_name { |
| 150 | u8 len; |
| 151 | u8 name[HFS_NAMELEN]; |
| 152 | } __packed; |
| 153 | |
| 154 | /* A "string" as used in filenames, etc. */ |
| 155 | struct hfsplus_unistr { |
| 156 | __be16 length; |
| 157 | hfsplus_unichr unicode[HFSPLUS_MAX_STRLEN]; |
| 158 | } __packed; |
| 159 | |
| 160 | /* |
| 161 | * A "string" is used in attributes file |
| 162 | * for name of extended attribute |
| 163 | */ |
| 164 | struct hfsplus_attr_unistr { |
| 165 | __be16 length; |
| 166 | hfsplus_unichr unicode[HFSPLUS_ATTR_MAX_STRLEN]; |
| 167 | } __packed; |
| 168 | |
| 169 | struct hfs_extent { |
| 170 | __be16 block; |
| 171 | __be16 count; |
| 172 | }; |
| 173 | typedef struct hfs_extent hfs_extent_rec[3]; |
| 174 | |
| 175 | /* A single contiguous area of a file */ |
| 176 | struct hfsplus_extent { |
| 177 | __be32 start_block; |
| 178 | __be32 block_count; |
| 179 | } __packed; |
| 180 | typedef struct hfsplus_extent hfsplus_extent_rec[8]; |
| 181 | |
| 182 | /* Information for a "Fork" in a file */ |
| 183 | struct hfsplus_fork_raw { |
| 184 | __be64 total_size; |
| 185 | __be32 clump_size; |
| 186 | __be32 total_blocks; |
| 187 | hfsplus_extent_rec extents; |
| 188 | } __packed; |
| 189 | |
| 190 | struct hfs_mdb { |
| 191 | __be16 drSigWord; /* Signature word indicating fs type */ |
| 192 | __be32 drCrDate; /* fs creation date/time */ |
| 193 | __be32 drLsMod; /* fs modification date/time */ |
| 194 | __be16 drAtrb; /* fs attributes */ |
| 195 | __be16 drNmFls; /* number of files in root directory */ |
| 196 | __be16 drVBMSt; /* location (in 512-byte blocks) |
| 197 | of the volume bitmap */ |
| 198 | __be16 drAllocPtr; /* location (in allocation blocks) |
| 199 | to begin next allocation search */ |
| 200 | __be16 drNmAlBlks; /* number of allocation blocks */ |
| 201 | __be32 drAlBlkSiz; /* bytes in an allocation block */ |
| 202 | __be32 drClpSiz; /* clumpsize, the number of bytes to |
| 203 | allocate when extending a file */ |
| 204 | __be16 drAlBlSt; /* location (in 512-byte blocks) |
| 205 | of the first allocation block */ |
| 206 | __be32 drNxtCNID; /* CNID to assign to the next |
| 207 | file or directory created */ |
| 208 | __be16 drFreeBks; /* number of free allocation blocks */ |
| 209 | u8 drVN[28]; /* the volume label */ |
| 210 | __be32 drVolBkUp; /* fs backup date/time */ |
| 211 | __be16 drVSeqNum; /* backup sequence number */ |
| 212 | __be32 drWrCnt; /* fs write count */ |
| 213 | __be32 drXTClpSiz; /* clumpsize for the extents B-tree */ |
| 214 | __be32 drCTClpSiz; /* clumpsize for the catalog B-tree */ |
| 215 | __be16 drNmRtDirs; /* number of directories in |
| 216 | the root directory */ |
| 217 | __be32 drFilCnt; /* number of files in the fs */ |
| 218 | __be32 drDirCnt; /* number of directories in the fs */ |
| 219 | u8 drFndrInfo[32]; /* data used by the Finder */ |
| 220 | __be16 drEmbedSigWord; /* embedded volume signature */ |
| 221 | __be32 drEmbedExtent; /* starting block number (xdrStABN) |
| 222 | and number of allocation blocks |
| 223 | (xdrNumABlks) occupied by embedded |
| 224 | volume */ |
| 225 | __be32 drXTFlSize; /* bytes in the extents B-tree */ |
| 226 | hfs_extent_rec drXTExtRec; /* extents B-tree's first 3 extents */ |
| 227 | __be32 drCTFlSize; /* bytes in the catalog B-tree */ |
| 228 | hfs_extent_rec drCTExtRec; /* catalog B-tree's first 3 extents */ |
| 229 | } __packed; |
| 230 | |
| 231 | /* HFS+ Volume Header */ |
| 232 | struct hfsplus_vh { |
| 233 | __be16 signature; |
| 234 | __be16 version; |
| 235 | __be32 attributes; |
| 236 | __be32 last_mount_vers; |
| 237 | u32 reserved; |
| 238 | |
| 239 | __be32 create_date; |
| 240 | __be32 modify_date; |
| 241 | __be32 backup_date; |
| 242 | __be32 checked_date; |
| 243 | |
| 244 | __be32 file_count; |
| 245 | __be32 folder_count; |
| 246 | |
| 247 | __be32 blocksize; |
| 248 | __be32 total_blocks; |
| 249 | __be32 free_blocks; |
| 250 | |
| 251 | __be32 next_alloc; |
| 252 | __be32 rsrc_clump_sz; |
| 253 | __be32 data_clump_sz; |
| 254 | hfsplus_cnid next_cnid; |
| 255 | |
| 256 | __be32 write_count; |
| 257 | __be64 encodings_bmp; |
| 258 | |
| 259 | u32 finder_info[8]; |
| 260 | |
| 261 | struct hfsplus_fork_raw alloc_file; |
| 262 | struct hfsplus_fork_raw ext_file; |
| 263 | struct hfsplus_fork_raw cat_file; |
| 264 | struct hfsplus_fork_raw attr_file; |
| 265 | struct hfsplus_fork_raw start_file; |
| 266 | } __packed; |
| 267 | |
| 268 | /* HFS+ volume attributes */ |
| 269 | #define HFSPLUS_VOL_UNMNT (1 << 8) |
| 270 | #define HFSPLUS_VOL_SPARE_BLK (1 << 9) |
| 271 | #define HFSPLUS_VOL_NOCACHE (1 << 10) |
| 272 | #define HFSPLUS_VOL_INCNSTNT (1 << 11) |
| 273 | #define HFSPLUS_VOL_NODEID_REUSED (1 << 12) |
| 274 | #define HFSPLUS_VOL_JOURNALED (1 << 13) |
| 275 | #define HFSPLUS_VOL_SOFTLOCK (1 << 15) |
| 276 | #define HFSPLUS_VOL_UNUSED_NODE_FIX (1 << 31) |
| 277 | |
| 278 | struct hfs_point { |
| 279 | __be16 v; |
| 280 | __be16 h; |
| 281 | } __packed; |
| 282 | |
| 283 | typedef struct hfs_point hfsp_point; |
| 284 | |
| 285 | struct hfs_rect { |
| 286 | __be16 top; |
| 287 | __be16 left; |
| 288 | __be16 bottom; |
| 289 | __be16 right; |
| 290 | } __packed; |
| 291 | |
| 292 | typedef struct hfs_rect hfsp_rect; |
| 293 | |
| 294 | struct hfs_finfo { |
| 295 | __be32 fdType; |
| 296 | __be32 fdCreator; |
| 297 | __be16 fdFlags; |
| 298 | struct hfs_point fdLocation; |
| 299 | __be16 fdFldr; |
| 300 | } __packed; |
| 301 | |
| 302 | typedef struct hfs_finfo FInfo; |
| 303 | |
| 304 | struct hfs_fxinfo { |
| 305 | __be16 fdIconID; |
| 306 | u8 fdUnused[8]; |
| 307 | __be16 ; |
| 308 | __be32 fdPutAway; |
| 309 | } __packed; |
| 310 | |
| 311 | typedef struct hfs_fxinfo FXInfo; |
| 312 | |
| 313 | struct hfs_dinfo { |
| 314 | struct hfs_rect frRect; |
| 315 | __be16 frFlags; |
| 316 | struct hfs_point frLocation; |
| 317 | __be16 frView; |
| 318 | } __packed; |
| 319 | |
| 320 | typedef struct hfs_dinfo DInfo; |
| 321 | |
| 322 | struct hfs_dxinfo { |
| 323 | struct hfs_point frScroll; |
| 324 | __be32 frOpenChain; |
| 325 | __be16 frUnused; |
| 326 | __be16 ; |
| 327 | __be32 frPutAway; |
| 328 | } __packed; |
| 329 | |
| 330 | typedef struct hfs_dxinfo DXInfo; |
| 331 | |
| 332 | union hfs_finder_info { |
| 333 | struct { |
| 334 | struct hfs_finfo finfo; |
| 335 | struct hfs_fxinfo fxinfo; |
| 336 | } file; |
| 337 | struct { |
| 338 | struct hfs_dinfo dinfo; |
| 339 | struct hfs_dxinfo dxinfo; |
| 340 | } dir; |
| 341 | } __packed; |
| 342 | |
| 343 | /* The key used in the catalog b-tree: */ |
| 344 | struct hfs_cat_key { |
| 345 | u8 key_len; /* number of bytes in the key */ |
| 346 | u8 reserved; /* padding */ |
| 347 | __be32 ParID; /* CNID of the parent dir */ |
| 348 | struct hfs_name CName; /* The filename of the entry */ |
| 349 | } __packed; |
| 350 | |
| 351 | /* HFS+ catalog entry key */ |
| 352 | struct hfsplus_cat_key { |
| 353 | __be16 key_len; |
| 354 | hfsplus_cnid parent; |
| 355 | struct hfsplus_unistr name; |
| 356 | } __packed; |
| 357 | |
| 358 | #define HFSPLUS_CAT_KEYLEN (sizeof(struct hfsplus_cat_key)) |
| 359 | |
| 360 | /* The key used in the extents b-tree: */ |
| 361 | struct hfs_ext_key { |
| 362 | u8 key_len; /* number of bytes in the key */ |
| 363 | u8 FkType; /* HFS_FK_{DATA,RSRC} */ |
| 364 | __be32 FNum; /* The File ID of the file */ |
| 365 | __be16 FABN; /* allocation blocks number*/ |
| 366 | } __packed; |
| 367 | |
| 368 | /* HFS+ extents tree key */ |
| 369 | struct hfsplus_ext_key { |
| 370 | __be16 key_len; |
| 371 | u8 fork_type; |
| 372 | u8 pad; |
| 373 | hfsplus_cnid cnid; |
| 374 | __be32 start_block; |
| 375 | } __packed; |
| 376 | |
| 377 | #define HFSPLUS_EXT_KEYLEN sizeof(struct hfsplus_ext_key) |
| 378 | |
| 379 | typedef union hfs_btree_key { |
| 380 | u8 key_len; /* number of bytes in the key */ |
| 381 | struct hfs_cat_key cat; |
| 382 | struct hfs_ext_key ext; |
| 383 | } hfs_btree_key; |
| 384 | |
| 385 | #define HFS_MAX_CAT_KEYLEN (sizeof(struct hfs_cat_key) - sizeof(u8)) |
| 386 | #define HFS_MAX_EXT_KEYLEN (sizeof(struct hfs_ext_key) - sizeof(u8)) |
| 387 | |
| 388 | typedef union hfs_btree_key btree_key; |
| 389 | |
| 390 | /* The catalog record for a file */ |
| 391 | struct hfs_cat_file { |
| 392 | s8 type; /* The type of entry */ |
| 393 | u8 reserved; |
| 394 | u8 Flags; /* Flags such as read-only */ |
| 395 | s8 Typ; /* file version number = 0 */ |
| 396 | struct hfs_finfo UsrWds; /* data used by the Finder */ |
| 397 | __be32 FlNum; /* The CNID */ |
| 398 | __be16 StBlk; /* obsolete */ |
| 399 | __be32 LgLen; /* The logical EOF of the data fork*/ |
| 400 | __be32 PyLen; /* The physical EOF of the data fork */ |
| 401 | __be16 RStBlk; /* obsolete */ |
| 402 | __be32 RLgLen; /* The logical EOF of the rsrc fork */ |
| 403 | __be32 RPyLen; /* The physical EOF of the rsrc fork */ |
| 404 | __be32 CrDat; /* The creation date */ |
| 405 | __be32 MdDat; /* The modified date */ |
| 406 | __be32 BkDat; /* The last backup date */ |
| 407 | struct hfs_fxinfo FndrInfo; /* more data for the Finder */ |
| 408 | __be16 ClpSize; /* number of bytes to allocate |
| 409 | when extending files */ |
| 410 | hfs_extent_rec ExtRec; /* first extent record |
| 411 | for the data fork */ |
| 412 | hfs_extent_rec RExtRec; /* first extent record |
| 413 | for the resource fork */ |
| 414 | u32 Resrv; /* reserved by Apple */ |
| 415 | } __packed; |
| 416 | |
| 417 | /* the catalog record for a directory */ |
| 418 | struct hfs_cat_dir { |
| 419 | s8 type; /* The type of entry */ |
| 420 | u8 reserved; |
| 421 | __be16 Flags; /* flags */ |
| 422 | __be16 Val; /* Valence: number of files and |
| 423 | dirs in the directory */ |
| 424 | __be32 DirID; /* The CNID */ |
| 425 | __be32 CrDat; /* The creation date */ |
| 426 | __be32 MdDat; /* The modification date */ |
| 427 | __be32 BkDat; /* The last backup date */ |
| 428 | struct hfs_dinfo UsrInfo; /* data used by the Finder */ |
| 429 | struct hfs_dxinfo FndrInfo; /* more data used by Finder */ |
| 430 | u8 Resrv[16]; /* reserved by Apple */ |
| 431 | } __packed; |
| 432 | |
| 433 | /* the catalog record for a thread */ |
| 434 | struct hfs_cat_thread { |
| 435 | s8 type; /* The type of entry */ |
| 436 | u8 reserved[9]; /* reserved by Apple */ |
| 437 | __be32 ParID; /* CNID of parent directory */ |
| 438 | struct hfs_name CName; /* The name of this entry */ |
| 439 | } __packed; |
| 440 | |
| 441 | /* A catalog tree record */ |
| 442 | typedef union hfs_cat_rec { |
| 443 | s8 type; /* The type of entry */ |
| 444 | struct hfs_cat_file file; |
| 445 | struct hfs_cat_dir dir; |
| 446 | struct hfs_cat_thread thread; |
| 447 | } hfs_cat_rec; |
| 448 | |
| 449 | /* POSIX permissions */ |
| 450 | struct hfsplus_perm { |
| 451 | __be32 owner; |
| 452 | __be32 group; |
| 453 | u8 rootflags; |
| 454 | u8 userflags; |
| 455 | __be16 mode; |
| 456 | __be32 dev; |
| 457 | } __packed; |
| 458 | |
| 459 | #define HFSPLUS_FLG_NODUMP 0x01 |
| 460 | #define HFSPLUS_FLG_IMMUTABLE 0x02 |
| 461 | #define HFSPLUS_FLG_APPEND 0x04 |
| 462 | |
| 463 | /* HFS/HFS+ BTree node descriptor */ |
| 464 | struct hfs_bnode_desc { |
| 465 | __be32 next; /* (V) Number of the next node at this level */ |
| 466 | __be32 prev; /* (V) Number of the prev node at this level */ |
| 467 | u8 type; /* (F) The type of node */ |
| 468 | u8 height; /* (F) The level of this node (leaves=1) */ |
| 469 | __be16 num_recs; /* (V) The number of records in this node */ |
| 470 | u16 reserved; |
| 471 | } __packed; |
| 472 | |
| 473 | /* HFS/HFS+ BTree node types */ |
| 474 | #define HFS_NODE_INDEX 0x00 /* An internal (index) node */ |
| 475 | #define 0x01 /* The tree header node (node 0) */ |
| 476 | #define HFS_NODE_MAP 0x02 /* Holds part of the bitmap of used nodes */ |
| 477 | #define HFS_NODE_LEAF 0xFF /* A leaf (ndNHeight==1) node */ |
| 478 | |
| 479 | /* HFS/HFS+ BTree header */ |
| 480 | struct { |
| 481 | __be16 ; /* (V) The number of levels in this B-tree */ |
| 482 | __be32 ; /* (V) The node number of the root node */ |
| 483 | __be32 ; /* (V) The number of leaf records */ |
| 484 | __be32 ; /* (V) The number of the first leaf node */ |
| 485 | __be32 ; /* (V) The number of the last leaf node */ |
| 486 | __be16 ; /* (F) The number of bytes in a node (=512) */ |
| 487 | __be16 ; /* (F) The length of a key in an index node */ |
| 488 | __be32 ; /* (V) The total number of nodes */ |
| 489 | __be32 ; /* (V) The number of unused nodes */ |
| 490 | u16 ; |
| 491 | __be32 ; /* (F) clump size. not usually used. */ |
| 492 | u8 ; /* (F) BTree type */ |
| 493 | u8 ; |
| 494 | __be32 ; /* (F) attributes */ |
| 495 | u32 [16]; |
| 496 | } __packed; |
| 497 | |
| 498 | /* BTree attributes */ |
| 499 | #define BTREE_ATTR_BADCLOSE 0x00000001 /* b-tree not closed properly. not |
| 500 | used by hfsplus. */ |
| 501 | #define HFS_TREE_BIGKEYS 0x00000002 /* key length is u16 instead of u8. |
| 502 | used by hfsplus. */ |
| 503 | #define HFS_TREE_VARIDXKEYS 0x00000004 /* variable key length instead of |
| 504 | max key length. use din catalog |
| 505 | b-tree but not in extents |
| 506 | b-tree (hfsplus). */ |
| 507 | |
| 508 | /* HFS+ BTree misc info */ |
| 509 | #define HFSPLUS_TREE_HEAD 0 |
| 510 | #define HFSPLUS_NODE_MXSZ 32768 |
| 511 | #define HFSPLUS_ATTR_TREE_NODE_SIZE 8192 |
| 512 | #define HFSPLUS_BTREE_HDR_NODE_RECS_COUNT 3 |
| 513 | #define HFSPLUS_BTREE_HDR_USER_BYTES 128 |
| 514 | |
| 515 | /* btree key type */ |
| 516 | #define HFSPLUS_KEY_CASEFOLDING 0xCF /* case-insensitive */ |
| 517 | #define HFSPLUS_KEY_BINARY 0xBC /* case-sensitive */ |
| 518 | |
| 519 | /* HFS+ folder data (part of an hfsplus_cat_entry) */ |
| 520 | struct hfsplus_cat_folder { |
| 521 | __be16 type; |
| 522 | __be16 flags; |
| 523 | __be32 valence; |
| 524 | hfsplus_cnid id; |
| 525 | __be32 create_date; |
| 526 | __be32 content_mod_date; |
| 527 | __be32 attribute_mod_date; |
| 528 | __be32 access_date; |
| 529 | __be32 backup_date; |
| 530 | struct hfsplus_perm permissions; |
| 531 | struct_group_attr(info, __packed, |
| 532 | DInfo user_info; |
| 533 | DXInfo finder_info; |
| 534 | ); |
| 535 | __be32 text_encoding; |
| 536 | __be32 subfolders; /* Subfolder count in HFSX. Reserved in HFS+. */ |
| 537 | } __packed; |
| 538 | |
| 539 | /* HFS+ file data (part of a cat_entry) */ |
| 540 | struct hfsplus_cat_file { |
| 541 | __be16 type; |
| 542 | __be16 flags; |
| 543 | u32 reserved1; |
| 544 | hfsplus_cnid id; |
| 545 | __be32 create_date; |
| 546 | __be32 content_mod_date; |
| 547 | __be32 attribute_mod_date; |
| 548 | __be32 access_date; |
| 549 | __be32 backup_date; |
| 550 | struct hfsplus_perm permissions; |
| 551 | struct_group_attr(info, __packed, |
| 552 | FInfo user_info; |
| 553 | FXInfo finder_info; |
| 554 | ); |
| 555 | __be32 text_encoding; |
| 556 | u32 reserved2; |
| 557 | |
| 558 | struct hfsplus_fork_raw data_fork; |
| 559 | struct hfsplus_fork_raw rsrc_fork; |
| 560 | } __packed; |
| 561 | |
| 562 | /* File and folder flag bits */ |
| 563 | #define HFSPLUS_FILE_LOCKED 0x0001 |
| 564 | #define HFSPLUS_FILE_THREAD_EXISTS 0x0002 |
| 565 | #define HFSPLUS_XATTR_EXISTS 0x0004 |
| 566 | #define HFSPLUS_ACL_EXISTS 0x0008 |
| 567 | #define HFSPLUS_HAS_FOLDER_COUNT 0x0010 /* Folder has subfolder count |
| 568 | * (HFSX only) */ |
| 569 | |
| 570 | /* HFS+ catalog thread (part of a cat_entry) */ |
| 571 | struct hfsplus_cat_thread { |
| 572 | __be16 type; |
| 573 | s16 reserved; |
| 574 | hfsplus_cnid parentID; |
| 575 | struct hfsplus_unistr nodeName; |
| 576 | } __packed; |
| 577 | |
| 578 | #define HFSPLUS_MIN_THREAD_SZ 10 |
| 579 | |
| 580 | /* A data record in the catalog tree */ |
| 581 | typedef union { |
| 582 | __be16 type; |
| 583 | struct hfsplus_cat_folder folder; |
| 584 | struct hfsplus_cat_file file; |
| 585 | struct hfsplus_cat_thread thread; |
| 586 | } __packed hfsplus_cat_entry; |
| 587 | |
| 588 | /* HFS+ catalog entry type */ |
| 589 | #define HFSPLUS_FOLDER 0x0001 |
| 590 | #define HFSPLUS_FILE 0x0002 |
| 591 | #define HFSPLUS_FOLDER_THREAD 0x0003 |
| 592 | #define HFSPLUS_FILE_THREAD 0x0004 |
| 593 | |
| 594 | #define HFSPLUS_XATTR_FINDER_INFO_NAME "com.apple.FinderInfo" |
| 595 | #define HFSPLUS_XATTR_ACL_NAME "com.apple.system.Security" |
| 596 | |
| 597 | #define HFSPLUS_ATTR_INLINE_DATA 0x10 |
| 598 | #define HFSPLUS_ATTR_FORK_DATA 0x20 |
| 599 | #define HFSPLUS_ATTR_EXTENTS 0x30 |
| 600 | |
| 601 | /* HFS+ attributes tree key */ |
| 602 | struct hfsplus_attr_key { |
| 603 | __be16 key_len; |
| 604 | __be16 pad; |
| 605 | hfsplus_cnid cnid; |
| 606 | __be32 start_block; |
| 607 | struct hfsplus_attr_unistr key_name; |
| 608 | } __packed; |
| 609 | |
| 610 | #define HFSPLUS_ATTR_KEYLEN sizeof(struct hfsplus_attr_key) |
| 611 | |
| 612 | /* HFS+ fork data attribute */ |
| 613 | struct hfsplus_attr_fork_data { |
| 614 | __be32 record_type; |
| 615 | __be32 reserved; |
| 616 | struct hfsplus_fork_raw the_fork; |
| 617 | } __packed; |
| 618 | |
| 619 | /* HFS+ extension attribute */ |
| 620 | struct hfsplus_attr_extents { |
| 621 | __be32 record_type; |
| 622 | __be32 reserved; |
| 623 | struct hfsplus_extent extents; |
| 624 | } __packed; |
| 625 | |
| 626 | #define HFSPLUS_MAX_INLINE_DATA_SIZE 3802 |
| 627 | |
| 628 | /* HFS+ attribute inline data */ |
| 629 | struct hfsplus_attr_inline_data { |
| 630 | __be32 record_type; |
| 631 | __be32 reserved1; |
| 632 | u8 reserved2[6]; |
| 633 | __be16 length; |
| 634 | u8 raw_bytes[HFSPLUS_MAX_INLINE_DATA_SIZE]; |
| 635 | } __packed; |
| 636 | |
| 637 | /* A data record in the attributes tree */ |
| 638 | typedef union { |
| 639 | __be32 record_type; |
| 640 | struct hfsplus_attr_fork_data fork_data; |
| 641 | struct hfsplus_attr_extents extents; |
| 642 | struct hfsplus_attr_inline_data inline_data; |
| 643 | } __packed hfsplus_attr_entry; |
| 644 | |
| 645 | /* HFS+ generic BTree key */ |
| 646 | typedef union { |
| 647 | __be16 key_len; |
| 648 | struct hfsplus_cat_key cat; |
| 649 | struct hfsplus_ext_key ext; |
| 650 | struct hfsplus_attr_key attr; |
| 651 | } __packed hfsplus_btree_key; |
| 652 | |
| 653 | #endif /* _HFS_COMMON_H_ */ |
| 654 | |