PRODUCT : Borland C++ NUMBER : 1030 VERSION : 3.x OS : DOS DATE : October 19, 1993 PAGE : 1/4 TITLE : Using XFCBs to set/remove Volume Labels /* ------------------ [ SET VOLUME LABEL ] ----------------- *\ | Finding the volume label of a particular Media can be | | achieved with the findfirst() function of the Borland C/C++ | | compilers. Modifying the Volume Label, however, requires | | using Extended File Control Blocks. The following function | | ( and Macros ) can be used to Set and Remove Volume Labels. | \* --------------------------------------------------------- */ #include #include #pragma option -a- struct EXTENDEDFCB { char extSignature ; char extReserved1[5] ; char extAttribute ; char extDriveID ; char extFileName[8] ; char extExtent[3] ; short extCurBlockNo ; short extRecSize ; char extFileSize[4] ; short extFileDate ; short extFileTime ; char extReserved2[8] ; char extCurRecNo ; char extRandonRecNo[4]; }; #pragma option -a. /* -------------------- [ FCB MACROS ]----------------------- *\ | The following MACROS take advantage of Borland C++'s | | pseudoregisters and the __emit__() function to create a | | wrapper around INT 21, FUNCTIONS 13H and 16H which allow for | PRODUCT : Borland C++ NUMBER : 1030 VERSION : 3.x OS : DOS DATE : October 19, 1993 PAGE : 2/4 TITLE : Using XFCBs to set/remove Volume Labels. | the deletion and creation of FILES using FCBS. The MACRO can| | be passed either an FCB or and Extended FCB structure with | | the various fields already initialized. The result of the | | operation is kept in the AL register... | \* ---------------------------------------------------------- */ #define CreateFCB( xfcb ) __emit__( 0x1E ); /* PUSH DS */\ _AH = 0x2F; /* Get Current DTA */\ geninterrupt( 0x21 ); /* Call Upon DOS.. */\ __emit__( 0x06, 0x53 ); /* PUSH ES - PUSH BX */\ _DS = FP_SEG( &xfcb ); /* Load Seg. of New DTA */\ _DX = FP_OFF( &xfcb ); /* Load Off. of New DTA */\ _AH = 0x1A; /* Set DTA Function.. */\ geninterrupt( 0x21 ); /* Call Upon DOS */\ _AH = 0x16; /* Create File Function */\ geninterrupt( 0x21 ); /* Call Upon DOS */\ __emit__( 0x5A, 0x1F ); /* POP DX - POP DS */\ __emit__( 0x50 ); /* PUSH AX ( results ) */\ _AH = 0x1A; /* Set ( Restore ) DTA */\ geninterrupt( 0x21 ); /* Call Upon DOS */\ __emit__( 0x58 ); /* Restore Results... */\ __emit__( 0x1F ); /* Restore DS value... */ #define DeleteFCB( xfcb ) __emit__( 0x1E ); /* PUSH DS */\ _AH = 0x2F; /* Get Current DTA */\ geninterrupt( 0x21 ); /* Call Upon DOS.. */\ __emit__( 0x06, 0x53 ); /* PUSH ES - PUSH BX */\ _DS = FP_SEG( &xfcb ); /* Load Seg. of New DTA */\ _DX = FP_OFF( &xfcb ); /* Load Off. of New DTA */\ _AH = 0x1A; /* Set DTA Function.. */\ geninterrupt( 0x21 ); /* Call Upon DOS */\ _AH = 0x13; /* Delete File Function */\ geninterrupt( 0x21 ); /* Call Upon DOS */\ __emit__( 0x5A, 0x1F ); /* POP DX - POP DS */\ __emit__( 0x50 ); /* PUSH AX ( results ) */\ _AH = 0x1A; /* Set ( Restore ) DTA */\ geninterrupt( 0x21 ); /* Call Upon DOS */\ __emit__( 0x58 ); /* Restore Results... */\ __emit__( 0x1F ); /* Restore DS value... */ /* --------------- [ SET VOLUME LABEL ]--------------------- *\ PRODUCT : Borland C++ NUMBER : 1030 VERSION : 3.x OS : DOS DATE : October 19, 1993 PAGE : 3/4 TITLE : Using XFCBs to set/remove Volume Labels. | This function modifies the VOLUME LABEL of the specified | | Drive using extended FCBs. The parameters are as follows: | | driveNum: 0 for current, 1 for A:, 2 for B:, 3 for C: etc| | Label : ASCIIZ string containing new label ( If NULL | | current label is merely removed ). | | RETURNS : 0x00-Successful 0xFF-Failed | \* --------------------------------------------------------- */ int SetVolLabel( int driveNum, char *Label ) { char *p; struct EXTENDEDFCB xfcb; memset(( void * )&xfcb, 0x20, sizeof( xfcb )); xfcb.extSignature = 0xFF; /* Signal Extended FCB */ xfcb.extAttribute = 0x08; /* Volume's Attribute */ xfcb.extDriveID = ( char )driveNum; /* Drive ID.*/ memset(( void * )xfcb.extFileName, '?', 11 ); DeleteFCB( xfcb ); /* Delete any LABEL */ if ( !Label ) /* NULL Label ? */ return(( int )_AL ); /* Just return if YES..*/ memset(( void * )xfcb.extFileName, ' ', 11 ); for( p = xfcb.extFileName; p < ( char * )&xfcb.extCurBlockNo; p++ ) { if ( *Label == NULL ) break; *p = *Label++; } CreateFCB( xfcb ); /* Create New Label.. */ return(( int )_AL ); /* Return Results.. */ } int main( int argc, char *argv[] ) { if ( argc > 1 ) PRODUCT : Borland C++ NUMBER : 1030 VERSION : 3.x OS : DOS DATE : October 19, 1993 PAGE : 4/4 TITLE : Using XFCBs to set/remove Volume Labels. SetVolLabel( 0, argv[1] ); /* Set Label of Local */ else SetVolLabel( 0, NULL ); /* Clear Label of Local*/ return( 0 ); }