Module Name:    src
Committed By:   uch
Date:           Tue Aug  9 09:12:07 UTC 2011

Modified Files:
        src/sbin/newfs_v7fs: main.c

Log Message:
Check whether superblock is writable sector.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sbin/newfs_v7fs/main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/newfs_v7fs/main.c
diff -u src/sbin/newfs_v7fs/main.c:1.7 src/sbin/newfs_v7fs/main.c:1.8
--- src/sbin/newfs_v7fs/main.c:1.7	Fri Jul 22 09:15:10 2011
+++ src/sbin/newfs_v7fs/main.c	Tue Aug  9 09:12:07 2011
@@ -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;

Reply via email to