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