138465Smsmith/* 2119482Sobrien * $NetBSD: pread.c,v 1.2 1997/03/22 01:48:38 thorpej Exp $ 338465Smsmith */ 438465Smsmith 5119482Sobrien/*- 638465Smsmith * Copyright (c) 1996 738465Smsmith * Matthias Drochner. All rights reserved. 838465Smsmith * 938465Smsmith * Redistribution and use in source and binary forms, with or without 1038465Smsmith * modification, are permitted provided that the following conditions 1138465Smsmith * are met: 1238465Smsmith * 1. Redistributions of source code must retain the above copyright 1338465Smsmith * notice, this list of conditions and the following disclaimer. 1438465Smsmith * 2. Redistributions in binary form must reproduce the above copyright 1538465Smsmith * notice, this list of conditions and the following disclaimer in the 1638465Smsmith * documentation and/or other materials provided with the distribution. 1738465Smsmith * 3. All advertising materials mentioning features or use of this software 1838465Smsmith * must display the following acknowledgement: 1938465Smsmith * This product includes software developed for the NetBSD Project 2038465Smsmith * by Matthias Drochner. 2138465Smsmith * 4. The name of the author may not be used to endorse or promote products 2238465Smsmith * derived from this software without specific prior written permission. 2338465Smsmith * 2438465Smsmith * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 2538465Smsmith * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 2638465Smsmith * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2738465Smsmith * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2838465Smsmith * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2938465Smsmith * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 3038465Smsmith * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 3138465Smsmith * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 3238465Smsmith * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 3338465Smsmith * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3438465Smsmith */ 3538465Smsmith 36119482Sobrien#include <sys/cdefs.h> 37119482Sobrien__FBSDID("$FreeBSD: releng/10.3/sys/boot/i386/libi386/pread.c 119482 2003-08-25 23:28:32Z obrien $"); 38119482Sobrien 3938465Smsmith/* read into destination in flat addr space */ 4038465Smsmith 4138465Smsmith#include <stand.h> 4238465Smsmith 4338465Smsmith#include "libi386.h" 4438465Smsmith 4538465Smsmith#ifdef SAVE_MEMORY 4638465Smsmith#define BUFSIZE (1*1024) 4738465Smsmith#else 4838465Smsmith#define BUFSIZE (4*1024) 4938465Smsmith#endif 5038465Smsmith 5138465Smsmithstatic char buf[BUFSIZE]; 5238465Smsmith 5338465Smsmithint 5438465Smsmithpread(fd, dest, size) 5538465Smsmith int fd; 5638465Smsmith vm_offset_t dest; 5738465Smsmith int size; 5838465Smsmith{ 5938465Smsmith int rsize; 6038465Smsmith 6138465Smsmith rsize = size; 6238465Smsmith while (rsize > 0) { 6338465Smsmith int count, got; 6438465Smsmith 6538465Smsmith count = (rsize < BUFSIZE ? rsize : BUFSIZE); 6638465Smsmith 6738465Smsmith got = read(fd, buf, count); 6838465Smsmith if (got < 0) 6938465Smsmith return (-1); 7038465Smsmith 7138465Smsmith /* put to physical space */ 7238465Smsmith vpbcopy(buf, dest, got); 7338465Smsmith 7438465Smsmith dest += got; 7538465Smsmith rsize -= got; 7638465Smsmith if (got < count) 7738465Smsmith break; /* EOF */ 7838465Smsmith } 7938465Smsmith return (size - rsize); 8038465Smsmith} 81