From 52342f5f4c2a9562b28d74f2c016b19beaef8fbc Mon Sep 17 00:00:00 2001 From: Christian Neukirchen Date: Thu, 25 Feb 2016 14:59:50 +0100 Subject: add %x for xattr metadata --- lr.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'lr.c') diff --git a/lr.c b/lr.c index de451fa..d9edc95 100644 --- a/lr.c +++ b/lr.c @@ -35,6 +35,10 @@ #include #include +#ifdef __linux__ +#include +#endif + #include #include #include @@ -1337,6 +1341,39 @@ color_name_on(const char *f, mode_t m) fg256(154); } +static char +xattr_char(const char *f) +{ +#ifdef __linux__ + char xattr[1024]; + int c, i, r; + + if (Lflag) + r = listxattr(f, xattr, sizeof xattr); + else + r = llistxattr(f, xattr, sizeof xattr); + if (r < 0 && errno == ERANGE) { + /* just look at prefix */ + r = sizeof xattr; + xattr[r-1] = 0; + } + // ignoring ENOTSUP or r == 0 + + for (i = 0, c = 0; i < r; i += strlen(xattr+i) + 1) + if (strcmp(xattr+i, "security.capability") == 0) { + if (c < 3) c = 3; + } else if (strcmp(xattr+i, "system.posix_acl_access") == 0) { + if (c < 2) c = 2; + } else { + if (c < 1) c = 1; + } + + return " @+#"[c]; +#else + return ' '; // No support for xattrs on this platform. +#endif +} + void print_format(struct fileinfo *fi) { @@ -1466,6 +1503,7 @@ print_format(struct fileinfo *fi) case 'e': printf("%ld", (long)fi->entries); break; case 't': printf("%jd", (intmax_t)fi->total); break; case 'Y': printf("%*s", -fwid, fstype(fi->sb.st_dev)); break; + case 'x': putchar(xattr_char(fi->fpath)); break; default: putchar('%'); putchar(*s); -- cgit 1.4.1