home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / os / msdos / programm / 9153 < prev    next >
Encoding:
Text File  |  1992-09-08  |  3.1 KB  |  115 lines

  1. Newsgroups: comp.os.msdos.programmer
  2. Path: sparky!uunet!utcsri!torn!csd.unb.ca!UNBVM1.CSD.UNB.CA
  3. From: P0LU000 <P0LU@UNB.CA>
  4. Subject: Using INT86x(): problem here...
  5. Message-ID: <08SEP92.08486758.0052@UNBVM1.CSD.UNB.CA>
  6. Lines: 103
  7. Sender: usenet@UNB.CA
  8. Organization: The University of New Brunswick
  9. References:  <04SEP92.16856055.0215@UNBVM1.CSD.UNB.CA>
  10. Date: Tue, 8 Sep 1992 11:51:29 GMT
  11.  
  12. Well, I adapted the code from a Pascal routine in PC Magazine
  13. (July 1992, page 496), and this version will run.  The only
  14. problem is that it does not print out the correct disk volume.
  15.  
  16. The program I've written up so far is included below.  Can
  17. anyone here tell me what I'm doing wrong.  More importantly,
  18. can anyone tell me how to do it right?
  19.  
  20. Thanx in advance...
  21. Leslie Mills
  22.  
  23. ********* Program Follows **********
  24.  
  25. /* sorry for the incredibly bad spacing.  I had a horrible time
  26.    trying to transfer the file where I could actually post it,
  27.    and the editor I'm currently using is horrible.
  28. */
  29.  
  30. //
  31. // File: t.c
  32. //
  33. //  Program to read a disk's serial number.
  34. //
  35.  
  36. void main( int argc, char *argv[] );
  37.  
  38. #include <stdio.h>
  39. #include <dos.h>
  40. #include <signal.h>
  41. #include <process.h>
  42.  
  43. #include "t.h"   // File contains only comments, unimportant
  44.  
  45. int get_disk_serial( unsigned char  diskno,
  46.       char           *ser );
  47.  
  48. int get_byte_form( unsigned char diskno,
  49.        long int      *i );
  50.  
  51. void main( int  argc,   // these variables are not used.
  52.       char *argv[] )     // I placed them here out of habit
  53. {
  54.   char ser[10];           // disk serial number
  55.   int res;                // result of function call
  56.  
  57.   res = get_disk_serial( (unsigned char) 3, ser );
  58.   if ( res == 0 ) {
  59.    printf( "The serial number of drive C: is: %s\n", ser );
  60.   } else {
  61.    printf( "Call barfed. Big Bad Ugly Error.\n" );
  62.   }
  63.  
  64.   return;
  65. }
  66.  
  67. //
  68. // I grabbed quite a bit of this procedure from:
  69. //          PC Magazine, July 1992, page 496
  70. // Written: 92/09/04
  71. //
  72. int get_disk_serial( unsigned char  diskno,
  73.        char           ser[] )
  74. {
  75.   long int i;         // This will hold the function result
  76.   char     *hexdigits = "0123456789ABCDEF";
  77.   int      res;
  78.  
  79.   union REGS   inregs, outregs;
  80.   struct SREGS segregs;
  81.  
  82.   inregs.h.ah = 0x69;     // DOS fcn call 69h : serial number code
  83.   inregs.h.al = 0x00;     // read from disk, don't write!
  84.   inregs.h.bl = diskno;   // read from disk number in diskno
  85.   inregs.x.dx = (unsigned int) &i;       // data pointer
  86.  
  87.   res = int86x( 0x21, &inregs, &outregs, &segregs );
  88.   if ( outregs.x.cflag ) {
  89.    // my ambiguous way of displaying an error message
  90.    printf( "Little Fluffy took a round, better take him to the vet.\n" );
  91.   } else {
  92.    printf( "Yeah!\n" );
  93.   }
  94.  
  95.   //*- Now long int variable i should have disk serial number
  96.  
  97. printf( "Byte value of i: %lX\n\n", i );
  98.  
  99.   ser[0] = hexdigits[  i >> 28 ];
  100.   ser[1] = hexdigits[ (i >> 24) & 0xf ];
  101.   ser[2] = hexdigits[ (i >> 20) & 0xf ];
  102.   ser[3] = hexdigits[ (i >> 16) & 0xf ];
  103.   ser[4] = '-';
  104.   ser[5] = hexdigits[ (i >> 12) & 0xf ];
  105.   ser[6] = hexdigits[ (i >>  8) & 0xf ];
  106.   ser[7] = hexdigits[ (i >>  4) & 0xf ];
  107.   ser[8] = hexdigits[ i & 0xf ];
  108.   ser[9] = '\0';
  109.  
  110.   printf( "We reached here all right...\n" );
  111.  
  112.   return( 0 );
  113. }
  114.  
  115.