- Display cache, strategy, and list of wedges if no command is specified in
the command line. - Sort list of wedges. Posted on tech-userlevel a while ago, no objections then.
This commit is contained in:
parent
6a632bad63
commit
b9691b268f
@ -1,4 +1,4 @@
|
||||
.\" $NetBSD: dkctl.8,v 1.17 2006/01/12 20:28:29 wiz Exp $
|
||||
.\" $NetBSD: dkctl.8,v 1.18 2009/02/07 17:13:32 uebayasi Exp $
|
||||
.\"
|
||||
.\" Copyright 2002 Wasabi Systems, Inc.
|
||||
.\" All rights reserved.
|
||||
@ -33,7 +33,7 @@
|
||||
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
.\" POSSIBILITY OF SUCH DAMAGE.
|
||||
.\"
|
||||
.Dd December 26, 2005
|
||||
.Dd February 8, 2009
|
||||
.Dt DKCTL 8
|
||||
.Os
|
||||
.Sh NAME
|
||||
@ -42,6 +42,8 @@
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Ar device
|
||||
.Nm
|
||||
.Ar device
|
||||
.Ar command
|
||||
.Op Ar arg Op ...
|
||||
.Sh DESCRIPTION
|
||||
@ -50,6 +52,10 @@ allows a user or system administrator to manipulate and configure disks
|
||||
in various ways.
|
||||
It is used by specifying a disk to manipulate, the command
|
||||
to perform, and any arguments the command may require.
|
||||
If
|
||||
.Nm
|
||||
is called without any command, it displays strategy, cache, and all of
|
||||
the wedges of the specified device.
|
||||
.Sh COMMANDS
|
||||
The following commands are supported:
|
||||
.Bl -tag -width XXstrategyXXnameXX
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: dkctl.c,v 1.16 2006/06/17 02:16:19 christos Exp $ */
|
||||
/* $NetBSD: dkctl.c,v 1.17 2009/02/07 17:13:32 uebayasi Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright 2001 Wasabi Systems, Inc.
|
||||
@ -41,7 +41,7 @@
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: dkctl.c,v 1.16 2006/06/17 02:16:19 christos Exp $");
|
||||
__RCSID("$NetBSD: dkctl.c,v 1.17 2009/02/07 17:13:32 uebayasi Exp $");
|
||||
#endif
|
||||
|
||||
|
||||
@ -78,14 +78,17 @@ struct command {
|
||||
int open_flags;
|
||||
};
|
||||
|
||||
struct command *lookup(const char *);
|
||||
void usage(void);
|
||||
void run(int, char *[]);
|
||||
void showall(void);
|
||||
|
||||
int fd; /* file descriptor for device */
|
||||
const char *dvname; /* device name */
|
||||
char dvname_store[MAXPATHLEN]; /* for opendisk(3) */
|
||||
const char *cmdname; /* command user issued */
|
||||
const char *argnames; /* helpstring; expected arguments */
|
||||
|
||||
int dkw_sort(const void *, const void *);
|
||||
int yesno(const char *);
|
||||
|
||||
void disk_getcache(int, char *[]);
|
||||
@ -100,6 +103,10 @@ void disk_getwedgeinfo(int, char *[]);
|
||||
void disk_listwedges(int, char *[]);
|
||||
void disk_strategy(int, char *[]);
|
||||
|
||||
void disk_foreachwedges(int, char *[], void (*)(struct dkwedge_list *));
|
||||
void disk_listwedges_cb(struct dkwedge_list *);
|
||||
void disk_getwedgeinfo_cb(struct dkwedge_info *);
|
||||
|
||||
struct command commands[] = {
|
||||
{ "getcache",
|
||||
"",
|
||||
@ -160,37 +167,58 @@ struct command commands[] = {
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
|
||||
/* Must have at least: device command */
|
||||
if (argc < 3)
|
||||
if (argc < 2)
|
||||
usage();
|
||||
|
||||
/* Skip program name, get and skip device name and command. */
|
||||
dvname = argv[1];
|
||||
cmdname = argv[2];
|
||||
argv += 3;
|
||||
argc -= 3;
|
||||
if (argc == 2)
|
||||
showall();
|
||||
else {
|
||||
/* Skip program name, get and skip device name and command. */
|
||||
cmdname = argv[2];
|
||||
argv += 3;
|
||||
argc -= 3;
|
||||
run(argc, argv);
|
||||
}
|
||||
|
||||
/* Look up and call the command. */
|
||||
for (i = 0; commands[i].cmd_name != NULL; i++)
|
||||
if (strcmp(cmdname, commands[i].cmd_name) == 0)
|
||||
break;
|
||||
if (commands[i].cmd_name == NULL)
|
||||
errx(1, "unknown command: %s", cmdname);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
argnames = commands[i].arg_names;
|
||||
void
|
||||
run(int argc, char *argv[])
|
||||
{
|
||||
struct command *command;
|
||||
|
||||
command = lookup(cmdname);
|
||||
|
||||
/* Open the device. */
|
||||
fd = opendisk(dvname, commands[i].open_flags, dvname_store,
|
||||
fd = opendisk(dvname, command->open_flags, dvname_store,
|
||||
sizeof(dvname_store), 0);
|
||||
if (fd == -1)
|
||||
err(1, "%s", dvname);
|
||||
|
||||
dvname = dvname_store;
|
||||
|
||||
(*commands[i].cmd_func)(argc, argv);
|
||||
exit(0);
|
||||
(*command->cmd_func)(argc, argv);
|
||||
|
||||
/* Close the device. */
|
||||
(void)close(fd);
|
||||
}
|
||||
|
||||
struct command *
|
||||
lookup(const char *name)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* Look up the command. */
|
||||
for (i = 0; commands[i].cmd_name != NULL; i++)
|
||||
if (strcmp(name, commands[i].cmd_name) == 0)
|
||||
break;
|
||||
if (commands[i].cmd_name == NULL)
|
||||
errx(1, "unknown command: %s", name);
|
||||
|
||||
return &commands[i];
|
||||
}
|
||||
|
||||
void
|
||||
@ -198,8 +226,10 @@ usage(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
fprintf(stderr, "usage: %s device command [arg [...]]\n",
|
||||
getprogname());
|
||||
fprintf(stderr,
|
||||
"usage: %s device\n"
|
||||
" %s device command [arg [...]]\n",
|
||||
getprogname(), getprogname());
|
||||
|
||||
fprintf(stderr, " Available commands:\n");
|
||||
for (i = 0; commands[i].cmd_name != NULL; i++)
|
||||
@ -209,6 +239,26 @@ usage(void)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void
|
||||
showall(void)
|
||||
{
|
||||
printf("strategy:\n");
|
||||
cmdname = "strategy";
|
||||
run(0, NULL);
|
||||
|
||||
putchar('\n');
|
||||
|
||||
printf("cache:\n");
|
||||
cmdname = "getcache";
|
||||
run(0, NULL);
|
||||
|
||||
putchar('\n');
|
||||
|
||||
printf("wedges:\n");
|
||||
cmdname = "listwedges";
|
||||
run(0, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
disk_strategy(int argc, char *argv[])
|
||||
{
|
||||
@ -605,6 +655,8 @@ disk_listwedges(int argc, char *argv[])
|
||||
return;
|
||||
}
|
||||
|
||||
qsort(dkw, dkwl.dkwl_nwedges, sizeof(*dkw), dkw_sort);
|
||||
|
||||
printf("%s: %u wedge%s:\n", dvname, dkwl.dkwl_nwedges,
|
||||
dkwl.dkwl_nwedges == 1 ? "" : "s");
|
||||
for (i = 0; i < dkwl.dkwl_nwedges; i++) {
|
||||
@ -615,6 +667,15 @@ disk_listwedges(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
dkw_sort(const void *a, const void *b)
|
||||
{
|
||||
const struct dkwedge_info *dkwa = a, *dkwb = b;
|
||||
const daddr_t oa = dkwa->dkw_offset, ob = dkwb->dkw_offset;
|
||||
|
||||
return (oa < ob) ? -1 : (oa > ob) ? 1 : 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* return YES, NO or -1.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user