aboutsummaryrefslogtreecommitdiff
path: root/toys/other/stat.c
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2019-06-06 15:29:29 -0700
committerRob Landley <rob@landley.net>2019-06-07 10:42:23 -0500
commit7771204cf7bc161822eb636ff6fb30a1579b622d (patch)
treee51e76fa7399fe9894e00a0a1b6b326a28f8650c /toys/other/stat.c
parente94952c598155b9d708f3957f0003086108e8c60 (diff)
downloadtoybox-7771204cf7bc161822eb636ff6fb30a1579b622d.tar.gz
Implement stat %C and find %Z.
We'd documented find %Z but not implemented it. We'd neither documented nor implemented stat's corresponding %C (they'd already taken %Z for ctime, which is ironic because %c/%C sounds more obvious than %z/%Z for that to me).
Diffstat (limited to 'toys/other/stat.c')
-rw-r--r--toys/other/stat.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/toys/other/stat.c b/toys/other/stat.c
index 3f1d1765..054e2ee7 100644
--- a/toys/other/stat.c
+++ b/toys/other/stat.c
@@ -20,14 +20,15 @@ config STAT
The valid format escape sequences for files:
%a Access bits (octal) |%A Access bits (flags)|%b Size/512
- %B Bytes per %b (512) |%d Device ID (dec) |%D Device ID (hex)
- %f All mode bits (hex) |%F File type |%g Group ID
- %G Group name |%h Hard links |%i Inode
- %m Mount point |%n Filename |%N Long filename
- %o I/O block size |%s Size (bytes) |%t Devtype major (hex)
- %T Devtype minor (hex) |%u User ID |%U User name
- %x Access time |%X Access unix time |%y Modification time
- %Y Mod unix time |%z Creation time |%Z Creation unix time
+ %B Bytes per %b (512) |%C Security context |%d Device ID (dec)
+ %D Device ID (hex) |%f All mode bits (hex)|%F File type
+ %g Group ID |%G Group name |%h Hard links
+ %i Inode |%m Mount point |%n Filename
+ %N Long filename |%o I/O block size |%s Size (bytes)
+ %t Devtype major (hex) |%T Devtype minor (hex)|%u User ID
+ %U User name |%x Access time |%X Access unix time
+ %y Modification time |%Y Mod unix time |%z Creation time
+ %Z Creation unix time
The valid format escape sequences for filesystems:
%a Available blocks |%b Total blocks |%c Total inodes
@@ -82,7 +83,12 @@ static void print_stat(char type)
strout(str);
} else if (type == 'b') out('u', stat->st_blocks);
else if (type == 'B') out('d', 512);
- else if (type == 'd') out('d', stat->st_dev);
+ else if (type == 'C') {
+ char *context = NULL;
+
+ strout(lsm_get_context(TT.file, &context) != -1 ? context : "?");
+ free(context);
+ } else if (type == 'd') out('d', stat->st_dev);
else if (type == 'D') out('x', stat->st_dev);
else if (type == 'f') out('x', stat->st_mode);
else if (type == 'F') {