xref: /csrg-svn/sys/stand.att/dev.c (revision 40502)
133510Sbostic /*
233510Sbostic  * Copyright (c) 1982, 1986, 1988 Regents of the University of California.
333510Sbostic  * All rights reserved.
433510Sbostic  *
533510Sbostic  * Redistribution and use in source and binary forms are permitted
634871Sbostic  * provided that the above copyright notice and this paragraph are
734871Sbostic  * duplicated in all such forms and that any documentation,
834871Sbostic  * advertising materials, and other materials related to such
934871Sbostic  * distribution and use acknowledge that the software was developed
1034871Sbostic  * by the University of California, Berkeley.  The name of the
1134871Sbostic  * University may not be used to endorse or promote products derived
1234871Sbostic  * from this software without specific prior written permission.
1334871Sbostic  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
1434871Sbostic  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
1534871Sbostic  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1633510Sbostic  *
17*40502Smckusick  *	@(#)dev.c	7.6 (Berkeley) 03/15/90
1833510Sbostic  */
1933510Sbostic 
2040501Sroot #include "sys/param.h"
2140501Sroot #include "ufs/inode.h"
2240501Sroot #include "ufs/fs.h"
2333510Sbostic #include "saio.h"
2433510Sbostic 
2533670Sbostic /*
26*40502Smckusick  * NB: the value "io->i_dev", used to offset the devsw[] array
2733670Sbostic  * in the routines below, is munged by the vaxstand Makefile to work
2833670Sbostic  * for certain boots.
2933670Sbostic  */
3033670Sbostic 
3133510Sbostic devread(io)
3233510Sbostic 	register struct iob *io;
3333510Sbostic {
3433510Sbostic 	int cc;
3533510Sbostic 
3633510Sbostic 	io->i_flgs |= F_RDDATA;
3733510Sbostic 	io->i_error = 0;
38*40502Smckusick 	cc = (*devsw[io->i_dev].dv_strategy)(io, READ);
3933510Sbostic 	io->i_flgs &= ~F_TYPEMASK;
4033510Sbostic 	return (cc);
4133510Sbostic }
4233510Sbostic 
4333510Sbostic devwrite(io)
4433510Sbostic 	register struct iob *io;
4533510Sbostic {
4633510Sbostic 	int cc;
4733510Sbostic 
4833510Sbostic 	io->i_flgs |= F_WRDATA;
4933510Sbostic 	io->i_error = 0;
50*40502Smckusick 	cc = (*devsw[io->i_dev].dv_strategy)(io, WRITE);
5133510Sbostic 	io->i_flgs &= ~F_TYPEMASK;
5233510Sbostic 	return (cc);
5333510Sbostic }
5433510Sbostic 
5533510Sbostic devopen(io)
5633510Sbostic 	register struct iob *io;
5733510Sbostic {
5833670Sbostic 	int ret;
5933670Sbostic 
60*40502Smckusick 	if (!(ret = (*devsw[io->i_dev].dv_open)(io)))
6133670Sbostic 		return (0);
62*40502Smckusick 	printf("%s(%d,%d,%d,%d): ", devsw[io->i_dev].dv_name,
6333670Sbostic 		io->i_adapt, io->i_ctlr, io->i_unit, io->i_part);
6433670Sbostic 	switch(ret) {
6534517Skarels 	case EIO:
6634517Skarels 		break;		/* already reported */
6733670Sbostic 	case EADAPT:
6834517Skarels 		printf("bad adaptor number\n");
6933670Sbostic 		break;
7033670Sbostic 	case ECTLR:
7134517Skarels 		printf("bad controller number\n");
7233670Sbostic 		break;
7333670Sbostic 	case EUNIT:
7434517Skarels 		printf("bad drive number\n");
7533670Sbostic 		break;
7633670Sbostic 	case EPART:
7733670Sbostic 		printf("bad partition\n");
7833670Sbostic 		break;
7933670Sbostic 	case ERDLAB:
8033670Sbostic 		printf("can't read disk label\n");
8133670Sbostic 		break;
8233670Sbostic 	case EUNLAB:
8333670Sbostic 		printf("unlabeled\n");
8433670Sbostic 		break;
8533670Sbostic 	case ENXIO:
8634517Skarels 		printf("bad device specification\n");
8734517Skarels 		break;
8833670Sbostic 	default:
8934517Skarels 		printf("unknown open error\n");
9034517Skarels 		break;
9133670Sbostic 	}
9233670Sbostic 	return (ret);
9333510Sbostic }
9433510Sbostic 
9533510Sbostic devclose(io)
9633510Sbostic 	register struct iob *io;
9733510Sbostic {
98*40502Smckusick 	(*devsw[io->i_dev].dv_close)(io);
9933510Sbostic }
10033510Sbostic 
10133510Sbostic devioctl(io, cmd, arg)
10233510Sbostic 	register struct iob *io;
10333510Sbostic 	int cmd;
10433510Sbostic 	caddr_t arg;
10533510Sbostic {
106*40502Smckusick 	return ((*devsw[io->i_dev].dv_ioctl)(io, cmd, arg));
10733510Sbostic }
10833510Sbostic 
10933510Sbostic /*ARGSUSED*/
11033510Sbostic nullsys(io)
11133510Sbostic 	struct iob *io;
11233510Sbostic {}
11333510Sbostic 
11433510Sbostic /*ARGSUSED*/
11533510Sbostic nodev(io)
11633510Sbostic 	struct iob *io;
11733510Sbostic {
11833510Sbostic 	errno = EBADF;
11933510Sbostic }
12033510Sbostic 
12133510Sbostic /*ARGSUSED*/
12233510Sbostic noioctl(io, cmd, arg)
12333510Sbostic 	struct iob *io;
12433510Sbostic 	int cmd;
12533510Sbostic 	caddr_t arg;
12633510Sbostic {
12733510Sbostic 	return (ECMD);
12833510Sbostic }
129