xref: /csrg-svn/sys/stand.att/dev.c (revision 34517)
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 this notice is preserved and that due credit is given
7  * to the University of California at Berkeley. The name of the University
8  * may not be used to endorse or promote products derived from this
9  * software without specific prior written permission. This software
10  * is provided ``as is'' without express or implied warranty.
11  *
12  *	@(#)dev.c	7.3 (Berkeley) 05/27/88
13  */
14 
15 #include "param.h"
16 #include "inode.h"
17 #include "fs.h"
18 #include "saio.h"
19 
20 /*
21  * NB: the value "io->i_ino.i_dev", used to offset the devsw[] array
22  * in the routines below, is munged by the vaxstand Makefile to work
23  * for certain boots.
24  */
25 
26 devread(io)
27 	register struct iob *io;
28 {
29 	int cc;
30 
31 	io->i_flgs |= F_RDDATA;
32 	io->i_error = 0;
33 	cc = (*devsw[io->i_ino.i_dev].dv_strategy)(io, READ);
34 	io->i_flgs &= ~F_TYPEMASK;
35 	return (cc);
36 }
37 
38 devwrite(io)
39 	register struct iob *io;
40 {
41 	int cc;
42 
43 	io->i_flgs |= F_WRDATA;
44 	io->i_error = 0;
45 	cc = (*devsw[io->i_ino.i_dev].dv_strategy)(io, WRITE);
46 	io->i_flgs &= ~F_TYPEMASK;
47 	return (cc);
48 }
49 
50 devopen(io)
51 	register struct iob *io;
52 {
53 	int ret;
54 
55 	if (!(ret = (*devsw[io->i_ino.i_dev].dv_open)(io)))
56 		return (0);
57 	printf("%s(%d,%d,%d,%d): ", devsw[io->i_ino.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_ino.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_ino.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