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.
28 #include <sys/ioctl.h>
30 #define ENSC_WRAPPERS_FCNTL 1
31 #define ENSC_WRAPPERS_IOCTL 1
32 #define ENSC_WRAPPERS_UNISTD 1
35 int wrapper_exit_code = 1;
38 #define VROOT_SET_DEV 0x5600
39 #define VROOT_CLR_DEV 0x5601
40 #define VROOT_INC_USE 0x56FE
41 #define VROOT_DEC_USE 0x56FF
45 { "help", no_argument, 0, 'h' },
46 { "version", no_argument, 0, 'v' },
51 showHelp(int fd, char const *cmd, int res)
53 WRITE_MSG(fd, "Usage: ");
60 " <rootdev> <real-rootdev>\n\n"
61 "Please report bugs to " PACKAGE_BUGREPORT "\n");
69 "vrsetup " VERSION " -- set up and control vroot devices\n"
70 "This program is part of " PACKAGE_STRING "\n\n"
71 "Copyright (C) 2004 Enrico Scholz\n"
72 VERSION_COPYRIGHT_DISCLAIMER);
77 int main(int argc, char *argv[])
79 bool do_delete = false;
80 bool do_decrement = false;
81 bool do_increment = false;
82 bool do_setup = false;
83 char const * root_device = 0;
84 char const * real_root_device = 0;
88 int c = getopt_long(argc, argv, "dID", CMDLINE_OPTIONS, 0);
92 case 'h' : showHelp(1, argv[0], 0);
93 case 'v' : showVersion();
94 case 'd' : do_delete = true; break;
95 case 'D' : do_decrement = true; break;
96 case 'I' : do_increment = true; break;
98 WRITE_MSG(2, "Try '");
99 WRITE_STR(2, argv[0]);
100 WRITE_MSG(2, " --help' for more information.\n");
106 do_setup = !(do_delete || do_decrement || do_increment);
109 WRITE_MSG(2, "No vroot-device given\n");
113 if (do_setup && optind+2>argc) {
114 WRITE_MSG(2, "No real root-device given\n");
118 root_device = argv[optind];
119 if (do_setup) real_root_device = argv[optind+1];
121 fd = EopenD(root_device, O_RDONLY, 0);
122 if (do_increment) Eioctl(fd, VROOT_INC_USE, 0);
123 else if (do_decrement) Eioctl(fd, VROOT_DEC_USE, 0);
124 else if (do_delete) Eioctl(fd, VROOT_CLR_DEV, 0);
126 int dfd = EopenD(real_root_device, O_RDONLY, 0);
127 Eioctl(fd, VROOT_SET_DEV, (void*)dfd);