From owner-svn-src-user@FreeBSD.ORG Thu May 8 01:13:20 2014 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 860685D8; Thu, 8 May 2014 01:13:20 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 6703B780; Thu, 8 May 2014 01:13:20 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s481DKZs095874; Thu, 8 May 2014 01:13:20 GMT (envelope-from marcel@svn.freebsd.org) Received: (from marcel@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s481DJPD095868; Thu, 8 May 2014 01:13:19 GMT (envelope-from marcel@svn.freebsd.org) Message-Id: <201405080113.s481DJPD095868@svn.freebsd.org> From: Marcel Moolenaar Date: Thu, 8 May 2014 01:13:19 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r265625 - user/marcel/mkimg X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 08 May 2014 01:13:20 -0000 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 +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#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 + +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 #include +#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 \n", getprogname()); @@ -75,13 +77,19 @@ usage(const char *why) fprintf(stderr, "\t-S \t- logical sector size\n"); fprintf(stderr, "\t-T \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- empty partition of given " "size\n"); fprintf(stderr, "\t[/]:=\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 +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include + +#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 +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include + +#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);