All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH]mke2fs: don't check mount flags for regular files
@ 2009-03-24  8:31 Peng Tao
  2009-04-23  2:27 ` Theodore Tso
  0 siblings, 1 reply; 2+ messages in thread
From: Peng Tao @ 2009-03-24  8:31 UTC (permalink / raw)
  To: linux-ext4; +Cc: tytso, Peng Tao

mke2fs scans /proc/mounts for mount flags of a device. But for regular files,
this is unnecessary and may cause troubles.

This can be triggered by:
$dd if=/dev/null of=rootfs bs=1024 seek=100000 count=0
$mke2fs -t ext3 -F rootfs
mke2fs 1.41.4 (27-Jan-2009)
rootfs is mounted; will not make a filesystem here!

Signed-off-by: Peng Tao <bergwolf@gmail.com>
---
 lib/ext2fs/mkjournal.c |    5 +++++
 misc/util.c            |    3 +++
 2 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/lib/ext2fs/mkjournal.c b/lib/ext2fs/mkjournal.c
index f5a9dba..ba7c6a8 100644
--- a/lib/ext2fs/mkjournal.c
+++ b/lib/ext2fs/mkjournal.c
@@ -466,6 +466,11 @@ errcode_t ext2fs_add_journal_inode(ext2_filsys fs, blk_t size, int flags)
 					       jfile, sizeof(jfile)-10)))
 		return retval;
 
+	/*
+	 * Discard mounted flag if it is a regular file.
+	 */
+	if (stat(fs->device_name, &st) < 0 || S_ISREG(st.st_mode))
+		mount_flags &= ~EXT2_MF_MOUNTED;
 	if (mount_flags & EXT2_MF_MOUNTED) {
 		strcat(jfile, "/.journal");
 
diff --git a/misc/util.c b/misc/util.c
index 837d60f..d5b8033 100644
--- a/misc/util.c
+++ b/misc/util.c
@@ -144,7 +144,10 @@ void check_mount(const char *device, int force, const char *type)
 {
 	errcode_t	retval;
 	int		mount_flags;
+	struct stat	st_buf;
 
+	if ((stat(device, &st_buf) != 0) || S_ISREG(st_buf.st_mode))
+		return;
 	retval = ext2fs_check_if_mounted(device, &mount_flags);
 	if (retval) {
 		com_err("ext2fs_check_if_mount", retval,
-- 
1.6.2-rc2.GIT


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

* Re: [PATCH]mke2fs: don't check mount flags for regular files
  2009-03-24  8:31 [PATCH]mke2fs: don't check mount flags for regular files Peng Tao
@ 2009-04-23  2:27 ` Theodore Tso
  0 siblings, 0 replies; 2+ messages in thread
From: Theodore Tso @ 2009-04-23  2:27 UTC (permalink / raw)
  To: Peng Tao; +Cc: linux-ext4

On Tue, Mar 24, 2009 at 04:31:33PM +0800, Peng Tao wrote:
> mke2fs scans /proc/mounts for mount flags of a device. But for regular files,
> this is unnecessary and may cause troubles.
> 
> This can be triggered by:
> $dd if=/dev/null of=rootfs bs=1024 seek=100000 count=0
> $mke2fs -t ext3 -F rootfs
> mke2fs 1.41.4 (27-Jan-2009)
> rootfs is mounted; will not make a filesystem here!

Actually, this is quite necessary; regular files can be mounted using
the loop device, and we want to catch this case.  So simply patching
out the check for regular files is the wrong thing to do, and hides
the real problem.

The correct patch to solve the problem you've reported is attached,
and has been checked into e2fsprogs source repository.

						- Ted

commit f9110f4480eade2d849c4cc08efa49bf0f7f5148
Author: Theodore Ts'o <tytso@mit.edu>
Date:   Wed Apr 22 22:20:22 2009 -0400

    libext2fs: Skip relative pathnames in /etc/mtab in ismounted.c
    
    The functions which test to see if a device is mounted can get
    confused by entries in /etc/mtab for virtual filesystems:
    
    rootfs / rootfs rw 0 0
    none /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0
    
    If the device name doesn't start with a slash, ignore the /etc/mtab
    entry, so that relative pathnames passed into functions such as
    ext2fs_check_mount_point() or ext2fs_check_if_mounted() don't return
    false positives.
    
    Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>

diff --git a/lib/ext2fs/ismounted.c b/lib/ext2fs/ismounted.c
index 4a7c8c6..4c5500f 100644
--- a/lib/ext2fs/ismounted.c
+++ b/lib/ext2fs/ismounted.c
@@ -65,6 +65,8 @@ static errcode_t check_mntent_file(const char *mtab_file, const char *file,
 		}
 	}
 	while ((mnt = getmntent (f)) != NULL) {
+		if (mnt->mnt_fsname[0] != '/')
+			continue;
 		if (strcmp(file, mnt->mnt_fsname) == 0)
 			break;
 		if (stat(mnt->mnt_fsname, &st_buf) == 0) {

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

end of thread, other threads:[~2009-04-23  2:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-24  8:31 [PATCH]mke2fs: don't check mount flags for regular files Peng Tao
2009-04-23  2:27 ` Theodore Tso

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.