added support for VC_IATTR_IMMUTABLE flag
[util-vserver.git] / util-vserver / src / setattr.c
1 // $Id$    --*- c -*--
2
3 // Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
4 //  
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.
8 //  
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.
13 //  
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.
17
18
19 #ifdef HAVE_CONFIG_H
20 #  include <config.h>
21 #endif
22
23 #include "fstool.h"
24 #include "util.h"
25
26 #include <lib/fmt.h>
27 #include <lib/vserver.h>
28 #include <lib/vserver-internal.h>
29
30 #include <stdio.h>
31 #include <sys/types.h>
32 #include <sys/stat.h>
33 #include <fcntl.h>
34
35
36 struct option const
37 CMDLINE_OPTIONS[] = {
38   { "help",     no_argument,  0, CMD_HELP },
39   { "version",  no_argument,  0, CMD_VERSION },
40   { "immu",        no_argument, 0, CMD_IMMU  },
41   { "iunlink",     no_argument, 0, CMD_IMMU  },
42   { "admin",       no_argument, 0, CMD_ADMIN },
43   { "watch",       no_argument, 0, CMD_WATCH },
44   { "hide",        no_argument, 0, CMD_HIDE  },
45   { "barrier",     no_argument, 0, CMD_BARRIER },
46   { "~iunlink",    no_argument, 0, CMD_UNSET_IMMU  },
47   { "~immu",       no_argument, 0, CMD_UNSET_IMMU  },
48   { "~admin",      no_argument, 0, CMD_UNSET_ADMIN },
49   { "~watch",      no_argument, 0, CMD_UNSET_WATCH },
50   { "~hide",       no_argument, 0, CMD_UNSET_HIDE  },
51   { "~barrier",    no_argument, 0, CMD_UNSET_BARRIER },
52   { "iunlink-but-not-immutable",   no_argument, 0, CMD_IMMUX },
53   { "~iunlink-but-not-immutable",  no_argument, 0, CMD_UNSET_IMMUX },
54   { 0,0,0,0 }
55 };
56
57 char const              CMDLINE_OPTIONS_SHORT[] = "Rx";
58
59 void
60 showHelp(int fd, char const *cmd, int res)
61 {
62   WRITE_MSG(fd, "Usage:  ");
63   WRITE_STR(fd, cmd);
64   WRITE_MSG(fd,
65             " [-Rx] [--[~](iunlink|admin|watch|hide|barrier|iunlink-but-not-immutable)]* [--] <file>+\n\n"
66             " Options:\n"
67             "   -R  ...  recurse through directories\n"
68             "   -x  ...  do not cross filesystems\n\n"
69             "Please report bugs to " PACKAGE_BUGREPORT "\n");
70   exit(res);
71 }
72
73 void
74 showVersion()
75 {
76   WRITE_MSG(1,
77             "setattr " VERSION " -- sets vserver specific file attributes\n"
78             "This program is part of " PACKAGE_STRING "\n\n"
79             "Copyright (C) 2004 Enrico Scholz\n"
80             VERSION_COPYRIGHT_DISCLAIMER);
81   exit(0);
82 }
83
84 void
85 fixupParams(struct Arguments * args, int argc)
86 {
87   if (optind==argc) {
88     WRITE_MSG(2, "No filename given; use '--help' for more information\n");
89     exit(1);
90   }
91
92   args->do_display_dir = !args->do_recurse;
93   args->do_display_dot = true;
94 }
95
96 bool
97 handleFile(char const *name, char const * display_name)
98 {
99   int rc = vc_set_iattr(name,
100                         0,
101                         global_args->set_mask & ~global_args->del_mask,
102                         global_args->set_mask |  global_args->del_mask);
103
104   if (rc==-1) {
105     perror(display_name);
106     return false;
107   }
108   
109   return true;
110 }