printmode: update print_symbolic_mode_t decoder

* printmode.c (print_symbolic_mode_t): Rewrite.
* xlat/modetypes.in: Add fallback values.
* xlat/modeflags.in: New file.
This commit is contained in:
Eugene Syromyatnikov 2018-10-07 14:31:00 +02:00
parent 2a905d1b00
commit be048f54c5
3 changed files with 33 additions and 21 deletions

View File

@ -36,28 +36,35 @@
#include <sys/stat.h> #include <sys/stat.h>
#include "xlat/modetypes.h" #include "xlat/modetypes.h"
#include "xlat/modeflags.h"
void void
print_symbolic_mode_t(const unsigned int mode) print_symbolic_mode_t(const unsigned int mode)
{ {
const char *ifmt = ""; const char *ifmt = xlookup(modetypes, mode & S_IFMT);
const unsigned int flags = mode & modeflags->flags_mask;
bool raw = (!ifmt && !flags)
|| xlat_verbose(xlat_verbosity) == XLAT_STYLE_RAW;
if (mode & S_IFMT) if (raw || xlat_verbose(xlat_verbosity) == XLAT_STYLE_VERBOSE)
ifmt = xlookup(modetypes, mode & S_IFMT);
if (!ifmt || xlat_verbose(xlat_verbosity) != XLAT_STYLE_ABBREV)
tprintf("%#03o", mode); tprintf("%#03o", mode);
if (raw)
if (!ifmt || xlat_verbose(xlat_verbosity) == XLAT_STYLE_RAW)
return; return;
(xlat_verbose(xlat_verbosity) == XLAT_STYLE_ABBREV if (xlat_verbose(xlat_verbosity) == XLAT_STYLE_VERBOSE)
? tprintf : tprintf_comment)("%s%s%s%s%s%#03o", printf(" /* ");
ifmt, ifmt[0] ? "|" : "", if (ifmt) {
(mode & S_ISUID) ? "S_ISUID|" : "", printxlat_ex(ifmt, mode & S_IFMT, XLAT_STYLE_FMT_O);
(mode & S_ISGID) ? "S_ISGID|" : "", tprints("|");
(mode & S_ISVTX) ? "S_ISVTX|" : "", }
mode & ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX)); if (flags) {
printflags(modeflags, flags, NULL);
tprints("|");
}
tprintf("%#03o", mode - flags - ifmt ? mode & S_IFMT : 0);
if (xlat_verbose(xlat_verbosity) == XLAT_STYLE_VERBOSE)
printf(" */")
} }
void void

4
xlat/modeflags.in Normal file
View File

@ -0,0 +1,4 @@
#sorted
S_ISVTX 0001000
S_ISGID 0002000
S_ISUID 0004000

View File

@ -1,7 +1,8 @@
S_IFREG #sorted
S_IFSOCK S_IFIFO 0010000
S_IFIFO S_IFCHR 0020000
S_IFLNK S_IFDIR 0040000
S_IFDIR S_IFBLK 0060000
S_IFBLK S_IFREG 0100000
S_IFCHR S_IFLNK 0120000
S_IFSOCK 0140000