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