Date: Thu, 8 May 2014 01:13:19 +0000 (UTC) From: Marcel Moolenaar <marcel@FreeBSD.org> To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r265625 - user/marcel/mkimg Message-ID: <201405080113.s481DJPD095868@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: marcel Date: Thu May 8 01:13:18 2014 New Revision: 265625 URL: http://svnweb.freebsd.org/changeset/base/265625 Log: Add a linker set for output formats. This is mostly copied and trimmed from the linker set for schemes. Add stubs for raw and vmdk output formats so as to demonstrate that the usage message is correct. Added: user/marcel/mkimg/format.c (contents, props changed) user/marcel/mkimg/format.h (contents, props changed) user/marcel/mkimg/raw.c (contents, props changed) user/marcel/mkimg/vmdk.c (contents, props changed) Modified: user/marcel/mkimg/Makefile user/marcel/mkimg/mkimg.c Modified: user/marcel/mkimg/Makefile ============================================================================== --- user/marcel/mkimg/Makefile Thu May 8 00:26:21 2014 (r265624) +++ user/marcel/mkimg/Makefile Thu May 8 01:13:18 2014 (r265625) @@ -1,11 +1,16 @@ # $FreeBSD$ PROG= mkimg -SRCS= image.c mkimg.c scheme.c +SRCS= format.c image.c mkimg.c scheme.c MAN= mkimg.1 CFLAGS+=-DSPARSE_WRITE +# List of formats to support +SRCS+= \ + raw.c \ + vmdk.c + # List of schemes to support SRCS+= \ apm.c \ Added: user/marcel/mkimg/format.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/marcel/mkimg/format.c Thu May 8 01:13:18 2014 (r265625) @@ -0,0 +1,67 @@ +/*- + * Copyright (c) 2014 Juniper Networks, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <sys/types.h> +#include <sys/linker_set.h> +#include <sys/queue.h> +#include <sys/stat.h> +#include <err.h> +#include <errno.h> +#include <stdint.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include "format.h" +#include "image.h" +#include "mkimg.h" + +static struct mkimg_format *format; + +int +format_select(const char *spec) +{ + struct mkimg_format *f, **iter; + + SET_FOREACH(iter, formats) { + f = *iter; + if (strcasecmp(spec, f->name) == 0) { + format = f; + return (0); + } + } + return (EINVAL); +} + +struct mkimg_format * +format_selected(void) +{ + + return (format); +} Added: user/marcel/mkimg/format.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/marcel/mkimg/format.h Thu May 8 01:13:18 2014 (r265625) @@ -0,0 +1,46 @@ +/*- + * Copyright (c) 2014 Juniper Networks, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _MKIMG_FORMAT_H_ +#define _MKIMG_FORMAT_H_ + +#include <sys/linker_set.h> + +struct mkimg_format { + const char *name; + const char *description; + int (*write)(int); +}; + +SET_DECLARE(formats, struct mkimg_format); +#define FORMAT_DEFINE(nm) DATA_SET(formats, nm) + +int format_select(const char *); +struct mkimg_format *format_selected(void); + +#endif /* _MKIMG_FORMAT_H_ */ Modified: user/marcel/mkimg/mkimg.c ============================================================================== --- user/marcel/mkimg/mkimg.c Thu May 8 00:26:21 2014 (r265624) +++ user/marcel/mkimg/mkimg.c Thu May 8 01:13:18 2014 (r265625) @@ -42,6 +42,7 @@ __FBSDID("$FreeBSD$"); #include <sysexits.h> #include <unistd.h> +#include "format.h" #include "image.h" #include "mkimg.h" #include "scheme.h" @@ -60,7 +61,8 @@ u_int blksz = 0; static void usage(const char *why) { - struct mkimg_scheme *s, **iter; + struct mkimg_format *f, **f_iter; + struct mkimg_scheme *s, **s_iter; warnx("error: %s", why); fprintf(stderr, "\nusage: %s <options>\n", getprogname()); @@ -75,13 +77,19 @@ usage(const char *why) fprintf(stderr, "\t-S <num>\t- logical sector size\n"); fprintf(stderr, "\t-T <num>\t- number of tracks to simulate\n"); - fprintf(stderr, " schemes:\n"); - SET_FOREACH(iter, schemes) { - s = *iter; + fprintf(stderr, "\n formats:\n"); + SET_FOREACH(f_iter, formats) { + f = *f_iter; + fprintf(stderr, "\t%s\t- %s\n", f->name, f->description); + } + + fprintf(stderr, "\n schemes:\n"); + SET_FOREACH(s_iter, schemes) { + s = *s_iter; fprintf(stderr, "\t%s\t- %s\n", s->name, s->description); } - fprintf(stderr, " partition specification:\n"); + fprintf(stderr, "\n partition specification:\n"); fprintf(stderr, "\t<t>[/<l>]::<size>\t- empty partition of given " "size\n"); fprintf(stderr, "\t<t>[/<l>]:=<file>\t- partition content and size " Added: user/marcel/mkimg/raw.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/marcel/mkimg/raw.c Thu May 8 01:13:18 2014 (r265625) @@ -0,0 +1,55 @@ +/*- + * Copyright (c) 2014 Juniper Networks, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <sys/types.h> +#include <sys/apm.h> +#include <sys/endian.h> +#include <sys/errno.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include "format.h" +#include "image.h" +#include "mkimg.h" + +static int +raw_write(int fd __unused) +{ + + return (ENOSYS); +} + +static struct mkimg_format raw_format = { + .name = "raw", + .description = "Raw Disk", + .write = raw_write, +}; + +FORMAT_DEFINE(raw_format); Added: user/marcel/mkimg/vmdk.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/marcel/mkimg/vmdk.c Thu May 8 01:13:18 2014 (r265625) @@ -0,0 +1,55 @@ +/*- + * Copyright (c) 2014 Juniper Networks, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <sys/types.h> +#include <sys/apm.h> +#include <sys/endian.h> +#include <sys/errno.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include "format.h" +#include "image.h" +#include "mkimg.h" + +static int +vmdk_write(int fd __unused) +{ + + return (ENOSYS); +} + +static struct mkimg_format vmdk_format = { + .name = "vmdk", + .description = "Virtual Machine Disk", + .write = vmdk_write, +}; + +FORMAT_DEFINE(vmdk_format);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201405080113.s481DJPD095868>