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[] = "Radx";
49 showHelp(int fd, char const *cmd, int res)
51 WRITE_MSG(fd, "Usage: ");
54 " [-Radx] [--] <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 " -x ... do not cross filesystems\n\n"
61 "Please report bugs to " PACKAGE_BUGREPORT "\n");
69 "showattr " VERSION " -- shows vserver specific file attributes\n"
70 "This program is part of " PACKAGE_STRING "\n\n"
71 "Copyright (C) 2004 Enrico Scholz\n"
72 VERSION_COPYRIGHT_DISCLAIMER);
77 fixupParams(struct Arguments UNUSED * args, int UNUSED argc)
82 getFlags(char const *name, struct stat const *exp_st, long *flags)
84 int fd = open(name, O_RDONLY);
93 checkForRace(fd, name, exp_st);
95 rc = vc_X_get_ext2flags(fd, flags);
96 *flags &= VC_IMMUTABLE_ALL;
99 perror("vc_X_get_ext2flags()");
106 writePadded(long num)
108 char buf[sizeof(num)*2+1];
109 size_t l = utilvserver_fmt_xulong(buf, num);
111 if (l<8) write(1, "00000000", 8-l);
115 #ifdef VC_ENABLE_API_LEGACY
117 handleFileLegacy(char const *name, char const *display_name,
118 struct stat const *exp_st)
122 if (S_ISLNK(exp_st->st_mode)) {
123 write(1, display_name, strlen(display_name));
128 if (!getFlags(name, exp_st, &flags)) {
129 perror(display_name);
133 write(1, display_name, strlen(display_name));
143 handleFile(char const *name, char const *display_name,
144 struct stat const *exp_st)
147 #ifdef VC_ENABLE_API_LEGACY
148 if (global_args->is_legacy)
149 return handleFileLegacy(name, display_name, exp_st);
152 if (S_ISLNK(exp_st->st_mode)) {
153 write(1, "--------", 8);
158 if (getFlags(name, exp_st, &flags))
167 write(1, display_name, strlen(display_name));