xref: /csrg-svn/sys/stand.att/dev.c (revision 49084)
1 /*
2  * Copyright (c) 1982, 1986, 1988 Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  *	@(#)dev.c	7.11 (Berkeley) 05/04/91
8  */
9 
10 #include "sys/param.h"
11 #include "stand/saio.h"			/* used from machine/stand dir */
12 #include <setjmp.h>
13 
14 /*
15  * NB: the value "io->i_dev", used to offset the devsw[] array in the
16  * routines below, is munged by the machine specific stand Makefiles
17  * to work for certain boots.
18  */
19 
20 jmp_buf exception;
21 
22 devread(io)
23 	register struct iob *io;
24 {
25 	int cc;
26 
27 	io->i_flgs |= F_RDDATA;
28 	io->i_error = 0;
29 	cc = (*devsw[io->i_dev].dv_strategy)(io, F_READ);
30 	io->i_flgs &= ~F_TYPEMASK;
31 	if (scankbd())
32 		_longjmp(&exception, 1);
33 	return (cc);
34 }
35 
36 devwrite(io)
37 	register struct iob *io;
38 {
39 	int cc;
40 
41 	io->i_flgs |= F_WRDATA;
42 	io->i_error = 0;
43 	cc = (*devsw[io->i_dev].dv_strategy)(io, F_WRITE);
44 	io->i_flgs &= ~F_TYPEMASK;
45 	if (scankbd())
46 		_longjmp(&exception, 1);
47 	return (cc);
48 }
49 
50 devopen(io)
51 	register struct iob *io;
52 {
53 	int ret;
54 
55 	if (!(ret = (*devsw[io->i_dev].dv_open)(io)))
56 		return (0);
57 	printf("%s(%d,%d,%d,%d): ", devsw[io->i_dev].dv_name,
58 		io->i_adapt, io->i_ctlr, io->i_unit, io->i_part);
59 	switch(ret) {
60 	case EIO:
61 		break;		/* already reported */
62 	case EADAPT:
63 		printf("bad adaptor number\n");
64 		break;
65 	case ECTLR:
66 		printf("bad controller number\n");
67 		break;
68 	case EUNIT:
69 		printf("bad drive number\n");
70 		break;
71 	case EPART:
72 		printf("bad partition\n");
73 		break;
74 	case ERDLAB:
75 		printf("can't read disk label\n");
76 		break;
77 	case EUNLAB:
78 		printf("unlabeled\n");
79 		break;
80 	case ENXIO:
81 		printf("bad device specification\n");
82 		break;
83 	default:
84 		printf("unknown open error\n");
85 		break;
86 	}
87 	return (ret);
88 }
89 
90 devclose(io)
91 	register struct iob *io;
92 {
93 	(*devsw[io->i_dev].dv_close)(io);
94 }
95 
96 devioctl(io, cmd, arg)
97 	register struct iob *io;
98 	int cmd;
99 	caddr_t arg;
100 {
101 	return ((*devsw[io->i_dev].dv_ioctl)(io, cmd, arg));
102 }
103 
104 /* ARGSUSED */
105 nullsys(io)
106 	struct iob *io;
107 {}
108 
109 /* ARGSUSED */
110 nodev(io)
111 	struct iob *io;
112 {
113 	errno = EBADF;
114 }
115 
116 /* ARGSUSED */
117 noioctl(io, cmd, arg)
118 	struct iob *io;
119 	int cmd;
120 	caddr_t arg;
121 {
122 	return (ECMD);
123 }
124