1 /* $NetBSD: main.c,v 1.6 2007/02/21 20:53:59 hubertf Exp $ */
4 * Copyright (c) 2001, 2002 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/cdefs.h>
34 __RCSID("$NetBSD: main.c,v 1.6 2007/02/21 20:53:59 hubertf Exp $");
37 #include <sys/types.h>
38 #include <sys/ioctl.h>
39 #include <sys/queue.h>
41 #include <dev/ic/mlxreg.h>
42 #include <dev/ic/mlxio.h>
65 #define CMD_DISKS 0x01
66 #define CMD_NOARGS 0x02
68 static const struct cmd cmdtab
[] = {
69 { "check", CMD_DISKS
, cmd_check
},
70 { "config", CMD_NOARGS
, cmd_config
},
71 { "cstatus", CMD_NOARGS
, cmd_cstatus
},
72 { "detach", CMD_DISKS
, cmd_detach
},
73 { "rebuild", 0, cmd_rebuild
},
74 { "rescan", CMD_NOARGS
, cmd_rescan
},
75 { "status", CMD_DISKS
, cmd_status
},
79 main(int argc
, char **argv
)
81 const struct cmd
*cmd
, *maxcmd
;
82 const char *cmdname
, *dv
;
89 while ((ch
= getopt(argc
, argv
, "af:v")) != -1) {
109 if ((cmdname
= argv
[optind
++]) == NULL
)
112 for (i
= 0; dv
[i
] != '\0'; i
++)
114 mlxname
= &dv
[i
+ 1];
116 if ((mlxfd
= open(dv
, O_RDWR
)) < 0)
117 err(EXIT_FAILURE
, "%s", dv
);
120 maxcmd
= &cmdtab
[sizeof(cmdtab
) / sizeof(cmdtab
[0])];
121 while (cmd
< maxcmd
) {
122 if (strcmp(cmdname
, cmd
->label
) == 0)
129 if (ioctl(mlxfd
, MLX_GET_CINFO
, &ci
))
130 err(EXIT_FAILURE
, "ioctl(MLX_GET_CINFO)");
132 if ((cmd
->flags
& CMD_DISKS
) != 0) {
136 while (argv
[optind
] != NULL
)
137 mlx_disk_add(argv
[optind
++]);
138 if (mlx_disk_empty())
140 "no logical drives attached to this controller");
141 } else if ((cmd
->flags
& CMD_NOARGS
) != 0)
142 if (argv
[optind
] != NULL
)
145 rv
= (*cmd
->func
)(&argv
[optind
]);
155 (void)fprintf(stderr
, "usage: %s [-f dev] [-av] command [...]\n",