diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2017-01-23 19:30:14 +0100 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-01-23 19:30:14 +0100 |
| commit | a1cbaca1ba6f4a3ffc7727fcd4c4ebb61c47e1a7 (patch) | |
| tree | 724e40235c9e3afcbaba94b6369e390574daf9ff /coreutils | |
| parent | 2c3131d88e438fff3cc578293e82cc5ffd4693d1 (diff) | |
| download | busybox-w32-a1cbaca1ba6f4a3ffc7727fcd4c4ebb61c47e1a7.tar.gz busybox-w32-a1cbaca1ba6f4a3ffc7727fcd4c4ebb61c47e1a7.tar.bz2 busybox-w32-a1cbaca1ba6f4a3ffc7727fcd4c4ebb61c47e1a7.zip | |
ls: make -Z output compatible with GNU coreutils 8.25
This also makes it clear that LIST_MODEBITS == LIST_LOPT
function old new delta
ls_main 752 777 +25
display_files 400 399 -1
display_single 1055 1053 -2
my_stat 320 317 -3
packed_usage 32311 32280 -31
.rodata 168895 168864 -31
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/5 up/down: 25/-68) Total: -43 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils')
| -rw-r--r-- | coreutils/ls.c | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/coreutils/ls.c b/coreutils/ls.c index b7eded73b..70118b1b2 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c | |||
| @@ -154,7 +154,6 @@ | |||
| 154 | //usage: ) | 154 | //usage: ) |
| 155 | //usage: "\n -r Reverse sort order" | 155 | //usage: "\n -r Reverse sort order" |
| 156 | //usage: IF_SELINUX( | 156 | //usage: IF_SELINUX( |
| 157 | //usage: "\n -k List security context" | ||
| 158 | //usage: "\n -Z List security context and permission" | 157 | //usage: "\n -Z List security context and permission" |
| 159 | //usage: ) | 158 | //usage: ) |
| 160 | //usage: IF_FEATURE_LS_WIDTH( | 159 | //usage: IF_FEATURE_LS_WIDTH( |
| @@ -198,16 +197,14 @@ SPLIT_SUBDIR = 2, | |||
| 198 | 197 | ||
| 199 | /* 51306 lrwxrwxrwx 1 root root 2 May 11 01:43 /bin/view -> vi* */ | 198 | /* 51306 lrwxrwxrwx 1 root root 2 May 11 01:43 /bin/view -> vi* */ |
| 200 | /* what file information will be listed */ | 199 | /* what file information will be listed */ |
| 201 | LIST_MODEBITS = 1 << 0, | ||
| 202 | LIST_LOPT = 1 << 1, /* long listing (-l and equivalents) */ | 200 | LIST_LOPT = 1 << 1, /* long listing (-l and equivalents) */ |
| 203 | LIST_ID_NAME = 1 << 2, | 201 | LIST_ID_NAME = 1 << 2, |
| 204 | LIST_ID_NUMERIC = 1 << 3, | 202 | LIST_ID_NUMERIC = 1 << 3, |
| 205 | LIST_CONTEXT = 1 << 4, | ||
| 206 | LIST_FULLTIME = 1 << 5, | 203 | LIST_FULLTIME = 1 << 5, |
| 207 | LIST_FILETYPE = 1 << 6, /* show / suffix for dirs */ | 204 | LIST_FILETYPE = 1 << 6, /* show / suffix for dirs */ |
| 208 | LIST_CLASSIFY = 1 << 7, /* requires LIST_FILETYPE, also show *,|,@,= suffixes */ | 205 | LIST_CLASSIFY = 1 << 7, /* requires LIST_FILETYPE, also show *,|,@,= suffixes */ |
| 209 | 206 | ||
| 210 | LIST_LONG = LIST_LOPT | LIST_MODEBITS | LIST_ID_NAME, | 207 | LIST_LONG = LIST_LOPT | LIST_ID_NAME, |
| 211 | 208 | ||
| 212 | /* what files will be displayed */ | 209 | /* what files will be displayed */ |
| 213 | DISP_DIRNAME = 1 << 8, /* 2 or more items? label directories */ | 210 | DISP_DIRNAME = 1 << 8, /* 2 or more items? label directories */ |
| @@ -225,8 +222,8 @@ STYLE_MASK = STYLE_SINGLE, | |||
| 225 | /* -Cadi1l Std options, busybox always supports */ | 222 | /* -Cadi1l Std options, busybox always supports */ |
| 226 | /* -gnsxA Std options, busybox always supports */ | 223 | /* -gnsxA Std options, busybox always supports */ |
| 227 | /* -Q GNU option, busybox always supports */ | 224 | /* -Q GNU option, busybox always supports */ |
| 228 | /* -k SELinux option, busybox always supports (ignores if !SELinux) */ | 225 | /* -k Std options, busybox always supports (by ignoring) */ |
| 229 | /* Std has -k which means "for -s, show sizes in kbytes" */ | 226 | /* It means "for -s, show sizes in kbytes" */ |
| 230 | /* Seems to only affect "POSIXLY_CORRECT=1 ls -sk" */ | 227 | /* Seems to only affect "POSIXLY_CORRECT=1 ls -sk" */ |
| 231 | /* since otherwise -s shows kbytes anyway */ | 228 | /* since otherwise -s shows kbytes anyway */ |
| 232 | /* -LHRctur Std options, busybox optionally supports */ | 229 | /* -LHRctur Std options, busybox optionally supports */ |
| @@ -317,7 +314,7 @@ static const uint32_t opt_flags[] = { | |||
| 317 | 0, /* s */ | 314 | 0, /* s */ |
| 318 | DISP_ROWS | STYLE_COLUMNAR, /* x */ | 315 | DISP_ROWS | STYLE_COLUMNAR, /* x */ |
| 319 | 0, /* A */ | 316 | 0, /* A */ |
| 320 | ENABLE_SELINUX * (LIST_CONTEXT|STYLE_SINGLE), /* k (ignored if !SELINUX) */ | 317 | 0, /* k (ignored) */ |
| 321 | #if ENABLE_FEATURE_LS_FILETYPES | 318 | #if ENABLE_FEATURE_LS_FILETYPES |
| 322 | LIST_FILETYPE | LIST_CLASSIFY, /* F */ | 319 | LIST_FILETYPE | LIST_CLASSIFY, /* F */ |
| 323 | LIST_FILETYPE, /* p */ | 320 | LIST_FILETYPE, /* p */ |
| @@ -326,7 +323,7 @@ static const uint32_t opt_flags[] = { | |||
| 326 | DISP_RECURSIVE, /* R */ | 323 | DISP_RECURSIVE, /* R */ |
| 327 | #endif | 324 | #endif |
| 328 | #if ENABLE_SELINUX | 325 | #if ENABLE_SELINUX |
| 329 | LIST_MODEBITS|LIST_ID_NAME|LIST_CONTEXT|STYLE_SINGLE, /* Z */ | 326 | 0, /* Z */ |
| 330 | #endif | 327 | #endif |
| 331 | (1U << 31) | 328 | (1U << 31) |
| 332 | /* options after Z are not processed through opt_flags */ | 329 | /* options after Z are not processed through opt_flags */ |
| @@ -554,10 +551,12 @@ static NOINLINE unsigned display_single(const struct dnode *dn) | |||
| 554 | //TODO: -h should affect -s too: | 551 | //TODO: -h should affect -s too: |
| 555 | if (option_mask32 & OPT_s) /* show allocated blocks */ | 552 | if (option_mask32 & OPT_s) /* show allocated blocks */ |
| 556 | column += printf("%6"OFF_FMT"u ", (off_t) (dn->dn_blocks >> 1)); | 553 | column += printf("%6"OFF_FMT"u ", (off_t) (dn->dn_blocks >> 1)); |
| 557 | if (G.all_fmt & LIST_MODEBITS) | 554 | if (G.all_fmt & LIST_LOPT) { |
| 555 | /* long listing: show mode */ | ||
| 558 | column += printf("%-10s ", (char *) bb_mode_string(dn->dn_mode)); | 556 | column += printf("%-10s ", (char *) bb_mode_string(dn->dn_mode)); |
| 559 | if (G.all_fmt & LIST_LOPT) /* long listing: show number of links */ | 557 | /* long listing: show number of links */ |
| 560 | column += printf("%4lu ", (long) dn->dn_nlink); | 558 | column += printf("%4lu ", (long) dn->dn_nlink); |
| 559 | } | ||
| 561 | if (G.all_fmt & LIST_ID_NUMERIC) { | 560 | if (G.all_fmt & LIST_ID_NUMERIC) { |
| 562 | if (option_mask32 & OPT_g) | 561 | if (option_mask32 & OPT_g) |
| 563 | column += printf("%-8u ", (int) dn->dn_gid); | 562 | column += printf("%-8u ", (int) dn->dn_gid); |
| @@ -578,6 +577,12 @@ static NOINLINE unsigned display_single(const struct dnode *dn) | |||
| 578 | } | 577 | } |
| 579 | } | 578 | } |
| 580 | #endif | 579 | #endif |
| 580 | #if ENABLE_SELINUX | ||
| 581 | if (option_mask32 & OPT_Z) { | ||
| 582 | column += printf("%-32s ", dn->sid ? dn->sid : "?"); | ||
| 583 | freecon(dn->sid); | ||
| 584 | } | ||
| 585 | #endif | ||
| 581 | if (G.all_fmt & LIST_LOPT) { | 586 | if (G.all_fmt & LIST_LOPT) { |
| 582 | /* long listing: show size */ | 587 | /* long listing: show size */ |
| 583 | if (S_ISBLK(dn->dn_mode) || S_ISCHR(dn->dn_mode)) { | 588 | if (S_ISBLK(dn->dn_mode) || S_ISCHR(dn->dn_mode)) { |
| @@ -624,12 +629,6 @@ static NOINLINE unsigned display_single(const struct dnode *dn) | |||
| 624 | } | 629 | } |
| 625 | #endif | 630 | #endif |
| 626 | } | 631 | } |
| 627 | #if ENABLE_SELINUX | ||
| 628 | if (G.all_fmt & LIST_CONTEXT) { | ||
| 629 | column += printf("%-32s ", dn->sid ? dn->sid : "unknown"); | ||
| 630 | freecon(dn->sid); | ||
| 631 | } | ||
| 632 | #endif | ||
| 633 | 632 | ||
| 634 | #if ENABLE_FEATURE_LS_COLOR | 633 | #if ENABLE_FEATURE_LS_COLOR |
| 635 | if (G_show_color) { | 634 | if (G_show_color) { |
| @@ -698,7 +697,7 @@ static void display_files(struct dnode **dn, unsigned nfiles) | |||
| 698 | column_width = len; | 697 | column_width = len; |
| 699 | } | 698 | } |
| 700 | column_width += 2 | 699 | column_width += 2 |
| 701 | IF_SELINUX(+ ((G.all_fmt & LIST_CONTEXT) ? 33 : 0)) | 700 | + ((option_mask32 & OPT_Z) ? 33 : 0) /* context width */ |
| 702 | + ((option_mask32 & OPT_i) ? 8 : 0) /* inode# width */ | 701 | + ((option_mask32 & OPT_i) ? 8 : 0) /* inode# width */ |
| 703 | + ((option_mask32 & OPT_s) ? 5 : 0) /* "alloc block" width */ | 702 | + ((option_mask32 & OPT_s) ? 5 : 0) /* "alloc block" width */ |
| 704 | ; | 703 | ; |
| @@ -752,7 +751,7 @@ static struct dnode *my_stat(const char *fullname, const char *name, int force_f | |||
| 752 | 751 | ||
| 753 | if ((option_mask32 & OPT_L) || force_follow) { | 752 | if ((option_mask32 & OPT_L) || force_follow) { |
| 754 | #if ENABLE_SELINUX | 753 | #if ENABLE_SELINUX |
| 755 | if (is_selinux_enabled()) { | 754 | if (option_mask32 & OPT_Z) { |
| 756 | getfilecon(fullname, &cur->sid); | 755 | getfilecon(fullname, &cur->sid); |
| 757 | } | 756 | } |
| 758 | #endif | 757 | #endif |
| @@ -765,7 +764,7 @@ static struct dnode *my_stat(const char *fullname, const char *name, int force_f | |||
| 765 | cur->dn_mode_stat = statbuf.st_mode; | 764 | cur->dn_mode_stat = statbuf.st_mode; |
| 766 | } else { | 765 | } else { |
| 767 | #if ENABLE_SELINUX | 766 | #if ENABLE_SELINUX |
| 768 | if (is_selinux_enabled()) { | 767 | if (option_mask32 & OPT_Z) { |
| 769 | lgetfilecon(fullname, &cur->sid); | 768 | lgetfilecon(fullname, &cur->sid); |
| 770 | } | 769 | } |
| 771 | #endif | 770 | #endif |
| @@ -1182,6 +1181,12 @@ int ls_main(int argc UNUSED_PARAM, char **argv) | |||
| 1182 | G.all_fmt |= flags; | 1181 | G.all_fmt |= flags; |
| 1183 | } | 1182 | } |
| 1184 | } | 1183 | } |
| 1184 | #if ENABLE_SELINUX | ||
| 1185 | if (opt & OPT_Z) { | ||
| 1186 | if (!is_selinux_enabled()) | ||
| 1187 | option_mask32 &= ~OPT_Z; | ||
| 1188 | } | ||
| 1189 | #endif | ||
| 1185 | if (opt & OPT_full_time) | 1190 | if (opt & OPT_full_time) |
| 1186 | G.all_fmt |= LIST_FULLTIME; | 1191 | G.all_fmt |= LIST_FULLTIME; |
| 1187 | 1192 | ||
