3 // Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; version 2 of the License.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 #include <lib/vserver.h>
28 #include <lib/vserver-internal.h>
31 #include <sys/types.h>
38 { "help", no_argument, 0, CMD_HELP },
39 { "version", no_argument, 0, CMD_VERSION },
40 { "immutable", no_argument, 0, CMD_IMMUTABLE },
41 { "immulink", no_argument, 0, CMD_IMMULINK },
45 char const CMDLINE_OPTIONS_SHORT[] = "Rsu";
47 static long set_mask = 0;
48 static long del_mask = VC_IMMUTABLE_ALL;
51 showHelp(int fd, char const *cmd, int res)
53 WRITE_MSG(fd, "Usage: ");
56 " [-Rsu] [--immutable] [--immulink] [--] <file>+\n\n"
58 " -R ... recurse through directories\n"
59 " -s ... set flag only; when only one of the '--immu*' options\n"
60 " is given, do not delete the other ones\n"
61 " -u ... revert operation and unset the given flags\n"
62 "Please report bugs to " PACKAGE_BUGREPORT "\n");
70 "setattr " VERSION " -- sets 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 * args, int argc)
81 WRITE_MSG(2, "No filename given; use '--help' for more information\n");
86 if (args->immutable) set_mask |= VC_IMMUTABLE_FILE_FL;
87 if (args->immulink) set_mask |= VC_IMMUTABLE_LINK_FL;
89 if (args->do_set) del_mask = 0;
90 else del_mask = VC_IMMUTABLE_ALL;
99 setFlags(char const *name, char const *display_name,
100 struct stat const *exp_st)
102 int fd = open(name, O_RDONLY);
111 !checkForRace(fd, name, exp_st))
114 if (vc_X_set_ext2flags(fd, set_mask, del_mask)==-1) {
115 perror(display_name);
127 handleFile(char const *name, char const * display_name,
128 struct stat const *exp_st)
130 if (S_ISLNK(exp_st->st_mode)) return true;
132 return setFlags(name, display_name, exp_st);