BSD 4_4_Lite1 release
[unix-history] / usr / src / sys / ufs / ffs / fs.h
index 722cd5c..bef052f 100644 (file)
@@ -30,7 +30,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- *     @(#)fs.h        8.1 (Berkeley) 6/11/93
+ *     @(#)fs.h        8.7 (Berkeley) 4/19/94
  */
 
 /*
  */
 
 /*
 #define MAXMNTLEN 512
 #define MAXCSBUFS 32
 
 #define MAXMNTLEN 512
 #define MAXCSBUFS 32
 
+/*
+ * A summary of contiguous blocks of various sizes is maintained
+ * in each cylinder group. Normally this is set by the initial
+ * value of fs_maxcontig. To conserve space, a maximum summary size
+ * is set by FS_MAXCONTIG.
+ */
+#define FS_MAXCONTIG   16
+
+/*
+ * MINFREE gives the minimum acceptable percentage of file system
+ * blocks which may be free. If the freelist drops below this level
+ * only the superuser may continue to allocate blocks. This may
+ * be set to 0 if no reserve of free blocks is deemed necessary,
+ * however throughput drops by fifty percent if the file system
+ * is run at between 95% and 100% full; thus the minimum default
+ * value of fs_minfree is 5%. However, to get good clustering
+ * performance, 10% is a better choice. hence we use 10% as our
+ * default value. With 10% free space, fragmentation is not a
+ * problem, so we choose to optimize for time.
+ */
+#define MINFREE                5
+#define DEFAULTOPT     FS_OPTTIME
+
 /*
  * Per cylinder group information; summarized in blocks allocated
  * from first cylinder group data blocks.  These blocks have to be
 /*
  * Per cylinder group information; summarized in blocks allocated
  * from first cylinder group data blocks.  These blocks have to be
@@ -196,7 +219,8 @@ struct fs {
        struct  csum *fs_csp[MAXCSBUFS];/* list of fs_cs info buffers */
        long    fs_cpc;                 /* cyl per cycle in postbl */
        short   fs_opostbl[16][8];      /* old rotation block list head */
        struct  csum *fs_csp[MAXCSBUFS];/* list of fs_cs info buffers */
        long    fs_cpc;                 /* cyl per cycle in postbl */
        short   fs_opostbl[16][8];      /* old rotation block list head */
-       long    fs_sparecon[51];        /* reserved for future constants */
+       long    fs_sparecon[50];        /* reserved for future constants */
+       long    fs_contigsumsize;       /* size of cluster summary array */ 
        long    fs_maxsymlinklen;       /* max length of an internal symlink */
        long    fs_inodefmt;            /* format of on-disk inodes */
        u_quad_t fs_maxfilesize;        /* maximum representable file size */
        long    fs_maxsymlinklen;       /* max length of an internal symlink */
        long    fs_inodefmt;            /* format of on-disk inodes */
        u_quad_t fs_maxfilesize;        /* maximum representable file size */
@@ -204,7 +228,7 @@ struct fs {
        quad_t  fs_qfmask;              /* ~fs_fmask - for use with quad size */
        long    fs_state;               /* validate fs_clean field */
        long    fs_postblformat;        /* format of positional layout tables */
        quad_t  fs_qfmask;              /* ~fs_fmask - for use with quad size */
        long    fs_state;               /* validate fs_clean field */
        long    fs_postblformat;        /* format of positional layout tables */
-       long    fs_nrpos;               /* number of rotaional positions */
+       long    fs_nrpos;               /* number of rotational positions */
        long    fs_postbloff;           /* (short) rotation block list head */
        long    fs_rotbloff;            /* (u_char) blocks for each rotation */
        long    fs_magic;               /* magic number */
        long    fs_postbloff;           /* (short) rotation block list head */
        long    fs_rotbloff;            /* (u_char) blocks for each rotation */
        long    fs_magic;               /* magic number */
@@ -241,6 +265,22 @@ struct fs {
     ? ((fs)->fs_space) \
     : ((u_char *)((char *)(fs) + (fs)->fs_rotbloff)))
 
     ? ((fs)->fs_space) \
     : ((u_char *)((char *)(fs) + (fs)->fs_rotbloff)))
 
+/*
+ * The size of a cylinder group is calculated by CGSIZE. The maximum size
+ * is limited by the fact that cylinder groups are at most one block.
+ * Its size is derived from the size of the maps maintained in the 
+ * cylinder group and the (struct cg) size.
+ */
+#define CGSIZE(fs) \
+    /* base cg */      (sizeof(struct cg) + sizeof(long) + \
+    /* blktot size */  (fs)->fs_cpg * sizeof(long) + \
+    /* blks size */    (fs)->fs_cpg * (fs)->fs_nrpos * sizeof(short) + \
+    /* inode map */    howmany((fs)->fs_ipg, NBBY) + \
+    /* block map */    howmany((fs)->fs_cpg * (fs)->fs_spc / NSPF(fs), NBBY) +\
+    /* if present */   ((fs)->fs_contigsumsize <= 0 ? 0 : \
+    /* cluster sum */  (fs)->fs_contigsumsize * sizeof(long) + \
+    /* cluster map */  howmany((fs)->fs_cpg * (fs)->fs_spc / NSPB(fs), NBBY)))
+
 /*
  * Convert cylinder group to base address of its global summary info.
  *
 /*
  * Convert cylinder group to base address of its global summary info.
  *
@@ -271,7 +311,10 @@ struct     cg {
        long    cg_iusedoff;            /* (char) used inode map */
        long    cg_freeoff;             /* (u_char) free block map */
        long    cg_nextfreeoff;         /* (u_char) next available space */
        long    cg_iusedoff;            /* (char) used inode map */
        long    cg_freeoff;             /* (u_char) free block map */
        long    cg_nextfreeoff;         /* (u_char) next available space */
-       long    cg_sparecon[16];        /* reserved for future use */
+       long    cg_clustersumoff;       /* (long) counts of avail clusters */
+       long    cg_clusteroff;          /* (char) free cluster map */
+       long    cg_nclusterblks;        /* number of clusters this cg */
+       long    cg_sparecon[13];        /* reserved for future use */
        u_char  cg_space[1];            /* space for cylinder group maps */
 /* actually longer */
 };
        u_char  cg_space[1];            /* space for cylinder group maps */
 /* actually longer */
 };
@@ -296,6 +339,10 @@ struct     cg {
     : ((u_char *)((char *)(cgp) + (cgp)->cg_freeoff)))
 #define cg_chkmagic(cgp) \
     ((cgp)->cg_magic == CG_MAGIC || ((struct ocg *)(cgp))->cg_magic == CG_MAGIC)
     : ((u_char *)((char *)(cgp) + (cgp)->cg_freeoff)))
 #define cg_chkmagic(cgp) \
     ((cgp)->cg_magic == CG_MAGIC || ((struct ocg *)(cgp))->cg_magic == CG_MAGIC)
+#define cg_clustersfree(cgp) \
+    ((u_char *)((char *)(cgp) + (cgp)->cg_clusteroff))
+#define cg_clustersum(cgp) \
+    ((long *)((char *)(cgp) + (cgp)->cg_clustersumoff))
 
 /*
  * The following structure is defined
 
 /*
  * The following structure is defined
@@ -334,12 +381,12 @@ struct    ocg {
  * They calc file system addresses of cylinder group data structures.
  */
 #define        cgbase(fs, c)   ((daddr_t)((fs)->fs_fpg * (c)))
  * They calc file system addresses of cylinder group data structures.
  */
 #define        cgbase(fs, c)   ((daddr_t)((fs)->fs_fpg * (c)))
-#define cgstart(fs, c) \
-       (cgbase(fs, c) + (fs)->fs_cgoffset * ((c) & ~((fs)->fs_cgmask)))
+#define        cgdmin(fs, c)   (cgstart(fs, c) + (fs)->fs_dblkno)      /* 1st data */
+#define        cgimin(fs, c)   (cgstart(fs, c) + (fs)->fs_iblkno)      /* inode blk */
 #define        cgsblock(fs, c) (cgstart(fs, c) + (fs)->fs_sblkno)      /* super blk */
 #define        cgtod(fs, c)    (cgstart(fs, c) + (fs)->fs_cblkno)      /* cg block */
 #define        cgsblock(fs, c) (cgstart(fs, c) + (fs)->fs_sblkno)      /* super blk */
 #define        cgtod(fs, c)    (cgstart(fs, c) + (fs)->fs_cblkno)      /* cg block */
-#define        cgimin(fs, c)   (cgstart(fs, c) + (fs)->fs_iblkno)      /* inode blk */
-#define        cgdmin(fs, c)   (cgstart(fs, c) + (fs)->fs_dblkno)      /* 1st data */
+#define cgstart(fs, c)                                                 \
+       (cgbase(fs, c) + (fs)->fs_cgoffset * ((c) & ~((fs)->fs_cgmask)))
 
 /*
  * Macros for handling inode numbers:
 
 /*
  * Macros for handling inode numbers:
@@ -347,11 +394,11 @@ struct    ocg {
  *     inode number to cylinder group number.
  *     inode number to file system block address.
  */
  *     inode number to cylinder group number.
  *     inode number to file system block address.
  */
-#define        itoo(fs, x)     ((x) % INOPB(fs))
-#define        itog(fs, x)     ((x) / (fs)->fs_ipg)
-#define        itod(fs, x) \
-       ((daddr_t)(cgimin(fs, itog(fs, x)) + \
-       (blkstofrags((fs), (((x) % (fs)->fs_ipg) / INOPB(fs))))))
+#define        ino_to_cg(fs, x)        ((x) / (fs)->fs_ipg)
+#define        ino_to_fsba(fs, x)                                              \
+       ((daddr_t)(cgimin(fs, ino_to_cg(fs, x)) +                       \
+           (blkstofrags((fs), (((x) % (fs)->fs_ipg) / INOPB(fs))))))
+#define        ino_to_fsbo(fs, x)      ((x) % INOPB(fs))
 
 /*
  * Give cylinder group number for a file system block.
 
 /*
  * Give cylinder group number for a file system block.