xref: /titanic_50/usr/src/cmd/volcheck/volcheck.c (revision 44743693dce3212f5edba623e0cb0327bd4337a3)
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <unistd.h>
31 #include <fcntl.h>
32 #include <string.h>
33 #include <strings.h>
34 #include <signal.h>
35 #include <errno.h>
36 #include <libintl.h>
37 #include <sys/types.h>
38 
39 #include "vold.h"
40 #include "rmm_common.h"
41 
42 char *progname = "volcheck";
43 
44 static void
45 usage()
46 {
47 	fprintf(stderr,
48 	    gettext("usage: %s [-t #secs -i #secs] [-v] [path | nickname]\n"),
49 	    progname);
50 	fprintf(stderr,
51 	    gettext("If path is not supplied all media is checked\n"));
52 }
53 
54 int
55 main(int argc, char **argv)
56 {
57 	const char	*opts = "itv";
58 	int		c;
59 	boolean_t	opt_i = B_FALSE;
60 	boolean_t	opt_t = B_FALSE;
61 	boolean_t	opt_v = B_FALSE;
62 	LibHalContext	*hal_ctx;
63 	DBusError	error;
64 	rmm_error_t	rmm_error;
65 	int		ret = 0;
66 
67 	vold_init(argc, argv);
68 
69 	while ((c = getopt(argc, argv, opts)) != EOF) {
70 		switch (c) {
71 		case 'i':
72 			opt_i = B_TRUE;
73 			break;
74 		case 't':
75 			opt_t = B_TRUE;
76 			break;
77 		case 'v':
78 			opt_v = B_TRUE;
79 			break;
80 		default:
81 			usage();
82 			return (1);
83 		}
84 	}
85 
86 	if ((hal_ctx = rmm_hal_init(0, 0, 0, &error, &rmm_error)) == NULL) {
87 		(void) fprintf(stderr,
88 		    gettext("HAL initialization failed: %s\n"),
89 		    rmm_strerror(&error, rmm_error));
90 		rmm_dbus_error_free(&error);
91 		return (1);
92 	}
93 
94 	if (optind == argc) {
95 		/* no name provided, check all */
96 		ret = rmm_rescan(hal_ctx, NULL, B_FALSE);
97 	} else {
98 		for (; optind < argc; optind++) {
99 			if (rmm_rescan(hal_ctx, argv[optind], B_FALSE) != 0) {
100 				ret = 1;
101 			}
102 		}
103 	}
104 
105 	rmm_hal_fini(hal_ctx);
106 
107 	return (ret);
108 }
109