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