home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PROGRAMS / UTILS / HARDDISK / BADCLU.ZIP / AE.ZIP / VL.C < prev   
Encoding:
C/C++ Source or Header  |  1990-04-10  |  2.5 KB  |  125 lines

  1. /**********************************************************************
  2.  *  
  3.  *  vl.c
  4.  *  
  5.  *  routines to get/set the volume label
  6.  *  
  7.  *  created jae 4/7/90  
  8.  *
  9.  *  WARNING: this module must be compiled with structure alignment
  10.  *  turned off or the dos calls will fail
  11.  *  
  12.  *********************************************************************/
  13.  
  14. #include <dos.h>
  15. #include <string.h>
  16.  
  17. #include "vl.h"
  18.  
  19. static int
  20. _get_vl(
  21.     struct xfcb *xfcb,
  22.     int         drive)
  23. {
  24.     int         ret;
  25.     char        dta[128];
  26.     char far    *curdta;
  27.  
  28.     curdta = getdta();
  29.     setdta(dta);
  30.     memset(xfcb, 0, sizeof(struct xfcb));
  31.     xfcb->xfcb_flag = 0xff;
  32.     xfcb->xfcb_attr = FA_LABEL;
  33.     xfcb->xfcb_fcb.fcb_drive = tolower(drive) - 'a' + 1;
  34.     memset(&xfcb->xfcb_fcb.fcb_name, '?', 8);
  35.     memset(&xfcb->xfcb_fcb.fcb_ext, '?', 3);
  36.     ret = bdosptr(0x11, xfcb, 0);
  37.     setdta(curdta);
  38.     return (ret & 0xff) == 0 ? 0 : -1;
  39. }
  40.  
  41. static int
  42. _cr_vl(
  43.     char    *label,
  44.     int     drive)
  45. {
  46.     int         i;
  47.     char        lab[11];
  48.     struct xfcb xfcb;
  49.  
  50.     memset(&xfcb, 0, sizeof(struct xfcb));
  51.     xfcb.xfcb_flag = 0xff;
  52.     xfcb.xfcb_attr = FA_LABEL;
  53.     xfcb.xfcb_fcb.fcb_drive = tolower(drive) - 'a' + 1;
  54.     
  55.     for (i = 0; i < 11 && label[i]; i++)
  56.         lab[i] = label[i];
  57.     while (i < 11)
  58.         lab[i++] = ' ';
  59.     memcpy(&xfcb.xfcb_fcb.fcb_name, lab, 11);
  60.     if ((bdosptr(0x16, &xfcb, 0) & 0xff) == 0) {
  61.         bdosptr(0x10, &xfcb, 0);
  62.         return 0;
  63.     } else
  64.         return -1;
  65. }
  66.  
  67. static int  curdrv;
  68. static char curdir[70];
  69.  
  70. static void
  71. set_drv(int drive)
  72. {
  73.     curdrv = getdisk();
  74.     setdisk(tolower(drive) - 'a');
  75.     getcurdir(0, curdir);
  76.     if (curdir[0] == 0)
  77.         strcpy(curdir, "\\");
  78.     chdir("\\");
  79. }
  80.  
  81. static void
  82. rst_drv(void)
  83. {
  84.     chdir(curdir);
  85.     setdisk(curdrv);
  86. }    
  87.  
  88. void
  89. get_vl(
  90.     int     drive,
  91.     char    *label)
  92. {
  93.     int         ret;
  94.     struct xfcb xfcb;
  95.     
  96.     set_drv(drive);
  97.     if (_get_vl(&xfcb, drive) == 0) {
  98.         memcpy(label, &xfcb.xfcb_fcb.fcb_name, 11);
  99.         label[11] = 0;
  100.     } else
  101.         label[0] = 0;
  102.     rst_drv();
  103. }    
  104.  
  105. int
  106. set_vl(
  107.     int     drive,
  108.     char    *label)
  109. {
  110.     struct xfcb     xfcb;
  111.     char            lab[20];
  112.     int             ret;
  113.     int             handle;
  114.         
  115.     set_drv(drive);
  116.     ret = _get_vl(&xfcb, drive);
  117.     if (ret == 0) 
  118.         bdosptr(0x13, &xfcb, 0);
  119.     ret = _cr_vl(label, drive);
  120.     rst_drv();
  121.     return ret;
  122. }
  123.  
  124.  
  125.