saj@iuvax.UUCP (02/15/84)
#N:iuvax:11700007:000:2452 iuvax!apratt Jan 9 04:23:00 1984 /** program in Lattice C for MS-DOS to change the volume label of a disk. Written by Allan Pratt (Collins Box 170, Indiana University, Bloomington, Indiana, 47406) at ...decvax!ihnp4!iuvax!apratt POSTED TO USENET 1/9/84 USAGE: A>LABEL text [drive] The first eleven characters of "text" are made into the volume label of the disk in drive "drive". If the drive specification is omitted, the default drive is assumed. **/ #define XFCB_PREFIX 0xff /* prefix for extended FCBs */ #define LABEL_ATTRIB 0x08 /* label attribute bit */ #define CLOSE_FILE 0x10 /* bdos fn # to close a file */ #define CREATE_FILE 0x16 /* bdos fn # to create a file */ #define RENAME_FILE 0x17 /* bdos fn # to rename a file */ char xfcb[48]; /* buffer for the xfcb itself */ main(argc,argv) int argc; char *argv[]; { char *fcb; char *c; int d = 0; int i; xfcb[0] = XFCB_PREFIX; /* says this is an extended fcb */ xfcb[6] = LABEL_ATTRIB; /* says this is the volume label */ /* all other bytes of the prefix are zero */ if(argc == 1 || argc > 3) { /* wrong # of params */ printf("label: newlabel [d]\n"); exit(); } if(argc == 3) { /* determine drive number (to d) */ if (*argv[2] >= 'A' && *argv[2] <= 'Z') d = *argv[2] - 'A' + 1; else if (*argv[2] >= 'a' && *argv[2] <= 'z') d = *argv[2] - 'a' + 1; else { printf("label: invalid drive specifier\n"); exit(); } } xfcb[7] = d; /* put the drive specifier in the fcb */ /* delete the label if there is one */ for(i=1;i<12;i++) xfcb[7+i]='?'; /* wildcard matches any label */ for(c=argv[1], i=0;i<11;i++) { /* fill the secondary part with the */ if(*c != '\0') xfcb[0x18+i] = *c++; /* new label name */ else xfcb[0x18+i] = ' '; } /* the following attempts to rename any file ("????????.???") which has the LABEL attribute set, to the new label (from the argument). If that fails, the XFCB is re-worked, so that the new label is in the normal filename position, and this file (again with the LABEL attribute) is created. If THAT fails, an error is reported. */ if(bdos(RENAME_FILE,xfcb) & 0xff) { /* attempt a RENAME. */ /* if that fails, move the filename and CREATE */ for(i=0; i<11; i++) /* move the new name into the normal */ xfcb[8+i] = xfcb[0x18+i]; /* filename spot */ if(bdos(CREATE_FILE,xfcb) & 0xff) printf("label: cannot create new label.\n"); else bdos(CLOSE_FILE,xfcb); } }