home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.os.msdos.programmer
- Path: sparky!uunet!cs.utexas.edu!torn!csd.unb.ca!UNBVM1.CSD.UNB.CA
- From: P0LU000 <P0LU@UNB.CA>
- Subject: RE: Using INT86x(): Problem solved
- Message-ID: <08SEP92.11461857.0198@UNBVM1.CSD.UNB.CA>
- Lines: 92
- Sender: usenet@UNB.CA
- Organization: The University of New Brunswick
- References: <04SEP92.16856055.0215@UNBVM1.CSD.UNB.CA> <08SEP92.08486758.0052@UNBVM1.CSD.UNB.CA>
- Date: Tue, 8 Sep 1992 14:36:46 GMT
-
- Regarding my earlier problems with int86x...h
-
- The reason why I can't get it to work is because I have to use
- another routine to read the disk info: int86(). This, along with
- correcting the structure (instead of using a long int variable),
- fixed the problem I was having. I solved this about two hours
- after I posted the earlier program. ogi
-
- If any of you need the same type of routine, here is my C version
- (original came from PC Magazine, July 1992, pg 496 written in
- Pascal)
-
-
- #include <stdio.h>
- #include <dos.h>
- #include <signal.h>
- #include <process.h>
-
- void main( int argc, char *argv[] );
-
- int get_disk_serial( unsigned char diskno,
- char *ser );
-
- int get_byte_form( unsigned char diskno,
- long int *i );
-
- void main( int argc,
- char *argv[] )
- {
- char ser[10]; // disk serial number
- int res; // result of function call
-
- res = get_disk_serial( (unsigned char) 3, ser );
- if ( res == 0 ) {
- printf( "The serial number of drive C: is: %s\n", ser );
- } else {
- printf( "Call barfed. Big Bad Ugly Error.\n" );
- }
-
- return;
- }
-
- struct infobuffer
- {
- int infolevel; // should be zero
- long int serial; // serial number in byte form
- char vol_label[11]; // volume label
- char file_sys[8]; // file system
- };
-
- //
- // I grabbed quite a bit of this procedure from:
- // PC Magazine, July 1992, page 496
- // Written: 92/09/04
- //
- int get_disk_serial( unsigned char diskno,
- char ser[] )
- {
- char *hexdigits = "0123456789ABCDEF";
- int res;
- struct infobuffer x; // where we are putting info
-
- union REGS inregs, outregs;
-
- inregs.h.ah = 0x69; // DOS fcn call 69h : serial number code
- inregs.h.al = 0x00; // read from disk, don't write!
- inregs.h.bl = diskno; // read from disk number in diskno
- inregs.x.dx = (unsigned int) &x; // data pointer
-
- res = int86( 0x21, &inregs, &outregs );
- if ( outregs.x.cflag ) {
- printf( "Little Fluffy took a round, better take him to the vet.\n" );
- return( 15 );
- }
-
- //*- Now long int variable serial should have disk serial number
-
- ser[0] = hexdigits[ x.serial >> 28 ];
- ser[1] = hexdigits[ (x.serial >> 24) & 0xf ];
- ser[2] = hexdigits[ (x.serial >> 20) & 0xf ];
- ser[3] = hexdigits[ (x.serial >> 16) & 0xf ];
- ser[4] = '-';
- ser[5] = hexdigits[ (x.serial >> 12) & 0xf ];
- ser[6] = hexdigits[ (x.serial >> 8) & 0xf ];
- ser[7] = hexdigits[ (x.serial >> 4) & 0xf ];
- ser[8] = hexdigits[ x.serial & 0xf ];
- ser[9] = '\0';
-
- return( 0 );
- }
-
-
-