2 * Copyright (c) 2002-2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
22 #ifndef __HFS_CATALOG__
23 #define __HFS_CATALOG__
25 #include <sys/appleapiopts.h>
28 #ifdef __APPLE_API_PRIVATE
29 #include <sys/vnode.h>
31 #include <hfs/hfs_format.h>
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).
45 typedef u_int32_t cnid_t
;
48 * Catalog Node Descriptor (runtime)
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) */
61 #define CD_HASBUF 0x01 /* allocated filename buffer */
62 #define CD_DECOMPOSED 0x02 /* name is fully decomposed */
63 #define CD_ISMETA 0x40 /* describes a metadata file */
64 #define CD_ISDIR 0x80 /* describes a directory */
67 * Catalog Node Attributes (runtime)
70 cnid_t ca_fileid
; /* inode number (for stat) normally == cnid */
71 mode_t ca_mode
; /* file access mode and type (16 bits) */
72 u_int16_t ca_recflags
; /* catalog record flags (16 bit integer) */
73 u_int32_t ca_nlink
; /* file link count */
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 */
78 time_t ca_atimeondisk
; /* access time value on disk */
79 time_t ca_mtime
; /* last data modification time */
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 */
83 u_int32_t ca_flags
; /* status flags (chflags) */
85 u_int32_t cau_blocks
; /* total file blocks used (rsrc + data) */
86 u_int32_t cau_entries
; /* total directory entries (valence) */
88 u_int8_t ca_finderinfo
[32]; /* Opaque Finder information */
89 u_int32_t ca_attrblks
; /* cached count of attribute data blocks */
91 /* Aliases for common fields */
92 #define ca_blocks ca_union.cau_blocks
93 #define ca_entries ca_union.cau_entries
96 * Catalog Node Fork (runtime)
98 * NOTE: this is not the same as a struct HFSPlusForkData
101 u_int64_t cf_size
; /* fork's logical size in bytes */
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 */
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 */
111 #define cf_clump cf_union.cfu_clump
112 #define cf_bytesread cf_union.cfu_bytesread
117 * Used to hold state across directory enumerations.
120 struct directoryhint
{
121 SLIST_ENTRY(directoryhint
) dh_link
; /* chain */
122 int dh_index
; /* index into directory (zero relative) */
124 struct cat_desc dh_desc
; /* entry's descriptor */
126 typedef struct directoryhint directoryhint_t
;
128 #define HFS_MAXDIRHINTS 32
129 #define HFS_DIRHINT_TTL 45
131 #define HFS_INDEX_MASK 0x03ffffff
132 #define HFS_INDEX_BITS 26
138 * A cat_entry is used for bulk enumerations (hfs_readdirattr).
141 struct cat_desc ce_desc
;
142 struct cat_attr ce_attr
;
149 #define MAXCATENTRIES 8
151 * Catalog Node Entry List
153 * A cat_entrylist is a list of Catalog Node Entries.
155 struct cat_entrylist
{
156 u_long maxentries
; /* length of list */
157 u_long realentries
; /* valid entry count */
158 struct cat_entry entry
[MAXCATENTRIES
]; /* array of entries */
162 * Catalog Operations Hint
164 * lower 16 bits: count of B-tree insert operations
165 * upper 16 bits: count of B-tree delete operations
168 #define CAT_DELETE 0x00020000
169 #define CAT_CREATE 0x00000002
170 #define CAT_RENAME 0x00020002
171 #define CAT_EXCHANGE 0x00020002
173 typedef u_int32_t catops_t
;
176 * The size of cat_cookie_t much match the size of
177 * the nreserve struct (in BTreeNodeReserve.c).
179 typedef struct cat_cookie_t
{
183 /* Universal catalog key */
186 HFSPlusCatalogKey hfsPlus
;
188 typedef union CatalogKey CatalogKey
;
190 /* Universal catalog data record */
191 union CatalogRecord
{
193 HFSCatalogFolder hfsFolder
;
194 HFSCatalogFile hfsFile
;
195 HFSCatalogThread hfsThread
;
196 HFSPlusCatalogFolder hfsPlusFolder
;
197 HFSPlusCatalogFile hfsPlusFile
;
198 HFSPlusCatalogThread hfsPlusThread
;
200 typedef union CatalogRecord CatalogRecord
;
206 * These functions perform a catalog transactions. The
207 * catalog b-tree is abstracted through this interface.
208 * (please don't go around it)
213 extern void cat_releasedesc(struct cat_desc
*descp
);
215 extern int cat_create ( struct hfsmount
*hfsmp
,
216 struct cat_desc
*descp
,
217 struct cat_attr
*attrp
,
218 struct cat_desc
*out_descp
);
220 extern int cat_delete ( struct hfsmount
*hfsmp
,
221 struct cat_desc
*descp
,
222 struct cat_attr
*attrp
);
224 extern int cat_lookup ( struct hfsmount
*hfsmp
,
225 struct cat_desc
*descp
,
227 struct cat_desc
*outdescp
,
228 struct cat_attr
*attrp
,
229 struct cat_fork
*forkp
,
232 extern int cat_idlookup (struct hfsmount
*hfsmp
,
234 struct cat_desc
*outdescp
,
235 struct cat_attr
*attrp
,
236 struct cat_fork
*forkp
);
238 extern int cat_findname (struct hfsmount
*hfsmp
,
240 struct cat_desc
*outdescp
);
242 extern int cat_getentriesattr(
243 struct hfsmount
*hfsmp
,
244 directoryhint_t
*dirhint
,
245 struct cat_entrylist
*ce_list
);
247 extern int cat_rename ( struct hfsmount
* hfsmp
,
248 struct cat_desc
* from_cdp
,
249 struct cat_desc
* todir_cdp
,
250 struct cat_desc
* to_cdp
,
251 struct cat_desc
* cdp
);
253 extern int cat_update ( struct hfsmount
*hfsmp
,
254 struct cat_desc
*descp
,
255 struct cat_attr
*attrp
,
256 struct cat_fork
*dataforkp
,
257 struct cat_fork
*rsrcforkp
);
259 extern int cat_getdirentries(
260 struct hfsmount
*hfsmp
,
262 directoryhint_t
*dirhint
,
267 extern int cat_insertfilethread (
268 struct hfsmount
*hfsmp
,
269 struct cat_desc
*descp
);
271 extern int cat_preflight(
272 struct hfsmount
*hfsmp
,
274 cat_cookie_t
*cookie
,
277 extern void cat_postflight(
278 struct hfsmount
*hfsmp
,
279 cat_cookie_t
*cookie
,
282 extern int cat_binarykeycompare(
283 HFSPlusCatalogKey
*searchKey
,
284 HFSPlusCatalogKey
*trialKey
);
286 extern int CompareCatalogKeys(
287 HFSCatalogKey
*searchKey
,
288 HFSCatalogKey
*trialKey
);
290 extern int CompareExtendedCatalogKeys(
291 HFSPlusCatalogKey
*searchKey
,
292 HFSPlusCatalogKey
*trialKey
);
294 extern void cat_convertattr(
295 struct hfsmount
*hfsmp
,
296 CatalogRecord
* recp
,
297 struct cat_attr
*attrp
,
298 struct cat_fork
*datafp
,
299 struct cat_fork
*rsrcfp
);
301 extern int cat_convertkey(
302 struct hfsmount
*hfsmp
,
304 CatalogRecord
* recp
,
305 struct cat_desc
*descp
);
307 extern int resolvelink(
308 struct hfsmount
*hfsmp
,
310 struct HFSPlusCatalogFile
*recp
);
312 extern int cat_getkeyplusattr(
313 struct hfsmount
*hfsmp
,
316 struct cat_attr
*attrp
);
318 #endif /* __APPLE_API_PRIVATE */
320 #endif /* __HFS_CATALOG__ */