xref: /original-bsd/sys/stand.att/dev.c (revision 57530171)
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.2 (Berkeley) 03/04/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 EADAPT:
61 		printf("bad adaptor\n");
62 		break;
63 	case ECTLR:
64 		printf("bad controller\n");
65 		break;
66 	case EUNIT:
67 		printf("bad drive\n");
68 		break;
69 	case EPART:
70 		printf("bad partition\n");
71 		break;
72 	case ERDLAB:
73 		printf("can't read disk label\n");
74 		break;
75 	case EUNLAB:
76 		printf("unlabeled\n");
77 		break;
78 	case ENXIO:
79 	default:
80 		printf("bad device specification\n");
81 	}
82 	return (ret);
83 }
84 
85 devclose(io)
86 	register struct iob *io;
87 {
88 	(*devsw[io->i_ino.i_dev].dv_close)(io);
89 }
90 
91 devioctl(io, cmd, arg)
92 	register struct iob *io;
93 	int cmd;
94 	caddr_t arg;
95 {
96 	return ((*devsw[io->i_ino.i_dev].dv_ioctl)(io, cmd, arg));
97 }
98 
99 /*ARGSUSED*/
100 nullsys(io)
101 	struct iob *io;
102 {}
103 
104 /*ARGSUSED*/
105 nodev(io)
106 	struct iob *io;
107 {
108 	errno = EBADF;
109 }
110 
111 /*ARGSUSED*/
112 noioctl(io, cmd, arg)
113 	struct iob *io;
114 	int cmd;
115 	caddr_t arg;
116 {
117 	return (ECMD);
118 }
119