summaryrefslogtreecommitdiffstats
path: root/sbin/gbde
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>2003-03-31 18:38:31 +0000
committerphk <phk@FreeBSD.org>2003-03-31 18:38:31 +0000
commit574223ef321bcd88953aec62abc49c44dcdbd349 (patch)
tree99a374c9bc5a3bb4b338dc9df43b56c6b07c7b77 /sbin/gbde
parent5b75c05966032cd391a6d88a2c22a048a1720339 (diff)
downloadFreeBSD-src-574223ef321bcd88953aec62abc49c44dcdbd349.zip
FreeBSD-src-574223ef321bcd88953aec62abc49c44dcdbd349.tar.gz
Use new GEOM OAM. Kernels have supported this for a number of days, so
people should be OK.
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 368edd9..7154066 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 4e6dd26..fbea437 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);
}
OpenPOWER on IntegriCloud