]>
Commit | Line | Data |
---|---|---|
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_CNODE_H_ | |
23 | #define _HFS_CNODE_H_ | |
24 | ||
25 | #include <sys/appleapiopts.h> | |
26 | ||
27 | #ifdef KERNEL | |
28 | #ifdef __APPLE_API_PRIVATE | |
29 | #include <sys/types.h> | |
9bccf70c A |
30 | #include <sys/queue.h> |
31 | #include <sys/stat.h> | |
32 | #include <sys/vnode.h> | |
33 | #include <sys/quota.h> | |
34 | ||
91447636 A |
35 | #include <kern/locks.h> |
36 | ||
9bccf70c A |
37 | #include <hfs/hfs_catalog.h> |
38 | #include <hfs/rangelist.h> | |
39 | ||
40 | ||
41 | /* | |
42 | * The filefork is used to represent an HFS file fork (data or resource). | |
43 | * Reading or writing any of these fields requires holding cnode lock. | |
44 | */ | |
45 | struct filefork { | |
91447636 A |
46 | struct cnode *ff_cp; /* cnode associated with this fork */ |
47 | struct rl_head ff_invalidranges; /* Areas of disk that should read back as zeroes */ | |
9bccf70c | 48 | union { |
91447636 A |
49 | void *ffu_sysfileinfo; /* additional info for system files */ |
50 | char *ffu_symlinkptr; /* symbolic link pathname */ | |
51 | } ff_union; | |
52 | struct cat_fork ff_data; /* fork data (size, extents) */ | |
9bccf70c | 53 | }; |
55e303ae | 54 | typedef struct filefork filefork_t; |
9bccf70c A |
55 | |
56 | /* Aliases for common fields */ | |
91447636 A |
57 | #define ff_size ff_data.cf_size |
58 | #define ff_clumpsize ff_data.cf_clump | |
59 | #define ff_bytesread ff_data.cf_bytesread | |
60 | #define ff_blocks ff_data.cf_blocks | |
61 | #define ff_extents ff_data.cf_extents | |
55e303ae A |
62 | #define ff_unallocblocks ff_data.cf_vblocks |
63 | ||
91447636 A |
64 | #define ff_symlinkptr ff_union.ffu_symlinkptr |
65 | #define ff_sysfileinfo ff_union.ffu_sysfileinfo | |
9bccf70c A |
66 | |
67 | ||
68 | /* The btree code still needs these... */ | |
91447636 A |
69 | #define fcbEOF ff_size |
70 | #define fcbExtents ff_extents | |
71 | #define fcbBTCBPtr ff_sysfileinfo | |
9bccf70c | 72 | |
91447636 A |
73 | typedef u_int8_t atomicflag_t; |
74 | ||
9bccf70c A |
75 | /* |
76 | * The cnode is used to represent each active (or recently active) | |
77 | * file or directory in the HFS filesystem. | |
78 | * | |
79 | * Reading or writing any of these fields requires holding c_lock. | |
80 | */ | |
81 | struct cnode { | |
91447636 A |
82 | lck_rw_t c_rwlock; /* cnode's lock */ |
83 | void * c_lockowner; /* cnode's lock owner (exclusive case only) */ | |
84 | lck_rw_t c_truncatelock; /* protects file from truncation during read/write */ | |
9bccf70c A |
85 | LIST_ENTRY(cnode) c_hash; /* cnode's hash chain */ |
86 | u_int32_t c_flag; /* cnode's runtime flags */ | |
91447636 | 87 | u_int32_t c_hflag; /* cnode's flags for maintaining hash - protected by global hash lock */ |
9bccf70c A |
88 | struct vnode *c_vp; /* vnode for data fork or dir */ |
89 | struct vnode *c_rsrc_vp; /* vnode for resource fork */ | |
90 | struct vnode *c_devvp; /* vnode for block I/O */ | |
91 | dev_t c_dev; /* cnode's device */ | |
92 | struct dquot *c_dquot[MAXQUOTAS]; /* cnode's quota info */ | |
55e303ae | 93 | struct klist c_knotes; /* knotes attached to this vnode */ |
91447636 | 94 | u_long c_childhint; /* catalog hint for children */ |
9bccf70c A |
95 | struct cat_desc c_desc; /* cnode's descriptor */ |
96 | struct cat_attr c_attr; /* cnode's attributes */ | |
b36670ce | 97 | TAILQ_HEAD(hfs_hinthead, directoryhint) c_hintlist; /* directory hint list */ |
91447636 A |
98 | int16_t c_dirhinttag; /* directory hint tag */ |
99 | union { | |
100 | int16_t cu_dirhintcnt; /* directory hint count */ | |
101 | int16_t cu_syslockcount; /* system file use only */ | |
102 | } c_union; | |
9bccf70c A |
103 | struct filefork *c_datafork; /* cnode's data fork */ |
104 | struct filefork *c_rsrcfork; /* cnode's rsrc fork */ | |
91447636 A |
105 | atomicflag_t c_touch_acctime; |
106 | atomicflag_t c_touch_chgtime; | |
107 | atomicflag_t c_touch_modtime; | |
9bccf70c | 108 | }; |
55e303ae | 109 | typedef struct cnode cnode_t; |
9bccf70c A |
110 | |
111 | /* Aliases for common cnode fields */ | |
112 | #define c_cnid c_desc.cd_cnid | |
113 | #define c_hint c_desc.cd_hint | |
114 | #define c_parentcnid c_desc.cd_parentcnid | |
115 | #define c_encoding c_desc.cd_encoding | |
116 | ||
117 | #define c_fileid c_attr.ca_fileid | |
118 | #define c_mode c_attr.ca_mode | |
119 | #define c_nlink c_attr.ca_nlink | |
120 | #define c_uid c_attr.ca_uid | |
121 | #define c_gid c_attr.ca_gid | |
122 | #define c_rdev c_attr.ca_rdev | |
123 | #define c_atime c_attr.ca_atime | |
124 | #define c_mtime c_attr.ca_mtime | |
9bccf70c A |
125 | #define c_ctime c_attr.ca_ctime |
126 | #define c_itime c_attr.ca_itime | |
127 | #define c_btime c_attr.ca_btime | |
128 | #define c_flags c_attr.ca_flags | |
129 | #define c_finderinfo c_attr.ca_finderinfo | |
130 | #define c_blocks c_attr.ca_blocks | |
91447636 | 131 | #define c_attrblks c_attr.ca_attrblks |
9bccf70c A |
132 | #define c_entries c_attr.ca_entries |
133 | #define c_zftimeout c_childhint | |
134 | ||
91447636 A |
135 | #define c_dirhintcnt c_union.cu_dirhintcnt |
136 | #define c_syslockcount c_union.cu_syslockcount | |
9bccf70c | 137 | |
55e303ae | 138 | |
91447636 A |
139 | /* hash maintenance flags kept in c_hflag and protected by hfs_chash_mutex */ |
140 | #define H_ALLOC 0x00001 /* CNode is being allocated */ | |
141 | #define H_ATTACH 0x00002 /* CNode is being attached to by another vnode */ | |
142 | #define H_TRANSIT 0x00004 /* CNode is getting recycled */ | |
143 | #define H_WAITING 0x00008 /* CNode is being waited for */ | |
144 | ||
9bccf70c | 145 | |
91447636 A |
146 | /* Runtime cnode flags (kept in c_flag) */ |
147 | #define C_NEED_RVNODE_PUT 0x00001 /* Need to do a vnode_put on c_rsrc_vp after the unlock */ | |
148 | #define C_NEED_DVNODE_PUT 0x00002 /* Need to do a vnode_put on c_vp after the unlock */ | |
149 | #define C_ZFWANTSYNC 0x00004 /* fsync requested and file has holes */ | |
150 | #define C_FROMSYNC 0x00008 /* fsync was called from sync */ | |
9bccf70c | 151 | |
91447636 A |
152 | #define C_MODIFIED 0x00010 /* CNode has been modified */ |
153 | #define C_NOEXISTS 0x00020 /* CNode has been deleted, catalog entry is gone */ | |
154 | #define C_DELETED 0x00040 /* CNode has been marked to be deleted */ | |
155 | #define C_HARDLINK 0x00080 /* CNode is a hard link */ | |
9bccf70c | 156 | |
91447636 A |
157 | #define C_FORCEUPDATE 0x00100 /* force the catalog entry update */ |
158 | #define C_HASXATTRS 0x00200 /* cnode has extended attributes */ | |
9bccf70c A |
159 | |
160 | ||
161 | #define ZFTIMELIMIT (5 * 60) | |
162 | ||
163 | /* | |
164 | * Convert between cnode pointers and vnode pointers | |
165 | */ | |
91447636 | 166 | #define VTOC(vp) ((struct cnode *)vnode_fsnode((vp))) |
9bccf70c A |
167 | |
168 | #define CTOV(cp,rsrc) (((rsrc) && S_ISREG((cp)->c_mode)) ? \ | |
169 | (cp)->c_rsrc_vp : (cp)->c_vp) | |
170 | ||
171 | /* | |
172 | * Convert between vnode pointers and file forks | |
173 | * | |
174 | * Note: no CTOF since that is ambiguous | |
175 | */ | |
176 | ||
177 | #define FTOC(fp) ((fp)->ff_cp) | |
178 | ||
179 | #define VTOF(vp) ((vp) == VTOC((vp))->c_rsrc_vp ? \ | |
180 | VTOC((vp))->c_rsrcfork : \ | |
181 | VTOC((vp))->c_datafork) | |
182 | ||
183 | #define FTOV(fp) ((fp) == FTOC(fp)->c_rsrcfork ? \ | |
184 | FTOC(fp)->c_rsrc_vp : \ | |
185 | FTOC(fp)->c_vp) | |
186 | ||
55e303ae | 187 | |
9bccf70c A |
188 | /* |
189 | * Test for a resource fork | |
190 | */ | |
191 | #define FORK_IS_RSRC(fp) ((fp) == FTOC(fp)->c_rsrcfork) | |
192 | ||
193 | #define VNODE_IS_RSRC(vp) ((vp) == VTOC((vp))->c_rsrc_vp) | |
194 | ||
195 | ||
55e303ae | 196 | #define ATIME_ONDISK_ACCURACY 300 |
9bccf70c | 197 | |
91447636 A |
198 | |
199 | /* This overlays the FileID portion of NFS file handles. */ | |
9bccf70c | 200 | struct hfsfid { |
9bccf70c A |
201 | u_int32_t hfsfid_cnid; /* Catalog node ID. */ |
202 | u_int32_t hfsfid_gen; /* Generation number (create date). */ | |
203 | }; | |
204 | ||
205 | ||
91447636 A |
206 | extern void hfs_touchtimes(struct hfsmount *, struct cnode *); |
207 | ||
9bccf70c A |
208 | /* |
209 | * HFS cnode hash functions. | |
210 | */ | |
211 | extern void hfs_chashinit(void); | |
212 | extern void hfs_chashinsert(struct cnode *cp); | |
91447636 A |
213 | extern int hfs_chashremove(struct cnode *cp); |
214 | extern void hfs_chash_abort(struct cnode *cp); | |
215 | extern void hfs_chash_rehash(struct cnode *cp1, struct cnode *cp2); | |
216 | extern void hfs_chashwakeup(struct cnode *cp, int flags); | |
217 | extern void hfs_chash_mark_in_transit(struct cnode *cp); | |
218 | ||
219 | extern struct vnode * hfs_chash_getvnode(dev_t dev, ino_t inum, int wantrsrc, int skiplock); | |
220 | extern struct cnode * hfs_chash_getcnode(dev_t dev, ino_t inum, struct vnode **vpp, int wantrsrc, int skiplock); | |
221 | extern int hfs_chash_snoop(dev_t, ino_t, int (*)(const struct cat_desc *, | |
222 | const struct cat_attr *, void *), void *); | |
223 | ||
224 | /* | |
225 | * HFS directory hint functions. | |
226 | */ | |
227 | extern directoryhint_t * hfs_getdirhint(struct cnode *, int); | |
228 | extern void hfs_reldirhint(struct cnode *, directoryhint_t *); | |
229 | extern void hfs_reldirhints(struct cnode *, int); | |
230 | ||
231 | /* | |
232 | * HFS cnode lock functions. | |
233 | * | |
234 | * HFS Locking Order: | |
235 | * | |
236 | * 1. cnode truncate lock (if needed) | |
237 | * 2. cnode lock (in parent-child order if related, otherwise by address order) | |
238 | * 3. journal (if needed) | |
239 | * 4. system files (as needed) | |
240 | * A. Catalog B-tree file | |
241 | * B. Attributes B-tree file | |
242 | * C. Allocation Bitmap file (always exclusive, supports recursion) | |
243 | * D. Overflow Extents B-tree file (always exclusive, supports recursion) | |
244 | * 5. hfs mount point (always last) | |
245 | * | |
246 | */ | |
247 | enum hfslocktype {HFS_SHARED_LOCK = 1, HFS_EXCLUSIVE_LOCK = 2, HFS_FORCE_LOCK = 3}; | |
248 | #define HFS_SHARED_OWNER (void *)0xffffffff | |
249 | ||
250 | extern int hfs_lock(struct cnode *, enum hfslocktype); | |
251 | extern int hfs_lockpair(struct cnode *, struct cnode *, enum hfslocktype); | |
252 | extern int hfs_lockfour(struct cnode *, struct cnode *, struct cnode *, struct cnode *, | |
253 | enum hfslocktype); | |
254 | ||
255 | extern void hfs_unlock(struct cnode *); | |
256 | extern void hfs_unlockpair(struct cnode *, struct cnode *); | |
257 | extern void hfs_unlockfour(struct cnode *, struct cnode *, struct cnode *, struct cnode *); | |
258 | ||
259 | extern void hfs_lock_truncate(struct cnode *, int); | |
260 | extern void hfs_unlock_truncate(struct cnode *); | |
9bccf70c A |
261 | |
262 | #endif /* __APPLE_API_PRIVATE */ | |
263 | #endif /* KERNEL */ | |
264 | ||
265 | #endif /* ! _HFS_CNODE_H_ */ |