Page MenuHomeFreeBSD

D37675.id114215.diff
No OneTemporary

D37675.id114215.diff

diff --git a/sys/kern/vfs_mountroot.c b/sys/kern/vfs_mountroot.c
--- a/sys/kern/vfs_mountroot.c
+++ b/sys/kern/vfs_mountroot.c
@@ -794,7 +794,7 @@
ma = parse_mountroot_options(ma, opts);
error = kernel_mount(ma, MNT_ROOTFS);
- if (error == 0 || timeout <= 0)
+ if (error == 0 || error == EILSEQ || timeout <= 0)
break;
if (root_mount_timeout * hz == timeout ||
diff --git a/sys/ufs/ffs/ffs_subr.c b/sys/ufs/ffs/ffs_subr.c
--- a/sys/ufs/ffs/ffs_subr.c
+++ b/sys/ufs/ffs/ffs_subr.c
@@ -35,6 +35,7 @@
__FBSDID("$FreeBSD$");
#include <sys/param.h>
+#include <sys/endian.h>
#include <sys/limits.h>
#ifndef _KERNEL
@@ -144,6 +145,7 @@
* EIO: non-existent or truncated superblock.
* EIO: error reading summary information.
* ENOENT: no usable known superblock found.
+ * EILSEQ: filesystem with wrong byte order found.
* ENOMEM: failed to allocate space for the superblock.
* EINVAL: The previous newfs operation on this volume did not complete.
* The administrator must complete newfs before using this volume.
@@ -382,6 +384,18 @@
prtmsg = ((flags & UFS_NOMSG) == 0);
warnerr = (flags & UFS_NOWARNFAIL) == UFS_NOWARNFAIL ? 0 : ENOENT;
wmsg = warnerr ? "" : " (Ignored)";
+
+ /*
+ * Check for endian mismatch between machine and filesystem.
+ */
+ if (((fs->fs_magic != FS_UFS2_MAGIC) &&
+ (bswap32(fs->fs_magic) == FS_UFS2_MAGIC)) ||
+ ((fs->fs_magic != FS_UFS1_MAGIC) &&
+ (bswap32(fs->fs_magic) == FS_UFS1_MAGIC))) {
+ MPRINT("UFS superblock failed due to endian mismatch "
+ "between machine and filesystem\n");
+ return(EILSEQ);
+ }
/*
* If just validating for recovery, then do just the minimal
* checks needed for the superblock fields needed to find
@@ -627,8 +641,16 @@
* failure can be avoided.
*/
flags = UFS_NOMSG | nocsum;
- if (ffs_sbget(devfd, fsp, UFS_STDSB, flags, filltype, readfunc) == 0)
- return (0);
+ error = ffs_sbget(devfd, fsp, UFS_STDSB, flags, filltype, readfunc);
+ /*
+ * If successful or endian error, no need to try further.
+ */
+ if (error == 0 || error == EILSEQ) {
+ if (msg && error == EILSEQ)
+ printf("UFS superblock failed due to endian mismatch "
+ "between machine and filesystem\n");
+ return (error);
+ }
/*
* First try: ignoring hash failures.
*/
@@ -677,6 +699,7 @@
* but some devices lie. So we just try a plausible range.
*/
error = ENOENT;
+ fsrbuf = NULL;
for (secsize = dbtob(1); secsize <= SBLOCKSIZE; secsize *= 2)
if ((error = (*readfunc)(devfd, (SBLOCK_UFS2 - secsize),
&fsrbuf, secsize)) == 0)

File Metadata

Mime Type
text/plain
Expires
Sun, Dec 15, 6:33 PM (20 h, 43 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
15416116
Default Alt Text
D37675.id114215.diff (2 KB)

Event Timeline