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*40501Sroot * @(#)dev.c 7.5 (Berkeley) 03/15/90 1833510Sbostic */ 1933510Sbostic 20*40501Sroot #include "sys/param.h" 21*40501Sroot #include "sys/time.h" 22*40501Sroot #include "sys/vnode.h" 23*40501Sroot #include "ufs/inode.h" 24*40501Sroot #include "ufs/fs.h" 2533510Sbostic #include "saio.h" 2633510Sbostic 2733670Sbostic /* 2833670Sbostic * NB: the value "io->i_ino.i_dev", used to offset the devsw[] array 2933670Sbostic * in the routines below, is munged by the vaxstand Makefile to work 3033670Sbostic * for certain boots. 3133670Sbostic */ 3233670Sbostic 3333510Sbostic devread(io) 3433510Sbostic register struct iob *io; 3533510Sbostic { 3633510Sbostic int cc; 3733510Sbostic 3833510Sbostic io->i_flgs |= F_RDDATA; 3933510Sbostic io->i_error = 0; 4033510Sbostic cc = (*devsw[io->i_ino.i_dev].dv_strategy)(io, READ); 4133510Sbostic io->i_flgs &= ~F_TYPEMASK; 4233510Sbostic return (cc); 4333510Sbostic } 4433510Sbostic 4533510Sbostic devwrite(io) 4633510Sbostic register struct iob *io; 4733510Sbostic { 4833510Sbostic int cc; 4933510Sbostic 5033510Sbostic io->i_flgs |= F_WRDATA; 5133510Sbostic io->i_error = 0; 5233510Sbostic cc = (*devsw[io->i_ino.i_dev].dv_strategy)(io, WRITE); 5333510Sbostic io->i_flgs &= ~F_TYPEMASK; 5433510Sbostic return (cc); 5533510Sbostic } 5633510Sbostic 5733510Sbostic devopen(io) 5833510Sbostic register struct iob *io; 5933510Sbostic { 6033670Sbostic int ret; 6133670Sbostic 6233670Sbostic if (!(ret = (*devsw[io->i_ino.i_dev].dv_open)(io))) 6333670Sbostic return (0); 6433670Sbostic printf("%s(%d,%d,%d,%d): ", devsw[io->i_ino.i_dev].dv_name, 6533670Sbostic io->i_adapt, io->i_ctlr, io->i_unit, io->i_part); 6633670Sbostic switch(ret) { 6734517Skarels case EIO: 6834517Skarels break; /* already reported */ 6933670Sbostic case EADAPT: 7034517Skarels printf("bad adaptor number\n"); 7133670Sbostic break; 7233670Sbostic case ECTLR: 7334517Skarels printf("bad controller number\n"); 7433670Sbostic break; 7533670Sbostic case EUNIT: 7634517Skarels printf("bad drive number\n"); 7733670Sbostic break; 7833670Sbostic case EPART: 7933670Sbostic printf("bad partition\n"); 8033670Sbostic break; 8133670Sbostic case ERDLAB: 8233670Sbostic printf("can't read disk label\n"); 8333670Sbostic break; 8433670Sbostic case EUNLAB: 8533670Sbostic printf("unlabeled\n"); 8633670Sbostic break; 8733670Sbostic case ENXIO: 8834517Skarels printf("bad device specification\n"); 8934517Skarels break; 9033670Sbostic default: 9134517Skarels printf("unknown open error\n"); 9234517Skarels break; 9333670Sbostic } 9433670Sbostic return (ret); 9533510Sbostic } 9633510Sbostic 9733510Sbostic devclose(io) 9833510Sbostic register struct iob *io; 9933510Sbostic { 10033510Sbostic (*devsw[io->i_ino.i_dev].dv_close)(io); 10133510Sbostic } 10233510Sbostic 10333510Sbostic devioctl(io, cmd, arg) 10433510Sbostic register struct iob *io; 10533510Sbostic int cmd; 10633510Sbostic caddr_t arg; 10733510Sbostic { 10833510Sbostic return ((*devsw[io->i_ino.i_dev].dv_ioctl)(io, cmd, arg)); 10933510Sbostic } 11033510Sbostic 11133510Sbostic /*ARGSUSED*/ 11233510Sbostic nullsys(io) 11333510Sbostic struct iob *io; 11433510Sbostic {} 11533510Sbostic 11633510Sbostic /*ARGSUSED*/ 11733510Sbostic nodev(io) 11833510Sbostic struct iob *io; 11933510Sbostic { 12033510Sbostic errno = EBADF; 12133510Sbostic } 12233510Sbostic 12333510Sbostic /*ARGSUSED*/ 12433510Sbostic noioctl(io, cmd, arg) 12533510Sbostic struct iob *io; 12633510Sbostic int cmd; 12733510Sbostic caddr_t arg; 12833510Sbostic { 12933510Sbostic return (ECMD); 13033510Sbostic } 131