Don't require a scheme if no partitions are given. Change the code

to handle that case. Note that we still require partitions, so the
change is effectively a no-op.
This commit is contained in:
Marcel Moolenaar 2015-02-22 01:20:49 +00:00
parent 8617260a03
commit aba885c960
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=279128
2 changed files with 13 additions and 10 deletions

View File

@ -541,7 +541,7 @@ main(int argc, char *argv[])
if (argc > optind)
usage("trailing arguments");
if (scheme_selected() == NULL)
if (scheme_selected() == NULL && nparts > 0)
usage("no scheme");
if (nparts == 0)
usage("no partitions");
@ -577,8 +577,9 @@ main(int argc, char *argv[])
fprintf(stderr, "Sectors per track: %u\n", nsecs);
fprintf(stderr, "Number of heads: %u\n", nheads);
fputc('\n', stderr);
fprintf(stderr, "Partitioning scheme: %s\n",
scheme_selected()->name);
if (scheme_selected())
fprintf(stderr, "Partitioning scheme: %s\n",
scheme_selected()->name);
fprintf(stderr, "Output file format: %s\n",
format_selected()->name);
fputc('\n', stderr);

View File

@ -31,8 +31,10 @@ __FBSDID("$FreeBSD$");
#include <sys/linker_set.h>
#include <sys/queue.h>
#include <sys/stat.h>
#include <assert.h>
#include <err.h>
#include <errno.h>
#include <limits.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
@ -104,7 +106,7 @@ scheme_bootcode(int fd)
{
struct stat sb;
if (scheme->bootcode == 0)
if (scheme == NULL || scheme->bootcode == 0)
return (ENXIO);
if (fstat(fd, &sb) == -1)
@ -130,6 +132,8 @@ scheme_check_part(struct part *p)
struct mkimg_alias *iter;
enum alias alias;
assert(scheme != NULL);
/* Check the partition type alias */
alias = scheme_parse_alias(p->alias);
if (alias == ALIAS_NONE)
@ -158,28 +162,26 @@ u_int
scheme_max_parts(void)
{
return (scheme->nparts);
return ((scheme == NULL) ? 0 : scheme->nparts);
}
u_int
scheme_max_secsz(void)
{
return (scheme->maxsecsz);
return ((scheme == NULL) ? INT_MAX+1U : scheme->maxsecsz);
}
lba_t
scheme_metadata(u_int where, lba_t start)
{
return (scheme->metadata(where, start));
return ((scheme == NULL) ? start : scheme->metadata(where, start));
}
int
scheme_write(lba_t end)
{
int error;
error = scheme->write(end, bootcode);
return (error);
return ((scheme == NULL) ? 0 : scheme->write(end, bootcode));
}