Generalize the UFS bad magic value used to determine when a filesystem

has only been partly initialized via newfs(8) so that it applies to both
UFS1 and UFS2.

Submitted by:	"Xin LI" delphij at frontfree dot net
MFC:		maybe?
This commit is contained in:
jhb 2004-08-19 11:09:13 +00:00
parent 31eee22fb9
commit b8b0c912ba
3 changed files with 12 additions and 7 deletions

View File

@ -306,7 +306,7 @@ readsb(int listerr)
super = bflag;
if ((bread(fsreadfd, (char *)&sblock, super, (long)SBLOCKSIZE)))
return (0);
if (sblock.fs_magic == FS_BAD2_MAGIC) {
if (sblock.fs_magic == FS_BAD_MAGIC) {
fprintf(stderr, BAD_MAGIC_MSG);
exit(11);
}
@ -322,7 +322,7 @@ readsb(int listerr)
if ((bread(fsreadfd, (char *)&sblock, super,
(long)SBLOCKSIZE)))
return (0);
if (sblock.fs_magic == FS_BAD2_MAGIC) {
if (sblock.fs_magic == FS_BAD_MAGIC) {
fprintf(stderr, BAD_MAGIC_MSG);
exit(11);
}

View File

@ -236,8 +236,14 @@ mkfs(struct partition *pp, char *fsys)
}
sblock.fs_fsbtodb = ilog2(sblock.fs_fsize / sectorsize);
sblock.fs_size = fssize = dbtofsb(&sblock, fssize);
/*
* Before the filesystem is finally initialized, mark it
* as incompletely initialized.
*/
sblock.fs_magic = FS_BAD_MAGIC;
if (Oflag == 1) {
sblock.fs_magic = FS_UFS1_MAGIC;
sblock.fs_sblockloc = SBLOCK_UFS1;
sblock.fs_nindir = sblock.fs_bsize / sizeof(ufs1_daddr_t);
sblock.fs_inopb = sblock.fs_bsize / sizeof(struct ufs1_dinode);
@ -257,7 +263,6 @@ mkfs(struct partition *pp, char *fsys)
sblock.fs_old_postblformat = 1;
sblock.fs_old_nrpos = 1;
} else {
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);
@ -455,8 +460,8 @@ mkfs(struct partition *pp, char *fsys)
}
if (Eflag == 2)
printf("** Leaving BAD MAGIC on Eflag 2\n");
else if (Oflag != 1)
sblock.fs_magic = FS_UFS2_MAGIC;
else
sblock.fs_magic = (Oflag != 1) ? FS_UFS2_MAGIC : FS_UFS1_MAGIC;
/*
* Now build the cylinders group blocks and

View File

@ -357,7 +357,7 @@ CTASSERT(sizeof(struct fs) == 1376);
*/
#define FS_UFS1_MAGIC 0x011954 /* UFS1 fast filesystem magic number */
#define FS_UFS2_MAGIC 0x19540119 /* UFS2 fast filesystem magic number */
#define FS_BAD2_MAGIC 0x19960408 /* UFS2 incomplete newfs magic number */
#define FS_BAD_MAGIC 0x19960408 /* UFS 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 */