~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina4/src/tools/fg-servers/dtserver/s_scsi.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /************************************************************
  2 *                                                                                                                       *
  3 *       Copyright (C) 1990 Analogic/CDA                                                 *
  4 *                                                                                                                       *
  5 *       scsi_io.c       low-level block-oriented SCSI i/o functions     *
  6 *                               for SunOS 4.0.0                                                         *
  7 *                                                                                                                       *
  8 *       09Nov89 (V. Michael Oratovsky)                                                  *
  9 *                                                                                                                       *
 10 *************************************************************/
 11 
 12 #include <stdio.h>
 13 #include <errno.h>
 14 #include <fcntl.h>
 15 #include <sys/types.h>
 16 #include <sys/file.h>
 17 #include <sys/buf.h>
 18 #include <sun/dkio.h>
 19 #include <sundev/sereg.h>
 20 #include <sundev/scsi.h>
 21 
 22 #define DASM_BLOCK_SIZE 512
 23 #define MAX_NUM_BLOCKS  0x7F    /* limited by Sun-3E SCSI controller */
 24 
 25 /*      +---------------------------+
 26 *       |       Open raw SCSI device    |
 27 *       +---------------------------+
 28 *
 29 *       Arguments:
 30 *
 31 *       devname -       string containing the name of character-special device
 32 *                               which corresponds to the desired SCSI unit - should
 33 *                               represent the slice of the entire disk device, such
 34 *                               as "/dev/rsd2c".
 35 *
 36 *       Return Value:
 37 *
 38 *       An integer file descriptor is returned on success, -1 otherwise.
 39 *
 40 **********************************************************************/
 41 
 42 int scsi_open( devname )
 43 char *devname ;
 44 {
 45 int fd ;
 46 
 47         if ((fd = open( devname, O_RDWR | O_NDELAY )) == -1)
 48         {
 49                 fprintf(stderr,"scsi_open:  could not open %s - errno %d\n",
 50                                         devname, errno);
 51                 return(-1);
 52         }
 53         else return( fd );
 54 }
 55 
 56 /*      +---------------------------+
 57 *       |       Close raw SCSI device   |
 58 *       +---------------------------+
 59 *
 60 *       Arguments:
 61 *
 62 *       fd - file descriptor returned by scsi_open()
 63 *
 64 *       Return value:
 65 *
 66 *       0 on success, -1 otherwise.
 67 *
 68 ************************************************/
 69 
 70 int scsi_close( fd )
 71 int fd ;
 72 {
 73         if (close(fd) == -1)
 74         {
 75                 fprintf(stderr,"scsi_close:  could not close - errno %d\n",errno);
 76                 return( -1 );
 77         }
 78         else return( 0 );
 79 }
 80 
 81 
 82 /*      +-------------------------------------------------------+
 83 *       |       Read a specified number of blocks from SCSI device      |
 84 *       +-------------------------------------------------------+
 85 *
 86 *       Arguments:
 87 *
 88 *       fd                              file descriptor returned by scsi_open()
 89 *       buf                     address of buffer where to place incoming data
 90 *       starting_block  starting logical SCSI block number
 91 *       num_blocks              number of logical SCSI blocks to read
 92 *
 93 *       Return value:
 94 *
 95 *       0 on success, -1 otherwise.
 96 *
 97 ******************************************************************/
 98 
 99 int scsi_read_blocks( fd, buf, starting_block, num_blocks )
100 int fd ;
101 char *buf ;
102 int starting_block;
103 int num_blocks;
104 {
105 struct dk_cmd scsi_command ;
106 
107         if ((starting_block < 0) || (num_blocks < 1) || (num_blocks > MAX_NUM_BLOCKS))
108         {
109                 fprintf(stderr,"scsi_read_blocks:  bad function arguments\n");
110                 return(-1);
111         }
112 
113         scsi_command.dkc_flags = DK_SILENT | DK_DIAGNOSE | DK_ISOLATE ;
114         scsi_command.dkc_blkno = starting_block ;
115         scsi_command.dkc_secnt = num_blocks ;
116         scsi_command.dkc_bufaddr = buf ;
117         scsi_command.dkc_buflen = num_blocks * DASM_BLOCK_SIZE ;
118         scsi_command.dkc_cmd = SC_READ ;
119 
120         if (ioctl( fd, DKIOCSCMD, & scsi_command ) == -1)
121         {
122                 fprintf(stderr,"scsi_read_blocks:  could not read - errno %d\n", errno);
123                 return( -1 );
124         }
125         else return( 0 );
126 }
127 
128 /*      +-------------------------------------------------------+
129 *       |       Write a specified number of blocks to SCSI device       |
130 *       +-------------------------------------------------------+
131 *
132 *       Arguments:
133 *
134 *       fd                              file descriptor returned by scsi_open()
135 *       buf                     address of buffer of data to write
136 *       starting_block  starting logical SCSI block number
137 *       num_blocks              number of logical SCSI blocks to write
138 *
139 *       Return value:
140 *
141 *       0 on success, -1 otherwise.
142 *
143 ******************************************************************/
144 
145 int scsi_write_blocks( fd, buf, starting_block, num_blocks )
146 int fd ;
147 char *buf ;
148 int starting_block;
149 int num_blocks;
150 {
151 struct dk_cmd scsi_command ;
152 
153         if ((starting_block < 0) || (num_blocks < 1) || (num_blocks > MAX_NUM_BLOCKS))
154         {
155                 fprintf(stderr,"scsi_write_blocks:  bad function arguments\n");
156                 return(-1);
157         }
158 
159         scsi_command.dkc_flags = DK_SILENT | DK_DIAGNOSE | DK_ISOLATE ;
160         scsi_command.dkc_blkno = starting_block ;
161         scsi_command.dkc_secnt = num_blocks ;
162         scsi_command.dkc_bufaddr = buf ;
163         scsi_command.dkc_buflen = num_blocks * DASM_BLOCK_SIZE ;
164         scsi_command.dkc_cmd = SC_WRITE ;
165 
166         if (ioctl( fd, DKIOCSCMD, & scsi_command ) == -1)
167         {
168                 fprintf(stderr,"scsi_write_blocks:  could not write - errno %d\n",
169                                 errno);
170                 return( -1 );
171         }
172         else return( 0 );
173 }
174 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.