[PATCH] io/attr.c: Disallow specifying both -D and -R options for chattr command

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



-D and -R options are mutually exclusive actually but chattr command
doesn't check it so that always applies -D option when both of them
are specified.  For example:
------------------------------------
# mkdir testdir
# mkdir testdir/tdir
# touch testdir/tfile
# xfs_io -c "chattr -D -R +s" testdir
# xfs_io -c "lsattr -R" testdir
----s----------- testdir/tdir
---------------- testdir/tfile
----s----------- testdir
------------------------------------

Add a check to disallow the combination.

Signed-off-by: Xiao Yang <yangx.jy@xxxxxxxxxxxxxx>
---
 io/attr.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/io/attr.c b/io/attr.c
index 80e28514..f82a0881 100644
--- a/io/attr.c
+++ b/io/attr.c
@@ -320,6 +320,13 @@ chattr_f(
 		}
 	}
 
+	if (recurse_all && recurse_dir) {
+		fprintf(stderr, _("%s: -R and -D options are mutually exclusive\n"),
+			progname);
+		exitcode = 1;
+		return 0;
+	}
+
 	if (recurse_all || recurse_dir) {
 		nftw(name, chattr_callback,
 			100, FTW_PHYS | FTW_MOUNT | FTW_DEPTH);
-- 
2.21.0






[Index of Archives]     [XFS Filesystem Development (older mail)]     [Linux Filesystem Development]     [Linux Audio Users]     [Yosemite Trails]     [Linux Kernel]     [Linux RAID]     [Linux SCSI]


  Powered by Linux