4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 #pragma ident "%Z%%M% %I% %E% SMI"
37 #include <sys/vfstab.h>
41 static int perr(const char *fmt
, ...);
46 #define VFS_PATH "/usr/lib/fs"
48 #define EQ(X, Y, Z) !strncmp(X, Y, Z)
50 (nargv[nargc++] = &argv[1][0],\
51 nargc == ARGV_MAX ? perr("volcopy: too many arguments.\n") : 1)
53 extern char *default_fstype();
55 char *nargv
[ARGV_MAX
];
58 char vfstab
[] = VFSTAB
;
60 static void doexec(char *fstype
, char *nargv
[]);
63 main(int argc
, char **argv
)
66 int ii
, Vflg
= 0, Fflg
= 0;
69 struct vfstab vget
, vref
;
71 (void) setlocale(LC_ALL
, "");
72 #if !defined(TEXT_DOMAIN)
73 #define TEXT_DOMAIN "SYS_TEST"
75 (void) textdomain(TEXT_DOMAIN
);
77 while (argc
> 1 && argv
[1][0] == '-') {
78 if (EQ(argv
[1], "-a", 2)) {
80 } else if (EQ(argv
[1], "-e", 2)) {
82 } else if (EQ(argv
[1], "-s", 2)) {
84 } else if (EQ(argv
[1], "-y", 2)) {
86 } else if (EQ(argv
[1], "-buf", 4)) {
88 } else if (EQ(argv
[1], "-bpi", 4)) {
90 if ((cc
= argv
[1][4]) < '0' || cc
> '9') {
95 } else if (EQ(argv
[1], "-feet", 5)) {
97 if ((cc
= argv
[1][5]) < '0' || cc
> '9') {
102 } else if (EQ(argv
[1], "-reel", 5)) {
104 if ((cc
= argv
[1][5]) < '0' || cc
> '9') {
109 } else if (EQ(argv
[1], "-r", 2)) { /* 3b15 only */
111 if ((cc
= argv
[1][2]) < '0' || cc
> '9') {
116 } else if (EQ(argv
[1], "-block", 6)) { /* 3b15 only */
118 if ((cc
= argv
[1][6]) < '0' || cc
> '9') {
123 } else if (EQ(argv
[1], "-V", 2)) {
125 } else if (EQ(argv
[1], "-F", 2)) {
127 perr("volcopy: More than one"
128 "FSType specified.\n"
129 "Usage:\nvolcopy [-F FSType] [-V]"
130 " [current_options] [-o "
131 "specific_options] operands\n");
133 if (argv
[1][2] == '\0') {
137 perr("Usage:\nvolcopy [-F FSType] [-V]"
138 " [current_options] [-o "
139 "specific_options] operands\n");
140 fstype
= &argv
[1][0];
142 fstype
= &argv
[1][2];
143 if (strlen(fstype
) > FSTYPE_MAX
)
144 perr("volcopy: FSType %s exceeds %d"
145 " characters\n", fstype
, FSTYPE_MAX
);
146 } else if (EQ(argv
[1], "-o", 2)) {
148 if (argv
[1][2] == '\0') {
153 if (Fflg
&& strlen(fstype
) > FSTYPE_MAX
)
154 perr("volcopy: FSType %s exceeds %d "
155 "characters.\nUsage:\nvolcopy "
156 "[-F FSType] [-V] [current_options] "
157 "[-o specific_options] "
158 "operands\n", fstype
, FSTYPE_MAX
);
159 } else if (EQ(argv
[1], "-nosh", 5)) { /* 3b15 only */
161 } else if (EQ(argv
[1], "-?", 2)) {
164 doexec(fstype
, nargv
);
166 perr("Usage:\nvolcopy [-F FSType] [-V] "
167 "[current_options] [-o "
168 "specific_options] operands\n");
171 perr("<%s> invalid option\nUsage:\n"
172 "volcopy [-F FSType] [-V] "
173 "[current_options] [-o "
174 "specific_options] operands\n", argv
[1]);
177 } /* argv[1][0] == '-' */
179 if (argc
!= 6) /* if mandatory fields not present */
180 perr("Usage:\nvolcopy [-F FSType] [-V] "
181 "[current_options] [-o "
182 "specific_options] operands\n");
184 if (nargc
+ 5 >= ARGV_MAX
)
185 perr("volcopy: too many arguments.\n");
187 for (ii
= 0; ii
< 5; ii
++)
188 nargv
[nargc
++] = argv
[ii
+1];
190 if (fstype
== NULL
) {
191 if ((fd
= fopen(vfstab
, "r")) == NULL
)
192 perr("volcopy: cannot open %s.\n", vfstab
);
195 vref
.vfs_special
= argv
[2];
196 ii
= getvfsany(fd
, &vget
, &vref
);
200 vref
.vfs_fsckdev
= argv
[2];
201 ii
= getvfsany(fd
, &vget
, &vref
);
208 fstype
= default_fstype(argv
[2]);
211 fstype
= vget
.vfs_fstype
;
214 perr("volcopy: line in vfstab exceeds "
215 "%d characters\n", VFS_LINE_MAX
-2);
218 perr("volcopy: line in vfstab has too few entries\n");
221 perr("volcopy: line in vfstab has too many entries\n");
229 printf("volcopy -F %s", fstype
);
230 for (ii
= 2; nargv
[ii
]; ii
++)
231 printf(" %s", nargv
[ii
]);
236 doexec(fstype
, nargv
);
241 doexec(char *fstype
, char *nargv
[])
243 char full_path
[PATH_MAX
];
244 char *vfs_path
= VFS_PATH
;
246 /* build the full pathname of the fstype dependent command. */
247 sprintf(full_path
, "%s/%s/volcopy", vfs_path
, fstype
);
249 /* set the new argv[0] to the filename */
250 nargv
[1] = "volcopy";
252 /* Try to exec the fstype dependent portion of the mount. */
253 execv(full_path
, &nargv
[1]);
254 if (errno
== EACCES
) {
255 perr("volcopy: cannot execute %s"
256 " - permission denied\n", full_path
);
259 if (errno
== ENOEXEC
) {
261 nargv
[1] = full_path
;
262 execv("/sbin/sh", &nargv
[0]);
264 perr("volcopy: Operation not applicable for FSType %s\n", fstype
);
269 * perr: Print error messages.
273 perr(const char *fmt
, ...)
278 (void) vfprintf(stderr
, gettext(fmt
), ap
);