Commit 926ed232 authored by Alessandro Rubini's avatar Alessandro Rubini

sdbfs/userspace: allow user-privided placement for dirs

This is a trivial patch, swapping two blocks and adding a few
lines, so to allow "position=" and "maxsize=" to be used for
subdirectories.

This allows to reserve space for a new SDBFS image to be added
at a later time.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent c375a87e
...@@ -344,6 +344,7 @@ static struct sdbf *scan_config(struct sdbf *tree, FILE *f) ...@@ -344,6 +344,7 @@ static struct sdbf *scan_config(struct sdbf *tree, FILE *f)
static struct sdbf *alloc_storage(struct sdbf *tree) static struct sdbf *alloc_storage(struct sdbf *tree)
{ {
int i, n; int i, n;
unsigned long subsize;
unsigned long rpos; /* the next expected relative position */ unsigned long rpos; /* the next expected relative position */
unsigned long l, last; /* keep track of last, for directory record */ unsigned long l, last; /* keep track of last, for directory record */
struct sdbf *f, *sub; struct sdbf *f, *sub;
...@@ -357,13 +358,7 @@ static struct sdbf *alloc_storage(struct sdbf *tree) ...@@ -357,13 +358,7 @@ static struct sdbf *alloc_storage(struct sdbf *tree)
for (i = 1; i < n; i++) { for (i = 1; i < n; i++) {
f = tree + i; f = tree + i;
if (f->userpos) { /* user-specified position (level 0) */
f->s_d.sdb_component.addr_first = htonll(f->ustart);
l = f->ustart + f->size - 1;
f->s_d.sdb_component.addr_last = htonll(l);
if (l > last) last = l;
continue;
}
/* If a directory, make it allocate itself */ /* If a directory, make it allocate itself */
if (f->subdir) { if (f->subdir) {
f->subdir->base = tree->base + rpos; f->subdir->base = tree->base + rpos;
...@@ -373,9 +368,21 @@ static struct sdbf *alloc_storage(struct sdbf *tree) ...@@ -373,9 +368,21 @@ static struct sdbf *alloc_storage(struct sdbf *tree)
prgname, f->fullname); prgname, f->fullname);
return NULL; return NULL;
} }
f->size = ntohll(sub->s_i.sdb_component.addr_last); /* this size may have been set by the user */
subsize = ntohll(sub->s_i.sdb_component.addr_last);
if (subsize > f->size)
f->size = subsize;
f->s_b.sdb_child = htonll(rpos); f->s_b.sdb_child = htonll(rpos);
} }
if (f->userpos) { /* user-specified position (level 0) */
f->s_d.sdb_component.addr_first = htonll(f->ustart);
l = f->ustart + f->size - 1;
f->s_d.sdb_component.addr_last = htonll(l);
if (l > last) last = l;
continue;
}
/* position not mandated: go sequential from previous one */ /* position not mandated: go sequential from previous one */
f->rstart = rpos; f->rstart = rpos;
f->s_d.sdb_component.addr_first = htonll(rpos); f->s_d.sdb_component.addr_first = htonll(rpos);
...@@ -490,8 +497,8 @@ static int usage(char *prgname) ...@@ -490,8 +497,8 @@ static int usage(char *prgname)
prgname, prgname); prgname, prgname);
fprintf(stderr, " -b <number> : block size (default 64)\n"); fprintf(stderr, " -b <number> : block size (default 64)\n");
fprintf(stderr, " -s <number> : device size (default: as needed)\n"); fprintf(stderr, " -s <number> : device size (default: as needed)\n");
fprintf(stderr, " a file called \"" CFG_NAME "\", in the root of\n" fprintf(stderr, " a file called \"" CFG_NAME "\", in each "
" <inputdir> is used as configuration file\n"); "subdir is used as configuration file\n");
exit(1); exit(1);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment