Home | History | Annotate | Line # | Download | only in librumpuser
      1  1.5   pooka /*	$NetBSD: rumpfiber_bio.c,v 1.5 2014/11/04 19:05:17 pooka Exp $	*/
      2  1.3   pooka 
      3  1.1  justin /*-
      4  1.1  justin  * Copyright (c) 2014 Antti Kantee.  All Rights Reserved.
      5  1.1  justin  *
      6  1.1  justin  * Redistribution and use in source and binary forms, with or without
      7  1.1  justin  * modification, are permitted provided that the following conditions
      8  1.1  justin  * are met:
      9  1.1  justin  * 1. Redistributions of source code must retain the above copyright
     10  1.1  justin  *    notice, this list of conditions and the following disclaimer.
     11  1.1  justin  * 2. Redistributions in binary form must reproduce the above copyright
     12  1.1  justin  *    notice, this list of conditions and the following disclaimer in the
     13  1.1  justin  *    documentation and/or other materials provided with the distribution.
     14  1.1  justin  *
     15  1.1  justin  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
     16  1.1  justin  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     17  1.1  justin  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     18  1.1  justin  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     19  1.1  justin  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     20  1.1  justin  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     21  1.1  justin  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     22  1.1  justin  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     23  1.1  justin  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     24  1.1  justin  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     25  1.1  justin  * SUCH DAMAGE.
     26  1.1  justin  */
     27  1.1  justin 
     28  1.1  justin #include "rumpuser_port.h"
     29  1.1  justin 
     30  1.1  justin #if !defined(lint)
     31  1.5   pooka __RCSID("$NetBSD: rumpfiber_bio.c,v 1.5 2014/11/04 19:05:17 pooka Exp $");
     32  1.1  justin #endif /* !lint */
     33  1.1  justin 
     34  1.1  justin #include <sys/types.h>
     35  1.1  justin 
     36  1.2  justin #include <errno.h>
     37  1.1  justin #include <stdint.h>
     38  1.1  justin #include <unistd.h>
     39  1.1  justin 
     40  1.1  justin #include <rump/rumpuser.h>
     41  1.1  justin 
     42  1.1  justin #include "rumpuser_int.h"
     43  1.1  justin 
     44  1.1  justin void
     45  1.1  justin rumpuser_bio(int fd, int op, void *data, size_t dlen, int64_t doff,
     46  1.1  justin 	rump_biodone_fn biodone, void *bioarg)
     47  1.1  justin {
     48  1.1  justin 	ssize_t rv;
     49  1.1  justin 	int error = 0;
     50  1.1  justin 
     51  1.1  justin 	if (op & RUMPUSER_BIO_READ) {
     52  1.1  justin 		if ((rv = pread(fd, data, dlen, doff)) == -1)
     53  1.4  justin 			error = rumpuser__errtrans(errno);
     54  1.1  justin 	} else {
     55  1.1  justin 		if ((rv = pwrite(fd, data, dlen, doff)) == -1)
     56  1.4  justin 			error = rumpuser__errtrans(errno);
     57  1.1  justin 		if (error == 0 && (op & RUMPUSER_BIO_SYNC)) {
     58  1.5   pooka #ifdef HAVE_FSYNC_RANGE
     59  1.1  justin 			fsync_range(fd, FDATASYNC, doff, dlen);
     60  1.1  justin #else
     61  1.1  justin 			fsync(fd);
     62  1.1  justin #endif
     63  1.1  justin 		}
     64  1.1  justin 	}
     65  1.1  justin 	if (rv == -1)
     66  1.1  justin 		rv = 0;
     67  1.1  justin 	biodone(bioarg, (size_t)rv, error);
     68  1.1  justin }
     69