home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c070 / 4.ddi / TOOLS.4 / TCTSRC1.EXE / FLRETVOL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-31  |  3.2 KB  |  121 lines

  1. /**
  2. *
  3. * Name        FLRETVOL -- Return the volume label on a given
  4. *                disk drive.
  5. *
  6. * Synopsis    ercode = flretvol (drive, pvol, pfdate, pftime);
  7. *
  8. *        int  ercode      1 if error or no label, 0 if okay.
  9. *        int  drive      Disk drive (0 = default, 1 = A:, etc.)
  10. *        char *pvol      Pointer to character buffer in which
  11. *                  to put volume name (if found).  This
  12. *                  must allow space for 11 bytes plus the
  13. *                  trailing NUL ('\0').
  14. *        unsigned *pfdate  Pointer to returned date stamp
  15. *        unsigned *pftime  Pointer to returned time stamp
  16. *
  17. * Description    This function returns the volume label (if any) on a
  18. *        given disk drive as well as the label's creation date
  19. *        and time.  The volume label (if found) is always
  20. *        returned as an 11-character string.  It may contain
  21. *        blanks or other characters which are ordinarily illegal
  22. *        in DOS filenames.
  23. *
  24. *        The date and time are represented as 16-bit quantities
  25. *        in the following format:
  26. *
  27. *              **********   bits   ***********
  28. *              1 1 1 1 1 1
  29. *              5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
  30. *
  31. *              y y y y y y y m m m m d d d d d    = *pfdate
  32. *
  33. *              h h h h h m m m m m m s s s s s    = *pftime
  34. *
  35. *        where the year bits represent 0 - 119 (1980 to 2099) and
  36. *        the second bits represent two-second increments.  This
  37. *        is the same format used by the DOS disk directory.
  38. *
  39. * Returns    ercode          1 if error or no label, 0 if okay.
  40. *        *pvol          Volume name.
  41. *        *pfdate       Returned date stamp
  42. *        *pftime       Returned time stamp
  43. *
  44. * Version    6.00 (C)Copyright Blaise Computing Inc. 1986, 1987, 1989
  45. *
  46. **/
  47.  
  48. #include <dos.h>
  49.  
  50. #include <bfiles.h>
  51.  
  52. #define fcb        (xfcb      + 7)
  53. #define found_fcb   (local_dta + 7)
  54.  
  55. int flretvol (drive, pvol, pfdate, pftime)
  56. int      drive;
  57. char     *pvol;
  58. unsigned *pfdate, *pftime;
  59. {
  60.     union  REGS    regs;
  61.     struct SREGS   sregs;
  62.     unsigned char  local_dta[44], xfcb[44];
  63.     register int   i;
  64.     int        result;
  65.     void far      *pold_dta;
  66.  
  67.         /* Save former Data Transfer Address.            */
  68.     pold_dta = flgetdta ();
  69.         /* Select local DTA.                    */
  70.     flputdta ((void far *) local_dta);
  71.  
  72.         /* Clear entire Extended FCB                */
  73.     for (i = 0; i < 44; i++)
  74.     xfcb[i] = 0;
  75.  
  76.         /* Mark this as an Extended FCB             */
  77.     fcb[-7] = 0xff;
  78.         /* Select volume attribute.                */
  79.     fcb[-1] = AT_VOLUME;
  80.     fcb[0]  = (char) drive;
  81.  
  82.         /* Search for "????????.???"                        */
  83.     for (i = 1;  i <= 11;  i++)
  84.     fcb[i] = '?';
  85.  
  86.         /* Set up for DOS function 0x11:  search for first  */
  87.         /* matching entry.                    */
  88.     regs.x.ax = 0x1100;
  89.     sregs.ds  = utseg (xfcb);
  90.     regs.x.dx = utoff (xfcb);
  91.  
  92.         /* Go do the search.                    */
  93.     int86x (FL_DOS_INT, ®s,®s,&sregs);
  94.  
  95.     if (regs.h.al == 0)
  96.     {        /* Found a volume label -- copy name to *pvol.        */
  97.     for (i = 1;  i <= 11;  i++)
  98.         *pvol++ = found_fcb[i];
  99.     *pvol    = '\0';
  100.  
  101.         /* Copy time and date stamps.                */
  102.     *pftime = *((unsigned *) &(found_fcb[23]));
  103.     *pfdate = *((unsigned *) &(found_fcb[25]));
  104.  
  105.     result    = 0;
  106.     }
  107.  
  108.     else
  109.     {        /* No volume label found.                */
  110.     *pvol    = '\0';
  111.     *pfdate = 0;
  112.     *pftime = 0;
  113.     result    = 1;
  114.     }
  115.  
  116.         /* Restore former DTA.                    */
  117.     flputdta (pold_dta);
  118.  
  119.     return (result);
  120. }
  121.