]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (c) 2002 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 | union { | |
48 | struct hfslockf *ffu_lockf; /* Head of byte-level lock list. */ | |
49 | void *ffu_sysdata; /* private data for system files */ | |
50 | char *ffu_symlinkptr; /* symbolic link pathname */ | |
51 | } ff_un; | |
52 | struct cat_fork ff_data; | |
53 | u_int32_t ff_unallocblocks; /* unallocated blocks (until cmap) */ | |
54 | }; | |
55 | ||
56 | /* Aliases for common fields */ | |
57 | #define ff_size ff_data.cf_size | |
58 | #define ff_clumpsize ff_data.cf_clump | |
59 | #define ff_blocks ff_data.cf_blocks | |
60 | #define ff_extents ff_data.cf_extents | |
61 | #define ff_symlinkptr ff_un.ffu_symlinkptr | |
62 | #define ff_lockf ff_un.ffu_lockf | |
63 | ||
64 | ||
65 | /* The btree code still needs these... */ | |
66 | #define fcbEOF ff_size | |
67 | #define fcbClmpSize ff_clumpsize | |
68 | #define fcbExtents ff_extents | |
69 | #define fcbBTCBPtr ff_un.ffu_sysdata | |
70 | ||
71 | ||
72 | /* | |
73 | * Directory index entry | |
74 | */ | |
75 | struct hfs_index { | |
76 | SLIST_ENTRY(hfs_index) hi_link; | |
77 | int hi_index; | |
78 | void *hi_thread; /* thread that created index entry */ | |
79 | char hi_name[1]; | |
80 | }; | |
81 | ||
82 | /* | |
83 | * The cnode is used to represent each active (or recently active) | |
84 | * file or directory in the HFS filesystem. | |
85 | * | |
86 | * Reading or writing any of these fields requires holding c_lock. | |
87 | */ | |
88 | struct cnode { | |
89 | struct lock__bsd__ c_lock; /* cnode's lock */ | |
90 | LIST_ENTRY(cnode) c_hash; /* cnode's hash chain */ | |
91 | u_int32_t c_flag; /* cnode's runtime flags */ | |
92 | struct vnode *c_vp; /* vnode for data fork or dir */ | |
93 | struct vnode *c_rsrc_vp; /* vnode for resource fork */ | |
94 | struct vnode *c_devvp; /* vnode for block I/O */ | |
95 | dev_t c_dev; /* cnode's device */ | |
96 | struct dquot *c_dquot[MAXQUOTAS]; /* cnode's quota info */ | |
97 | cnid_t c_childhint; /* catalog hint for children */ | |
98 | struct cat_desc c_desc; /* cnode's descriptor */ | |
99 | struct cat_attr c_attr; /* cnode's attributes */ | |
100 | SLIST_HEAD(hfs_indexhead, hfs_index) c_indexlist; /* directory index list */ | |
101 | struct filefork *c_datafork; /* cnode's data fork */ | |
102 | struct filefork *c_rsrcfork; /* cnode's rsrc fork */ | |
103 | }; | |
104 | ||
105 | /* Aliases for common cnode fields */ | |
106 | #define c_cnid c_desc.cd_cnid | |
107 | #define c_hint c_desc.cd_hint | |
108 | #define c_parentcnid c_desc.cd_parentcnid | |
109 | #define c_encoding c_desc.cd_encoding | |
110 | ||
111 | #define c_fileid c_attr.ca_fileid | |
112 | #define c_mode c_attr.ca_mode | |
113 | #define c_nlink c_attr.ca_nlink | |
114 | #define c_uid c_attr.ca_uid | |
115 | #define c_gid c_attr.ca_gid | |
116 | #define c_rdev c_attr.ca_rdev | |
117 | #define c_atime c_attr.ca_atime | |
118 | #define c_mtime c_attr.ca_mtime | |
119 | #define c_mtime_nsec c_attr.ca_mtime_nsec | |
120 | #define c_ctime c_attr.ca_ctime | |
121 | #define c_itime c_attr.ca_itime | |
122 | #define c_btime c_attr.ca_btime | |
123 | #define c_flags c_attr.ca_flags | |
124 | #define c_finderinfo c_attr.ca_finderinfo | |
125 | #define c_blocks c_attr.ca_blocks | |
126 | #define c_entries c_attr.ca_entries | |
127 | #define c_zftimeout c_childhint | |
128 | ||
129 | ||
130 | /* Runtime cnode flags (kept in c_flag) */ | |
131 | #define C_ACCESS 0x0001 /* Access time update request */ | |
132 | #define C_CHANGE 0x0002 /* Change time update request */ | |
133 | #define C_UPDATE 0x0004 /* Modification time update request */ | |
134 | #define C_MODIFIED 0x0008 /* CNode has been modified */ | |
135 | #define C_ATIMEMOD 0x0010 /* Access time has been modified */ | |
136 | ||
137 | #define C_NOEXISTS 0x0020 /* CNode has been deleted, catalog entry is gone */ | |
138 | #define C_DELETED 0x0040 /* CNode has been marked to be deleted */ | |
139 | #define C_HARDLINK 0x0080 /* CNode is a hard link */ | |
140 | ||
141 | #define C_ALLOC 0x0100 /* CNode is being allocated */ | |
142 | #define C_WALLOC 0x0200 /* Waiting for allocation to finish */ | |
143 | #define C_TRANSIT 0x0400 /* CNode is getting recycled */ | |
144 | #define C_WTRANSIT 0x0800 /* Waiting for cnode getting recycled */ | |
145 | ||
146 | #define C_RENAME 0x1000 /* CNode is being renamed */ | |
147 | #define C_ZFWANTSYNC 0x2000 /* fsync requested and file has holes */ | |
148 | ||
149 | ||
150 | #define ZFTIMELIMIT (5 * 60) | |
151 | ||
152 | /* | |
153 | * Convert between cnode pointers and vnode pointers | |
154 | */ | |
155 | #define VTOC(vp) ((struct cnode *)(vp)->v_data) | |
156 | ||
157 | #define CTOV(cp,rsrc) (((rsrc) && S_ISREG((cp)->c_mode)) ? \ | |
158 | (cp)->c_rsrc_vp : (cp)->c_vp) | |
159 | ||
160 | /* | |
161 | * Convert between vnode pointers and file forks | |
162 | * | |
163 | * Note: no CTOF since that is ambiguous | |
164 | */ | |
165 | ||
166 | #define FTOC(fp) ((fp)->ff_cp) | |
167 | ||
168 | #define VTOF(vp) ((vp) == VTOC((vp))->c_rsrc_vp ? \ | |
169 | VTOC((vp))->c_rsrcfork : \ | |
170 | VTOC((vp))->c_datafork) | |
171 | ||
172 | #define FTOV(fp) ((fp) == FTOC(fp)->c_rsrcfork ? \ | |
173 | FTOC(fp)->c_rsrc_vp : \ | |
174 | FTOC(fp)->c_vp) | |
175 | ||
176 | /* | |
177 | * Test for a resource fork | |
178 | */ | |
179 | #define FORK_IS_RSRC(fp) ((fp) == FTOC(fp)->c_rsrcfork) | |
180 | ||
181 | #define VNODE_IS_RSRC(vp) ((vp) == VTOC((vp))->c_rsrc_vp) | |
182 | ||
183 | ||
184 | /* | |
185 | * CTIMES should be an inline function... | |
186 | */ | |
187 | #define C_TIMEMASK (C_ACCESS | C_CHANGE | C_UPDATE) | |
188 | ||
189 | #define ATIME_ACCURACY 60 | |
190 | ||
191 | #define CTIMES(cp, t1, t2) { \ | |
192 | if ((cp)->c_flag & C_TIMEMASK) { \ | |
193 | /* \ | |
194 | * If only the access time is changing then defer \ | |
195 | * updating it on-disk util later (in hfs_inactive). \ | |
196 | * If it was recently updated then skip the update. \ | |
197 | */ \ | |
198 | if (((cp)->c_flag & (C_TIMEMASK | C_MODIFIED)) == C_ACCESS) { \ | |
199 | if (((cp)->c_flag & C_ATIMEMOD) || \ | |
200 | (t1)->tv_sec > ((cp)->c_atime + ATIME_ACCURACY)) { \ | |
201 | (cp)->c_atime = (t1)->tv_sec; \ | |
202 | (cp)->c_flag |= C_ATIMEMOD; \ | |
203 | } \ | |
204 | (cp)->c_flag &= ~C_ACCESS; \ | |
205 | } else { \ | |
206 | if ((cp)->c_flag & C_ACCESS) { \ | |
207 | (cp)->c_atime = (t1)->tv_sec; \ | |
208 | } \ | |
209 | if ((cp)->c_flag & C_UPDATE) { \ | |
210 | (cp)->c_mtime = (t2)->tv_sec; \ | |
211 | (cp)->c_mtime_nsec = (t2)->tv_usec * 1000; \ | |
212 | } \ | |
213 | if ((cp)->c_flag & C_CHANGE) { \ | |
214 | (cp)->c_ctime = time.tv_sec; \ | |
215 | } \ | |
216 | (cp)->c_flag |= C_MODIFIED; \ | |
217 | (cp)->c_flag &= ~C_TIMEMASK; \ | |
218 | } \ | |
219 | } \ | |
220 | } | |
221 | ||
222 | /* This overlays the fid structure (see mount.h). */ | |
223 | struct hfsfid { | |
224 | u_int16_t hfsfid_len; /* Length of structure. */ | |
225 | u_int16_t hfsfid_pad; /* Force 32-bit alignment. */ | |
226 | /* The following data is filesystem-dependent, up to MAXFIDSZ (16) bytes: */ | |
227 | u_int32_t hfsfid_cnid; /* Catalog node ID. */ | |
228 | u_int32_t hfsfid_gen; /* Generation number (create date). */ | |
229 | }; | |
230 | ||
231 | ||
232 | /* | |
233 | * HFS cnode hash functions. | |
234 | */ | |
235 | extern void hfs_chashinit(void); | |
236 | extern void hfs_chashinsert(struct cnode *cp); | |
237 | extern void hfs_chashremove(struct cnode *cp); | |
238 | extern struct cnode * hfs_chashget(dev_t dev, ino_t inum, int wantrsrc, | |
239 | struct vnode **vpp, struct vnode **rvpp); | |
240 | ||
241 | #endif /* __APPLE_API_PRIVATE */ | |
242 | #endif /* KERNEL */ | |
243 | ||
244 | #endif /* ! _HFS_CNODE_H_ */ |