Skip to contentSkip to conversation

f2fs-tools: deal with permission denial on non-root user

PATCH In review Jaegeuk Kim 4 participants 4 messages Mar 5, 2024 – Mar 6, 2024 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 f2fs-tools: deal with permission denial on non-root user

This fixes some android build failures due to the missing permission when checking the loop device. Until we get a better solution, let's ignore the error with warnings.

---
 lib/libf2fs.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
lib/libf2fs.c +9 -3
index d51e485361ee..1cfbf31a9c85 100644
@@ -854,9 +854,15 @@ int f2fs_dev_is_umounted(char *path)
 
 			loop_fd = open(mnt->mnt_fsname, O_RDONLY);
 			if (loop_fd < 0) {
+				/* non-root users have no permission */
+				if (errno == EPERM || errno == EACCES) {
+					MSG(0, "Info: open %s failed errno:%d - be careful to overwrite a mounted loopback file.\n",
+							mnt->mnt_fsname, errno);
+					return 0;
+				}
 				MSG(0, "Info: open %s failed errno:%d\n",
-					mnt->mnt_fsname, errno);
-				return -1;
+							mnt->mnt_fsname, errno);
+				return -errno;
 			}
 
 			err = ioctl(loop_fd, LOOP_GET_STATUS64, &loopinfo);
@@ -864,7 +870,7 @@ int f2fs_dev_is_umounted(char *path)
 			if (err < 0) {
 				MSG(0, "\tError: ioctl LOOP_GET_STATUS64 failed errno:%d!\n",
 					errno);
-				return -1;
+				return -errno;
 			}
 
 			if (st_buf.st_dev == loopinfo.lo_device &&
Signature · 8 lines
2.44.0.278.ge034bb2e1d-goog



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Reviewed-by on v1 1/1
#1 lore raw
Quoted 46 lines · Jaegeuk Kim

This fixes some android build failures due to the missing permission when checking the loop device. Until we get a better solution, let's ignore the error with warnings.

---
 lib/libf2fs.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
lib/libf2fs.c +9 -4
index d51e485361ee..1cfbf31a9c85 100644
@@ -854,9 +854,15 @@ int f2fs_dev_is_umounted(char *path)
 
                        loop_fd = open(mnt->mnt_fsname, O_RDONLY);
                        if (loop_fd < 0) {
+                               /* non-root users have no permission */
+                               if (errno == EPERM || errno == EACCES) {
+                                       MSG(0, "Info: open %s failed errno:%d - be careful to overwrite a mounted loopback file.\n",
+                                                       mnt->mnt_fsname, errno);
+                                       return 0;
+                               }
                                MSG(0, "Info: open %s failed errno:%d\n",
-                                       mnt->mnt_fsname, errno);
-                               return -1;
+                                                       mnt->mnt_fsname, errno);
+                               return -errno;
                        }
 
                        err = ioctl(loop_fd, LOOP_GET_STATUS64, &loopinfo);
@@ -864,7 +870,7 @@ int f2fs_dev_is_umounted(char *path)
                        if (err < 0) {
                                MSG(0, "\tError: ioctl LOOP_GET_STATUS64 failed errno:%d!\n",
                                        errno);
-                               return -1;
+                               return -errno;
                        }
 
                        if (st_buf.st_dev == loopinfo.lo_device &&
--

2.44.0.278.ge034bb2e1d-goog

Quoted 4 lines

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

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

Reviewed-by Huang Jianan on v1 1/1
#2 lore raw
In reply to Jaegeuk Kim

Thanks.

Quoted 45 lines · Jaegeuk Kim

This fixes some android build failures due to the missing permission when checking the loop device. Until we get a better solution, let's ignore the error with warnings.

---
  lib/libf2fs.c | 12 +++++++++---
  1 file changed, 9 insertions(+), 3 deletions(-)
lib/libf2fs.c +9 -4
index d51e485361ee..1cfbf31a9c85 100644
@@ -854,9 +854,15 @@ int f2fs_dev_is_umounted(char *path)
 
                         loop_fd = open(mnt->mnt_fsname, O_RDONLY);
                         if (loop_fd < 0) {
+                               /* non-root users have no permission */
+                               if (errno == EPERM || errno == EACCES) {
+                                       MSG(0, "Info: open %s failed errno:%d - be careful to overwrite a mounted loopback file.\n",
+                                                       mnt->mnt_fsname, errno);
+                                       return 0;
+                               }
                                 MSG(0, "Info: open %s failed errno:%d\n",
-                                       mnt->mnt_fsname, errno);
-                               return -1;
+                                                       mnt->mnt_fsname, errno);
+                               return -errno;
                         }
 
                         err = ioctl(loop_fd, LOOP_GET_STATUS64, &loopinfo);
@@ -864,7 +870,7 @@ int f2fs_dev_is_umounted(char *path)
                         if (err < 0) {
                                 MSG(0, "\tError: ioctl LOOP_GET_STATUS64 failed errno:%d!\n",
                                         errno);
-                               return -1;
+                               return -errno;
                         }
 
                         if (st_buf.st_dev == loopinfo.lo_device &&
--

2.44.0.278.ge034bb2e1d-goog

Quoted 4 lines

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

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

Reviewed-by on v1 1/1
#3 lore raw
In reply to Jaegeuk Kim
Quoted 5 lines · Jaegeuk Kim

This fixes some android build failures due to the missing permission when checking the loop device. Until we get a better solution, let's ignore the error with warnings.

Thanks,

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