]> git.saurik.com Git - apple/xnu.git/blame - bsd/hfs/hfs_catalog.h
xnu-792.17.14.tar.gz
[apple/xnu.git] / bsd / hfs / hfs_catalog.h
CommitLineData
9bccf70c 1/*
91447636 2 * Copyright (c) 2002-2005 Apple Computer, Inc. All rights reserved.
9bccf70c 3 *
8f6c56a5 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
9bccf70c 5 *
8f6c56a5
A
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
8ad349bb 24 * limitations under the License.
8f6c56a5
A
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
9bccf70c
A
27 */
28#ifndef __HFS_CATALOG__
29#define __HFS_CATALOG__
30
31#include <sys/appleapiopts.h>
32
33#ifdef KERNEL
34#ifdef __APPLE_API_PRIVATE
9bccf70c 35#include <sys/vnode.h>
9bccf70c
A
36
37#include <hfs/hfs_format.h>
38
39/* HFS Catalog */
40
41
42/*
43 * Catalog ADTs
44 *
45 * The cat_desc, cat_attr, and cat_fork structures are
46 * use to import/export data to/from the Catalog file.
47 * The fields in these structures are always in BSD
48 * runtime format (e.g. dates and names).
49 */
50
51typedef u_int32_t cnid_t;
52
53/*
54 * Catalog Node Descriptor (runtime)
55 */
56struct cat_desc {
57 u_int8_t cd_flags; /* see below (8 bits) */
58 u_int8_t cd_encoding; /* name encoding */
59 int16_t cd_namelen; /* length of cnode name */
60 char * cd_nameptr; /* pointer to cnode name */
61 cnid_t cd_parentcnid; /* parent directory CNID */
62 u_long cd_hint; /* catalog file hint */
63 cnid_t cd_cnid; /* cnode id (for getattrlist) */
64};
65
66/* cd_flags */
67#define CD_HASBUF 0x01 /* allocated filename buffer */
68#define CD_DECOMPOSED 0x02 /* name is fully decomposed */
55e303ae 69#define CD_ISMETA 0x40 /* describes a metadata file */
9bccf70c
A
70#define CD_ISDIR 0x80 /* describes a directory */
71
72/*
73 * Catalog Node Attributes (runtime)
74 */
75struct cat_attr {
76 cnid_t ca_fileid; /* inode number (for stat) normally == cnid */
77 mode_t ca_mode; /* file access mode and type (16 bits) */
91447636
A
78 u_int16_t ca_recflags; /* catalog record flags (16 bit integer) */
79 u_int32_t ca_nlink; /* file link count */
9bccf70c
A
80 uid_t ca_uid; /* file owner */
81 gid_t ca_gid; /* file group */
82 dev_t ca_rdev; /* device a special file represents */
83 time_t ca_atime; /* last access time */
91447636 84 time_t ca_atimeondisk; /* access time value on disk */
9bccf70c 85 time_t ca_mtime; /* last data modification time */
9bccf70c
A
86 time_t ca_ctime; /* last file status change */
87 time_t ca_itime; /* file initialization time */
88 time_t ca_btime; /* last backup time */
91447636 89 u_int32_t ca_flags; /* status flags (chflags) */
9bccf70c
A
90 union {
91 u_int32_t cau_blocks; /* total file blocks used (rsrc + data) */
92 u_int32_t cau_entries; /* total directory entries (valence) */
93 } ca_union;
94 u_int8_t ca_finderinfo[32]; /* Opaque Finder information */
91447636 95 u_int32_t ca_attrblks; /* cached count of attribute data blocks */
9bccf70c
A
96};
97/* Aliases for common fields */
98#define ca_blocks ca_union.cau_blocks
99#define ca_entries ca_union.cau_entries
100
101/*
55e303ae
A
102 * Catalog Node Fork (runtime)
103 *
104 * NOTE: this is not the same as a struct HFSPlusForkData
9bccf70c
A
105 */
106struct cat_fork {
55e303ae
A
107 u_int64_t cf_size; /* fork's logical size in bytes */
108 union {
109 u_int32_t cfu_clump; /* fork's clump size in bytes (sys files only) */
110 u_int64_t cfu_bytesread; /* bytes read from this fork */
111 } cf_union;
112 u_int32_t cf_vblocks; /* virtual (unalloated) blocks */
113 u_int32_t cf_blocks; /* total blocks used by this fork */
114 struct HFSPlusExtentDescriptor cf_extents[8]; /* initial set of extents */
9bccf70c
A
115};
116
55e303ae
A
117#define cf_clump cf_union.cfu_clump
118#define cf_bytesread cf_union.cfu_bytesread
119
9bccf70c 120
91447636
A
121/*
122 * Directory Hint
123 * Used to hold state across directory enumerations.
124 *
125 */
126struct directoryhint {
b36670ce 127 TAILQ_ENTRY(directoryhint) dh_link; /* chain */
91447636
A
128 int dh_index; /* index into directory (zero relative) */
129 u_int32_t dh_time;
130 struct cat_desc dh_desc; /* entry's descriptor */
131};
132typedef struct directoryhint directoryhint_t;
133
b36670ce
A
134/*
135 * HFS_MAXDIRHINTS cannot be larger than 63 without reducing
136 * HFS_INDEX_BITS, because given the 6-bit tag, at most 63 different
137 * tags can exist. When HFS_MAXDIRHINTS is larger than 63, the same
138 * list may contain dirhints of the same tag, and a staled dirhint may
139 * be returned.
140 */
91447636
A
141#define HFS_MAXDIRHINTS 32
142#define HFS_DIRHINT_TTL 45
143
144#define HFS_INDEX_MASK 0x03ffffff
145#define HFS_INDEX_BITS 26
146
147
9bccf70c
A
148/*
149 * Catalog Node Entry
150 *
151 * A cat_entry is used for bulk enumerations (hfs_readdirattr).
152 */
153struct cat_entry {
154 struct cat_desc ce_desc;
155 struct cat_attr ce_attr;
156 off_t ce_datasize;
157 off_t ce_rsrcsize;
158 u_long ce_datablks;
159 u_long ce_rsrcblks;
160};
161
162#define MAXCATENTRIES 8
163/*
164 * Catalog Node Entry List
165 *
166 * A cat_entrylist is a list of Catalog Node Entries.
167 */
168struct cat_entrylist {
169 u_long maxentries; /* length of list */
170 u_long realentries; /* valid entry count */
171 struct cat_entry entry[MAXCATENTRIES]; /* array of entries */
172};
173
55e303ae
A
174/*
175 * Catalog Operations Hint
176 *
177 * lower 16 bits: count of B-tree insert operations
178 * upper 16 bits: count of B-tree delete operations
179 *
180 */
181#define CAT_DELETE 0x00020000
182#define CAT_CREATE 0x00000002
183#define CAT_RENAME 0x00020002
184#define CAT_EXCHANGE 0x00020002
185
186typedef u_int32_t catops_t;
187
188/*
189 * The size of cat_cookie_t much match the size of
190 * the nreserve struct (in BTreeNodeReserve.c).
191 */
192typedef struct cat_cookie_t {
193 char opaque[24];
194} cat_cookie_t;
195
91447636
A
196/* Universal catalog key */
197union CatalogKey {
198 HFSCatalogKey hfs;
199 HFSPlusCatalogKey hfsPlus;
200};
201typedef union CatalogKey CatalogKey;
202
203/* Universal catalog data record */
204union CatalogRecord {
205 int16_t recordType;
206 HFSCatalogFolder hfsFolder;
207 HFSCatalogFile hfsFile;
208 HFSCatalogThread hfsThread;
209 HFSPlusCatalogFolder hfsPlusFolder;
210 HFSPlusCatalogFile hfsPlusFile;
211 HFSPlusCatalogThread hfsPlusThread;
212};
213typedef union CatalogRecord CatalogRecord;
214
215
9bccf70c
A
216/*
217 * Catalog Interface
218 *
219 * These functions perform a catalog transactions. The
220 * catalog b-tree is abstracted through this interface.
221 * (please don't go around it)
222 */
223
224struct hfsmount;
225
226extern void cat_releasedesc(struct cat_desc *descp);
227
228extern int cat_create ( struct hfsmount *hfsmp,
229 struct cat_desc *descp,
230 struct cat_attr *attrp,
231 struct cat_desc *out_descp);
232
233extern int cat_delete ( struct hfsmount *hfsmp,
234 struct cat_desc *descp,
235 struct cat_attr *attrp);
236
237extern int cat_lookup ( struct hfsmount *hfsmp,
238 struct cat_desc *descp,
239 int wantrsrc,
240 struct cat_desc *outdescp,
241 struct cat_attr *attrp,
91447636
A
242 struct cat_fork *forkp,
243 cnid_t *desc_cnid);
9bccf70c
A
244
245extern int cat_idlookup (struct hfsmount *hfsmp,
246 cnid_t cnid,
247 struct cat_desc *outdescp,
248 struct cat_attr *attrp,
249 struct cat_fork *forkp);
250
91447636
A
251extern int cat_findname (struct hfsmount *hfsmp,
252 cnid_t cnid,
253 struct cat_desc *outdescp);
254
9bccf70c
A
255extern int cat_getentriesattr(
256 struct hfsmount *hfsmp,
91447636 257 directoryhint_t *dirhint,
9bccf70c
A
258 struct cat_entrylist *ce_list);
259
260extern int cat_rename ( struct hfsmount * hfsmp,
261 struct cat_desc * from_cdp,
262 struct cat_desc * todir_cdp,
263 struct cat_desc * to_cdp,
264 struct cat_desc * cdp);
265
266extern int cat_update ( struct hfsmount *hfsmp,
267 struct cat_desc *descp,
268 struct cat_attr *attrp,
269 struct cat_fork *dataforkp,
270 struct cat_fork *rsrcforkp);
271
272extern int cat_getdirentries(
273 struct hfsmount *hfsmp,
55e303ae 274 int entrycnt,
91447636
A
275 directoryhint_t *dirhint,
276 uio_t uio,
277 int extended,
3a60a9f5
A
278 int * items,
279 int * eofflag);
9bccf70c
A
280
281extern int cat_insertfilethread (
282 struct hfsmount *hfsmp,
283 struct cat_desc *descp);
284
55e303ae
A
285extern int cat_preflight(
286 struct hfsmount *hfsmp,
287 catops_t ops,
288 cat_cookie_t *cookie,
289 struct proc *p);
290
291extern void cat_postflight(
292 struct hfsmount *hfsmp,
293 cat_cookie_t *cookie,
294 struct proc *p);
295
296extern int cat_binarykeycompare(
297 HFSPlusCatalogKey *searchKey,
298 HFSPlusCatalogKey *trialKey);
299
91447636
A
300extern int CompareCatalogKeys(
301 HFSCatalogKey *searchKey,
302 HFSCatalogKey *trialKey);
303
304extern int CompareExtendedCatalogKeys(
305 HFSPlusCatalogKey *searchKey,
306 HFSPlusCatalogKey *trialKey);
307
308extern void cat_convertattr(
309 struct hfsmount *hfsmp,
310 CatalogRecord * recp,
311 struct cat_attr *attrp,
312 struct cat_fork *datafp,
313 struct cat_fork *rsrcfp);
314
315extern int cat_convertkey(
316 struct hfsmount *hfsmp,
317 CatalogKey *key,
318 CatalogRecord * recp,
319 struct cat_desc *descp);
320
321extern int resolvelink(
322 struct hfsmount *hfsmp,
323 u_long linkref,
324 struct HFSPlusCatalogFile *recp);
325
326extern int cat_getkeyplusattr(
327 struct hfsmount *hfsmp,
328 cnid_t cnid,
329 CatalogKey *key,
330 struct cat_attr *attrp);
331
9bccf70c
A
332#endif /* __APPLE_API_PRIVATE */
333#endif /* KERNEL */
334#endif /* __HFS_CATALOG__ */