lfs_inode.h revision 1.7 1 1.7 ryoon /* $NetBSD: lfs_inode.h,v 1.7 2014/05/26 19:12:43 ryoon Exp $ */
2 1.1 dholland /* from NetBSD: ulfs_inode.h,v 1.5 2013/06/06 00:51:50 dholland Exp */
3 1.1 dholland /* from NetBSD: inode.h,v 1.64 2012/11/19 00:36:21 jakllsch Exp */
4 1.1 dholland
5 1.1 dholland /*
6 1.1 dholland * Copyright (c) 1982, 1989, 1993
7 1.1 dholland * The Regents of the University of California. All rights reserved.
8 1.1 dholland * (c) UNIX System Laboratories, Inc.
9 1.1 dholland * All or some portions of this file are derived from material licensed
10 1.1 dholland * to the University of California by American Telephone and Telegraph
11 1.1 dholland * Co. or Unix System Laboratories, Inc. and are reproduced herein with
12 1.1 dholland * the permission of UNIX System Laboratories, Inc.
13 1.1 dholland *
14 1.1 dholland * Redistribution and use in source and binary forms, with or without
15 1.1 dholland * modification, are permitted provided that the following conditions
16 1.1 dholland * are met:
17 1.1 dholland * 1. Redistributions of source code must retain the above copyright
18 1.1 dholland * notice, this list of conditions and the following disclaimer.
19 1.1 dholland * 2. Redistributions in binary form must reproduce the above copyright
20 1.1 dholland * notice, this list of conditions and the following disclaimer in the
21 1.1 dholland * documentation and/or other materials provided with the distribution.
22 1.1 dholland * 3. Neither the name of the University nor the names of its contributors
23 1.1 dholland * may be used to endorse or promote products derived from this software
24 1.1 dholland * without specific prior written permission.
25 1.1 dholland *
26 1.1 dholland * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 1.1 dholland * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 1.1 dholland * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 1.1 dholland * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 1.1 dholland * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 1.1 dholland * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 1.1 dholland * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 1.1 dholland * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 1.1 dholland * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 1.1 dholland * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 1.1 dholland * SUCH DAMAGE.
37 1.1 dholland *
38 1.1 dholland * @(#)inode.h 8.9 (Berkeley) 5/14/95
39 1.1 dholland */
40 1.1 dholland
41 1.1 dholland #ifndef _UFS_LFS_LFS_INODE_H_
42 1.1 dholland #define _UFS_LFS_LFS_INODE_H_
43 1.1 dholland
44 1.1 dholland /*
45 1.1 dholland * Some of the userlevel code (fsck, newfs, lfs_cleanerd) wants to use
46 1.1 dholland * the in-memory inode structure in a faked-up kernel environment.
47 1.1 dholland * This header file provides a reasonably sanitized version of the
48 1.1 dholland * structures and definitions needed for that purpose.
49 1.1 dholland */
50 1.1 dholland
51 1.1 dholland #include <miscfs/genfs/genfs_node.h>
52 1.1 dholland #include <ufs/lfs/lfs.h>
53 1.1 dholland
54 1.1 dholland /*
55 1.5 dholland * Adjustable filesystem parameters
56 1.5 dholland */
57 1.5 dholland #define MIN_FREE_SEGS 20
58 1.5 dholland #define MIN_RESV_SEGS 15
59 1.5 dholland
60 1.5 dholland /*
61 1.1 dholland * The following constants define the usage of the quota file array in the
62 1.1 dholland * ulfsmount structure and dquot array in the inode structure. The semantics
63 1.1 dholland * of the elements of these arrays are defined in the routine lfs_getinoquota;
64 1.1 dholland * the remainder of the quota code treats them generically and need not be
65 1.1 dholland * inspected when changing the size of the array.
66 1.1 dholland */
67 1.1 dholland #define ULFS_MAXQUOTAS 2
68 1.1 dholland #define ULFS_USRQUOTA 0 /* element used for user quotas */
69 1.1 dholland #define ULFS_GRPQUOTA 1 /* element used for group quotas */
70 1.1 dholland
71 1.1 dholland /*
72 1.1 dholland * Lookup result state (other than the result inode). This is
73 1.1 dholland * currently stashed in the vnode between VOP_LOOKUP and directory
74 1.1 dholland * operation VOPs, which is gross.
75 1.1 dholland *
76 1.1 dholland * XXX ulr_diroff is a lookup hint from the previos call of VOP_LOOKUP.
77 1.1 dholland * probably it should not be here.
78 1.1 dholland */
79 1.1 dholland struct ulfs_lookup_results {
80 1.1 dholland int32_t ulr_count; /* Size of free slot in directory. */
81 1.1 dholland doff_t ulr_endoff; /* End of useful stuff in directory. */
82 1.1 dholland doff_t ulr_diroff; /* Offset in dir, where we found last entry. */
83 1.1 dholland doff_t ulr_offset; /* Offset of free space in directory. */
84 1.1 dholland u_int32_t ulr_reclen; /* Size of found directory entry. */
85 1.1 dholland };
86 1.1 dholland
87 1.1 dholland /* notyet XXX */
88 1.1 dholland #define ULFS_CHECK_CRAPCOUNTER(dp) ((void)(dp)->i_crapcounter)
89 1.1 dholland
90 1.1 dholland /*
91 1.1 dholland * Per-filesystem inode extensions.
92 1.1 dholland */
93 1.1 dholland struct lfs_inode_ext;
94 1.1 dholland
95 1.1 dholland /*
96 1.1 dholland * The inode is used to describe each active (or recently active) file in the
97 1.1 dholland * ULFS filesystem. It is composed of two types of information. The first part
98 1.1 dholland * is the information that is needed only while the file is active (such as
99 1.1 dholland * the identity of the file and linkage to speed its lookup). The second part
100 1.1 dholland * is the permanent meta-data associated with the file which is read in
101 1.1 dholland * from the permanent dinode from long term storage when the file becomes
102 1.1 dholland * active, and is put back when the file is no longer being used.
103 1.1 dholland */
104 1.1 dholland struct inode {
105 1.1 dholland struct genfs_node i_gnode;
106 1.1 dholland LIST_ENTRY(inode) i_hash;/* Hash chain. */
107 1.1 dholland TAILQ_ENTRY(inode) i_nextsnap; /* snapshot file list. */
108 1.1 dholland struct vnode *i_vnode; /* Vnode associated with this inode. */
109 1.1 dholland struct ulfsmount *i_ump; /* Mount point associated with this inode. */
110 1.1 dholland struct vnode *i_devvp; /* Vnode for block I/O. */
111 1.1 dholland u_int32_t i_flag; /* flags, see below */
112 1.1 dholland dev_t i_dev; /* Device associated with the inode. */
113 1.1 dholland ino_t i_number; /* The identity of the inode. */
114 1.1 dholland
115 1.3 dholland struct lfs *i_lfs; /* The LFS volume we belong to. */
116 1.1 dholland
117 1.1 dholland void *i_unused1; /* Unused. */
118 1.1 dholland struct dquot *i_dquot[ULFS_MAXQUOTAS]; /* Dquot structures. */
119 1.1 dholland u_quad_t i_modrev; /* Revision level for NFS lease. */
120 1.1 dholland struct lockf *i_lockf;/* Head of byte-level lock list. */
121 1.1 dholland
122 1.1 dholland /*
123 1.1 dholland * Side effects; used during (and after) directory lookup.
124 1.1 dholland * XXX should not be here.
125 1.1 dholland */
126 1.1 dholland struct ulfs_lookup_results i_crap;
127 1.1 dholland unsigned i_crapcounter; /* serial number for i_crap */
128 1.1 dholland
129 1.1 dholland /*
130 1.1 dholland * Inode extensions
131 1.1 dholland */
132 1.1 dholland union {
133 1.1 dholland /* Other extensions could go here... */
134 1.1 dholland struct lfs_inode_ext *lfs;
135 1.1 dholland } inode_ext;
136 1.1 dholland /*
137 1.1 dholland * Copies from the on-disk dinode itself.
138 1.1 dholland *
139 1.1 dholland * These fields are currently only used by LFS.
140 1.1 dholland */
141 1.1 dholland u_int16_t i_mode; /* IFMT, permissions; see below. */
142 1.1 dholland int16_t i_nlink; /* File link count. */
143 1.1 dholland u_int64_t i_size; /* File byte count. */
144 1.1 dholland u_int32_t i_flags; /* Status flags (chflags). */
145 1.1 dholland int32_t i_gen; /* Generation number. */
146 1.1 dholland u_int32_t i_uid; /* File owner. */
147 1.1 dholland u_int32_t i_gid; /* File group. */
148 1.1 dholland u_int16_t i_omode; /* Old mode, for ulfs_reclaim. */
149 1.1 dholland
150 1.1 dholland struct dirhash *i_dirhash; /* Hashing for large directories */
151 1.1 dholland
152 1.1 dholland /*
153 1.1 dholland * The on-disk dinode itself.
154 1.1 dholland */
155 1.1 dholland union {
156 1.1 dholland struct ulfs1_dinode *ffs1_din; /* 128 bytes of the on-disk dinode. */
157 1.1 dholland struct ulfs2_dinode *ffs2_din;
158 1.1 dholland } i_din;
159 1.1 dholland };
160 1.1 dholland
161 1.1 dholland #define i_ffs1_atime i_din.ffs1_din->di_atime
162 1.1 dholland #define i_ffs1_atimensec i_din.ffs1_din->di_atimensec
163 1.1 dholland #define i_ffs1_blocks i_din.ffs1_din->di_blocks
164 1.1 dholland #define i_ffs1_ctime i_din.ffs1_din->di_ctime
165 1.1 dholland #define i_ffs1_ctimensec i_din.ffs1_din->di_ctimensec
166 1.1 dholland #define i_ffs1_db i_din.ffs1_din->di_db
167 1.1 dholland #define i_ffs1_flags i_din.ffs1_din->di_flags
168 1.1 dholland #define i_ffs1_gen i_din.ffs1_din->di_gen
169 1.1 dholland #define i_ffs1_gid i_din.ffs1_din->di_gid
170 1.1 dholland #define i_ffs1_ib i_din.ffs1_din->di_ib
171 1.1 dholland #define i_ffs1_mode i_din.ffs1_din->di_mode
172 1.1 dholland #define i_ffs1_mtime i_din.ffs1_din->di_mtime
173 1.1 dholland #define i_ffs1_mtimensec i_din.ffs1_din->di_mtimensec
174 1.1 dholland #define i_ffs1_nlink i_din.ffs1_din->di_nlink
175 1.1 dholland #define i_ffs1_rdev i_din.ffs1_din->di_rdev
176 1.1 dholland #define i_ffs1_size i_din.ffs1_din->di_size
177 1.1 dholland #define i_ffs1_uid i_din.ffs1_din->di_uid
178 1.1 dholland
179 1.1 dholland #define i_ffs2_atime i_din.ffs2_din->di_atime
180 1.1 dholland #define i_ffs2_atimensec i_din.ffs2_din->di_atimensec
181 1.1 dholland #define i_ffs2_birthtime i_din.ffs2_din->di_birthtime
182 1.1 dholland #define i_ffs2_birthnsec i_din.ffs2_din->di_birthnsec
183 1.1 dholland #define i_ffs2_blocks i_din.ffs2_din->di_blocks
184 1.1 dholland #define i_ffs2_blksize i_din.ffs2_din->di_blksize
185 1.1 dholland #define i_ffs2_ctime i_din.ffs2_din->di_ctime
186 1.1 dholland #define i_ffs2_ctimensec i_din.ffs2_din->di_ctimensec
187 1.1 dholland #define i_ffs2_db i_din.ffs2_din->di_db
188 1.1 dholland #define i_ffs2_flags i_din.ffs2_din->di_flags
189 1.1 dholland #define i_ffs2_gen i_din.ffs2_din->di_gen
190 1.1 dholland #define i_ffs2_gid i_din.ffs2_din->di_gid
191 1.1 dholland #define i_ffs2_ib i_din.ffs2_din->di_ib
192 1.1 dholland #define i_ffs2_mode i_din.ffs2_din->di_mode
193 1.1 dholland #define i_ffs2_mtime i_din.ffs2_din->di_mtime
194 1.1 dholland #define i_ffs2_mtimensec i_din.ffs2_din->di_mtimensec
195 1.1 dholland #define i_ffs2_nlink i_din.ffs2_din->di_nlink
196 1.1 dholland #define i_ffs2_rdev i_din.ffs2_din->di_rdev
197 1.1 dholland #define i_ffs2_size i_din.ffs2_din->di_size
198 1.1 dholland #define i_ffs2_uid i_din.ffs2_din->di_uid
199 1.1 dholland #define i_ffs2_kernflags i_din.ffs2_din->di_kernflags
200 1.1 dholland #define i_ffs2_extsize i_din.ffs2_din->di_extsize
201 1.1 dholland #define i_ffs2_extb i_din.ffs2_din->di_extb
202 1.1 dholland
203 1.1 dholland /* These flags are kept in i_flag. */
204 1.1 dholland #define IN_ACCESS 0x0001 /* Access time update request. */
205 1.1 dholland #define IN_CHANGE 0x0002 /* Inode change time update request. */
206 1.1 dholland #define IN_UPDATE 0x0004 /* Inode was written to; update mtime. */
207 1.1 dholland #define IN_MODIFY 0x2000 /* Modification time update request. */
208 1.1 dholland #define IN_MODIFIED 0x0008 /* Inode has been modified. */
209 1.1 dholland #define IN_ACCESSED 0x0010 /* Inode has been accessed. */
210 1.6 dholland /* unused 0x0020 */ /* was IN_RENAME */
211 1.1 dholland #define IN_SHLOCK 0x0040 /* File has shared lock. */
212 1.1 dholland #define IN_EXLOCK 0x0080 /* File has exclusive lock. */
213 1.1 dholland #define IN_CLEANING 0x0100 /* LFS: file is being cleaned */
214 1.1 dholland #define IN_ADIROP 0x0200 /* LFS: dirop in progress */
215 1.7 ryoon /* unused 0x0400 */ /* was FFS-only IN_SPACECOUNTED */
216 1.1 dholland #define IN_PAGING 0x1000 /* LFS: file is on paging queue */
217 1.1 dholland #define IN_CDIROP 0x4000 /* LFS: dirop completed pending i/o */
218 1.1 dholland
219 1.4 dholland /*
220 1.4 dholland * LFS inode extensions.
221 1.4 dholland */
222 1.4 dholland struct lfs_inode_ext {
223 1.4 dholland off_t lfs_osize; /* size of file on disk */
224 1.4 dholland u_int32_t lfs_effnblocks; /* number of blocks when i/o completes */
225 1.4 dholland size_t lfs_fragsize[ULFS_NDADDR]; /* size of on-disk direct blocks */
226 1.4 dholland TAILQ_ENTRY(inode) lfs_dchain; /* Dirop chain. */
227 1.4 dholland TAILQ_ENTRY(inode) lfs_pchain; /* Paging chain. */
228 1.4 dholland #define LFSI_NO_GOP_WRITE 0x01
229 1.4 dholland #define LFSI_DELETED 0x02
230 1.4 dholland #define LFSI_WRAPBLOCK 0x04
231 1.4 dholland #define LFSI_WRAPWAIT 0x08
232 1.4 dholland #define LFSI_BMAP 0x10
233 1.4 dholland u_int32_t lfs_iflags; /* Inode flags */
234 1.4 dholland daddr_t lfs_hiblk; /* Highest lbn held by inode */
235 1.4 dholland #ifdef _KERNEL
236 1.4 dholland SPLAY_HEAD(lfs_splay, lbnentry) lfs_lbtree; /* Tree of balloc'd lbns */
237 1.4 dholland int lfs_nbtree; /* Size of tree */
238 1.4 dholland LIST_HEAD(, segdelta) lfs_segdhd;
239 1.4 dholland #endif
240 1.4 dholland int16_t lfs_odnlink; /* on-disk nlink count for cleaner */
241 1.4 dholland };
242 1.4 dholland #define i_lfs_osize inode_ext.lfs->lfs_osize
243 1.4 dholland #define i_lfs_effnblks inode_ext.lfs->lfs_effnblocks
244 1.4 dholland #define i_lfs_fragsize inode_ext.lfs->lfs_fragsize
245 1.4 dholland #define i_lfs_dchain inode_ext.lfs->lfs_dchain
246 1.4 dholland #define i_lfs_pchain inode_ext.lfs->lfs_pchain
247 1.4 dholland #define i_lfs_iflags inode_ext.lfs->lfs_iflags
248 1.4 dholland #define i_lfs_hiblk inode_ext.lfs->lfs_hiblk
249 1.4 dholland #define i_lfs_lbtree inode_ext.lfs->lfs_lbtree
250 1.4 dholland #define i_lfs_nbtree inode_ext.lfs->lfs_nbtree
251 1.4 dholland #define i_lfs_segdhd inode_ext.lfs->lfs_segdhd
252 1.4 dholland #define i_lfs_odnlink inode_ext.lfs->lfs_odnlink
253 1.4 dholland
254 1.5 dholland /*
255 1.5 dholland * "struct buf" associated definitions
256 1.5 dholland */
257 1.5 dholland
258 1.5 dholland #ifdef _KERNEL
259 1.5 dholland
260 1.5 dholland # define LFS_IS_MALLOC_BUF(bp) ((bp)->b_iodone == lfs_callback)
261 1.5 dholland
262 1.5 dholland # ifdef DEBUG
263 1.5 dholland # define LFS_DEBUG_COUNTLOCKED(m) do { \
264 1.5 dholland if (lfs_debug_log_subsys[DLOG_LLIST]) { \
265 1.5 dholland lfs_countlocked(&locked_queue_count, &locked_queue_bytes, (m)); \
266 1.5 dholland cv_broadcast(&locked_queue_cv); \
267 1.5 dholland } \
268 1.5 dholland } while (0)
269 1.5 dholland # else
270 1.5 dholland # define LFS_DEBUG_COUNTLOCKED(m)
271 1.5 dholland # endif
272 1.5 dholland
273 1.5 dholland /* log for debugging writes to the Ifile */
274 1.5 dholland # ifdef DEBUG
275 1.5 dholland struct lfs_log_entry {
276 1.5 dholland const char *op;
277 1.5 dholland const char *file;
278 1.5 dholland int pid;
279 1.5 dholland int line;
280 1.5 dholland daddr_t block;
281 1.5 dholland unsigned long flags;
282 1.5 dholland };
283 1.5 dholland extern int lfs_lognum;
284 1.5 dholland extern struct lfs_log_entry lfs_log[LFS_LOGLENGTH];
285 1.5 dholland # define LFS_BWRITE_LOG(bp) lfs_bwrite_log((bp), __FILE__, __LINE__)
286 1.5 dholland # define LFS_ENTER_LOG(theop, thefile, theline, lbn, theflags, thepid) do {\
287 1.5 dholland int _s; \
288 1.5 dholland \
289 1.5 dholland mutex_enter(&lfs_lock); \
290 1.5 dholland _s = splbio(); \
291 1.5 dholland lfs_log[lfs_lognum].op = theop; \
292 1.5 dholland lfs_log[lfs_lognum].file = thefile; \
293 1.5 dholland lfs_log[lfs_lognum].line = (theline); \
294 1.5 dholland lfs_log[lfs_lognum].pid = (thepid); \
295 1.5 dholland lfs_log[lfs_lognum].block = (lbn); \
296 1.5 dholland lfs_log[lfs_lognum].flags = (theflags); \
297 1.5 dholland lfs_lognum = (lfs_lognum + 1) % LFS_LOGLENGTH; \
298 1.5 dholland splx(_s); \
299 1.5 dholland mutex_exit(&lfs_lock); \
300 1.5 dholland } while (0)
301 1.5 dholland
302 1.5 dholland # define LFS_BCLEAN_LOG(fs, bp) do { \
303 1.5 dholland if ((bp)->b_vp == (fs)->lfs_ivnode) \
304 1.5 dholland LFS_ENTER_LOG("clear", __FILE__, __LINE__, \
305 1.5 dholland bp->b_lblkno, bp->b_flags, curproc->p_pid);\
306 1.5 dholland } while (0)
307 1.5 dholland
308 1.5 dholland /* Must match list in lfs_vfsops.c ! */
309 1.5 dholland # define DLOG_RF 0 /* roll forward */
310 1.5 dholland # define DLOG_ALLOC 1 /* inode alloc */
311 1.5 dholland # define DLOG_AVAIL 2 /* lfs_{,r,f}avail */
312 1.5 dholland # define DLOG_FLUSH 3 /* flush */
313 1.5 dholland # define DLOG_LLIST 4 /* locked list accounting */
314 1.5 dholland # define DLOG_WVNODE 5 /* vflush/writevnodes verbose */
315 1.5 dholland # define DLOG_VNODE 6 /* vflush/writevnodes */
316 1.5 dholland # define DLOG_SEG 7 /* segwrite */
317 1.5 dholland # define DLOG_SU 8 /* seguse accounting */
318 1.5 dholland # define DLOG_CLEAN 9 /* cleaner routines */
319 1.5 dholland # define DLOG_MOUNT 10 /* mount/unmount */
320 1.5 dholland # define DLOG_PAGE 11 /* putpages/gop_write */
321 1.5 dholland # define DLOG_DIROP 12 /* dirop accounting */
322 1.5 dholland # define DLOG_MALLOC 13 /* lfs_malloc accounting */
323 1.5 dholland # define DLOG_MAX 14 /* The terminator */
324 1.5 dholland # define DLOG(a) lfs_debug_log a
325 1.5 dholland # else /* ! DEBUG */
326 1.5 dholland # define LFS_BCLEAN_LOG(fs, bp)
327 1.5 dholland # define LFS_BWRITE_LOG(bp) VOP_BWRITE((bp)->b_vp, (bp))
328 1.5 dholland # define DLOG(a)
329 1.5 dholland # endif /* ! DEBUG */
330 1.5 dholland #else /* ! _KERNEL */
331 1.5 dholland # define LFS_BWRITE_LOG(bp) VOP_BWRITE((bp))
332 1.5 dholland #endif /* _KERNEL */
333 1.5 dholland
334 1.4 dholland
335 1.1 dholland #endif /* _UFS_LFS_LFS_INODE_H_ */
336