home *** CD-ROM | disk | FTP | other *** search
- /**********************************************************************
- *
- * vl.c
- *
- * routines to get/set the volume label
- *
- * created jae 4/7/90
- *
- * WARNING: this module must be compiled with structure alignment
- * turned off or the dos calls will fail
- *
- *********************************************************************/
-
- #include <dos.h>
- #include <string.h>
-
- #include "vl.h"
-
- static int
- _get_vl(
- struct xfcb *xfcb,
- int drive)
- {
- int ret;
- char dta[128];
- char far *curdta;
-
- curdta = getdta();
- setdta(dta);
- memset(xfcb, 0, sizeof(struct xfcb));
- xfcb->xfcb_flag = 0xff;
- xfcb->xfcb_attr = FA_LABEL;
- xfcb->xfcb_fcb.fcb_drive = tolower(drive) - 'a' + 1;
- memset(&xfcb->xfcb_fcb.fcb_name, '?', 8);
- memset(&xfcb->xfcb_fcb.fcb_ext, '?', 3);
- ret = bdosptr(0x11, xfcb, 0);
- setdta(curdta);
- return (ret & 0xff) == 0 ? 0 : -1;
- }
-
- static int
- _cr_vl(
- char *label,
- int drive)
- {
- int i;
- char lab[11];
- struct xfcb xfcb;
-
- memset(&xfcb, 0, sizeof(struct xfcb));
- xfcb.xfcb_flag = 0xff;
- xfcb.xfcb_attr = FA_LABEL;
- xfcb.xfcb_fcb.fcb_drive = tolower(drive) - 'a' + 1;
-
- for (i = 0; i < 11 && label[i]; i++)
- lab[i] = label[i];
- while (i < 11)
- lab[i++] = ' ';
- memcpy(&xfcb.xfcb_fcb.fcb_name, lab, 11);
- if ((bdosptr(0x16, &xfcb, 0) & 0xff) == 0) {
- bdosptr(0x10, &xfcb, 0);
- return 0;
- } else
- return -1;
- }
-
- static int curdrv;
- static char curdir[70];
-
- static void
- set_drv(int drive)
- {
- curdrv = getdisk();
- setdisk(tolower(drive) - 'a');
- getcurdir(0, curdir);
- if (curdir[0] == 0)
- strcpy(curdir, "\\");
- chdir("\\");
- }
-
- static void
- rst_drv(void)
- {
- chdir(curdir);
- setdisk(curdrv);
- }
-
- void
- get_vl(
- int drive,
- char *label)
- {
- int ret;
- struct xfcb xfcb;
-
- set_drv(drive);
- if (_get_vl(&xfcb, drive) == 0) {
- memcpy(label, &xfcb.xfcb_fcb.fcb_name, 11);
- label[11] = 0;
- } else
- label[0] = 0;
- rst_drv();
- }
-
- int
- set_vl(
- int drive,
- char *label)
- {
- struct xfcb xfcb;
- char lab[20];
- int ret;
- int handle;
-
- set_drv(drive);
- ret = _get_vl(&xfcb, drive);
- if (ret == 0)
- bdosptr(0x13, &xfcb, 0);
- ret = _cr_vl(label, drive);
- rst_drv();
- return ret;
- }
-
-
-