Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/ufs/ffs ffs_superblock_validate(): compute fs_bshift and...



details:   https://anonhg.NetBSD.org/src/rev/d66971c76620
branches:  trunk
changeset: 336140:d66971c76620
user:      maxv <maxv%NetBSD.org@localhost>
date:      Sat Feb 14 10:21:29 2015 +0000

description:
ffs_superblock_validate(): compute fs_bshift and fs_fshift, and ensure
they are consistent with what is indicated in the superblock. This allows
us to safely use some ffs_ macros.

diffstat:

 sys/ufs/ffs/ffs_vfsops.c |  22 +++++++++++++++++++---
 1 files changed, 19 insertions(+), 3 deletions(-)

diffs (51 lines):

diff -r c2d3328ba6bb -r d66971c76620 sys/ufs/ffs/ffs_vfsops.c
--- a/sys/ufs/ffs/ffs_vfsops.c  Sat Feb 14 09:55:53 2015 +0000
+++ b/sys/ufs/ffs/ffs_vfsops.c  Sat Feb 14 10:21:29 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ffs_vfsops.c,v 1.314 2015/02/14 09:55:53 maxv Exp $    */
+/*     $NetBSD: ffs_vfsops.c,v 1.315 2015/02/14 10:21:29 maxv Exp $    */
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.314 2015/02/14 09:55:53 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.315 2015/02/14 10:21:29 maxv Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -925,6 +925,8 @@
 static int
 ffs_superblock_validate(struct fs *fs)
 {
+       int32_t i, fs_bshift = 0, fs_fshift = 0;
+
        /* Check the superblock size */
        if (fs->fs_sbsize > SBLOCKSIZE || fs->fs_sbsize < sizeof(struct fs))
                return 0;
@@ -948,8 +950,22 @@
        if (fs->fs_bsize < fs->fs_fsize)
                return 0;
 
+       /* Compute fs_bshift and ensure it is consistent */
+       for (i = fs->fs_bsize; i > 1; i >>= 1)
+               fs_bshift++;
+       if (fs->fs_bshift != fs_bshift)
+               return 0;
+
+       /* Compute fs_fshift and ensure it is consistent */
+       for (i = fs->fs_fsize; i > 1; i >>= 1)
+               fs_fshift++;
+       if (fs->fs_fshift != fs_fshift)
+               return 0;
+
+       /* Now that the shifts are sanitized, we can use the ffs_ API */
+
        /* Check the number of frag blocks */
-       if ((fs->fs_bsize / fs->fs_fsize) > MAXFRAG)
+       if (ffs_numfrags(fs, fs->fs_bsize) > MAXFRAG)
                return 0;
 
        return 1;



Home | Main Index | Thread Index | Old Index