]>
Commit | Line | Data |
---|---|---|
9bccf70c | 1 | /* |
b0d623f7 | 2 | * Copyright (c) 2002-2008 Apple Inc. All rights reserved. |
9bccf70c | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
9bccf70c | 5 | * |
2d21ac55 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 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. | |
8f6c56a5 | 14 | * |
2d21ac55 A |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
17 | * | |
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 | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
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. | |
8f6c56a5 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
9bccf70c A |
27 | */ |
28 | #ifndef _HFS_CNODE_H_ | |
29 | #define _HFS_CNODE_H_ | |
30 | ||
31 | #include <sys/appleapiopts.h> | |
32 | ||
33 | #ifdef KERNEL | |
34 | #ifdef __APPLE_API_PRIVATE | |
35 | #include <sys/types.h> | |
9bccf70c A |
36 | #include <sys/queue.h> |
37 | #include <sys/stat.h> | |
38 | #include <sys/vnode.h> | |
39 | #include <sys/quota.h> | |
40 | ||
91447636 A |
41 | #include <kern/locks.h> |
42 | ||
9bccf70c A |
43 | #include <hfs/hfs_catalog.h> |
44 | #include <hfs/rangelist.h> | |
b0d623f7 A |
45 | #if HFS_COMPRESSION |
46 | #include <sys/decmpfs.h> | |
47 | #endif | |
6d2010ae A |
48 | #if CONFIG_PROTECT |
49 | #include <sys/cprotect.h> | |
50 | #endif | |
51 | ||
9bccf70c A |
52 | |
53 | /* | |
54 | * The filefork is used to represent an HFS file fork (data or resource). | |
55 | * Reading or writing any of these fields requires holding cnode lock. | |
56 | */ | |
57 | struct filefork { | |
91447636 A |
58 | struct cnode *ff_cp; /* cnode associated with this fork */ |
59 | struct rl_head ff_invalidranges; /* Areas of disk that should read back as zeroes */ | |
9bccf70c | 60 | union { |
91447636 A |
61 | void *ffu_sysfileinfo; /* additional info for system files */ |
62 | char *ffu_symlinkptr; /* symbolic link pathname */ | |
63 | } ff_union; | |
64 | struct cat_fork ff_data; /* fork data (size, extents) */ | |
9bccf70c | 65 | }; |
55e303ae | 66 | typedef struct filefork filefork_t; |
9bccf70c A |
67 | |
68 | /* Aliases for common fields */ | |
91447636 | 69 | #define ff_size ff_data.cf_size |
593a1d5f | 70 | #define ff_new_size ff_data.cf_new_size |
91447636 A |
71 | #define ff_clumpsize ff_data.cf_clump |
72 | #define ff_bytesread ff_data.cf_bytesread | |
73 | #define ff_blocks ff_data.cf_blocks | |
74 | #define ff_extents ff_data.cf_extents | |
55e303ae A |
75 | #define ff_unallocblocks ff_data.cf_vblocks |
76 | ||
91447636 A |
77 | #define ff_symlinkptr ff_union.ffu_symlinkptr |
78 | #define ff_sysfileinfo ff_union.ffu_sysfileinfo | |
9bccf70c A |
79 | |
80 | ||
81 | /* The btree code still needs these... */ | |
91447636 A |
82 | #define fcbEOF ff_size |
83 | #define fcbExtents ff_extents | |
84 | #define fcbBTCBPtr ff_sysfileinfo | |
9bccf70c | 85 | |
91447636 | 86 | typedef u_int8_t atomicflag_t; |
2d21ac55 A |
87 | |
88 | ||
89 | /* | |
90 | * Hardlink Origin (for hardlinked directories). | |
91 | */ | |
92 | struct linkorigin { | |
93 | TAILQ_ENTRY(linkorigin) lo_link; /* chain */ | |
94 | void * lo_thread; /* thread that performed the lookup */ | |
95 | cnid_t lo_cnid; /* hardlink's cnid */ | |
96 | cnid_t lo_parentcnid; /* hardlink's parent cnid */ | |
97 | }; | |
98 | typedef struct linkorigin linkorigin_t; | |
99 | ||
100 | #define MAX_CACHED_ORIGINS 10 | |
935ed37a | 101 | #define MAX_CACHED_FILE_ORIGINS 8 |
2d21ac55 | 102 | |
9bccf70c A |
103 | /* |
104 | * The cnode is used to represent each active (or recently active) | |
105 | * file or directory in the HFS filesystem. | |
106 | * | |
107 | * Reading or writing any of these fields requires holding c_lock. | |
108 | */ | |
109 | struct cnode { | |
91447636 A |
110 | lck_rw_t c_rwlock; /* cnode's lock */ |
111 | void * c_lockowner; /* cnode's lock owner (exclusive case only) */ | |
112 | lck_rw_t c_truncatelock; /* protects file from truncation during read/write */ | |
6d2010ae | 113 | void * c_truncatelockowner; /* truncate lock owner (exclusive case only) */ |
9bccf70c A |
114 | LIST_ENTRY(cnode) c_hash; /* cnode's hash chain */ |
115 | u_int32_t c_flag; /* cnode's runtime flags */ | |
91447636 | 116 | u_int32_t c_hflag; /* cnode's flags for maintaining hash - protected by global hash lock */ |
9bccf70c A |
117 | struct vnode *c_vp; /* vnode for data fork or dir */ |
118 | struct vnode *c_rsrc_vp; /* vnode for resource fork */ | |
b0d623f7 | 119 | struct dquot *c_dquot[MAXQUOTAS]; /* cnode's quota info */ |
2d21ac55 A |
120 | u_int32_t c_childhint; /* catalog hint for children (small dirs only) */ |
121 | u_int32_t c_dirthreadhint; /* catalog hint for directory's thread rec */ | |
9bccf70c A |
122 | struct cat_desc c_desc; /* cnode's descriptor */ |
123 | struct cat_attr c_attr; /* cnode's attributes */ | |
2d21ac55 A |
124 | TAILQ_HEAD(hfs_originhead, linkorigin) c_originlist; /* hardlink origin cache */ |
125 | TAILQ_HEAD(hfs_hinthead, directoryhint) c_hintlist; /* readdir directory hint list */ | |
91447636 A |
126 | int16_t c_dirhinttag; /* directory hint tag */ |
127 | union { | |
128 | int16_t cu_dirhintcnt; /* directory hint count */ | |
129 | int16_t cu_syslockcount; /* system file use only */ | |
130 | } c_union; | |
2d21ac55 | 131 | u_int32_t c_dirchangecnt; /* changes each insert/delete (in-core only) */ |
9bccf70c A |
132 | struct filefork *c_datafork; /* cnode's data fork */ |
133 | struct filefork *c_rsrcfork; /* cnode's rsrc fork */ | |
91447636 A |
134 | atomicflag_t c_touch_acctime; |
135 | atomicflag_t c_touch_chgtime; | |
136 | atomicflag_t c_touch_modtime; | |
b0d623f7 A |
137 | #if HFS_COMPRESSION |
138 | decmpfs_cnode *c_decmp; | |
139 | #endif /* HFS_COMPRESSION */ | |
6d2010ae A |
140 | #if CONFIG_PROTECT |
141 | cprotect_t c_cpentry; /* content protection data */ | |
142 | #endif | |
143 | ||
9bccf70c | 144 | }; |
55e303ae | 145 | typedef struct cnode cnode_t; |
9bccf70c A |
146 | |
147 | /* Aliases for common cnode fields */ | |
148 | #define c_cnid c_desc.cd_cnid | |
149 | #define c_hint c_desc.cd_hint | |
150 | #define c_parentcnid c_desc.cd_parentcnid | |
151 | #define c_encoding c_desc.cd_encoding | |
152 | ||
153 | #define c_fileid c_attr.ca_fileid | |
154 | #define c_mode c_attr.ca_mode | |
2d21ac55 | 155 | #define c_linkcount c_attr.ca_linkcount |
9bccf70c A |
156 | #define c_uid c_attr.ca_uid |
157 | #define c_gid c_attr.ca_gid | |
2d21ac55 | 158 | #define c_rdev c_attr.ca_union1.cau_rdev |
9bccf70c A |
159 | #define c_atime c_attr.ca_atime |
160 | #define c_mtime c_attr.ca_mtime | |
9bccf70c A |
161 | #define c_ctime c_attr.ca_ctime |
162 | #define c_itime c_attr.ca_itime | |
163 | #define c_btime c_attr.ca_btime | |
164 | #define c_flags c_attr.ca_flags | |
165 | #define c_finderinfo c_attr.ca_finderinfo | |
2d21ac55 A |
166 | #define c_blocks c_attr.ca_union2.cau_blocks |
167 | #define c_entries c_attr.ca_union2.cau_entries | |
9bccf70c A |
168 | #define c_zftimeout c_childhint |
169 | ||
91447636 A |
170 | #define c_dirhintcnt c_union.cu_dirhintcnt |
171 | #define c_syslockcount c_union.cu_syslockcount | |
9bccf70c | 172 | |
55e303ae | 173 | |
91447636 A |
174 | /* hash maintenance flags kept in c_hflag and protected by hfs_chash_mutex */ |
175 | #define H_ALLOC 0x00001 /* CNode is being allocated */ | |
176 | #define H_ATTACH 0x00002 /* CNode is being attached to by another vnode */ | |
177 | #define H_TRANSIT 0x00004 /* CNode is getting recycled */ | |
178 | #define H_WAITING 0x00008 /* CNode is being waited for */ | |
179 | ||
9bccf70c | 180 | |
91447636 A |
181 | /* Runtime cnode flags (kept in c_flag) */ |
182 | #define C_NEED_RVNODE_PUT 0x00001 /* Need to do a vnode_put on c_rsrc_vp after the unlock */ | |
183 | #define C_NEED_DVNODE_PUT 0x00002 /* Need to do a vnode_put on c_vp after the unlock */ | |
184 | #define C_ZFWANTSYNC 0x00004 /* fsync requested and file has holes */ | |
185 | #define C_FROMSYNC 0x00008 /* fsync was called from sync */ | |
9bccf70c | 186 | |
91447636 A |
187 | #define C_MODIFIED 0x00010 /* CNode has been modified */ |
188 | #define C_NOEXISTS 0x00020 /* CNode has been deleted, catalog entry is gone */ | |
189 | #define C_DELETED 0x00040 /* CNode has been marked to be deleted */ | |
2d21ac55 | 190 | #define C_HARDLINK 0x00080 /* CNode is a hard link (file or dir) */ |
9bccf70c | 191 | |
91447636 A |
192 | #define C_FORCEUPDATE 0x00100 /* force the catalog entry update */ |
193 | #define C_HASXATTRS 0x00200 /* cnode has extended attributes */ | |
2d21ac55 | 194 | #define C_NEG_ENTRIES 0x00400 /* directory has negative name entries */ |
6d2010ae | 195 | #define C_SWAPINPROGRESS 0x00800 /* cnode's data is about to be swapped. Issue synchronous cluster io */ |
9bccf70c | 196 | |
0c530ab8 A |
197 | #define C_NEED_DATA_SETSIZE 0x01000 /* Do a ubc_setsize(0) on c_rsrc_vp after the unlock */ |
198 | #define C_NEED_RSRC_SETSIZE 0x02000 /* Do a ubc_setsize(0) on c_vp after the unlock */ | |
2d21ac55 | 199 | #define C_DIR_MODIFICATION 0x04000 /* Directory is being modified, wait for lookups */ |
b0d623f7 | 200 | #define C_ALWAYS_ZEROFILL 0x08000 /* Always zero-fill the file on an fsync */ |
9bccf70c | 201 | |
6d2010ae A |
202 | #define C_RENAMED 0x10000 /* cnode was deleted as part of rename; C_DELETED should also be set */ |
203 | #define C_NEEDS_DATEADDED 0x20000 /* cnode needs date-added written to the finderinfo bit */ | |
204 | #define C_BACKINGSTORE 0x40000 /* cnode is a backing store for an existing or currently-mounting filesystem */ | |
9bccf70c A |
205 | #define ZFTIMELIMIT (5 * 60) |
206 | ||
2d21ac55 A |
207 | /* |
208 | * The following is the "invisible" bit from the fdFlags field | |
209 | * in the FndrFileInfo. | |
210 | */ | |
211 | enum { kFinderInvisibleMask = 1 << 14 }; | |
212 | ||
213 | ||
9bccf70c A |
214 | /* |
215 | * Convert between cnode pointers and vnode pointers | |
216 | */ | |
91447636 | 217 | #define VTOC(vp) ((struct cnode *)vnode_fsnode((vp))) |
9bccf70c A |
218 | |
219 | #define CTOV(cp,rsrc) (((rsrc) && S_ISREG((cp)->c_mode)) ? \ | |
220 | (cp)->c_rsrc_vp : (cp)->c_vp) | |
221 | ||
222 | /* | |
223 | * Convert between vnode pointers and file forks | |
224 | * | |
225 | * Note: no CTOF since that is ambiguous | |
226 | */ | |
227 | ||
228 | #define FTOC(fp) ((fp)->ff_cp) | |
229 | ||
230 | #define VTOF(vp) ((vp) == VTOC((vp))->c_rsrc_vp ? \ | |
231 | VTOC((vp))->c_rsrcfork : \ | |
232 | VTOC((vp))->c_datafork) | |
233 | ||
2d21ac55 A |
234 | #define VCTOF(vp, cp) ((vp) == (cp)->c_rsrc_vp ? \ |
235 | (cp)->c_rsrcfork : \ | |
236 | (cp)->c_datafork) | |
237 | ||
9bccf70c A |
238 | #define FTOV(fp) ((fp) == FTOC(fp)->c_rsrcfork ? \ |
239 | FTOC(fp)->c_rsrc_vp : \ | |
240 | FTOC(fp)->c_vp) | |
241 | ||
b7266188 A |
242 | /* |
243 | * This is a helper function used for determining whether or not a cnode has become open | |
244 | * unlinked in between the time we acquired its vnode and the time we acquire the cnode lock | |
245 | * to start manipulating it. Due to the SMP nature of VFS, it is probably necessary to | |
246 | * use this macro every time we acquire a cnode lock, as the content of the Cnode may have | |
247 | * been modified in betweeen the lookup and a VNOP. Whether or not to call this is dependent | |
248 | * upon the VNOP in question. Sometimes it is OK to use an open-unlinked file, for example, in, | |
249 | * reading. But other times, such as on the source of a VNOP_RENAME, it should be disallowed. | |
250 | */ | |
6d2010ae | 251 | int hfs_checkdeleted(struct cnode *cp); |
55e303ae | 252 | |
9bccf70c A |
253 | /* |
254 | * Test for a resource fork | |
255 | */ | |
256 | #define FORK_IS_RSRC(fp) ((fp) == FTOC(fp)->c_rsrcfork) | |
257 | ||
258 | #define VNODE_IS_RSRC(vp) ((vp) == VTOC((vp))->c_rsrc_vp) | |
259 | ||
b0d623f7 A |
260 | #if HFS_COMPRESSION |
261 | /* | |
262 | * VTOCMP(vp) returns a pointer to vp's decmpfs_cnode; this could be NULL | |
263 | * if the file is not compressed or if hfs_file_is_compressed() hasn't | |
264 | * yet been called on this file. | |
265 | */ | |
266 | #define VTOCMP(vp) (VTOC((vp))->c_decmp) | |
267 | int hfs_file_is_compressed(struct cnode *cp, int skiplock); | |
268 | int hfs_uncompressed_size_of_compressed_file(struct hfsmount *hfsmp, struct vnode *vp, cnid_t fid, off_t *size, int skiplock); | |
269 | int hfs_hides_rsrc(vfs_context_t ctx, struct cnode *cp, int skiplock); | |
270 | int hfs_hides_xattr(vfs_context_t ctx, struct cnode *cp, const char *name, int skiplock); | |
271 | #endif | |
9bccf70c | 272 | |
55e303ae | 273 | #define ATIME_ONDISK_ACCURACY 300 |
9bccf70c | 274 | |
91447636 A |
275 | |
276 | /* This overlays the FileID portion of NFS file handles. */ | |
9bccf70c | 277 | struct hfsfid { |
9bccf70c A |
278 | u_int32_t hfsfid_cnid; /* Catalog node ID. */ |
279 | u_int32_t hfsfid_gen; /* Generation number (create date). */ | |
280 | }; | |
281 | ||
282 | ||
2d21ac55 A |
283 | /* Get new default vnode */ |
284 | extern int hfs_getnewvnode(struct hfsmount *hfsmp, struct vnode *dvp, struct componentname *cnp, | |
285 | struct cat_desc *descp, int flags, struct cat_attr *attrp, | |
6d2010ae | 286 | struct cat_fork *forkp, struct vnode **vpp, int *out_flags); |
2d21ac55 | 287 | |
6d2010ae | 288 | /* Input flags for hfs_getnewvnode */ |
2d21ac55 A |
289 | |
290 | #define GNV_WANTRSRC 0x01 /* Request the resource fork vnode. */ | |
291 | #define GNV_SKIPLOCK 0x02 /* Skip taking the cnode lock (when getting resource fork). */ | |
292 | #define GNV_CREATE 0x04 /* The vnode is for a newly created item. */ | |
6d2010ae | 293 | #define GNV_NOCACHE 0x08 /* Delay entering this item in the name cache */ |
2d21ac55 | 294 | |
6d2010ae A |
295 | /* Output flags for hfs_getnewvnode */ |
296 | #define GNV_CHASH_RENAMED 0x01 /* The cnode was renamed in-flight */ | |
297 | #define GNV_CAT_DELETED 0x02 /* The cnode was deleted from the catalog */ | |
298 | #define GNV_NEW_CNODE 0x04 /* We are vending out a newly initialized cnode */ | |
299 | #define GNV_CAT_ATTRCHANGED 0x08 /* Something in struct cat_attr changed in between cat_lookups */ | |
2d21ac55 A |
300 | |
301 | /* Touch cnode times based on c_touch_xxx flags */ | |
91447636 | 302 | extern void hfs_touchtimes(struct hfsmount *, struct cnode *); |
6d2010ae A |
303 | extern void hfs_write_dateadded (struct cat_attr *cattrp, u_int32_t dateadded); |
304 | extern u_int32_t hfs_get_dateadded (struct cnode *cp); | |
305 | ||
306 | /* Zero-fill file and push regions out to disk */ | |
307 | extern int hfs_filedone(struct vnode *vp, vfs_context_t context); | |
91447636 | 308 | |
9bccf70c A |
309 | /* |
310 | * HFS cnode hash functions. | |
311 | */ | |
312 | extern void hfs_chashinit(void); | |
b0d623f7 A |
313 | extern void hfs_chashinit_finish(struct hfsmount *hfsmp); |
314 | extern void hfs_delete_chash(struct hfsmount *hfsmp); | |
315 | extern int hfs_chashremove(struct hfsmount *hfsmp, struct cnode *cp); | |
316 | extern void hfs_chash_abort(struct hfsmount *hfsmp, struct cnode *cp); | |
317 | extern void hfs_chash_rehash(struct hfsmount *hfsmp, struct cnode *cp1, struct cnode *cp2); | |
318 | extern void hfs_chashwakeup(struct hfsmount *hfsmp, struct cnode *cp, int flags); | |
319 | extern void hfs_chash_mark_in_transit(struct hfsmount *hfsmp, struct cnode *cp); | |
320 | ||
6d2010ae A |
321 | extern struct vnode * hfs_chash_getvnode(struct hfsmount *hfsmp, ino_t inum, int wantrsrc, |
322 | int skiplock, int allow_deleted); | |
323 | extern struct cnode * hfs_chash_getcnode(struct hfsmount *hfsmp, ino_t inum, struct vnode **vpp, | |
324 | int wantrsrc, int skiplock, int *out_flags, int *hflags); | |
b0d623f7 | 325 | extern int hfs_chash_snoop(struct hfsmount *, ino_t, int (*)(const struct cat_desc *, |
91447636 | 326 | const struct cat_attr *, void *), void *); |
6d2010ae A |
327 | extern int hfs_valid_cnode(struct hfsmount *hfsmp, struct vnode *dvp, struct componentname *cnp, |
328 | cnid_t cnid, struct cat_attr *cattr, int *error); | |
91447636 | 329 | |
b0d623f7 | 330 | extern int hfs_chash_set_childlinkbit(struct hfsmount *hfsmp, cnid_t cnid); |
91447636 A |
331 | |
332 | /* | |
333 | * HFS cnode lock functions. | |
334 | * | |
335 | * HFS Locking Order: | |
336 | * | |
337 | * 1. cnode truncate lock (if needed) | |
338 | * 2. cnode lock (in parent-child order if related, otherwise by address order) | |
339 | * 3. journal (if needed) | |
340 | * 4. system files (as needed) | |
341 | * A. Catalog B-tree file | |
342 | * B. Attributes B-tree file | |
2d21ac55 A |
343 | * C. Startup file (if there is one) |
344 | * D. Allocation Bitmap file (always exclusive, supports recursion) | |
345 | * E. Overflow Extents B-tree file (always exclusive, supports recursion) | |
91447636 A |
346 | * 5. hfs mount point (always last) |
347 | * | |
348 | */ | |
6d2010ae | 349 | enum hfslocktype {HFS_SHARED_LOCK = 1, HFS_EXCLUSIVE_LOCK = 2, HFS_FORCE_LOCK = 3, HFS_RECURSE_TRUNCLOCK = 4}; |
91447636 A |
350 | #define HFS_SHARED_OWNER (void *)0xffffffff |
351 | ||
6d2010ae A |
352 | int hfs_lock(struct cnode *, enum hfslocktype); |
353 | int hfs_lockpair(struct cnode *, struct cnode *, enum hfslocktype); | |
354 | int hfs_lockfour(struct cnode *, struct cnode *, struct cnode *, struct cnode *, | |
b0d623f7 | 355 | enum hfslocktype, struct cnode **); |
91447636 | 356 | |
6d2010ae A |
357 | void hfs_unlock(struct cnode *); |
358 | void hfs_unlockpair(struct cnode *, struct cnode *); | |
359 | void hfs_unlockfour(struct cnode *, struct cnode *, struct cnode *, struct cnode *); | |
360 | ||
361 | void hfs_lock_truncate(struct cnode *, enum hfslocktype); | |
362 | void hfs_unlock_truncate(struct cnode *, int been_recursed); | |
91447636 | 363 | |
6d2010ae | 364 | int hfs_try_trunclock(struct cnode *, enum hfslocktype); |
9bccf70c A |
365 | |
366 | #endif /* __APPLE_API_PRIVATE */ | |
367 | #endif /* KERNEL */ | |
368 | ||
369 | #endif /* ! _HFS_CNODE_H_ */ |