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

  1. /**
  2. *
  3. * Name        drsetvol -- Create or alter the volume label on a given
  4. *                disk drive.
  5. *
  6. * Synopsis    ercode = drsetvol(drive,pvol);
  7. *
  8. *        int  ercode      1 if error, 0 if okay.
  9. *        int  drive      Disk drive (0 = default, 1 = A:, etc.)
  10. *        char *pvol      Volume name (up to 11 characters long).
  11. *
  12. * Description    This function changes the volume label on a given disk
  13. *        drive (if one already exists) or creates it (if none
  14. *        already exists).  If the label is created, it is given
  15. *        the current time and date; if it is merely renamed, its
  16. *        date and time stamps are not changed.
  17. *
  18. *        The volume label may contain blanks or other characters
  19. *        which are ordinarily illegal in DOS filenames.    The
  20. *        first 11 characters of *pvol are used (at most).
  21. *
  22. * Returns    ercode          1 if error, 0 if okay.
  23. *
  24. * Version    3.0 (C)Copyright Blaise Computing Inc.    1986
  25. *
  26. * Version    3.02 March 24, 1987
  27. *        Removed a strong typing warning (no change in object
  28. *            code).
  29. *
  30. **/
  31.  
  32. #include <string.h>
  33.  
  34. #include <bdirect.h>
  35. #include <bfile.h>
  36.  
  37. int drsetvol(drive,pvol)
  38. int     drive;
  39. char     *pvol;
  40. {
  41.     DOSREG     dos_reg;
  42.     char     local_dta[44],xfcb[44];
  43.     ADS      old_dta_ads,ldta_ads,xfcb_ads;
  44.     register int i;
  45.     int      length;
  46.  
  47. #define fcb        (xfcb      + 7)
  48. #define found_fcb   (local_dta + 7)
  49.  
  50.     flretdta(&old_dta_ads);          /* Save former Data Transfer    */
  51.                       /* Address.              */
  52.     utabsptr(local_dta,&ldta_ads);
  53.     flsetdta(&ldta_ads);          /* Select local DTA.          */
  54.  
  55.     for (i = 0; i < 44; i++)          /* Clear entire Extended FCB    */
  56.     xfcb[i] = 0;
  57.     fcb[-7] = (char) 0xff;          /* Mark this as an Extended FCB */
  58.     fcb[-1] = AT_VOLUME;          /* Select volume attribute.     */
  59.     fcb[0]  = (char) drive;
  60.     for (i = 1; i <= 11; i++)          /* Search for "????????.???"    */
  61.     fcb[i] = '?';
  62.  
  63.     dos_reg.ax = 0x1100;          /* DOS function 0x11:  search   */
  64.     utabsptr(xfcb,&xfcb_ads);          /* for first matching entry.    */
  65.     dos_reg.ds = xfcb_ads.s;
  66.     dos_reg.dx = xfcb_ads.r;
  67.     dos(&dos_reg);
  68.  
  69.     length = (int) strlen(pvol);
  70.     utuplim(length,11)
  71.  
  72.     if (utlobyte(dos_reg.ax) == 0)
  73.     {                      /* Found a volume label, so     */
  74.                       /* rename it.              */
  75.     for (i = 12; i <= 36   ; i++)
  76.         found_fcb[i] = 0;
  77.     for (i = 0 ; i < length; i++)
  78.         found_fcb[17 + i] = *pvol++;
  79.     for (       ; i < 12    ; i++)
  80.         found_fcb[17 + i] = ' ';  /* Pad volume name with blanks. */
  81.  
  82.     dos_reg.ax = 0x1700;          /* DOS function 0x17:  rename.  */
  83.     dos_reg.ds = ldta_ads.s;
  84.     dos_reg.dx = ldta_ads.r;
  85.     dos(&dos_reg);
  86.     }
  87.     else
  88.     {                      /* No volume label found, so    */
  89.                       /* create one.              */
  90.     for (i = 12; i <= 36   ; i++)
  91.         fcb[i] = 0;
  92.     for (i = 0 ; i < length; i++)
  93.         fcb[1 + i] = *pvol++;
  94.     for (       ; i < 12    ; i++)
  95.         fcb[1 + i] = ' ';         /* Pad volume name with blanks. */
  96.  
  97.     dos_reg.ax = 0x1600;          /* DOS function 0x16:  create   */
  98.     dos(&dos_reg);              /* file.                  */
  99.  
  100.     if (utlobyte(dos_reg.ax) == 0)/* Successfully created the     */
  101.     {                  /* label, so close the newly-   */
  102.         dos_reg.ax = 0x1000;      /* created file.              */
  103.         dos(&dos_reg);
  104.     }
  105.     }
  106.  
  107.     flsetdta(&old_dta_ads);          /* Restore former DTA.          */
  108.  
  109.     return (utlobyte(dos_reg.ax) != 0);
  110. }
  111.