pread.c revision 1.1
11.1Sperry/* $NetBSD: pread.c,v 1.1 1997/03/14 02:40:33 perry Exp $ */ 21.1Sperry 31.1Sperry/* 41.1Sperry * Copyright (c) 1996 51.1Sperry * Matthias Drochner. All rights reserved. 61.1Sperry * 71.1Sperry * Redistribution and use in source and binary forms, with or without 81.1Sperry * modification, are permitted provided that the following conditions 91.1Sperry * are met: 101.1Sperry * 1. Redistributions of source code must retain the above copyright 111.1Sperry * notice, this list of conditions and the following disclaimer. 121.1Sperry * 2. Redistributions in binary form must reproduce the above copyright 131.1Sperry * notice, this list of conditions and the following disclaimer in the 141.1Sperry * documentation and/or other materials provided with the distribution. 151.1Sperry * 3. All advertising materials mentioning features or use of this software 161.1Sperry * must display the following acknowledgement: 171.1Sperry * This product includes software developed for the NetBSD Project 181.1Sperry * by Matthias Drochner. 191.1Sperry * 4. The name of the author may not be used to endorse or promote products 201.1Sperry * derived from this software without specific prior written permission. 211.1Sperry * 221.1Sperry * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 231.1Sperry * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 241.1Sperry * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 251.1Sperry * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 261.1Sperry * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 271.1Sperry * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 281.1Sperry * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 291.1Sperry * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 301.1Sperry * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 311.1Sperry * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 321.1Sperry * 331.1Sperry */ 341.1Sperry 351.1Sperry/* read into destination in flat addr space */ 361.1Sperry 371.1Sperry#include <lib/libsa/stand.h> 381.1Sperry 391.1Sperry#include "libi386.h" 401.1Sperry 411.1Sperry#ifdef SAVE_MEMORY 421.1Sperry#define BUFSIZE (1*1024) 431.1Sperry#else 441.1Sperry#define BUFSIZE (4*1024) 451.1Sperry#endif 461.1Sperry 471.1Sperrystatic char buf[BUFSIZE]; 481.1Sperry 491.1Sperryint pread(fd, dest, size) 501.1Sperryint fd; 511.1Sperryphysaddr_t dest; 521.1Sperryint size; 531.1Sperry{ 541.1Sperry int rsize; 551.1Sperry 561.1Sperry rsize = size; 571.1Sperry while(rsize > 0) { 581.1Sperry int count, got; 591.1Sperry 601.1Sperry count = (rsize < BUFSIZE ? rsize : BUFSIZE); 611.1Sperry 621.1Sperry got = read(fd, buf, count); 631.1Sperry if(got < 0) return(-1); 641.1Sperry 651.1Sperry /* put to physical space */ 661.1Sperry vpbcopy(buf, dest, got); 671.1Sperry 681.1Sperry dest += got; 691.1Sperry rsize -= got; 701.1Sperry if(got < count) break; /* EOF */ 711.1Sperry } 721.1Sperry return(size - rsize); 731.1Sperry} 74