home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / sys / stand / dev.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-05  |  3.8 KB  |  159 lines

  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, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice, this list of conditions and the following disclaimer in the
  12.  *    documentation and/or other materials provided with the distribution.
  13.  * 3. All advertising materials mentioning features or use of this software
  14.  *    must display the following acknowledgement:
  15.  *    This product includes software developed by the University of
  16.  *    California, Berkeley and its contributors.
  17.  * 4. Neither the name of the University nor the names of its contributors
  18.  *    may be used to endorse or promote products derived from this software
  19.  *    without specific prior written permission.
  20.  *
  21.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  22.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31.  * SUCH DAMAGE.
  32.  *
  33.  *    @(#)dev.c    7.14 (Berkeley) 5/5/91
  34.  */
  35.  
  36. #include <sys/param.h>
  37. #include <setjmp.h>
  38. #include "saio.h"
  39.  
  40. /*
  41.  * NB: the value "io->i_dev", used to offset the devsw[] array in the
  42.  * routines below, is munged by the machine specific stand Makefiles
  43.  * to work for certain boots.
  44.  */
  45.  
  46. jmp_buf exception;
  47.  
  48. devread(io)
  49.     register struct iob *io;
  50. {
  51.     int cc;
  52.  
  53.     io->i_flgs |= F_RDDATA;
  54.     io->i_error = 0;
  55.     cc = (*devsw[io->i_dev].dv_strategy)(io, F_READ);
  56.     io->i_flgs &= ~F_TYPEMASK;
  57. #ifndef SMALL
  58.     if (scankbd())
  59.         _longjmp(exception, 1);
  60. #endif
  61.     return (cc);
  62. }
  63.  
  64. devwrite(io)
  65.     register struct iob *io;
  66. {
  67.     int cc;
  68.  
  69.     io->i_flgs |= F_WRDATA;
  70.     io->i_error = 0;
  71.     cc = (*devsw[io->i_dev].dv_strategy)(io, F_WRITE);
  72.     io->i_flgs &= ~F_TYPEMASK;
  73. #ifndef SMALL
  74.     if (scankbd())
  75.         _longjmp(exception, 1);
  76. #endif
  77.     return (cc);
  78. }
  79.  
  80. devopen(io)
  81.     register struct iob *io;
  82. {
  83.     int ret;
  84.  
  85.     if (!(ret = (*devsw[io->i_dev].dv_open)(io)))
  86.         return (0);
  87. #ifdef SMALL
  88.     printf("open error\n");
  89. #else
  90.     printf("%s(%d,%d,%d,%d): ", devsw[io->i_dev].dv_name,
  91.         io->i_adapt, io->i_ctlr, io->i_unit, io->i_part);
  92.     switch(ret) {
  93.     case EIO:
  94.         break;        /* already reported */
  95.     case EADAPT:
  96.         printf("bad adaptor number\n");
  97.         break;
  98.     case ECTLR:
  99.         printf("bad controller number\n");
  100.         break;
  101.     case EUNIT:
  102.         printf("bad drive number\n");
  103.         break;
  104.     case EPART:
  105.         printf("bad partition\n");
  106.         break;
  107.     case ERDLAB:
  108.         printf("can't read disk label\n");
  109.         break;
  110.     case EUNLAB:
  111.         printf("unlabeled\n");
  112.         break;
  113.     case ENXIO:
  114.         printf("bad device specification\n");
  115.         break;
  116.     default:
  117.         printf("unknown open error\n");
  118.         break;
  119.     }
  120. #endif
  121.     return (ret);
  122. }
  123.  
  124. devclose(io)
  125.     register struct iob *io;
  126. {
  127.     (*devsw[io->i_dev].dv_close)(io);
  128. }
  129.  
  130. devioctl(io, cmd, arg)
  131.     register struct iob *io;
  132.     int cmd;
  133.     caddr_t arg;
  134. {
  135.     return ((*devsw[io->i_dev].dv_ioctl)(io, cmd, arg));
  136. }
  137.  
  138. /* ARGSUSED */
  139. nullsys(io)
  140.     struct iob *io;
  141. {}
  142.  
  143. /* ARGSUSED */
  144. nodev(io)
  145.     struct iob *io;
  146. {
  147.     errno = EBADF;
  148.     return(-1);
  149. }
  150.  
  151. /* ARGSUSED */
  152. noioctl(io, cmd, arg)
  153.     struct iob *io;
  154.     int cmd;
  155.     caddr_t arg;
  156. {
  157.     return (ECMD);
  158. }
  159.