BBS: Inland Empire Archive Date: 04-24-92 (05:10) Number: 99 From: STEVE HALKO Refer#: NONE To: LOGAN ASHBY Recvd: NO Subj: # of disk drives 1/2 Conf: (2) Quik_Bas
LA> Ok, now that you've piqued our interest, let's see the code. :-) I LA>bet it's sitting right over there ( ---->> ) on your hard LA>drive, crying out to be posted. <grin> ( <F/X, small voice LA>heard from distance> post me ........post me .........post me LA>.........post me ..........) See, what did I tell you!!! <BIG grin> <G> Well actually, I already posted it. It was about a year ago. What?? You mean you missed it?? Okay, I guess I can post it again. Actually, I was hoping someone would have had enough interest to dig out Ralf Brown's Int List and figure it out - that's what I did, and it was very educational. A nice learning experience. I just LOVE rooting around in DOS's innards! Here it is: 'LOGDRIVE.BAS by Steve Halko '|
-| '| This program explores the use of undocumented DOS function 52h to| '| examine DOS's Logical Drive Table and extract some parameters | '| from it. Details are described in the LogicalDrives SUB | '|
-| DEFINT A-Z DECLARE SUB LogicalDrives () DECLARE FUNCTION Int2Hex$ (n&) '$INCLUDE: 'QB.BI' DIM SHARED inreg AS regtypex, outreg AS regtypex COLOR 14, 1 CLS CALL LogicalDrives END FUNCTION Int2Hex$ (n&) 'This function converts a word to a 4 character hex string Int2Hex = STRING$(4 - LEN(HEX$(n&)), "0") + HEX$(n&) END FUNCTION SUB LogicalDrives '
--' '| This subprogram determines the logical drives including those | '| created by the DOS commands SUBST and JOIN. The procedure uses | '| the undocumented DOS service call function 52H which returns a | '| pointer to the DOS List of Lists (also called the Configuration | '| Variable Table or CVT). For DOS versions 3, 4, and 5, offset | '| 16H of the CVT is a double word pointer to the Logical Drive | '| Table (LDT). The LDT contains one entry for each possible | '| logical drive in the system starting at drive A and continuing | '| to the drive letter specified by the LASTDRIVE= line in the | '| CONFIG.SYS file. With no LASTDRIVE line, the LDT contains the | '| default of 5 drives, A through E. The entire LDT is in one | '| contiguous memory location, that is the entry for each drive | '| follows the previous drive entry. In DOS version 3, each | '| drive entry is 81 bytes long. In DOS versions 4 and 5, each | '| drive entry is 88 bytes long. To find out which of these logical | '| drives listed in the LDT are valid, check offset 43H of the LDT | '| which is a word containing the Current Drive Status, as follows: | '| | '| 0000H - invalid drive | '| 1000H - SUBSTed unit | '| 2000H - JOINed unit | '| 4000H - local drive | '| 8000H - network drive | '| | '| This information is from the book, DOS Programmer's Reference, 2nd| '| Edition, from Que, and PC Magazine, August 1991. | '| | '| Steve Halko 6/1/91 | '|
-| 'First get the major DOS version inreg.ax = &H3000 CALL interruptx(&H21, inreg, outreg) MajorVersion = outreg.ax AND &HFF 'Now get into the CVT inreg.ax = &H5200 CALL interruptx(&H21, inreg, outreg) DEF SEG = outreg.es 'Segement of CVT CVTOffset = outreg.bx 'Offset of CVT 'Print # of physical drives and # of logical drives LOCATE 1, 2 PRINT "Number of physical drives = "; PEEK(CVTOffset + &H20) NrLogDrives = PEEK(CVTOffset + &H21) LOCATE 2, 2 PRINT "Number of Logical Drives = "; NrLogDrives 'Print heading for drive table LOCATE 4, 15 PRINT "Drive Type" LOCATE 5, 8 PRINT "------------------------" PRINT " Drive Network Local JOIN SUBST DPB Ptr Current Directory" PRINT " "; PRINT " " VIEW PRINT 8 TO 25 SELECT CASE MajorVersion 'For DOS Version 2 CASE 2 'LDT not introduced until DOS 3.0 PRINT PRINT "DOS Version 3.0 and above required." END 'For DOS Versions 3, 4, 5 CASE 3, 4, 5 'Get Segment/Offset of LDT LDTSeg = PEEK(outreg.bx + &H18) + 256& * PEEK(outreg.bx + &H19) LDTOffset = PEEK(outreg.bx + &H16) + 256& * PEEK(outreg.bx + &H17) DEF SEG = LDTSeg IF MajorVersion = 3 THEN SizeOfLDT = 81 ELSE SizeOfLDT = 88 'LDT is 7 bytes larger in DOS 4, 5 END IF 'Step through LDT FOR i = 0 TO NrLogDrives - 1 TableOffset = LDTOffset + i * SizeOfLDT 'Print drive letter LOCATE 8 + i, 4 PRINT CHR$(i + 65); 'Check flag at offset &H44 (Current Drive Status) flag = PEEK(TableOffset + &H44) IF flag AND &H80 THEN 'If network drive LOCATE 8 + i, 11 PRINT "X"; END IF IF flag AND &H40 THEN 'If local drive LOCATE 8 + i, 18 PRINT "X"; END IF >>> Continued to next message * SLMR 2.1a * More bass at all frequencies, man! --- DB B1065/002487
Books at Amazon:
Back to BASIC: The History, Corruption, and Future of the Language
Hackers: Heroes of the Computer Revolution (including Tiny BASIC)
Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution
The Advent of the Algorithm: The Idea that Rules the World
Moths in the Machine: The Power and Perils of Programming
Mastering Visual Basic .NET