home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / SRC / msdos_diskaccess.lzh / MS_DISK_ACCESS / devices.c < prev    next >
Text File  |  1991-07-20  |  2KB  |  88 lines

  1. #ifndef lint
  2. static char RCSid[]="$Header: /auto/n/melon/b/viktor/src/nmt/RCS/devices.c,v 1.3 90/03/16 02:52:20 viktor Exp Locker: viktor $" ;
  3. #endif
  4. /*
  5.  *  Device switch for "mtools",  each driver defines a device name,
  6.  *  an initialization function, and extra "open" flags,  typically to allow
  7.  *  NDELAY for opening floppies with non-default sectoring,  which otherwise
  8.  *  yield EIO
  9.  *
  10.  * $Log:    devices.c,v $
  11.  * Revision 1.3  90/03/16  02:52:20  viktor
  12.  * *** empty log message ***
  13.  * 
  14.  * Revision 1.2  90/03/08  20:29:59  viktor
  15.  * Added unixpc support.
  16.  * 
  17.  */
  18. #include "devices.h"
  19.  
  20. #ifdef sun
  21. #include <fcntl.h>
  22. #endif
  23.  
  24. #ifdef unixpc
  25. #include <sys/gdioctl.h>
  26. #include <fcntl.h>
  27. int unixpc_fd_init() ;
  28. #endif
  29.  
  30. struct device fd_devices[] = {
  31.  
  32. #ifdef sun
  33.   {"/dev/rfd0c", (int (*)())0, 0 },
  34. #endif
  35. #ifdef unixpc
  36.   {"/dev/rfp020", unixpc_fd_init, O_NDELAY},
  37. #endif
  38.   {(char*)0, (int (*)())0, 0}
  39. } ;
  40.  
  41. #ifdef unixpc
  42. unixpc_fd_init(fd,ncyl,ntrack,nsect)
  43.      int fd,ncyl,ntrack,nsect;
  44. {
  45.   struct gdctl gdbuf;
  46.  
  47.   if( ! ncyl && ! nsect && ! ntrack ) {
  48.     ncyl = 40;
  49.     /* Default to 1 track, will reset to 2 later if needed */
  50.     ntrack = 1;
  51.     nsect = 8;
  52.   }
  53.  
  54.   if ( ioctl(fd,GDGETA,&gdbuf) == -1 ) {
  55.     perror("init: ioctl: GDGETA") ;
  56.     dismount(fd) ;
  57.   }
  58.  
  59.   if (ncyl) gdbuf.params.cyls = ncyl;
  60.   if (ntrack) gdbuf.params.heads = ntrack;
  61.   if (nsect) gdbuf.params.psectrk = nsect;
  62.  
  63.   gdbuf.params.pseccyl = gdbuf.params.psectrk * gdbuf.params.heads ;
  64.   gdbuf.params.flags = 1;        /* disk type flag */
  65.   gdbuf.params.step = 0;        /* step rate for controller */
  66.   gdbuf.params.sectorsz = 512;        /* sector size */
  67.  
  68.   if (ioctl(fd, GDSETA, &gdbuf) < 0) {
  69.     perror("init: ioctl: GDSETA");
  70.     dismount(fd);
  71.   }
  72. }
  73.  
  74. /*
  75.  * Dismount the floppy.  Useful only if one of the above ioctls fail
  76.  * and leaves the drive light turned on.
  77.  */
  78. void
  79. dismount(fd)
  80. {
  81.     struct gdctl gdbuf;
  82.     void exit();
  83.  
  84.     ioctl(fd, GDDISMNT, &gdbuf);
  85.     exit(1);
  86. }
  87. #endif
  88.