[Toybox] [patch] stat - support %C format
Rob Landley
rob at landley.net
Fri Jul 10 10:32:11 PDT 2015
On 07/09/2015 12:42 AM, Hyejin Kim wrote:
> 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
> + */
Ah, so the reason you moved the filesystem sequences was so STAT_C would
attach the %C help text to the end of the _files_ block instead of the
filesystem block.
Sigh. There's missing infrastructure in the help parsing, I need to be
able to specify where to insert help text for suboptions. (The default
behavior is fine most of the time, but sometimes you need to override
it. This has come up for the -Z stuff a lot.
Ok, what would be the right way to indicate this... How about @STAT_C at
the left edge? Lemme take a swing at this and see what I can do...
> #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);
> + }
> + }
Your indentation here is strange. (I can fix it up, just FYI.)
Lemme go upgrade scripts/config2help.c...
Rob
Rob
1436549531.0
More information about the Toybox
mailing list