]>
git.saurik.com Git - apple/xnu.git/blob - bsd/hfs/hfs_cnode.h
6188156d37fa8f1958fe1fca0856c79df2b1b817
2 * Copyright (c) 2002-2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
25 #include <sys/appleapiopts.h>
28 #ifdef __APPLE_API_PRIVATE
29 #include <sys/types.h>
31 #include <sys/queue.h>
33 #include <sys/vnode.h>
34 #include <sys/quota.h>
36 #include <hfs/hfs_catalog.h>
37 #include <hfs/rangelist.h>
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.
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) */
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 */
53 struct cat_fork ff_data
;
55 typedef struct filefork filefork_t
;
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
65 #define ff_symlinkptr ff_un.ffu_symlinkptr
66 #define ff_lockf ff_un.ffu_lockf
69 /* The btree code still needs these... */
70 #define fcbEOF ff_size
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 struct klist c_knotes
; /* knotes attached to this vnode */
101 cnid_t c_childhint
; /* catalog hint for children */
102 struct cat_desc c_desc
; /* cnode's descriptor */
103 struct cat_attr c_attr
; /* cnode's attributes */
104 SLIST_HEAD(hfs_indexhead
, hfs_index
) c_indexlist
; /* directory index list */
105 long c_evtonly_refs
; /* number of vnode references used solely for events (O_EVTONLY) */
106 struct filefork
*c_datafork
; /* cnode's data fork */
107 struct filefork
*c_rsrcfork
; /* cnode's rsrc fork */
109 typedef struct cnode cnode_t
;
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
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
125 #define c_mtime_nsec c_attr.ca_mtime_nsec
126 #define c_ctime c_attr.ca_ctime
127 #define c_itime c_attr.ca_itime
128 #define c_btime c_attr.ca_btime
129 #define c_flags c_attr.ca_flags
130 #define c_finderinfo c_attr.ca_finderinfo
131 #define c_blocks c_attr.ca_blocks
132 #define c_entries c_attr.ca_entries
133 #define c_zftimeout c_childhint
136 /* Runtime cnode flags (kept in c_flag) */
137 #define C_ACCESS 0x00001 /* Access time update request */
138 #define C_CHANGE 0x00002 /* Change time update request */
139 #define C_UPDATE 0x00004 /* Modification time update request */
140 #define C_MODIFIED 0x00008 /* CNode has been modified */
142 #define C_RELOCATING 0x00010 /* CNode's fork is being relocated */
143 #define C_NOEXISTS 0x00020 /* CNode has been deleted, catalog entry is gone */
144 #define C_DELETED 0x00040 /* CNode has been marked to be deleted */
145 #define C_HARDLINK 0x00080 /* CNode is a hard link */
147 #define C_ALLOC 0x00100 /* CNode is being allocated */
148 #define C_WALLOC 0x00200 /* Waiting for allocation to finish */
149 #define C_TRANSIT 0x00400 /* CNode is getting recycled */
150 #define C_WTRANSIT 0x00800 /* Waiting for cnode getting recycled */
151 #define C_NOBLKMAP 0x01000 /* CNode blocks cannot be mapped */
152 #define C_WBLKMAP 0x02000 /* Waiting for block map */
154 #define C_ZFWANTSYNC 0x04000 /* fsync requested and file has holes */
155 #define C_VPREFHELD 0x08000 /* resource fork has done a vget() on c_vp (for its parent ptr) */
157 #define C_FROMSYNC 0x10000 /* fsync was called from sync */
158 #define C_FORCEUPDATE 0x20000 /* force the catalog entry update */
161 #define ZFTIMELIMIT (5 * 60)
164 * Convert between cnode pointers and vnode pointers
166 #define VTOC(vp) ((struct cnode *)(vp)->v_data)
168 #define CTOV(cp,rsrc) (((rsrc) && S_ISREG((cp)->c_mode)) ? \
169 (cp)->c_rsrc_vp : (cp)->c_vp)
172 * Convert between vnode pointers and file forks
174 * Note: no CTOF since that is ambiguous
177 #define FTOC(fp) ((fp)->ff_cp)
179 #define VTOF(vp) ((vp) == VTOC((vp))->c_rsrc_vp ? \
180 VTOC((vp))->c_rsrcfork : \
181 VTOC((vp))->c_datafork)
183 #define FTOV(fp) ((fp) == FTOC(fp)->c_rsrcfork ? \
184 FTOC(fp)->c_rsrc_vp : \
187 #define EVTONLYREFS(vp) ((vp->v_type == VREG) ? VTOF(vp)->ff_evtonly_refs : VTOC(vp)->c_evtonly_refs)
190 * Test for a resource fork
192 #define FORK_IS_RSRC(fp) ((fp) == FTOC(fp)->c_rsrcfork)
194 #define VNODE_IS_RSRC(vp) ((vp) == VTOC((vp))->c_rsrc_vp)
198 * CTIMES should be an inline function...
200 #define C_TIMEMASK (C_ACCESS | C_CHANGE | C_UPDATE)
202 #define C_CHANGEMASK (C_ACCESS | C_CHANGE | C_UPDATE | C_MODIFIED)
204 #define ATIME_ACCURACY 1
205 #define ATIME_ONDISK_ACCURACY 300
207 #define CTIMES(cp, t1, t2) { \
208 if ((cp)->c_flag & C_TIMEMASK) { \
210 * Only do the update if it is more than just \
211 * the C_ACCESS field being updated. \
213 if (((cp)->c_flag & C_CHANGEMASK) != C_ACCESS) { \
214 if ((cp)->c_flag & C_ACCESS) { \
215 (cp)->c_atime = (t1)->tv_sec; \
217 if ((cp)->c_flag & C_UPDATE) { \
218 (cp)->c_mtime = (t2)->tv_sec; \
219 (cp)->c_mtime_nsec = (t2)->tv_usec * 1000; \
221 if ((cp)->c_flag & C_CHANGE) { \
222 (cp)->c_ctime = time.tv_sec; \
224 (cp)->c_flag |= C_MODIFIED; \
225 (cp)->c_flag &= ~C_TIMEMASK; \
230 /* This overlays the fid structure (see mount.h). */
232 u_int16_t hfsfid_len
; /* Length of structure. */
233 u_int16_t hfsfid_pad
; /* Force 32-bit alignment. */
234 /* The following data is filesystem-dependent, up to MAXFIDSZ (16) bytes: */
235 u_int32_t hfsfid_cnid
; /* Catalog node ID. */
236 u_int32_t hfsfid_gen
; /* Generation number (create date). */
241 * HFS cnode hash functions.
243 extern void hfs_chashinit(void);
244 extern void hfs_chashinsert(struct cnode
*cp
);
245 extern void hfs_chashremove(struct cnode
*cp
);
246 extern struct cnode
* hfs_chashget(dev_t dev
, ino_t inum
, int wantrsrc
,
247 struct vnode
**vpp
, struct vnode
**rvpp
);
249 #endif /* __APPLE_API_PRIVATE */
252 #endif /* ! _HFS_CNODE_H_ */