summaryrefslogtreecommitdiffstats
path: root/sbin/gbde
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>2002-12-18 19:57:27 +0000
committerphk <phk@FreeBSD.org>2002-12-18 19:57:27 +0000
commit761d063e808061f78a2bd10e65cc88ff442124c6 (patch)
tree73efd719fdb177063848159195753ffb42085e80 /sbin/gbde
parent4052863334f88b834ae48faa0160fd6fdd753299 (diff)
downloadFreeBSD-src-761d063e808061f78a2bd10e65cc88ff442124c6.zip
FreeBSD-src-761d063e808061f78a2bd10e65cc88ff442124c6.tar.gz
Fix two blunders in the mapping functions which can lead to corrupt data,
for request sizes larger than the sectorsize or for multi-key setups. See warning mailed to current@ for details of recovery. Found by: Marcus Reid <marcus@blazingdot.com>
Diffstat (limited to 'sbin/gbde')
-rw-r--r--sbin/gbde/gbde.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/sbin/gbde/gbde.c b/sbin/gbde/gbde.c
index e3e278e..041d206 100644
--- a/sbin/gbde/gbde.c
+++ b/sbin/gbde/gbde.c
@@ -418,7 +418,16 @@ cmd_write(struct g_bde_key *gl, struct g_bde_softc *sc, int dfd , int key, const
if (i != (int)gl->sectorsize)
err(1, "write");
printf("Wrote key %d at %jd\n", key, (intmax_t)offset);
-
+#if 0
+ printf("s0 = %jd\n", (intmax_t)gl->sector0);
+ printf("sN = %jd\n", (intmax_t)gl->sectorN);
+ printf("l[0] = %jd\n", (intmax_t)gl->lsector[0]);
+ printf("l[1] = %jd\n", (intmax_t)gl->lsector[1]);
+ printf("l[2] = %jd\n", (intmax_t)gl->lsector[2]);
+ printf("l[3] = %jd\n", (intmax_t)gl->lsector[3]);
+ printf("k = %jd\n", (intmax_t)gl->keyoffset);
+ printf("ss = %jd\n", (intmax_t)gl->sectorsize);
+#endif
}
static void
@@ -436,6 +445,16 @@ cmd_destroy(struct g_bde_key *gl, int nkey)
gl->lsector[i] = ~0;
}
+static int
+sorthelp(const void *a, const void *b)
+{
+ const off_t *oa, *ob;
+
+ oa = a;
+ ob = b;
+ return (*oa - *ob);
+}
+
static void
cmd_init(struct g_bde_key *gl, int dfd, const char *f_opt, int i_opt, const char *l_opt)
{
@@ -597,6 +616,7 @@ cmd_init(struct g_bde_key *gl, int dfd, const char *f_opt, int i_opt, const char
while (o < gl->sectorN);
gl->lsector[u] = o;
}
+ qsort(gl->lsector, G_BDE_MAXKEYS, sizeof gl->lsector[0], sorthelp);
/* Flush sector zero if we use it for lockfile data */
if (gl->flags & 1) {
OpenPOWER on IntegriCloud