xref: /minix3/sys/ufs/lfs/ulfs_inode.h (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc /*	$NetBSD: ulfs_inode.h,v 1.16 2015/09/01 06:08:37 dholland Exp $	*/
284d9c625SLionel Sambuc /*  from NetBSD: inode.h,v 1.64 2012/11/19 00:36:21 jakllsch Exp  */
384d9c625SLionel Sambuc 
484d9c625SLionel Sambuc /*
584d9c625SLionel Sambuc  * Copyright (c) 1982, 1989, 1993
684d9c625SLionel Sambuc  *	The Regents of the University of California.  All rights reserved.
784d9c625SLionel Sambuc  * (c) UNIX System Laboratories, Inc.
884d9c625SLionel Sambuc  * All or some portions of this file are derived from material licensed
984d9c625SLionel Sambuc  * to the University of California by American Telephone and Telegraph
1084d9c625SLionel Sambuc  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
1184d9c625SLionel Sambuc  * the permission of UNIX System Laboratories, Inc.
1284d9c625SLionel Sambuc  *
1384d9c625SLionel Sambuc  * Redistribution and use in source and binary forms, with or without
1484d9c625SLionel Sambuc  * modification, are permitted provided that the following conditions
1584d9c625SLionel Sambuc  * are met:
1684d9c625SLionel Sambuc  * 1. Redistributions of source code must retain the above copyright
1784d9c625SLionel Sambuc  *    notice, this list of conditions and the following disclaimer.
1884d9c625SLionel Sambuc  * 2. Redistributions in binary form must reproduce the above copyright
1984d9c625SLionel Sambuc  *    notice, this list of conditions and the following disclaimer in the
2084d9c625SLionel Sambuc  *    documentation and/or other materials provided with the distribution.
2184d9c625SLionel Sambuc  * 3. Neither the name of the University nor the names of its contributors
2284d9c625SLionel Sambuc  *    may be used to endorse or promote products derived from this software
2384d9c625SLionel Sambuc  *    without specific prior written permission.
2484d9c625SLionel Sambuc  *
2584d9c625SLionel Sambuc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2684d9c625SLionel Sambuc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2784d9c625SLionel Sambuc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2884d9c625SLionel Sambuc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2984d9c625SLionel Sambuc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3084d9c625SLionel Sambuc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3184d9c625SLionel Sambuc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3284d9c625SLionel Sambuc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3384d9c625SLionel Sambuc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3484d9c625SLionel Sambuc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3584d9c625SLionel Sambuc  * SUCH DAMAGE.
3684d9c625SLionel Sambuc  *
3784d9c625SLionel Sambuc  *	@(#)inode.h	8.9 (Berkeley) 5/14/95
3884d9c625SLionel Sambuc  */
3984d9c625SLionel Sambuc 
4084d9c625SLionel Sambuc #ifndef _UFS_LFS_ULFS_INODE_H_
4184d9c625SLionel Sambuc #define	_UFS_LFS_ULFS_INODE_H_
4284d9c625SLionel Sambuc 
4384d9c625SLionel Sambuc #include <sys/vnode.h>
4484d9c625SLionel Sambuc #include <ufs/lfs/lfs_inode.h>
4584d9c625SLionel Sambuc #include <ufs/lfs/ulfs_dinode.h>
4684d9c625SLionel Sambuc #include <ufs/lfs/ulfs_quotacommon.h>
4784d9c625SLionel Sambuc 
4884d9c625SLionel Sambuc /*
4984d9c625SLionel Sambuc  * These macros are used to bracket ULFS directory ops, so that we can
5084d9c625SLionel Sambuc  * identify all the pages touched during directory ops which need to
5184d9c625SLionel Sambuc  * be ordered and flushed atomically, so that they may be recovered.
5284d9c625SLionel Sambuc  *
5384d9c625SLionel Sambuc  * Because we have to mark nodes VU_DIROP in order to prevent
5484d9c625SLionel Sambuc  * the cache from reclaiming them while a dirop is in progress, we must
5584d9c625SLionel Sambuc  * also manage the number of nodes so marked (otherwise we can run out).
5684d9c625SLionel Sambuc  * We do this by setting lfs_dirvcount to the number of marked vnodes; it
5784d9c625SLionel Sambuc  * is decremented during segment write, when VU_DIROP is taken off.
5884d9c625SLionel Sambuc  */
5984d9c625SLionel Sambuc #define	MARK_VNODE(vp)			lfs_mark_vnode(vp)
6084d9c625SLionel Sambuc #define	UNMARK_VNODE(vp)		lfs_unmark_vnode(vp)
6184d9c625SLionel Sambuc int lfs_set_dirop(struct vnode *, struct vnode *);
62*0a6a1f1dSLionel Sambuc void lfs_unset_dirop(struct lfs *, struct vnode *, const char *);
6384d9c625SLionel Sambuc 
6484d9c625SLionel Sambuc /* Misc. definitions */
6584d9c625SLionel Sambuc #define BW_CLEAN	1		/* Flag for lfs_bwrite_ext() */
6684d9c625SLionel Sambuc #define PG_DELWRI	PG_PAGER1	/* Local def for delayed pageout */
6784d9c625SLionel Sambuc 
6884d9c625SLionel Sambuc /* Resource limits */
6984d9c625SLionel Sambuc #define	LFS_MAX_RESOURCE(x, u)	(((x) >> 2) - 10 * (u))
7084d9c625SLionel Sambuc #define	LFS_WAIT_RESOURCE(x, u)	(((x) >> 1) - ((x) >> 3) - 10 * (u))
7184d9c625SLionel Sambuc #define	LFS_INVERSE_MAX_RESOURCE(x, u)	(((x) + 10 * (u)) << 2)
7284d9c625SLionel Sambuc #define LFS_MAX_BUFS	    LFS_MAX_RESOURCE(nbuf, 1)
7384d9c625SLionel Sambuc #define LFS_WAIT_BUFS	    LFS_WAIT_RESOURCE(nbuf, 1)
7484d9c625SLionel Sambuc #define LFS_INVERSE_MAX_BUFS(n)	LFS_INVERSE_MAX_RESOURCE(n, 1)
7584d9c625SLionel Sambuc #define LFS_MAX_BYTES	    LFS_MAX_RESOURCE(bufmem_lowater, PAGE_SIZE)
7684d9c625SLionel Sambuc #define LFS_INVERSE_MAX_BYTES(n) LFS_INVERSE_MAX_RESOURCE(n, PAGE_SIZE)
7784d9c625SLionel Sambuc #define LFS_WAIT_BYTES	    LFS_WAIT_RESOURCE(bufmem_lowater, PAGE_SIZE)
7884d9c625SLionel Sambuc #define LFS_MAX_DIROP	    ((desiredvnodes >> 2) + (desiredvnodes >> 3))
79*0a6a1f1dSLionel Sambuc #define SIZEOF_DIROP(fs)	(2 * (lfs_sb_getbsize(fs) + DINOSIZE(fs)))
8084d9c625SLionel Sambuc #define LFS_MAX_FSDIROP(fs)						\
81*0a6a1f1dSLionel Sambuc 	(lfs_sb_getnclean(fs) <= lfs_sb_getresvseg(fs) ? 0 :		\
82*0a6a1f1dSLionel Sambuc 	 ((lfs_sb_getnclean(fs) - lfs_sb_getresvseg(fs)) * lfs_sb_getssize(fs)) / \
8384d9c625SLionel Sambuc           (2 * SIZEOF_DIROP(fs)))
8484d9c625SLionel Sambuc #define LFS_MAX_PAGES	lfs_max_pages()
8584d9c625SLionel Sambuc #define LFS_WAIT_PAGES	lfs_wait_pages()
8684d9c625SLionel Sambuc #define LFS_BUFWAIT	    2	/* How long to wait if over *_WAIT_* */
8784d9c625SLionel Sambuc 
8884d9c625SLionel Sambuc #ifdef _KERNEL
8984d9c625SLionel Sambuc extern u_long bufmem_lowater, bufmem_hiwater; /* XXX */
9084d9c625SLionel Sambuc 
9184d9c625SLionel Sambuc int lfs_wait_pages(void);
9284d9c625SLionel Sambuc int lfs_max_pages(void);
9384d9c625SLionel Sambuc #endif /* _KERNEL */
9484d9c625SLionel Sambuc 
9584d9c625SLionel Sambuc /* How starved can we be before we start holding back page writes */
96*0a6a1f1dSLionel Sambuc #define LFS_STARVED_FOR_SEGS(fs) (lfs_sb_getnclean(fs) < lfs_sb_getresvseg(fs))
9784d9c625SLionel Sambuc 
9884d9c625SLionel Sambuc /*
9984d9c625SLionel Sambuc  * Reserved blocks for lfs_malloc
10084d9c625SLionel Sambuc  */
10184d9c625SLionel Sambuc 
10284d9c625SLionel Sambuc /* Structure to keep reserved blocks */
10384d9c625SLionel Sambuc typedef struct lfs_res_blk {
10484d9c625SLionel Sambuc 	void *p;
10584d9c625SLionel Sambuc 	LIST_ENTRY(lfs_res_blk) res;
10684d9c625SLionel Sambuc 	int size;
10784d9c625SLionel Sambuc 	char inuse;
10884d9c625SLionel Sambuc } res_t;
10984d9c625SLionel Sambuc 
11084d9c625SLionel Sambuc /* Types for lfs_newbuf and lfs_malloc */
11184d9c625SLionel Sambuc #define LFS_NB_UNKNOWN -1
11284d9c625SLionel Sambuc #define LFS_NB_SUMMARY	0
11384d9c625SLionel Sambuc #define LFS_NB_SBLOCK	1
11484d9c625SLionel Sambuc #define LFS_NB_IBLOCK	2
11584d9c625SLionel Sambuc #define LFS_NB_CLUSTER	3
11684d9c625SLionel Sambuc #define LFS_NB_CLEAN	4
11784d9c625SLionel Sambuc #define LFS_NB_BLKIOV	5
11884d9c625SLionel Sambuc #define LFS_NB_COUNT	6 /* always last */
11984d9c625SLionel Sambuc 
12084d9c625SLionel Sambuc /* Number of reserved memory blocks of each type */
12184d9c625SLionel Sambuc #define LFS_N_SUMMARIES 2
12284d9c625SLionel Sambuc #define LFS_N_SBLOCKS	1   /* Always 1, to throttle superblock writes */
12384d9c625SLionel Sambuc #define LFS_N_IBLOCKS	16  /* In theory ssize/bsize; in practice around 2 */
12484d9c625SLionel Sambuc #define LFS_N_CLUSTERS	16  /* In theory ssize/MAXPHYS */
12584d9c625SLionel Sambuc #define LFS_N_CLEAN	0
12684d9c625SLionel Sambuc #define LFS_N_BLKIOV	1
12784d9c625SLionel Sambuc 
12884d9c625SLionel Sambuc /* Total count of "large" (non-pool) types */
12984d9c625SLionel Sambuc #define LFS_N_TOTAL (LFS_N_SUMMARIES + LFS_N_SBLOCKS + LFS_N_IBLOCKS +	\
13084d9c625SLionel Sambuc 		     LFS_N_CLUSTERS + LFS_N_CLEAN + LFS_N_BLKIOV)
13184d9c625SLionel Sambuc 
13284d9c625SLionel Sambuc /* Counts for pool types */
13384d9c625SLionel Sambuc #define LFS_N_CL	LFS_N_CLUSTERS
13484d9c625SLionel Sambuc #define LFS_N_BPP	2
13584d9c625SLionel Sambuc #define LFS_N_SEG	2
13684d9c625SLionel Sambuc 
13784d9c625SLionel Sambuc /*
13884d9c625SLionel Sambuc  * "struct buf" associated definitions
13984d9c625SLionel Sambuc  */
14084d9c625SLionel Sambuc 
14184d9c625SLionel Sambuc /* Determine if a buffer belongs to the ifile */
14284d9c625SLionel Sambuc #define IS_IFILE(bp)	(VTOI(bp->b_vp)->i_number == LFS_IFILE_INUM)
14384d9c625SLionel Sambuc 
14484d9c625SLionel Sambuc #ifdef _KERNEL
14584d9c625SLionel Sambuc /* This overlays the fid structure (see fstypes.h). */
14684d9c625SLionel Sambuc struct ulfs_ufid {
14784d9c625SLionel Sambuc 	u_int16_t ufid_len;	/* Length of structure. */
14884d9c625SLionel Sambuc 	u_int16_t ufid_pad;	/* Force 32-bit alignment. */
14984d9c625SLionel Sambuc 	u_int32_t ufid_ino;	/* File number (ino). */
15084d9c625SLionel Sambuc 	int32_t	  ufid_gen;	/* Generation number. */
15184d9c625SLionel Sambuc };
15284d9c625SLionel Sambuc /* Filehandle structure for exported LFSes */
15384d9c625SLionel Sambuc struct lfid {
15484d9c625SLionel Sambuc 	struct ulfs_ufid lfid_ufid;
15584d9c625SLionel Sambuc #define lfid_len lfid_ufid.ufid_len
15684d9c625SLionel Sambuc #define lfid_ino lfid_ufid.ufid_ino
15784d9c625SLionel Sambuc #define lfid_gen lfid_ufid.ufid_gen
15884d9c625SLionel Sambuc 	uint32_t lfid_ident;
15984d9c625SLionel Sambuc };
16084d9c625SLionel Sambuc #endif /* _KERNEL */
16184d9c625SLionel Sambuc 
16284d9c625SLionel Sambuc /* Address calculations for metadata located in the inode */
16384d9c625SLionel Sambuc #define	S_INDIR(fs)	-ULFS_NDADDR
16484d9c625SLionel Sambuc #define	D_INDIR(fs)	(S_INDIR(fs) - LFS_NINDIR(fs) - 1)
16584d9c625SLionel Sambuc #define	T_INDIR(fs)	(D_INDIR(fs) - LFS_NINDIR(fs) * LFS_NINDIR(fs) - 1)
16684d9c625SLionel Sambuc 
16784d9c625SLionel Sambuc /*
16884d9c625SLionel Sambuc  * "struct vnode" associated definitions
16984d9c625SLionel Sambuc  */
17084d9c625SLionel Sambuc 
17184d9c625SLionel Sambuc /* Heuristic emptiness measure */
17284d9c625SLionel Sambuc #define VPISEMPTY(vp)	 (LIST_EMPTY(&(vp)->v_dirtyblkhd) && 		\
17384d9c625SLionel Sambuc 			  !(vp->v_type == VREG && (vp)->v_iflag & VI_ONWORKLST) &&\
17484d9c625SLionel Sambuc 			  VTOI(vp)->i_lfs_nbtree == 0)
17584d9c625SLionel Sambuc 
17684d9c625SLionel Sambuc #define WRITEINPROG(vp) ((vp)->v_numoutput > 0 ||			\
17784d9c625SLionel Sambuc 	(!LIST_EMPTY(&(vp)->v_dirtyblkhd) &&				\
17884d9c625SLionel Sambuc 	 !(VTOI(vp)->i_flag & (IN_MODIFIED | IN_ACCESSED | IN_CLEANING))))
17984d9c625SLionel Sambuc 
18084d9c625SLionel Sambuc 
18184d9c625SLionel Sambuc 
18284d9c625SLionel Sambuc 
18384d9c625SLionel Sambuc 
18484d9c625SLionel Sambuc #if defined(_KERNEL)
18584d9c625SLionel Sambuc 
18684d9c625SLionel Sambuc /*
18784d9c625SLionel Sambuc  * The DIP macro is used to access fields in the dinode that are
18884d9c625SLionel Sambuc  * not cached in the inode itself.
18984d9c625SLionel Sambuc  */
19084d9c625SLionel Sambuc #define	DIP(ip, field) \
19184d9c625SLionel Sambuc 	(((ip)->i_ump->um_fstype == ULFS1) ? \
192*0a6a1f1dSLionel Sambuc 	(ip)->i_din->u_32.di_##field : (ip)->i_din->u_64.di_##field)
19384d9c625SLionel Sambuc 
19484d9c625SLionel Sambuc #define	DIP_ASSIGN(ip, field, value)					\
19584d9c625SLionel Sambuc 	do {								\
19684d9c625SLionel Sambuc 		if ((ip)->i_ump->um_fstype == ULFS1)			\
197*0a6a1f1dSLionel Sambuc 			(ip)->i_din->u_32.di_##field = (value);	\
19884d9c625SLionel Sambuc 		else							\
199*0a6a1f1dSLionel Sambuc 			(ip)->i_din->u_64.di_##field = (value);	\
20084d9c625SLionel Sambuc 	} while(0)
20184d9c625SLionel Sambuc 
20284d9c625SLionel Sambuc #define	DIP_ADD(ip, field, value)					\
20384d9c625SLionel Sambuc 	do {								\
20484d9c625SLionel Sambuc 		if ((ip)->i_ump->um_fstype == ULFS1)			\
205*0a6a1f1dSLionel Sambuc 			(ip)->i_din->u_32.di_##field += (value);	\
20684d9c625SLionel Sambuc 		else							\
207*0a6a1f1dSLionel Sambuc 			(ip)->i_din->u_64.di_##field += (value);	\
20884d9c625SLionel Sambuc 	} while(0)
20984d9c625SLionel Sambuc 
210*0a6a1f1dSLionel Sambuc /* XXX rework this better */
21184d9c625SLionel Sambuc #define	 SHORTLINK(ip) \
21284d9c625SLionel Sambuc 	(((ip)->i_ump->um_fstype == ULFS1) ? \
213*0a6a1f1dSLionel Sambuc 	(void *)(ip)->i_din->u_32.di_db : (void *)(ip)->i_din->u_64.di_db)
21484d9c625SLionel Sambuc 
21584d9c625SLionel Sambuc 
21684d9c625SLionel Sambuc /*
21784d9c625SLionel Sambuc  * Structure used to pass around logical block paths generated by
21884d9c625SLionel Sambuc  * ulfs_getlbns and used by truncate and bmap code.
21984d9c625SLionel Sambuc  */
22084d9c625SLionel Sambuc struct indir {
22184d9c625SLionel Sambuc 	daddr_t in_lbn;		/* Logical block number. */
22284d9c625SLionel Sambuc 	int	in_off;			/* Offset in buffer. */
22384d9c625SLionel Sambuc 	int	in_exists;		/* Flag if the block exists. */
22484d9c625SLionel Sambuc };
22584d9c625SLionel Sambuc 
22684d9c625SLionel Sambuc /* Convert between inode pointers and vnode pointers. */
22784d9c625SLionel Sambuc #define	VTOI(vp)	((struct inode *)(vp)->v_data)
22884d9c625SLionel Sambuc #define	ITOV(ip)	((ip)->i_vnode)
22984d9c625SLionel Sambuc 
23084d9c625SLionel Sambuc #endif /* _KERNEL */
23184d9c625SLionel Sambuc 
23284d9c625SLionel Sambuc #endif /* !_UFS_LFS_ULFS_INODE_H_ */
233