xref: /csrg-svn/sys/stand.att/dev.c (revision 40501)
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 are permitted
6  * provided that the above copyright notice and this paragraph are
7  * duplicated in all such forms and that any documentation,
8  * advertising materials, and other materials related to such
9  * distribution and use acknowledge that the software was developed
10  * by the University of California, Berkeley.  The name of the
11  * University may not be used to endorse or promote products derived
12  * from this software without specific prior written permission.
13  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16  *
17  *	@(#)dev.c	7.5 (Berkeley) 03/15/90
18  */
19 
20 #include "sys/param.h"
21 #include "sys/time.h"
22 #include "sys/vnode.h"
23 #include "ufs/inode.h"
24 #include "ufs/fs.h"
25 #include "saio.h"
26 
27 /*
28  * NB: the value "io->i_ino.i_dev", used to offset the devsw[] array
29  * in the routines below, is munged by the vaxstand Makefile to work
30  * for certain boots.
31  */
32 
33 devread(io)
34 	register struct iob *io;
35 {
36 	int cc;
37 
38 	io->i_flgs |= F_RDDATA;
39 	io->i_error = 0;
40 	cc = (*devsw[io->i_ino.i_dev].dv_strategy)(io, READ);
41 	io->i_flgs &= ~F_TYPEMASK;
42 	return (cc);
43 }
44 
45 devwrite(io)
46 	register struct iob *io;
47 {
48 	int cc;
49 
50 	io->i_flgs |= F_WRDATA;
51 	io->i_error = 0;
52 	cc = (*devsw[io->i_ino.i_dev].dv_strategy)(io, WRITE);
53 	io->i_flgs &= ~F_TYPEMASK;
54 	return (cc);
55 }
56 
57 devopen(io)
58 	register struct iob *io;
59 {
60 	int ret;
61 
62 	if (!(ret = (*devsw[io->i_ino.i_dev].dv_open)(io)))
63 		return (0);
64 	printf("%s(%d,%d,%d,%d): ", devsw[io->i_ino.i_dev].dv_name,
65 		io->i_adapt, io->i_ctlr, io->i_unit, io->i_part);
66 	switch(ret) {
67 	case EIO:
68 		break;		/* already reported */
69 	case EADAPT:
70 		printf("bad adaptor number\n");
71 		break;
72 	case ECTLR:
73 		printf("bad controller number\n");
74 		break;
75 	case EUNIT:
76 		printf("bad drive number\n");
77 		break;
78 	case EPART:
79 		printf("bad partition\n");
80 		break;
81 	case ERDLAB:
82 		printf("can't read disk label\n");
83 		break;
84 	case EUNLAB:
85 		printf("unlabeled\n");
86 		break;
87 	case ENXIO:
88 		printf("bad device specification\n");
89 		break;
90 	default:
91 		printf("unknown open error\n");
92 		break;
93 	}
94 	return (ret);
95 }
96 
97 devclose(io)
98 	register struct iob *io;
99 {
100 	(*devsw[io->i_ino.i_dev].dv_close)(io);
101 }
102 
103 devioctl(io, cmd, arg)
104 	register struct iob *io;
105 	int cmd;
106 	caddr_t arg;
107 {
108 	return ((*devsw[io->i_ino.i_dev].dv_ioctl)(io, cmd, arg));
109 }
110 
111 /*ARGSUSED*/
112 nullsys(io)
113 	struct iob *io;
114 {}
115 
116 /*ARGSUSED*/
117 nodev(io)
118 	struct iob *io;
119 {
120 	errno = EBADF;
121 }
122 
123 /*ARGSUSED*/
124 noioctl(io, cmd, arg)
125 	struct iob *io;
126 	int cmd;
127 	caddr_t arg;
128 {
129 	return (ECMD);
130 }
131