Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sbin/newfs Ensure the area between the end of the main super...



details:   https://anonhg.NetBSD.org/src/rev/ec77d57faa03
branches:  trunk
changeset: 551286:ec77d57faa03
user:      dsl <dsl%NetBSD.org@localhost>
date:      Wed Sep 03 19:29:12 2003 +0000

description:
Ensure the area between the end of the main superblock and the start of the
first alternate superblock is zerod.
Removes any possibility of any programs using a trully out of date
alternate superblock if a filesystem is remade with a larger block size.

diffstat:

 sbin/newfs/extern.h |   4 +---
 sbin/newfs/mkfs.c   |  24 +++++++++++++-----------
 sbin/newfs/newfs.c  |  14 ++++----------
 3 files changed, 18 insertions(+), 24 deletions(-)

diffs (142 lines):

diff -r a5b186294779 -r ec77d57faa03 sbin/newfs/extern.h
--- a/sbin/newfs/extern.h       Wed Sep 03 18:56:37 2003 +0000
+++ b/sbin/newfs/extern.h       Wed Sep 03 19:29:12 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: extern.h,v 1.9 2003/04/02 10:39:29 fvdl Exp $  */
+/*     $NetBSD: extern.h,v 1.10 2003/09/03 19:29:12 dsl Exp $  */
 
 /*
  * Copyright (c) 1997 Christos Zoulas.  All rights reserved.
@@ -51,8 +51,6 @@
 extern int     maxbpg;         /* maximum blocks per file in a cyl group */
 extern int     maxblkspercg;
 extern int     nrpos;          /* # of distinguished rotational positions */
-extern int     bbsize;         /* boot block size */
-extern int     sbsize;         /* superblock size */
 extern int     avgfilesize;    /* expected average file size */
 extern int     avgfpdir;       /* expected number of files per directory */
 extern u_long  memleft;        /* virtual memory available */
diff -r a5b186294779 -r ec77d57faa03 sbin/newfs/mkfs.c
--- a/sbin/newfs/mkfs.c Wed Sep 03 18:56:37 2003 +0000
+++ b/sbin/newfs/mkfs.c Wed Sep 03 19:29:12 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mkfs.c,v 1.75 2003/09/03 17:08:58 dsl Exp $    */
+/*     $NetBSD: mkfs.c,v 1.76 2003/09/03 19:29:13 dsl Exp $    */
 
 /*
  * Copyright (c) 1980, 1989, 1993
@@ -73,7 +73,7 @@
 #if 0
 static char sccsid[] = "@(#)mkfs.c     8.11 (Berkeley) 5/3/95";
 #else
-__RCSID("$NetBSD: mkfs.c,v 1.75 2003/09/03 17:08:58 dsl Exp $");
+__RCSID("$NetBSD: mkfs.c,v 1.76 2003/09/03 19:29:13 dsl Exp $");
 #endif
 #endif /* not lint */
 
@@ -154,8 +154,6 @@
 char *iobuf;
 int iobufsize;
 
-char writebuf[MAXBSIZE];
-
 int    fsi, fso;
 
 void
@@ -563,10 +561,9 @@
         * Make a copy of the superblock into the buffer that we will be
         * writing out in each cylinder group.
         */
-       memcpy(writebuf, &sblock, sbsize);
+       memcpy(iobuf, &sblock, sizeof sblock);
        if (needswap)
-               ffs_sb_swap(&sblock, (struct fs*)writebuf);
-       memcpy(iobuf, writebuf, SBLOCKSIZE);
+               ffs_sb_swap(&sblock, (struct fs *)iobuf);
 
        if (!mfs)
                printf("super-block backups (for fsck -b #) at:");
@@ -587,7 +584,6 @@
 
        /*
         * Now construct the initial file system,
-        * then write out the super-block.
         */
        if (fsinit(&tv, mfsmode, mfsuid, mfsgid) == 0 && mfs)
                errx(1, "Error making filesystem");
@@ -598,10 +594,16 @@
                sblock.fs_old_cstotal.cs_nifree = sblock.fs_cstotal.cs_nifree;
                sblock.fs_old_cstotal.cs_nffree = sblock.fs_cstotal.cs_nffree;
        }
-        memcpy(writebuf, &sblock, sbsize);
+       /*
+        * Write out the super-block and zeros until the first cg info
+        */
+       memset(iobuf, 0, iobufsize);
+        memcpy(iobuf, &sblock, sizeof sblock);
        if (needswap)
-               ffs_sb_swap(&sblock, (struct fs*)writebuf);
-        wtfs(sblock.fs_sblockloc / sectorsize, sbsize, writebuf);
+               ffs_sb_swap(&sblock, (struct fs *)iobuf);
+        wtfs(sblock.fs_sblockloc / sectorsize,
+           cgsblock(&sblock, 0) * sblock.fs_fsize - sblock.fs_sblockloc,
+           iobuf);
 
        /* Write out first and last cylinder summary sectors */
        if (needswap)
diff -r a5b186294779 -r ec77d57faa03 sbin/newfs/newfs.c
--- a/sbin/newfs/newfs.c        Wed Sep 03 18:56:37 2003 +0000
+++ b/sbin/newfs/newfs.c        Wed Sep 03 19:29:12 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: newfs.c,v 1.68 2003/08/21 15:47:26 dsl Exp $   */
+/*     $NetBSD: newfs.c,v 1.69 2003/09/03 19:29:14 dsl Exp $   */
 
 /*
  * Copyright (c) 1983, 1989, 1993, 1994
@@ -78,7 +78,7 @@
 #if 0
 static char sccsid[] = "@(#)newfs.c    8.13 (Berkeley) 5/1/95";
 #else
-__RCSID("$NetBSD: newfs.c,v 1.68 2003/08/21 15:47:26 dsl Exp $");
+__RCSID("$NetBSD: newfs.c,v 1.69 2003/09/03 19:29:14 dsl Exp $");
 #endif
 #endif /* not lint */
 
@@ -200,8 +200,6 @@
 int    maxbpg;                 /* maximum blocks per file in a cyl group */
 int    avgfilesize = AVFILESIZ;/* expected average file size */
 int    avgfpdir = AFPDIR;      /* expected number of files per directory */
-int    bbsize = BBSIZE;        /* boot block size */
-int    sbsize = SBLOCKSIZE;    /* superblock size */
 int    mntflags = MNT_ASYNC;   /* flags to be passed to mount */
 u_long memleft;                /* virtual memory available */
 caddr_t        membase;                /* start address of memory based filesystem */
@@ -433,7 +431,7 @@
                if (Fflag && !Nflag) {  /* creating image in a regular file */
                        if (fssize == 0)
                                errx(1, "need to specify size when using -F");
-                       fso = open(special, O_RDWR | O_CREAT | O_TRUNC, 0777);
+                       fso = open(special, O_RDWR | O_CREAT, 0777);
                        if (fso == -1)
                                err(1, "can't open file %s", special);
                        if ((fsi = dup(fso)) == -1)
@@ -443,7 +441,7 @@
                                err(1, "can't resize %s to %lld",
                                    special, (long long)fssize);
 
-                       if (Zflag) {    /* pre-zero the file */
+                       if (Zflag) {    /* pre-zero (and de-sparce) the file */
                                char    *buf;
                                int     bufsize, i;
                                off_t   bufrem;
@@ -620,10 +618,6 @@
                else
                        maxbpg = MAXBLKPG_UFS2(bsize);
        }
-#ifdef notdef /* label may be 0 if faked up by kernel */
-       bbsize = lp->d_bbsize;
-       sbsize = lp->d_sbsize;
-#endif
        oldpartition = *pp;
        mkfs(pp, special, fsi, fso, mfsmode, mfsuid, mfsgid);
        if (!Nflag && memcmp(pp, &oldpartition, sizeof(oldpartition)) && !Fflag)



Home | Main Index | Thread Index | Old Index