2 * Copyright (c) 2002-2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 #ifndef __HFS_CATALOG__
29 #define __HFS_CATALOG__
31 #include <sys/appleapiopts.h>
34 #ifdef __APPLE_API_PRIVATE
35 #include <sys/vnode.h>
37 #include <hfs/hfs_format.h>
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).
51 typedef u_int32_t cnid_t
;
54 * Catalog Node Descriptor (runtime)
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) */
67 #define CD_HASBUF 0x01 /* allocated filename buffer */
68 #define CD_DECOMPOSED 0x02 /* name is fully decomposed */
69 #define CD_ISMETA 0x40 /* describes a metadata file */
70 #define CD_ISDIR 0x80 /* describes a directory */
73 * Catalog Node Attributes (runtime)
76 cnid_t ca_fileid
; /* inode number (for stat) normally == cnid */
77 mode_t ca_mode
; /* file access mode and type (16 bits) */
78 u_int16_t ca_recflags
; /* catalog record flags (16 bit integer) */
79 u_int32_t ca_nlink
; /* file link count */
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 */
84 time_t ca_atimeondisk
; /* access time value on disk */
85 time_t ca_mtime
; /* last data modification time */
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 */
89 u_int32_t ca_flags
; /* status flags (chflags) */
91 u_int32_t cau_blocks
; /* total file blocks used (rsrc + data) */
92 u_int32_t cau_entries
; /* total directory entries (valence) */
94 u_int8_t ca_finderinfo
[32]; /* Opaque Finder information */
95 u_int32_t ca_attrblks
; /* cached count of attribute data blocks */
97 /* Aliases for common fields */
98 #define ca_blocks ca_union.cau_blocks
99 #define ca_entries ca_union.cau_entries
102 * Catalog Node Fork (runtime)
104 * NOTE: this is not the same as a struct HFSPlusForkData
107 u_int64_t cf_size
; /* fork's logical size in bytes */
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 */
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 */
117 #define cf_clump cf_union.cfu_clump
118 #define cf_bytesread cf_union.cfu_bytesread
123 * Used to hold state across directory enumerations.
126 struct directoryhint
{
127 TAILQ_ENTRY(directoryhint
) dh_link
; /* chain */
128 int dh_index
; /* index into directory (zero relative) */
130 struct cat_desc dh_desc
; /* entry's descriptor */
132 typedef struct directoryhint directoryhint_t
;
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
141 #define HFS_MAXDIRHINTS 32
142 #define HFS_DIRHINT_TTL 45
144 #define HFS_INDEX_MASK 0x03ffffff
145 #define HFS_INDEX_BITS 26
151 * A cat_entry is used for bulk enumerations (hfs_readdirattr).
154 struct cat_desc ce_desc
;
155 struct cat_attr ce_attr
;
162 #define MAXCATENTRIES 8
164 * Catalog Node Entry List
166 * A cat_entrylist is a list of Catalog Node Entries.
168 struct 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 */
175 * Catalog Operations Hint
177 * lower 16 bits: count of B-tree insert operations
178 * upper 16 bits: count of B-tree delete operations
181 #define CAT_DELETE 0x00020000
182 #define CAT_CREATE 0x00000002
183 #define CAT_RENAME 0x00020002
184 #define CAT_EXCHANGE 0x00020002
186 typedef u_int32_t catops_t
;
189 * The size of cat_cookie_t much match the size of
190 * the nreserve struct (in BTreeNodeReserve.c).
192 typedef struct cat_cookie_t
{
196 /* Universal catalog key */
199 HFSPlusCatalogKey hfsPlus
;
201 typedef union CatalogKey CatalogKey
;
203 /* Universal catalog data record */
204 union CatalogRecord
{
206 HFSCatalogFolder hfsFolder
;
207 HFSCatalogFile hfsFile
;
208 HFSCatalogThread hfsThread
;
209 HFSPlusCatalogFolder hfsPlusFolder
;
210 HFSPlusCatalogFile hfsPlusFile
;
211 HFSPlusCatalogThread hfsPlusThread
;
213 typedef union CatalogRecord CatalogRecord
;
219 * These functions perform a catalog transactions. The
220 * catalog b-tree is abstracted through this interface.
221 * (please don't go around it)
226 extern void cat_releasedesc(struct cat_desc
*descp
);
228 extern int cat_create ( struct hfsmount
*hfsmp
,
229 struct cat_desc
*descp
,
230 struct cat_attr
*attrp
,
231 struct cat_desc
*out_descp
);
233 extern int cat_delete ( struct hfsmount
*hfsmp
,
234 struct cat_desc
*descp
,
235 struct cat_attr
*attrp
);
237 extern int cat_lookup ( struct hfsmount
*hfsmp
,
238 struct cat_desc
*descp
,
240 struct cat_desc
*outdescp
,
241 struct cat_attr
*attrp
,
242 struct cat_fork
*forkp
,
245 extern int cat_idlookup (struct hfsmount
*hfsmp
,
247 struct cat_desc
*outdescp
,
248 struct cat_attr
*attrp
,
249 struct cat_fork
*forkp
);
251 extern int cat_findname (struct hfsmount
*hfsmp
,
253 struct cat_desc
*outdescp
);
255 extern int cat_getentriesattr(
256 struct hfsmount
*hfsmp
,
257 directoryhint_t
*dirhint
,
258 struct cat_entrylist
*ce_list
);
260 extern 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
);
266 extern 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
);
272 extern int cat_getdirentries(
273 struct hfsmount
*hfsmp
,
275 directoryhint_t
*dirhint
,
281 extern int cat_insertfilethread (
282 struct hfsmount
*hfsmp
,
283 struct cat_desc
*descp
);
285 extern int cat_preflight(
286 struct hfsmount
*hfsmp
,
288 cat_cookie_t
*cookie
,
291 extern void cat_postflight(
292 struct hfsmount
*hfsmp
,
293 cat_cookie_t
*cookie
,
296 extern int cat_binarykeycompare(
297 HFSPlusCatalogKey
*searchKey
,
298 HFSPlusCatalogKey
*trialKey
);
300 extern int CompareCatalogKeys(
301 HFSCatalogKey
*searchKey
,
302 HFSCatalogKey
*trialKey
);
304 extern int CompareExtendedCatalogKeys(
305 HFSPlusCatalogKey
*searchKey
,
306 HFSPlusCatalogKey
*trialKey
);
308 extern 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
);
315 extern int cat_convertkey(
316 struct hfsmount
*hfsmp
,
318 CatalogRecord
* recp
,
319 struct cat_desc
*descp
);
321 extern int resolvelink(
322 struct hfsmount
*hfsmp
,
324 struct HFSPlusCatalogFile
*recp
);
326 extern int cat_getkeyplusattr(
327 struct hfsmount
*hfsmp
,
330 struct cat_attr
*attrp
);
332 #endif /* __APPLE_API_PRIVATE */
334 #endif /* __HFS_CATALOG__ */