1 // $Id: chxid.c 2473 2007-01-25 09:51:43Z dhozac $ --*- c -*--
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.
26 #include "lib/vserver.h"
30 #include <sys/types.h>
36 { "help", no_argument, 0, CMD_HELP },
37 { "version", no_argument, 0, CMD_VERSION },
41 char const CMDLINE_OPTIONS_SHORT[] = "Rc:xU";
44 showHelp(int fd, char const *cmd, int res)
46 WRITE_MSG(fd, "Usage: ");
49 " -c <ctx|vserver> [-RxU] [--] <file>+\n\n"
51 " -R ... recurse through directories\n"
52 " -c ... assign the given context/vserver to the file(s)\n"
53 " -x ... do not cross filesystems\n"
54 " -U ... skip unified files\n\n"
55 "Please report bugs to " PACKAGE_BUGREPORT "\n");
63 "chxid " VERSION " -- assigns a context to a file\n"
64 "This program is part of " PACKAGE_STRING "\n\n"
65 "Copyright (C) 2004 Enrico Scholz\n"
66 VERSION_COPYRIGHT_DISCLAIMER);
71 isUnified(char const *filename)
73 uint_least32_t const V = VC_IATTR_IUNLINK|VC_IATTR_IMMUTABLE;
76 uint_least32_t mask = V;
78 if (vc_get_iattr(filename, 0, &flags, &mask)==-1 || (mask & V) != V)
81 return (flags & V)==V ? true : false;
85 handleFile(char const *name, char const * display_name)
87 if (!global_args->no_unified || !isUnified(name)) {
88 int rc = vc_set_iattr(name, global_args->ctx, 0, VC_IATTR_XID);
100 fixupParams(struct Arguments UNUSED *args, int argc)
103 WRITE_MSG(2, "No filename given; use '--help' for more information\n");
107 if (args->ctx_str==0) {
108 WRITE_MSG(2, "No context given; use '--help' for more information\n");
112 args->ctx = vc_xidopt2xid(args->ctx_str, true, 0);
113 args->do_display_dir = !args->do_recurse;
114 args->do_display_dot = true;