dkctl(8) -- a program to manupulate disks. It currently supports
the disk cache-related ioctls.
This commit is contained in:
parent
52544dc3f4
commit
fcc3de9c40
|
@ -0,0 +1,9 @@
|
|||
# $NetBSD: Makefile,v 1.1 2002/01/09 22:30:14 thorpej Exp $
|
||||
|
||||
PROG= dkctl
|
||||
MAN= dkctl.8
|
||||
|
||||
LDADD+= -lutil
|
||||
DPADD+= ${LIBUTIL}
|
||||
|
||||
.include <bsd.prog.mk>
|
|
@ -0,0 +1,103 @@
|
|||
.\" $NetBSD: dkctl.8,v 1.1 2002/01/09 22:30:14 thorpej Exp $
|
||||
.\"
|
||||
.\" Copyright 2002 Wasabi Systems, Inc.
|
||||
.\" All rights reserved.
|
||||
.\"
|
||||
.\" Written by Jason R. Thorpe for Wasabi Systems, Inc.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 3. All advertising materials mentioning features or use of this software
|
||||
.\" must display the following acknowledgement:
|
||||
.\" This product includes software developed for the NetBSD Project by
|
||||
.\" Wasabi Systems, Inc.
|
||||
.\" 4. The name of Wasabi Systems, Inc. may not be used to endorse
|
||||
.\" or promote products derived from this software without specific prior
|
||||
.\" written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
|
||||
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
.\" POSSIBILITY OF SUCH DAMAGE.
|
||||
.\"
|
||||
.Dd January 9, 2002
|
||||
.Dt DKCTL 8
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm dkctl
|
||||
.Nd a program to manipulate disks
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Ar device
|
||||
.Ar command
|
||||
.Oo
|
||||
.Ar arg Oo ...
|
||||
.Oc
|
||||
.Oc
|
||||
.Sh DESCRIPTION
|
||||
.Nm
|
||||
allows a user or system administrator to manipulate and configure disks
|
||||
in various ways. It is used by specifying a disk manipulate, the command
|
||||
to perform, and any arguments the command may require.
|
||||
.Sh COMMANDS
|
||||
The following commands are supported:
|
||||
.Pp
|
||||
.Nm getcache
|
||||
.Pp
|
||||
Get and display the cache enables for the specified device.
|
||||
.Pp
|
||||
.Nm setcache
|
||||
.Ar none | r | w | rw
|
||||
.Op Ar save
|
||||
.Pp
|
||||
Set the cache enables for the specified device. The enables are
|
||||
as follows:
|
||||
.Bl -tag -width indent
|
||||
.It none
|
||||
Disable all caches on the disk.
|
||||
.It r
|
||||
Enable the read cache, and disable all other caches on the disk.
|
||||
.It w
|
||||
Enable the write cache, and disable all other caches on the disk.
|
||||
.It rw
|
||||
Enable both the read and write caches on the disk.
|
||||
.It save
|
||||
If specified, and the cache enables are savable, saves the cache
|
||||
enables in the disk's non-volatile parameter storage.
|
||||
.El
|
||||
.Pp
|
||||
.Nm synccache
|
||||
.Op Ar force
|
||||
.Pp
|
||||
Causes the cache on the disk to be synchronized, flushing all dirty
|
||||
write cache blocks to the media. If
|
||||
.Ar force
|
||||
is specified, the cache synchronization command will be issued even
|
||||
if the kernel does not believe that there are any dirty cache blocks
|
||||
in the disk's cache.
|
||||
.Sh SEE ALSO
|
||||
.Xr ioctl 2 ,
|
||||
.Xr sd 4 ,
|
||||
.Xr wd 4 ,
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Nm
|
||||
command first appeared in
|
||||
.Nx 1.6 .
|
||||
.Sh AUTHORS
|
||||
The
|
||||
.Nm
|
||||
command was written by Jason R. Thorpe of Wasabi Systems, Inc.
|
|
@ -0,0 +1,227 @@
|
|||
/* $NetBSD: dkctl.c,v 1.1 2002/01/09 22:30:14 thorpej Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright 2001 Wasabi Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Written by Jason R. Thorpe for Wasabi Systems, Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed for the NetBSD Project by
|
||||
* Wasabi Systems, Inc.
|
||||
* 4. The name of Wasabi Systems, Inc. may not be used to endorse
|
||||
* or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* dkctl(8) -- a program to manipulate disks.
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/dkio.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <util.h>
|
||||
|
||||
struct command {
|
||||
const char *cmd_name;
|
||||
const char *arg_names;
|
||||
void (*cmd_func)(int, char *[]);
|
||||
int open_flags;
|
||||
};
|
||||
|
||||
int main(int, char *[]);
|
||||
void usage(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 */
|
||||
|
||||
void disk_getcache(int, char *[]);
|
||||
void disk_setcache(int, char *[]);
|
||||
void disk_synccache(int, char *[]);
|
||||
|
||||
struct command commands[] = {
|
||||
{ "getcache",
|
||||
"",
|
||||
disk_getcache,
|
||||
O_RDONLY },
|
||||
|
||||
{ "setcache",
|
||||
"none | r | w | rw [save]",
|
||||
disk_setcache,
|
||||
O_RDWR },
|
||||
|
||||
{ "synccache",
|
||||
"[force]",
|
||||
disk_synccache,
|
||||
O_RDWR },
|
||||
|
||||
{ NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
0 },
|
||||
};
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
|
||||
/* Must have at least: device command */
|
||||
if (argc < 3)
|
||||
usage();
|
||||
|
||||
/* Skip program name, get and skip device name and command. */
|
||||
dvname = argv[1];
|
||||
cmdname = argv[2];
|
||||
argv += 3;
|
||||
argc -= 3;
|
||||
|
||||
/* 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);
|
||||
|
||||
argnames = commands[i].arg_names;
|
||||
|
||||
/* Open the device. */
|
||||
fd = opendisk(dvname, commands[i].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);
|
||||
}
|
||||
|
||||
void
|
||||
usage()
|
||||
{
|
||||
int i;
|
||||
|
||||
fprintf(stderr, "Usage: %s device command [arg [...]]\n",
|
||||
getprogname());
|
||||
|
||||
fprintf(stderr, " Available commands:\n");
|
||||
for (i = 0; commands[i].cmd_name != NULL; i++)
|
||||
fprintf(stderr, "\t%s %s\n", commands[i].cmd_name,
|
||||
commands[i].arg_names);
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void
|
||||
disk_getcache(int argc, char *argv[])
|
||||
{
|
||||
int bits;
|
||||
|
||||
if (ioctl(fd, DIOCGCACHE, &bits) == -1)
|
||||
err(1, "%s: getcache", dvname);
|
||||
|
||||
if ((bits & (DKCACHE_READ|DKCACHE_WRITE)) == 0)
|
||||
printf("%s: No caches enabled\n", dvname);
|
||||
else {
|
||||
if (bits & DKCACHE_READ)
|
||||
printf("%s: read cache enabled\n", dvname);
|
||||
if (bits & DKCACHE_WRITE)
|
||||
printf("%s: write-back cache enabled\n", dvname);
|
||||
}
|
||||
|
||||
printf("%s: read cache enable is %schangeable\n", dvname,
|
||||
(bits & DKCACHE_RCHANGE) ? "" : "not ");
|
||||
printf("%s: write cache enable is %schangeable\n", dvname,
|
||||
(bits & DKCACHE_WCHANGE) ? "" : "not ");
|
||||
|
||||
printf("%s: cache parameters are %ssavable\n", dvname,
|
||||
(bits & DKCACHE_SAVE) ? "" : "not ");
|
||||
}
|
||||
|
||||
void
|
||||
disk_setcache(int argc, char *argv[])
|
||||
{
|
||||
int bits;
|
||||
|
||||
if (argc > 2 || argc == 0)
|
||||
usage();
|
||||
|
||||
if (strcmp(argv[0], "none") == 0)
|
||||
bits = 0;
|
||||
else if (strcmp(argv[0], "r") == 0)
|
||||
bits = DKCACHE_READ;
|
||||
else if (strcmp(argv[0], "w") == 0)
|
||||
bits = DKCACHE_WRITE;
|
||||
else if (strcmp(argv[0], "rw") == 0)
|
||||
bits = DKCACHE_READ|DKCACHE_WRITE;
|
||||
else
|
||||
usage();
|
||||
|
||||
if (argc == 2) {
|
||||
if (strcmp(argv[1], "save") == 0)
|
||||
bits |= DKCACHE_SAVE;
|
||||
else
|
||||
usage();
|
||||
}
|
||||
|
||||
if (ioctl(fd, DIOCSCACHE, &bits) == -1)
|
||||
err(1, "%s: setcache", dvname);
|
||||
}
|
||||
|
||||
void
|
||||
disk_synccache(int argc, char *argv[])
|
||||
{
|
||||
int force;
|
||||
|
||||
switch (argc) {
|
||||
case 0:
|
||||
force = 0;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
if (strcmp(argv[0], "force") == 0)
|
||||
force = 1;
|
||||
else
|
||||
usage();
|
||||
break;
|
||||
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
|
||||
if (ioctl(fd, DIOCCACHESYNC, &force) == -1)
|
||||
err(1, "%s: sync cache", dvname);
|
||||
}
|
Loading…
Reference in New Issue