From c16e610c5100cd5829d969272af3035fac8e1a31 Mon Sep 17 00:00:00 2001 From: Andreas Dilger Date: Sat, 5 Aug 2006 19:05:53 -0400 Subject: [PATCH] Require mke2fs -F -F for really dangerous operations Disambiguate the use of "-F" (force) flag for mke2fs to avoid dangerous situations. The use of -F is needed for regular backing files and for filesystems on whole block devices. It should NOT be confused with mke2fs on an apparently-mounted or in-use filesystem. Signed-off-by: Andreas Dilger Signed-off-by: "Theodore Ts'o" --- misc/ChangeLog | 4 ++++ misc/mke2fs.8.in | 9 +++++++-- misc/mke2fs.c | 2 +- misc/util.c | 4 ++-- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/misc/ChangeLog b/misc/ChangeLog index d489bf1..9b3ccd1 100644 --- a/misc/ChangeLog +++ b/misc/ChangeLog @@ -1,5 +1,9 @@ 2006-08-05 Theodore Tso + * mke2fs.c (PRS), util.c (check_mount): In order to force mke2fs + to create a filesystem even though it appears to be in use + or mounted, the -F (force) flag must be specified twice. + * filefrag.c: Change EXT3_EXTENTS_FL to EXT4_EXTENTS_FL 2006-07-15 Theodore Tso diff --git a/misc/mke2fs.8.in b/misc/mke2fs.8.in index 390bb88..a3dc4a1 100644 --- a/misc/mke2fs.8.in +++ b/misc/mke2fs.8.in @@ -195,8 +195,13 @@ Specify the size of fragments in bytes. .B \-F Force .B mke2fs -to run, even if the specified device is not a -block special device, or appears to be mounted. +to create a filesystem, even if the specified device is not a partition +on a block special device, or if other parameters do not make sense. +In order to force +.B mke2fs +to create a filesystem even if the filesystem appears to be in use +or is mounted (a truly dangerous thing to do), this option must be +specified twice. .TP .BI \-g " blocks-per-group" Specify the number of blocks in a block group. There is generally no diff --git a/misc/mke2fs.c b/misc/mke2fs.c index 2686d72..677c514 100644 --- a/misc/mke2fs.c +++ b/misc/mke2fs.c @@ -1089,7 +1089,7 @@ static void PRS(int argc, char *argv[]) verbose = 1; break; case 'F': - force = 1; + force++; break; case 'L': volume_label = optarg; diff --git a/misc/util.c b/misc/util.c index d496c3e..7cb952f 100644 --- a/misc/util.c +++ b/misc/util.c @@ -154,7 +154,7 @@ void check_mount(const char *device, int force, const char *type) } if (mount_flags & EXT2_MF_MOUNTED) { fprintf(stderr, _("%s is mounted; "), device); - if (force) { + if (force > 2) { fputs(_("mke2fs forced anyway. Hope /etc/mtab is " "incorrect.\n"), stderr); return; @@ -166,7 +166,7 @@ void check_mount(const char *device, int force, const char *type) if (mount_flags & EXT2_MF_BUSY) { fprintf(stderr, _("%s is apparently in use by the system; "), device); - if (force) { + if (force > 2) { fputs(_("mke2fs forced anyway.\n"), stderr); return; } -- 1.8.3.1