Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sbin/dkctl Add commands to create, delete, and query the con...



details:   https://anonhg.NetBSD.org/src/rev/e0ca7b47b6fc
branches:  trunk
changeset: 570112:e0ca7b47b6fc
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Sat Sep 25 03:31:35 2004 +0000

description:
Add commands to create, delete, and query the configuration of wedges.

diffstat:

 sbin/dkctl/dkctl.8 |   41 +++++++++++++-
 sbin/dkctl/dkctl.c |  155 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 193 insertions(+), 3 deletions(-)

diffs (247 lines):

diff -r 01c596741e1a -r e0ca7b47b6fc sbin/dkctl/dkctl.8
--- a/sbin/dkctl/dkctl.8        Sat Sep 25 03:30:44 2004 +0000
+++ b/sbin/dkctl/dkctl.8        Sat Sep 25 03:31:35 2004 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: dkctl.8,v 1.12 2004/09/16 18:02:27 erh Exp $
+.\"    $NetBSD: dkctl.8,v 1.13 2004/09/25 03:31:35 thorpej Exp $
 .\"
 .\" Copyright 2002 Wasabi Systems, Inc.
 .\" All rights reserved.
@@ -121,8 +121,47 @@
 .Em can only
 be used with character devices.
 .El
+.Pp
+.Nm addwedge
+.Ar name
+.Ar startblk
+.Ar blkcnt
+.Ar ptype
+.Pp
+Define a
+.Sq wedge
+on the specified disk starting at block number
+.Ar startblk
+and spanning
+.Ar blkcnt
+blocks.
+The wedge will have the volume name
+.Ar name
+and the partition type
+.Ar ptype .
+The device name of the virtual block device assigned to the wedge will be
+displayed after the wedge has been successfully created.
+See
+.Xr dk 4
+for more information about disk wedges.
+.Pp
+.Nm delwedge
+.Ar dk
+.Pp
+Delete the wedge specified by its device name
+.Ar dk
+from the specified disk.
+.Pp
+.Nm getwedgeinfo
+.Pp
+Display information about the specified disk wedge.
+.Pp
+.Nm listwedges
+.Pp
+List all of the wedges configured on the specified disk.
 .Sh SEE ALSO
 .Xr ioctl 2 ,
+.Xr dk 4 ,
 .Xr sd 4 ,
 .Xr wd 4 ,
 .Xr disklabel 5 ,
diff -r 01c596741e1a -r e0ca7b47b6fc sbin/dkctl/dkctl.c
--- a/sbin/dkctl/dkctl.c        Sat Sep 25 03:30:44 2004 +0000
+++ b/sbin/dkctl/dkctl.c        Sat Sep 25 03:31:35 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dkctl.c,v 1.8 2004/01/05 23:23:32 jmmv Exp $   */
+/*     $NetBSD: dkctl.c,v 1.9 2004/09/25 03:31:35 thorpej Exp $        */
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -41,7 +41,7 @@
 #include <sys/cdefs.h>
 
 #ifndef lint
-__RCSID("$NetBSD: dkctl.c,v 1.8 2004/01/05 23:23:32 jmmv Exp $");
+__RCSID("$NetBSD: dkctl.c,v 1.9 2004/09/25 03:31:35 thorpej Exp $");
 #endif
 
 
@@ -95,6 +95,11 @@
 void   disk_keeplabel(int, char *[]);
 void   disk_badsectors(int, char *[]);
 
+void   disk_addwedge(int, char *[]);
+void   disk_delwedge(int, char *[]);
+void   disk_getwedgeinfo(int, char *[]);
+void   disk_listwedges(int, char *[]);
+
 struct command commands[] = {
        { "getcache",
          "",
@@ -121,6 +126,26 @@
           disk_badsectors,
           O_RDWR },
 
+       { "addwedge",
+         "name startblk blkcnt ptype",
+         disk_addwedge,
+         O_RDWR },
+
+       { "delwedge",
+         "dk",
+         disk_delwedge,
+         O_RDWR },
+
+       { "getwedgeinfo",
+         "",
+         disk_getwedgeinfo,
+         O_RDONLY },
+
+       { "listwedges",
+         "",
+         disk_listwedges,
+         O_RDONLY },
+
        { NULL,
          NULL,
          NULL,
@@ -425,6 +450,132 @@
        }
 }
 
+void
+disk_addwedge(int argc, char *argv[])
+{
+       struct dkwedge_info dkw;
+       char *cp;
+       daddr_t start;
+       uint64_t size;
+
+       if (argc != 4)
+               usage();
+
+       /* XXX Unicode. */
+       if (strlen(argv[0]) > sizeof(dkw.dkw_wname) - 1)
+               errx(1, "Wedge name too long; max %zd characters",
+                   sizeof(dkw.dkw_wname) - 1);
+       strcpy(dkw.dkw_wname, argv[0]);
+
+       if (strlen(argv[3]) > sizeof(dkw.dkw_ptype) - 1)
+               errx(1, "Wedge partition type too long; max %zd characters",
+                   sizeof(dkw.dkw_ptype) - 1);
+       strcpy(dkw.dkw_ptype, argv[3]);
+
+       errno = 0;
+       start = strtoll(argv[1], &cp, 0);
+       if (*cp != '\0')
+               errx(1, "Invalid start block: %s", argv[1]);
+       if (errno == ERANGE && (start == LLONG_MAX ||
+                               start == LLONG_MIN))
+               errx(1, "Start block out of range.");
+       if (start < 0)
+               errx(1, "Start block must be >= 0.");
+
+       errno = 0;
+       size = strtoull(argv[2], &cp, 0);
+       if (*cp != '\0')
+               errx(1, "Invalid block count: %s", argv[2]);
+       if (errno == ERANGE && (size == ULLONG_MAX))
+               errx(1, "Block count out of range.");
+
+       dkw.dkw_offset = start;
+       dkw.dkw_size = size;
+
+       if (ioctl(fd, DIOCAWEDGE, &dkw) == -1)
+               err(1, "%s: addwedge", dvname);
+}
+
+void
+disk_delwedge(int argc, char *argv[])
+{
+       struct dkwedge_info dkw;
+
+       if (argc != 1)
+               usage();
+
+       if (strlen(argv[0]) > sizeof(dkw.dkw_devname) - 1)
+               errx(1, "Wedge dk name too long; max %zd characters",
+                   sizeof(dkw.dkw_devname) - 1);
+       strcpy(dkw.dkw_devname, argv[0]);
+
+       if (ioctl(fd, DIOCDWEDGE, &dkw) == -1)
+               err(1, "%s: delwedge", dvname);
+}
+
+void
+disk_getwedgeinfo(int argc, char *argv[])
+{
+       struct dkwedge_info dkw;
+
+       if (argc != 0)
+               usage();
+
+       if (ioctl(fd, DIOCGWEDGEINFO, &dkw) == -1)
+               err(1, "%s: getwedgeinfo", dvname);
+
+       printf("%s at %s: %s\n", dkw.dkw_devname, dkw.dkw_parent,
+           dkw.dkw_wname);     /* XXX Unicode */
+       printf("%s: %llu blocks at %lld, type: %s\n",
+           dkw.dkw_devname, dkw.dkw_size, dkw.dkw_offset, dkw.dkw_ptype);
+}
+
+void
+disk_listwedges(int argc, char *argv[])
+{
+       struct dkwedge_info *dkw;
+       struct dkwedge_list dkwl;
+       size_t bufsize;
+       u_int i;
+
+       if (argc != 0)
+               usage();
+
+       dkw = NULL;
+       dkwl.dkwl_buf = dkw;
+       dkwl.dkwl_bufsize = 0;
+
+       for (;;) {
+               if (ioctl(fd, DIOCLWEDGES, &dkwl) == -1)
+                       err(1, "%s: listwedges", dvname);
+               if (dkwl.dkwl_nwedges == dkwl.dkwl_ncopied)
+                       break;
+               bufsize = dkwl.dkwl_nwedges * sizeof(*dkw);
+               if (dkwl.dkwl_bufsize < bufsize) {
+                       dkw = realloc(dkwl.dkwl_buf, bufsize);
+                       if (dkw == NULL)
+                               errx(1, "%s: listwedges: unable to "
+                                   "allocate wedge info buffer", dvname);
+                       dkwl.dkwl_buf = dkw;
+                       dkwl.dkwl_bufsize = bufsize;
+               }
+       }
+
+       if (dkwl.dkwl_nwedges == 0) {
+               printf("%s: no wedges configured\n", dvname);
+               return;
+       }
+
+       printf("%s: %u wedge%s:\n", dvname, dkwl.dkwl_nwedges,
+           dkwl.dkwl_nwedges == 1 ? "" : "s");
+       for (i = 0; i < dkwl.dkwl_nwedges; i++) {
+               printf("%s: %s, %llu blocks at %lld, type: %s\n",
+                   dkw[i].dkw_devname,
+                   dkw[i].dkw_wname,   /* XXX Unicode */
+                   dkw[i].dkw_size, dkw[i].dkw_offset, dkw[i].dkw_ptype);
+       }
+}
+
 /*
  * return YES, NO or -1.
  */



Home | Main Index | Thread Index | Old Index