This commit was manufactured by cvs2svn to create tag 'FreeBSD-release/1.0'.
[unix-history] / sys / stand / dev.c
CommitLineData
15637ed4
RG
1/*
2 * Copyright (c) 1982, 1986, 1988 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
78ed81a3 33 * from: @(#)dev.c 7.14 (Berkeley) 5/5/91
34 * $Id$
15637ed4
RG
35 */
36
37#include <sys/param.h>
38#include <setjmp.h>
39#include "saio.h"
40
41/*
42 * NB: the value "io->i_dev", used to offset the devsw[] array in the
43 * routines below, is munged by the machine specific stand Makefiles
44 * to work for certain boots.
45 */
46
47jmp_buf exception;
48
49devread(io)
50 register struct iob *io;
51{
52 int cc;
53
54 io->i_flgs |= F_RDDATA;
55 io->i_error = 0;
56 cc = (*devsw[io->i_dev].dv_strategy)(io, F_READ);
57 io->i_flgs &= ~F_TYPEMASK;
58#ifndef SMALL
59 if (scankbd())
60 _longjmp(exception, 1);
61#endif
62 return (cc);
63}
64
65devwrite(io)
66 register struct iob *io;
67{
68 int cc;
69
70 io->i_flgs |= F_WRDATA;
71 io->i_error = 0;
72 cc = (*devsw[io->i_dev].dv_strategy)(io, F_WRITE);
73 io->i_flgs &= ~F_TYPEMASK;
74#ifndef SMALL
75 if (scankbd())
76 _longjmp(exception, 1);
77#endif
78 return (cc);
79}
80
81devopen(io)
82 register struct iob *io;
83{
84 int ret;
85
86 if (!(ret = (*devsw[io->i_dev].dv_open)(io)))
87 return (0);
88#ifdef SMALL
89 printf("open error\n");
90#else
91 printf("%s(%d,%d,%d,%d): ", devsw[io->i_dev].dv_name,
92 io->i_adapt, io->i_ctlr, io->i_unit, io->i_part);
93 switch(ret) {
94 case EIO:
95 break; /* already reported */
96 case EADAPT:
97 printf("bad adaptor number\n");
98 break;
99 case ECTLR:
100 printf("bad controller number\n");
101 break;
102 case EUNIT:
103 printf("bad drive number\n");
104 break;
105 case EPART:
106 printf("bad partition\n");
107 break;
108 case ERDLAB:
109 printf("can't read disk label\n");
110 break;
111 case EUNLAB:
112 printf("unlabeled\n");
113 break;
114 case ENXIO:
115 printf("bad device specification\n");
116 break;
117 default:
118 printf("unknown open error\n");
119 break;
120 }
121#endif
122 return (ret);
123}
124
125devclose(io)
126 register struct iob *io;
127{
128 (*devsw[io->i_dev].dv_close)(io);
129}
130
131devioctl(io, cmd, arg)
132 register struct iob *io;
133 int cmd;
134 caddr_t arg;
135{
136 return ((*devsw[io->i_dev].dv_ioctl)(io, cmd, arg));
137}
138
139/* ARGSUSED */
140nullsys(io)
141 struct iob *io;
142{}
143
144/* ARGSUSED */
145nodev(io)
146 struct iob *io;
147{
148 errno = EBADF;
149 return(-1);
150}
151
152/* ARGSUSED */
153noioctl(io, cmd, arg)
154 struct iob *io;
155 int cmd;
156 caddr_t arg;
157{
158 return (ECMD);
159}