Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 24 Feb 2018 03:33:46 +0000 (UTC)
From:      Kirk McKusick <mckusick@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r329896 - head/sys/ufs/ffs
Message-ID:  <201802240333.w1O3Xkic067442@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mckusick
Date: Sat Feb 24 03:33:46 2018
New Revision: 329896
URL: https://svnweb.freebsd.org/changeset/base/329896

Log:
  Relax the location restraints when validating one of the
  backup superblocks.

Modified:
  head/sys/ufs/ffs/ffs_subr.c

Modified: head/sys/ufs/ffs/ffs_subr.c
==============================================================================
--- head/sys/ufs/ffs/ffs_subr.c	Sat Feb 24 02:57:24 2018	(r329895)
+++ head/sys/ufs/ffs/ffs_subr.c	Sat Feb 24 03:33:46 2018	(r329896)
@@ -162,28 +162,28 @@ static int readsuper(void *, struct fs **, off_t,
  *         The administrator must complete newfs before using this volume.
  */
 int
-ffs_sbget(void *devfd, struct fs **fsp, off_t altsuperblock,
+ffs_sbget(void *devfd, struct fs **fsp, off_t altsblock,
     struct malloc_type *filltype,
     int (*readfunc)(void *devfd, off_t loc, void **bufp, int size))
 {
 	struct fs *fs;
-	int i, ret, size, blks;
+	int i, error, size, blks;
 	uint8_t *space;
 	int32_t *lp;
 	char *buf;
 
 	*fsp = NULL;
-	if (altsuperblock != -1) {
-		if ((ret = readsuper(devfd, fsp, altsuperblock, readfunc)) != 0)
-			return (ret);
+	if (altsblock != -1) {
+		if ((error = readsuper(devfd, fsp, -altsblock, readfunc)) != 0)
+			return (error);
 	} else {
 		for (i = 0; sblock_try[i] != -1; i++) {
-			if ((ret = readsuper(devfd, fsp, sblock_try[i],
+			if ((error = readsuper(devfd, fsp, sblock_try[i],
 			     readfunc)) == 0)
 				break;
-			if (ret == ENOENT)
+			if (error == ENOENT)
 				continue;
-			return (ret);
+			return (error);
 		}
 		if (sblock_try[i] == -1)
 			return (ENOENT);
@@ -209,13 +209,13 @@ ffs_sbget(void *devfd, struct fs **fsp, off_t altsuper
 		if (i + fs->fs_frag > blks)
 			size = (blks - i) * fs->fs_fsize;
 		buf = NULL;
-		ret = (*readfunc)(devfd,
+		error = (*readfunc)(devfd,
 		    dbtob(fsbtodb(fs, fs->fs_csaddr + i)), (void **)&buf, size);
-		if (ret) {
+		if (error) {
 			UFS_FREE(buf, filltype);
 			UFS_FREE(fs->fs_csp, filltype);
 			fs->fs_csp = NULL;
-			return (ret);
+			return (error);
 		}
 		memcpy(space, buf, size);
 		UFS_FREE(buf, filltype);
@@ -242,8 +242,13 @@ readsuper(void *devfd, struct fs **fsp, off_t sblocklo
     int (*readfunc)(void *devfd, off_t loc, void **bufp, int size))
 {
 	struct fs *fs;
-	int error;
+	int error, altblk;
 
+	altblk = 0;
+	if (sblockloc < 0) {
+		altblk = 1;
+		sblockloc = - sblockloc;
+	}
 	error = (*readfunc)(devfd, sblockloc, (void **)fsp, SBLOCKSIZE);
 	if (*fsp != NULL)
 		(*fsp)->fs_csp = NULL;	/* Not yet any summary information */
@@ -252,9 +257,10 @@ readsuper(void *devfd, struct fs **fsp, off_t sblocklo
 	fs = *fsp;
 	if (fs->fs_magic == FS_BAD_MAGIC)
 		return (EINVAL);
-	if (((fs->fs_magic == FS_UFS1_MAGIC && sblockloc <= SBLOCK_UFS1) ||
-	     (fs->fs_magic == FS_UFS2_MAGIC &&
-	      sblockloc == fs->fs_sblockloc)) &&
+	if (((fs->fs_magic == FS_UFS1_MAGIC && (altblk ||
+	      sblockloc <= SBLOCK_UFS1)) ||
+	     (fs->fs_magic == FS_UFS2_MAGIC && (altblk ||
+	      sblockloc == fs->fs_sblockloc))) &&
 	    fs->fs_ncg >= 1 &&
 	    fs->fs_bsize >= MINBSIZE &&
 	    fs->fs_bsize <= MAXBSIZE &&



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201802240333.w1O3Xkic067442>