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 "xlat/modetypes.h"
#include "xlat/modeflags.h"
void
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)
ifmt = xlookup(modetypes, mode & S_IFMT);
if (!ifmt || xlat_verbose(xlat_verbosity) != XLAT_STYLE_ABBREV)
if (raw || xlat_verbose(xlat_verbosity) == XLAT_STYLE_VERBOSE)
tprintf("%#03o", mode);
if (!ifmt || xlat_verbose(xlat_verbosity) == XLAT_STYLE_RAW)
if (raw)
return;
(xlat_verbose(xlat_verbosity) == XLAT_STYLE_ABBREV
? tprintf : tprintf_comment)("%s%s%s%s%s%#03o",
ifmt, ifmt[0] ? "|" : "",
(mode & S_ISUID) ? "S_ISUID|" : "",
(mode & S_ISGID) ? "S_ISGID|" : "",
(mode & S_ISVTX) ? "S_ISVTX|" : "",
mode & ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX));
if (xlat_verbose(xlat_verbosity) == XLAT_STYLE_VERBOSE)
printf(" /* ");
if (ifmt) {
printxlat_ex(ifmt, mode & S_IFMT, XLAT_STYLE_FMT_O);
tprints("|");
}
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

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
S_IFSOCK
S_IFIFO
S_IFLNK
S_IFDIR
S_IFBLK
S_IFCHR
#sorted
S_IFIFO 0010000
S_IFCHR 0020000
S_IFDIR 0040000
S_IFBLK 0060000
S_IFREG 0100000
S_IFLNK 0120000
S_IFSOCK 0140000