162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci *  linux/fs/hfs/hfs.h
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * Copyright (C) 1995-1997  Paul H. Hargrove
562306a36Sopenharmony_ci * (C) 2003 Ardis Technologies <roman@ardistech.com>
662306a36Sopenharmony_ci * This file may be distributed under the terms of the GNU General Public License.
762306a36Sopenharmony_ci */
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#ifndef _HFS_H
1062306a36Sopenharmony_ci#define _HFS_H
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci/* offsets to various blocks */
1362306a36Sopenharmony_ci#define HFS_DD_BLK		0 /* Driver Descriptor block */
1462306a36Sopenharmony_ci#define HFS_PMAP_BLK		1 /* First block of partition map */
1562306a36Sopenharmony_ci#define HFS_MDB_BLK		2 /* Block (w/i partition) of MDB */
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_ci/* magic numbers for various disk blocks */
1862306a36Sopenharmony_ci#define HFS_DRVR_DESC_MAGIC	0x4552 /* "ER": driver descriptor map */
1962306a36Sopenharmony_ci#define HFS_OLD_PMAP_MAGIC	0x5453 /* "TS": old-type partition map */
2062306a36Sopenharmony_ci#define HFS_NEW_PMAP_MAGIC	0x504D /* "PM": new-type partition map */
2162306a36Sopenharmony_ci#define HFS_SUPER_MAGIC		0x4244 /* "BD": HFS MDB (super block) */
2262306a36Sopenharmony_ci#define HFS_MFS_SUPER_MAGIC	0xD2D7 /* MFS MDB (super block) */
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ci/* various FIXED size parameters */
2562306a36Sopenharmony_ci#define HFS_SECTOR_SIZE		512    /* size of an HFS sector */
2662306a36Sopenharmony_ci#define HFS_SECTOR_SIZE_BITS	9      /* log_2(HFS_SECTOR_SIZE) */
2762306a36Sopenharmony_ci#define HFS_NAMELEN		31     /* maximum length of an HFS filename */
2862306a36Sopenharmony_ci#define HFS_MAX_NAMELEN		128
2962306a36Sopenharmony_ci#define HFS_MAX_VALENCE		32767U
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_ci/* Meanings of the drAtrb field of the MDB,
3262306a36Sopenharmony_ci * Reference: _Inside Macintosh: Files_ p. 2-61
3362306a36Sopenharmony_ci */
3462306a36Sopenharmony_ci#define HFS_SB_ATTRIB_HLOCK	(1 << 7)
3562306a36Sopenharmony_ci#define HFS_SB_ATTRIB_UNMNT	(1 << 8)
3662306a36Sopenharmony_ci#define HFS_SB_ATTRIB_SPARED	(1 << 9)
3762306a36Sopenharmony_ci#define HFS_SB_ATTRIB_INCNSTNT	(1 << 11)
3862306a36Sopenharmony_ci#define HFS_SB_ATTRIB_SLOCK	(1 << 15)
3962306a36Sopenharmony_ci
4062306a36Sopenharmony_ci/* Some special File ID numbers */
4162306a36Sopenharmony_ci#define HFS_POR_CNID		1	/* Parent Of the Root */
4262306a36Sopenharmony_ci#define HFS_ROOT_CNID		2	/* ROOT directory */
4362306a36Sopenharmony_ci#define HFS_EXT_CNID		3	/* EXTents B-tree */
4462306a36Sopenharmony_ci#define HFS_CAT_CNID		4	/* CATalog B-tree */
4562306a36Sopenharmony_ci#define HFS_BAD_CNID		5	/* BAD blocks file */
4662306a36Sopenharmony_ci#define HFS_ALLOC_CNID		6	/* ALLOCation file (HFS+) */
4762306a36Sopenharmony_ci#define HFS_START_CNID		7	/* STARTup file (HFS+) */
4862306a36Sopenharmony_ci#define HFS_ATTR_CNID		8	/* ATTRibutes file (HFS+) */
4962306a36Sopenharmony_ci#define HFS_EXCH_CNID		15	/* ExchangeFiles temp id */
5062306a36Sopenharmony_ci#define HFS_FIRSTUSER_CNID	16
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ci/* values for hfs_cat_rec.cdrType */
5362306a36Sopenharmony_ci#define HFS_CDR_DIR    0x01    /* folder (directory) */
5462306a36Sopenharmony_ci#define HFS_CDR_FIL    0x02    /* file */
5562306a36Sopenharmony_ci#define HFS_CDR_THD    0x03    /* folder (directory) thread */
5662306a36Sopenharmony_ci#define HFS_CDR_FTH    0x04    /* file thread */
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ci/* legal values for hfs_ext_key.FkType and hfs_file.fork */
5962306a36Sopenharmony_ci#define HFS_FK_DATA	0x00
6062306a36Sopenharmony_ci#define HFS_FK_RSRC	0xFF
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ci/* bits in hfs_fil_entry.Flags */
6362306a36Sopenharmony_ci#define HFS_FIL_LOCK	0x01  /* locked */
6462306a36Sopenharmony_ci#define HFS_FIL_THD	0x02  /* file thread */
6562306a36Sopenharmony_ci#define HFS_FIL_DOPEN   0x04  /* data fork open */
6662306a36Sopenharmony_ci#define HFS_FIL_ROPEN   0x08  /* resource fork open */
6762306a36Sopenharmony_ci#define HFS_FIL_DIR     0x10  /* directory (always clear) */
6862306a36Sopenharmony_ci#define HFS_FIL_NOCOPY  0x40  /* copy-protected file */
6962306a36Sopenharmony_ci#define HFS_FIL_USED	0x80  /* open */
7062306a36Sopenharmony_ci
7162306a36Sopenharmony_ci/* bits in hfs_dir_entry.Flags. dirflags is 16 bits. */
7262306a36Sopenharmony_ci#define HFS_DIR_LOCK        0x01  /* locked */
7362306a36Sopenharmony_ci#define HFS_DIR_THD         0x02  /* directory thread */
7462306a36Sopenharmony_ci#define HFS_DIR_INEXPFOLDER 0x04  /* in a shared area */
7562306a36Sopenharmony_ci#define HFS_DIR_MOUNTED     0x08  /* mounted */
7662306a36Sopenharmony_ci#define HFS_DIR_DIR         0x10  /* directory (always set) */
7762306a36Sopenharmony_ci#define HFS_DIR_EXPFOLDER   0x20  /* share point */
7862306a36Sopenharmony_ci
7962306a36Sopenharmony_ci/* bits hfs_finfo.fdFlags */
8062306a36Sopenharmony_ci#define HFS_FLG_INITED		0x0100
8162306a36Sopenharmony_ci#define HFS_FLG_LOCKED		0x1000
8262306a36Sopenharmony_ci#define HFS_FLG_INVISIBLE	0x4000
8362306a36Sopenharmony_ci
8462306a36Sopenharmony_ci/*======== HFS structures as they appear on the disk ========*/
8562306a36Sopenharmony_ci
8662306a36Sopenharmony_ci/* Pascal-style string of up to 31 characters */
8762306a36Sopenharmony_cistruct hfs_name {
8862306a36Sopenharmony_ci	u8 len;
8962306a36Sopenharmony_ci	u8 name[HFS_NAMELEN];
9062306a36Sopenharmony_ci} __packed;
9162306a36Sopenharmony_ci
9262306a36Sopenharmony_cistruct hfs_point {
9362306a36Sopenharmony_ci	__be16 v;
9462306a36Sopenharmony_ci	__be16 h;
9562306a36Sopenharmony_ci} __packed;
9662306a36Sopenharmony_ci
9762306a36Sopenharmony_cistruct hfs_rect {
9862306a36Sopenharmony_ci	__be16 top;
9962306a36Sopenharmony_ci	__be16 left;
10062306a36Sopenharmony_ci	__be16 bottom;
10162306a36Sopenharmony_ci	__be16 right;
10262306a36Sopenharmony_ci} __packed;
10362306a36Sopenharmony_ci
10462306a36Sopenharmony_cistruct hfs_finfo {
10562306a36Sopenharmony_ci	__be32 fdType;
10662306a36Sopenharmony_ci	__be32 fdCreator;
10762306a36Sopenharmony_ci	__be16 fdFlags;
10862306a36Sopenharmony_ci	struct hfs_point fdLocation;
10962306a36Sopenharmony_ci	__be16 fdFldr;
11062306a36Sopenharmony_ci} __packed;
11162306a36Sopenharmony_ci
11262306a36Sopenharmony_cistruct hfs_fxinfo {
11362306a36Sopenharmony_ci	__be16 fdIconID;
11462306a36Sopenharmony_ci	u8 fdUnused[8];
11562306a36Sopenharmony_ci	__be16 fdComment;
11662306a36Sopenharmony_ci	__be32 fdPutAway;
11762306a36Sopenharmony_ci} __packed;
11862306a36Sopenharmony_ci
11962306a36Sopenharmony_cistruct hfs_dinfo {
12062306a36Sopenharmony_ci	struct hfs_rect frRect;
12162306a36Sopenharmony_ci	__be16 frFlags;
12262306a36Sopenharmony_ci	struct hfs_point frLocation;
12362306a36Sopenharmony_ci	__be16 frView;
12462306a36Sopenharmony_ci} __packed;
12562306a36Sopenharmony_ci
12662306a36Sopenharmony_cistruct hfs_dxinfo {
12762306a36Sopenharmony_ci	struct hfs_point frScroll;
12862306a36Sopenharmony_ci	__be32 frOpenChain;
12962306a36Sopenharmony_ci	__be16 frUnused;
13062306a36Sopenharmony_ci	__be16 frComment;
13162306a36Sopenharmony_ci	__be32 frPutAway;
13262306a36Sopenharmony_ci} __packed;
13362306a36Sopenharmony_ci
13462306a36Sopenharmony_ciunion hfs_finder_info {
13562306a36Sopenharmony_ci	struct {
13662306a36Sopenharmony_ci		struct hfs_finfo finfo;
13762306a36Sopenharmony_ci		struct hfs_fxinfo fxinfo;
13862306a36Sopenharmony_ci	} file;
13962306a36Sopenharmony_ci	struct {
14062306a36Sopenharmony_ci		struct hfs_dinfo dinfo;
14162306a36Sopenharmony_ci		struct hfs_dxinfo dxinfo;
14262306a36Sopenharmony_ci	} dir;
14362306a36Sopenharmony_ci} __packed;
14462306a36Sopenharmony_ci
14562306a36Sopenharmony_ci/* Cast to a pointer to a generic bkey */
14662306a36Sopenharmony_ci#define	HFS_BKEY(X)	(((void)((X)->KeyLen)), ((struct hfs_bkey *)(X)))
14762306a36Sopenharmony_ci
14862306a36Sopenharmony_ci/* The key used in the catalog b-tree: */
14962306a36Sopenharmony_cistruct hfs_cat_key {
15062306a36Sopenharmony_ci	u8 key_len;		/* number of bytes in the key */
15162306a36Sopenharmony_ci	u8 reserved;		/* padding */
15262306a36Sopenharmony_ci	__be32 ParID;		/* CNID of the parent dir */
15362306a36Sopenharmony_ci	struct hfs_name	CName;	/* The filename of the entry */
15462306a36Sopenharmony_ci} __packed;
15562306a36Sopenharmony_ci
15662306a36Sopenharmony_ci/* The key used in the extents b-tree: */
15762306a36Sopenharmony_cistruct hfs_ext_key {
15862306a36Sopenharmony_ci	u8 key_len;		/* number of bytes in the key */
15962306a36Sopenharmony_ci	u8 FkType;		/* HFS_FK_{DATA,RSRC} */
16062306a36Sopenharmony_ci	__be32 FNum;		/* The File ID of the file */
16162306a36Sopenharmony_ci	__be16 FABN;		/* allocation blocks number*/
16262306a36Sopenharmony_ci} __packed;
16362306a36Sopenharmony_ci
16462306a36Sopenharmony_citypedef union hfs_btree_key {
16562306a36Sopenharmony_ci	u8 key_len;			/* number of bytes in the key */
16662306a36Sopenharmony_ci	struct hfs_cat_key cat;
16762306a36Sopenharmony_ci	struct hfs_ext_key ext;
16862306a36Sopenharmony_ci} hfs_btree_key;
16962306a36Sopenharmony_ci
17062306a36Sopenharmony_ci#define HFS_MAX_CAT_KEYLEN	(sizeof(struct hfs_cat_key) - sizeof(u8))
17162306a36Sopenharmony_ci#define HFS_MAX_EXT_KEYLEN	(sizeof(struct hfs_ext_key) - sizeof(u8))
17262306a36Sopenharmony_ci
17362306a36Sopenharmony_citypedef union hfs_btree_key btree_key;
17462306a36Sopenharmony_ci
17562306a36Sopenharmony_cistruct hfs_extent {
17662306a36Sopenharmony_ci	__be16 block;
17762306a36Sopenharmony_ci	__be16 count;
17862306a36Sopenharmony_ci};
17962306a36Sopenharmony_citypedef struct hfs_extent hfs_extent_rec[3];
18062306a36Sopenharmony_ci
18162306a36Sopenharmony_ci/* The catalog record for a file */
18262306a36Sopenharmony_cistruct hfs_cat_file {
18362306a36Sopenharmony_ci	s8 type;			/* The type of entry */
18462306a36Sopenharmony_ci	u8 reserved;
18562306a36Sopenharmony_ci	u8 Flags;			/* Flags such as read-only */
18662306a36Sopenharmony_ci	s8 Typ;				/* file version number = 0 */
18762306a36Sopenharmony_ci	struct hfs_finfo UsrWds;	/* data used by the Finder */
18862306a36Sopenharmony_ci	__be32 FlNum;			/* The CNID */
18962306a36Sopenharmony_ci	__be16 StBlk;			/* obsolete */
19062306a36Sopenharmony_ci	__be32 LgLen;			/* The logical EOF of the data fork*/
19162306a36Sopenharmony_ci	__be32 PyLen;			/* The physical EOF of the data fork */
19262306a36Sopenharmony_ci	__be16 RStBlk;			/* obsolete */
19362306a36Sopenharmony_ci	__be32 RLgLen;			/* The logical EOF of the rsrc fork */
19462306a36Sopenharmony_ci	__be32 RPyLen;			/* The physical EOF of the rsrc fork */
19562306a36Sopenharmony_ci	__be32 CrDat;			/* The creation date */
19662306a36Sopenharmony_ci	__be32 MdDat;			/* The modified date */
19762306a36Sopenharmony_ci	__be32 BkDat;			/* The last backup date */
19862306a36Sopenharmony_ci	struct hfs_fxinfo FndrInfo;	/* more data for the Finder */
19962306a36Sopenharmony_ci	__be16 ClpSize;			/* number of bytes to allocate
20062306a36Sopenharmony_ci					   when extending files */
20162306a36Sopenharmony_ci	hfs_extent_rec ExtRec;		/* first extent record
20262306a36Sopenharmony_ci					   for the data fork */
20362306a36Sopenharmony_ci	hfs_extent_rec RExtRec;		/* first extent record
20462306a36Sopenharmony_ci					   for the resource fork */
20562306a36Sopenharmony_ci	u32 Resrv;			/* reserved by Apple */
20662306a36Sopenharmony_ci} __packed;
20762306a36Sopenharmony_ci
20862306a36Sopenharmony_ci/* the catalog record for a directory */
20962306a36Sopenharmony_cistruct hfs_cat_dir {
21062306a36Sopenharmony_ci	s8 type;			/* The type of entry */
21162306a36Sopenharmony_ci	u8 reserved;
21262306a36Sopenharmony_ci	__be16 Flags;			/* flags */
21362306a36Sopenharmony_ci	__be16 Val;			/* Valence: number of files and
21462306a36Sopenharmony_ci					   dirs in the directory */
21562306a36Sopenharmony_ci	__be32 DirID;			/* The CNID */
21662306a36Sopenharmony_ci	__be32 CrDat;			/* The creation date */
21762306a36Sopenharmony_ci	__be32 MdDat;			/* The modification date */
21862306a36Sopenharmony_ci	__be32 BkDat;			/* The last backup date */
21962306a36Sopenharmony_ci	struct hfs_dinfo UsrInfo;	/* data used by the Finder */
22062306a36Sopenharmony_ci	struct hfs_dxinfo FndrInfo;	/* more data used by Finder */
22162306a36Sopenharmony_ci	u8 Resrv[16];			/* reserved by Apple */
22262306a36Sopenharmony_ci} __packed;
22362306a36Sopenharmony_ci
22462306a36Sopenharmony_ci/* the catalog record for a thread */
22562306a36Sopenharmony_cistruct hfs_cat_thread {
22662306a36Sopenharmony_ci	s8 type;			/* The type of entry */
22762306a36Sopenharmony_ci	u8 reserved[9];			/* reserved by Apple */
22862306a36Sopenharmony_ci	__be32 ParID;			/* CNID of parent directory */
22962306a36Sopenharmony_ci	struct hfs_name CName;		/* The name of this entry */
23062306a36Sopenharmony_ci}  __packed;
23162306a36Sopenharmony_ci
23262306a36Sopenharmony_ci/* A catalog tree record */
23362306a36Sopenharmony_citypedef union hfs_cat_rec {
23462306a36Sopenharmony_ci	s8 type;			/* The type of entry */
23562306a36Sopenharmony_ci	struct hfs_cat_file file;
23662306a36Sopenharmony_ci	struct hfs_cat_dir dir;
23762306a36Sopenharmony_ci	struct hfs_cat_thread thread;
23862306a36Sopenharmony_ci} hfs_cat_rec;
23962306a36Sopenharmony_ci
24062306a36Sopenharmony_cistruct hfs_mdb {
24162306a36Sopenharmony_ci	__be16 drSigWord;		/* Signature word indicating fs type */
24262306a36Sopenharmony_ci	__be32 drCrDate;		/* fs creation date/time */
24362306a36Sopenharmony_ci	__be32 drLsMod;			/* fs modification date/time */
24462306a36Sopenharmony_ci	__be16 drAtrb;			/* fs attributes */
24562306a36Sopenharmony_ci	__be16 drNmFls;			/* number of files in root directory */
24662306a36Sopenharmony_ci	__be16 drVBMSt;			/* location (in 512-byte blocks)
24762306a36Sopenharmony_ci					   of the volume bitmap */
24862306a36Sopenharmony_ci	__be16 drAllocPtr;		/* location (in allocation blocks)
24962306a36Sopenharmony_ci					   to begin next allocation search */
25062306a36Sopenharmony_ci	__be16 drNmAlBlks;		/* number of allocation blocks */
25162306a36Sopenharmony_ci	__be32 drAlBlkSiz;		/* bytes in an allocation block */
25262306a36Sopenharmony_ci	__be32 drClpSiz;		/* clumpsize, the number of bytes to
25362306a36Sopenharmony_ci					   allocate when extending a file */
25462306a36Sopenharmony_ci	__be16 drAlBlSt;		/* location (in 512-byte blocks)
25562306a36Sopenharmony_ci					   of the first allocation block */
25662306a36Sopenharmony_ci	__be32 drNxtCNID;		/* CNID to assign to the next
25762306a36Sopenharmony_ci					   file or directory created */
25862306a36Sopenharmony_ci	__be16 drFreeBks;		/* number of free allocation blocks */
25962306a36Sopenharmony_ci	u8 drVN[28];			/* the volume label */
26062306a36Sopenharmony_ci	__be32 drVolBkUp;		/* fs backup date/time */
26162306a36Sopenharmony_ci	__be16 drVSeqNum;		/* backup sequence number */
26262306a36Sopenharmony_ci	__be32 drWrCnt;			/* fs write count */
26362306a36Sopenharmony_ci	__be32 drXTClpSiz;		/* clumpsize for the extents B-tree */
26462306a36Sopenharmony_ci	__be32 drCTClpSiz;		/* clumpsize for the catalog B-tree */
26562306a36Sopenharmony_ci	__be16 drNmRtDirs;		/* number of directories in
26662306a36Sopenharmony_ci					   the root directory */
26762306a36Sopenharmony_ci	__be32 drFilCnt;		/* number of files in the fs */
26862306a36Sopenharmony_ci	__be32 drDirCnt;		/* number of directories in the fs */
26962306a36Sopenharmony_ci	u8 drFndrInfo[32];		/* data used by the Finder */
27062306a36Sopenharmony_ci	__be16 drEmbedSigWord;		/* embedded volume signature */
27162306a36Sopenharmony_ci	__be32 drEmbedExtent;		/* starting block number (xdrStABN)
27262306a36Sopenharmony_ci					   and number of allocation blocks
27362306a36Sopenharmony_ci					   (xdrNumABlks) occupied by embedded
27462306a36Sopenharmony_ci					   volume */
27562306a36Sopenharmony_ci	__be32 drXTFlSize;		/* bytes in the extents B-tree */
27662306a36Sopenharmony_ci	hfs_extent_rec drXTExtRec;	/* extents B-tree's first 3 extents */
27762306a36Sopenharmony_ci	__be32 drCTFlSize;		/* bytes in the catalog B-tree */
27862306a36Sopenharmony_ci	hfs_extent_rec drCTExtRec;	/* catalog B-tree's first 3 extents */
27962306a36Sopenharmony_ci} __packed;
28062306a36Sopenharmony_ci
28162306a36Sopenharmony_ci/*======== Data structures kept in memory ========*/
28262306a36Sopenharmony_ci
28362306a36Sopenharmony_cistruct hfs_readdir_data {
28462306a36Sopenharmony_ci	struct list_head list;
28562306a36Sopenharmony_ci	struct file *file;
28662306a36Sopenharmony_ci	struct hfs_cat_key key;
28762306a36Sopenharmony_ci};
28862306a36Sopenharmony_ci
28962306a36Sopenharmony_ci#endif
290