[git commit] chattr: if IOC_FSGETXATTR fails, do not try IOC_FSSETXATTR

Denys Vlasenko vda.linux at googlemail.com
Wed Jun 23 17:44:15 UTC 2021


commit: https://git.busybox.net/busybox/commit/?id=0e55af6c61a5420ffbeae990928b0fc546a7ef06
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master

function                                             old     new   delta
change_attributes                                    416     410      -6

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 e2fsprogs/chattr.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/e2fsprogs/chattr.c b/e2fsprogs/chattr.c
index 1b12c9f37..e599abae7 100644
--- a/e2fsprogs/chattr.c
+++ b/e2fsprogs/chattr.c
@@ -141,6 +141,8 @@ static void change_attributes(const char *name, struct globals *gp);
 
 static int FAST_FUNC chattr_dir_proc(const char *dir_name, struct dirent *de, void *gp)
 {
+//TODO: use de->d_type (if it's not DT_UNKNOWN) to skip !(REG || DIR || LNK) entries without lstat?
+
 	char *path = concat_subpath_file(dir_name, de->d_name);
 	/* path is NULL if de->d_name is "." or "..", else... */
 	if (path) {
@@ -184,12 +186,14 @@ static void change_attributes(const char *name, struct globals *gp)
 			struct ext2_fsxattr fsxattr;
 			r = ioctl(fd, EXT2_IOC_FSGETXATTR, &fsxattr);
 			/* note: ^^^ may fail in 32-bit userspace on 64-bit kernel (seen on 4.12.0) */
-			if (r != 0)
+			if (r != 0) {
 				bb_perror_msg("getting %s on %s", "project ID", name);
-			fsxattr.fsx_projid = gp->projid;
-			r = ioctl(fd, EXT2_IOC_FSSETXATTR, &fsxattr);
-			if (r != 0)
-				bb_perror_msg("setting %s on %s", "project ID", name);
+			} else {
+				fsxattr.fsx_projid = gp->projid;
+				r = ioctl(fd, EXT2_IOC_FSSETXATTR, &fsxattr);
+				if (r != 0)
+					bb_perror_msg("setting %s on %s", "project ID", name);
+			}
 		}
 
 		if (gp->flags & OPT_SET) {


More information about the busybox-cvs mailing list