]> git.saurik.com Git - apple/xnu.git/blob - bsd/ufs/ufs/inode.h
b35cf294fc02f85de818951f7a6dedc657624fea
[apple/xnu.git] / bsd / ufs / ufs / inode.h
1 /*
2 * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
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
13 * file.
14 *
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.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
26 /*
27 * Copyright (c) 1982, 1989, 1993
28 * The Regents of the University of California. All rights reserved.
29 * (c) UNIX System Laboratories, Inc.
30 * All or some portions of this file are derived from material licensed
31 * to the University of California by American Telephone and Telegraph
32 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
33 * the permission of UNIX System Laboratories, Inc.
34 *
35 * Redistribution and use in source and binary forms, with or without
36 * modification, are permitted provided that the following conditions
37 * are met:
38 * 1. Redistributions of source code must retain the above copyright
39 * notice, this list of conditions and the following disclaimer.
40 * 2. Redistributions in binary form must reproduce the above copyright
41 * notice, this list of conditions and the following disclaimer in the
42 * documentation and/or other materials provided with the distribution.
43 * 3. All advertising materials mentioning features or use of this software
44 * must display the following acknowledgement:
45 * This product includes software developed by the University of
46 * California, Berkeley and its contributors.
47 * 4. Neither the name of the University nor the names of its contributors
48 * may be used to endorse or promote products derived from this software
49 * without specific prior written permission.
50 *
51 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
52 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
53 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
54 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
55 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
56 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
57 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
58 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
59 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
60 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
61 * SUCH DAMAGE.
62 *
63 * @(#)inode.h 8.9 (Berkeley) 5/14/95
64 */
65 #ifndef _UFS_INDOE_H_
66 #define _UFS_INDOE_H_
67
68 #include <sys/appleapiopts.h>
69
70 #ifdef __APPLE_API_PRIVATE
71 #include <ufs/ufs/dir.h>
72 #include <ufs/ufs/dinode.h>
73 #include <sys/lock.h>
74 #include <sys/quota.h>
75
76 /*
77 * The inode is used to describe each active (or recently active) file in the
78 * UFS filesystem. It is composed of two types of information. The first part
79 * is the information that is needed only while the file is active (such as
80 * the identity of the file and linkage to speed its lookup). The second part
81 * is * the permanent meta-data associated with the file which is read in
82 * from the permanent dinode from long term storage when the file becomes
83 * active, and is put back when the file is no longer being used.
84 */
85 struct inode {
86 LIST_ENTRY(inode) i_hash;/* Hash chain. */
87 struct vnode *i_vnode;/* Vnode associated with this inode. */
88 struct vnode *i_devvp;/* Vnode for block I/O. */
89 u_int32_t i_flag; /* flags, see below */
90 dev_t i_dev; /* Device associated with the inode. */
91 ino_t i_number; /* The identity of the inode. */
92
93 union { /* Associated filesystem. */
94 struct fs *fs; /* FFS */
95 } inode_u;
96 #define i_fs inode_u.fs
97
98 struct dquot *i_dquot[MAXQUOTAS]; /* Dquot structures. */
99 u_quad_t i_modrev; /* Revision level for NFS lease. */
100 struct lockf *i_lockf;/* Head of byte-level lock list. */
101 struct lock__bsd__ i_lock; /* Inode lock. */
102 /*
103 * Side effects; used during directory lookup.
104 */
105 int32_t i_count; /* Size of free slot in directory. */
106 doff_t i_endoff; /* End of useful stuff in directory. */
107 doff_t i_diroff; /* Offset in dir, where we found last entry. */
108 doff_t i_offset; /* Offset of free space in directory. */
109 ino_t i_ino; /* Inode number of found directory. */
110 u_int32_t i_reclen; /* Size of found directory entry. */
111 /*
112 * The on-disk dinode itself.
113 */
114 struct dinode i_din; /* 128 bytes of the on-disk dinode. */
115 };
116
117 #define i_atime i_din.di_atime
118 #define i_atimensec i_din.di_atimensec
119 #define i_blocks i_din.di_blocks
120 #define i_ctime i_din.di_ctime
121 #define i_ctimensec i_din.di_ctimensec
122 #define i_db i_din.di_db
123 #define i_flags i_din.di_flags
124 #define i_gen i_din.di_gen
125 #define i_gid i_din.di_gid
126 #define i_ib i_din.di_ib
127 #define i_mode i_din.di_mode
128 #define i_mtime i_din.di_mtime
129 #define i_mtimensec i_din.di_mtimensec
130 #define i_nlink i_din.di_nlink
131 #define i_rdev i_din.di_rdev
132 #define i_shortlink i_din.di_shortlink
133 #define i_size i_din.di_size
134 #define i_uid i_din.di_uid
135 #define i_spare i_din.di_spare
136 #define i_oldids i_din.di_u.oldids
137 #define i_inumber i_din.di_u.inumber
138
139 /* These flags are kept in i_flag. */
140 #define IN_ACCESS 0x0001 /* Access time update request. */
141 #define IN_CHANGE 0x0002 /* Inode change time update request. */
142 #define IN_UPDATE 0x0004 /* Modification time update request. */
143 #define IN_MODIFIED 0x0008 /* Inode has been modified. */
144 #define IN_RENAME 0x0010 /* Inode is being renamed. */
145 #define IN_SHLOCK 0x0020 /* File has shared lock. */
146 #define IN_EXLOCK 0x0040 /* File has exclusive lock. */
147 #define IN_TRANSIT 0x0080 /* inode is getting recycled */
148 #define IN_WTRANSIT 0x0100 /* waiting for inode getting recycled */
149 #define IN_ALLOC 0x0200 /* being allocated */
150 #define IN_WALLOC 0x0400 /* waiting for allocation to be done */
151
152 #ifdef KERNEL
153 /*
154 * Structure used to pass around logical block paths generated by
155 * ufs_getlbns and used by truncate and bmap code.
156 */
157 struct indir {
158 ufs_daddr_t in_lbn; /* Logical block number. */
159 int in_off; /* Offset in buffer. */
160 int in_exists; /* Flag if the block exists. */
161 };
162
163 /* Convert between inode pointers and vnode pointers. */
164 #define VTOI(vp) ((struct inode *)(vp)->v_data)
165 #define ITOV(ip) ((ip)->i_vnode)
166
167 #define ITIMES(ip, t1, t2) { \
168 if ((ip)->i_flag & (IN_ACCESS | IN_CHANGE | IN_UPDATE)) { \
169 (ip)->i_flag |= IN_MODIFIED; \
170 if ((ip)->i_flag & IN_ACCESS) \
171 (ip)->i_atime = (t1)->tv_sec; \
172 if ((ip)->i_flag & IN_UPDATE) { \
173 (ip)->i_mtime = (t2)->tv_sec; \
174 (ip)->i_modrev++; \
175 } \
176 if ((ip)->i_flag & IN_CHANGE) \
177 (ip)->i_ctime = time.tv_sec; \
178 (ip)->i_flag &= ~(IN_ACCESS | IN_CHANGE | IN_UPDATE); \
179 } \
180 }
181
182 /* This overlays the fid structure (see mount.h). */
183 struct ufid {
184 u_int16_t ufid_len; /* Length of structure. */
185 u_int16_t ufid_pad; /* Force 32-bit alignment. */
186 ino_t ufid_ino; /* File number (ino). */
187 int32_t ufid_gen; /* Generation number. */
188 };
189 #endif /* KERNEL */
190
191 #endif /* __APPLE_API_PRIVATE */
192 #endif /* ! _UFS_INDOE_H_ */