#ifdef _KERNEL
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/blist.h>
#include <sys/malloc.h>
#else
#ifndef BLIST_NO_DEBUG
#define BLIST_DEBUG
#endif
#include <sys/types.h>
#include <assert.h>
#include <err.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <limits.h>
#define malloc(s,t,f) calloc(1, s)
#define mallocarray(n,s,t,f) reallocarray(NULL, n, s)
#define free(p,t,s) free(p)
#define KASSERT(exp) assert(exp)
#define KDASSERT(exp) assert(exp)
#include "../sys/blist.h"
#define panic(...) do { errx(1, __VA_ARGS__); } while (0)
#endif
static swblk_t blst_leaf_alloc(blmeta_t *scan, swblk_t blkat,
swblk_t blk, swblk_t count);
static swblk_t blst_meta_alloc(blmeta_t *scan, swblk_t blkat,
swblk_t blk, swblk_t count,
swblk_t radix, swblk_t skip);
static void blst_leaf_free(blmeta_t *scan, swblk_t relblk, swblk_t count);
static void blst_meta_free(blmeta_t *scan, swblk_t freeBlk, swblk_t count,
swblk_t radix, swblk_t skip,
swblk_t blk);
static swblk_t blst_leaf_fill(blmeta_t *scan, swblk_t blk, swblk_t count);
static swblk_t blst_meta_fill(blmeta_t *scan, swblk_t fillBlk, swblk_t count,
swblk_t radix, swblk_t skip,
swblk_t blk);
static void blst_copy(blmeta_t *scan, swblk_t blk, swblk_t radix,
swblk_t skip, blist_t dest, swblk_t count);
static swblk_t blst_radix_init(blmeta_t *scan, swblk_t radix,
swblk_t skip, swblk_t count);
static int blst_radix_gapfind(blmeta_t *scan, swblk_t blk, swblk_t radix, swblk_t skip,
int state, swblk_t *maxbp, swblk_t *maxep, swblk_t *bp, swblk_t *ep);
#if defined(BLIST_DEBUG) || defined(DDB)
static void blst_radix_print(blmeta_t *scan, swblk_t blk,
swblk_t radix, swblk_t skip, int tab);
#endif
blist_t
blist_create(swblk_t blocks)
{
blist_t bl;
swblk_t radix;
swblk_t skip = 0;
KASSERT(blocks > 0);
radix = BLIST_BMAP_RADIX;
while (radix < blocks) {
radix *= BLIST_META_RADIX;
skip = (skip + 1) * BLIST_META_RADIX;
KASSERT(skip > 0);
}
bl = malloc(sizeof(struct blist), M_VMSWAP, M_WAITOK | M_ZERO);
bl->bl_blocks = blocks;
bl->bl_radix = radix;
bl->bl_skip = skip;
bl->bl_rootblks = 1 +
blst_radix_init(NULL, bl->bl_radix, bl->bl_skip, blocks);
bl->bl_root = mallocarray(bl->bl_rootblks, sizeof(blmeta_t),
M_VMSWAP, M_WAITOK);
#if defined(BLIST_DEBUG)
printf(
"BLIST representing %lu blocks (%lu MB of swap)"
", requiring %6.2fM of ram\n",
bl->bl_blocks,
bl->bl_blocks * 4 / 1024,
(bl->bl_rootblks * sizeof(blmeta_t) + 1023) / (1024.0 * 1024.0)
);
printf("BLIST raw radix tree: %lu records, top-radix %lu\n",
bl->bl_rootblks, bl->bl_radix);
#endif
blst_radix_init(bl->bl_root, bl->bl_radix, bl->bl_skip, blocks);
return(bl);
}
void
blist_destroy(blist_t bl)
{
KASSERT(bl != NULL);
free(bl->bl_root, M_VMSWAP, sizeof(blmeta_t) * bl->bl_rootblks);
free(bl, M_VMSWAP, sizeof(struct blist));
}
swblk_t
blist_alloc(blist_t bl, swblk_t count)
{
swblk_t blk = SWAPBLK_NONE;
if (bl) {
if (bl->bl_radix == BLIST_BMAP_RADIX)
blk = blst_leaf_alloc(bl->bl_root, 0, 0, count);
else
blk = blst_meta_alloc(bl->bl_root, 0, 0, count,
bl->bl_radix, bl->bl_skip);
if (blk != SWAPBLK_NONE) {
bl->bl_free -= count;
KDASSERT(blk < bl->bl_blocks);
KDASSERT(bl->bl_free <= bl->bl_blocks);
}
}
return(blk);
}
swblk_t
blist_allocat(blist_t bl, swblk_t count, swblk_t blkat)
{
swblk_t blk = SWAPBLK_NONE;
if (bl) {
KDASSERT(blkat < bl->bl_blocks);
KDASSERT(blkat + count <= bl->bl_blocks);
if (bl->bl_radix == BLIST_BMAP_RADIX)
blk = blst_leaf_alloc(bl->bl_root, blkat, 0, count);
else
blk = blst_meta_alloc(bl->bl_root, blkat, 0, count,
bl->bl_radix, bl->bl_skip);
if (blk != SWAPBLK_NONE) {
bl->bl_free -= count;
KDASSERT(blk < bl->bl_blocks);
KDASSERT(bl->bl_free <= bl->bl_blocks);
}
}
return(blk);
}
void
blist_free(blist_t bl, swblk_t blkno, swblk_t count)
{
if (bl) {
KDASSERT(blkno < bl->bl_blocks);
KDASSERT(blkno + count <= bl->bl_blocks);
if (bl->bl_radix == BLIST_BMAP_RADIX)
blst_leaf_free(bl->bl_root, blkno, count);
else
blst_meta_free(bl->bl_root, blkno, count, bl->bl_radix, bl->bl_skip, 0);
bl->bl_free += count;
KDASSERT(bl->bl_free <= bl->bl_blocks);
}
}
swblk_t
blist_fill(blist_t bl, swblk_t blkno, swblk_t count)
{
swblk_t filled;
if (bl) {
KDASSERT(blkno < bl->bl_blocks);
KDASSERT(blkno + count <= bl->bl_blocks);
if (bl->bl_radix == BLIST_BMAP_RADIX) {
filled = blst_leaf_fill(bl->bl_root, blkno, count);
} else {
filled = blst_meta_fill(bl->bl_root, blkno, count,
bl->bl_radix, bl->bl_skip, 0);
}
bl->bl_free -= filled;
KDASSERT(bl->bl_free <= bl->bl_blocks);
return (filled);
} else {
return 0;
}
}
void
blist_resize(blist_t *pbl, swblk_t count, int freenew)
{
blist_t newbl = blist_create(count);
blist_t save = *pbl;
*pbl = newbl;
if (count > save->bl_blocks)
count = save->bl_blocks;
blst_copy(save->bl_root, 0, save->bl_radix, save->bl_skip, newbl, count);
if (freenew && count < newbl->bl_blocks) {
blist_free(newbl, count, newbl->bl_blocks - count);
}
blist_destroy(save);
}
#define GAPFIND_FIRSTFREE 0
#define GAPFIND_FIRSTUSED 1
void
blist_gapfind(blist_t bl, swblk_t *maxbp, swblk_t *maxep)
{
int state;
swblk_t b, e;
*maxbp = *maxep = 0;
b = e = 0;
state = blst_radix_gapfind(bl->bl_root, 0, bl->bl_radix, bl->bl_skip,
GAPFIND_FIRSTFREE, maxbp, maxep, &b, &e);
if (state == GAPFIND_FIRSTUSED) {
e = bl->bl_blocks;
if (*maxep - *maxbp < e - b) {
*maxbp = b;
*maxep = e;
}
}
KDASSERT(*maxbp <= *maxep);
KDASSERT(*maxbp < bl->bl_blocks);
KDASSERT(*maxep <= bl->bl_blocks);
}
static int
blst_radix_gapfind(blmeta_t *scan, swblk_t blk, swblk_t radix, swblk_t skip,
int state, swblk_t *maxbp, swblk_t *maxep, swblk_t *bp, swblk_t *ep)
{
swblk_t i;
swblk_t next_skip;
if (radix == BLIST_BMAP_RADIX) {
if (state == GAPFIND_FIRSTFREE) {
if (scan->u.bmu_bitmap == (u_swblk_t)-1) {
*bp = blk;
return GAPFIND_FIRSTUSED;
}
return state;
} else if (state == GAPFIND_FIRSTUSED) {
if (scan->u.bmu_bitmap == (u_swblk_t)-1) {
return state;
}
*ep = blk;
if (*maxep - *maxbp < *ep - *bp) {
*maxbp = *bp;
*maxep = *ep;
}
return GAPFIND_FIRSTFREE;
}
}
if (scan->u.bmu_avail == 0) {
if (state == GAPFIND_FIRSTFREE) {
return state;
} else if (state == GAPFIND_FIRSTUSED) {
*ep = blk;
if (*maxep - *maxbp < *ep - *bp) {
*maxbp = *bp;
*maxep = *ep;
}
return GAPFIND_FIRSTFREE;
}
}
if (scan->u.bmu_avail == radix) {
if (state == GAPFIND_FIRSTFREE) {
*bp = blk;
return GAPFIND_FIRSTUSED;
} else if (state == GAPFIND_FIRSTUSED) {
return state;
}
}
radix /= BLIST_META_RADIX;
next_skip = (skip / BLIST_META_RADIX);
for (i = 1; i <= skip; i += next_skip) {
if (scan[i].bm_bighint == (swblk_t)-1)
break;
state = blst_radix_gapfind(&scan[i], blk, radix, next_skip - 1,
state, maxbp, maxep, bp, ep);
blk += radix;
}
return state;
}
#if defined(BLIST_DEBUG) || defined(DDB)
void
blist_print(blist_t bl)
{
printf("BLIST {\n");
blst_radix_print(bl->bl_root, 0, bl->bl_radix, bl->bl_skip, 4);
printf("}\n");
}
#endif
static swblk_t
blst_leaf_alloc(blmeta_t *scan, swblk_t blkat __unused, swblk_t blk,
swblk_t count)
{
u_swblk_t orig = scan->u.bmu_bitmap;
if (orig == 0) {
scan->bm_bighint = 0;
return(SWAPBLK_NONE);
}
if (count == 1) {
u_swblk_t mask;
int j = BLIST_BMAP_RADIX/2;
int r = 0;
mask = (u_swblk_t)-1 >> (BLIST_BMAP_RADIX/2);
while (j) {
if ((orig & mask) == 0) {
r += j;
orig >>= j;
}
j >>= 1;
mask >>= j;
}
scan->u.bmu_bitmap &= ~((u_swblk_t)1 << r);
return(blk + r);
}
if (count <= BLIST_BMAP_RADIX) {
int j;
int n = (int)(BLIST_BMAP_RADIX - count);
u_swblk_t mask;
mask = (u_swblk_t)-1 >> n;
for (j = 0; j <= n; ++j) {
if ((orig & mask) == mask) {
scan->u.bmu_bitmap &= ~mask;
return(blk + j);
}
mask = (mask << 1);
}
}
scan->bm_bighint = count - 1;
return(SWAPBLK_NONE);
}
static swblk_t
blst_meta_alloc(blmeta_t *scan, swblk_t blkat,
swblk_t blk, swblk_t count,
swblk_t radix, swblk_t skip)
{
int hintok = (blk >= blkat);
swblk_t next_skip = ((swblk_t)skip / BLIST_META_RADIX);
swblk_t i;
#ifndef _KERNEL
printf("blist_meta_alloc blkat %lu blk %lu count %lu radix %lu\n",
blkat, blk, count, radix);
#endif
if (scan->u.bmu_avail == 0) {
scan->bm_bighint = 0;
return(SWAPBLK_NONE);
}
if (scan->u.bmu_avail == radix) {
scan->bm_bighint = radix;
radix /= BLIST_META_RADIX;
for (i = 1; i <= skip; i += next_skip) {
if (scan[i].bm_bighint == (swblk_t)-1)
break;
if (next_skip == 1) {
scan[i].u.bmu_bitmap = (u_swblk_t)-1;
scan[i].bm_bighint = BLIST_BMAP_RADIX;
} else {
scan[i].bm_bighint = (swblk_t)radix;
scan[i].u.bmu_avail = (swblk_t)radix;
}
}
} else {
radix /= BLIST_META_RADIX;
}
for (i = 1; i <= skip; i += next_skip) {
if (scan[i].bm_bighint == (swblk_t)-1) {
break;
}
if (count <= scan[i].bm_bighint &&
blk + (swblk_t)radix > blkat) {
swblk_t r;
if (next_skip == 1) {
r = blst_leaf_alloc(&scan[i], blkat,
blk, count);
} else {
r = blst_meta_alloc(&scan[i], blkat,
blk, count,
radix, next_skip - 1);
}
if (r != SWAPBLK_NONE) {
scan->u.bmu_avail -= count;
if (scan->bm_bighint > scan->u.bmu_avail)
scan->bm_bighint = scan->u.bmu_avail;
return(r);
}
} else if (count > (swblk_t)radix) {
panic("%s: allocation too large %lu/%lu",
__func__, count, radix);
}
blk += (swblk_t)radix;
}
if (hintok && scan->bm_bighint >= count)
scan->bm_bighint = count - 1;
return(SWAPBLK_NONE);
}
static void
blst_leaf_free(blmeta_t *scan, swblk_t blk, swblk_t count)
{
int n = blk & (BLIST_BMAP_RADIX - 1);
u_swblk_t mask;
mask = ((u_swblk_t)-1 << n) &
((u_swblk_t)-1 >> (BLIST_BMAP_RADIX - count - n));
if (scan->u.bmu_bitmap & mask)
panic("%s: freeing free block", __func__);
scan->u.bmu_bitmap |= mask;
scan->bm_bighint = BLIST_BMAP_RADIX;
}
static void
blst_meta_free(blmeta_t *scan, swblk_t freeBlk, swblk_t count,
swblk_t radix, swblk_t skip, swblk_t blk)
{
swblk_t i;
swblk_t next_skip = ((swblk_t)skip / BLIST_META_RADIX);
#if 0
printf("FREE (%04lx,%lu) FROM (%04lx,%lu)\n",
freeBlk, count,
blk, radix
);
#endif
if (scan->u.bmu_avail == 0) {
scan->u.bmu_avail = count;
scan->bm_bighint = count;
if (count != radix) {
for (i = 1; i <= skip; i += next_skip) {
if (scan[i].bm_bighint == (swblk_t)-1)
break;
scan[i].bm_bighint = 0;
if (next_skip == 1) {
scan[i].u.bmu_bitmap = 0;
} else {
scan[i].u.bmu_avail = 0;
}
}
}
} else {
scan->u.bmu_avail += count;
}
if (scan->u.bmu_avail == radix) {
scan->bm_bighint = radix;
return;
}
if (scan->u.bmu_avail > radix) {
panic("%s: freeing already "
"free blocks (%lu) %lu/%lu",
__func__, count, (long)scan->u.bmu_avail, radix);
}
radix /= BLIST_META_RADIX;
i = (freeBlk - blk) / (swblk_t)radix;
blk += i * (swblk_t)radix;
i = i * next_skip + 1;
while (i <= skip && blk < freeBlk + count) {
swblk_t v;
v = blk + (swblk_t)radix - freeBlk;
if (v > count)
v = count;
if (scan->bm_bighint == (swblk_t)-1)
panic("%s: freeing unexpected range", __func__);
if (next_skip == 1) {
blst_leaf_free(&scan[i], freeBlk, v);
} else {
blst_meta_free(&scan[i], freeBlk, v,
radix, next_skip - 1, blk);
}
if (scan->bm_bighint < scan[i].bm_bighint) {
scan->bm_bighint = scan[i].bm_bighint;
}
count -= v;
freeBlk += v;
blk += (swblk_t)radix;
i += next_skip;
}
}
static swblk_t
blst_leaf_fill(blmeta_t *scan, swblk_t blk, swblk_t count)
{
int n = blk & (BLIST_BMAP_RADIX - 1);
swblk_t nblks;
u_swblk_t mask, bitmap;
mask = ((u_swblk_t)-1 << n) &
((u_swblk_t)-1 >> (BLIST_BMAP_RADIX - count - n));
bitmap = scan->u.bmu_bitmap & mask;
for (nblks = 0; bitmap != 0; nblks++)
bitmap &= bitmap - 1;
scan->u.bmu_bitmap &= ~mask;
return (nblks);
}
static swblk_t
blst_meta_fill(blmeta_t *scan, swblk_t fillBlk, swblk_t count,
swblk_t radix, swblk_t skip, swblk_t blk)
{
swblk_t i;
swblk_t next_skip = ((swblk_t)skip / BLIST_META_RADIX);
swblk_t nblks = 0;
if (count == radix || scan->u.bmu_avail == 0) {
nblks = scan->u.bmu_avail;
scan->u.bmu_avail = 0;
scan->bm_bighint = count;
return (nblks);
}
if (scan->u.bmu_avail == radix) {
radix /= BLIST_META_RADIX;
for (i = 1; i <= skip; i += next_skip) {
if (scan[i].bm_bighint == (swblk_t)-1)
break;
if (next_skip == 1) {
scan[i].u.bmu_bitmap = (u_swblk_t)-1;
scan[i].bm_bighint = BLIST_BMAP_RADIX;
} else {
scan[i].bm_bighint = (swblk_t)radix;
scan[i].u.bmu_avail = (swblk_t)radix;
}
}
} else {
radix /= BLIST_META_RADIX;
}
if (count > (swblk_t)radix)
panic("%s: allocation too large", __func__);
i = (fillBlk - blk) / (swblk_t)radix;
blk += i * (swblk_t)radix;
i = i * next_skip + 1;
while (i <= skip && blk < fillBlk + count) {
swblk_t v;
v = blk + (swblk_t)radix - fillBlk;
if (v > count)
v = count;
if (scan->bm_bighint == (swblk_t)-1)
panic("%s: filling unexpected range", __func__);
if (next_skip == 1) {
nblks += blst_leaf_fill(&scan[i], fillBlk, v);
} else {
nblks += blst_meta_fill(&scan[i], fillBlk, v,
radix, next_skip - 1, blk);
}
count -= v;
fillBlk += v;
blk += (swblk_t)radix;
i += next_skip;
}
scan->u.bmu_avail -= nblks;
return (nblks);
}
static void
blst_copy(blmeta_t *scan, swblk_t blk, swblk_t radix,
swblk_t skip, blist_t dest, swblk_t count)
{
swblk_t next_skip;
swblk_t i;
if (radix == BLIST_BMAP_RADIX) {
u_swblk_t v = scan->u.bmu_bitmap;
if (v == (u_swblk_t)-1) {
blist_free(dest, blk, count);
} else if (v != 0) {
for (i = 0; i < BLIST_BMAP_RADIX && i < count; ++i) {
if (v & ((swblk_t)1 << i))
blist_free(dest, blk + i, 1);
}
}
return;
}
if (scan->u.bmu_avail == 0) {
return;
}
if (scan->u.bmu_avail == radix) {
if (count < radix)
blist_free(dest, blk, count);
else
blist_free(dest, blk, (swblk_t)radix);
return;
}
radix /= BLIST_META_RADIX;
next_skip = ((u_swblk_t)skip / BLIST_META_RADIX);
for (i = 1; count && i <= skip; i += next_skip) {
if (scan[i].bm_bighint == (swblk_t)-1)
break;
if (count >= (swblk_t)radix) {
blst_copy(
&scan[i],
blk,
radix,
next_skip - 1,
dest,
(swblk_t)radix
);
count -= (swblk_t)radix;
} else {
if (count) {
blst_copy(
&scan[i],
blk,
radix,
next_skip - 1,
dest,
count
);
}
count = 0;
}
blk += (swblk_t)radix;
}
}
static swblk_t
blst_radix_init(blmeta_t *scan, swblk_t radix, swblk_t skip, swblk_t count)
{
swblk_t i;
swblk_t next_skip;
swblk_t memindex = 0;
if (radix == BLIST_BMAP_RADIX) {
if (scan) {
scan->bm_bighint = 0;
scan->u.bmu_bitmap = 0;
}
return(memindex);
}
if (scan) {
scan->bm_bighint = 0;
scan->u.bmu_avail = 0;
}
radix /= BLIST_META_RADIX;
next_skip = ((u_swblk_t)skip / BLIST_META_RADIX);
for (i = 1; i <= skip; i += next_skip) {
if (count >= (swblk_t)radix) {
memindex = i + blst_radix_init(
((scan) ? &scan[i] : NULL),
radix,
next_skip - 1,
(swblk_t)radix
);
count -= (swblk_t)radix;
} else if (count > 0) {
memindex = i + blst_radix_init(
((scan) ? &scan[i] : NULL),
radix,
next_skip - 1,
count
);
count = 0;
} else {
if (scan)
scan[i].bm_bighint = (swblk_t)-1;
break;
}
}
if (memindex < i)
memindex = i;
return(memindex);
}
#if defined(BLIST_DEBUG) || defined(DDB)
static void
blst_radix_print(blmeta_t *scan, swblk_t blk, swblk_t radix, swblk_t skip, int tab)
{
swblk_t i;
swblk_t next_skip;
if (radix == BLIST_BMAP_RADIX) {
printf(
"%*.*s(%04lx,%lu): bitmap %0*llx big=%lu\n",
tab, tab, "",
blk, radix,
(int)(1 + (BLIST_BMAP_RADIX - 1) / 4),
scan->u.bmu_bitmap,
scan->bm_bighint
);
return;
}
if (scan->u.bmu_avail == 0) {
printf(
"%*.*s(%04lx,%lu) ALL ALLOCATED\n",
tab, tab, "",
blk,
radix
);
return;
}
if (scan->u.bmu_avail == radix) {
printf(
"%*.*s(%04lx,%lu) ALL FREE\n",
tab, tab, "",
blk,
radix
);
return;
}
printf(
"%*.*s(%04lx,%lu): subtree (%lu/%lu) big=%lu {\n",
tab, tab, "",
blk, radix,
scan->u.bmu_avail,
radix,
scan->bm_bighint
);
radix /= BLIST_META_RADIX;
next_skip = ((u_swblk_t)skip / BLIST_META_RADIX);
tab += 4;
for (i = 1; i <= skip; i += next_skip) {
if (scan[i].bm_bighint == (swblk_t)-1) {
printf(
"%*.*s(%04lx,%lu): Terminator\n",
tab, tab, "",
blk, radix
);
break;
}
blst_radix_print(
&scan[i],
blk,
radix,
next_skip - 1,
tab
);
blk += (swblk_t)radix;
}
tab -= 4;
printf(
"%*.*s}\n",
tab, tab, ""
);
}
#endif
#if !defined(_KERNEL) && defined(BLIST_DEBUG)
int
main(int ac, char **av)
{
swblk_t size = 1024;
swblk_t i;
blist_t bl;
for (i = 1; i < (swblk_t)ac; ++i) {
const char *ptr = av[i];
if (*ptr != '-') {
size = strtol(ptr, NULL, 0);
continue;
}
ptr += 2;
fprintf(stderr, "Bad option: %s\n", ptr - 2);
exit(1);
}
bl = blist_create(size);
blist_free(bl, 0, size);
for (;;) {
char buf[1024];
swblk_t da = 0;
swblk_t count = 0;
swblk_t blkat;
printf("%lu/%lu/%lu> ",
bl->bl_free, size, bl->bl_radix);
fflush(stdout);
if (fgets(buf, sizeof(buf), stdin) == NULL)
break;
switch(buf[0]) {
case '#':
continue;
case 'r':
if (sscanf(buf + 1, "%li", &count) == 1) {
blist_resize(&bl, count, 1);
size = count;
} else {
printf("?\n");
}
case 'p':
blist_print(bl);
break;
case 'a':
if (sscanf(buf + 1, "%li %li", &count, &blkat) == 1) {
printf("count %lu\n", count);
swblk_t blk = blist_alloc(bl, count);
if (blk == SWAPBLK_NONE)
printf(" R=SWAPBLK_NONE\n");
else
printf(" R=%04lx\n", blk);
} else if (sscanf(buf + 1, "%li %li", &count, &blkat) == 2) {
swblk_t blk = blist_allocat(bl, count, blkat);
if (blk == SWAPBLK_NONE)
printf(" R=SWAPBLK_NONE\n");
else
printf(" R=%04lx\n", blk);
} else {
printf("?\n");
}
break;
case 'f':
if (sscanf(buf + 1, "%li %li", &da, &count) == 2) {
blist_free(bl, da, count);
} else {
printf("?\n");
}
break;
case 'g': {
swblk_t b, e;
blist_gapfind(bl, &b, &e);
printf("gapfind: begin=%04lx end=%04lx size=%lu\n",
b, e, e-b);
break;
}
case 'l':
if (sscanf(buf + 1, "%li %li", &da, &count) == 2) {
printf(" n=%lu\n",
blist_fill(bl, da, count));
} else {
printf("?\n");
}
break;
case '?':
case 'h':
puts(
"p -print\n"
"a %li -allocate\n"
"f %li %li -free\n"
"l %li %li -fill\n"
"g -gapfind\n"
"r %li -resize\n"
"h/? -help\n"
" hex may be specified with 0x prefix\n"
);
break;
default:
printf("?\n");
break;
}
}
return(0);
}
#endif