Linux NILFS development
 help / color / mirror / Atom feed
* [PATCH] nilfs-utils: mkfs.nilfs2 should check presence of NILFS2 volume on device
@ 2013-03-23 11:45 Vyacheslav Dubeyko
       [not found] ` <1364039122.16985.2.camel-dzAnj6fV1RxGeWtTaGDT1UEK6ufn8VP3@public.gmane.org>
  0 siblings, 1 reply; 7+ messages in thread
From: Vyacheslav Dubeyko @ 2013-03-23 11:45 UTC (permalink / raw)
  To: linux-nilfs-u79uwXL29TY76Z2rM5mHXA, Ryusuke Konishi; +Cc: Hendrik Levsen

From: Vyacheslav Dubeyko <slava-yeENwD64cLxBDgjK7y7TUQ@public.gmane.org>
Subject: [PATCH] nilfs-utils: mkfs.nilfs2 should check presence of NILFS2 volume on device

The mkfs.nilfs2 utility should check presence of NILFS2 volume on device and to warn a user about possibility to destroy data by mkfs activity. This patch tries to read and to validate checksums of primary and secondary superblocks on opened device. If this operation ends successfully then mkfs.nilfs2 informs a user about potential danger to destroy existing NILFS2 volume. The execution of mkfs.nilfs2 stops with offering to make decision about continuation or abortion of operation. However, if a user runs mkfs.nilfs2 with "-q" option then checking of NILFS2 volume is skipped.

Reported-by: Hendrik Levsen <hendrik-j5CO6tLloWodnm+yROfE0A@public.gmane.org>
Signed-off-by: Vyacheslav Dubeyko <slava-yeENwD64cLxBDgjK7y7TUQ@public.gmane.org>
Tested-by: Vyacheslav Dubeyko <slava-yeENwD64cLxBDgjK7y7TUQ@public.gmane.org>
---
 sbin/mkfs/Makefile.am |    3 ++-
 sbin/mkfs/mkfs.c      |   34 ++++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/sbin/mkfs/Makefile.am b/sbin/mkfs/Makefile.am
index b3eb78a..631b04f 100644
--- a/sbin/mkfs/Makefile.am
+++ b/sbin/mkfs/Makefile.am
@@ -4,7 +4,8 @@ AM_CFLAGS = -Wall
 AM_CPPFLAGS = -I$(top_srcdir)/include
 LDADD = -luuid $(top_builddir)/lib/libnilfsfeature.la \
 	$(top_builddir)/lib/libmountchk.la \
-	$(top_builddir)/lib/libcrc32.la
+	$(top_builddir)/lib/libcrc32.la \
+	$(top_builddir)/lib/libnilfs.la
 
 sbin_PROGRAMS = mkfs.nilfs2
 
diff --git a/sbin/mkfs/mkfs.c b/sbin/mkfs/mkfs.c
index fde1c76..9f18afe 100644
--- a/sbin/mkfs/mkfs.c
+++ b/sbin/mkfs/mkfs.c
@@ -347,6 +347,8 @@ static int nilfs_mkfs_discard_zeroes_data(int fd)
 
 static void disk_scan(const char *device);
 static void check_mount(int fd, const char *device);
+static void check_presence_of_nilfs_volume_on_device(int fd,
+						const char *device);
 
 
 /*
@@ -611,6 +613,7 @@ int main(int argc, char *argv[])
 	if ((fd = open(device, O_RDWR)) < 0)
 		perr("Error: cannot open device: %s", device);
 	check_mount(fd, device);
+	check_presence_of_nilfs_volume_on_device(fd, device);
 
 	init_disk_layout(di, fd, device);
 	si = new_segment(di);
@@ -729,6 +732,37 @@ static void check_mount(int fd, const char *device)
 	fclose(fp);
 }
 
+static void check_presence_of_nilfs_volume_on_device(int fd,
+						const char *device)
+{
+	struct nilfs_super_block *sbp = NULL;
+	int c;
+
+	if (quiet == 0) {
+		sbp = nilfs_sb_read(fd);
+		if (sbp) {
+			free(sbp);
+
+			pinfo("WARNING: Device %s has NILFS2 superblocks.",
+				device);
+			pinfo("WARNING: All data will be lost after format!");
+			pinfo("\nDO YOU REALLY WANT TO FORMAT DEVICE %s?",
+				device);
+
+			do {
+				fprintf(stderr, "\nContinue? [y/N] ");
+				c = getchar();
+
+				if (c == 'n' || c == 'N' || c == EOF) {
+					close(fd);
+					perr("Abort format of device %s",
+						device);
+				}
+			} while (c != 'y' && c != 'Y');
+		}
+	}
+}
+
 static void destroy_disk_buffer(void)
 {
 	if (disk_buffer) {
-- 
1.7.9.5



--
To unsubscribe from this list: send the line "unsubscribe linux-nilfs" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2013-03-24 16:08 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-23 11:45 [PATCH] nilfs-utils: mkfs.nilfs2 should check presence of NILFS2 volume on device Vyacheslav Dubeyko
     [not found] ` <1364039122.16985.2.camel-dzAnj6fV1RxGeWtTaGDT1UEK6ufn8VP3@public.gmane.org>
2013-03-23 14:32   ` Ryusuke Konishi
     [not found]     ` <20130323.233257.27780281.konishi.ryusuke-Zyj7fXuS5i5L9jVzuh4AOg@public.gmane.org>
2013-03-24 12:09       ` Martin Steigerwald
     [not found]         ` <201303241309.19162.Martin-3kZCPVa5dk2azgQtNeiOUg@public.gmane.org>
2013-03-24 13:41           ` Vyacheslav Dubeyko
     [not found]             ` <91A35B7F-A668-4B57-888F-7CE2A7D0ED86-yeENwD64cLxBDgjK7y7TUQ@public.gmane.org>
2013-03-24 14:43               ` Martin Steigerwald
     [not found]                 ` <201303241543.23310.Martin-3kZCPVa5dk2azgQtNeiOUg@public.gmane.org>
2013-03-24 16:08                   ` Vyacheslav Dubeyko
     [not found]                     ` <8C599058-8F00-4B0E-9BB0-D7F1DF34DC91-yeENwD64cLxBDgjK7y7TUQ@public.gmane.org>
2013-03-24 16:03                       ` Eric Sandeen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox