home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / os / msdos / programm / 9059 < prev    next >
Encoding:
Text File  |  1992-09-04  |  3.1 KB  |  138 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: MicroSoft C v6.0 code prob.
  5. Message-ID: <04SEP92.16856055.0215@UNBVM1.CSD.UNB.CA>
  6. Lines: 127
  7. Sender: usenet@UNB.CA
  8. Organization: The University of New Brunswick
  9. Date: Fri, 4 Sep 1992 19:36:26 GMT
  10.  
  11. //
  12. // File: t.c
  13. //
  14. //      Test out various subroutines quickly and hopefully with min fuss
  15. //
  16. //
  17.  
  18. void main( int argc, char *argv[] );
  19.  
  20. #include <stdio.h>
  21. #include <dos.h>
  22. #include <signal.h>
  23. #include <process.h>
  24.  
  25. #include "t.h"
  26.  
  27. int get_disk_serial( unsigned char  diskno,
  28.                      char           *ser );
  29.  
  30. int get_byte_form( unsigned char diskno,
  31.                    long int      *i );
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52. A few weeks ago, some people were kind enough to assist me in
  53. writing code that will allow a program to read the disk serial
  54. number (for DOS 4.0 and up).
  55.  
  56. Well, I adapted the code from a Pascal routine in PC magazine
  57. (July 1992, page 496), and this version will run.  The only
  58. problem is that it does not print out the correct disk volume.
  59.  
  60. The program I've written up so far is included below.  Can
  61. anyone here tell me what I'm doing wrong.  More importantly,
  62. can anyone tell me how to do it right?
  63.  
  64. Thanx in advance...
  65. Leslie Mills
  66.  
  67. ********* Program Follows **********
  68.  
  69. /* sorry for the incredibly bad spacing.  I had a horrible time
  70.    trying to transfer the file where I could actually post it
  71. */
  72.  
  73. void main( int  argc,   // these variables are not used.
  74.      char *argv[] )     // I placed them here out of habit
  75. {
  76.  char ser[10];           // disk serial number
  77.  int res;                // result of function call
  78.  
  79.  res = get_disk_serial( (unsigned char) 3, ser );
  80.  if ( res == 0 ) {
  81.   printf( "The serial number of drive C: is: %s\n", ser );
  82.  } else {
  83.   printf( "Call barfed. Big Bad Ugly Error.\n" );
  84.  }
  85.  
  86.  return;
  87. }
  88.  
  89. //
  90. // I grabbed quite a bit of this procedure from:
  91. //          PC Magazine, July 1992, page 496
  92. // Written: 92/09/04
  93. //
  94. int get_disk_serial( unsigned char  diskno,
  95.       char           ser[] )
  96. {
  97.  long int i;         // This will hold the function result
  98.  char     *hexdigits = "0123456789ABCDEF";
  99.  int      res;
  100.  
  101.  union REGS   inregs, outregs;
  102.  struct SREGS segregs;
  103.  
  104.  inregs.h.ah = 0x69;     // DOS fcn call 69h : serial number code
  105.  inregs.h.al = 0x00;     // read from disk, don't write!
  106.  inregs.h.bl = diskno;   // read from disk number in diskno
  107.  inregs.x.dx = (unsigned int) &i;       // data pointer
  108.  
  109.  res = int86x( 0x21, &inregs, &outregs, &segregs );
  110.  if ( outregs.x.cflag ) {
  111.   // my ambiguous way of displaying an error message
  112.   printf( "Little Fluffy took a round, better take him to the vet.\n" );
  113.  } else {
  114.   printf( "Yeah!\n" );
  115.  }
  116.  
  117.  //*- Now long int variable i should have disk serial number
  118.  
  119. printf( "Byte value of i: %lX\n\n", i );
  120.  
  121.  ser[0] = hexdigits[  i >> 28 ];
  122.  ser[1] = hexdigits[ (i >> 24) & 0xf ];
  123.  ser[2] = hexdigits[ (i >> 20) & 0xf ];
  124.  ser[3] = hexdigits[ (i >> 16) & 0xf ];
  125.  ser[4] = '-';
  126.  ser[5] = hexdigits[ (i >> 12) & 0xf ];
  127.  ser[6] = hexdigits[ (i >>  8) & 0xf ];
  128.  ser[7] = hexdigits[ (i >>  4) & 0xf ];
  129.  ser[8] = hexdigits[ i & 0xf ];
  130.  ser[9] = '\0';
  131.  
  132.  printf( "We reached here all right...\n" );
  133.  
  134.  return( 0 );
  135. }
  136.  
  137.  
  138.