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