Index: user/marcel/libvdsk/libvdsk/Makefile =================================================================== --- user/marcel/libvdsk/libvdsk/Makefile (nonexistent) +++ user/marcel/libvdsk/libvdsk/Makefile (revision 274779) @@ -0,0 +1,7 @@ +# $FreeBSD$ + +LIB= vdsk +SRCS= vdsk.c +INCS= vdsk.h + +.include Property changes on: user/marcel/libvdsk/libvdsk/Makefile ___________________________________________________________________ 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/vdsk.c =================================================================== --- user/marcel/libvdsk/libvdsk/vdsk.c (nonexistent) +++ user/marcel/libvdsk/libvdsk/vdsk.c (revision 274779) @@ -0,0 +1,150 @@ +/*- + * 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 "vdsk_int.h" + +static struct vdsk * +vdsk_deref(vdskctx ctx) +{ + struct vdsk *vdsk = ctx; + + return (vdsk - 1); +} + +vdskctx +vdsk_open(const char *path, int flags, size_t size) +{ + struct stat sb; + struct vdsk *vdsk; + + size += sizeof(struct vdsk); + vdsk = malloc(size); + if (vdsk == NULL) + return (NULL); + + vdsk->fd = open(path, flags); + if (vdsk->fd == -1) { + free(vdsk); + return (NULL); + } + + if (fstat(vdsk->fd, &sb) == -1) { + close(vdsk->fd); + free(vdsk); + return (NULL); + } + + if (S_ISCHR(sb.st_mode)) { + if (ioctl(vdsk->fd, DIOCGMEDIASIZE, &vdsk->capacity) < 0 || + ioctl(vdsk->fd, DIOCGSECTORSIZE, &vdsk->sectorsize) < 0) { + close(vdsk->fd); + free(vdsk); + return (NULL); + } + } else { + vdsk->capacity = sb.st_size; + vdsk->sectorsize = DEV_BSIZE; + } + return (vdsk + 1); +} + +int +vdsk_close(vdskctx ctx) +{ + struct vdsk *vdsk = vdsk_deref(ctx); + + close(vdsk->fd); + free(vdsk); + return (0); +} + +off_t +vdsk_capacity(vdskctx ctx) +{ + struct vdsk *vdsk = vdsk_deref(ctx); + + return (vdsk->capacity); +} + +int +vdsk_sectorsize(vdskctx ctx) +{ + struct vdsk *vdsk = vdsk_deref(ctx); + + return (vdsk->sectorsize); +} + +ssize_t +vdsk_read(vdskctx ctx, void *buf, size_t nbytes, off_t offset) +{ + struct vdsk *vdsk = vdsk_deref(ctx); + ssize_t res; + + res = pread(vdsk->fd, buf, nbytes, offset); + return (res); +} + +ssize_t +vdsk_readv(vdskctx ctx, const struct iovec *iov, int iovcnt, off_t offset) +{ + struct vdsk *vdsk = vdsk_deref(ctx); + ssize_t res; + + res = preadv(vdsk->fd, iov, iovcnt, offset); + return (res); +} + +ssize_t +vdsk_writev(vdskctx ctx, const struct iovec *iov, int iovcnt, off_t offset) +{ + struct vdsk *vdsk = vdsk_deref(ctx); + ssize_t res; + + res = pwritev(vdsk->fd, iov, iovcnt, offset); + return (res); +} + +int +vdsk_flush(vdskctx ctx __unused) +{ + + return (0); +} + Property changes on: user/marcel/libvdsk/libvdsk/vdsk.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/vdsk.h =================================================================== --- user/marcel/libvdsk/libvdsk/vdsk.h (nonexistent) +++ user/marcel/libvdsk/libvdsk/vdsk.h (revision 274779) @@ -0,0 +1,50 @@ +/*- + * 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. + * + * $FreeBSD$ + */ + +#ifndef __VDSK_H__ +#define __VDSK_H__ + +#include +#include +#include + +typedef void *vdskctx; + +vdskctx vdsk_open(const char *, int, size_t); +int vdsk_close(vdskctx); + +off_t vdsk_capacity(vdskctx); +int vdsk_sectorsize(vdskctx); + +ssize_t vdsk_read(vdskctx, void *, size_t, off_t); +ssize_t vdsk_readv(vdskctx, const struct iovec *, int, off_t); +ssize_t vdsk_writev(vdskctx, const struct iovec *, int, off_t); + +int vdsk_flush(vdskctx); + +#endif /* __VDSK_H__ */ Property changes on: user/marcel/libvdsk/libvdsk/vdsk.h ___________________________________________________________________ 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/vdsk_int.h =================================================================== --- user/marcel/libvdsk/libvdsk/vdsk_int.h (nonexistent) +++ user/marcel/libvdsk/libvdsk/vdsk_int.h (revision 274779) @@ -0,0 +1,38 @@ +/*- + * 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. + * + * $FreeBSD$ + */ + +#ifndef __VDSK_INT_H__ +#define __VDSK_INT_H__ + +struct vdsk { + int fd; + int sectorsize; + off_t capacity; +}; + +#endif /* __VDSK_INT_H__ */ Property changes on: user/marcel/libvdsk/libvdsk/vdsk_int.h ___________________________________________________________________ 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