]> git.saurik.com Git - apple/xnu.git/blob - bsd/hfs/hfs_cnode.h
eeaee061709ba11c279b94c27700451e3b706a63
[apple/xnu.git] / bsd / hfs / hfs_cnode.h
1 /*
2 * Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 #ifndef _HFS_CNODE_H_
26 #define _HFS_CNODE_H_
27
28 #include <sys/appleapiopts.h>
29
30 #ifdef KERNEL
31 #ifdef __APPLE_API_PRIVATE
32 #include <sys/types.h>
33 #include <sys/lock.h>
34 #include <sys/queue.h>
35 #include <sys/stat.h>
36 #include <sys/vnode.h>
37 #include <sys/quota.h>
38
39 #include <hfs/hfs_catalog.h>
40 #include <hfs/rangelist.h>
41
42
43 /*
44 * The filefork is used to represent an HFS file fork (data or resource).
45 * Reading or writing any of these fields requires holding cnode lock.
46 */
47 struct filefork {
48 struct cnode *ff_cp; /* cnode associated with this fork */
49 struct rl_head ff_invalidranges; /* Areas of disk that should read back as zeroes */
50 union {
51 struct hfslockf *ffu_lockf; /* Head of byte-level lock list. */
52 void *ffu_sysdata; /* private data for system files */
53 char *ffu_symlinkptr; /* symbolic link pathname */
54 } ff_un;
55 struct cat_fork ff_data;
56 u_int32_t ff_unallocblocks; /* unallocated blocks (until cmap) */
57 };
58
59 /* Aliases for common fields */
60 #define ff_size ff_data.cf_size
61 #define ff_clumpsize ff_data.cf_clump
62 #define ff_blocks ff_data.cf_blocks
63 #define ff_extents ff_data.cf_extents
64 #define ff_symlinkptr ff_un.ffu_symlinkptr
65 #define ff_lockf ff_un.ffu_lockf
66
67
68 /* The btree code still needs these... */
69 #define fcbEOF ff_size
70 #define fcbClmpSize ff_clumpsize
71 #define fcbExtents ff_extents
72 #define fcbBTCBPtr ff_un.ffu_sysdata
73
74
75 /*
76 * Directory index entry
77 */
78 struct hfs_index {
79 SLIST_ENTRY(hfs_index) hi_link;
80 int hi_index;
81 void *hi_thread; /* thread that created index entry */
82 char hi_name[1];
83 };
84
85 /*
86 * The cnode is used to represent each active (or recently active)
87 * file or directory in the HFS filesystem.
88 *
89 * Reading or writing any of these fields requires holding c_lock.
90 */
91 struct cnode {
92 struct lock__bsd__ c_lock; /* cnode's lock */
93 LIST_ENTRY(cnode) c_hash; /* cnode's hash chain */
94 u_int32_t c_flag; /* cnode's runtime flags */
95 struct vnode *c_vp; /* vnode for data fork or dir */
96 struct vnode *c_rsrc_vp; /* vnode for resource fork */
97 struct vnode *c_devvp; /* vnode for block I/O */
98 dev_t c_dev; /* cnode's device */
99 struct dquot *c_dquot[MAXQUOTAS]; /* cnode's quota info */
100 cnid_t c_childhint; /* catalog hint for children */
101 struct cat_desc c_desc; /* cnode's descriptor */
102 struct cat_attr c_attr; /* cnode's attributes */
103 SLIST_HEAD(hfs_indexhead, hfs_index) c_indexlist; /* directory index list */
104 struct filefork *c_datafork; /* cnode's data fork */
105 struct filefork *c_rsrcfork; /* cnode's rsrc fork */
106 };
107
108 /* Aliases for common cnode fields */
109 #define c_cnid c_desc.cd_cnid
110 #define c_hint c_desc.cd_hint
111 #define c_parentcnid c_desc.cd_parentcnid
112 #define c_encoding c_desc.cd_encoding
113
114 #define c_fileid c_attr.ca_fileid
115 #define c_mode c_attr.ca_mode
116 #define c_nlink c_attr.ca_nlink
117 #define c_uid c_attr.ca_uid
118 #define c_gid c_attr.ca_gid
119 #define c_rdev c_attr.ca_rdev
120 #define c_atime c_attr.ca_atime
121 #define c_mtime c_attr.ca_mtime
122 #define c_mtime_nsec c_attr.ca_mtime_nsec
123 #define c_ctime c_attr.ca_ctime
124 #define c_itime c_attr.ca_itime
125 #define c_btime c_attr.ca_btime
126 #define c_flags c_attr.ca_flags
127 #define c_finderinfo c_attr.ca_finderinfo
128 #define c_blocks c_attr.ca_blocks
129 #define c_entries c_attr.ca_entries
130 #define c_zftimeout c_childhint
131
132
133 /* Runtime cnode flags (kept in c_flag) */
134 #define C_ACCESS 0x0001 /* Access time update request */
135 #define C_CHANGE 0x0002 /* Change time update request */
136 #define C_UPDATE 0x0004 /* Modification time update request */
137 #define C_MODIFIED 0x0008 /* CNode has been modified */
138 #define C_ATIMEMOD 0x0010 /* Access time has been modified */
139
140 #define C_NOEXISTS 0x0020 /* CNode has been deleted, catalog entry is gone */
141 #define C_DELETED 0x0040 /* CNode has been marked to be deleted */
142 #define C_HARDLINK 0x0080 /* CNode is a hard link */
143
144 #define C_ALLOC 0x0100 /* CNode is being allocated */
145 #define C_WALLOC 0x0200 /* Waiting for allocation to finish */
146 #define C_TRANSIT 0x0400 /* CNode is getting recycled */
147 #define C_WTRANSIT 0x0800 /* Waiting for cnode getting recycled */
148
149 #define C_RENAME 0x1000 /* CNode is being renamed */
150 #define C_ZFWANTSYNC 0x2000 /* fsync requested and file has holes */
151
152
153 #define ZFTIMELIMIT (5 * 60)
154
155 /*
156 * Convert between cnode pointers and vnode pointers
157 */
158 #define VTOC(vp) ((struct cnode *)(vp)->v_data)
159
160 #define CTOV(cp,rsrc) (((rsrc) && S_ISREG((cp)->c_mode)) ? \
161 (cp)->c_rsrc_vp : (cp)->c_vp)
162
163 /*
164 * Convert between vnode pointers and file forks
165 *
166 * Note: no CTOF since that is ambiguous
167 */
168
169 #define FTOC(fp) ((fp)->ff_cp)
170
171 #define VTOF(vp) ((vp) == VTOC((vp))->c_rsrc_vp ? \
172 VTOC((vp))->c_rsrcfork : \
173 VTOC((vp))->c_datafork)
174
175 #define FTOV(fp) ((fp) == FTOC(fp)->c_rsrcfork ? \
176 FTOC(fp)->c_rsrc_vp : \
177 FTOC(fp)->c_vp)
178
179 /*
180 * Test for a resource fork
181 */
182 #define FORK_IS_RSRC(fp) ((fp) == FTOC(fp)->c_rsrcfork)
183
184 #define VNODE_IS_RSRC(vp) ((vp) == VTOC((vp))->c_rsrc_vp)
185
186
187 /*
188 * CTIMES should be an inline function...
189 */
190 #define C_TIMEMASK (C_ACCESS | C_CHANGE | C_UPDATE)
191
192 #define ATIME_ACCURACY 60
193
194 #define CTIMES(cp, t1, t2) { \
195 if ((cp)->c_flag & C_TIMEMASK) { \
196 /* \
197 * If only the access time is changing then defer \
198 * updating it on-disk util later (in hfs_inactive). \
199 * If it was recently updated then skip the update. \
200 */ \
201 if (((cp)->c_flag & (C_TIMEMASK | C_MODIFIED)) == C_ACCESS) { \
202 if (((cp)->c_flag & C_ATIMEMOD) || \
203 (t1)->tv_sec > ((cp)->c_atime + ATIME_ACCURACY)) { \
204 (cp)->c_atime = (t1)->tv_sec; \
205 (cp)->c_flag |= C_ATIMEMOD; \
206 } \
207 (cp)->c_flag &= ~C_ACCESS; \
208 } else { \
209 if ((cp)->c_flag & C_ACCESS) { \
210 (cp)->c_atime = (t1)->tv_sec; \
211 } \
212 if ((cp)->c_flag & C_UPDATE) { \
213 (cp)->c_mtime = (t2)->tv_sec; \
214 (cp)->c_mtime_nsec = (t2)->tv_usec * 1000; \
215 } \
216 if ((cp)->c_flag & C_CHANGE) { \
217 (cp)->c_ctime = time.tv_sec; \
218 } \
219 (cp)->c_flag |= C_MODIFIED; \
220 (cp)->c_flag &= ~C_TIMEMASK; \
221 } \
222 } \
223 }
224
225 /* This overlays the fid structure (see mount.h). */
226 struct hfsfid {
227 u_int16_t hfsfid_len; /* Length of structure. */
228 u_int16_t hfsfid_pad; /* Force 32-bit alignment. */
229 /* The following data is filesystem-dependent, up to MAXFIDSZ (16) bytes: */
230 u_int32_t hfsfid_cnid; /* Catalog node ID. */
231 u_int32_t hfsfid_gen; /* Generation number (create date). */
232 };
233
234
235 /*
236 * HFS cnode hash functions.
237 */
238 extern void hfs_chashinit(void);
239 extern void hfs_chashinsert(struct cnode *cp);
240 extern void hfs_chashremove(struct cnode *cp);
241 extern struct cnode * hfs_chashget(dev_t dev, ino_t inum, int wantrsrc,
242 struct vnode **vpp, struct vnode **rvpp);
243
244 #endif /* __APPLE_API_PRIVATE */
245 #endif /* KERNEL */
246
247 #endif /* ! _HFS_CNODE_H_ */