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