4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
28 * The file containing main() for rmformat. The command line
29 * options are parsed in this file.
33 #include <priv_utils.h>
52 char *slice_file
= NULL
;
54 diskaddr_t repair_blk_no
;
55 int32_t quick_format
= 0;
56 int32_t long_format
= 0;
57 int32_t force_format
= 0;
58 int32_t rw_protect_enable
= 0;
59 int32_t rw_protect_disable
= 0;
60 int32_t wp_enable_passwd
= 0;
61 int32_t wp_disable_passwd
= 0;
62 int32_t wp_enable
= 0;
63 int32_t wp_disable
= 0;
64 int32_t verify_write
= 0;
65 char *dev_name
= NULL
;
67 static void usage(char *);
68 void check_invalid_combinations();
69 void check_invalid_combinations_again(int32_t);
70 extern uint64_t my_atoll(char *ptr
);
71 extern void my_perror(char *err_string
);
72 void process_options();
75 main(int32_t argc
, char **argv
)
81 * This program requires file_dac_read, file_dac_write,
82 * proc_fork, proc_exec, and sys_devices privileges.
84 * child processes require the sys_mount privilege
86 (void) __init_suid_priv(PU_INHERITPRIVS
,
87 PRIV_FILE_DAC_READ
, PRIV_FILE_DAC_WRITE
, PRIV_PROC_FORK
,
88 PRIV_PROC_EXEC
, PRIV_SYS_MOUNT
, PRIV_SYS_DEVICES
, NULL
);
90 (void) setlocale(LC_ALL
, "");
92 #if !defined(TEXT_DOMAIN)
93 #define TEXT_DOMAIN "SYS_TEST"
96 (void) textdomain(TEXT_DOMAIN
);
99 DPRINTF1("myname %s\n", myname
);
101 while ((i
= getopt(argc
, argv
, "b:c:DeF:HlpR:s:tUV:W:w:")) != -1) {
102 DPRINTF1("arg %c\n", i
);
106 label
= strdup(optarg
);
107 if (strlen(label
) > 8) {
108 (void) fprintf(stderr
, gettext("Label is \
109 restricted to 8 characters.\n"));
118 tmp_ptr
= strdup(optarg
);
120 repair_blk_no
= my_atoll(tmp_ptr
);
121 if (repair_blk_no
== (diskaddr_t
)(-1)) {
123 usage("invalid block number");
126 DPRINTF1(" block no. %llu\n", repair_blk_no
);
140 tmp_ptr
= strdup(optarg
);
141 if (strcmp(tmp_ptr
, "quick") == 0) {
144 } else if (strcmp(tmp_ptr
, "long") == 0) {
147 } else if (strcmp(tmp_ptr
, "force") == 0) {
152 usage("invalid argument for option -F");
171 tmp_ptr
= strdup(optarg
);
172 if (strcmp(tmp_ptr
, "enable") == 0) {
174 } else if (strcmp(tmp_ptr
, "disable") == 0) {
175 rw_protect_disable
++;
177 usage("Invalid argument for -R option");
185 slice_file
= strdup(optarg
);
194 tmp_ptr
= strdup(optarg
);
195 if (strcmp(tmp_ptr
, "read") == 0) {
197 } else if (strcmp(tmp_ptr
, "write") == 0) {
200 usage("Invalid argument for -V option");
207 tmp_ptr
= strdup(optarg
);
208 if (strcmp(tmp_ptr
, "enable") == 0) {
210 } else if (strcmp(tmp_ptr
, "disable") == 0) {
213 usage("Invalid argument for -W option");
220 tmp_ptr
= strdup(optarg
);
221 if (strcmp(tmp_ptr
, "enable") == 0) {
223 } else if (strcmp(tmp_ptr
, "disable") == 0) {
226 usage("Invalid arguments for -w option");
236 if (optind
< argc
-1) {
237 usage("more than one device name argument");
241 if (optind
== argc
-1) {
242 dev_name
= argv
[optind
];
243 } else if (optind
== 1) {
244 /* list devices by default */
246 } else if ((optind
== argc
) && !l_flag
) {
247 (void) fprintf(stderr
,
248 gettext("No device specified.\n"));
252 (void) printf("Using floppy device\n");
253 dev_name
= "/dev/rdiskette";
259 /* Remove the privileges we gave. */
269 (void) fprintf(stderr
, "%s : ", myname
);
270 (void) fprintf(stderr
, gettext(str
));
271 (void) fprintf(stderr
, "\n");
274 (void) fprintf(stderr
, "Usage:\n");
275 (void) fprintf(stderr
, gettext("\t%s \
276 [ -DeHpU ] [ -b label ] [ -c blockno ] [ -F quick|long|force ] \
277 [ -R enable|disable ] [ -s filename ] [ -V read|write ] \
278 [ -w enable|disable ] [ -W enable|disable ] devname \n"), myname
);
279 (void) fprintf(stderr
, gettext("\t%s -l [ devname ]\n"),
286 check_invalid_combinations()
289 /* Inherited from FLOPPY */
291 if (D_flag
&& H_flag
) {
292 usage("Options -D and -H incompatible");
295 if (D_flag
&& F_flag
) {
296 usage("Options -D and -F incompatible");
299 if (H_flag
&& F_flag
) {
300 usage("Options -H and -F incompatible");
303 /* rmformat additions */
305 if ((w_flag
&& W_flag
) || (w_flag
&& R_flag
) || (W_flag
&& R_flag
)) {
306 usage("Options -w, -W and -R incompatible");
309 if (c_flag
&& F_flag
) {
310 usage("Options -c, -F incompatible");
313 /* l_flag is mutually exclusive of these flags */
314 if (l_flag
&& (D_flag
+ e_flag
+ H_flag
+ p_flag
+ U_flag
+
315 b_flag
+ c_flag
+ F_flag
+ R_flag
+ s_flag
+ V_flag
+
317 usage("Options incompatible");
323 check_invalid_combinations_again(int32_t medium_type
)
325 if ((medium_type
!= SM_FLOPPY
) &&
326 (medium_type
!= SM_PCMCIA_MEM
)) {
327 if (D_flag
|| H_flag
) {
328 usage("-D, -H options are compatible with floppy and \
329 PCMCIA memory cards only.");