1*63277Smckusick /*- 2*63277Smckusick * Copyright (c) 1993 The Regents of the University of California. 3*63277Smckusick * All rights reserved. 4*63277Smckusick * 5*63277Smckusick * This code is derived from software contributed to Berkeley by 6*63277Smckusick * The Mach Operating System project at Carnegie-Mellon University. 7*63277Smckusick * 8*63277Smckusick * %sccs.include.redist.c% 9*63277Smckusick * 10*63277Smckusick * @(#)read.c 7.1 (Berkeley) 06/11/93 11*63277Smckusick * 12*63277Smckusick * 13*63277Smckusick * Copyright (c) 1989, 1990, 1991 Carnegie Mellon University 14*63277Smckusick * All Rights Reserved. 15*63277Smckusick * 16*63277Smckusick * Author: Alessandro Forin 17*63277Smckusick * 18*63277Smckusick * Permission to use, copy, modify and distribute this software and its 19*63277Smckusick * documentation is hereby granted, provided that both the copyright 20*63277Smckusick * notice and this permission notice appear in all copies of the 21*63277Smckusick * software, derivative works or modified versions, and any portions 22*63277Smckusick * thereof, and that both notices appear in supporting documentation. 23*63277Smckusick * 24*63277Smckusick * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 25*63277Smckusick * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 26*63277Smckusick * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 27*63277Smckusick * 28*63277Smckusick * Carnegie Mellon requests users of this software to return to 29*63277Smckusick * 30*63277Smckusick * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 31*63277Smckusick * School of Computer Science 32*63277Smckusick * Carnegie Mellon University 33*63277Smckusick * Pittsburgh PA 15213-3890 34*63277Smckusick * 35*63277Smckusick * any improvements or extensions that they make and grant Carnegie the 36*63277Smckusick * rights to redistribute these changes. 37*63277Smckusick */ 38*63277Smckusick 39*63277Smckusick #include <stand/stand.h> 40*63277Smckusick 41*63277Smckusick read(fd, dest, bcount) 42*63277Smckusick int fd; 43*63277Smckusick char *dest; 44*63277Smckusick u_int bcount; 45*63277Smckusick { 46*63277Smckusick register struct open_file *f = &files[fd]; 47*63277Smckusick u_int resid; 48*63277Smckusick 49*63277Smckusick if ((unsigned)fd >= SOPEN_MAX || !(f->f_flags & F_READ)) { 50*63277Smckusick errno = EBADF; 51*63277Smckusick return (-1); 52*63277Smckusick } 53*63277Smckusick if (f->f_flags & F_RAW) { 54*63277Smckusick errno = (f->f_dev->dv_strategy)(f->f_devdata, F_READ, 55*63277Smckusick (daddr_t)0, bcount, dest, &resid); 56*63277Smckusick if (errno) 57*63277Smckusick return (-1); 58*63277Smckusick return (resid); 59*63277Smckusick } 60*63277Smckusick resid = bcount; 61*63277Smckusick if (errno = (f->f_ops->read)(f, dest, bcount, &resid)) 62*63277Smckusick return (-1); 63*63277Smckusick return (bcount - resid); 64*63277Smckusick } 65