3 // Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
4 // based on showattr.cc by Jacques Gelinas
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2, or (at your option)
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 #include <lib/vserver.h>
29 #include <lib/vserver-internal.h>
32 #include <sys/types.h>
39 { "help", no_argument, 0, CMD_HELP },
40 { "version", no_argument, 0, CMD_VERSION },
41 #ifdef VC_ENABLE_API_LEGACY
42 { "legacy", no_argument, 0, CMD_LEGACY },
47 char const CMDLINE_OPTIONS_SHORT[] = "Radx";
50 showHelp(int fd, char const *cmd, int res)
52 WRITE_MSG(fd, "Usage: ");
55 " [-Radx] [--] <file>*\n\n"
57 " -R ... recurse through directories\n"
58 " -a ... display files starting with '.' also\n"
59 " -d ... list directories like other files instead of listing\n"
61 " -x ... do not cross filesystems\n\n"
62 "Please report bugs to " PACKAGE_BUGREPORT "\n");
70 "showattr " VERSION " -- shows vserver specific file attributes\n"
71 "This program is part of " PACKAGE_STRING "\n\n"
72 "Copyright (C) 2004 Enrico Scholz\n"
73 VERSION_COPYRIGHT_DISCLAIMER);
78 fixupParams(struct Arguments UNUSED * args, int UNUSED argc)
83 getFlags(char const *name, uint32_t *flags, uint32_t *mask)
88 if (vc_get_iattr(name, &xid, flags, mask)==-1) {
89 perror("vc_get_iattr()");
97 handleFile(char const *name, char const *display_name)
105 memset(buf, ' ', sizeof buf);
107 if (getFlags(name, &flags, &mask)) {
109 // fedcba9876543210fedcba9876543210
110 static char const MARKER[33] = ".......x.....iub............mhwa";
112 uint32_t used_flags = (VC_IATTR_XID|VC_IATTR_ADMIN|
113 VC_IATTR_WATCH|VC_IATTR_HIDE|
114 VC_IATTR_BARRIER|VC_IATTR_IUNLINK|
115 VC_IATTR_IMMUTABLE|VC_IATTR_WRITE);
117 for (i=0; i<32; ++i) {
118 if (used_flags & 1) {
119 if (! (mask & 1) ) *ptr++ = '-';
120 else if (flags & 1) *ptr++ = toupper(MARKER[31-i]);
121 else *ptr++ = MARKER[31-i];
130 memcpy(buf, "ERR ", 8);
135 Vwrite(1, display_name, strlen(display_name));