f2fs-tools: mkfs: fix to avoid format of device when already mounted
Subsystems (2)
PATCH 1/1 f2fs-tools: mkfs: fix to avoid format of device when already mounted
From: Namjae Jeon <[email protected]>
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
--- lib/libf2fs.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
lib/libf2fs.c +7 -2
@@ -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);
Signature · 1 line
1.7.9.5