Index: user/marcel/libvdsk/libvdsk/Makefile =================================================================== --- user/marcel/libvdsk/libvdsk/Makefile (revision 275094) +++ user/marcel/libvdsk/libvdsk/Makefile (revision 275095) @@ -1,15 +1,18 @@ # $FreeBSD$ LIB= vdsk SHLIB_MAJOR= 0 SRCS= vdsk.c INCS= vdsk.h # List of formats to support SRCS+= \ - raw.c + qcow.c \ + raw.c \ + vhd.c \ + vmdk.c DEBUG_FLAGS=-O0 -gdwarf-2 .include Index: user/marcel/libvdsk/libvdsk/qcow.c =================================================================== --- user/marcel/libvdsk/libvdsk/qcow.c (nonexistent) +++ user/marcel/libvdsk/libvdsk/qcow.c (revision 275095) @@ -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); + Property changes on: user/marcel/libvdsk/libvdsk/qcow.c ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: user/marcel/libvdsk/libvdsk/vhd.c =================================================================== --- user/marcel/libvdsk/libvdsk/vhd.c (nonexistent) +++ user/marcel/libvdsk/libvdsk/vhd.c (revision 275095) @@ -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); + Property changes on: user/marcel/libvdsk/libvdsk/vhd.c ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: user/marcel/libvdsk/libvdsk/vmdk.c =================================================================== --- user/marcel/libvdsk/libvdsk/vmdk.c (nonexistent) +++ user/marcel/libvdsk/libvdsk/vmdk.c (revision 275095) @@ -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); + Property changes on: user/marcel/libvdsk/libvdsk/vmdk.c ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property