xref: /csrg-svn/sys/stand/read.c (revision 63370)
163277Smckusick /*-
2*63370Sbostic  * Copyright (c) 1993
3*63370Sbostic  *	The Regents of the University of California.  All rights reserved.
463277Smckusick  *
563277Smckusick  * This code is derived from software contributed to Berkeley by
663277Smckusick  * The Mach Operating System project at Carnegie-Mellon University.
763277Smckusick  *
863277Smckusick  * %sccs.include.redist.c%
963277Smckusick  *
10*63370Sbostic  *	@(#)read.c	8.1 (Berkeley) 06/11/93
1163277Smckusick  *
1263277Smckusick  *
1363277Smckusick  * Copyright (c) 1989, 1990, 1991 Carnegie Mellon University
1463277Smckusick  * All Rights Reserved.
1563277Smckusick  *
1663277Smckusick  * Author: Alessandro Forin
1763277Smckusick  *
1863277Smckusick  * Permission to use, copy, modify and distribute this software and its
1963277Smckusick  * documentation is hereby granted, provided that both the copyright
2063277Smckusick  * notice and this permission notice appear in all copies of the
2163277Smckusick  * software, derivative works or modified versions, and any portions
2263277Smckusick  * thereof, and that both notices appear in supporting documentation.
2363277Smckusick  *
2463277Smckusick  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
2563277Smckusick  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
2663277Smckusick  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
2763277Smckusick  *
2863277Smckusick  * Carnegie Mellon requests users of this software to return to
2963277Smckusick  *
3063277Smckusick  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
3163277Smckusick  *  School of Computer Science
3263277Smckusick  *  Carnegie Mellon University
3363277Smckusick  *  Pittsburgh PA 15213-3890
3463277Smckusick  *
3563277Smckusick  * any improvements or extensions that they make and grant Carnegie the
3663277Smckusick  * rights to redistribute these changes.
3763277Smckusick  */
3863277Smckusick 
3963277Smckusick #include <stand/stand.h>
4063277Smckusick 
read(fd,dest,bcount)4163277Smckusick read(fd, dest, bcount)
4263277Smckusick 	int fd;
4363277Smckusick 	char *dest;
4463277Smckusick 	u_int bcount;
4563277Smckusick {
4663277Smckusick 	register struct open_file *f = &files[fd];
4763277Smckusick 	u_int resid;
4863277Smckusick 
4963277Smckusick 	if ((unsigned)fd >= SOPEN_MAX || !(f->f_flags & F_READ)) {
5063277Smckusick 		errno = EBADF;
5163277Smckusick 		return (-1);
5263277Smckusick 	}
5363277Smckusick 	if (f->f_flags & F_RAW) {
5463277Smckusick 		errno = (f->f_dev->dv_strategy)(f->f_devdata, F_READ,
5563277Smckusick 			(daddr_t)0, bcount, dest, &resid);
5663277Smckusick 		if (errno)
5763277Smckusick 			return (-1);
5863277Smckusick 		return (resid);
5963277Smckusick 	}
6063277Smckusick 	resid = bcount;
6163277Smckusick 	if (errno = (f->f_ops->read)(f, dest, bcount, &resid))
6263277Smckusick 		return (-1);
6363277Smckusick 	return (bcount - resid);
6463277Smckusick }
65