home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / boot / scsiDiskBoot / devRawBlockDev.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-06-15  |  5.6 KB  |  200 lines

  1. /* 
  2.  * devRawBlockDev.c --
  3.  *
  4.  *    Routines for providing the Raw open/close/read/write/ioctl on 
  5.  *    Block Devices. The routines in this file are called though the
  6.  *     file system device switch table.
  7.  *
  8.  * Copyright 1989 Regents of the University of California
  9.  * Permission to use, copy, modify, and distribute this
  10.  * software and its documentation for any purpose and without
  11.  * fee is hereby granted, provided that the above copyright
  12.  * notice appear in all copies.  The University of California
  13.  * makes no representations about the suitability of this
  14.  * software for any purpose.  It is provided "as is" without
  15.  * express or implied warranty.
  16.  */
  17.  
  18. #ifdef notdef
  19. static char rcsid[] = "$Header: /sprite/src/kernel/dev/RCS/devRawBlockDev.c,v 1.1 89/05/01 15:51:17 mendel Exp Locker: brent $ SPRITE (Berkeley)";
  20. #endif /* not lint */
  21.  
  22. #include "sprite.h"
  23. #include "status.h"
  24. #include "rawBlockDev.h"
  25. #include "devBlockDevice.h"
  26. #include "dev.h"
  27. #include "devInt.h"
  28. #include "user/fs.h"
  29. #include "fs.h"
  30.  
  31.  
  32. /*
  33.  *----------------------------------------------------------------------
  34.  *
  35.  * DevRawBlockDevOpen --
  36.  *
  37.  *    Open a Block Device as a file for reads and writes.  Modify the
  38.  *    Fs_Device structure to point at the attached device's handle.
  39.  *
  40.  * Results:
  41.  *    SUCCESS if the device is successfully attached.
  42.  *
  43.  * Side effects:
  44.  *    None.
  45.  *
  46.  *----------------------------------------------------------------------
  47.  */
  48. /* ARGSUSED */
  49. ReturnStatus
  50. DevRawBlockDevOpen(devicePtr, useFlags, token)
  51.     Fs_Device *devicePtr;    /* Device info, unit number etc. */
  52.     int useFlags;        /* Flags from the stream being opened */
  53.     ClientData token;        /* Call-back token for input, unused here */
  54. {
  55.  
  56.  
  57.     /*
  58.      * See if the device was already open by someone else. NOTE: The 
  59.      * file system passes us the same Fs_Device for each open and initalizes
  60.      * the clientData field to NIL on the first call. 
  61.      */
  62.     /*
  63.      * If the device is not already attach, attach it. This will fail if the 
  64.      * device doesn't exists or is not functioning correctly.
  65.      */
  66.     devicePtr->data = (ClientData) Dev_BlockDeviceAttach(devicePtr);
  67.     if (devicePtr->data == (ClientData) NIL) {
  68.     return(DEV_NO_DEVICE);
  69.     }
  70.     return(SUCCESS);
  71. }
  72.  
  73. /*
  74.  *----------------------------------------------------------------------
  75.  *
  76.  * DevRawBlockDevRead --
  77.  *
  78.  *    Read from a raw Block Device. 
  79.  *
  80.  * Results:
  81.  *    The Sprite return status of the read.
  82.  *
  83.  * Side effects:
  84.  *    None.
  85.  *
  86.  *----------------------------------------------------------------------
  87.  */
  88. ReturnStatus
  89. DevRawBlockDevRead(devicePtr, offset, bufSize, buffer, lenPtr)
  90.     Fs_Device *devicePtr;    /* Handle for raw Block device */
  91.     int offset;            /* Indicates starting point for read.  */
  92.     int bufSize;        /* Number of bytes to read. */
  93.     char *buffer;        /* Buffer for the read */
  94.     int *lenPtr;        /* How many bytes actually read */
  95. {
  96.     ReturnStatus error;
  97.     DevBlockDeviceRequest    request;
  98.     DevBlockDeviceHandle    *handlePtr;
  99.     int                transferLen;
  100.  
  101.     /*
  102.      * Extract the BlockDeviceHandle from the Fs_Device and sent a 
  103.      * BlockDeviceRequest READ request using the synchronous
  104.      * Block IO interface. If the request is too large break it into
  105.      * smaller pieces. Insure the request to a multiple of the min
  106.      * blocksize.
  107.      */
  108.     handlePtr = (DevBlockDeviceHandle *) (devicePtr->data);
  109.     request.operation = FS_READ;
  110.     request.startAddress = offset;
  111.     request.startAddrHigh = 0;
  112.     request.bufferLen = bufSize;
  113.     request.buffer = buffer;
  114.     error = Dev_BlockDeviceIOSync(handlePtr, &request, lenPtr);
  115.     *lenPtr += transferLen;
  116.     return(error);
  117. }
  118.  
  119. /*
  120.  *----------------------------------------------------------------------
  121.  *
  122.  * DevRawBlockDevWrite --
  123.  *
  124.  *    Write to a raw Block Device.
  125.  *
  126.  * Results:
  127.  *    The return status of the IO.
  128.  *
  129.  * Side effects:
  130.  *    None.
  131.  *
  132.  *----------------------------------------------------------------------
  133.  */
  134. ReturnStatus
  135. DevRawBlockDevWrite(devicePtr, offset, bufSize, buffer, lenPtr)
  136.     Fs_Device *devicePtr;    /* Handle of raw disk device */
  137.     int offset;            /* Indicates the starting point of the write.
  138.                  */
  139.     int bufSize;        /* Number of bytes to write.  */
  140.     char *buffer;        /* Write buffer */
  141.     int *lenPtr;        /* How much was actually written */
  142. {
  143. }
  144.  
  145. /*
  146.  *----------------------------------------------------------------------
  147.  *
  148.  * DevRawBlockDevIOControl --
  149.  *
  150.  *    Do a special operation on a raw Block Device.
  151.  *
  152.  * Results:
  153.  *    Return status of the IOControl.
  154.  *
  155.  * Side effects:
  156.  *    None.
  157.  *
  158.  *----------------------------------------------------------------------
  159.  */
  160.  
  161. /*ARGSUSED*/
  162. ReturnStatus
  163. DevRawBlockDevIOControl(devicePtr, command, inBufSize, inBuffer,
  164.                  outBufSize, outBuffer)
  165.     Fs_Device *devicePtr;    /* Device pointer to operate of. */
  166.     int command;        /* IO Control to be performed. */
  167.     int inBufSize;        /* Size of inBuffer in bytes. */
  168.     char *inBuffer;        /* Input data to command. */
  169.     int outBufSize;        /* Size of inBuffer in bytes. */
  170.     char *outBuffer;        /* Output data from command. */
  171. {
  172. }
  173.  
  174. /*
  175.  *----------------------------------------------------------------------
  176.  *
  177.  * DevRawBlockDevClose --
  178.  *
  179.  *    Close a raw Block Device file. If this is last open of the device
  180.  *    to be close then detach the device.
  181.  *
  182.  * Results:
  183.  *    The return status of the close operation.
  184.  *
  185.  * Side effects:
  186.  *    Block device may be detached.
  187.  *
  188.  *----------------------------------------------------------------------
  189.  */
  190. /*ARGSUSED*/
  191. ReturnStatus
  192. DevRawBlockDevClose(devicePtr, useFlags, openCount, writerCount)
  193.     Fs_Device    *devicePtr;    /* Device to close. */
  194.     int     useFlags;    /* File system useFlags. */
  195.     int        openCount;    /* Count of reference to device. */
  196.     int        writerCount;    /* Count of open writers. */
  197. {
  198. }
  199.  
  200.