🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Finding available drives (using Microsoft C)

#2143
From: Jim Dunn
Date: Mon, 10 Sep 1990 14:29
58 lines
2244 bytes
The question was posed as to how to check a drive to see if it is available
without getting the annoying "Abort, Retry, Ignore" error.  Below I have
a source of a program (written in microsoft or quick c) that will check the
drive H: and if it is NOT available will simply print that info to the
standard out.  This can/could be easily re-written to display all available
drives, etc.  

Have at it!

---Cut Here---

/********************************************************************
*  WR_PROT.C
*
*       Check to see if a drive is write protected
*
*       Compiled with MSC 5.1   2/5/90   by Kevin English
*       kje2282@venus.tamu.edu  kje2282@tamvenus.bitnet
*       edited a bit by jdunn@dsac.dla.mil
*
*       Uses the DOS Interupts 25H and 26H to do an absolute
*       read, then write of logical sector 0 of the drive.
*
*       resultant ERRORLEVELs:
*          2 : error accessing drive
*          1 : write protected
*          0 : writable
*/
#include <dos.h>
char buffer[2048];

int main()
{
   union REGS inregs, outregs;
   struct SREGS segregs;
   char far *bufferp;

   inregs.h.al = 133; /* drive number 0,1 = a,b: 128,129=c,d: 133=h (lan) */
   inregs.x.cx = 1;   /* sectors to read */
   inregs.x.dx = 0;   /* starting sector number */
   bufferp = buffer;
   inregs.x.bx = FP_OFF(bufferp);
   segregs.ds  = FP_SEG(bufferp);

   int86x(0x25, &inregs, &outregs, &segregs);
   if (outregs.x.cflag == 1) {
	  printf("error reading drive H:\n");
      return 2;
   }

   int86x(0x26, &inregs, &outregs, &segregs);
   if (outregs.x.cflag == 1) {
	  printf("error writing drive H:\n");
      return 1;
   }

   return 0;
}
Technical Details
Message-ID: <2481@dsacg4.dsac.dla.mil>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!mailrus!uunet!tut.cis.ohio-state.edu!dsac.dla.mil!dsacg3.dsac.dla.mil!dsacg4.dsac.dla.mil!nol2321
References: <5181@munnari.oz.au> <6307@darkstar.ucsc.edu> <4306@duesling>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!mailrus!uunet!tut.cis.ohio-state.edu!dsac.dla.mil!dsacg3.dsac.dla.mil!dsacg4.dsac.dla.mil!nol2321
From: nol2321@dsacg4.dsac.dla.mil (Jim Dunn)
Newsgroups: comp.os.msdos.programmer
Subject: Re: Finding available drives (using Microsoft C)
Message-ID: <2481@dsacg4.dsac.dla.mil>
Date: 10 Sep 90 14:29:44 GMT
References: <5181@munnari.oz.au> <6307@darkstar.ucsc.edu> <4306@duesling>
Distribution: usa
Organization: Defense Logistics Agency Systems Automation Center, Columbus
Lines: 58