[Toybox] [patch] stat - support %C format
Hyejin Kim
hj8296 at gmail.com
Wed Jul 8 22:42:30 PDT 2015
Hi.
For smack feature, stat command also needs %C format as before jose
mentioned.
So, added it with lsm_ API.
plz, have a look.
toys/other/stat.c | 30 +++++++++++++++++++++++-------
1 file changed, 23 insertions(+), 7 deletions(-)
diff --git a/toys/other/stat.c b/toys/other/stat.c
index d6db44d..e305c28 100644
--- a/toys/other/stat.c
+++ b/toys/other/stat.c
@@ -15,7 +15,13 @@ config STAT
-f display filesystem status instead of file status
-c Output specified FORMAT string instead of default
- The valid format escape sequences for files:
+ The valid format escape sequences for filesystems:
+ %a Available blocks |%b Total blocks |%c Total inodes
+ %d Free inodes |%f Free blocks |%i File system ID
+ %l Max filename length |%n File name |%s Fragment size
+ %S Best transfer size |%t File system type
+
+ The valid format escape sequences for files:
%a Access bits (octal) |%A Access bits (flags)|%b Blocks allocated
%B Bytes per block |%d Device ID (dec) |%D Device ID (hex)
%f All mode bits (hex) |%F File type |%g Group ID
@@ -25,12 +31,15 @@ config STAT
%x Access time |%X Access unix time |%y File write time
%Y File write unix time|%z Dir change time |%Z Dir change unix
time
- The valid format escape sequences for filesystems:
- %a Available blocks |%b Total blocks |%c Total inodes
- %d Free inodes |%f Free blocks |%i File system ID
- %l Max filename length |%n File name |%s Fragment size
- %S Best transfer size |%t File system type
-*/
+config STAT_C
+ bool
+ default y
+ depends on STAT && !TOYBOX_LSM_NONE
+ help
+ usage: stat
+
+ %C Security context
+ */
#define FOR_stat
#include "toys.h"
@@ -70,6 +79,13 @@ static void print_stat(char type)
xprintf("%s", str);
} else if (type == 'b') xprintf("%llu", stat->st_blocks);
else if (type == 'B') xprintf("%lu", stat->st_blksize);
+ else if (CFG_STAT_C && type == 'C') {
+ char *label = NULL;
+ if ((lsm_lget_context(*toys.optargs, (char **)&label) > 0) && label) {
+ xprintf("%s", label);
+ free(label);
+ }
+ }
else if (type == 'd') xprintf("%ldd", stat->st_dev);
else if (type == 'D') xprintf("%llxh", stat->st_dev);
else if (type == 'f') xprintf("%lx", stat->st_mode);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20150709/49b19b1e/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-stat-support-C-format.patch
Type: application/octet-stream
Size: 2472 bytes
Desc: not available
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20150709/49b19b1e/attachment.obj>
More information about the Toybox
mailing list