home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name FLSETVOL -- Create or alter the volume label on a given
- * disk drive.
- *
- * Synopsis ercode = flsetvol (drive, pvol);
- *
- * int ercode 1 if error, 0 if okay.
- * int drive Disk drive (0 = default, 1 = A:, etc.)
- * const 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 6.00 (C)Copyright Blaise Computing Inc. 1986,1987,1989
- *
- **/
-
- #include <dos.h>
- #include <string.h>
-
- #include <bfiles.h>
-
- #define fcb (xfcb + 7)
- #define found_fcb (local_dta + 7)
-
- int flsetvol (drive, pvol)
- int drive;
- const char *pvol;
- {
- union REGS regs;
- struct SREGS sregs;
- unsigned char local_dta[44], xfcb[44];
- register int i;
- int length;
- void far *pold_dta;
-
- /* Save former Data Transfer Address. */
- pold_dta = flgetdta ();
- /* Select local DTA. */
- flputdta ((void far *) local_dta);
-
- /* Clear entire Extended FCB */
- for (i = 0; i < 44; i++)
- xfcb[i] = 0;
-
- /* Mark this as an Extended FCB */
- fcb[-7] = 0xff;
- /* Select volume attribute. */
- fcb[-1] = AT_VOLUME;
- fcb[0] = (char) drive;
-
- /* Search for "????????.???" */
- for (i = 1; i <= 11; i++)
- fcb[i] = '?';
-
- /* Set up for DOS function 0x11: search for first */
- /* matching entry. */
- regs.x.ax = 0x1100;
- sregs.ds = utseg (xfcb);
- regs.x.dx = utoff (xfcb);
-
- /* Go do the search. */
- int86x (FL_DOS_INT, ®s,®s,&sregs);
-
- length = (int) strlen (pvol);
- utuplim (length, 11)
-
- if (regs.h.al == 0)
- { /* Found a volume label, so rename it. */
-
- /* Zero parts of FCB. */
- for (i = 12; i <= 36; i++)
- found_fcb[i] = 0;
-
- /* Copy over new volume name. */
- for (i = 0; i < length; i++)
- found_fcb[17 + i] = *pvol++;
-
- /* Pad volume name with blanks. */
- for (; i < 12; i++)
- found_fcb[17 + i] = ' ';
-
- /* DOS function 0x17: rename. */
- regs.x.ax = 0x1700;
- sregs.ds = utseg (local_dta);
- regs.x.dx = utoff (local_dta);
-
- /* Go rename it. */
- int86x (FL_DOS_INT, ®s, ®s, &sregs);
- }
-
- else
- { /* No volume label found, so create one. */
-
- /* Zero parts of FCB. */
- for (i = 12; i <= 36; i++)
- fcb[i] = 0;
-
- /* Copy over new volume name. */
- for (i = 0; i < length; i++)
- fcb[1 + i] = *pvol++;
-
- /* Pad volume name with blanks. */
- for (; i < 12; i++)
- fcb[1 + i] = ' ';
-
- /* DOS function 0x16: create file. */
- regs.x.ax = 0x1600;
-
- /* Go create the volume label. */
- int86x(FL_DOS_INT,®s,®s,&sregs);
-
- if (regs.h.al == 0)
- { /* Successfully created the label, so close the */
- /* newly-created file. */
- regs.x.ax = 0x1000;
- int86x(FL_DOS_INT,®s,®s,&sregs);
- }
- }
-
- /* Restore former DTA. */
- flputdta (pold_dta);
-
- return (regs.h.al != 0);
- }