summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugene Syromyatnikov <evgsyr@gmail.com>2018-10-07 14:31:00 +0200
committerEugene Syromyatnikov <evgsyr@gmail.com>2022-09-02 17:55:13 +0200
commitc23773a5e712d5b5254e611781e43ba3a918e3a3 (patch)
tree241f1f205365ebf5170856e8a174dd9924ba15fa
parent90d339003e4dfe9d0c2e3c069248021d14856e5e (diff)
downloadstrace-c23773a5e712d5b5254e611781e43ba3a918e3a3.tar.gz
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.
-rw-r--r--src/printmode.c36
-rw-r--r--src/xlat/modeflags.in3
-rw-r--r--src/xlat/modetypes.in15
-rw-r--r--tests/mknod.c8
4 files changed, 41 insertions, 21 deletions
diff --git a/src/printmode.c b/src/printmode.c
index b509411a5..4aba83c3d 100644
--- a/src/printmode.c
+++ b/src/printmode.c
@@ -15,29 +15,37 @@
#include <fcntl.h>
#include <sys/stat.h>
+#include "xlat/modeflags.h"
#include "xlat/modetypes.h"
void
print_symbolic_mode_t(const unsigned int mode)
{
- const char *ifmt = "";
+ const unsigned int fmt = mode & S_IFMT;
+ const char *fmt_str = xlookup(modetypes, fmt);
+ const unsigned int flags = mode & modeflags->flags_mask;
+ bool raw = (!(fmt && fmt_str) && (!flags || fmt))
+ || 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)
PRINT_VAL_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)
+ tprint_comment_begin();
+ if (fmt_str) {
+ print_xlat_ex(fmt, fmt_str, XLAT_STYLE_ABBREV|XLAT_STYLE_FMT_O);
+ tprint_or();
+ }
+ if (flags) {
+ printflags(modeflags, flags, NULL);
+ tprint_or();
+ }
+ PRINT_VAL_03O(mode & ~flags & ~fmt);
+
+ if (xlat_verbose(xlat_verbosity) == XLAT_STYLE_VERBOSE)
+ tprint_comment_end();
}
void
diff --git a/src/xlat/modeflags.in b/src/xlat/modeflags.in
new file mode 100644
index 000000000..faa307f4f
--- /dev/null
+++ b/src/xlat/modeflags.in
@@ -0,0 +1,3 @@
+S_ISUID 0004000
+S_ISGID 0002000
+S_ISVTX 0001000
diff --git a/src/xlat/modetypes.in b/src/xlat/modetypes.in
index 602cb0068..476b4ce15 100644
--- a/src/xlat/modetypes.in
+++ b/src/xlat/modetypes.in
@@ -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
diff --git a/tests/mknod.c b/tests/mknod.c
index e4d0e5fcf..6488d5688 100644
--- a/tests/mknod.c
+++ b/tests/mknod.c
@@ -54,6 +54,14 @@ main(int ac, char **av)
printf("mknod(\"%s\", S_IFIFO|0600) = %s\n",
sample, sprintrc(rc));
+ rc = call_mknod(S_ISUID | 0600, 0);
+ printf("mknod(\"%s\", S_ISUID|0600) = %s\n",
+ sample, sprintrc(rc));
+
+ rc = call_mknod(S_IFMT | 0600, 0);
+ printf("mknod(\"%s\", 0170600) = %s\n",
+ sample, sprintrc(rc));
+
dev = (unsigned long) 0xdeadbeef00000000ULL | makedev(1, 7);
rc = call_mknod(S_IFCHR | 024, dev);