aboutsummaryrefslogtreecommitdiff
path: root/sbin/gbde
diff options
context:
space:
mode:
authorPoul-Henning Kamp <phk@FreeBSD.org>2003-03-31 18:38:31 +0000
committerPoul-Henning Kamp <phk@FreeBSD.org>2003-03-31 18:38:31 +0000
commit8b3ee9cd3bc87e6542570a09465c2d7d0a9ea25f (patch)
tree99a374c9bc5a3bb4b338dc9df43b56c6b07c7b77 /sbin/gbde
parentafa2a5aab75ae5fdef6ab23dcd205c12d21c3a27 (diff)
downloadsrc-8b3ee9cd3bc87e6542570a09465c2d7d0a9ea25f.tar.gz
src-8b3ee9cd3bc87e6542570a09465c2d7d0a9ea25f.zip
Use new GEOM OAM. Kernels have supported this for a number of days, so
people should be OK.
Notes
Notes: svn path=/head/; revision=112877
Diffstat (limited to 'sbin/gbde')
-rw-r--r--sbin/gbde/Makefile2
-rw-r--r--sbin/gbde/gbde.c67
2 files changed, 29 insertions, 40 deletions
diff --git a/sbin/gbde/Makefile b/sbin/gbde/Makefile
index 368edd91f168..715406646854 100644
--- a/sbin/gbde/Makefile
+++ b/sbin/gbde/Makefile
@@ -25,7 +25,7 @@ CFLAGS+= -I${.CURDIR}/../../sys
CLEANFILES+= template.c
MAN= gbde.8
-LDADD= -lmd -lutil
+LDADD= -lmd -lutil -lgeom -lbsdxml -lsbuf
.include <bsd.prog.mk>
diff --git a/sbin/gbde/gbde.c b/sbin/gbde/gbde.c
index 4e6dd26e7814..fbea4375ae87 100644
--- a/sbin/gbde/gbde.c
+++ b/sbin/gbde/gbde.c
@@ -47,6 +47,7 @@
#include <err.h>
#include <stdio.h>
#include <libutil.h>
+#include <libgeom.h>
#include <sys/errno.h>
#include <sys/disk.h>
#include <sys/stat.h>
@@ -219,58 +220,46 @@ encrypt_sector(void *d, int len, int klen, void *key)
static void
cmd_attach(const struct g_bde_softc *sc, const char *dest, const char *lfile)
{
- int gfd, i, ffd;
- struct geomconfiggeom gcg;
- u_char buf[256 + 16];
-
- gfd = open("/dev/geom.ctl", O_RDWR);
- if (gfd < 0)
- err(1, "/dev/geom.ctl");
- memset(&gcg, 0, sizeof gcg);
- gcg.class.u.name = "BDE";
- gcg.class.len = strlen(gcg.class.u.name);
- gcg.provider.u.name = dest;
- gcg.provider.len = strlen(gcg.provider.u.name);
- gcg.flag = GCFG_CREATE;
- gcg.len = sizeof buf;
- gcg.ptr = buf;
-
+ int ffd;
+ u_char buf[16];
+ struct gctl_req *r;
+ const char *errstr;
+
+ r = gctl_get_handle(GCTL_CREATE_GEOM);
+ gctl_ro_param(r, "class", -1, "BDE");
+ gctl_ro_param(r, "provider", -1, dest);
+ gctl_ro_param(r, "pass", SHA512_DIGEST_LENGTH, sc->sha2);
if (lfile != NULL) {
ffd = open(lfile, O_RDONLY, 0);
if (ffd < 0)
err(1, "%s", lfile);
- read(ffd, buf + sizeof(sc->sha2), 16);
+ read(ffd, buf, 16);
+ gctl_ro_param(r, "key", 16, buf);
close(ffd);
- } else {
- memset(buf + sizeof(sc->sha2), 0, 16);
}
- memcpy(buf, sc->sha2, sizeof(sc->sha2));
+ /* gctl_dump(r, stdout); */
+ errstr = gctl_issue(r);
+ if (errstr != NULL)
+ errx(1, "Attach to %s failed: %s\n", dest, errstr);
- i = ioctl(gfd, GEOMCONFIGGEOM, &gcg);
- if (i != 0)
- err(1, "ioctl(GEOMCONFIGGEOM)");
exit (0);
}
static void
cmd_detach(const char *dest)
{
- int i, gfd;
- struct geomconfiggeom gcg;
-
- gfd = open("/dev/geom.ctl", O_RDWR);
- if (gfd < 0)
- err(1, "/dev/geom.ctl");
- memset(&gcg, 0, sizeof gcg);
- gcg.class.u.name = "BDE";
- gcg.class.len = strlen(gcg.class.u.name);
- gcg.provider.u.name = dest;
- gcg.provider.len = strlen(gcg.provider.u.name);
- gcg.flag = GCFG_DISMANTLE;
-
- i = ioctl(gfd, GEOMCONFIGGEOM, &gcg);
- if (i != 0)
- err(1, "ioctl(GEOMCONFIGGEOM)");
+ struct gctl_req *r;
+ const char *errstr;
+ char buf[BUFSIZ];
+
+ r = gctl_get_handle(GCTL_DESTROY_GEOM);
+ gctl_ro_param(r, "class", -1, "BDE");
+ sprintf(buf, "%s.bde", dest);
+ gctl_ro_param(r, "geom", -1, buf);
+ /* gctl_dump(r, stdout); */
+ errstr = gctl_issue(r);
+ if (errstr != NULL)
+ errx(1, "Detach of %s failed: %s\n", dest, errstr);
exit (0);
}