Home | History | Annotate | Line # | Download | only in lfs
lfs.h revision 1.26
      1  1.26  perseant /*	$NetBSD: lfs.h,v 1.26 2000/06/27 20:57:11 perseant Exp $	*/
      2   1.6   mycroft 
      3   1.1   mycroft /*-
      4  1.11  perseant  * Copyright (c) 1999 The NetBSD Foundation, Inc.
      5  1.11  perseant  * All rights reserved.
      6  1.11  perseant  *
      7  1.11  perseant  * This code is derived from software contributed to The NetBSD Foundation
      8  1.11  perseant  * by Konrad E. Schroder <perseant (at) hhhh.org>.
      9  1.11  perseant  *
     10  1.11  perseant  * Redistribution and use in source and binary forms, with or without
     11  1.11  perseant  * modification, are permitted provided that the following conditions
     12  1.11  perseant  * are met:
     13  1.11  perseant  * 1. Redistributions of source code must retain the above copyright
     14  1.11  perseant  *    notice, this list of conditions and the following disclaimer.
     15  1.11  perseant  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.11  perseant  *    notice, this list of conditions and the following disclaimer in the
     17  1.11  perseant  *    documentation and/or other materials provided with the distribution.
     18  1.11  perseant  * 3. All advertising materials mentioning features or use of this software
     19  1.11  perseant  *    must display the following acknowledgement:
     20  1.11  perseant  *      This product includes software developed by the NetBSD
     21  1.11  perseant  *      Foundation, Inc. and its contributors.
     22  1.11  perseant  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.11  perseant  *    contributors may be used to endorse or promote products derived
     24  1.11  perseant  *    from this software without specific prior written permission.
     25  1.11  perseant  *
     26  1.11  perseant  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.11  perseant  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.11  perseant  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.11  perseant  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.11  perseant  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.11  perseant  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.11  perseant  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.11  perseant  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.11  perseant  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.11  perseant  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.11  perseant  * POSSIBILITY OF SUCH DAMAGE.
     37  1.11  perseant  */
     38  1.11  perseant /*-
     39   1.1   mycroft  * Copyright (c) 1991, 1993
     40   1.1   mycroft  *	The Regents of the University of California.  All rights reserved.
     41   1.1   mycroft  *
     42   1.1   mycroft  * Redistribution and use in source and binary forms, with or without
     43   1.1   mycroft  * modification, are permitted provided that the following conditions
     44   1.1   mycroft  * are met:
     45   1.1   mycroft  * 1. Redistributions of source code must retain the above copyright
     46   1.1   mycroft  *    notice, this list of conditions and the following disclaimer.
     47   1.1   mycroft  * 2. Redistributions in binary form must reproduce the above copyright
     48   1.1   mycroft  *    notice, this list of conditions and the following disclaimer in the
     49   1.1   mycroft  *    documentation and/or other materials provided with the distribution.
     50   1.1   mycroft  * 3. All advertising materials mentioning features or use of this software
     51   1.1   mycroft  *    must display the following acknowledgement:
     52   1.1   mycroft  *	This product includes software developed by the University of
     53   1.1   mycroft  *	California, Berkeley and its contributors.
     54   1.1   mycroft  * 4. Neither the name of the University nor the names of its contributors
     55   1.1   mycroft  *    may be used to endorse or promote products derived from this software
     56   1.1   mycroft  *    without specific prior written permission.
     57   1.1   mycroft  *
     58   1.1   mycroft  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     59   1.1   mycroft  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     60   1.1   mycroft  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     61   1.1   mycroft  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     62   1.1   mycroft  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     63   1.1   mycroft  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     64   1.1   mycroft  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     65   1.1   mycroft  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     66   1.1   mycroft  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     67   1.1   mycroft  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     68   1.1   mycroft  * SUCH DAMAGE.
     69   1.1   mycroft  *
     70   1.9      fvdl  *	@(#)lfs.h	8.9 (Berkeley) 5/8/95
     71   1.1   mycroft  */
     72   1.1   mycroft 
     73  1.11  perseant /*
     74  1.11  perseant  * Compile-time options for LFS.
     75  1.11  perseant  */
     76  1.11  perseant #define LFS_EAGAIN_FAIL          /* markv fail with EAGAIN if ino is locked */
     77  1.14  perseant #define LFS_TRACK_IOS            /* attempt to avoid cleaning segments not yet fully written to disk */
     78  1.11  perseant #define LFS_CANNOT_ROLLFW       /* No roll-forward agent exists */
     79  1.11  perseant 
     80  1.11  perseant /* #define DEBUG_LFS */              /* Intensive debugging of LFS subsystem */
     81  1.11  perseant 
     82  1.11  perseant /* #define LFS_ATIME_IFILE */         /* Store atime in Ifile, don't push */
     83  1.11  perseant 
     84  1.11  perseant /*
     85  1.11  perseant  * Parameters and generic definitions
     86  1.11  perseant  */
     87  1.17  perseant #define BW_CLEAN	1
     88  1.17  perseant #define MIN_FREE_SEGS	4
     89  1.17  perseant #define LFS_MAX_ACTIVE	10
     90  1.17  perseant #define LFS_MAXDIROP	(desiredvnodes>>2)
     91  1.24  perseant 
     92  1.24  perseant /* For convenience */
     93  1.24  perseant #define IN_ALLMOD (IN_MODIFIED|IN_ACCESS|IN_CHANGE|IN_UPDATE|IN_ACCESSED|IN_CLEANING)
     94  1.11  perseant 
     95  1.11  perseant #ifndef LFS_ATIME_IFILE
     96  1.11  perseant # define LFS_ITIMES(ip, acc, mod, cre) FFS_ITIMES((ip),(acc),(mod),(cre))
     97  1.11  perseant #else
     98  1.11  perseant # define LFS_ITIMES(ip, acc, mod, cre) {                                \
     99  1.11  perseant 	struct buf *ibp;						\
    100  1.11  perseant 	IFILE *ifp;							\
    101  1.11  perseant 									\
    102  1.11  perseant         if ((ip)->i_flag & IN_ACCESS) {                         	\
    103  1.11  perseant 	LFS_IENTRY(ifp, ip->i_lfs, ip->i_number, ibp);			\
    104  1.11  perseant        		ifp->if_atime = (mod);					\
    105  1.11  perseant        		VOP_BWRITE(bp);						\
    106  1.11  perseant 		(ip)->i_flag &= ~IN_ACCESS;				\
    107  1.11  perseant         }                                                       	\
    108  1.11  perseant         if ((ip)->i_flag & (IN_CHANGE | IN_UPDATE)) {       		\
    109  1.11  perseant                 (ip)->i_flag |= IN_MODIFIED;                            \
    110  1.11  perseant                 if ((ip)->i_flag & IN_UPDATE) {                         \
    111  1.11  perseant                         (ip)->i_ffs_mtime = (mod)->tv_sec;		\
    112  1.11  perseant                         (ip)->i_ffs_mtimensec = (mod)->tv_nsec;         \
    113  1.11  perseant                         (ip)->i_modrev++;                               \
    114  1.11  perseant                 }                                                       \
    115  1.11  perseant                 if ((ip)->i_flag & IN_CHANGE) {                         \
    116  1.11  perseant                         (ip)->i_ffs_ctime = (cre)->tv_sec;		\
    117  1.11  perseant                         (ip)->i_ffs_ctimensec = (cre)->tv_nsec;         \
    118  1.11  perseant                 }                                                       \
    119  1.11  perseant                 (ip)->i_flag &= ~(IN_CHANGE | IN_UPDATE);   		\
    120  1.11  perseant         }                                                               \
    121  1.11  perseant }
    122  1.11  perseant #endif
    123  1.11  perseant 
    124  1.26  perseant #define WRITEINPROG(vp) (vp->v_dirtyblkhd.lh_first && !(VTOI(vp)->i_flag & (IN_MODIFIED|IN_ACCESSED|IN_CLEANING)))
    125  1.11  perseant 
    126  1.11  perseant /* Here begins the berkeley code */
    127  1.11  perseant 
    128   1.1   mycroft #define	LFS_LABELPAD	8192		/* LFS label size */
    129   1.1   mycroft #define	LFS_SBPAD	8192		/* LFS superblock size */
    130   1.1   mycroft 
    131   1.1   mycroft /* On-disk and in-memory checkpoint segment usage structure. */
    132   1.1   mycroft typedef struct segusage SEGUSE;
    133   1.1   mycroft struct segusage {
    134   1.3       cgd 	u_int32_t su_nbytes;		/* number of live bytes */
    135   1.3       cgd 	u_int32_t su_lastmod;		/* SEGUSE last modified timestamp */
    136   1.3       cgd 	u_int16_t su_nsums;		/* number of summaries in segment */
    137   1.3       cgd 	u_int16_t su_ninos;		/* number of inode blocks in seg */
    138   1.5   mycroft 
    139   1.5   mycroft #define	SEGUSE_ACTIVE		0x01	/* segment is currently being written */
    140   1.5   mycroft #define	SEGUSE_DIRTY		0x02	/* segment has data in it */
    141   1.5   mycroft #define	SEGUSE_SUPERBLOCK	0x04	/* segment contains a superblock */
    142   1.3       cgd 	u_int32_t su_flags;
    143   1.1   mycroft };
    144   1.1   mycroft 
    145   1.1   mycroft #define	SEGUPB(fs)	(1 << (fs)->lfs_sushift)
    146   1.1   mycroft #define	SEGTABSIZE_SU(fs)						\
    147   1.1   mycroft 	(((fs)->lfs_nseg + SEGUPB(fs) - 1) >> (fs)->lfs_sushift)
    148   1.1   mycroft 
    149   1.1   mycroft /* On-disk file information.  One per file with data blocks in the segment. */
    150   1.1   mycroft typedef struct finfo FINFO;
    151   1.1   mycroft struct finfo {
    152   1.3       cgd 	u_int32_t fi_nblocks;		/* number of blocks */
    153   1.3       cgd 	u_int32_t fi_version;		/* version number */
    154   1.3       cgd 	u_int32_t fi_ino;		/* inode number */
    155   1.9      fvdl 	u_int32_t fi_lastlength;	/* length of last block in array */
    156   1.9      fvdl 	ufs_daddr_t	  fi_blocks[1];		/* array of logical block numbers */
    157   1.1   mycroft };
    158   1.1   mycroft 
    159  1.10        pk /* On-disk super block. */
    160  1.10        pk struct dlfs {
    161   1.1   mycroft #define	LFS_MAGIC	0x070162
    162  1.10        pk         u_int32_t dlfs_magic;     /* 0: magic number */
    163   1.1   mycroft #define	LFS_VERSION	1
    164  1.10        pk         u_int32_t dlfs_version;   /* 4: version number */
    165   1.1   mycroft 
    166  1.10        pk         u_int32_t dlfs_size;      /* 8: number of blocks in fs */
    167  1.10        pk         u_int32_t dlfs_ssize;     /* 12: number of blocks per segment */
    168  1.10        pk         u_int32_t dlfs_dsize;     /* 16: number of disk blocks in fs */
    169  1.10        pk         u_int32_t dlfs_bsize;     /* 20: file system block size */
    170  1.10        pk         u_int32_t dlfs_fsize;     /* 24: size of frag blocks in fs */
    171  1.10        pk         u_int32_t dlfs_frag;      /* 28: number of frags in a block in fs */
    172   1.1   mycroft 
    173   1.1   mycroft /* Checkpoint region. */
    174  1.18    simonb         u_int32_t dlfs_free;      /* 32: start of the free list */
    175  1.10        pk         u_int32_t dlfs_bfree;     /* 36: number of free disk blocks */
    176  1.10        pk         u_int32_t dlfs_nfiles;    /* 40: number of allocated inodes */
    177  1.10        pk         int32_t   dlfs_avail;     /* 44: blocks available for writing */
    178  1.10        pk         u_int32_t dlfs_uinodes;   /* 48: inodes in cache not yet on disk */
    179  1.10        pk         ufs_daddr_t  dlfs_idaddr; /* 52: inode file disk address */
    180  1.18    simonb         u_int32_t dlfs_ifile;     /* 56: inode file inode number */
    181  1.10        pk         ufs_daddr_t  dlfs_lastseg; /* 60: address of last segment written */
    182  1.10        pk         ufs_daddr_t  dlfs_nextseg; /* 64: address of next segment to write */
    183  1.10        pk         ufs_daddr_t  dlfs_curseg; /* 68: current segment being written */
    184  1.10        pk         ufs_daddr_t  dlfs_offset; /* 72: offset in curseg for next partial */
    185  1.10        pk         ufs_daddr_t  dlfs_lastpseg; /* 76: address of last partial written */
    186  1.10        pk         u_int32_t dlfs_tstamp;    /* 80: time stamp */
    187   1.1   mycroft 
    188   1.1   mycroft /* These are configuration parameters. */
    189  1.10        pk         u_int32_t dlfs_minfree;   /* 84: minimum percentage of free blocks */
    190   1.1   mycroft 
    191   1.1   mycroft /* These fields can be computed from the others. */
    192  1.10        pk         u_int64_t dlfs_maxfilesize; /* 88: maximum representable file size */
    193  1.10        pk         u_int32_t dlfs_dbpseg;    /* 96: disk blocks per segment */
    194  1.10        pk         u_int32_t dlfs_inopb;     /* 100: inodes per block */
    195  1.10        pk         u_int32_t dlfs_ifpb;      /* 104: IFILE entries per block */
    196  1.10        pk         u_int32_t dlfs_sepb;      /* 108: SEGUSE entries per block */
    197  1.10        pk         u_int32_t dlfs_nindir;    /* 112: indirect pointers per block */
    198  1.10        pk         u_int32_t dlfs_nseg;      /* 116: number of segments */
    199  1.10        pk         u_int32_t dlfs_nspf;      /* 120: number of sectors per fragment */
    200  1.10        pk         u_int32_t dlfs_cleansz;   /* 124: cleaner info size in blocks */
    201  1.10        pk         u_int32_t dlfs_segtabsz;  /* 128: segment table size in blocks */
    202  1.10        pk         u_int32_t dlfs_segmask;   /* 132: calculate offset within a segment */
    203  1.10        pk         u_int32_t dlfs_segshift;  /* 136: fast mult/div for segments */
    204  1.10        pk         u_int32_t dlfs_bshift;    /* 140: calc block number from file offset */
    205  1.10        pk         u_int32_t dlfs_ffshift;   /* 144: fast mult/div for frag from file */
    206  1.10        pk         u_int32_t dlfs_fbshift;   /* 148: fast mult/div for frag from block */
    207  1.10        pk         u_int64_t dlfs_bmask;     /* 152: calc block offset from file offset */
    208  1.10        pk         u_int64_t dlfs_ffmask;    /* 160: calc frag offset from file offset */
    209  1.10        pk         u_int64_t dlfs_fbmask;    /* 168: calc frag offset from block offset */
    210  1.10        pk         u_int32_t dlfs_fsbtodb;   /* 176: fsbtodb and dbtofsb shift constant */
    211  1.10        pk         u_int32_t dlfs_sushift;   /* 180: fast mult/div for segusage table */
    212   1.3       cgd 
    213  1.10        pk         int32_t   dlfs_maxsymlinklen; /* 184: max length of an internal symlink */
    214   1.1   mycroft 
    215  1.11  perseant #define	LFS_MIN_SBINTERVAL	5  /* minimum superblock segment spacing */
    216  1.10        pk #define LFS_MAXNUMSB            10 /* 188: superblock disk offsets */
    217  1.10        pk         ufs_daddr_t       dlfs_sboffs[LFS_MAXNUMSB];
    218   1.3       cgd 
    219  1.11  perseant 	u_int32_t dlfs_nclean;    /* 228: Number of clean segments */
    220  1.11  perseant 	u_char	  dlfs_fsmnt[MNAMELEN];	 /* 232: name mounted on */
    221  1.11  perseant 	/* XXX this is 2 bytes only to pad to a quad boundary */
    222  1.11  perseant 	u_int16_t dlfs_clean;     /* 322: file system is clean flag */
    223  1.26  perseant 	u_int32_t dlfs_dmeta;     /* 324: total number of dirty summaries */
    224  1.26  perseant         int8_t    dlfs_pad[180];  /* 328: round to 512 bytes */
    225   1.5   mycroft /* Checksum -- last valid disk field. */
    226  1.26  perseant         u_int32_t dlfs_cksum;     /* 508: checksum for superblock checking */
    227  1.10        pk };
    228   1.1   mycroft 
    229  1.11  perseant /* Maximum number of io's we can have pending at once */
    230  1.11  perseant #define LFS_THROTTLE  16 /* XXX should be better paramtrized - ? */
    231  1.11  perseant 
    232  1.10        pk /* In-memory super block. */
    233  1.10        pk struct lfs {
    234  1.10        pk         struct dlfs lfs_dlfs;           /* on-disk parameters */
    235  1.10        pk #define lfs_magic lfs_dlfs.dlfs_magic
    236  1.10        pk #define lfs_version lfs_dlfs.dlfs_version
    237  1.10        pk #define lfs_size lfs_dlfs.dlfs_size
    238  1.10        pk #define lfs_ssize lfs_dlfs.dlfs_ssize
    239  1.10        pk #define lfs_dsize lfs_dlfs.dlfs_dsize
    240  1.10        pk #define lfs_bsize lfs_dlfs.dlfs_bsize
    241  1.10        pk #define lfs_fsize lfs_dlfs.dlfs_fsize
    242  1.10        pk #define lfs_frag lfs_dlfs.dlfs_frag
    243  1.10        pk #define lfs_free lfs_dlfs.dlfs_free
    244  1.10        pk #define lfs_bfree lfs_dlfs.dlfs_bfree
    245  1.10        pk #define lfs_nfiles lfs_dlfs.dlfs_nfiles
    246  1.10        pk #define lfs_avail lfs_dlfs.dlfs_avail
    247  1.10        pk #define lfs_uinodes lfs_dlfs.dlfs_uinodes
    248  1.10        pk #define lfs_idaddr lfs_dlfs.dlfs_idaddr
    249  1.10        pk #define lfs_ifile lfs_dlfs.dlfs_ifile
    250  1.10        pk #define lfs_lastseg lfs_dlfs.dlfs_lastseg
    251  1.10        pk #define lfs_nextseg lfs_dlfs.dlfs_nextseg
    252  1.10        pk #define lfs_curseg lfs_dlfs.dlfs_curseg
    253  1.10        pk #define lfs_offset lfs_dlfs.dlfs_offset
    254  1.10        pk #define lfs_lastpseg lfs_dlfs.dlfs_lastpseg
    255  1.10        pk #define lfs_tstamp lfs_dlfs.dlfs_tstamp
    256  1.10        pk #define lfs_minfree lfs_dlfs.dlfs_minfree
    257  1.10        pk #define lfs_maxfilesize lfs_dlfs.dlfs_maxfilesize
    258  1.10        pk #define lfs_dbpseg lfs_dlfs.dlfs_dbpseg
    259  1.10        pk #define lfs_inopb lfs_dlfs.dlfs_inopb
    260  1.10        pk #define lfs_ifpb lfs_dlfs.dlfs_ifpb
    261  1.10        pk #define lfs_sepb lfs_dlfs.dlfs_sepb
    262  1.10        pk #define lfs_nindir lfs_dlfs.dlfs_nindir
    263  1.10        pk #define lfs_nseg lfs_dlfs.dlfs_nseg
    264  1.10        pk #define lfs_nspf lfs_dlfs.dlfs_nspf
    265  1.10        pk #define lfs_cleansz lfs_dlfs.dlfs_cleansz
    266  1.10        pk #define lfs_segtabsz lfs_dlfs.dlfs_segtabsz
    267  1.10        pk #define lfs_segmask lfs_dlfs.dlfs_segmask
    268  1.10        pk #define lfs_segshift lfs_dlfs.dlfs_segshift
    269  1.10        pk #define lfs_bmask lfs_dlfs.dlfs_bmask
    270  1.10        pk #define lfs_bshift lfs_dlfs.dlfs_bshift
    271  1.10        pk #define lfs_ffmask lfs_dlfs.dlfs_ffmask
    272  1.10        pk #define lfs_ffshift lfs_dlfs.dlfs_ffshift
    273  1.10        pk #define lfs_fbmask lfs_dlfs.dlfs_fbmask
    274  1.10        pk #define lfs_fbshift lfs_dlfs.dlfs_fbshift
    275  1.10        pk #define lfs_fsbtodb lfs_dlfs.dlfs_fsbtodb
    276  1.10        pk #define lfs_sushift lfs_dlfs.dlfs_sushift
    277  1.10        pk #define lfs_maxsymlinklen lfs_dlfs.dlfs_maxsymlinklen
    278  1.10        pk #define lfs_sboffs lfs_dlfs.dlfs_sboffs
    279  1.10        pk #define lfs_cksum lfs_dlfs.dlfs_cksum
    280  1.11  perseant #define lfs_clean lfs_dlfs.dlfs_clean
    281  1.11  perseant #define lfs_fsmnt lfs_dlfs.dlfs_fsmnt
    282  1.11  perseant #define lfs_nclean lfs_dlfs.dlfs_nclean
    283  1.26  perseant #define lfs_dmeta lfs_dlfs.dlfs_dmeta
    284  1.26  perseant 
    285   1.1   mycroft /* These fields are set at mount time and are meaningless on disk. */
    286   1.5   mycroft 	struct segment *lfs_sp;		/* current segment being written */
    287   1.5   mycroft 	struct vnode *lfs_ivnode;	/* vnode for the ifile */
    288   1.8        is 	u_int32_t  lfs_seglock;		/* single-thread the segment writer */
    289   1.5   mycroft 	pid_t	  lfs_lockpid;		/* pid of lock holder */
    290   1.8        is 	u_int32_t lfs_iocount;		/* number of ios pending */
    291   1.8        is 	u_int32_t lfs_writer;		/* don't allow any dirops to start */
    292   1.8        is 	u_int32_t lfs_dirops;		/* count of active directory ops */
    293   1.8        is 	u_int32_t lfs_doifile;		/* Write ifile blocks on next write */
    294   1.8        is 	u_int32_t lfs_nactive;		/* Number of segments since last ckp */
    295   1.5   mycroft 	int8_t	  lfs_fmod;		/* super block modified flag */
    296   1.5   mycroft 	int8_t	  lfs_ronly;		/* mounted read-only flag */
    297  1.25  perseant #define LFS_NOTYET 0x01
    298   1.5   mycroft 	int8_t	  lfs_flags;		/* currently unused flag */
    299  1.11  perseant 	u_int16_t lfs_activesb;         /* toggle between superblocks */
    300  1.11  perseant #ifdef LFS_TRACK_IOS
    301  1.11  perseant 	daddr_t   lfs_pending[LFS_THROTTLE]; /* daddrs of pending writes */
    302  1.11  perseant #endif /* LFS_TRACK_IOS */
    303  1.11  perseant #ifdef LFS_CANNOT_ROLLFW
    304  1.11  perseant 	daddr_t   lfs_sbactive;         /* disk address of in-progress sb write */
    305  1.11  perseant #endif
    306  1.11  perseant 	struct vnode *lfs_flushvp;      /* vnode being flushed */
    307  1.21  perseant 	struct vnode *lfs_unlockvp;     /* being inactivated in lfs_segunlock */
    308  1.15  perseant 	u_int32_t lfs_diropwait;	/* # procs waiting on dirop flush */
    309  1.20  perseant 	struct lock lfs_freelock;
    310  1.25  perseant 	pid_t lfs_rfpid;		/* Process ID of roll-forward agent */
    311  1.23  perseant 	int       lfs_nadirop;		/* number of active dirop nodes */
    312   1.1   mycroft };
    313   1.1   mycroft 
    314   1.1   mycroft /*
    315   1.3       cgd  * Inode 0:	out-of-band inode number
    316   1.3       cgd  * Inode 1:	IFILE inode number
    317   1.3       cgd  * Inode 2:	root inode
    318   1.3       cgd  * Inode 3:	lost+found inode number
    319   1.1   mycroft  */
    320   1.1   mycroft #define	LFS_UNUSED_INUM	0		/* out of band inode number */
    321   1.1   mycroft #define	LFS_IFILE_INUM	1		/* IFILE inode number */
    322   1.1   mycroft #define	LOSTFOUNDINO	3		/* lost+found inode number */
    323   1.1   mycroft #define	LFS_FIRST_INUM	4		/* first free inode number */
    324   1.1   mycroft 
    325   1.1   mycroft /* Address calculations for metadata located in the inode */
    326   1.1   mycroft #define	S_INDIR(fs)	-NDADDR
    327   1.1   mycroft #define	D_INDIR(fs)	(S_INDIR(fs) - NINDIR(fs) - 1)
    328   1.1   mycroft #define	T_INDIR(fs)	(D_INDIR(fs) - NINDIR(fs) * NINDIR(fs) - 1)
    329   1.1   mycroft 
    330  1.21  perseant /* Unassigned disk addresses. */
    331   1.1   mycroft #define	UNASSIGNED	-1
    332  1.21  perseant #define UNWRITTEN       -2
    333   1.1   mycroft 
    334   1.1   mycroft /* Unused logical block number */
    335   1.1   mycroft #define LFS_UNUSED_LBN	-1
    336   1.1   mycroft 
    337   1.1   mycroft typedef struct ifile IFILE;
    338   1.1   mycroft struct ifile {
    339   1.3       cgd 	u_int32_t if_version;		/* inode version number */
    340   1.1   mycroft #define	LFS_UNUSED_DADDR	0	/* out-of-band daddr */
    341   1.9      fvdl 	ufs_daddr_t if_daddr;		/* inode disk address */
    342   1.3       cgd 	ino_t	  if_nextfree;		/* next-unallocated inode */
    343  1.11  perseant #ifdef LFS_ATIME_IFILE
    344  1.11  perseant 	struct timespec if_atime;	/* Last access time */
    345  1.11  perseant #endif
    346   1.1   mycroft };
    347   1.1   mycroft 
    348   1.1   mycroft /*
    349   1.1   mycroft  * Cleaner information structure.  This resides in the ifile and is used
    350   1.1   mycroft  * to pass information between the cleaner and the kernel.
    351   1.1   mycroft  */
    352   1.1   mycroft typedef struct _cleanerinfo {
    353   1.3       cgd 	u_int32_t clean;		/* K: number of clean segments */
    354   1.3       cgd 	u_int32_t dirty;		/* K: number of dirty segments */
    355   1.1   mycroft } CLEANERINFO;
    356   1.1   mycroft 
    357   1.1   mycroft #define	CLEANSIZE_SU(fs)						\
    358   1.1   mycroft 	((sizeof(CLEANERINFO) + (fs)->lfs_bsize - 1) >> (fs)->lfs_bshift)
    359   1.1   mycroft 
    360   1.1   mycroft /*
    361   1.1   mycroft  * All summary blocks are the same size, so we can always read a summary
    362   1.1   mycroft  * block easily from a segment.
    363   1.1   mycroft  */
    364   1.1   mycroft #define	LFS_SUMMARY_SIZE	512
    365   1.1   mycroft 
    366   1.1   mycroft /* On-disk segment summary information */
    367   1.1   mycroft typedef struct segsum SEGSUM;
    368   1.1   mycroft struct segsum {
    369   1.3       cgd 	u_int32_t ss_sumsum;		/* check sum of summary block */
    370   1.3       cgd 	u_int32_t ss_datasum;		/* check sum of data */
    371   1.9      fvdl 	u_int32_t ss_magic;		/* segment summary magic number */
    372   1.9      fvdl #define SS_MAGIC	0x061561
    373   1.9      fvdl 	ufs_daddr_t ss_next;		/* next segment */
    374   1.3       cgd 	u_int32_t ss_create;		/* creation time stamp */
    375   1.3       cgd 	u_int16_t ss_nfinfo;		/* number of file info structures */
    376   1.3       cgd 	u_int16_t ss_ninos;		/* number of inodes in summary */
    377   1.5   mycroft 
    378   1.1   mycroft #define	SS_DIROP	0x01		/* segment begins a dirop */
    379   1.1   mycroft #define	SS_CONT		0x02		/* more partials to finish this write*/
    380   1.3       cgd 	u_int16_t ss_flags;		/* used for directory operations */
    381   1.3       cgd 	u_int16_t ss_pad;		/* extra space */
    382   1.1   mycroft 	/* FINFO's and inode daddr's... */
    383   1.1   mycroft };
    384   1.1   mycroft 
    385   1.1   mycroft /* NINDIR is the number of indirects in a file system block. */
    386   1.1   mycroft #define	NINDIR(fs)	((fs)->lfs_nindir)
    387   1.1   mycroft 
    388   1.1   mycroft /* INOPB is the number of inodes in a secondary storage block. */
    389   1.1   mycroft #define	INOPB(fs)	((fs)->lfs_inopb)
    390   1.1   mycroft 
    391   1.9      fvdl #define	blksize(fs, ip, lbn) \
    392   1.9      fvdl 	(((lbn) >= NDADDR || (ip)->i_ffs_size >= ((lbn) + 1) << (fs)->lfs_bshift) \
    393   1.9      fvdl 	    ? (fs)->lfs_bsize \
    394   1.9      fvdl 	    : (fragroundup(fs, blkoff(fs, (ip)->i_ffs_size))))
    395   1.9      fvdl #define	blkoff(fs, loc)		((int)(loc) & (fs)->lfs_bmask)
    396   1.9      fvdl #define fragoff(fs, loc)    /* calculates (loc % fs->lfs_fsize) */ \
    397   1.9      fvdl     ((int)((loc) & (fs)->lfs_ffmask))
    398   1.1   mycroft #define	fsbtodb(fs, b)		((b) << (fs)->lfs_fsbtodb)
    399   1.1   mycroft #define	dbtofsb(fs, b)		((b) >> (fs)->lfs_fsbtodb)
    400   1.9      fvdl #define fragstodb(fs, b)	((b) << ((fs)->lfs_fsbtodb - (fs)->lfs_fbshift))
    401   1.9      fvdl #define dbtofrags(fs, b)	((b) >> ((fs)->lfs_fsbtodb - (fs)->lfs_fbshift))
    402   1.1   mycroft #define	lblkno(fs, loc)		((loc) >> (fs)->lfs_bshift)
    403   1.1   mycroft #define	lblktosize(fs, blk)	((blk) << (fs)->lfs_bshift)
    404   1.9      fvdl #define numfrags(fs, loc)	/* calculates (loc / fs->lfs_fsize) */	\
    405   1.9      fvdl 	((loc) >> (fs)->lfs_ffshift)
    406   1.9      fvdl #define blkroundup(fs, size)	/* calculates roundup(size, fs->lfs_bsize) */ \
    407   1.9      fvdl 	((int)(((size) + (fs)->lfs_bmask) & (~(fs)->lfs_bmask)))
    408   1.9      fvdl #define fragroundup(fs, size)	/* calculates roundup(size, fs->lfs_fsize) */ \
    409   1.9      fvdl 	((int)(((size) + (fs)->lfs_ffmask) & (~(fs)->lfs_ffmask)))
    410   1.9      fvdl #define fragstoblks(fs, frags)	/* calculates (frags / fs->lfs_frag) */ \
    411   1.9      fvdl 	((frags) >> (fs)->lfs_fbshift)
    412   1.9      fvdl #define blkstofrags(fs, blks)	/* calculates (blks * fs->lfs_frag) */ \
    413   1.9      fvdl 	((blks) << (fs)->lfs_fbshift)
    414   1.9      fvdl #define fragnum(fs, fsb)	/* calculates (fsb % fs->lfs_frag) */ \
    415   1.9      fvdl 	((fsb) & ((fs)->lfs_frag - 1))
    416   1.9      fvdl #define blknum(fs, fsb)		/* calculates rounddown(fsb, fs->lfs_frag) */ \
    417   1.9      fvdl 	((fsb) &~ ((fs)->lfs_frag - 1))
    418   1.9      fvdl #define dblksize(fs, dip, lbn) \
    419   1.9      fvdl 	(((lbn) >= NDADDR || (dip)->di_size >= ((lbn) + 1) << (fs)->lfs_bshift)\
    420   1.9      fvdl 	    ? (fs)->lfs_bsize \
    421   1.9      fvdl 	    : (fragroundup(fs, blkoff(fs, (dip)->di_size))))
    422   1.1   mycroft #define	datosn(fs, daddr)	/* disk address to segment number */	\
    423   1.1   mycroft 	(((daddr) - (fs)->lfs_sboffs[0]) / fsbtodb((fs), (fs)->lfs_ssize))
    424   1.1   mycroft #define sntoda(fs, sn) 		/* segment number to disk address */	\
    425   1.9      fvdl 	((ufs_daddr_t)((sn) * ((fs)->lfs_ssize << (fs)->lfs_fsbtodb) +	\
    426   1.1   mycroft 	    (fs)->lfs_sboffs[0]))
    427   1.1   mycroft 
    428   1.1   mycroft /* Read in the block with the cleaner info from the ifile. */
    429   1.1   mycroft #define LFS_CLEANERINFO(CP, F, BP) {					\
    430   1.1   mycroft 	VTOI((F)->lfs_ivnode)->i_flag |= IN_ACCESS;			\
    431   1.1   mycroft 	if (bread((F)->lfs_ivnode,					\
    432   1.9      fvdl 	    (ufs_daddr_t)0, (F)->lfs_bsize, NOCRED, &(BP)))		\
    433   1.1   mycroft 		panic("lfs: ifile read");				\
    434   1.1   mycroft 	(CP) = (CLEANERINFO *)(BP)->b_data;				\
    435   1.1   mycroft }
    436   1.1   mycroft 
    437   1.1   mycroft /* Read in the block with a specific inode from the ifile. */
    438   1.1   mycroft #define	LFS_IENTRY(IP, F, IN, BP) {					\
    439   1.1   mycroft 	int _e;								\
    440   1.1   mycroft 	VTOI((F)->lfs_ivnode)->i_flag |= IN_ACCESS;			\
    441   1.7  christos 	if ((_e = bread((F)->lfs_ivnode,				\
    442   1.1   mycroft 	    (IN) / (F)->lfs_ifpb + (F)->lfs_cleansz + (F)->lfs_segtabsz,\
    443   1.7  christos 	    (F)->lfs_bsize, NOCRED, &(BP))) != 0)			\
    444   1.1   mycroft 		panic("lfs: ifile read %d", _e);			\
    445   1.1   mycroft 	(IP) = (IFILE *)(BP)->b_data + (IN) % (F)->lfs_ifpb;		\
    446   1.1   mycroft }
    447   1.1   mycroft 
    448   1.1   mycroft /* Read in the block with a specific segment usage entry from the ifile. */
    449   1.1   mycroft #define	LFS_SEGENTRY(SP, F, IN, BP) {					\
    450   1.1   mycroft 	int _e;								\
    451   1.1   mycroft 	VTOI((F)->lfs_ivnode)->i_flag |= IN_ACCESS;			\
    452   1.7  christos 	if ((_e = bread((F)->lfs_ivnode,				\
    453   1.1   mycroft 	    ((IN) >> (F)->lfs_sushift) + (F)->lfs_cleansz,		\
    454   1.7  christos 	    (F)->lfs_bsize, NOCRED, &(BP))) != 0)			\
    455   1.1   mycroft 		panic("lfs: ifile read: %d", _e);			\
    456   1.7  christos 	(SP) = (SEGUSE *)(BP)->b_data + ((IN) & ((F)->lfs_sepb - 1));	\
    457   1.1   mycroft }
    458   1.1   mycroft 
    459   1.1   mycroft /* Determine if a buffer belongs to the ifile */
    460   1.1   mycroft #define IS_IFILE(bp)	(VTOI(bp->b_vp)->i_number == LFS_IFILE_INUM)
    461   1.1   mycroft 
    462   1.1   mycroft /*
    463   1.1   mycroft  * Structures used by lfs_bmapv and lfs_markv to communicate information
    464   1.1   mycroft  * about inodes and data blocks.
    465   1.1   mycroft  */
    466   1.1   mycroft typedef struct block_info {
    467   1.1   mycroft 	ino_t	bi_inode;		/* inode # */
    468   1.9      fvdl 	ufs_daddr_t bi_lbn;		/* logical block w/in file */
    469   1.9      fvdl 	ufs_daddr_t bi_daddr;		/* disk address of block */
    470   1.1   mycroft 	time_t	bi_segcreate;		/* origin segment create time */
    471   1.1   mycroft 	int	bi_version;		/* file version number */
    472   1.1   mycroft 	void	*bi_bp;			/* data buffer */
    473   1.9      fvdl 	int     bi_size;		/* size of the block (if fragment) */
    474   1.1   mycroft } BLOCK_INFO;
    475   1.1   mycroft 
    476   1.1   mycroft /* In-memory description of a segment about to be written. */
    477   1.1   mycroft struct segment {
    478   1.5   mycroft 	struct lfs	 *fs;		/* file system pointer */
    479   1.1   mycroft 	struct buf	**bpp;		/* pointer to buffer array */
    480   1.1   mycroft 	struct buf	**cbpp;		/* pointer to next available bp */
    481   1.1   mycroft 	struct buf	**start_bpp;	/* pointer to first bp in this set */
    482   1.5   mycroft 	struct buf	 *ibp;		/* buffer pointer to inode page */
    483  1.16  perseant 	struct dinode    *idp;          /* pointer to ifile dinode */
    484   1.5   mycroft 	struct finfo	 *fip;		/* current fileinfo pointer */
    485   1.5   mycroft 	struct vnode	 *vp;		/* vnode being gathered */
    486   1.3       cgd 	void	 *segsum;		/* segment summary info */
    487   1.3       cgd 	u_int32_t ninodes;		/* number of inodes in this segment */
    488   1.3       cgd 	u_int32_t seg_bytes_left;	/* bytes left in segment */
    489   1.3       cgd 	u_int32_t sum_bytes_left;	/* bytes left in summary block */
    490   1.3       cgd 	u_int32_t seg_number;		/* number of this segment */
    491   1.9      fvdl 	ufs_daddr_t *start_lbp;		/* beginning lbn for this set */
    492   1.5   mycroft 
    493   1.1   mycroft #define	SEGM_CKP	0x01		/* doing a checkpoint */
    494   1.1   mycroft #define	SEGM_CLEAN	0x02		/* cleaner call; don't sort */
    495   1.1   mycroft #define	SEGM_SYNC	0x04		/* wait for segment */
    496  1.25  perseant #define	SEGM_PROT	0x08		/* don't inactivate at segunlock */
    497   1.5   mycroft 	u_int16_t seg_flags;		/* run-time flags for this segment */
    498   1.1   mycroft };
    499   1.1   mycroft 
    500  1.26  perseant /*
    501  1.26  perseant  * Mecros for determining free space on the disk, with the variable metadata
    502  1.26  perseant  * of segment summaries and inode blocks taken into account.
    503  1.26  perseant  */
    504  1.26  perseant /* Estimate number of clean blocks not available for writing */
    505  1.26  perseant #define LFS_EST_CMETA(F) ((u_int32_t)(((F)->lfs_dmeta *                     \
    506  1.26  perseant 				       (u_int64_t)(F)->lfs_nclean) /        \
    507  1.26  perseant 				      ((F)->lfs_nseg - (F)->lfs_nclean)))
    508  1.26  perseant 
    509  1.26  perseant /* Estimate total size of the disk not including metadata */
    510  1.26  perseant #define LFS_EST_NONMETA(F) ((F)->lfs_dsize - fsbtodb((F), MIN_FREE_SEGS *   \
    511  1.26  perseant 						     (F)->lfs_ssize) -      \
    512  1.26  perseant 			    (F)->lfs_dmeta - LFS_EST_CMETA(F))
    513  1.26  perseant 
    514  1.26  perseant /* Estimate number of blocks actually available for writing */
    515  1.26  perseant #define LFS_EST_BFREE(F) ((F)->lfs_bfree - LFS_EST_CMETA(F))
    516  1.26  perseant 
    517  1.26  perseant /* Amount of non-meta space not available to mortal man */
    518  1.26  perseant #define LFS_EST_RSVD(F) ((u_int32_t)(((LFS_EST_NONMETA(F) *         \
    519  1.26  perseant 				       (u_int64_t)(F)->lfs_minfree)) / 100))
    520  1.26  perseant 
    521  1.26  perseant /* Can credential C write BB blocks */
    522   1.1   mycroft #define ISSPACE(F, BB, C)						\
    523  1.26  perseant 	((((C) == NOCRED || (C)->cr_uid == 0) &&			\
    524  1.26  perseant           LFS_EST_BFREE(F) >= (BB)) ||					\
    525  1.26  perseant 	 ((C)->cr_uid != 0 && IS_FREESPACE(F, BB)))
    526   1.1   mycroft 
    527  1.26  perseant /* Can an ordinary user write BB blocks */
    528   1.1   mycroft #define IS_FREESPACE(F, BB)						\
    529  1.26  perseant           (LFS_EST_BFREE(F) >= (BB) + LFS_EST_RSVD(F))
    530   1.1   mycroft 
    531   1.1   mycroft /* Statistics Counters */
    532   1.1   mycroft struct lfs_stats {
    533   1.5   mycroft 	u_int	segsused;
    534   1.5   mycroft 	u_int	psegwrites;
    535   1.5   mycroft 	u_int	psyncwrites;
    536   1.5   mycroft 	u_int	pcleanwrites;
    537   1.5   mycroft 	u_int	blocktot;
    538   1.5   mycroft 	u_int	cleanblocks;
    539   1.5   mycroft 	u_int	ncheckpoints;
    540   1.5   mycroft 	u_int	nwrites;
    541   1.5   mycroft 	u_int	nsync_writes;
    542   1.5   mycroft 	u_int	wait_exceeded;
    543   1.5   mycroft 	u_int	write_exceeded;
    544   1.5   mycroft 	u_int	flush_invoked;
    545  1.11  perseant 	u_int	vflush_invoked;
    546   1.1   mycroft };
    547   1.1   mycroft extern struct lfs_stats lfs_stats;
    548