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

  1. /**
  2. *
  3. * Name        FLSETVOL -- Create or alter the volume label on a given
  4. *                disk drive.
  5. *
  6. * Synopsis    ercode = flsetvol (drive, pvol);
  7. *
  8. *        int  ercode      1 if error, 0 if okay.
  9. *        int  drive      Disk drive (0 = default, 1 = A:, etc.)
  10. *        const 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    6.00 (C)Copyright Blaise Computing Inc. 1986,1987,1989
  25. *
  26. **/
  27.  
  28. #include <dos.h>
  29. #include <string.h>
  30.  
  31. #include <bfiles.h>
  32.  
  33. #define fcb        (xfcb      + 7)
  34. #define found_fcb   (local_dta + 7)
  35.  
  36. int flsetvol (drive, pvol)
  37. int        drive;
  38. const char *pvol;
  39. {
  40.     union  REGS    regs;
  41.     struct SREGS   sregs;
  42.     unsigned char  local_dta[44], xfcb[44];
  43.     register int   i;
  44.     int        length;
  45.     void far      *pold_dta;
  46.  
  47.         /* Save former Data Transfer Address.            */
  48.     pold_dta = flgetdta ();
  49.         /* Select local DTA.                    */
  50.     flputdta ((void far *) local_dta);
  51.  
  52.         /* Clear entire Extended FCB                */
  53.     for (i = 0; i < 44; i++)
  54.     xfcb[i] = 0;
  55.  
  56.         /* Mark this as an Extended FCB             */
  57.     fcb[-7] = 0xff;
  58.         /* Select volume attribute.                */
  59.     fcb[-1] = AT_VOLUME;
  60.     fcb[0]  = (char) drive;
  61.  
  62.         /* Search for "????????.???"                        */
  63.     for (i = 1;  i <= 11;  i++)
  64.     fcb[i] = '?';
  65.  
  66.         /* Set up for DOS function 0x11:  search for first  */
  67.         /* matching entry.                    */
  68.     regs.x.ax = 0x1100;
  69.     sregs.ds  = utseg (xfcb);
  70.     regs.x.dx = utoff (xfcb);
  71.  
  72.         /* Go do the search.                    */
  73.     int86x (FL_DOS_INT, ®s,®s,&sregs);
  74.  
  75.     length = (int) strlen (pvol);
  76.     utuplim (length, 11)
  77.  
  78.     if (regs.h.al == 0)
  79.     {        /* Found a volume label, so rename it.            */
  80.  
  81.         /* Zero parts of FCB.                    */
  82.     for (i = 12;  i <= 36;       i++)
  83.         found_fcb[i] = 0;
  84.  
  85.         /* Copy over new volume name.                */
  86.     for (i = 0;   i < length;  i++)
  87.         found_fcb[17 + i] = *pvol++;
  88.  
  89.         /* Pad volume name with blanks.             */
  90.     for (;          i < 12;       i++)
  91.         found_fcb[17 + i] = ' ';
  92.  
  93.         /* DOS function 0x17:  rename.                */
  94.     regs.x.ax = 0x1700;
  95.     sregs.ds  = utseg (local_dta);
  96.     regs.x.dx = utoff (local_dta);
  97.  
  98.         /* Go rename it.                    */
  99.     int86x (FL_DOS_INT, ®s, ®s, &sregs);
  100.     }
  101.  
  102.     else
  103.     {        /* No volume label found, so create one.        */
  104.  
  105.         /* Zero parts of FCB.                    */
  106.     for (i = 12;  i <= 36;       i++)
  107.         fcb[i] = 0;
  108.  
  109.         /* Copy over new volume name.                */
  110.     for (i = 0;   i < length;  i++)
  111.         fcb[1 + i] = *pvol++;
  112.  
  113.         /* Pad volume name with blanks.             */
  114.     for (;          i < 12;       i++)
  115.         fcb[1 + i] = ' ';
  116.  
  117.         /* DOS function 0x16:  create file.            */
  118.     regs.x.ax = 0x1600;
  119.  
  120.         /* Go create the volume label.                */
  121.     int86x(FL_DOS_INT,®s,®s,&sregs);
  122.  
  123.     if (regs.h.al == 0)
  124.     {    /* Successfully created the label, so close the     */
  125.         /* newly-created file.                    */
  126.         regs.x.ax = 0x1000;
  127.         int86x(FL_DOS_INT,®s,®s,&sregs);
  128.     }
  129.     }
  130.  
  131.         /* Restore former DTA.                    */
  132.     flputdta (pold_dta);
  133.  
  134.     return (regs.h.al != 0);
  135. }
  136.