Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  *  linux/fs/hfs/hfs.h
0003  *
0004  * Copyright (C) 1995-1997  Paul H. Hargrove
0005  * (C) 2003 Ardis Technologies <roman@ardistech.com>
0006  * This file may be distributed under the terms of the GNU General Public License.
0007  */
0008 
0009 #ifndef _HFS_H
0010 #define _HFS_H
0011 
0012 /* offsets to various blocks */
0013 #define HFS_DD_BLK      0 /* Driver Descriptor block */
0014 #define HFS_PMAP_BLK        1 /* First block of partition map */
0015 #define HFS_MDB_BLK     2 /* Block (w/i partition) of MDB */
0016 
0017 /* magic numbers for various disk blocks */
0018 #define HFS_DRVR_DESC_MAGIC 0x4552 /* "ER": driver descriptor map */
0019 #define HFS_OLD_PMAP_MAGIC  0x5453 /* "TS": old-type partition map */
0020 #define HFS_NEW_PMAP_MAGIC  0x504D /* "PM": new-type partition map */
0021 #define HFS_SUPER_MAGIC     0x4244 /* "BD": HFS MDB (super block) */
0022 #define HFS_MFS_SUPER_MAGIC 0xD2D7 /* MFS MDB (super block) */
0023 
0024 /* various FIXED size parameters */
0025 #define HFS_SECTOR_SIZE     512    /* size of an HFS sector */
0026 #define HFS_SECTOR_SIZE_BITS    9      /* log_2(HFS_SECTOR_SIZE) */
0027 #define HFS_NAMELEN     31     /* maximum length of an HFS filename */
0028 #define HFS_MAX_NAMELEN     128
0029 #define HFS_MAX_VALENCE     32767U
0030 
0031 /* Meanings of the drAtrb field of the MDB,
0032  * Reference: _Inside Macintosh: Files_ p. 2-61
0033  */
0034 #define HFS_SB_ATTRIB_HLOCK (1 << 7)
0035 #define HFS_SB_ATTRIB_UNMNT (1 << 8)
0036 #define HFS_SB_ATTRIB_SPARED    (1 << 9)
0037 #define HFS_SB_ATTRIB_INCNSTNT  (1 << 11)
0038 #define HFS_SB_ATTRIB_SLOCK (1 << 15)
0039 
0040 /* Some special File ID numbers */
0041 #define HFS_POR_CNID        1   /* Parent Of the Root */
0042 #define HFS_ROOT_CNID       2   /* ROOT directory */
0043 #define HFS_EXT_CNID        3   /* EXTents B-tree */
0044 #define HFS_CAT_CNID        4   /* CATalog B-tree */
0045 #define HFS_BAD_CNID        5   /* BAD blocks file */
0046 #define HFS_ALLOC_CNID      6   /* ALLOCation file (HFS+) */
0047 #define HFS_START_CNID      7   /* STARTup file (HFS+) */
0048 #define HFS_ATTR_CNID       8   /* ATTRibutes file (HFS+) */
0049 #define HFS_EXCH_CNID       15  /* ExchangeFiles temp id */
0050 #define HFS_FIRSTUSER_CNID  16
0051 
0052 /* values for hfs_cat_rec.cdrType */
0053 #define HFS_CDR_DIR    0x01    /* folder (directory) */
0054 #define HFS_CDR_FIL    0x02    /* file */
0055 #define HFS_CDR_THD    0x03    /* folder (directory) thread */
0056 #define HFS_CDR_FTH    0x04    /* file thread */
0057 
0058 /* legal values for hfs_ext_key.FkType and hfs_file.fork */
0059 #define HFS_FK_DATA 0x00
0060 #define HFS_FK_RSRC 0xFF
0061 
0062 /* bits in hfs_fil_entry.Flags */
0063 #define HFS_FIL_LOCK    0x01  /* locked */
0064 #define HFS_FIL_THD 0x02  /* file thread */
0065 #define HFS_FIL_DOPEN   0x04  /* data fork open */
0066 #define HFS_FIL_ROPEN   0x08  /* resource fork open */
0067 #define HFS_FIL_DIR     0x10  /* directory (always clear) */
0068 #define HFS_FIL_NOCOPY  0x40  /* copy-protected file */
0069 #define HFS_FIL_USED    0x80  /* open */
0070 
0071 /* bits in hfs_dir_entry.Flags. dirflags is 16 bits. */
0072 #define HFS_DIR_LOCK        0x01  /* locked */
0073 #define HFS_DIR_THD         0x02  /* directory thread */
0074 #define HFS_DIR_INEXPFOLDER 0x04  /* in a shared area */
0075 #define HFS_DIR_MOUNTED     0x08  /* mounted */
0076 #define HFS_DIR_DIR         0x10  /* directory (always set) */
0077 #define HFS_DIR_EXPFOLDER   0x20  /* share point */
0078 
0079 /* bits hfs_finfo.fdFlags */
0080 #define HFS_FLG_INITED      0x0100
0081 #define HFS_FLG_LOCKED      0x1000
0082 #define HFS_FLG_INVISIBLE   0x4000
0083 
0084 /*======== HFS structures as they appear on the disk ========*/
0085 
0086 /* Pascal-style string of up to 31 characters */
0087 struct hfs_name {
0088     u8 len;
0089     u8 name[HFS_NAMELEN];
0090 } __packed;
0091 
0092 struct hfs_point {
0093     __be16 v;
0094     __be16 h;
0095 } __packed;
0096 
0097 struct hfs_rect {
0098     __be16 top;
0099     __be16 left;
0100     __be16 bottom;
0101     __be16 right;
0102 } __packed;
0103 
0104 struct hfs_finfo {
0105     __be32 fdType;
0106     __be32 fdCreator;
0107     __be16 fdFlags;
0108     struct hfs_point fdLocation;
0109     __be16 fdFldr;
0110 } __packed;
0111 
0112 struct hfs_fxinfo {
0113     __be16 fdIconID;
0114     u8 fdUnused[8];
0115     __be16 fdComment;
0116     __be32 fdPutAway;
0117 } __packed;
0118 
0119 struct hfs_dinfo {
0120     struct hfs_rect frRect;
0121     __be16 frFlags;
0122     struct hfs_point frLocation;
0123     __be16 frView;
0124 } __packed;
0125 
0126 struct hfs_dxinfo {
0127     struct hfs_point frScroll;
0128     __be32 frOpenChain;
0129     __be16 frUnused;
0130     __be16 frComment;
0131     __be32 frPutAway;
0132 } __packed;
0133 
0134 union hfs_finder_info {
0135     struct {
0136         struct hfs_finfo finfo;
0137         struct hfs_fxinfo fxinfo;
0138     } file;
0139     struct {
0140         struct hfs_dinfo dinfo;
0141         struct hfs_dxinfo dxinfo;
0142     } dir;
0143 } __packed;
0144 
0145 /* Cast to a pointer to a generic bkey */
0146 #define HFS_BKEY(X) (((void)((X)->KeyLen)), ((struct hfs_bkey *)(X)))
0147 
0148 /* The key used in the catalog b-tree: */
0149 struct hfs_cat_key {
0150     u8 key_len;     /* number of bytes in the key */
0151     u8 reserved;        /* padding */
0152     __be32 ParID;       /* CNID of the parent dir */
0153     struct hfs_name CName;  /* The filename of the entry */
0154 } __packed;
0155 
0156 /* The key used in the extents b-tree: */
0157 struct hfs_ext_key {
0158     u8 key_len;     /* number of bytes in the key */
0159     u8 FkType;      /* HFS_FK_{DATA,RSRC} */
0160     __be32 FNum;        /* The File ID of the file */
0161     __be16 FABN;        /* allocation blocks number*/
0162 } __packed;
0163 
0164 typedef union hfs_btree_key {
0165     u8 key_len;         /* number of bytes in the key */
0166     struct hfs_cat_key cat;
0167     struct hfs_ext_key ext;
0168 } hfs_btree_key;
0169 
0170 #define HFS_MAX_CAT_KEYLEN  (sizeof(struct hfs_cat_key) - sizeof(u8))
0171 #define HFS_MAX_EXT_KEYLEN  (sizeof(struct hfs_ext_key) - sizeof(u8))
0172 
0173 typedef union hfs_btree_key btree_key;
0174 
0175 struct hfs_extent {
0176     __be16 block;
0177     __be16 count;
0178 };
0179 typedef struct hfs_extent hfs_extent_rec[3];
0180 
0181 /* The catalog record for a file */
0182 struct hfs_cat_file {
0183     s8 type;            /* The type of entry */
0184     u8 reserved;
0185     u8 Flags;           /* Flags such as read-only */
0186     s8 Typ;             /* file version number = 0 */
0187     struct hfs_finfo UsrWds;    /* data used by the Finder */
0188     __be32 FlNum;           /* The CNID */
0189     __be16 StBlk;           /* obsolete */
0190     __be32 LgLen;           /* The logical EOF of the data fork*/
0191     __be32 PyLen;           /* The physical EOF of the data fork */
0192     __be16 RStBlk;          /* obsolete */
0193     __be32 RLgLen;          /* The logical EOF of the rsrc fork */
0194     __be32 RPyLen;          /* The physical EOF of the rsrc fork */
0195     __be32 CrDat;           /* The creation date */
0196     __be32 MdDat;           /* The modified date */
0197     __be32 BkDat;           /* The last backup date */
0198     struct hfs_fxinfo FndrInfo; /* more data for the Finder */
0199     __be16 ClpSize;         /* number of bytes to allocate
0200                        when extending files */
0201     hfs_extent_rec ExtRec;      /* first extent record
0202                        for the data fork */
0203     hfs_extent_rec RExtRec;     /* first extent record
0204                        for the resource fork */
0205     u32 Resrv;          /* reserved by Apple */
0206 } __packed;
0207 
0208 /* the catalog record for a directory */
0209 struct hfs_cat_dir {
0210     s8 type;            /* The type of entry */
0211     u8 reserved;
0212     __be16 Flags;           /* flags */
0213     __be16 Val;         /* Valence: number of files and
0214                        dirs in the directory */
0215     __be32 DirID;           /* The CNID */
0216     __be32 CrDat;           /* The creation date */
0217     __be32 MdDat;           /* The modification date */
0218     __be32 BkDat;           /* The last backup date */
0219     struct hfs_dinfo UsrInfo;   /* data used by the Finder */
0220     struct hfs_dxinfo FndrInfo; /* more data used by Finder */
0221     u8 Resrv[16];           /* reserved by Apple */
0222 } __packed;
0223 
0224 /* the catalog record for a thread */
0225 struct hfs_cat_thread {
0226     s8 type;            /* The type of entry */
0227     u8 reserved[9];         /* reserved by Apple */
0228     __be32 ParID;           /* CNID of parent directory */
0229     struct hfs_name CName;      /* The name of this entry */
0230 }  __packed;
0231 
0232 /* A catalog tree record */
0233 typedef union hfs_cat_rec {
0234     s8 type;            /* The type of entry */
0235     struct hfs_cat_file file;
0236     struct hfs_cat_dir dir;
0237     struct hfs_cat_thread thread;
0238 } hfs_cat_rec;
0239 
0240 struct hfs_mdb {
0241     __be16 drSigWord;       /* Signature word indicating fs type */
0242     __be32 drCrDate;        /* fs creation date/time */
0243     __be32 drLsMod;         /* fs modification date/time */
0244     __be16 drAtrb;          /* fs attributes */
0245     __be16 drNmFls;         /* number of files in root directory */
0246     __be16 drVBMSt;         /* location (in 512-byte blocks)
0247                        of the volume bitmap */
0248     __be16 drAllocPtr;      /* location (in allocation blocks)
0249                        to begin next allocation search */
0250     __be16 drNmAlBlks;      /* number of allocation blocks */
0251     __be32 drAlBlkSiz;      /* bytes in an allocation block */
0252     __be32 drClpSiz;        /* clumpsize, the number of bytes to
0253                        allocate when extending a file */
0254     __be16 drAlBlSt;        /* location (in 512-byte blocks)
0255                        of the first allocation block */
0256     __be32 drNxtCNID;       /* CNID to assign to the next
0257                        file or directory created */
0258     __be16 drFreeBks;       /* number of free allocation blocks */
0259     u8 drVN[28];            /* the volume label */
0260     __be32 drVolBkUp;       /* fs backup date/time */
0261     __be16 drVSeqNum;       /* backup sequence number */
0262     __be32 drWrCnt;         /* fs write count */
0263     __be32 drXTClpSiz;      /* clumpsize for the extents B-tree */
0264     __be32 drCTClpSiz;      /* clumpsize for the catalog B-tree */
0265     __be16 drNmRtDirs;      /* number of directories in
0266                        the root directory */
0267     __be32 drFilCnt;        /* number of files in the fs */
0268     __be32 drDirCnt;        /* number of directories in the fs */
0269     u8 drFndrInfo[32];      /* data used by the Finder */
0270     __be16 drEmbedSigWord;      /* embedded volume signature */
0271     __be32 drEmbedExtent;       /* starting block number (xdrStABN)
0272                        and number of allocation blocks
0273                        (xdrNumABlks) occupied by embedded
0274                        volume */
0275     __be32 drXTFlSize;      /* bytes in the extents B-tree */
0276     hfs_extent_rec drXTExtRec;  /* extents B-tree's first 3 extents */
0277     __be32 drCTFlSize;      /* bytes in the catalog B-tree */
0278     hfs_extent_rec drCTExtRec;  /* catalog B-tree's first 3 extents */
0279 } __packed;
0280 
0281 /*======== Data structures kept in memory ========*/
0282 
0283 struct hfs_readdir_data {
0284     struct list_head list;
0285     struct file *file;
0286     struct hfs_cat_key key;
0287 };
0288 
0289 #endif