163282Smckusick /*-
2*63370Sbostic * Copyright (c) 1993
3*63370Sbostic * The Regents of the University of California. All rights reserved.
463282Smckusick *
563282Smckusick * This code is derived from software contributed to Berkeley by
663282Smckusick * The Mach Operating System project at Carnegie-Mellon University.
763282Smckusick *
863282Smckusick * %sccs.include.redist.c%
963282Smckusick *
10*63370Sbostic * @(#)write.c 8.1 (Berkeley) 06/11/93
1163282Smckusick *
1263282Smckusick *
1363282Smckusick * Copyright (c) 1989, 1990, 1991 Carnegie Mellon University
1463282Smckusick * All Rights Reserved.
1563282Smckusick *
1663282Smckusick * Author: Alessandro Forin
1763282Smckusick *
1863282Smckusick * Permission to use, copy, modify and distribute this software and its
1963282Smckusick * documentation is hereby granted, provided that both the copyright
2063282Smckusick * notice and this permission notice appear in all copies of the
2163282Smckusick * software, derivative works or modified versions, and any portions
2263282Smckusick * thereof, and that both notices appear in supporting documentation.
2363282Smckusick *
2463282Smckusick * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
2563282Smckusick * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
2663282Smckusick * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
2763282Smckusick *
2863282Smckusick * Carnegie Mellon requests users of this software to return to
2963282Smckusick *
3063282Smckusick * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
3163282Smckusick * School of Computer Science
3263282Smckusick * Carnegie Mellon University
3363282Smckusick * Pittsburgh PA 15213-3890
3463282Smckusick *
3563282Smckusick * any improvements or extensions that they make and grant Carnegie the
3663282Smckusick * rights to redistribute these changes.
3763282Smckusick */
3863282Smckusick
3963282Smckusick #include <stand/stand.h>
4063282Smckusick
write(fd,dest,bcount)4163282Smckusick write(fd, dest, bcount)
4263282Smckusick int fd;
4363282Smckusick char *dest;
4463282Smckusick u_int bcount;
4563282Smckusick {
4663282Smckusick register struct open_file *f = &files[fd];
4763282Smckusick u_int resid;
4863282Smckusick
4963282Smckusick if ((unsigned)fd >= SOPEN_MAX || !(f->f_flags & F_WRITE)) {
5063282Smckusick errno = EBADF;
5163282Smckusick return (-1);
5263282Smckusick }
5363282Smckusick if (f->f_flags & F_RAW) {
5463282Smckusick errno = (f->f_dev->dv_strategy)(f->f_devdata, F_WRITE,
5563282Smckusick (daddr_t)0, bcount, dest, &resid);
5663282Smckusick if (errno)
5763282Smckusick return (-1);
5863282Smckusick return (resid);
5963282Smckusick }
6063282Smckusick resid = bcount;
6163282Smckusick if (errno = (f->f_ops->write)(f, dest, bcount, &resid))
6263282Smckusick return (-1);
6363282Smckusick return (0);
6463282Smckusick }
65