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>
38 { "help", no_argument, 0, CMD_HELP },
39 { "version", no_argument, 0, CMD_VERSION },
40 #ifdef VC_ENABLE_API_LEGACY
41 { "legacy", no_argument, 0, CMD_LEGACY },
46 char const CMDLINE_OPTIONS_SHORT[] = "Rad";
49 showHelp(int fd, char const *cmd, int res)
51 WRITE_MSG(fd, "Usage: ");
54 " [-Rad] [--] <file>*\n\n"
56 " -R ... recurse through directories\n"
57 " -a ... display files starting with '.' also\n"
58 " -d ... list directories like other files instead of listing\n"
60 "Please report bugs to " PACKAGE_BUGREPORT "\n");
68 "showattr " VERSION " -- shows vserver specific file attributes\n"
69 "This program is part of " PACKAGE_STRING "\n\n"
70 "Copyright (C) 2004 Enrico Scholz\n"
71 VERSION_COPYRIGHT_DISCLAIMER);
76 fixupParams(struct Arguments UNUSED * args, int UNUSED argc)
81 getFlags(char const *name, struct stat const *exp_st, long *flags)
83 int fd = open(name, O_RDONLY);
92 checkForRace(fd, name, exp_st);
94 rc = vc_X_get_ext2flags(fd, flags);
95 *flags &= VC_IMMUTABLE_ALL;
98 perror("vc_X_get_ext2flags()");
105 writePadded(long num)
107 char buf[sizeof(num)*2+1];
108 size_t l = utilvserver_fmt_xulong(buf, num);
110 if (l<8) write(1, "00000000", 8-l);
114 #ifdef VC_ENABLE_API_LEGACY
116 handleFileLegacy(char const *name, char const *display_name,
117 struct stat const *exp_st)
121 if (S_ISLNK(exp_st->st_mode)) {
122 write(1, display_name, strlen(display_name));
127 if (!getFlags(name, exp_st, &flags)) {
128 perror(display_name);
132 write(1, display_name, strlen(display_name));
142 handleFile(char const *name, char const *display_name,
143 struct stat const *exp_st)
146 #ifdef VC_ENABLE_API_LEGACY
147 if (global_args->is_legacy)
148 return handleFileLegacy(name, display_name, exp_st);
151 if (S_ISLNK(exp_st->st_mode)) {
152 write(1, "--------", 8);
157 if (getFlags(name, exp_st, &flags))
166 write(1, display_name, strlen(display_name));