aboutsummaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-01-23 18:43:43 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2017-01-23 18:43:43 +0100
commit5d43ddc59bf62d03cfc0017f24e36533294c455e (patch)
tree4ef2fcc0beb10d7a87f2ecbcb513c8b18583893a /coreutils
parentb60686cc2a9550527a548f9e52ff4dd96bdfe222 (diff)
downloadbusybox-w32-5d43ddc59bf62d03cfc0017f24e36533294c455e.tar.gz
busybox-w32-5d43ddc59bf62d03cfc0017f24e36533294c455e.tar.bz2
busybox-w32-5d43ddc59bf62d03cfc0017f24e36533294c455e.zip
ls: handle -s through option_mask32
function old new delta scan_and_display_dirs_recur 493 494 +1 sort_and_display_files 424 423 -1 ls_main 682 677 -5 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/ls.c32
1 files changed, 16 insertions, 16 deletions
diff --git a/coreutils/ls.c b/coreutils/ls.c
index 7ed6a1fdc..b138520b3 100644
--- a/coreutils/ls.c
+++ b/coreutils/ls.c
@@ -198,7 +198,6 @@ SPLIT_SUBDIR = 2,
198 198
199/* 51306 lrwxrwxrwx 1 root root 2 May 11 01:43 /bin/view -> vi* */ 199/* 51306 lrwxrwxrwx 1 root root 2 May 11 01:43 /bin/view -> vi* */
200/* what file information will be listed */ 200/* what file information will be listed */
201LIST_BLOCKS = 1 << 1,
202LIST_MODEBITS = 1 << 2, 201LIST_MODEBITS = 1 << 2,
203LIST_NLINKS = 1 << 3, 202LIST_NLINKS = 1 << 3,
204LIST_ID_NAME = 1 << 4, 203LIST_ID_NAME = 1 << 4,
@@ -210,23 +209,21 @@ LIST_FULLTIME = 1 << 9,
210LIST_SYMLINK = 1 << 10, 209LIST_SYMLINK = 1 << 10,
211LIST_FILETYPE = 1 << 11, /* show / suffix for dirs */ 210LIST_FILETYPE = 1 << 11, /* show / suffix for dirs */
212LIST_CLASSIFY = 1 << 12, /* requires LIST_FILETYPE, also show *,|,@,= suffixes */ 211LIST_CLASSIFY = 1 << 12, /* requires LIST_FILETYPE, also show *,|,@,= suffixes */
213LIST_MASK = (LIST_CLASSIFY << 1) - 1, 212
213LIST_LONG = LIST_MODEBITS | LIST_NLINKS | LIST_ID_NAME | LIST_SIZE | \
214 LIST_DATE_TIME | LIST_SYMLINK,
214 215
215/* what files will be displayed */ 216/* what files will be displayed */
216DISP_DIRNAME = 1 << 13, /* 2 or more items? label directories */ 217DISP_DIRNAME = 1 << 13, /* 2 or more items? label directories */
217DISP_NOLIST = 1 << 16, /* show directory as itself, not contents */ 218DISP_NOLIST = 1 << 16, /* show directory as itself, not contents */
218DISP_RECURSIVE = 1 << 17, /* show directory and everything below it */ 219DISP_RECURSIVE = 1 << 17, /* show directory and everything below it */
219DISP_ROWS = 1 << 18, /* print across rows */ 220DISP_ROWS = 1 << 18, /* print across rows */
220DISP_MASK = ((DISP_ROWS << 1) - 1) & ~(DISP_DIRNAME - 1),
221 221
222/* what is the overall style of the listing */ 222/* what is the overall style of the listing */
223STYLE_COLUMNAR = 1 << 19, /* many records per line */ 223STYLE_COLUMNAR = 1 << 19, /* many records per line */
224STYLE_LONG = 2 << 19, /* one record per line, extended info */ 224STYLE_LONG = 2 << 19, /* one record per line, extended info */
225STYLE_SINGLE = 3 << 19, /* one record per line */ 225STYLE_SINGLE = 3 << 19, /* one record per line */
226STYLE_MASK = STYLE_SINGLE, 226STYLE_MASK = STYLE_SINGLE,
227
228LIST_LONG = LIST_MODEBITS | LIST_NLINKS | LIST_ID_NAME | LIST_SIZE | \
229 LIST_DATE_TIME | LIST_SYMLINK,
230}; 227};
231 228
232/* -Cadi1l Std options, busybox always supports */ 229/* -Cadi1l Std options, busybox always supports */
@@ -262,7 +259,7 @@ enum {
262 OPT_l = (1 << 5), 259 OPT_l = (1 << 5),
263 OPT_g = (1 << 6), 260 OPT_g = (1 << 6),
264 //OPT_n = (1 << 7), 261 //OPT_n = (1 << 7),
265 //OPT_s = (1 << 8), 262 OPT_s = (1 << 8),
266 //OPT_x = (1 << 9), 263 //OPT_x = (1 << 9),
267 OPT_A = (1 << 10), 264 OPT_A = (1 << 10),
268 //OPT_k = (1 << 11), 265 //OPT_k = (1 << 11),
@@ -321,7 +318,7 @@ static const uint32_t opt_flags[] = {
321 LIST_LONG | STYLE_LONG, /* l - by keeping it after -1, "ls -l -1" ignores -1 */ 318 LIST_LONG | STYLE_LONG, /* l - by keeping it after -1, "ls -l -1" ignores -1 */
322 LIST_LONG | STYLE_LONG, /* g (don't show owner) - handled via OPT_g. assumes l */ 319 LIST_LONG | STYLE_LONG, /* g (don't show owner) - handled via OPT_g. assumes l */
323 LIST_LONG | STYLE_LONG | LIST_ID_NUMERIC, /* n (assumes l) */ 320 LIST_LONG | STYLE_LONG | LIST_ID_NUMERIC, /* n (assumes l) */
324 LIST_BLOCKS, /* s */ 321 0, /* s */
325 DISP_ROWS | STYLE_COLUMNAR, /* x */ 322 DISP_ROWS | STYLE_COLUMNAR, /* x */
326 0, /* A */ 323 0, /* A */
327 ENABLE_SELINUX * (LIST_CONTEXT|STYLE_SINGLE), /* k (ignored if !SELINUX) */ 324 ENABLE_SELINUX * (LIST_CONTEXT|STYLE_SINGLE), /* k (ignored if !SELINUX) */
@@ -559,7 +556,7 @@ static NOINLINE unsigned display_single(const struct dnode *dn)
559 if (option_mask32 & OPT_i) /* list inodes */ 556 if (option_mask32 & OPT_i) /* list inodes */
560 column += printf("%7llu ", (long long) dn->dn_ino); 557 column += printf("%7llu ", (long long) dn->dn_ino);
561//TODO: -h should affect -s too: 558//TODO: -h should affect -s too:
562 if (G.all_fmt & LIST_BLOCKS) 559 if (option_mask32 & OPT_s) /* list allocated blocks */
563 column += printf("%6"OFF_FMT"u ", (off_t) (dn->dn_blocks >> 1)); 560 column += printf("%6"OFF_FMT"u ", (off_t) (dn->dn_blocks >> 1));
564 if (G.all_fmt & LIST_MODEBITS) 561 if (G.all_fmt & LIST_MODEBITS)
565 column += printf("%-10s ", (char *) bb_mode_string(dn->dn_mode)); 562 column += printf("%-10s ", (char *) bb_mode_string(dn->dn_mode));
@@ -704,10 +701,11 @@ static void display_files(struct dnode **dn, unsigned nfiles)
704 if (column_width < len) 701 if (column_width < len)
705 column_width = len; 702 column_width = len;
706 } 703 }
707 column_width += 2 + 704 column_width += 2
708 IF_SELINUX( ((G.all_fmt & LIST_CONTEXT) ? 33 : 0) + ) 705 IF_SELINUX(+ ((G.all_fmt & LIST_CONTEXT) ? 33 : 0))
709 ((option_mask32 & OPT_i) ? 8 : 0) /* inode# width */ 706 + ((option_mask32 & OPT_i) ? 8 : 0) /* inode# width */
710 + ((G.all_fmt & LIST_BLOCKS) ? 5 : 0); 707 + ((option_mask32 & OPT_s) ? 5 : 0) /* "alloc block" width */
708 ;
711 ncols = (unsigned)G_terminal_width / column_width; 709 ncols = (unsigned)G_terminal_width / column_width;
712 } 710 }
713 711
@@ -1069,8 +1067,11 @@ static void scan_and_display_dirs_recur(struct dnode **dn, int first)
1069 } 1067 }
1070 subdnp = scan_one_dir((*dn)->fullname, &nfiles); 1068 subdnp = scan_one_dir((*dn)->fullname, &nfiles);
1071#if ENABLE_DESKTOP 1069#if ENABLE_DESKTOP
1072 if ((G.all_fmt & STYLE_MASK) == STYLE_LONG || (G.all_fmt & LIST_BLOCKS)) 1070 if ((G.all_fmt & STYLE_MASK) == STYLE_LONG
1071 || (option_mask32 & OPT_s)
1072 ) {
1073 printf("total %"OFF_FMT"u\n", calculate_blocks(subdnp)); 1073 printf("total %"OFF_FMT"u\n", calculate_blocks(subdnp));
1074 }
1074#endif 1075#endif
1075 if (nfiles > 0) { 1076 if (nfiles > 0) {
1076 /* list all files at this level */ 1077 /* list all files at this level */
@@ -1247,8 +1248,7 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
1247 cur = my_stat(*argv, *argv, 1248 cur = my_stat(*argv, *argv,
1248 /* follow links on command line unless -l, -s or -F: */ 1249 /* follow links on command line unless -l, -s or -F: */
1249 !((G.all_fmt & STYLE_MASK) == STYLE_LONG 1250 !((G.all_fmt & STYLE_MASK) == STYLE_LONG
1250 || (G.all_fmt & LIST_BLOCKS) 1251 || (option_mask32 & (OPT_s|OPT_F))
1251 || (option_mask32 & OPT_F)
1252 ) 1252 )
1253 /* ... or if -H: */ 1253 /* ... or if -H: */
1254 || (option_mask32 & OPT_H) 1254 || (option_mask32 & OPT_H)