home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name drsetvol -- Create or alter the volume label on a given
- * disk drive.
- *
- * Synopsis ercode = drsetvol(drive,pvol);
- *
- * int ercode 1 if error, 0 if okay.
- * int drive Disk drive (0 = default, 1 = A:, etc.)
- * char *pvol Volume name (up to 11 characters long).
- *
- * Description This function changes the volume label on a given disk
- * drive (if one already exists) or creates it (if none
- * already exists). If the label is created, it is given
- * the current time and date; if it is merely renamed, its
- * date and time stamps are not changed.
- *
- * The volume label may contain blanks or other characters
- * which are ordinarily illegal in DOS filenames. The
- * first 11 characters of *pvol are used (at most).
- *
- * Returns ercode 1 if error, 0 if okay.
- *
- * Version 3.0 (C)Copyright Blaise Computing Inc. 1986
- *
- * Version 3.02 March 24, 1987
- * Removed a strong typing warning (no change in object
- * code).
- *
- **/
-
- #include <string.h>
-
- #include <bdirect.h>
- #include <bfile.h>
-
- int drsetvol(drive,pvol)
- int drive;
- char *pvol;
- {
- DOSREG dos_reg;
- char local_dta[44],xfcb[44];
- ADS old_dta_ads,ldta_ads,xfcb_ads;
- register int i;
- int length;
-
- #define fcb (xfcb + 7)
- #define found_fcb (local_dta + 7)
-
- flretdta(&old_dta_ads); /* Save former Data Transfer */
- /* Address. */
- utabsptr(local_dta,&ldta_ads);
- flsetdta(&ldta_ads); /* Select local DTA. */
-
- for (i = 0; i < 44; i++) /* Clear entire Extended FCB */
- xfcb[i] = 0;
- fcb[-7] = (char) 0xff; /* Mark this as an Extended FCB */
- fcb[-1] = AT_VOLUME; /* Select volume attribute. */
- fcb[0] = (char) drive;
- for (i = 1; i <= 11; i++) /* Search for "????????.???" */
- fcb[i] = '?';
-
- dos_reg.ax = 0x1100; /* DOS function 0x11: search */
- utabsptr(xfcb,&xfcb_ads); /* for first matching entry. */
- dos_reg.ds = xfcb_ads.s;
- dos_reg.dx = xfcb_ads.r;
- dos(&dos_reg);
-
- length = (int) strlen(pvol);
- utuplim(length,11)
-
- if (utlobyte(dos_reg.ax) == 0)
- { /* Found a volume label, so */
- /* rename it. */
- for (i = 12; i <= 36 ; i++)
- found_fcb[i] = 0;
- for (i = 0 ; i < length; i++)
- found_fcb[17 + i] = *pvol++;
- for ( ; i < 12 ; i++)
- found_fcb[17 + i] = ' '; /* Pad volume name with blanks. */
-
- dos_reg.ax = 0x1700; /* DOS function 0x17: rename. */
- dos_reg.ds = ldta_ads.s;
- dos_reg.dx = ldta_ads.r;
- dos(&dos_reg);
- }
- else
- { /* No volume label found, so */
- /* create one. */
- for (i = 12; i <= 36 ; i++)
- fcb[i] = 0;
- for (i = 0 ; i < length; i++)
- fcb[1 + i] = *pvol++;
- for ( ; i < 12 ; i++)
- fcb[1 + i] = ' '; /* Pad volume name with blanks. */
-
- dos_reg.ax = 0x1600; /* DOS function 0x16: create */
- dos(&dos_reg); /* file. */
-
- if (utlobyte(dos_reg.ax) == 0)/* Successfully created the */
- { /* label, so close the newly- */
- dos_reg.ax = 0x1000; /* created file. */
- dos(&dos_reg);
- }
- }
-
- flsetdta(&old_dta_ads); /* Restore former DTA. */
-
- return (utlobyte(dos_reg.ax) != 0);
- }