linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] f2fs-tools: mkfs: fix to avoid format of device when already mounted
@ 2013-03-31  2:51 Namjae Jeon
  0 siblings, 0 replies; only message in thread
From: Namjae Jeon @ 2013-03-31  2:51 UTC (permalink / raw)
  To: jaegeuk.kim
  Cc: linux-f2fs-devel, linux-fsdevel, linux-kernel, Namjae Jeon,
	Namjae Jeon, Amit Sahrawat

From: Namjae Jeon <namjae.jeon@samsung.com>

In case of embedded devices, where /etc/ is mounted as 'read-only'.
We donot have the /etc/mtab file. So, checking if the device is already
mounted from this file is not sufficient.
Try to read /proc/mounts in case of failure from /etc/mtab.

Issue logs:
/dev/sdb4 /mnt vfat rw,relatime,fmask=0022,dmask=0022,codepage=cp437,
iocharset=ascii,errors=remount-ro 0 0

Here device - sb4 is already mounted.
But, when trying to format using mkfs.f2fs

F2FS-tools: Ver: 1.1.0 (2013-01-14)
Info: sector size = 512
Info: total sectors = 13108784 (in 512bytes)
WARN: Align start sector number in a unit of pages
        i.e., start sector: 2542124, ofs:4 (sectors per page: 8)
Info: zone aligned segment0 blkaddr: 186
Info: This device doesn't support TRIM
Info: format successful

After Change:

F2FS-tools: Ver: 1.1.0 (2013-01-14)
Error: /dev/sdb4 is already mounted

Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Amit Sahrawat <a.sahrawat@samsung.com>
---
 lib/libf2fs.c |    9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/lib/libf2fs.c b/lib/libf2fs.c
index 37ed147..d228492 100644
--- a/lib/libf2fs.c
+++ b/lib/libf2fs.c
@@ -152,8 +152,13 @@ int f2fs_dev_is_mounted(struct f2fs_configuration *c)
 	struct mntent *mnt = NULL;
 
 	file = setmntent(MOUNTED, "r");
-	if (file == NULL)
-		return 0;
+	if (file == NULL) {
+		/* if failed due to /etc/mtab file not present
+		   try with /proc/mounts */
+		file = setmntent("/proc/mounts", "r");
+		if (file == NULL)
+			return 0;
+	}
 
 	while (1) {
 		mnt = getmntent(file);
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2013-03-31  2:51 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-31  2:51 [PATCH] f2fs-tools: mkfs: fix to avoid format of device when already mounted Namjae Jeon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).