diff options
-rw-r--r-- | sys/kern/vfs_mountroot.c | 2 | ||||
-rw-r--r-- | sys/ufs/ffs/ffs_subr.c | 26 |
2 files changed, 25 insertions, 3 deletions
diff --git a/sys/kern/vfs_mountroot.c b/sys/kern/vfs_mountroot.c index 5361f41276a0..3c506378ad2f 100644 --- a/sys/kern/vfs_mountroot.c +++ b/sys/kern/vfs_mountroot.c @@ -794,7 +794,7 @@ parse_mount(char **conf) 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 index 705f8c9c961d..31f30ba5d175 100644 --- 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 @@ static int validate_sblock(struct fs *, int); * 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. @@ -383,6 +385,17 @@ validate_sblock(struct fs *fs, int flags) 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 * alternate superblocks. @@ -627,8 +640,16 @@ ffs_sbsearch(void *devfd, struct fs **fsp, int reqflags, * 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 +698,7 @@ ffs_sbsearch(void *devfd, struct fs **fsp, int reqflags, * 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) |