Date: Tue, 11 Nov 2003 13:52:05 -0800 From: Wes Peters <wes@softweyr.com> To: arch@freebsd.org Cc: Kirk McKusick <mckusick@beastie.mckusick.com> Subject: New newfs vs. half-baked disks patch Message-ID: <200311111339.30853.wes@softweyr.com>
next in thread | raw e-mail | index | archive | help
--Boundary-00=_FoVs/1khD/qbQm2 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline I re-did the patch using a differing magic number, as suggested. This approach works quite nicely. The patch is smaller and does more with no kernel mods. This patch does more because a filesystem partially created with newfs now has an invalid magic number on the first superblock. This means older kernels will not mount the filesystem and older fsck will at least warn about not finding the first superblock. This patch includes a change to fsck so it will recognize an incomplete newfs filesystem, exiting with a unique status (11) and issuing the message "This volume is incomplete, run newfs again." The patch to newfs includes the -E flag to generate error conditions; these changes will be committed separately. Barring lack of objections, I'd like to commit this tomorrow. Thanks to everyone who commented on the first round. This was my first foray into filesystem programming since my Minix days and you were all more than generous. -- "Where am I, and what am I doing in this handbasket?" Wes Peters wes@softweyr.com --Boundary-00=_FoVs/1khD/qbQm2 Content-Type: text/x-diff; charset="us-ascii"; name="newfs.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="newfs.patch" --- sys/ufs/ffs/fs.h.orig Mon Nov 10 17:13:43 2003 +++ sys/ufs/ffs/fs.h Mon Nov 10 17:14:57 2003 @@ -361,6 +361,7 @@ */ #define FS_UFS1_MAGIC 0x011954 /* UFS1 fast filesystem magic number */ #define FS_UFS2_MAGIC 0x19540119 /* UFS2 fast filesystem magic number */ +#define FS_BAD2_MAGIG 0x19960408 /* UFS2 incomplete newfs magic number */ #define FS_OKAY 0x7c269d38 /* superblock checksum */ #define FS_42INODEFMT -1 /* 4.2BSD inode format */ #define FS_44INODEFMT 2 /* 4.4BSD inode format */ --- sbin/newfs/mkfs.c.orig Tue Oct 14 13:53:55 2003 +++ sbin/newfs/mkfs.c Mon Nov 10 17:31:35 2003 @@ -258,7 +258,7 @@ sblock.fs_old_postblformat = 1; sblock.fs_old_nrpos = 1; } else { - sblock.fs_magic = FS_UFS2_MAGIC; + sblock.fs_magic = FS_BAD2_MAGIC; sblock.fs_sblockloc = SBLOCK_UFS2; sblock.fs_nindir = sblock.fs_bsize / sizeof(ufs2_daddr_t); sblock.fs_inopb = sblock.fs_bsize / sizeof(struct ufs2_dinode); @@ -448,6 +448,16 @@ chdummy, SBLOCKSIZE); } } + if (!Nflag) + sbwrite(&disk, 0); + if (Eflag == 1) { + printf("** Exiting on Eflag 1\n"); + exit(0); + } + if (Eflag == 2) + printf("** Leaving BAD MAGIC on Eflag 2\n"); + else + sblock.fs_magic = FS_UFS2_MAGIC; /* * Now build the cylinders group blocks and @@ -502,6 +512,10 @@ sblock.fs_old_cstotal.cs_nbfree = sblock.fs_cstotal.cs_nbfree; sblock.fs_old_cstotal.cs_nifree = sblock.fs_cstotal.cs_nifree; sblock.fs_old_cstotal.cs_nffree = sblock.fs_cstotal.cs_nffree; + } + if (Eflag == 3) { + printf("** Exiting on Eflag 3\n"); + exit(0); } if (!Nflag) sbwrite(&disk, 0); --- sbin/newfs/newfs.h.orig Tue Nov 4 16:27:31 2003 +++ sbin/newfs/newfs.h Mon Nov 10 17:26:13 2003 @@ -52,6 +52,7 @@ extern int Oflag; /* build UFS1 format file system */ extern int Rflag; /* regression test */ extern int Uflag; /* enable soft updates for file system */ +extern int Eflag; /* exit as if error, for testing */ extern quad_t fssize; /* file system size */ extern int sectorsize; /* bytes/sector */ extern int realsectorsize; /* bytes/sector in hardware*/ --- sbin/newfs/newfs.c.orig Tue Nov 4 16:20:42 2003 +++ sbin/newfs/newfs.c Mon Nov 10 17:26:24 2003 @@ -119,6 +119,7 @@ int Oflag = 2; /* file system format (1 => UFS1, 2 => UFS2) */ int Rflag; /* regression test */ int Uflag; /* enable soft updates for file system */ +int Eflag = 0; /* exit in middle of newfs for testing */ quad_t fssize; /* file system size */ int sectorsize; /* bytes/sector */ int realsectorsize; /* bytes/sector in hardware */ @@ -156,8 +157,11 @@ off_t mediasize; while ((ch = getopt(argc, argv, - "L:NO:RS:T:Ua:b:c:d:e:f:g:h:i:m:o:s:")) != -1) + "EL:NO:RS:T:Ua:b:c:d:e:f:g:h:i:m:o:s:")) != -1) switch (ch) { + case 'E': + Eflag++; + break; case 'L': volumelabel = optarg; i = -1; --- sbin/fsck_ffs/setup.c.orig Wed Nov 5 15:50:12 2003 +++ sbin/fsck_ffs/setup.c Mon Nov 10 18:24:03 2003 @@ -301,6 +301,11 @@ super = bflag; if ((bread(fsreadfd, (char *)&sblock, super, (long)SBLOCKSIZE))) return (0); + if (sblock.fs_magic == FS_BAD2_MAGIC) { + fprintf(stderr, + "This volume is incomplete, run newfs again\n"); + exit(11); + } if (sblock.fs_magic != FS_UFS1_MAGIC && sblock.fs_magic != FS_UFS2_MAGIC) { fprintf(stderr, "%d is not a file system superblock\n", @@ -313,6 +318,11 @@ if ((bread(fsreadfd, (char *)&sblock, super, (long)SBLOCKSIZE))) return (0); + if (sblock.fs_magic == FS_BAD2_MAGIC) { + fprintf(stderr, "This volume is incomplete, " + "run newfs again\n"); + exit(11); + } if ((sblock.fs_magic == FS_UFS1_MAGIC || (sblock.fs_magic == FS_UFS2_MAGIC && sblock.fs_sblockloc == sblock_try[i])) && --Boundary-00=_FoVs/1khD/qbQm2--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200311111339.30853.wes>