1*0a6a1f1dSLionel Sambuc /* $NetBSD: lfs_inode.h,v 1.11 2015/09/01 06:08:37 dholland Exp $ */ 284d9c625SLionel Sambuc /* from NetBSD: ulfs_inode.h,v 1.5 2013/06/06 00:51:50 dholland Exp */ 384d9c625SLionel Sambuc /* from NetBSD: inode.h,v 1.64 2012/11/19 00:36:21 jakllsch Exp */ 484d9c625SLionel Sambuc 584d9c625SLionel Sambuc /* 684d9c625SLionel Sambuc * Copyright (c) 1982, 1989, 1993 784d9c625SLionel Sambuc * The Regents of the University of California. All rights reserved. 884d9c625SLionel Sambuc * (c) UNIX System Laboratories, Inc. 984d9c625SLionel Sambuc * All or some portions of this file are derived from material licensed 1084d9c625SLionel Sambuc * to the University of California by American Telephone and Telegraph 1184d9c625SLionel Sambuc * Co. or Unix System Laboratories, Inc. and are reproduced herein with 1284d9c625SLionel Sambuc * the permission of UNIX System Laboratories, Inc. 1384d9c625SLionel Sambuc * 1484d9c625SLionel Sambuc * Redistribution and use in source and binary forms, with or without 1584d9c625SLionel Sambuc * modification, are permitted provided that the following conditions 1684d9c625SLionel Sambuc * are met: 1784d9c625SLionel Sambuc * 1. Redistributions of source code must retain the above copyright 1884d9c625SLionel Sambuc * notice, this list of conditions and the following disclaimer. 1984d9c625SLionel Sambuc * 2. Redistributions in binary form must reproduce the above copyright 2084d9c625SLionel Sambuc * notice, this list of conditions and the following disclaimer in the 2184d9c625SLionel Sambuc * documentation and/or other materials provided with the distribution. 2284d9c625SLionel Sambuc * 3. Neither the name of the University nor the names of its contributors 2384d9c625SLionel Sambuc * may be used to endorse or promote products derived from this software 2484d9c625SLionel Sambuc * without specific prior written permission. 2584d9c625SLionel Sambuc * 2684d9c625SLionel Sambuc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2784d9c625SLionel Sambuc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2884d9c625SLionel Sambuc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2984d9c625SLionel Sambuc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 3084d9c625SLionel Sambuc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 3184d9c625SLionel Sambuc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3284d9c625SLionel Sambuc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3384d9c625SLionel Sambuc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3484d9c625SLionel Sambuc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3584d9c625SLionel Sambuc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3684d9c625SLionel Sambuc * SUCH DAMAGE. 3784d9c625SLionel Sambuc * 3884d9c625SLionel Sambuc * @(#)inode.h 8.9 (Berkeley) 5/14/95 3984d9c625SLionel Sambuc */ 4084d9c625SLionel Sambuc 4184d9c625SLionel Sambuc #ifndef _UFS_LFS_LFS_INODE_H_ 4284d9c625SLionel Sambuc #define _UFS_LFS_LFS_INODE_H_ 4384d9c625SLionel Sambuc 4484d9c625SLionel Sambuc /* 4584d9c625SLionel Sambuc * Some of the userlevel code (fsck, newfs, lfs_cleanerd) wants to use 4684d9c625SLionel Sambuc * the in-memory inode structure in a faked-up kernel environment. 4784d9c625SLionel Sambuc * This header file provides a reasonably sanitized version of the 4884d9c625SLionel Sambuc * structures and definitions needed for that purpose. 4984d9c625SLionel Sambuc */ 5084d9c625SLionel Sambuc 5184d9c625SLionel Sambuc #include <miscfs/genfs/genfs_node.h> 5284d9c625SLionel Sambuc #include <ufs/lfs/lfs.h> 5384d9c625SLionel Sambuc 5484d9c625SLionel Sambuc /* 5584d9c625SLionel Sambuc * Adjustable filesystem parameters 5684d9c625SLionel Sambuc */ 5784d9c625SLionel Sambuc #define MIN_FREE_SEGS 20 5884d9c625SLionel Sambuc #define MIN_RESV_SEGS 15 5984d9c625SLionel Sambuc 6084d9c625SLionel Sambuc /* 6184d9c625SLionel Sambuc * The following constants define the usage of the quota file array in the 6284d9c625SLionel Sambuc * ulfsmount structure and dquot array in the inode structure. The semantics 6384d9c625SLionel Sambuc * of the elements of these arrays are defined in the routine lfs_getinoquota; 6484d9c625SLionel Sambuc * the remainder of the quota code treats them generically and need not be 6584d9c625SLionel Sambuc * inspected when changing the size of the array. 6684d9c625SLionel Sambuc */ 6784d9c625SLionel Sambuc #define ULFS_MAXQUOTAS 2 6884d9c625SLionel Sambuc #define ULFS_USRQUOTA 0 /* element used for user quotas */ 6984d9c625SLionel Sambuc #define ULFS_GRPQUOTA 1 /* element used for group quotas */ 7084d9c625SLionel Sambuc 7184d9c625SLionel Sambuc /* 7284d9c625SLionel Sambuc * Lookup result state (other than the result inode). This is 7384d9c625SLionel Sambuc * currently stashed in the vnode between VOP_LOOKUP and directory 7484d9c625SLionel Sambuc * operation VOPs, which is gross. 7584d9c625SLionel Sambuc * 7684d9c625SLionel Sambuc * XXX ulr_diroff is a lookup hint from the previos call of VOP_LOOKUP. 7784d9c625SLionel Sambuc * probably it should not be here. 7884d9c625SLionel Sambuc */ 7984d9c625SLionel Sambuc struct ulfs_lookup_results { 8084d9c625SLionel Sambuc int32_t ulr_count; /* Size of free slot in directory. */ 8184d9c625SLionel Sambuc doff_t ulr_endoff; /* End of useful stuff in directory. */ 8284d9c625SLionel Sambuc doff_t ulr_diroff; /* Offset in dir, where we found last entry. */ 8384d9c625SLionel Sambuc doff_t ulr_offset; /* Offset of free space in directory. */ 8484d9c625SLionel Sambuc u_int32_t ulr_reclen; /* Size of found directory entry. */ 8584d9c625SLionel Sambuc }; 8684d9c625SLionel Sambuc 8784d9c625SLionel Sambuc /* notyet XXX */ 8884d9c625SLionel Sambuc #define ULFS_CHECK_CRAPCOUNTER(dp) ((void)(dp)->i_crapcounter) 8984d9c625SLionel Sambuc 9084d9c625SLionel Sambuc /* 9184d9c625SLionel Sambuc * Per-filesystem inode extensions. 9284d9c625SLionel Sambuc */ 9384d9c625SLionel Sambuc struct lfs_inode_ext; 9484d9c625SLionel Sambuc 9584d9c625SLionel Sambuc /* 9684d9c625SLionel Sambuc * The inode is used to describe each active (or recently active) file in the 9784d9c625SLionel Sambuc * ULFS filesystem. It is composed of two types of information. The first part 9884d9c625SLionel Sambuc * is the information that is needed only while the file is active (such as 9984d9c625SLionel Sambuc * the identity of the file and linkage to speed its lookup). The second part 10084d9c625SLionel Sambuc * is the permanent meta-data associated with the file which is read in 10184d9c625SLionel Sambuc * from the permanent dinode from long term storage when the file becomes 10284d9c625SLionel Sambuc * active, and is put back when the file is no longer being used. 10384d9c625SLionel Sambuc */ 10484d9c625SLionel Sambuc struct inode { 10584d9c625SLionel Sambuc struct genfs_node i_gnode; 10684d9c625SLionel Sambuc LIST_ENTRY(inode) i_hash;/* Hash chain. */ 10784d9c625SLionel Sambuc TAILQ_ENTRY(inode) i_nextsnap; /* snapshot file list. */ 10884d9c625SLionel Sambuc struct vnode *i_vnode; /* Vnode associated with this inode. */ 10984d9c625SLionel Sambuc struct ulfsmount *i_ump; /* Mount point associated with this inode. */ 11084d9c625SLionel Sambuc struct vnode *i_devvp; /* Vnode for block I/O. */ 11184d9c625SLionel Sambuc u_int32_t i_flag; /* flags, see below */ 11284d9c625SLionel Sambuc dev_t i_dev; /* Device associated with the inode. */ 11384d9c625SLionel Sambuc ino_t i_number; /* The identity of the inode. */ 11484d9c625SLionel Sambuc 11584d9c625SLionel Sambuc struct lfs *i_lfs; /* The LFS volume we belong to. */ 11684d9c625SLionel Sambuc 11784d9c625SLionel Sambuc void *i_unused1; /* Unused. */ 11884d9c625SLionel Sambuc struct dquot *i_dquot[ULFS_MAXQUOTAS]; /* Dquot structures. */ 11984d9c625SLionel Sambuc u_quad_t i_modrev; /* Revision level for NFS lease. */ 12084d9c625SLionel Sambuc struct lockf *i_lockf;/* Head of byte-level lock list. */ 12184d9c625SLionel Sambuc 12284d9c625SLionel Sambuc /* 12384d9c625SLionel Sambuc * Side effects; used during (and after) directory lookup. 12484d9c625SLionel Sambuc * XXX should not be here. 12584d9c625SLionel Sambuc */ 12684d9c625SLionel Sambuc struct ulfs_lookup_results i_crap; 12784d9c625SLionel Sambuc unsigned i_crapcounter; /* serial number for i_crap */ 12884d9c625SLionel Sambuc 12984d9c625SLionel Sambuc /* 13084d9c625SLionel Sambuc * Inode extensions 13184d9c625SLionel Sambuc */ 13284d9c625SLionel Sambuc union { 13384d9c625SLionel Sambuc /* Other extensions could go here... */ 13484d9c625SLionel Sambuc struct lfs_inode_ext *lfs; 13584d9c625SLionel Sambuc } inode_ext; 13684d9c625SLionel Sambuc /* 13784d9c625SLionel Sambuc * Copies from the on-disk dinode itself. 13884d9c625SLionel Sambuc * 13984d9c625SLionel Sambuc * These fields are currently only used by LFS. 14084d9c625SLionel Sambuc */ 14184d9c625SLionel Sambuc u_int16_t i_mode; /* IFMT, permissions; see below. */ 14284d9c625SLionel Sambuc int16_t i_nlink; /* File link count. */ 14384d9c625SLionel Sambuc u_int64_t i_size; /* File byte count. */ 14484d9c625SLionel Sambuc u_int32_t i_flags; /* Status flags (chflags). */ 14584d9c625SLionel Sambuc int32_t i_gen; /* Generation number. */ 14684d9c625SLionel Sambuc u_int32_t i_uid; /* File owner. */ 14784d9c625SLionel Sambuc u_int32_t i_gid; /* File group. */ 14884d9c625SLionel Sambuc u_int16_t i_omode; /* Old mode, for ulfs_reclaim. */ 14984d9c625SLionel Sambuc 15084d9c625SLionel Sambuc struct dirhash *i_dirhash; /* Hashing for large directories */ 15184d9c625SLionel Sambuc 15284d9c625SLionel Sambuc /* 15384d9c625SLionel Sambuc * The on-disk dinode itself. 15484d9c625SLionel Sambuc */ 155*0a6a1f1dSLionel Sambuc union lfs_dinode *i_din; 15684d9c625SLionel Sambuc }; 15784d9c625SLionel Sambuc 15884d9c625SLionel Sambuc /* These flags are kept in i_flag. */ 15984d9c625SLionel Sambuc #define IN_ACCESS 0x0001 /* Access time update request. */ 16084d9c625SLionel Sambuc #define IN_CHANGE 0x0002 /* Inode change time update request. */ 16184d9c625SLionel Sambuc #define IN_UPDATE 0x0004 /* Inode was written to; update mtime. */ 16284d9c625SLionel Sambuc #define IN_MODIFY 0x2000 /* Modification time update request. */ 16384d9c625SLionel Sambuc #define IN_MODIFIED 0x0008 /* Inode has been modified. */ 16484d9c625SLionel Sambuc #define IN_ACCESSED 0x0010 /* Inode has been accessed. */ 165*0a6a1f1dSLionel Sambuc /* unused 0x0020 */ /* was IN_RENAME */ 16684d9c625SLionel Sambuc #define IN_SHLOCK 0x0040 /* File has shared lock. */ 16784d9c625SLionel Sambuc #define IN_EXLOCK 0x0080 /* File has exclusive lock. */ 16884d9c625SLionel Sambuc #define IN_CLEANING 0x0100 /* LFS: file is being cleaned */ 16984d9c625SLionel Sambuc #define IN_ADIROP 0x0200 /* LFS: dirop in progress */ 170*0a6a1f1dSLionel Sambuc /* unused 0x0400 */ /* was FFS-only IN_SPACECOUNTED */ 17184d9c625SLionel Sambuc #define IN_PAGING 0x1000 /* LFS: file is on paging queue */ 17284d9c625SLionel Sambuc #define IN_CDIROP 0x4000 /* LFS: dirop completed pending i/o */ 17384d9c625SLionel Sambuc 17484d9c625SLionel Sambuc /* 17584d9c625SLionel Sambuc * LFS inode extensions. 17684d9c625SLionel Sambuc */ 17784d9c625SLionel Sambuc struct lfs_inode_ext { 17884d9c625SLionel Sambuc off_t lfs_osize; /* size of file on disk */ 179*0a6a1f1dSLionel Sambuc u_int64_t lfs_effnblocks; /* number of blocks when i/o completes */ 18084d9c625SLionel Sambuc size_t lfs_fragsize[ULFS_NDADDR]; /* size of on-disk direct blocks */ 18184d9c625SLionel Sambuc TAILQ_ENTRY(inode) lfs_dchain; /* Dirop chain. */ 18284d9c625SLionel Sambuc TAILQ_ENTRY(inode) lfs_pchain; /* Paging chain. */ 18384d9c625SLionel Sambuc #define LFSI_NO_GOP_WRITE 0x01 18484d9c625SLionel Sambuc #define LFSI_DELETED 0x02 18584d9c625SLionel Sambuc #define LFSI_WRAPBLOCK 0x04 18684d9c625SLionel Sambuc #define LFSI_WRAPWAIT 0x08 18784d9c625SLionel Sambuc #define LFSI_BMAP 0x10 18884d9c625SLionel Sambuc u_int32_t lfs_iflags; /* Inode flags */ 18984d9c625SLionel Sambuc daddr_t lfs_hiblk; /* Highest lbn held by inode */ 19084d9c625SLionel Sambuc #ifdef _KERNEL 19184d9c625SLionel Sambuc SPLAY_HEAD(lfs_splay, lbnentry) lfs_lbtree; /* Tree of balloc'd lbns */ 19284d9c625SLionel Sambuc int lfs_nbtree; /* Size of tree */ 19384d9c625SLionel Sambuc LIST_HEAD(, segdelta) lfs_segdhd; 19484d9c625SLionel Sambuc #endif 19584d9c625SLionel Sambuc int16_t lfs_odnlink; /* on-disk nlink count for cleaner */ 19684d9c625SLionel Sambuc }; 19784d9c625SLionel Sambuc #define i_lfs_osize inode_ext.lfs->lfs_osize 19884d9c625SLionel Sambuc #define i_lfs_effnblks inode_ext.lfs->lfs_effnblocks 19984d9c625SLionel Sambuc #define i_lfs_fragsize inode_ext.lfs->lfs_fragsize 20084d9c625SLionel Sambuc #define i_lfs_dchain inode_ext.lfs->lfs_dchain 20184d9c625SLionel Sambuc #define i_lfs_pchain inode_ext.lfs->lfs_pchain 20284d9c625SLionel Sambuc #define i_lfs_iflags inode_ext.lfs->lfs_iflags 20384d9c625SLionel Sambuc #define i_lfs_hiblk inode_ext.lfs->lfs_hiblk 20484d9c625SLionel Sambuc #define i_lfs_lbtree inode_ext.lfs->lfs_lbtree 20584d9c625SLionel Sambuc #define i_lfs_nbtree inode_ext.lfs->lfs_nbtree 20684d9c625SLionel Sambuc #define i_lfs_segdhd inode_ext.lfs->lfs_segdhd 20784d9c625SLionel Sambuc #define i_lfs_odnlink inode_ext.lfs->lfs_odnlink 20884d9c625SLionel Sambuc 20984d9c625SLionel Sambuc /* 21084d9c625SLionel Sambuc * "struct buf" associated definitions 21184d9c625SLionel Sambuc */ 21284d9c625SLionel Sambuc 21384d9c625SLionel Sambuc #ifdef _KERNEL 21484d9c625SLionel Sambuc 21584d9c625SLionel Sambuc # define LFS_IS_MALLOC_BUF(bp) ((bp)->b_iodone == lfs_callback) 21684d9c625SLionel Sambuc 21784d9c625SLionel Sambuc # ifdef DEBUG 21884d9c625SLionel Sambuc # define LFS_DEBUG_COUNTLOCKED(m) do { \ 21984d9c625SLionel Sambuc if (lfs_debug_log_subsys[DLOG_LLIST]) { \ 22084d9c625SLionel Sambuc lfs_countlocked(&locked_queue_count, &locked_queue_bytes, (m)); \ 22184d9c625SLionel Sambuc cv_broadcast(&locked_queue_cv); \ 22284d9c625SLionel Sambuc } \ 22384d9c625SLionel Sambuc } while (0) 22484d9c625SLionel Sambuc # else 22584d9c625SLionel Sambuc # define LFS_DEBUG_COUNTLOCKED(m) 22684d9c625SLionel Sambuc # endif 22784d9c625SLionel Sambuc 22884d9c625SLionel Sambuc /* log for debugging writes to the Ifile */ 22984d9c625SLionel Sambuc # ifdef DEBUG 23084d9c625SLionel Sambuc struct lfs_log_entry { 23184d9c625SLionel Sambuc const char *op; 23284d9c625SLionel Sambuc const char *file; 23384d9c625SLionel Sambuc int pid; 23484d9c625SLionel Sambuc int line; 23584d9c625SLionel Sambuc daddr_t block; 23684d9c625SLionel Sambuc unsigned long flags; 23784d9c625SLionel Sambuc }; 23884d9c625SLionel Sambuc extern int lfs_lognum; 23984d9c625SLionel Sambuc extern struct lfs_log_entry lfs_log[LFS_LOGLENGTH]; 24084d9c625SLionel Sambuc # define LFS_BWRITE_LOG(bp) lfs_bwrite_log((bp), __FILE__, __LINE__) 24184d9c625SLionel Sambuc # define LFS_ENTER_LOG(theop, thefile, theline, lbn, theflags, thepid) do {\ 24284d9c625SLionel Sambuc int _s; \ 24384d9c625SLionel Sambuc \ 24484d9c625SLionel Sambuc mutex_enter(&lfs_lock); \ 24584d9c625SLionel Sambuc _s = splbio(); \ 24684d9c625SLionel Sambuc lfs_log[lfs_lognum].op = theop; \ 24784d9c625SLionel Sambuc lfs_log[lfs_lognum].file = thefile; \ 24884d9c625SLionel Sambuc lfs_log[lfs_lognum].line = (theline); \ 24984d9c625SLionel Sambuc lfs_log[lfs_lognum].pid = (thepid); \ 25084d9c625SLionel Sambuc lfs_log[lfs_lognum].block = (lbn); \ 25184d9c625SLionel Sambuc lfs_log[lfs_lognum].flags = (theflags); \ 25284d9c625SLionel Sambuc lfs_lognum = (lfs_lognum + 1) % LFS_LOGLENGTH; \ 25384d9c625SLionel Sambuc splx(_s); \ 25484d9c625SLionel Sambuc mutex_exit(&lfs_lock); \ 25584d9c625SLionel Sambuc } while (0) 25684d9c625SLionel Sambuc 25784d9c625SLionel Sambuc # define LFS_BCLEAN_LOG(fs, bp) do { \ 25884d9c625SLionel Sambuc if ((bp)->b_vp == (fs)->lfs_ivnode) \ 25984d9c625SLionel Sambuc LFS_ENTER_LOG("clear", __FILE__, __LINE__, \ 26084d9c625SLionel Sambuc bp->b_lblkno, bp->b_flags, curproc->p_pid);\ 26184d9c625SLionel Sambuc } while (0) 26284d9c625SLionel Sambuc 26384d9c625SLionel Sambuc /* Must match list in lfs_vfsops.c ! */ 26484d9c625SLionel Sambuc # define DLOG_RF 0 /* roll forward */ 26584d9c625SLionel Sambuc # define DLOG_ALLOC 1 /* inode alloc */ 26684d9c625SLionel Sambuc # define DLOG_AVAIL 2 /* lfs_{,r,f}avail */ 26784d9c625SLionel Sambuc # define DLOG_FLUSH 3 /* flush */ 26884d9c625SLionel Sambuc # define DLOG_LLIST 4 /* locked list accounting */ 26984d9c625SLionel Sambuc # define DLOG_WVNODE 5 /* vflush/writevnodes verbose */ 27084d9c625SLionel Sambuc # define DLOG_VNODE 6 /* vflush/writevnodes */ 27184d9c625SLionel Sambuc # define DLOG_SEG 7 /* segwrite */ 27284d9c625SLionel Sambuc # define DLOG_SU 8 /* seguse accounting */ 27384d9c625SLionel Sambuc # define DLOG_CLEAN 9 /* cleaner routines */ 27484d9c625SLionel Sambuc # define DLOG_MOUNT 10 /* mount/unmount */ 27584d9c625SLionel Sambuc # define DLOG_PAGE 11 /* putpages/gop_write */ 27684d9c625SLionel Sambuc # define DLOG_DIROP 12 /* dirop accounting */ 27784d9c625SLionel Sambuc # define DLOG_MALLOC 13 /* lfs_malloc accounting */ 27884d9c625SLionel Sambuc # define DLOG_MAX 14 /* The terminator */ 27984d9c625SLionel Sambuc # define DLOG(a) lfs_debug_log a 28084d9c625SLionel Sambuc # else /* ! DEBUG */ 28184d9c625SLionel Sambuc # define LFS_BCLEAN_LOG(fs, bp) 28284d9c625SLionel Sambuc # define LFS_BWRITE_LOG(bp) VOP_BWRITE((bp)->b_vp, (bp)) 28384d9c625SLionel Sambuc # define DLOG(a) 28484d9c625SLionel Sambuc # endif /* ! DEBUG */ 28584d9c625SLionel Sambuc #else /* ! _KERNEL */ 28684d9c625SLionel Sambuc # define LFS_BWRITE_LOG(bp) VOP_BWRITE((bp)) 28784d9c625SLionel Sambuc #endif /* _KERNEL */ 28884d9c625SLionel Sambuc 28984d9c625SLionel Sambuc 29084d9c625SLionel Sambuc #endif /* _UFS_LFS_LFS_INODE_H_ */ 291