Home | History | Annotate | Line # | Download | only in lfs
ulfs_inode.h revision 1.9
      1  1.9  christos /*	$NetBSD: ulfs_inode.h,v 1.9 2013/06/18 18:18:58 christos Exp $	*/
      2  1.1  dholland /*  from NetBSD: inode.h,v 1.64 2012/11/19 00:36:21 jakllsch Exp  */
      3  1.1  dholland 
      4  1.1  dholland /*
      5  1.1  dholland  * Copyright (c) 1982, 1989, 1993
      6  1.1  dholland  *	The Regents of the University of California.  All rights reserved.
      7  1.1  dholland  * (c) UNIX System Laboratories, Inc.
      8  1.1  dholland  * All or some portions of this file are derived from material licensed
      9  1.1  dholland  * to the University of California by American Telephone and Telegraph
     10  1.1  dholland  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
     11  1.1  dholland  * the permission of UNIX System Laboratories, Inc.
     12  1.1  dholland  *
     13  1.1  dholland  * Redistribution and use in source and binary forms, with or without
     14  1.1  dholland  * modification, are permitted provided that the following conditions
     15  1.1  dholland  * are met:
     16  1.1  dholland  * 1. Redistributions of source code must retain the above copyright
     17  1.1  dholland  *    notice, this list of conditions and the following disclaimer.
     18  1.1  dholland  * 2. Redistributions in binary form must reproduce the above copyright
     19  1.1  dholland  *    notice, this list of conditions and the following disclaimer in the
     20  1.1  dholland  *    documentation and/or other materials provided with the distribution.
     21  1.1  dholland  * 3. Neither the name of the University nor the names of its contributors
     22  1.1  dholland  *    may be used to endorse or promote products derived from this software
     23  1.1  dholland  *    without specific prior written permission.
     24  1.1  dholland  *
     25  1.1  dholland  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     26  1.1  dholland  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     27  1.1  dholland  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     28  1.1  dholland  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     29  1.1  dholland  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     30  1.1  dholland  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     31  1.1  dholland  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     32  1.1  dholland  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     33  1.1  dholland  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     34  1.1  dholland  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     35  1.1  dholland  * SUCH DAMAGE.
     36  1.1  dholland  *
     37  1.1  dholland  *	@(#)inode.h	8.9 (Berkeley) 5/14/95
     38  1.1  dholland  */
     39  1.1  dholland 
     40  1.3  dholland #ifndef _UFS_LFS_ULFS_INODE_H_
     41  1.3  dholland #define	_UFS_LFS_ULFS_INODE_H_
     42  1.1  dholland 
     43  1.1  dholland #include <sys/vnode.h>
     44  1.6  dholland #include <ufs/lfs/lfs_inode.h>
     45  1.2  dholland #include <ufs/lfs/ulfs_dinode.h>
     46  1.2  dholland #include <ufs/lfs/ulfs_quotacommon.h>
     47  1.1  dholland 
     48  1.8  dholland /* Misc. definitions */
     49  1.8  dholland #define BW_CLEAN	1		/* Flag for lfs_bwrite_ext() */
     50  1.8  dholland #define PG_DELWRI	PG_PAGER1	/* Local def for delayed pageout */
     51  1.8  dholland 
     52  1.8  dholland /* Resource limits */
     53  1.8  dholland #define	LFS_MAX_RESOURCE(x, u)	(((x) >> 2) - 10 * (u))
     54  1.8  dholland #define	LFS_WAIT_RESOURCE(x, u)	(((x) >> 1) - ((x) >> 3) - 10 * (u))
     55  1.8  dholland #define	LFS_INVERSE_MAX_RESOURCE(x, u)	(((x) + 10 * (u)) << 2)
     56  1.8  dholland #define LFS_MAX_BUFS	    LFS_MAX_RESOURCE(nbuf, 1)
     57  1.8  dholland #define LFS_WAIT_BUFS	    LFS_WAIT_RESOURCE(nbuf, 1)
     58  1.8  dholland #define LFS_INVERSE_MAX_BUFS(n)	LFS_INVERSE_MAX_RESOURCE(n, 1)
     59  1.8  dholland #define LFS_MAX_BYTES	    LFS_MAX_RESOURCE(bufmem_lowater, PAGE_SIZE)
     60  1.8  dholland #define LFS_INVERSE_MAX_BYTES(n) LFS_INVERSE_MAX_RESOURCE(n, PAGE_SIZE)
     61  1.8  dholland #define LFS_WAIT_BYTES	    LFS_WAIT_RESOURCE(bufmem_lowater, PAGE_SIZE)
     62  1.8  dholland #define LFS_MAX_DIROP	    ((desiredvnodes >> 2) + (desiredvnodes >> 3))
     63  1.8  dholland #define SIZEOF_DIROP(fs)	(2 * ((fs)->lfs_bsize + LFS_DINODE1_SIZE))
     64  1.8  dholland #define LFS_MAX_FSDIROP(fs)						\
     65  1.8  dholland 	((fs)->lfs_nclean <= (fs)->lfs_resvseg ? 0 :			\
     66  1.8  dholland 	 (((fs)->lfs_nclean - (fs)->lfs_resvseg) * (fs)->lfs_ssize) /	\
     67  1.8  dholland           (2 * SIZEOF_DIROP(fs)))
     68  1.8  dholland #define LFS_MAX_PAGES	lfs_max_pages()
     69  1.8  dholland #define LFS_WAIT_PAGES	lfs_wait_pages()
     70  1.8  dholland #define LFS_BUFWAIT	    2	/* How long to wait if over *_WAIT_* */
     71  1.8  dholland 
     72  1.8  dholland #ifdef _KERNEL
     73  1.8  dholland extern u_long bufmem_lowater, bufmem_hiwater; /* XXX */
     74  1.8  dholland 
     75  1.8  dholland int lfs_wait_pages(void);
     76  1.8  dholland int lfs_max_pages(void);
     77  1.8  dholland #endif /* _KERNEL */
     78  1.8  dholland 
     79  1.8  dholland /* How starved can we be before we start holding back page writes */
     80  1.8  dholland #define LFS_STARVED_FOR_SEGS(fs) ((fs)->lfs_nclean < (fs)->lfs_resvseg)
     81  1.8  dholland 
     82  1.8  dholland /*
     83  1.8  dholland  * Reserved blocks for lfs_malloc
     84  1.8  dholland  */
     85  1.8  dholland 
     86  1.8  dholland /* Structure to keep reserved blocks */
     87  1.8  dholland typedef struct lfs_res_blk {
     88  1.8  dholland 	void *p;
     89  1.8  dholland 	LIST_ENTRY(lfs_res_blk) res;
     90  1.8  dholland 	int size;
     91  1.8  dholland 	char inuse;
     92  1.8  dholland } res_t;
     93  1.8  dholland 
     94  1.8  dholland /* Types for lfs_newbuf and lfs_malloc */
     95  1.8  dholland #define LFS_NB_UNKNOWN -1
     96  1.8  dholland #define LFS_NB_SUMMARY	0
     97  1.8  dholland #define LFS_NB_SBLOCK	1
     98  1.8  dholland #define LFS_NB_IBLOCK	2
     99  1.8  dholland #define LFS_NB_CLUSTER	3
    100  1.8  dholland #define LFS_NB_CLEAN	4
    101  1.8  dholland #define LFS_NB_BLKIOV	5
    102  1.8  dholland #define LFS_NB_COUNT	6 /* always last */
    103  1.8  dholland 
    104  1.8  dholland /* Number of reserved memory blocks of each type */
    105  1.8  dholland #define LFS_N_SUMMARIES 2
    106  1.8  dholland #define LFS_N_SBLOCKS	1   /* Always 1, to throttle superblock writes */
    107  1.8  dholland #define LFS_N_IBLOCKS	16  /* In theory ssize/bsize; in practice around 2 */
    108  1.8  dholland #define LFS_N_CLUSTERS	16  /* In theory ssize/MAXPHYS */
    109  1.8  dholland #define LFS_N_CLEAN	0
    110  1.8  dholland #define LFS_N_BLKIOV	1
    111  1.8  dholland 
    112  1.8  dholland /* Total count of "large" (non-pool) types */
    113  1.8  dholland #define LFS_N_TOTAL (LFS_N_SUMMARIES + LFS_N_SBLOCKS + LFS_N_IBLOCKS +	\
    114  1.8  dholland 		     LFS_N_CLUSTERS + LFS_N_CLEAN + LFS_N_BLKIOV)
    115  1.8  dholland 
    116  1.8  dholland /* Counts for pool types */
    117  1.8  dholland #define LFS_N_CL	LFS_N_CLUSTERS
    118  1.8  dholland #define LFS_N_BPP	2
    119  1.8  dholland #define LFS_N_SEG	2
    120  1.8  dholland 
    121  1.8  dholland /*
    122  1.8  dholland  * "struct buf" associated definitions
    123  1.8  dholland  */
    124  1.8  dholland 
    125  1.8  dholland /* Determine if a buffer belongs to the ifile */
    126  1.8  dholland #define IS_IFILE(bp)	(VTOI(bp->b_vp)->i_number == LFS_IFILE_INUM)
    127  1.8  dholland 
    128  1.8  dholland #ifdef _KERNEL
    129  1.8  dholland /* This overlays the fid structure (see fstypes.h). */
    130  1.8  dholland struct ulfs_ufid {
    131  1.8  dholland 	u_int16_t ufid_len;	/* Length of structure. */
    132  1.8  dholland 	u_int16_t ufid_pad;	/* Force 32-bit alignment. */
    133  1.8  dholland 	u_int32_t ufid_ino;	/* File number (ino). */
    134  1.8  dholland 	int32_t	  ufid_gen;	/* Generation number. */
    135  1.8  dholland };
    136  1.8  dholland /* Filehandle structure for exported LFSes */
    137  1.8  dholland struct lfid {
    138  1.8  dholland 	struct ulfs_ufid lfid_ufid;
    139  1.8  dholland #define lfid_len lfid_ufid.ufid_len
    140  1.8  dholland #define lfid_ino lfid_ufid.ufid_ino
    141  1.8  dholland #define lfid_gen lfid_ufid.ufid_gen
    142  1.8  dholland 	uint32_t lfid_ident;
    143  1.8  dholland };
    144  1.8  dholland #endif /* _KERNEL */
    145  1.8  dholland 
    146  1.8  dholland /* Address calculations for metadata located in the inode */
    147  1.8  dholland #define	S_INDIR(fs)	-ULFS_NDADDR
    148  1.9  christos #define	D_INDIR(fs)	(S_INDIR(fs) - LFS_NINDIR(fs) - 1)
    149  1.9  christos #define	T_INDIR(fs)	(D_INDIR(fs) - LFS_NINDIR(fs) * LFS_NINDIR(fs) - 1)
    150  1.8  dholland 
    151  1.8  dholland /*
    152  1.8  dholland  * "struct vnode" associated definitions
    153  1.8  dholland  */
    154  1.8  dholland 
    155  1.8  dholland /* Heuristic emptiness measure */
    156  1.8  dholland #define VPISEMPTY(vp)	 (LIST_EMPTY(&(vp)->v_dirtyblkhd) && 		\
    157  1.8  dholland 			  !(vp->v_type == VREG && (vp)->v_iflag & VI_ONWORKLST) &&\
    158  1.8  dholland 			  VTOI(vp)->i_lfs_nbtree == 0)
    159  1.8  dholland 
    160  1.8  dholland #define WRITEINPROG(vp) ((vp)->v_numoutput > 0 ||			\
    161  1.8  dholland 	(!LIST_EMPTY(&(vp)->v_dirtyblkhd) &&				\
    162  1.8  dholland 	 !(VTOI(vp)->i_flag & (IN_MODIFIED | IN_ACCESSED | IN_CLEANING))))
    163  1.8  dholland 
    164  1.8  dholland 
    165  1.8  dholland 
    166  1.8  dholland 
    167  1.8  dholland 
    168  1.1  dholland #if defined(_KERNEL)
    169  1.1  dholland 
    170  1.1  dholland /*
    171  1.1  dholland  * The DIP macro is used to access fields in the dinode that are
    172  1.1  dholland  * not cached in the inode itself.
    173  1.1  dholland  */
    174  1.1  dholland #define	DIP(ip, field) \
    175  1.3  dholland 	(((ip)->i_ump->um_fstype == ULFS1) ? \
    176  1.1  dholland 	(ip)->i_ffs1_##field : (ip)->i_ffs2_##field)
    177  1.1  dholland 
    178  1.1  dholland #define	DIP_ASSIGN(ip, field, value)					\
    179  1.1  dholland 	do {								\
    180  1.3  dholland 		if ((ip)->i_ump->um_fstype == ULFS1)			\
    181  1.1  dholland 			(ip)->i_ffs1_##field = (value);			\
    182  1.1  dholland 		else							\
    183  1.1  dholland 			(ip)->i_ffs2_##field = (value);			\
    184  1.1  dholland 	} while(0)
    185  1.1  dholland 
    186  1.1  dholland #define	DIP_ADD(ip, field, value)					\
    187  1.1  dholland 	do {								\
    188  1.3  dholland 		if ((ip)->i_ump->um_fstype == ULFS1)			\
    189  1.1  dholland 			(ip)->i_ffs1_##field += (value);		\
    190  1.1  dholland 		else							\
    191  1.1  dholland 			(ip)->i_ffs2_##field += (value);		\
    192  1.1  dholland 	} while(0)
    193  1.1  dholland 
    194  1.1  dholland #define	 SHORTLINK(ip) \
    195  1.3  dholland 	(((ip)->i_ump->um_fstype == ULFS1) ? \
    196  1.1  dholland 	(void *)(ip)->i_ffs1_db : (void *)(ip)->i_ffs2_db)
    197  1.1  dholland 
    198  1.1  dholland 
    199  1.1  dholland /*
    200  1.1  dholland  * Structure used to pass around logical block paths generated by
    201  1.3  dholland  * ulfs_getlbns and used by truncate and bmap code.
    202  1.1  dholland  */
    203  1.1  dholland struct indir {
    204  1.1  dholland 	daddr_t in_lbn;		/* Logical block number. */
    205  1.1  dholland 	int	in_off;			/* Offset in buffer. */
    206  1.1  dholland 	int	in_exists;		/* Flag if the block exists. */
    207  1.1  dholland };
    208  1.1  dholland 
    209  1.1  dholland /* Convert between inode pointers and vnode pointers. */
    210  1.1  dholland #define	VTOI(vp)	((struct inode *)(vp)->v_data)
    211  1.1  dholland #define	ITOV(ip)	((ip)->i_vnode)
    212  1.1  dholland 
    213  1.1  dholland #endif /* _KERNEL */
    214  1.1  dholland 
    215  1.3  dholland #endif /* !_UFS_LFS_ULFS_INODE_H_ */
    216