Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* |
| 3 | * chattr.c - Change file attributes on an ext2 file system |
| 4 | * |
| 5 | * Copyright (C) 1993, 1994 Remy Card <card@masi.ibp.fr> |
| 6 | * Laboratoire MASI, Institut Blaise Pascal |
| 7 | * Universite Pierre et Marie Curie (Paris VI) |
| 8 | * |
| 9 | * This file can be redistributed under the terms of the GNU General |
| 10 | * Public License |
| 11 | */ |
Denys Vlasenko | 000eda4 | 2015-10-18 22:40:23 +0200 | [diff] [blame] | 12 | //config:config CHATTR |
Denys Vlasenko | b097a84 | 2018-12-28 03:20:17 +0100 | [diff] [blame] | 13 | //config: bool "chattr (3.8 kb)" |
Denys Vlasenko | 000eda4 | 2015-10-18 22:40:23 +0200 | [diff] [blame] | 14 | //config: default y |
| 15 | //config: help |
Denys Vlasenko | 72089cf | 2017-07-21 09:50:55 +0200 | [diff] [blame] | 16 | //config: chattr changes the file attributes on a second extended file system. |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 17 | |
Denys Vlasenko | 99125c0 | 2017-08-05 20:38:04 +0200 | [diff] [blame] | 18 | //applet:IF_CHATTR(APPLET_NOEXEC(chattr, chattr, BB_DIR_BIN, BB_SUID_DROP, chattr)) |
Denys Vlasenko | 000eda4 | 2015-10-18 22:40:23 +0200 | [diff] [blame] | 19 | |
| 20 | //kbuild:lib-$(CONFIG_CHATTR) += chattr.o e2fs_lib.o |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 21 | |
Pere Orga | 6a3e01d | 2011-04-01 22:56:30 +0200 | [diff] [blame] | 22 | //usage:#define chattr_trivial_usage |
Denys Vlasenko | 526b834 | 2021-06-20 10:57:24 +0200 | [diff] [blame] | 23 | //usage: "[-R] [-v VERSION] [-p PROJID] [-+=AacDdijsStTu] FILE..." |
Pere Orga | 6a3e01d | 2011-04-01 22:56:30 +0200 | [diff] [blame] | 24 | //usage:#define chattr_full_usage "\n\n" |
Denys Vlasenko | 36647ab | 2015-10-19 01:29:20 +0200 | [diff] [blame] | 25 | //usage: "Change ext2 file attributes\n" |
Denys Vlasenko | d3147cd | 2017-08-05 20:33:48 +0200 | [diff] [blame] | 26 | //usage: "\n -R Recurse" |
Denys Vlasenko | e2b9215 | 2021-06-14 20:47:20 +0200 | [diff] [blame] | 27 | //usage: "\n -v NUM Set version/generation number" |
Denys Vlasenko | 526b834 | 2021-06-20 10:57:24 +0200 | [diff] [blame] | 28 | //usage: "\n -p NUM Set project number" |
Denys Vlasenko | d3147cd | 2017-08-05 20:33:48 +0200 | [diff] [blame] | 29 | //-V, -f accepted but ignored |
Pere Orga | 6a3e01d | 2011-04-01 22:56:30 +0200 | [diff] [blame] | 30 | //usage: "\nModifiers:" |
Denys Vlasenko | 36647ab | 2015-10-19 01:29:20 +0200 | [diff] [blame] | 31 | //usage: "\n -,+,= Remove/add/set attributes" |
Pere Orga | 6a3e01d | 2011-04-01 22:56:30 +0200 | [diff] [blame] | 32 | //usage: "\nAttributes:" |
Denys Vlasenko | e2b9215 | 2021-06-14 20:47:20 +0200 | [diff] [blame] | 33 | //usage: "\n A No atime" |
| 34 | //usage: "\n a Append only" |
Denys Vlasenko | e7ff017 | 2021-06-23 09:42:01 +0200 | [diff] [blame] | 35 | //usage: "\n C No copy-on-write" |
Denys Vlasenko | e2b9215 | 2021-06-14 20:47:20 +0200 | [diff] [blame] | 36 | //usage: "\n c Compressed" |
| 37 | //usage: "\n D Synchronous dir updates" |
Pere Orga | 6a3e01d | 2011-04-01 22:56:30 +0200 | [diff] [blame] | 38 | //usage: "\n d Don't backup with dump" |
Denys Vlasenko | e7ff017 | 2021-06-23 09:42:01 +0200 | [diff] [blame] | 39 | //usage: "\n E Encrypted" |
| 40 | //usage: "\n e File uses extents" |
| 41 | //usage: "\n F Case-insensitive dir" |
| 42 | //usage: "\n I Indexed dir" |
Denys Vlasenko | e2b9215 | 2021-06-14 20:47:20 +0200 | [diff] [blame] | 43 | //usage: "\n i Immutable" |
| 44 | //usage: "\n j Write data to journal first" |
Denys Vlasenko | e7ff017 | 2021-06-23 09:42:01 +0200 | [diff] [blame] | 45 | //usage: "\n N File is stored in inode" |
| 46 | //usage: "\n P Hierarchical project ID dir" |
Denys Vlasenko | e2b9215 | 2021-06-14 20:47:20 +0200 | [diff] [blame] | 47 | //usage: "\n S Synchronous file updates" |
Denys Vlasenko | e7ff017 | 2021-06-23 09:42:01 +0200 | [diff] [blame] | 48 | //usage: "\n s Zero storage when deleted" |
| 49 | //usage: "\n T Top of dir hierarchy" |
Denys Vlasenko | e2b9215 | 2021-06-14 20:47:20 +0200 | [diff] [blame] | 50 | //usage: "\n t Don't tail-merge with other files" |
| 51 | //usage: "\n u Allow undelete" |
Denys Vlasenko | e7ff017 | 2021-06-23 09:42:01 +0200 | [diff] [blame] | 52 | //usage: "\n V Verity" |
Pere Orga | 6a3e01d | 2011-04-01 22:56:30 +0200 | [diff] [blame] | 53 | |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 54 | #include "libbb.h" |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 55 | #include "e2fs_lib.h" |
| 56 | |
Denys Vlasenko | 526b834 | 2021-06-20 10:57:24 +0200 | [diff] [blame] | 57 | #define OPT_ADD (1 << 0) |
| 58 | #define OPT_REM (1 << 1) |
| 59 | #define OPT_SET (1 << 2) |
| 60 | #define OPT_SET_VER (1 << 3) |
| 61 | #define OPT_SET_PROJ (1 << 4) |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 62 | |
Denis Vlasenko | 8acf521 | 2007-04-15 11:48:27 +0000 | [diff] [blame] | 63 | struct globals { |
Denys Vlasenko | 96436fb | 2021-06-23 12:45:51 +0200 | [diff] [blame] | 64 | unsigned version; |
| 65 | unsigned af; |
| 66 | unsigned rf; |
Denys Vlasenko | d3147cd | 2017-08-05 20:33:48 +0200 | [diff] [blame] | 67 | int flags; |
Denys Vlasenko | 526b834 | 2021-06-20 10:57:24 +0200 | [diff] [blame] | 68 | uint32_t projid; |
Denis Vlasenko | 8acf521 | 2007-04-15 11:48:27 +0000 | [diff] [blame] | 69 | smallint recursive; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | static unsigned long get_flag(char c) |
| 73 | { |
Denis Vlasenko | d059ddc | 2007-10-30 19:36:07 +0000 | [diff] [blame] | 74 | const char *fp = strchr(e2attr_flags_sname_chattr, c); |
| 75 | if (fp) |
| 76 | return e2attr_flags_value_chattr[fp - e2attr_flags_sname_chattr]; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 77 | bb_show_usage(); |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 78 | } |
| 79 | |
Denys Vlasenko | d3147cd | 2017-08-05 20:33:48 +0200 | [diff] [blame] | 80 | static char** decode_arg(char **argv, struct globals *gp) |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 81 | { |
Denys Vlasenko | 96436fb | 2021-06-23 12:45:51 +0200 | [diff] [blame] | 82 | unsigned *fl; |
Denys Vlasenko | d3147cd | 2017-08-05 20:33:48 +0200 | [diff] [blame] | 83 | const char *arg = *argv; |
| 84 | char opt = *arg; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 85 | |
Denis Vlasenko | 8acf521 | 2007-04-15 11:48:27 +0000 | [diff] [blame] | 86 | fl = &gp->af; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 87 | if (opt == '-') { |
Denys Vlasenko | 5709b51 | 2021-06-23 18:57:00 +0200 | [diff] [blame] | 88 | /* gp->flags |= OPT_REM; - WRONG, it can be an option */ |
| 89 | /* testcase: chattr =ae -R FILE should not complain "= is incompatible with - and +" */ |
| 90 | /* (and should not read flags, with =FLAGS they can be just set directly) */ |
Denis Vlasenko | 8acf521 | 2007-04-15 11:48:27 +0000 | [diff] [blame] | 91 | fl = &gp->rf; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 92 | } else if (opt == '+') { |
Denis Vlasenko | 8acf521 | 2007-04-15 11:48:27 +0000 | [diff] [blame] | 93 | gp->flags |= OPT_ADD; |
Denys Vlasenko | d3147cd | 2017-08-05 20:33:48 +0200 | [diff] [blame] | 94 | } else { /* if (opt == '=') */ |
Denis Vlasenko | 8acf521 | 2007-04-15 11:48:27 +0000 | [diff] [blame] | 95 | gp->flags |= OPT_SET; |
Denys Vlasenko | d3147cd | 2017-08-05 20:33:48 +0200 | [diff] [blame] | 96 | } |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 97 | |
Denys Vlasenko | d3147cd | 2017-08-05 20:33:48 +0200 | [diff] [blame] | 98 | while (*++arg) { |
| 99 | if (opt == '-') { |
| 100 | //e2fsprogs-1.43.1 accepts: |
| 101 | // "-RRR", "-RRRv VER" and even "-ARRRva VER" and "-vvv V1 V2 V3" |
| 102 | // but not "-vVER". |
| 103 | // IOW: options are parsed as part of "remove attrs" strings, |
| 104 | // if "v" is seen, next argv[] is VER, even if more opts/attrs follow in this argv[]! |
| 105 | if (*arg == 'R') { |
| 106 | gp->recursive = 1; |
| 107 | continue; |
| 108 | } |
| 109 | if (*arg == 'V') { |
| 110 | /*"verbose and print program version" (nop for now) */; |
| 111 | continue; |
| 112 | } |
| 113 | if (*arg == 'f') { |
| 114 | /*"suppress most error messages" (nop) */; |
| 115 | continue; |
| 116 | } |
| 117 | if (*arg == 'v') { |
| 118 | if (!*++argv) |
| 119 | bb_show_usage(); |
Denys Vlasenko | 5709b51 | 2021-06-23 18:57:00 +0200 | [diff] [blame] | 120 | gp->version = xatou(*argv); |
Denys Vlasenko | d3147cd | 2017-08-05 20:33:48 +0200 | [diff] [blame] | 121 | gp->flags |= OPT_SET_VER; |
| 122 | continue; |
| 123 | } |
Denys Vlasenko | 526b834 | 2021-06-20 10:57:24 +0200 | [diff] [blame] | 124 | if (*arg == 'p') { |
| 125 | if (!*++argv) |
| 126 | bb_show_usage(); |
| 127 | gp->projid = xatou32(*argv); |
| 128 | gp->flags |= OPT_SET_PROJ; |
| 129 | continue; |
| 130 | } |
Denys Vlasenko | d3147cd | 2017-08-05 20:33:48 +0200 | [diff] [blame] | 131 | /* not a known option, try as an attribute */ |
Denys Vlasenko | 5709b51 | 2021-06-23 18:57:00 +0200 | [diff] [blame] | 132 | gp->flags |= OPT_REM; |
Denys Vlasenko | d3147cd | 2017-08-05 20:33:48 +0200 | [diff] [blame] | 133 | } |
Denys Vlasenko | 5709b51 | 2021-06-23 18:57:00 +0200 | [diff] [blame] | 134 | *fl |= get_flag(*arg); /* aborts on bad flag letter */ |
Denys Vlasenko | d3147cd | 2017-08-05 20:33:48 +0200 | [diff] [blame] | 135 | } |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 136 | |
Denys Vlasenko | d3147cd | 2017-08-05 20:33:48 +0200 | [diff] [blame] | 137 | return argv; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 138 | } |
| 139 | |
Denis Vlasenko | 8acf521 | 2007-04-15 11:48:27 +0000 | [diff] [blame] | 140 | static void change_attributes(const char *name, struct globals *gp); |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 141 | |
Denys Vlasenko | d5f1b1b | 2009-06-05 12:06:05 +0200 | [diff] [blame] | 142 | static int FAST_FUNC chattr_dir_proc(const char *dir_name, struct dirent *de, void *gp) |
Denis Vlasenko | 5dd7ef0 | 2006-12-26 03:36:28 +0000 | [diff] [blame] | 143 | { |
Denys Vlasenko | 0e55af6 | 2021-06-23 19:44:15 +0200 | [diff] [blame] | 144 | //TODO: use de->d_type (if it's not DT_UNKNOWN) to skip !(REG || DIR || LNK) entries without lstat? |
| 145 | |
Denis Vlasenko | 5dd7ef0 | 2006-12-26 03:36:28 +0000 | [diff] [blame] | 146 | char *path = concat_subpath_file(dir_name, de->d_name); |
| 147 | /* path is NULL if de->d_name is "." or "..", else... */ |
| 148 | if (path) { |
Denis Vlasenko | 8acf521 | 2007-04-15 11:48:27 +0000 | [diff] [blame] | 149 | change_attributes(path, gp); |
Denis Vlasenko | 5dd7ef0 | 2006-12-26 03:36:28 +0000 | [diff] [blame] | 150 | free(path); |
| 151 | } |
| 152 | return 0; |
| 153 | } |
| 154 | |
Denis Vlasenko | 8acf521 | 2007-04-15 11:48:27 +0000 | [diff] [blame] | 155 | static void change_attributes(const char *name, struct globals *gp) |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 156 | { |
Denys Vlasenko | 96436fb | 2021-06-23 12:45:51 +0200 | [diff] [blame] | 157 | unsigned fsflags; |
| 158 | int fd; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 159 | struct stat st; |
| 160 | |
Denis Vlasenko | 8acf521 | 2007-04-15 11:48:27 +0000 | [diff] [blame] | 161 | if (lstat(name, &st) != 0) { |
Denys Vlasenko | 85a5bc9 | 2021-06-23 15:33:22 +0200 | [diff] [blame] | 162 | bb_perror_msg("can't stat '%s'", name); |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 163 | return; |
| 164 | } |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 165 | |
| 166 | /* Don't try to open device files, fifos etc. We probably |
| 167 | * ought to display an error if the file was explicitly given |
| 168 | * on the command line (whether or not recursive was |
| 169 | * requested). */ |
| 170 | if (!S_ISREG(st.st_mode) && !S_ISLNK(st.st_mode) && !S_ISDIR(st.st_mode)) |
| 171 | return; |
| 172 | |
Denys Vlasenko | 9468ea0 | 2021-06-24 01:07:56 +0200 | [diff] [blame] | 173 | /* There is no way to run needed ioctls on a symlink. |
| 174 | * open(O_PATH | O_NOFOLLOW) _can_ be used to get a fd referring to the symlink, |
| 175 | * but ioctls fail on such a fd (tried on 4.12.0 kernel). |
| 176 | * e2fsprogs-1.46.2 uses open(O_NOFOLLOW), it fails on symlinks. |
| 177 | */ |
| 178 | fd = open_or_warn(name, O_RDONLY | O_NONBLOCK | O_NOCTTY | O_NOFOLLOW); |
Denys Vlasenko | 96436fb | 2021-06-23 12:45:51 +0200 | [diff] [blame] | 179 | if (fd >= 0) { |
| 180 | int r; |
Denys Vlasenko | 526b834 | 2021-06-20 10:57:24 +0200 | [diff] [blame] | 181 | |
Denys Vlasenko | 96436fb | 2021-06-23 12:45:51 +0200 | [diff] [blame] | 182 | if (gp->flags & OPT_SET_VER) { |
| 183 | r = ioctl(fd, EXT2_IOC_SETVERSION, &gp->version); |
| 184 | if (r != 0) |
| 185 | bb_perror_msg("setting %s on %s", "version", name); |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 186 | } |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 187 | |
Denys Vlasenko | 96436fb | 2021-06-23 12:45:51 +0200 | [diff] [blame] | 188 | if (gp->flags & OPT_SET_PROJ) { |
| 189 | struct ext2_fsxattr fsxattr; |
| 190 | r = ioctl(fd, EXT2_IOC_FSGETXATTR, &fsxattr); |
Denys Vlasenko | 85a5bc9 | 2021-06-23 15:33:22 +0200 | [diff] [blame] | 191 | /* note: ^^^ may fail in 32-bit userspace on 64-bit kernel (seen on 4.12.0) */ |
Denys Vlasenko | 0e55af6 | 2021-06-23 19:44:15 +0200 | [diff] [blame] | 192 | if (r != 0) { |
Denys Vlasenko | 96436fb | 2021-06-23 12:45:51 +0200 | [diff] [blame] | 193 | bb_perror_msg("getting %s on %s", "project ID", name); |
Denys Vlasenko | 0e55af6 | 2021-06-23 19:44:15 +0200 | [diff] [blame] | 194 | } else { |
| 195 | fsxattr.fsx_projid = gp->projid; |
| 196 | r = ioctl(fd, EXT2_IOC_FSSETXATTR, &fsxattr); |
| 197 | if (r != 0) |
| 198 | bb_perror_msg("setting %s on %s", "project ID", name); |
| 199 | } |
Denys Vlasenko | 96436fb | 2021-06-23 12:45:51 +0200 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | if (gp->flags & OPT_SET) { |
| 203 | fsflags = gp->af; |
| 204 | } else { |
| 205 | r = ioctl(fd, EXT2_IOC_GETFLAGS, &fsflags); |
| 206 | if (r != 0) { |
| 207 | bb_perror_msg("getting %s on %s", "flags", name); |
| 208 | goto skip_setflags; |
| 209 | } |
| 210 | /*if (gp->flags & OPT_REM) - not needed, rf is zero otherwise */ |
| 211 | fsflags &= ~gp->rf; |
| 212 | /*if (gp->flags & OPT_ADD) - not needed, af is zero otherwise */ |
| 213 | fsflags |= gp->af; |
| 214 | // What is this? And why it's not done for SET case? |
| 215 | if (!S_ISDIR(st.st_mode)) |
| 216 | fsflags &= ~EXT2_DIRSYNC_FL; |
| 217 | } |
| 218 | r = ioctl(fd, EXT2_IOC_SETFLAGS, &fsflags); |
| 219 | if (r != 0) |
| 220 | bb_perror_msg("setting %s on %s", "flags", name); |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 221 | skip_setflags: |
Denys Vlasenko | 96436fb | 2021-06-23 12:45:51 +0200 | [diff] [blame] | 222 | close(fd); |
| 223 | } |
| 224 | |
Denis Vlasenko | 8acf521 | 2007-04-15 11:48:27 +0000 | [diff] [blame] | 225 | if (gp->recursive && S_ISDIR(st.st_mode)) |
| 226 | iterate_on_dir(name, chattr_dir_proc, gp); |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 227 | } |
| 228 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 229 | int chattr_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 230 | int chattr_main(int argc UNUSED_PARAM, char **argv) |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 231 | { |
Denis Vlasenko | 8acf521 | 2007-04-15 11:48:27 +0000 | [diff] [blame] | 232 | struct globals g; |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 233 | |
Denis Vlasenko | 8acf521 | 2007-04-15 11:48:27 +0000 | [diff] [blame] | 234 | memset(&g, 0, sizeof(g)); |
| 235 | |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 236 | /* parse the args */ |
Denys Vlasenko | d3147cd | 2017-08-05 20:33:48 +0200 | [diff] [blame] | 237 | for (;;) { |
| 238 | char *arg = *++argv; |
| 239 | if (!arg) |
| 240 | bb_show_usage(); |
| 241 | if (arg[0] != '-' && arg[0] != '+' && arg[0] != '=') |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 242 | break; |
Denys Vlasenko | d3147cd | 2017-08-05 20:33:48 +0200 | [diff] [blame] | 243 | |
| 244 | argv = decode_arg(argv, &g); |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 245 | } |
Denys Vlasenko | d3147cd | 2017-08-05 20:33:48 +0200 | [diff] [blame] | 246 | /* note: on loop exit, remaining argv[] is never empty */ |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 247 | |
| 248 | /* run sanity checks on all the arguments given us */ |
Denis Vlasenko | 8acf521 | 2007-04-15 11:48:27 +0000 | [diff] [blame] | 249 | if ((g.flags & OPT_SET) && (g.flags & (OPT_ADD|OPT_REM))) |
James Byrne | 6937487 | 2019-07-02 11:35:03 +0200 | [diff] [blame] | 250 | bb_simple_error_msg_and_die("= is incompatible with - and +"); |
Denis Vlasenko | 8acf521 | 2007-04-15 11:48:27 +0000 | [diff] [blame] | 251 | if (g.rf & g.af) |
James Byrne | 6937487 | 2019-07-02 11:35:03 +0200 | [diff] [blame] | 252 | bb_simple_error_msg_and_die("can't set and unset a flag"); |
Denis Vlasenko | 8acf521 | 2007-04-15 11:48:27 +0000 | [diff] [blame] | 253 | if (!g.flags) |
Denys Vlasenko | 5709b51 | 2021-06-23 18:57:00 +0200 | [diff] [blame] | 254 | bb_simple_error_msg_and_die("must use -v, -p, =, - or +"); |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 255 | |
| 256 | /* now run chattr on all the files passed to us */ |
Denis Vlasenko | 8acf521 | 2007-04-15 11:48:27 +0000 | [diff] [blame] | 257 | do change_attributes(*argv, &g); while (*++argv); |
Denis Vlasenko | c4f623e | 2006-12-26 01:30:59 +0000 | [diff] [blame] | 258 | |
| 259 | return EXIT_SUCCESS; |
| 260 | } |