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