From owner-svn-src-user@FreeBSD.ORG Wed Nov 26 00:58:38 2014 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 4D098753; Wed, 26 Nov 2014 00:58:38 +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 2F9A21DF; Wed, 26 Nov 2014 00:58:38 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id sAQ0wcGZ095019; Wed, 26 Nov 2014 00:58:38 GMT (envelope-from marcel@FreeBSD.org) Received: (from marcel@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id sAQ0wbPU095009; Wed, 26 Nov 2014 00:58:37 GMT (envelope-from marcel@FreeBSD.org) Message-Id: <201411260058.sAQ0wbPU095009@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: marcel set sender to marcel@FreeBSD.org using -f From: Marcel Moolenaar Date: Wed, 26 Nov 2014 00:58:37 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r275095 - user/marcel/libvdsk/libvdsk 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-1 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: Wed, 26 Nov 2014 00:58:38 -0000 Author: marcel Date: Wed Nov 26 00:58:36 2014 New Revision: 275095 URL: https://svnweb.freebsd.org/changeset/base/275095 Log: Add qcow.c, vhd.c and vmdk.c for adding support for QCOW, VHD and VMDK (resp.). These formats return nothing but errors, but help to test the probe logic. It's generally good to be able to detect a format, even if support for it is not present. It avoids treating the file as a raw disk. Added: user/marcel/libvdsk/libvdsk/qcow.c (contents, props changed) user/marcel/libvdsk/libvdsk/vhd.c (contents, props changed) user/marcel/libvdsk/libvdsk/vmdk.c (contents, props changed) Modified: user/marcel/libvdsk/libvdsk/Makefile Modified: user/marcel/libvdsk/libvdsk/Makefile ============================================================================== --- user/marcel/libvdsk/libvdsk/Makefile Wed Nov 26 00:48:07 2014 (r275094) +++ user/marcel/libvdsk/libvdsk/Makefile Wed Nov 26 00:58:36 2014 (r275095) @@ -8,7 +8,10 @@ INCS= vdsk.h # List of formats to support SRCS+= \ - raw.c + qcow.c \ + raw.c \ + vhd.c \ + vmdk.c DEBUG_FLAGS=-O0 -gdwarf-2 Added: user/marcel/libvdsk/libvdsk/qcow.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/marcel/libvdsk/libvdsk/qcow.c Wed Nov 26 00:58:36 2014 (r275095) @@ -0,0 +1,148 @@ +/*- + * Copyright (c) 2014 Marcel Moolenaar + * 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 + +#include "vdsk_int.h" + +/* Flag bits in cluster offsets */ +#define QCOW_CLSTR_COMPRESSED (1ULL << 62) +#define QCOW_CLSTR_COPIED (1ULL << 63) + +struct qcow_header { + uint32_t magic; +#define QCOW_MAGIC 0x514649fb + uint32_t version; +#define QCOW_VERSION_1 1 +#define QCOW_VERSION_2 2 + uint64_t path_offset; + uint32_t path_length; + uint32_t clstr_log2sz; /* v2 only */ + uint64_t disk_size; + union { + struct { + uint8_t clstr_log2sz; + uint8_t l2_log2sz; + uint16_t _pad; + uint32_t encryption; + uint64_t l1_offset; + } v1; + struct { + uint32_t encryption; + uint32_t l1_entries; + uint64_t l1_offset; + uint64_t refcnt_offset; + uint32_t refcnt_entries; + uint32_t snapshot_count; + uint64_t snapshot_offset; + } v2; + } u; +}; + +static int +qcow_probe(struct vdsk *vdsk) +{ + struct qcow_header *hdr; + + if (vdsk->sectorsize < 512 || vdsk->sectorsize > 4096) + return (ENOTBLK); + + hdr = malloc(vdsk->sectorsize); + if (hdr == NULL) + return (errno); + + if (read(vdsk->fd, hdr, vdsk->sectorsize) != vdsk->sectorsize) + return (errno); + + if (be32dec(&hdr->magic) != QCOW_MAGIC) + return (ENXIO); + + return (0); +} + +static int +qcow_open(struct vdsk *vdsk __unused) +{ + + return (ENOSYS); +} + +static int +qcow_close(struct vdsk *vdsk __unused) +{ + + return (ENOSYS); +} + +static int +qcow_read(struct vdsk *vdsk __unused, const struct iovec *iov __unused, + int iovcnt __unused, off_t offset __unused) +{ + + return (ENOSYS); +} + +static int +qcow_write(struct vdsk *vdsk __unused, const struct iovec *iov __unused, + int iovcnt __unused, off_t offset __unused) +{ + + return (ENOSYS); +} + +static int +qcow_flush(struct vdsk *vdsk __unused) +{ + + return (ENOSYS); +} + +static struct vdsk_format qcow_format = { + .name = "qcow", + .description = "QEMU Copy-On-Write, version 1", + .flags = VDSKFMT_HAS_HEADER, + .probe = qcow_probe, + .open = qcow_open, + .close = qcow_close, + .read = qcow_read, + .write = qcow_write, + .flush = qcow_flush, +}; +FORMAT_DEFINE(qcow_format); + Added: user/marcel/libvdsk/libvdsk/vhd.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/marcel/libvdsk/libvdsk/vhd.c Wed Nov 26 00:58:36 2014 (r275095) @@ -0,0 +1,100 @@ +/*- + * Copyright (c) 2014 Marcel Moolenaar + * 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 + +#include "vdsk_int.h" + +static int +vhd_probe(struct vdsk *vdsk __unused) +{ + + return (ENOSYS); +} + +static int +vhd_open(struct vdsk *vdsk __unused) +{ + + return (ENOSYS); +} + +static int +vhd_close(struct vdsk *vdsk __unused) +{ + + return (ENOSYS); +} + +static int +vhd_read(struct vdsk *vdsk __unused, const struct iovec *iov __unused, + int iovcnt __unused, off_t offset __unused) +{ + + return (ENOSYS); +} + +static int +vhd_write(struct vdsk *vdsk __unused, const struct iovec *iov __unused, + int iovcnt __unused, off_t offset __unused) +{ + + return (ENOSYS); +} + +static int +vhd_flush(struct vdsk *vdsk __unused) +{ + + return (ENOSYS); +} + +static struct vdsk_format vhd_format = { + .name = "vhd", + .description = "Virtual Hard Disk", + .flags = VDSKFMT_HAS_HEADER, + .probe = vhd_probe, + .open = vhd_open, + .close = vhd_close, + .read = vhd_read, + .write = vhd_write, + .flush = vhd_flush, +}; +FORMAT_DEFINE(vhd_format); + Added: user/marcel/libvdsk/libvdsk/vmdk.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/marcel/libvdsk/libvdsk/vmdk.c Wed Nov 26 00:58:36 2014 (r275095) @@ -0,0 +1,100 @@ +/*- + * Copyright (c) 2014 Marcel Moolenaar + * 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 + +#include "vdsk_int.h" + +static int +vmdk_probe(struct vdsk *vdsk __unused) +{ + + return (ENOSYS); +} + +static int +vmdk_open(struct vdsk *vdsk __unused) +{ + + return (ENOSYS); +} + +static int +vmdk_close(struct vdsk *vdsk __unused) +{ + + return (ENOSYS); +} + +static int +vmdk_read(struct vdsk *vdsk __unused, const struct iovec *iov __unused, + int iovcnt __unused, off_t offset __unused) +{ + + return (ENOSYS); +} + +static int +vmdk_write(struct vdsk *vdsk __unused, const struct iovec *iov __unused, + int iovcnt __unused, off_t offset __unused) +{ + + return (ENOSYS); +} + +static int +vmdk_flush(struct vdsk *vdsk __unused) +{ + + return (ENOSYS); +} + +static struct vdsk_format vmdk_format = { + .name = "vmdk", + .description = "Virtual Machine Disk", + .flags = VDSKFMT_HAS_HEADER, + .probe = vmdk_probe, + .open = vmdk_open, + .close = vmdk_close, + .read = vmdk_read, + .write = vmdk_write, + .flush = vmdk_flush, +}; +FORMAT_DEFINE(vmdk_format); +