]> git.saurik.com Git - apple/xnu.git/blob - bsd/hfs/hfs_cnode.h
xnu-517.12.7.tar.gz
[apple/xnu.git] / bsd / hfs / hfs_cnode.h
1 /*
2 * Copyright (c) 2002-2003 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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.
11 *
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
18 * under the License.
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>
30 #include <sys/lock.h>
31 #include <sys/queue.h>
32 #include <sys/stat.h>
33 #include <sys/vnode.h>
34 #include <sys/quota.h>
35
36 #include <hfs/hfs_catalog.h>
37 #include <hfs/rangelist.h>
38
39
40 /*
41 * The filefork is used to represent an HFS file fork (data or resource).
42 * Reading or writing any of these fields requires holding cnode lock.
43 */
44 struct filefork {
45 struct cnode *ff_cp; /* cnode associated with this fork */
46 struct rl_head ff_invalidranges; /* Areas of disk that should read back as zeroes */
47 long ff_evtonly_refs; /* number of vnode references used solely for events (O_EVTONLY) */
48 union {
49 struct hfslockf *ffu_lockf; /* Head of byte-level lock list. */
50 void *ffu_sysdata; /* private data for system files */
51 char *ffu_symlinkptr; /* symbolic link pathname */
52 } ff_un;
53 struct cat_fork ff_data;
54 };
55 typedef struct filefork filefork_t;
56
57 /* Aliases for common fields */
58 #define ff_size ff_data.cf_size
59 #define ff_clumpsize ff_data.cf_clump
60 #define ff_bytesread ff_data.cf_bytesread
61 #define ff_blocks ff_data.cf_blocks
62 #define ff_extents ff_data.cf_extents
63 #define ff_unallocblocks ff_data.cf_vblocks
64
65 #define ff_symlinkptr ff_un.ffu_symlinkptr
66 #define ff_lockf ff_un.ffu_lockf
67
68
69 /* The btree code still needs these... */
70 #define fcbEOF ff_size
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 char hi_name[1];
82 };
83
84 /*
85 * The cnode is used to represent each active (or recently active)
86 * file or directory in the HFS filesystem.
87 *
88 * Reading or writing any of these fields requires holding c_lock.
89 */
90 struct cnode {
91 struct lock__bsd__ c_lock; /* cnode's lock */
92 LIST_ENTRY(cnode) c_hash; /* cnode's hash chain */
93 u_int32_t c_flag; /* cnode's runtime flags */
94 struct vnode *c_vp; /* vnode for data fork or dir */
95 struct vnode *c_rsrc_vp; /* vnode for resource fork */
96 struct vnode *c_devvp; /* vnode for block I/O */
97 dev_t c_dev; /* cnode's device */
98 struct dquot *c_dquot[MAXQUOTAS]; /* cnode's quota info */
99 struct klist c_knotes; /* knotes attached to this vnode */
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 long c_evtonly_refs; /* number of vnode references used solely for events (O_EVTONLY) */
105 struct filefork *c_datafork; /* cnode's data fork */
106 struct filefork *c_rsrcfork; /* cnode's rsrc fork */
107 };
108 typedef struct cnode cnode_t;
109
110 /* Aliases for common cnode fields */
111 #define c_cnid c_desc.cd_cnid
112 #define c_hint c_desc.cd_hint
113 #define c_parentcnid c_desc.cd_parentcnid
114 #define c_encoding c_desc.cd_encoding
115
116 #define c_fileid c_attr.ca_fileid
117 #define c_mode c_attr.ca_mode
118 #define c_nlink c_attr.ca_nlink
119 #define c_uid c_attr.ca_uid
120 #define c_gid c_attr.ca_gid
121 #define c_rdev c_attr.ca_rdev
122 #define c_atime c_attr.ca_atime
123 #define c_mtime c_attr.ca_mtime
124 #define c_mtime_nsec c_attr.ca_mtime_nsec
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
131 #define c_entries c_attr.ca_entries
132 #define c_zftimeout c_childhint
133
134
135 /* Runtime cnode flags (kept in c_flag) */
136 #define C_ACCESS 0x00001 /* Access time update request */
137 #define C_CHANGE 0x00002 /* Change time update request */
138 #define C_UPDATE 0x00004 /* Modification time update request */
139 #define C_MODIFIED 0x00008 /* CNode has been modified */
140
141 #define C_RELOCATING 0x00010 /* CNode's fork is being relocated */
142 #define C_NOEXISTS 0x00020 /* CNode has been deleted, catalog entry is gone */
143 #define C_DELETED 0x00040 /* CNode has been marked to be deleted */
144 #define C_HARDLINK 0x00080 /* CNode is a hard link */
145
146 #define C_ALLOC 0x00100 /* CNode is being allocated */
147 #define C_WALLOC 0x00200 /* Waiting for allocation to finish */
148 #define C_TRANSIT 0x00400 /* CNode is getting recycled */
149 #define C_WTRANSIT 0x00800 /* Waiting for cnode getting recycled */
150 #define C_NOBLKMAP 0x01000 /* CNode blocks cannot be mapped */
151 #define C_WBLKMAP 0x02000 /* Waiting for block map */
152
153 #define C_ZFWANTSYNC 0x04000 /* fsync requested and file has holes */
154 #define C_VPREFHELD 0x08000 /* resource fork has done a vget() on c_vp (for its parent ptr) */
155
156 #define C_FROMSYNC 0x10000 /* fsync was called from sync */
157 #define C_FORCEUPDATE 0x20000 /* force the catalog entry update */
158
159
160 #define ZFTIMELIMIT (5 * 60)
161
162 /*
163 * Convert between cnode pointers and vnode pointers
164 */
165 #define VTOC(vp) ((struct cnode *)(vp)->v_data)
166
167 #define CTOV(cp,rsrc) (((rsrc) && S_ISREG((cp)->c_mode)) ? \
168 (cp)->c_rsrc_vp : (cp)->c_vp)
169
170 /*
171 * Convert between vnode pointers and file forks
172 *
173 * Note: no CTOF since that is ambiguous
174 */
175
176 #define FTOC(fp) ((fp)->ff_cp)
177
178 #define VTOF(vp) ((vp) == VTOC((vp))->c_rsrc_vp ? \
179 VTOC((vp))->c_rsrcfork : \
180 VTOC((vp))->c_datafork)
181
182 #define FTOV(fp) ((fp) == FTOC(fp)->c_rsrcfork ? \
183 FTOC(fp)->c_rsrc_vp : \
184 FTOC(fp)->c_vp)
185
186 #define EVTONLYREFS(vp) ((vp->v_type == VREG) ? VTOF(vp)->ff_evtonly_refs : VTOC(vp)->c_evtonly_refs)
187
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
196 /*
197 * CTIMES should be an inline function...
198 */
199 #define C_TIMEMASK (C_ACCESS | C_CHANGE | C_UPDATE)
200
201 #define C_CHANGEMASK (C_ACCESS | C_CHANGE | C_UPDATE | C_MODIFIED)
202
203 #define ATIME_ACCURACY 1
204 #define ATIME_ONDISK_ACCURACY 300
205
206 #define CTIMES(cp, t1, t2) { \
207 if ((cp)->c_flag & C_TIMEMASK) { \
208 /* \
209 * Only do the update if it is more than just \
210 * the C_ACCESS field being updated. \
211 */ \
212 if (((cp)->c_flag & C_CHANGEMASK) != C_ACCESS) { \
213 if ((cp)->c_flag & C_ACCESS) { \
214 (cp)->c_atime = (t1)->tv_sec; \
215 } \
216 if ((cp)->c_flag & C_UPDATE) { \
217 (cp)->c_mtime = (t2)->tv_sec; \
218 (cp)->c_mtime_nsec = (t2)->tv_usec * 1000; \
219 } \
220 if ((cp)->c_flag & C_CHANGE) { \
221 (cp)->c_ctime = time.tv_sec; \
222 } \
223 (cp)->c_flag |= C_MODIFIED; \
224 (cp)->c_flag &= ~C_TIMEMASK; \
225 } \
226 } \
227 }
228
229 /* This overlays the fid structure (see mount.h). */
230 struct hfsfid {
231 u_int16_t hfsfid_len; /* Length of structure. */
232 u_int16_t hfsfid_pad; /* Force 32-bit alignment. */
233 /* The following data is filesystem-dependent, up to MAXFIDSZ (16) bytes: */
234 u_int32_t hfsfid_cnid; /* Catalog node ID. */
235 u_int32_t hfsfid_gen; /* Generation number (create date). */
236 };
237
238
239 /*
240 * HFS cnode hash functions.
241 */
242 extern void hfs_chashinit(void);
243 extern void hfs_chashinsert(struct cnode *cp);
244 extern void hfs_chashremove(struct cnode *cp);
245 extern struct cnode * hfs_chashget(dev_t dev, ino_t inum, int wantrsrc,
246 struct vnode **vpp, struct vnode **rvpp);
247
248 #endif /* __APPLE_API_PRIVATE */
249 #endif /* KERNEL */
250
251 #endif /* ! _HFS_CNODE_H_ */