home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / FLOPPY2.ZIP / FLOPPY.C next >
Text File  |  1992-02-02  |  3KB  |  99 lines

  1. /*
  2.  *    FLOPPY.C -- Version 0.9 (c) 1992 Emrys Software
  3.  *  Programmed by Wynne Stepp
  4.  *
  5.  *  FLOPPY is designed to be used in batch files to allow the user to proceed
  6.  *  immediately after the diskette has been changed.  It may take one or two
  7.  *  parameters: a required drive letter and an optional volume name.  FLOPPY
  8.  *  will pause until the diskette is changed.  If the volume name was specified
  9.  *  then FLOPPY will continue pausing until the new volume is equal to the one
  10.  *  requested.
  11.  *
  12.  *  It, unfortunately, relies on polling the drive since their is no documented
  13.  *  way to block until the removable medium has been removed.  To prevent this
  14.  *    from seriously affecting system performance, FLOPPY sleeps in the interval
  15.  *  between polls.  I have found that 7 seconds is a reasonable amount of time
  16.  *  to wait from a user's perspective.
  17.  *
  18.  *  A couple fixes from the previous version have been made on recommendation
  19.  *  from members of the FidoNet OS2PROG echo.  First, it is no longer necessary
  20.  *  to include the AUTOFAIL=YES parameter in CONFIG.SYS.  Second, FLOPPY now
  21.  *  checks the volume's serial number to detect whether or not the volume has
  22.  *  changed, so it will now work with different volumes with the same label.
  23.  *
  24.  */
  25.  
  26. #define INCL_DOS
  27. #include <os2.h>
  28. #include <stdio.h>
  29. #include <ctype.h>
  30. #include <string.h>
  31.  
  32. #define WAIT_INTERVAL    7000
  33. #define MAXVOLUME        12
  34.  
  35. void beep (void)
  36.     {
  37.     DosBeep (800, 100) ;
  38.     DosBeep (1200, 100) ;
  39.     DosBeep (1600, 200) ;
  40.     }
  41.     
  42. int QueryVolumeLabel (char chDrive, char *pszVolume, ULONG *pidVolume)
  43.     {
  44.     FSINFO  fsinf ;
  45.     int     iError ;
  46.  
  47.     if (0 == (iError = DosQFSInfo (toupper (chDrive) - 'A' + 1, 2, (PBYTE) &fsinf, sizeof (fsinf))))
  48.         {
  49.         strcpy (pszVolume, fsinf.vol.szVolLabel) ;
  50.         *pidVolume = fsinf.ulVSN ;
  51.         }
  52.  
  53.     return iError ;
  54.     }
  55.  
  56. void WaitUntilVolumeChanged (char chDrive, char *pszVolume)
  57.     {
  58.     char    szVolume [MAXVOLUME] ;
  59.     ULONG   idOldVolume, idVolume ;
  60.  
  61.     DosError (HARDERROR_DISABLE) ;
  62.  
  63.     QueryVolumeLabel (chDrive, szVolume, &idVolume) ;
  64.     idOldVolume = idVolume ;
  65.  
  66.     while ((pszVolume && strcmpi (szVolume, pszVolume)) || (!pszVolume && idOldVolume == idVolume))
  67.         {
  68.         DosSleep (WAIT_INTERVAL) ;
  69.         QueryVolumeLabel (chDrive, szVolume, &idVolume) ;
  70.         }
  71.     }
  72.  
  73. int main (int argc, char *argv[])
  74.     {
  75.     if (argc < 2)
  76.         {
  77.         printf ("FLOPPY 0.9\n") ;
  78.         printf ("Copyright (c) 1992 Emrys Software & Wynne Stepp\n\n") ;
  79.         printf ("Usage:  FLOPPY drv [volume label]\n\n") ;
  80.         printf ("* AUTOFAIL=YES is no longer needed in CONFIG.SYS\n") ;
  81.  
  82.         return 1 ;
  83.         }
  84.  
  85.     printf ("Please insert the %s diskette now.\n", argc > 2 ? argv [2] : "new") ;
  86.     beep () ;
  87.  
  88.     WaitUntilVolumeChanged (*argv [1], argc > 2 ? argv [2] : NULL) ;
  89.     
  90.     return 0 ;
  91.     }
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.