Skip to contentSkip to conversation

f2fs-tools: fix to check loop device

PATCH New Chao Yu 1 participant 1 message Jan 31, 2024 Library code

lore
Share & tools
lore

Chao Yu

author
#0 lore raw

PATCH 1/1 f2fs-tools: fix to check loop device

Otherwise, mkfs/fsck can update backfile of moutned loop device.

1. mkfs.f2fs image
2. mount -o loop image /mnt/f2fs/
3. mkfs.f2fs image -f

Before:
...
Info: format successful

After:
...
Error: In use by loop device!

---
 configure.ac             |  2 ++
 fsck/main.c              |  4 +--
 include/android_config.h |  2 ++
 lib/libf2fs.c            | 74 ++++++++++++++++++++++++++++++++++------
 mkfs/f2fs_format_main.c  |  7 ++--
 5 files changed, 74 insertions(+), 15 deletions(-)
configure.ac +2 -0
index 123ddbb..21c6391 100644
@@ -144,6 +144,8 @@ AC_CHECK_HEADERS(m4_flatten([
 	linux/fs.h
 	linux/hdreg.h
 	linux/limits.h
+	linux/loop.h
+	linux/major.h
 	linux/posix_acl.h
 	linux/types.h
 	linux/xattr.h
fsck/main.c +2 -2
index 1affa72..c4d0956 100644
@@ -1111,8 +1111,8 @@ int main(int argc, char **argv)
 
 	f2fs_parse_options(argc, argv);
 
-	if (c.func != DUMP && f2fs_devs_are_umounted() < 0) {
-		if (errno == EBUSY) {
+	if (c.func != DUMP && (ret = f2fs_devs_are_umounted()) < 0) {
+		if (ret == -EBUSY) {
 			ret = -1;
 			if (c.func == FSCK)
 				ret = FSCK_OPERATIONAL_ERROR;
include/android_config.h +2 -0
index da8abcb..05b686e 100644
@@ -6,6 +6,8 @@
 #define HAVE_FSYNC 1
 #define HAVE_LINUX_HDREG_H 1
 #define HAVE_LINUX_LIMITS_H 1
+#define HAVE_LINUX_LOOP_H 1
+#define HAVE_LINUX_MAJOR_H 1
 #define HAVE_POSIX_ACL_H 1
 #define HAVE_LINUX_TYPES_H 1
 #define HAVE_LINUX_XATTR_H 1
lib/libf2fs.c +63 -11

108 lines not on this page · raw message

mkfs/f2fs_format_main.c +5 -2
index 4de517a..f3316f7 100644
@@ -443,6 +443,8 @@ static int f2fs_check_overwrite(void)
 
 int main(int argc, char *argv[])
 {
+	int ret;
+
 	f2fs_init_configuration();
 
 	f2fs_parse_options(argc, argv);
@@ -451,8 +453,9 @@ int main(int argc, char *argv[])
 
 	c.func = MKFS;
 
-	if (f2fs_devs_are_umounted() < 0) {
-		if (errno != EBUSY)
+	ret = f2fs_devs_are_umounted();
+	if (ret) {
+		if (ret != -EBUSY)
 			MSG(0, "\tError: Not available on mounted device!\n");
 		goto err_format;
 	}
Signature · 8 lines
2.40.1



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel