home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c005 / 4.ddi / C / DRRETVOL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1987-04-13  |  3.3 KB  |  114 lines

  1. /**
  2. *
  3. * Name        drretvol -- Return the volume label on a given
  4. *                disk drive.
  5. *
  6. * Synopsis    ercode = drretvol(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    = fdate
  32. *
  33. *              h h h h h m m m m m m s s s s s    = ftime
  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 DRRETSTP, DRSETSTP, DRSFIRST,
  38. *        and DRSNEXT.
  39. *
  40. *        Use DRSTP2DT and DRSTP2TM to split the time and date
  41. *        stamps into year, month, day, etc.
  42. *
  43. * Returns    ercode          1 if error or no label, 0 if okay.
  44. *        *pvol          Volume name.
  45. *        *pfdate       Returned date stamp
  46. *        *pftime       Returned time stamp
  47. *
  48. * Version    3.0 (C)Copyright Blaise Computing Inc.    1986
  49. *
  50. * Version    3.02 March 24, 1987
  51. *        Removed a strong typing warning (no change in object
  52. *            code).
  53. *
  54. **/
  55.  
  56. #include <bdirect.h>
  57. #include <bfile.h>
  58.  
  59. int drretvol(drive,pvol,pfdate,pftime)
  60. int     drive;
  61. char     *pvol;
  62. unsigned *pfdate,*pftime;
  63. {
  64.     DOSREG     dos_reg;
  65.     char     local_dta[39];
  66.     ADS      old_dta_ads,ldta_ads,xfcb_ads;
  67.     char     xfcb[44];
  68.     register int i;
  69.     int      result;
  70.  
  71. #define fcb        (xfcb      + 7)
  72. #define found_fcb   (local_dta + 7)
  73.  
  74.     flretdta(&old_dta_ads);          /* Save former Data Transfer    */
  75.                       /* Address.              */
  76.     utabsptr(local_dta,&ldta_ads);
  77.     flsetdta(&ldta_ads);          /* Select local DTA.          */
  78.  
  79.     for (i = 0; i < 44; i++)          /* Clear entire Extended FCB    */
  80.     xfcb[i] = 0;
  81.     fcb[-7] = (char) 0xff;          /* Mark this as an Extended FCB */
  82.     fcb[-1] = AT_VOLUME;          /* Select volume attribute.     */
  83.     fcb[0]  = (char) drive;
  84.     for (i = 1; i <= 11; i++)          /* Search for "????????.???"    */
  85.     fcb[i] = '?';
  86.  
  87.     dos_reg.ax = 0x1100;          /* DOS function 0x11:  search   */
  88.     utabsptr(xfcb,&xfcb_ads);          /* for first matching entry.    */
  89.     dos_reg.ds = xfcb_ads.s;
  90.     dos_reg.dx = xfcb_ads.r;
  91.     dos(&dos_reg);
  92.  
  93.     if (utlobyte(dos_reg.ax) == 0)
  94.     {                      /* Found a volume label.          */
  95.     for (i = 1; i <= 11; i++)
  96.         *pvol++ = found_fcb[i];
  97.     *pvol    = '\0';
  98.     *pftime = *((unsigned *) &(found_fcb[23]));
  99.     *pfdate = *((unsigned *) &(found_fcb[25]));
  100.     result    = 0;
  101.     }
  102.     else
  103.     {                      /* No volume label found.       */
  104.     *pvol    = '\0';
  105.     *pfdate =
  106.     *pftime = 0;
  107.     result    = 1;
  108.     }
  109.  
  110.     flsetdta(&old_dta_ads);          /* Restore former DTA.          */
  111.  
  112.     return result;
  113. }
  114.