]> git.saurik.com Git - apple/xnu.git/blame_incremental - bsd/hfs/hfs_catalog.h
xnu-517.7.7.tar.gz
[apple/xnu.git] / bsd / hfs / hfs_catalog.h
... / ...
CommitLineData
1/*
2 * Copyright (c) 2002-2003 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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.
11 *
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
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
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
29#include <sys/namei.h>
30#include <sys/vnode.h>
31#include <sys/lock.h>
32
33#include <hfs/hfs_format.h>
34
35/* HFS Catalog */
36
37
38/*
39 * Catalog ADTs
40 *
41 * The cat_desc, cat_attr, and cat_fork structures are
42 * use to import/export data to/from the Catalog file.
43 * The fields in these structures are always in BSD
44 * runtime format (e.g. dates and names).
45 */
46
47typedef u_int32_t cnid_t;
48
49/*
50 * Catalog Node Descriptor (runtime)
51 */
52struct cat_desc {
53 u_int8_t cd_flags; /* see below (8 bits) */
54 u_int8_t cd_encoding; /* name encoding */
55 int16_t cd_namelen; /* length of cnode name */
56 char * cd_nameptr; /* pointer to cnode name */
57 cnid_t cd_parentcnid; /* parent directory CNID */
58 u_long cd_hint; /* catalog file hint */
59 cnid_t cd_cnid; /* cnode id (for getattrlist) */
60};
61
62/* cd_flags */
63#define CD_HASBUF 0x01 /* allocated filename buffer */
64#define CD_DECOMPOSED 0x02 /* name is fully decomposed */
65#define CD_ISMETA 0x40 /* describes a metadata file */
66#define CD_ISDIR 0x80 /* describes a directory */
67
68/*
69 * Catalog Node Attributes (runtime)
70 */
71struct cat_attr {
72 cnid_t ca_fileid; /* inode number (for stat) normally == cnid */
73 mode_t ca_mode; /* file access mode and type (16 bits) */
74 nlink_t ca_nlink; /* file link count (16 bit integer) */
75 uid_t ca_uid; /* file owner */
76 gid_t ca_gid; /* file group */
77 dev_t ca_rdev; /* device a special file represents */
78 time_t ca_atime; /* last access time */
79 time_t ca_mtime; /* last data modification time */
80 int32_t ca_mtime_nsec; /* last data modification time nanosec */
81 time_t ca_ctime; /* last file status change */
82 time_t ca_itime; /* file initialization time */
83 time_t ca_btime; /* last backup time */
84 u_long ca_flags; /* status flags (chflags) */
85 union {
86 u_int32_t cau_blocks; /* total file blocks used (rsrc + data) */
87 u_int32_t cau_entries; /* total directory entries (valence) */
88 } ca_union;
89 u_int8_t ca_finderinfo[32]; /* Opaque Finder information */
90};
91/* Aliases for common fields */
92#define ca_blocks ca_union.cau_blocks
93#define ca_entries ca_union.cau_entries
94
95/*
96 * Catalog Node Fork (runtime)
97 *
98 * NOTE: this is not the same as a struct HFSPlusForkData
99 */
100struct cat_fork {
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 */
109};
110
111#define cf_clump cf_union.cfu_clump
112#define cf_bytesread cf_union.cfu_bytesread
113
114
115/*
116 * Catalog Node Entry
117 *
118 * A cat_entry is used for bulk enumerations (hfs_readdirattr).
119 */
120struct cat_entry {
121 struct cat_desc ce_desc;
122 struct cat_attr ce_attr;
123 off_t ce_datasize;
124 off_t ce_rsrcsize;
125 u_long ce_datablks;
126 u_long ce_rsrcblks;
127};
128
129#define MAXCATENTRIES 8
130/*
131 * Catalog Node Entry List
132 *
133 * A cat_entrylist is a list of Catalog Node Entries.
134 */
135struct cat_entrylist {
136 u_long maxentries; /* length of list */
137 u_long realentries; /* valid entry count */
138 struct cat_entry entry[MAXCATENTRIES]; /* array of entries */
139};
140
141/*
142 * Catalog Operations Hint
143 *
144 * lower 16 bits: count of B-tree insert operations
145 * upper 16 bits: count of B-tree delete operations
146 *
147 */
148#define CAT_DELETE 0x00020000
149#define CAT_CREATE 0x00000002
150#define CAT_RENAME 0x00020002
151#define CAT_EXCHANGE 0x00020002
152
153typedef u_int32_t catops_t;
154
155/*
156 * The size of cat_cookie_t much match the size of
157 * the nreserve struct (in BTreeNodeReserve.c).
158 */
159typedef struct cat_cookie_t {
160 char opaque[24];
161} cat_cookie_t;
162
163/*
164 * Catalog Interface
165 *
166 * These functions perform a catalog transactions. The
167 * catalog b-tree is abstracted through this interface.
168 * (please don't go around it)
169 */
170
171struct hfsmount;
172
173extern void cat_releasedesc(struct cat_desc *descp);
174
175extern int cat_create ( struct hfsmount *hfsmp,
176 struct cat_desc *descp,
177 struct cat_attr *attrp,
178 struct cat_desc *out_descp);
179
180extern int cat_delete ( struct hfsmount *hfsmp,
181 struct cat_desc *descp,
182 struct cat_attr *attrp);
183
184extern int cat_lookup ( struct hfsmount *hfsmp,
185 struct cat_desc *descp,
186 int wantrsrc,
187 struct cat_desc *outdescp,
188 struct cat_attr *attrp,
189 struct cat_fork *forkp);
190
191extern int cat_idlookup (struct hfsmount *hfsmp,
192 cnid_t cnid,
193 struct cat_desc *outdescp,
194 struct cat_attr *attrp,
195 struct cat_fork *forkp);
196
197extern int cat_getentriesattr(
198 struct hfsmount *hfsmp,
199 struct cat_desc *prevdesc,
200 int index,
201 struct cat_entrylist *ce_list);
202
203extern int cat_rename ( struct hfsmount * hfsmp,
204 struct cat_desc * from_cdp,
205 struct cat_desc * todir_cdp,
206 struct cat_desc * to_cdp,
207 struct cat_desc * cdp);
208
209extern int cat_update ( struct hfsmount *hfsmp,
210 struct cat_desc *descp,
211 struct cat_attr *attrp,
212 struct cat_fork *dataforkp,
213 struct cat_fork *rsrcforkp);
214
215extern int cat_getdirentries(
216 struct hfsmount *hfsmp,
217 struct cat_desc *descp,
218 int entrycnt,
219 struct uio *uio,
220 int *eofflag,
221 u_long *cookies,
222 int ncookies);
223
224extern int cat_insertfilethread (
225 struct hfsmount *hfsmp,
226 struct cat_desc *descp);
227
228extern int cat_preflight(
229 struct hfsmount *hfsmp,
230 catops_t ops,
231 cat_cookie_t *cookie,
232 struct proc *p);
233
234extern void cat_postflight(
235 struct hfsmount *hfsmp,
236 cat_cookie_t *cookie,
237 struct proc *p);
238
239extern int cat_binarykeycompare(
240 HFSPlusCatalogKey *searchKey,
241 HFSPlusCatalogKey *trialKey);
242
243#endif /* __APPLE_API_PRIVATE */
244#endif /* KERNEL */
245#endif /* __HFS_CATALOG__ */