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

  1. Newsgroups: comp.os.msdos.programmer
  2. Path: sparky!uunet!cs.utexas.edu!torn!csd.unb.ca!UNBVM1.CSD.UNB.CA
  3. From: P0LU000 <P0LU@UNB.CA>
  4. Subject: RE: Using INT86x(): Problem solved
  5. Message-ID: <08SEP92.11461857.0198@UNBVM1.CSD.UNB.CA>
  6. Lines: 92
  7. Sender: usenet@UNB.CA
  8. Organization: The University of New Brunswick
  9. References:  <04SEP92.16856055.0215@UNBVM1.CSD.UNB.CA> <08SEP92.08486758.0052@UNBVM1.CSD.UNB.CA>
  10. Date: Tue, 8 Sep 1992 14:36:46 GMT
  11.  
  12. Regarding my earlier problems with int86x...h
  13.  
  14. The reason why I can't get it to work is because I have to use
  15. another routine to read the disk info: int86().  This, along with
  16. correcting the structure (instead of using a long int variable),
  17. fixed the problem I was having.  I solved this about two hours
  18. after I posted the earlier program.        ogi
  19.  
  20. If any of you need the same type of routine, here is my C version
  21. (original came from PC Magazine, July 1992, pg 496 written in
  22. Pascal)
  23.  
  24.  
  25. #include <stdio.h>
  26. #include <dos.h>
  27. #include <signal.h>
  28. #include <process.h>
  29.  
  30. void main( int argc, char *argv[] );
  31.  
  32. int get_disk_serial( unsigned char diskno,
  33.       char          *ser  );
  34.  
  35. int get_byte_form( unsigned char diskno,
  36.        long int      *i );
  37.  
  38. void main( int  argc,
  39.      char *argv[] )
  40. {
  41.  char ser[10];           // disk serial number
  42.  int res;                // result of function call
  43.  
  44.  res = get_disk_serial( (unsigned char) 3, ser );
  45.  if ( res == 0 ) {
  46.   printf( "The serial number of drive C: is: %s\n", ser );
  47.  } else {
  48.   printf( "Call barfed. Big Bad Ugly Error.\n" );
  49.  }
  50.  
  51.  return;
  52. }
  53.  
  54. struct infobuffer
  55. {
  56.  int      infolevel;         // should be zero
  57.  long int serial;            // serial number in byte form
  58.  char     vol_label[11];     // volume label
  59.  char     file_sys[8];       // file system
  60. };
  61.  
  62. //
  63. // I grabbed quite a bit of this procedure from:
  64. //          PC Magazine, July 1992, page 496
  65. // Written: 92/09/04
  66. //
  67. int get_disk_serial( unsigned char  diskno,
  68.       char           ser[] )
  69. {
  70.  char     *hexdigits = "0123456789ABCDEF";
  71.  int      res;
  72.  struct infobuffer x;             // where we are putting info
  73.  
  74.  union REGS   inregs, outregs;
  75.  
  76.  inregs.h.ah = 0x69;     // DOS fcn call 69h : serial number code
  77.  inregs.h.al = 0x00;     // read from disk, don't write!
  78.  inregs.h.bl = diskno;   // read from disk number in diskno
  79.  inregs.x.dx = (unsigned int) &x;       // data pointer
  80.  
  81.  res = int86( 0x21, &inregs, &outregs );
  82.  if ( outregs.x.cflag ) {
  83.   printf( "Little Fluffy took a round, better take him to the vet.\n" );
  84.   return( 15 );
  85.  }
  86.  
  87.  //*- Now long int variable serial should have disk serial number
  88.  
  89.  ser[0] = hexdigits[  x.serial >> 28 ];
  90.  ser[1] = hexdigits[ (x.serial >> 24) & 0xf ];
  91.  ser[2] = hexdigits[ (x.serial >> 20) & 0xf ];
  92.  ser[3] = hexdigits[ (x.serial >> 16) & 0xf ];
  93.  ser[4] = '-';
  94.  ser[5] = hexdigits[ (x.serial >> 12) & 0xf ];
  95.  ser[6] = hexdigits[ (x.serial >>  8) & 0xf ];
  96.  ser[7] = hexdigits[ (x.serial >>  4) & 0xf ];
  97.  ser[8] = hexdigits[ x.serial & 0xf ];
  98.  ser[9] = '\0';
  99.  
  100.  return( 0 );
  101. }
  102.  
  103.  
  104.