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