Source-Changes-HG archive

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

[src/trunk]: src/sbin/newfs_v7fs Check whether superblock is writable sector.



details:   https://anonhg.NetBSD.org/src/rev/19683a1bcbc8
branches:  trunk
changeset: 768125:19683a1bcbc8
user:      uch <uch%NetBSD.org@localhost>
date:      Tue Aug 09 09:12:07 2011 +0000

description:
Check whether superblock is writable sector.

diffstat:

 sbin/newfs_v7fs/main.c |  30 +++++++++++++++++++++++++++---
 1 files changed, 27 insertions(+), 3 deletions(-)

diffs (65 lines):

diff -r c0319e1ffbd2 -r 19683a1bcbc8 sbin/newfs_v7fs/main.c
--- a/sbin/newfs_v7fs/main.c    Tue Aug 09 09:06:52 2011 +0000
+++ b/sbin/newfs_v7fs/main.c    Tue Aug 09 09:12:07 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.7 2011/07/22 09:15:10 uch Exp $     */
+/*     $NetBSD: main.c,v 1.8 2011/08/09 09:12:07 uch Exp $     */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: main.c,v 1.7 2011/07/22 09:15:10 uch Exp $");
+__RCSID("$NetBSD: main.c,v 1.8 2011/08/09 09:12:07 uch Exp $");
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -72,6 +72,26 @@
 }
 
 static int
+partition_check(struct v7fs_self *fs)
+{
+       struct v7fs_superblock *sb = &fs->superblock;
+       int error;
+
+       if ((error = v7fs_superblock_load(fs))) {
+               warnx("Can't read superblock sector.");
+       }
+       sb->modified = 1;
+       if ((error = v7fs_superblock_writeback(fs))) {
+               if (errno == EROFS) {
+                       warnx("Overwriting disk label? ");
+               }
+               warnx("Can't write superblock sector.");
+       }
+
+       return error;
+}
+
+static int
 make_root(struct v7fs_self *fs)
 {
        struct v7fs_inode inode;
@@ -126,7 +146,7 @@
        v7fs_inode_writeback(fs, &inode);
        if ((error = v7fs_superblock_writeback(fs))) {
                errno = error;
-               warn("Can't write superblock.");
+               warnx("Can't write superblock.");
        }
 
        return error;
@@ -272,6 +292,10 @@
        fs->endian = mount->endian;
        v7fs_endian_init(fs);
 
+       if ((error = partition_check(fs))) {
+               return error;
+       }
+
        /* Construct filesystem. */
        if ((error = make_filesystem(fs, volume_size, ilist_size))) {
                return error;



Home | Main Index | Thread Index | Old Index