home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_01_02 / 1n02062a < prev    next >
Text File  |  1990-07-09  |  2KB  |  68 lines

  1. /*
  2. **  Listing 8 - Removing, setting, or changing volume labels
  3. **
  4. **  Note: Requires byte alignment and use of xfcb structure,
  5. **        therefore written for TC 2.0 or TC++ 1.0. Also compiles
  6. **        under ZTC/C++ using MFLZT's TCPORT.H.
  7. */
  8.  
  9. #include <stdio.h>
  10. #include <dos.h>
  11. #include <dir.h>
  12. #include <io.h>
  13.  
  14. int PushDir(char *);
  15. int PopDir(void);
  16.  
  17. int vol_kill(char *fname)
  18. {
  19.         union REGS regs;
  20.         struct SREGS sregs;
  21.         struct xfcb buf;
  22.  
  23.         /* Parse the filename into an FCB               */
  24.         segread(&sregs);
  25.         regs.h.ah = 0x29;
  26.         regs.h.al = 0;
  27.         regs.x.si = (unsigned)fname;
  28.         regs.x.di = (unsigned)&buf.xfcb_fcb;
  29.         sregs.es  = sregs.ds;
  30.         intdosx(®s, ®s, &sregs);
  31.  
  32.         /* Volume labels require extended FCB's         */
  33.         buf.xfcb_flag = 0xff;
  34.         buf.xfcb_attr = FA_LABEL;
  35.  
  36.         /* Delete the old label                         */
  37.         regs.h.ah = 0x13;
  38.         regs.x.dx = (unsigned)&buf;
  39.         intdos(®s, ®s);
  40. }
  41.  
  42. void flsetvol(char *label)
  43. {
  44.         int fd;
  45.         struct ffblk finfo;
  46.  
  47.         pushdir("\\");          /* Move to the root directory   */
  48.         /* If drive is already labeled, remove it               */
  49.         if (0 == findfirst("*.*", &finfo, FA_LABEL)) do
  50.         {       if (FA_LABEL & finfo.ff_attrib)
  51.                         break;
  52.         } while (0 == findnext(&finfo));
  53.         if (FA_LABEL & finfo.ff_attrib)
  54.                 vol_kill(finfo.ff_name);
  55.         fd = _creat(label, FA_LABEL);   /* Create new label     */
  56.         close(fd);
  57.         popdir();
  58. }
  59.  
  60. main(int argc, char *argv[])
  61. {
  62.         if (2 > argc)
  63.         {       puts("\aUsage: SETVOL new_name");
  64.                 abort();
  65.         }
  66.         flsetvol(argv[1]);
  67. }
  68.