2 * Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
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
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.
23 * @APPLE_LICENSE_HEADER_END@
28 #include <sys/appleapiopts.h>
31 #ifdef __APPLE_API_PRIVATE
32 #include <sys/types.h>
34 #include <sys/queue.h>
36 #include <sys/vnode.h>
37 #include <sys/quota.h>
39 #include <hfs/hfs_catalog.h>
40 #include <hfs/rangelist.h>
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.
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 */
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 */
55 struct cat_fork ff_data
;
56 u_int32_t ff_unallocblocks
; /* unallocated blocks (until cmap) */
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
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
76 * Directory index entry
79 SLIST_ENTRY(hfs_index
) hi_link
;
81 void *hi_thread
; /* thread that created index entry */
86 * The cnode is used to represent each active (or recently active)
87 * file or directory in the HFS filesystem.
89 * Reading or writing any of these fields requires holding c_lock.
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 */
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
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
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 */
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 */
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 */
149 #define C_RENAME 0x1000 /* CNode is being renamed */
150 #define C_ZFWANTSYNC 0x2000 /* fsync requested and file has holes */
153 #define ZFTIMELIMIT (5 * 60)
156 * Convert between cnode pointers and vnode pointers
158 #define VTOC(vp) ((struct cnode *)(vp)->v_data)
160 #define CTOV(cp,rsrc) (((rsrc) && S_ISREG((cp)->c_mode)) ? \
161 (cp)->c_rsrc_vp : (cp)->c_vp)
164 * Convert between vnode pointers and file forks
166 * Note: no CTOF since that is ambiguous
169 #define FTOC(fp) ((fp)->ff_cp)
171 #define VTOF(vp) ((vp) == VTOC((vp))->c_rsrc_vp ? \
172 VTOC((vp))->c_rsrcfork : \
173 VTOC((vp))->c_datafork)
175 #define FTOV(fp) ((fp) == FTOC(fp)->c_rsrcfork ? \
176 FTOC(fp)->c_rsrc_vp : \
180 * Test for a resource fork
182 #define FORK_IS_RSRC(fp) ((fp) == FTOC(fp)->c_rsrcfork)
184 #define VNODE_IS_RSRC(vp) ((vp) == VTOC((vp))->c_rsrc_vp)
188 * CTIMES should be an inline function...
190 #define C_TIMEMASK (C_ACCESS | C_CHANGE | C_UPDATE)
192 #define ATIME_ACCURACY 60
194 #define CTIMES(cp, t1, t2) { \
195 if ((cp)->c_flag & C_TIMEMASK) { \
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. \
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; \
207 (cp)->c_flag &= ~C_ACCESS; \
209 if ((cp)->c_flag & C_ACCESS) { \
210 (cp)->c_atime = (t1)->tv_sec; \
212 if ((cp)->c_flag & C_UPDATE) { \
213 (cp)->c_mtime = (t2)->tv_sec; \
214 (cp)->c_mtime_nsec = (t2)->tv_usec * 1000; \
216 if ((cp)->c_flag & C_CHANGE) { \
217 (cp)->c_ctime = time.tv_sec; \
219 (cp)->c_flag |= C_MODIFIED; \
220 (cp)->c_flag &= ~C_TIMEMASK; \
225 /* This overlays the fid structure (see mount.h). */
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). */
236 * HFS cnode hash functions.
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
);
244 #endif /* __APPLE_API_PRIVATE */
247 #endif /* ! _HFS_CNODE_H_ */