🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.msdos.programmer
Article #1352

Using INT86x(): problem here...

#1352
From: P0LU000
Date: Tue, 08 Sep 1992 11:51
102 lines
3306 bytes
Well, I adapted the code from a Pascal routine in PC Magazine
(July 1992, page 496), and this version will run.  The only
problem is that it does not print out the correct disk volume.

The program I've written up so far is included below.  Can
anyone here tell me what I'm doing wrong.  More importantly,
can anyone tell me how to do it right?

Thanx in advance...
Leslie Mills

********* Program Follows **********

/* sorry for the incredibly bad spacing.  I had a horrible time
   trying to transfer the file where I could actually post it,
   and the editor I'm currently using is horrible.
*/

//
// File: t.c
//
//  Program to read a disk's serial number.
//

void main( int argc, char *argv[] );

#include <stdio.h>
#include <dos.h>
#include <signal.h>
#include <process.h>

#include "t.h"   // File contains only comments, unimportant

int get_disk_serial( unsigned char  diskno,
      char           *ser );

int get_byte_form( unsigned char diskno,
       long int      *i );

void main( int  argc,   // these variables are not used.
      char *argv[] )     // I placed them here out of habit
{
  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;
}

//
// 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[] )
{
  long int i;         // This will hold the function result
  char     *hexdigits = "0123456789ABCDEF";
  int      res;

  union REGS   inregs, outregs;
  struct SREGS segregs;

  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) &i;       // data pointer

  res = int86x( 0x21, &inregs, &outregs, &segregs );
  if ( outregs.x.cflag ) {
   // my ambiguous way of displaying an error message
   printf( "Little Fluffy took a round, better take him to the vet.\n" );
  } else {
   printf( "Yeah!\n" );
  }

  //*- Now long int variable i should have disk serial number

printf( "Byte value of i: %lX\n\n", i );

  ser[0] = hexdigits[  i >> 28 ];
  ser[1] = hexdigits[ (i >> 24) & 0xf ];
  ser[2] = hexdigits[ (i >> 20) & 0xf ];
  ser[3] = hexdigits[ (i >> 16) & 0xf ];
  ser[4] = '-';
  ser[5] = hexdigits[ (i >> 12) & 0xf ];
  ser[6] = hexdigits[ (i >>  8) & 0xf ];
  ser[7] = hexdigits[ (i >>  4) & 0xf ];
  ser[8] = hexdigits[ i & 0xf ];
  ser[9] = '\0';

  printf( "We reached here all right...\n" );

  return( 0 );
}
Technical Details
Message-ID: <08SEP92.08486758.0052@UNBVM1.CSD.UNB.CA>
Path: arc1-ca.pugleaf.net!sparky!uunet!utcsri!torn!csd.unb.ca!UNBVM1.CSD.UNB.CA
References: <04SEP92.16856055.0215@UNBVM1.CSD.UNB.CA>

Show Full Headers
Complete Article Headers
Newsgroups: comp.os.msdos.programmer
Path: arc1-ca.pugleaf.net!sparky!uunet!utcsri!torn!csd.unb.ca!UNBVM1.CSD.UNB.CA
From: P0LU000 <P0LU@UNB.CA>
Subject: Using INT86x(): problem here...
Message-ID: <08SEP92.08486758.0052@UNBVM1.CSD.UNB.CA>
Lines: 103
Sender: usenet@UNB.CA
Organization: The University of New Brunswick
References:  <04SEP92.16856055.0215@UNBVM1.CSD.UNB.CA>
Date: Tue, 8 Sep 1992 11:51:29 GMT