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 */
34 #include <sys/vfstab.h>
38 static int perr(const char *fmt
, ...);
43 #define VFS_PATH "/usr/lib/fs"
45 #define EQ(X, Y, Z) !strncmp(X, Y, Z)
47 (nargv[nargc++] = &argv[1][0],\
48 nargc == ARGV_MAX ? perr("volcopy: too many arguments.\n") : 1)
50 extern char *default_fstype();
52 char *nargv
[ARGV_MAX
];
55 char vfstab
[] = VFSTAB
;
57 static void doexec(char *fstype
, char *nargv
[]);
60 main(int argc
, char **argv
)
63 int ii
, Vflg
= 0, Fflg
= 0;
66 struct vfstab vget
, vref
;
68 (void) setlocale(LC_ALL
, "");
69 #if !defined(TEXT_DOMAIN)
70 #define TEXT_DOMAIN "SYS_TEST"
72 (void) textdomain(TEXT_DOMAIN
);
74 while (argc
> 1 && argv
[1][0] == '-') {
75 if (EQ(argv
[1], "-a", 2)) {
77 } else if (EQ(argv
[1], "-e", 2)) {
79 } else if (EQ(argv
[1], "-s", 2)) {
81 } else if (EQ(argv
[1], "-y", 2)) {
83 } else if (EQ(argv
[1], "-buf", 4)) {
85 } else if (EQ(argv
[1], "-bpi", 4)) {
87 if ((cc
= argv
[1][4]) < '0' || cc
> '9') {
92 } else if (EQ(argv
[1], "-feet", 5)) {
94 if ((cc
= argv
[1][5]) < '0' || cc
> '9') {
99 } else if (EQ(argv
[1], "-reel", 5)) {
101 if ((cc
= argv
[1][5]) < '0' || cc
> '9') {
106 } else if (EQ(argv
[1], "-r", 2)) { /* 3b15 only */
108 if ((cc
= argv
[1][2]) < '0' || cc
> '9') {
113 } else if (EQ(argv
[1], "-block", 6)) { /* 3b15 only */
115 if ((cc
= argv
[1][6]) < '0' || cc
> '9') {
120 } else if (EQ(argv
[1], "-V", 2)) {
122 } else if (EQ(argv
[1], "-F", 2)) {
124 perr("volcopy: More than one"
125 "FSType specified.\n"
126 "Usage:\nvolcopy [-F FSType] [-V]"
127 " [current_options] [-o "
128 "specific_options] operands\n");
130 if (argv
[1][2] == '\0') {
134 perr("Usage:\nvolcopy [-F FSType] [-V]"
135 " [current_options] [-o "
136 "specific_options] operands\n");
137 fstype
= &argv
[1][0];
139 fstype
= &argv
[1][2];
140 if (strlen(fstype
) > FSTYPE_MAX
)
141 perr("volcopy: FSType %s exceeds %d"
142 " characters\n", fstype
, FSTYPE_MAX
);
143 } else if (EQ(argv
[1], "-o", 2)) {
145 if (argv
[1][2] == '\0') {
150 if (Fflg
&& strlen(fstype
) > FSTYPE_MAX
)
151 perr("volcopy: FSType %s exceeds %d "
152 "characters.\nUsage:\nvolcopy "
153 "[-F FSType] [-V] [current_options] "
154 "[-o specific_options] "
155 "operands\n", fstype
, FSTYPE_MAX
);
156 } else if (EQ(argv
[1], "-nosh", 5)) { /* 3b15 only */
158 } else if (EQ(argv
[1], "-?", 2)) {
161 doexec(fstype
, nargv
);
163 perr("Usage:\nvolcopy [-F FSType] [-V] "
164 "[current_options] [-o "
165 "specific_options] operands\n");
168 perr("<%s> invalid option\nUsage:\n"
169 "volcopy [-F FSType] [-V] "
170 "[current_options] [-o "
171 "specific_options] operands\n", argv
[1]);
174 } /* argv[1][0] == '-' */
176 if (argc
!= 6) /* if mandatory fields not present */
177 perr("Usage:\nvolcopy [-F FSType] [-V] "
178 "[current_options] [-o "
179 "specific_options] operands\n");
181 if (nargc
+ 5 >= ARGV_MAX
)
182 perr("volcopy: too many arguments.\n");
184 for (ii
= 0; ii
< 5; ii
++)
185 nargv
[nargc
++] = argv
[ii
+1];
187 if (fstype
== NULL
) {
188 if ((fd
= fopen(vfstab
, "r")) == NULL
)
189 perr("volcopy: cannot open %s.\n", vfstab
);
192 vref
.vfs_special
= argv
[2];
193 ii
= getvfsany(fd
, &vget
, &vref
);
197 vref
.vfs_fsckdev
= argv
[2];
198 ii
= getvfsany(fd
, &vget
, &vref
);
205 fstype
= default_fstype(argv
[2]);
208 fstype
= vget
.vfs_fstype
;
211 perr("volcopy: line in vfstab exceeds "
212 "%d characters\n", VFS_LINE_MAX
-2);
215 perr("volcopy: line in vfstab has too few entries\n");
218 perr("volcopy: line in vfstab has too many entries\n");
226 printf("volcopy -F %s", fstype
);
227 for (ii
= 2; nargv
[ii
]; ii
++)
228 printf(" %s", nargv
[ii
]);
233 doexec(fstype
, nargv
);
238 doexec(char *fstype
, char *nargv
[])
240 char full_path
[PATH_MAX
];
241 char *vfs_path
= VFS_PATH
;
243 /* build the full pathname of the fstype dependent command. */
244 sprintf(full_path
, "%s/%s/volcopy", vfs_path
, fstype
);
246 /* set the new argv[0] to the filename */
247 nargv
[1] = "volcopy";
249 /* Try to exec the fstype dependent portion of the mount. */
250 execv(full_path
, &nargv
[1]);
251 if (errno
== EACCES
) {
252 perr("volcopy: cannot execute %s"
253 " - permission denied\n", full_path
);
256 if (errno
== ENOEXEC
) {
258 nargv
[1] = full_path
;
259 execv("/sbin/sh", &nargv
[0]);
261 perr("volcopy: Operation not applicable for FSType %s\n", fstype
);
266 * perr: Print error messages.
270 perr(const char *fmt
, ...)
275 (void) vfprintf(stderr
, gettext(fmt
), ap
);