home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
magazine
/
nvdc87
/
doslabel
/
volume.c
< prev
next >
Wrap
Text File
|
1987-07-02
|
4KB
|
115 lines
/* VOLUME.C: Reads and writes volume label */
/* INCLUDES */
#include <stdio.h>
#include <dos.h>
#include <string.h>
/* CONSTANTS */
#define PROMPT "\nLabel is limited to 11 characters:"
#define BEEP 7
#ifndef TRUE
#define TRUE 1
#define FALSE 0
#endif
/* LOCAL FUNCTION PROTOTYPES */
char gotlabel (void);
void change (void);
void addlabel (void);
void pad (char name[]);
/* GLOBALS */
union REGS reg; /* register set */
struct { /* simulated xfcb loaded by DOS fcn 11h */
char skip1[8]; /* space to old label */
char oldlabel[11]; /* old label */
char skip2[5]; /* space to new label */
char newlabel[11]; /* new label */
char skip3[29]; /* to make struct 64 bytes long */
} dta;
struct xfcb fcbx = {{0xFF}, /* initialize xfcb for label search */
{"\0\0\0\0\0"}, /* reserved zeros */
{FA_LABEL}, /* set label attribute */
};
/* -------------------------- */
main ()
{
char exists;
/* INITIALIZE */
setdta (MK_FP (_DS,(unsigned) &dta)); /* dta = scratch buffer */
puts ("\nGet volume label from which drive?");
fcbx.xfcb_fcb.fcb_drive = toupper (getch ()) - '@'; /* get drive */
strcpy (fcbx.xfcb_fcb.fcb_name, "???????????"); /* set wildcard */
/* PROCESS */
if (exists = gotlabel ())
printf ("\nLabel of drive %c is %.11s",
fcbx.xfcb_fcb.fcb_drive + '@', dta.oldlabel);
else
printf ("\nDrive %c has no label",
fcbx.xfcb_fcb.fcb_drive + '@');
puts ("\n\nDo you want to write a new label? (y/n)");
if (toupper (getch ()) == 'Y')
if (exists)
change ();
else
addlabel ();
} /* ------------------------ */
char gotlabel (void) /* read label from disk */
/* returns TRUE if found, else FALSE */
{
reg.x.dx = (unsigned) &fcbx; /* point DX to fcbx */
reg.h.ah = 0x11; /* DOS fcn: search for first */
intdos (®, ®); /* call DOS */
if (!reg.h.al) /* AL = 0 when successful */
return (TRUE);
else /* non-zero AL means no label found */
return (FALSE);
} /* ------------------------ */
void change (void) /* change disk label */
{ /* same DOS call as renaming file */
puts (PROMPT);
scanf ("%11s", dta.newlabel); /* ignore more than 11 chars */
pad (dta.newlabel); /* pad with trailing spaces */
reg.x.dx = (unsigned) &dta; /* point to dta buffer */
reg.h.ah = 0x17; /* DOS fcn: rename file */
intdos (®, ®); /* call DOS */
if (!reg.h.al) /* AL = 0 when successful */
printf ("\n\nLabel successfully changed to %.11s",
dta.newlabel);
else {
puts ("\n\nUnsuccessful! Disk may be damaged");
putchar (BEEP);
}
} /* ------------------------ */
void addlabel (void) /* label an unlabeled disk */
{ /* same DOS call as creating new file */
puts (PROMPT);
scanf ("%11s", fcbx.xfcb_fcb.fcb_name); /* get 11 chars */
pad (fcbx.xfcb_fcb.fcb_name); /* pad with trailing spaces */
reg.x.dx = (unsigned) &fcbx; /* have to use xfcb for this */
reg.h.ah = 0x16; /* DOS fcn: create file */
intdos (®, ®); /* call DOS */
if (!reg.h.al) /* AL = 0 when successful */
printf ("\n\nDisk is now labeled %.11s", fcbx.xfcb_fcb.fcb_name);
else {
puts ("\n\nUnsuccessful! Root directory may be full");
putchar (BEEP);
}
} /* ------------------------ */
void pad (char name[]) /* pad filename with trailing spaces */
{ /* DOS chokes on C null terminator in filename */
int p;
if (strlen (name) < 11)
for (p = strlen (name); p < 11; p++)
name[p] = ' ';
} /* ------------------------ */