]> git.saurik.com Git - apple/xnu.git/blame - bsd/hfs/hfs_cnode.h
xnu-792.13.8.tar.gz
[apple/xnu.git] / bsd / hfs / hfs_cnode.h
CommitLineData
9bccf70c 1/*
91447636 2 * Copyright (c) 2002-2005 Apple Computer, Inc. All rights reserved.
9bccf70c 3 *
8ad349bb 4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
9bccf70c 5 *
8ad349bb
A
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
9bccf70c
A
29 */
30#ifndef _HFS_CNODE_H_
31#define _HFS_CNODE_H_
32
33#include <sys/appleapiopts.h>
34
35#ifdef KERNEL
36#ifdef __APPLE_API_PRIVATE
37#include <sys/types.h>
9bccf70c
A
38#include <sys/queue.h>
39#include <sys/stat.h>
40#include <sys/vnode.h>
41#include <sys/quota.h>
42
91447636
A
43#include <kern/locks.h>
44
9bccf70c
A
45#include <hfs/hfs_catalog.h>
46#include <hfs/rangelist.h>
47
48
49/*
50 * The filefork is used to represent an HFS file fork (data or resource).
51 * Reading or writing any of these fields requires holding cnode lock.
52 */
53struct filefork {
91447636
A
54 struct cnode *ff_cp; /* cnode associated with this fork */
55 struct rl_head ff_invalidranges; /* Areas of disk that should read back as zeroes */
9bccf70c 56 union {
91447636
A
57 void *ffu_sysfileinfo; /* additional info for system files */
58 char *ffu_symlinkptr; /* symbolic link pathname */
59 } ff_union;
60 struct cat_fork ff_data; /* fork data (size, extents) */
9bccf70c 61};
55e303ae 62typedef struct filefork filefork_t;
9bccf70c
A
63
64/* Aliases for common fields */
91447636
A
65#define ff_size ff_data.cf_size
66#define ff_clumpsize ff_data.cf_clump
67#define ff_bytesread ff_data.cf_bytesread
68#define ff_blocks ff_data.cf_blocks
69#define ff_extents ff_data.cf_extents
55e303ae
A
70#define ff_unallocblocks ff_data.cf_vblocks
71
91447636
A
72#define ff_symlinkptr ff_union.ffu_symlinkptr
73#define ff_sysfileinfo ff_union.ffu_sysfileinfo
9bccf70c
A
74
75
76/* The btree code still needs these... */
91447636
A
77#define fcbEOF ff_size
78#define fcbExtents ff_extents
79#define fcbBTCBPtr ff_sysfileinfo
9bccf70c 80
91447636
A
81typedef u_int8_t atomicflag_t;
82
9bccf70c
A
83/*
84 * The cnode is used to represent each active (or recently active)
85 * file or directory in the HFS filesystem.
86 *
87 * Reading or writing any of these fields requires holding c_lock.
88 */
89struct cnode {
91447636
A
90 lck_rw_t c_rwlock; /* cnode's lock */
91 void * c_lockowner; /* cnode's lock owner (exclusive case only) */
92 lck_rw_t c_truncatelock; /* protects file from truncation during read/write */
9bccf70c
A
93 LIST_ENTRY(cnode) c_hash; /* cnode's hash chain */
94 u_int32_t c_flag; /* cnode's runtime flags */
91447636 95 u_int32_t c_hflag; /* cnode's flags for maintaining hash - protected by global hash lock */
9bccf70c
A
96 struct vnode *c_vp; /* vnode for data fork or dir */
97 struct vnode *c_rsrc_vp; /* vnode for resource fork */
98 struct vnode *c_devvp; /* vnode for block I/O */
99 dev_t c_dev; /* cnode's device */
100 struct dquot *c_dquot[MAXQUOTAS]; /* cnode's quota info */
55e303ae 101 struct klist c_knotes; /* knotes attached to this vnode */
91447636 102 u_long c_childhint; /* catalog hint for children */
9bccf70c
A
103 struct cat_desc c_desc; /* cnode's descriptor */
104 struct cat_attr c_attr; /* cnode's attributes */
b36670ce 105 TAILQ_HEAD(hfs_hinthead, directoryhint) c_hintlist; /* directory hint list */
91447636
A
106 int16_t c_dirhinttag; /* directory hint tag */
107 union {
108 int16_t cu_dirhintcnt; /* directory hint count */
109 int16_t cu_syslockcount; /* system file use only */
110 } c_union;
9bccf70c
A
111 struct filefork *c_datafork; /* cnode's data fork */
112 struct filefork *c_rsrcfork; /* cnode's rsrc fork */
91447636
A
113 atomicflag_t c_touch_acctime;
114 atomicflag_t c_touch_chgtime;
115 atomicflag_t c_touch_modtime;
9bccf70c 116};
55e303ae 117typedef struct cnode cnode_t;
9bccf70c
A
118
119/* Aliases for common cnode fields */
120#define c_cnid c_desc.cd_cnid
121#define c_hint c_desc.cd_hint
122#define c_parentcnid c_desc.cd_parentcnid
123#define c_encoding c_desc.cd_encoding
124
125#define c_fileid c_attr.ca_fileid
126#define c_mode c_attr.ca_mode
127#define c_nlink c_attr.ca_nlink
128#define c_uid c_attr.ca_uid
129#define c_gid c_attr.ca_gid
130#define c_rdev c_attr.ca_rdev
131#define c_atime c_attr.ca_atime
132#define c_mtime c_attr.ca_mtime
9bccf70c
A
133#define c_ctime c_attr.ca_ctime
134#define c_itime c_attr.ca_itime
135#define c_btime c_attr.ca_btime
136#define c_flags c_attr.ca_flags
137#define c_finderinfo c_attr.ca_finderinfo
138#define c_blocks c_attr.ca_blocks
91447636 139#define c_attrblks c_attr.ca_attrblks
9bccf70c
A
140#define c_entries c_attr.ca_entries
141#define c_zftimeout c_childhint
142
91447636
A
143#define c_dirhintcnt c_union.cu_dirhintcnt
144#define c_syslockcount c_union.cu_syslockcount
9bccf70c 145
55e303ae 146
91447636
A
147/* hash maintenance flags kept in c_hflag and protected by hfs_chash_mutex */
148#define H_ALLOC 0x00001 /* CNode is being allocated */
149#define H_ATTACH 0x00002 /* CNode is being attached to by another vnode */
150#define H_TRANSIT 0x00004 /* CNode is getting recycled */
151#define H_WAITING 0x00008 /* CNode is being waited for */
152
9bccf70c 153
91447636
A
154/* Runtime cnode flags (kept in c_flag) */
155#define C_NEED_RVNODE_PUT 0x00001 /* Need to do a vnode_put on c_rsrc_vp after the unlock */
156#define C_NEED_DVNODE_PUT 0x00002 /* Need to do a vnode_put on c_vp after the unlock */
157#define C_ZFWANTSYNC 0x00004 /* fsync requested and file has holes */
158#define C_FROMSYNC 0x00008 /* fsync was called from sync */
9bccf70c 159
91447636
A
160#define C_MODIFIED 0x00010 /* CNode has been modified */
161#define C_NOEXISTS 0x00020 /* CNode has been deleted, catalog entry is gone */
162#define C_DELETED 0x00040 /* CNode has been marked to be deleted */
163#define C_HARDLINK 0x00080 /* CNode is a hard link */
9bccf70c 164
91447636
A
165#define C_FORCEUPDATE 0x00100 /* force the catalog entry update */
166#define C_HASXATTRS 0x00200 /* cnode has extended attributes */
9bccf70c 167
5d5c5d0d
A
168#define C_NEED_DATA_SETSIZE 0x01000 /* Do a ubc_setsize(0) on c_rsrc_vp after the unlock */
169#define C_NEED_RSRC_SETSIZE 0x02000 /* Do a ubc_setsize(0) on c_vp after the unlock */
170
9bccf70c
A
171
172#define ZFTIMELIMIT (5 * 60)
173
174/*
175 * Convert between cnode pointers and vnode pointers
176 */
91447636 177#define VTOC(vp) ((struct cnode *)vnode_fsnode((vp)))
9bccf70c
A
178
179#define CTOV(cp,rsrc) (((rsrc) && S_ISREG((cp)->c_mode)) ? \
180 (cp)->c_rsrc_vp : (cp)->c_vp)
181
182/*
183 * Convert between vnode pointers and file forks
184 *
185 * Note: no CTOF since that is ambiguous
186 */
187
188#define FTOC(fp) ((fp)->ff_cp)
189
190#define VTOF(vp) ((vp) == VTOC((vp))->c_rsrc_vp ? \
191 VTOC((vp))->c_rsrcfork : \
192 VTOC((vp))->c_datafork)
193
194#define FTOV(fp) ((fp) == FTOC(fp)->c_rsrcfork ? \
195 FTOC(fp)->c_rsrc_vp : \
196 FTOC(fp)->c_vp)
197
55e303ae 198
9bccf70c
A
199/*
200 * Test for a resource fork
201 */
202#define FORK_IS_RSRC(fp) ((fp) == FTOC(fp)->c_rsrcfork)
203
204#define VNODE_IS_RSRC(vp) ((vp) == VTOC((vp))->c_rsrc_vp)
205
206
55e303ae 207#define ATIME_ONDISK_ACCURACY 300
9bccf70c 208
91447636
A
209
210/* This overlays the FileID portion of NFS file handles. */
9bccf70c 211struct hfsfid {
9bccf70c
A
212 u_int32_t hfsfid_cnid; /* Catalog node ID. */
213 u_int32_t hfsfid_gen; /* Generation number (create date). */
214};
215
216
91447636
A
217extern void hfs_touchtimes(struct hfsmount *, struct cnode *);
218
9bccf70c
A
219/*
220 * HFS cnode hash functions.
221 */
222extern void hfs_chashinit(void);
223extern void hfs_chashinsert(struct cnode *cp);
91447636
A
224extern int hfs_chashremove(struct cnode *cp);
225extern void hfs_chash_abort(struct cnode *cp);
226extern void hfs_chash_rehash(struct cnode *cp1, struct cnode *cp2);
227extern void hfs_chashwakeup(struct cnode *cp, int flags);
228extern void hfs_chash_mark_in_transit(struct cnode *cp);
229
230extern struct vnode * hfs_chash_getvnode(dev_t dev, ino_t inum, int wantrsrc, int skiplock);
231extern struct cnode * hfs_chash_getcnode(dev_t dev, ino_t inum, struct vnode **vpp, int wantrsrc, int skiplock);
232extern int hfs_chash_snoop(dev_t, ino_t, int (*)(const struct cat_desc *,
233 const struct cat_attr *, void *), void *);
234
235/*
236 * HFS directory hint functions.
237 */
238extern directoryhint_t * hfs_getdirhint(struct cnode *, int);
239extern void hfs_reldirhint(struct cnode *, directoryhint_t *);
240extern void hfs_reldirhints(struct cnode *, int);
241
242/*
243 * HFS cnode lock functions.
244 *
245 * HFS Locking Order:
246 *
247 * 1. cnode truncate lock (if needed)
248 * 2. cnode lock (in parent-child order if related, otherwise by address order)
249 * 3. journal (if needed)
250 * 4. system files (as needed)
251 * A. Catalog B-tree file
252 * B. Attributes B-tree file
253 * C. Allocation Bitmap file (always exclusive, supports recursion)
254 * D. Overflow Extents B-tree file (always exclusive, supports recursion)
255 * 5. hfs mount point (always last)
256 *
257 */
258enum hfslocktype {HFS_SHARED_LOCK = 1, HFS_EXCLUSIVE_LOCK = 2, HFS_FORCE_LOCK = 3};
259#define HFS_SHARED_OWNER (void *)0xffffffff
260
261extern int hfs_lock(struct cnode *, enum hfslocktype);
262extern int hfs_lockpair(struct cnode *, struct cnode *, enum hfslocktype);
263extern int hfs_lockfour(struct cnode *, struct cnode *, struct cnode *, struct cnode *,
264 enum hfslocktype);
265
266extern void hfs_unlock(struct cnode *);
267extern void hfs_unlockpair(struct cnode *, struct cnode *);
268extern void hfs_unlockfour(struct cnode *, struct cnode *, struct cnode *, struct cnode *);
269
270extern void hfs_lock_truncate(struct cnode *, int);
271extern void hfs_unlock_truncate(struct cnode *);
9bccf70c
A
272
273#endif /* __APPLE_API_PRIVATE */
274#endif /* KERNEL */
275
276#endif /* ! _HFS_CNODE_H_ */