3 // Copyright (C) 2006 Daniel Hokka Zakrisson
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.
24 #include <lib/internal.h>
31 #define ENSC_WRAPPERS_PREFIX "vdevmap: "
32 #define ENSC_WRAPPERS_UNISTD 1
33 #define ENSC_WRAPPERS_VSERVER 1
36 #define CMD_HELP 0x1000
37 #define CMD_VERSION 0x1001
39 int wrapper_exit_code = 1;
43 { "help", no_argument, 0, CMD_HELP },
44 { "version", no_argument, 0, CMD_VERSION },
45 { "xid", required_argument, 0, 'x' },
46 { "set", no_argument, 0, 's' },
47 { "unset", no_argument, 0, 'u' },
48 { "open", no_argument, 0, 'o' },
49 { "create", no_argument, 0, 'c' },
50 { "remap", no_argument, 0, 'r' },
51 { "flags", required_argument, 0, 'f' },
52 { "device", required_argument, 0, 'd' },
53 { "target", required_argument, 0, 't' },
58 showHelp(int fd, char const *cmd)
60 WRITE_MSG(fd, "Usage: ");
63 " --xid <xid> {--set|--unset} [--flags <flags>] [--open] [--create]\n"
64 " [--device <dev>] [--remap --target <dev>]\n"
66 " --flags <flags> Set the specified flags\n"
67 " --open Allow opening of the device\n"
68 " --create If SECURE_MKNOD is given, allow mknod(2)\n"
69 " --device <dev> Device to apply the command to\n"
70 " --remap Remap the device to the target\n"
71 " --target <dev> Target for --remap\n"
73 "Please report bugs to " PACKAGE_BUGREPORT "\n");
82 "vdevmap " VERSION " -- manages device mappings\n"
83 "This program is part of " PACKAGE_STRING "\n\n"
84 "Copyright (C) 2006 Daniel Hokka Zakrisson\n"
85 VERSION_COPYRIGHT_DISCLAIMER);
89 int main(int argc, char *argv[])
92 bool allow_open = false;
93 bool allow_create = false;
94 bool do_remap = false;
99 unsigned long tmp = 0;
102 int c = getopt_long(argc, argv, "+x:suocrf:d:t:", CMDLINE_OPTIONS, 0);
106 case CMD_HELP : showHelp(1, argv[0]);
107 case CMD_VERSION : showVersion();
108 case 'x' : xid = Evc_xidopt2xid(optarg, true); break;
109 case 'o' : allow_open = true; break;
110 case 'c' : allow_create = true; break;
111 case 'r' : do_remap = true; break;
112 case 'd' : device = optarg; break;
113 case 't' : target = optarg; break;
114 case 's' : set = 1; break;
115 case 'u' : set = 0; break;
117 if (!isNumberUnsigned(optarg, &tmp, false)) {
118 WRITE_MSG(2, "Invalid flags argument: '");
119 WRITE_STR(2, optarg);
120 WRITE_MSG(2, "'; try '--help' for more information\n");
123 flags |= (uint32_t) tmp;
127 WRITE_MSG(2, "Try '");
128 WRITE_STR(2, argv[0]);
129 WRITE_MSG(2, " --help' for more information.\n");
135 if (allow_open) flags |= VC_DATTR_OPEN;
136 if (allow_create) flags |= VC_DATTR_CREATE;
137 if (do_remap) flags |= VC_DATTR_REMAP;
139 if (target && !do_remap)
140 WRITE_MSG(2, "Target specified without --remap; try '--help' for more information\n");
141 else if (xid==VC_NOCTX)
142 WRITE_MSG(2, "No xid specified; try '--help' for more information\n");
143 else if (optind!=argc)
144 WRITE_MSG(2, "Unused argument(s); try '--help' for more information\n");
145 else if (set && vc_set_mapping(xid, device, target, flags)==-1)
146 perror("vc_set_mapping()");
147 else if (!set && vc_unset_mapping(xid, device, target, flags)==-1)
148 perror("vc_unset_mapping()");