Replace the use of linker sets with constructors for both the
formats and schemes. Formats and schemes are registered at runtime now, rather than collected at link time.
This commit is contained in:
parent
a471b1ed8a
commit
a70a0571cb
@ -28,8 +28,6 @@
|
|||||||
__FBSDID("$FreeBSD$");
|
__FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/linker_set.h>
|
|
||||||
#include <sys/queue.h>
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@ -42,8 +40,24 @@ __FBSDID("$FreeBSD$");
|
|||||||
#include "format.h"
|
#include "format.h"
|
||||||
#include "mkimg.h"
|
#include "mkimg.h"
|
||||||
|
|
||||||
|
static struct mkimg_format *first;
|
||||||
static struct mkimg_format *format;
|
static struct mkimg_format *format;
|
||||||
|
|
||||||
|
struct mkimg_format *
|
||||||
|
format_iterate(struct mkimg_format *f)
|
||||||
|
{
|
||||||
|
|
||||||
|
return ((f == NULL) ? first : f->next);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
format_register(struct mkimg_format *f)
|
||||||
|
{
|
||||||
|
|
||||||
|
f->next = first;
|
||||||
|
first = f;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
format_resize(lba_t end)
|
format_resize(lba_t end)
|
||||||
{
|
{
|
||||||
@ -56,10 +70,10 @@ format_resize(lba_t end)
|
|||||||
int
|
int
|
||||||
format_select(const char *spec)
|
format_select(const char *spec)
|
||||||
{
|
{
|
||||||
struct mkimg_format *f, **iter;
|
struct mkimg_format *f;
|
||||||
|
|
||||||
SET_FOREACH(iter, formats) {
|
f = NULL;
|
||||||
f = *iter;
|
while ((f = format_iterate(f)) != NULL) {
|
||||||
if (strcasecmp(spec, f->name) == 0) {
|
if (strcasecmp(spec, f->name) == 0) {
|
||||||
format = f;
|
format = f;
|
||||||
return (0);
|
return (0);
|
||||||
|
@ -29,21 +29,24 @@
|
|||||||
#ifndef _MKIMG_FORMAT_H_
|
#ifndef _MKIMG_FORMAT_H_
|
||||||
#define _MKIMG_FORMAT_H_
|
#define _MKIMG_FORMAT_H_
|
||||||
|
|
||||||
#include <sys/linker_set.h>
|
|
||||||
|
|
||||||
struct mkimg_format {
|
struct mkimg_format {
|
||||||
|
struct mkimg_format *next;
|
||||||
const char *name;
|
const char *name;
|
||||||
const char *description;
|
const char *description;
|
||||||
int (*resize)(lba_t);
|
int (*resize)(lba_t);
|
||||||
int (*write)(int);
|
int (*write)(int);
|
||||||
};
|
};
|
||||||
|
|
||||||
SET_DECLARE(formats, struct mkimg_format);
|
#define FORMAT_DEFINE(nm) \
|
||||||
#define FORMAT_DEFINE(nm) DATA_SET(formats, nm)
|
static void format_register_##nm(void) __attribute__((constructor)); \
|
||||||
|
static void format_register_##nm(void) { format_register(&nm); }
|
||||||
|
|
||||||
int format_resize(lba_t);
|
struct mkimg_format *format_iterate(struct mkimg_format *);
|
||||||
|
void format_register(struct mkimg_format *);
|
||||||
int format_select(const char *);
|
int format_select(const char *);
|
||||||
struct mkimg_format *format_selected(void);
|
struct mkimg_format *format_selected(void);
|
||||||
|
|
||||||
|
int format_resize(lba_t);
|
||||||
int format_write(int);
|
int format_write(int);
|
||||||
|
|
||||||
#endif /* _MKIMG_FORMAT_H_ */
|
#endif /* _MKIMG_FORMAT_H_ */
|
||||||
|
@ -27,7 +27,6 @@
|
|||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
__FBSDID("$FreeBSD$");
|
__FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
#include <sys/linker_set.h>
|
|
||||||
#include <sys/queue.h>
|
#include <sys/queue.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@ -77,20 +76,20 @@ u_int blksz = 0;
|
|||||||
static void
|
static void
|
||||||
print_formats(int usage)
|
print_formats(int usage)
|
||||||
{
|
{
|
||||||
struct mkimg_format *f, **f_iter;
|
struct mkimg_format *f;
|
||||||
const char *sep;
|
const char *sep;
|
||||||
|
|
||||||
if (usage) {
|
if (usage) {
|
||||||
fprintf(stderr, " formats:\n");
|
fprintf(stderr, " formats:\n");
|
||||||
SET_FOREACH(f_iter, formats) {
|
f = NULL;
|
||||||
f = *f_iter;
|
while ((f = format_iterate(f)) != NULL) {
|
||||||
fprintf(stderr, "\t%s\t- %s\n", f->name,
|
fprintf(stderr, "\t%s\t- %s\n", f->name,
|
||||||
f->description);
|
f->description);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sep = "";
|
sep = "";
|
||||||
SET_FOREACH(f_iter, formats) {
|
f = NULL;
|
||||||
f = *f_iter;
|
while ((f = format_iterate(f)) != NULL) {
|
||||||
printf("%s%s", sep, f->name);
|
printf("%s%s", sep, f->name);
|
||||||
sep = " ";
|
sep = " ";
|
||||||
}
|
}
|
||||||
@ -101,20 +100,20 @@ print_formats(int usage)
|
|||||||
static void
|
static void
|
||||||
print_schemes(int usage)
|
print_schemes(int usage)
|
||||||
{
|
{
|
||||||
struct mkimg_scheme *s, **s_iter;
|
struct mkimg_scheme *s;
|
||||||
const char *sep;
|
const char *sep;
|
||||||
|
|
||||||
if (usage) {
|
if (usage) {
|
||||||
fprintf(stderr, " schemes:\n");
|
fprintf(stderr, " schemes:\n");
|
||||||
SET_FOREACH(s_iter, schemes) {
|
s = NULL;
|
||||||
s = *s_iter;
|
while ((s = scheme_iterate(s)) != NULL) {
|
||||||
fprintf(stderr, "\t%s\t- %s\n", s->name,
|
fprintf(stderr, "\t%s\t- %s\n", s->name,
|
||||||
s->description);
|
s->description);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sep = "";
|
sep = "";
|
||||||
SET_FOREACH(s_iter, schemes) {
|
s = NULL;
|
||||||
s = *s_iter;
|
while ((s = scheme_iterate(s)) != NULL) {
|
||||||
printf("%s%s", sep, s->name);
|
printf("%s%s", sep, s->name);
|
||||||
sep = " ";
|
sep = " ";
|
||||||
}
|
}
|
||||||
|
@ -28,8 +28,6 @@
|
|||||||
__FBSDID("$FreeBSD$");
|
__FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/linker_set.h>
|
|
||||||
#include <sys/queue.h>
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
@ -65,6 +63,7 @@ static struct {
|
|||||||
{ NULL, ALIAS_NONE } /* Keep last! */
|
{ NULL, ALIAS_NONE } /* Keep last! */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static struct mkimg_scheme *first;
|
||||||
static struct mkimg_scheme *scheme;
|
static struct mkimg_scheme *scheme;
|
||||||
static void *bootcode;
|
static void *bootcode;
|
||||||
|
|
||||||
@ -82,13 +81,27 @@ scheme_parse_alias(const char *name)
|
|||||||
return (ALIAS_NONE);
|
return (ALIAS_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct mkimg_scheme *
|
||||||
|
scheme_iterate(struct mkimg_scheme *s)
|
||||||
|
{
|
||||||
|
|
||||||
|
return ((s == NULL) ? first : s->next);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
scheme_register(struct mkimg_scheme *s)
|
||||||
|
{
|
||||||
|
s->next = first;
|
||||||
|
first = s;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
scheme_select(const char *spec)
|
scheme_select(const char *spec)
|
||||||
{
|
{
|
||||||
struct mkimg_scheme *s, **iter;
|
struct mkimg_scheme *s;
|
||||||
|
|
||||||
SET_FOREACH(iter, schemes) {
|
s = NULL;
|
||||||
s = *iter;
|
while ((s = scheme_iterate(s)) != NULL) {
|
||||||
if (strcasecmp(spec, s->name) == 0) {
|
if (strcasecmp(spec, s->name) == 0) {
|
||||||
scheme = s;
|
scheme = s;
|
||||||
return (0);
|
return (0);
|
||||||
|
@ -29,8 +29,6 @@
|
|||||||
#ifndef _MKIMG_SCHEME_H_
|
#ifndef _MKIMG_SCHEME_H_
|
||||||
#define _MKIMG_SCHEME_H_
|
#define _MKIMG_SCHEME_H_
|
||||||
|
|
||||||
#include <sys/linker_set.h>
|
|
||||||
|
|
||||||
enum alias {
|
enum alias {
|
||||||
ALIAS_NONE, /* Keep first! */
|
ALIAS_NONE, /* Keep first! */
|
||||||
/* start */
|
/* start */
|
||||||
@ -62,6 +60,7 @@ struct mkimg_alias {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct mkimg_scheme {
|
struct mkimg_scheme {
|
||||||
|
struct mkimg_scheme *next;
|
||||||
const char *name;
|
const char *name;
|
||||||
const char *description;
|
const char *description;
|
||||||
struct mkimg_alias *aliases;
|
struct mkimg_alias *aliases;
|
||||||
@ -77,9 +76,12 @@ struct mkimg_scheme {
|
|||||||
u_int maxsecsz;
|
u_int maxsecsz;
|
||||||
};
|
};
|
||||||
|
|
||||||
SET_DECLARE(schemes, struct mkimg_scheme);
|
#define SCHEME_DEFINE(nm) \
|
||||||
#define SCHEME_DEFINE(nm) DATA_SET(schemes, nm)
|
static void scheme_register_##nm(void) __attribute__((constructor)); \
|
||||||
|
static void scheme_register_##nm(void) { scheme_register(&nm); }
|
||||||
|
|
||||||
|
struct mkimg_scheme *scheme_iterate(struct mkimg_scheme *);
|
||||||
|
void scheme_register(struct mkimg_scheme *);
|
||||||
int scheme_select(const char *);
|
int scheme_select(const char *);
|
||||||
struct mkimg_scheme *scheme_selected(void);
|
struct mkimg_scheme *scheme_selected(void);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user