Advanced Search
Apple Developer Connection
Member Login Log In | Not a Member? Contact ADC

Previous Book Contents Book Index Next

Inside Macintosh: Files /
Chapter 2 - File Manager / Data Organization in Memory


The Drive Queue

The File Manager maintains a list of all disk drives connected to the computer. It maintains this list in the drive queue, which is a standard operating system queue. The drive queue is initially created at system startup time. Elements are added to the queue at system startup time or when you call the AddDrive procedure. The drive queue can support any number of drives, limited only by memory space. Each element in the drive queue contains information about the corresponding drive; the structure of a drive queue element is defined by the DrvQEl data type.

TYPE DrvQEl =
RECORD
   qLink:         QElemPtr;   {next queue entry}
   qType:         Integer;    {flag for dQDrvSz and dQDrvSz2}
   dQDrive:       Integer;    {drive number}
   dQRefNum:      Integer;    {driver reference number}
   dQFSID:        Integer;    {file-system identifier}
   dQDrvSz:       Integer;    {number of logical blocks on drive}
   dQDrvSz2:      Integer;    {additional field for large drives}
END;
Field Description
qLink
A pointer to the next entry in the drive queue.
qType
Used to specify the size of the drive. If the value of qType is 0,
the number of logical blocks on the drive is contained in the dQDrvSz field alone. If the value of qType is 1, both dQDrvSz
and dQDrvSz2 are used to store the number of blocks; in that case, dQDrvSz2 contains the high-order word of this number
and dQDrvSz contains the low-order word.
dQDrive
The drive number of the drive.
dQRefNum
The driver reference number of the driver controlling the device on which the volume is mounted.
dQFSID
An identifier for the file system handling the volume in the drive; it's zero for volumes handled by the File Manager and nonzero for volumes handled by other file systems.
dQDrvSz
The number of logical blocks on the drive.
dQDrvSz2
An additional field to handle large drives. This field is used only if the qType field contains 1.
The File Manager also maintains four flag bytes preceding each drive queue element. These bytes contain the following information:
ByteContents
0Bit 7=1 if the volume on the drive is locked
10 if no disk in drive; 1 or 2 if disk in drive; 8 if nonejectable disk in drive; $FC-$FF if disk was ejected within last 1.5 seconds; $48 if disk in drive is nonejectable but driver wants a call
2Used internally during system startup
3Bit 7=0 if disk is single-sided

You can read these flags by subtracting 4 bytes from the beginning of a drive queue element, as illustrated in Listing 2-11.

Listing 2-11 Reading a drive queue element's flag bytes

FUNCTION GetDriveFlags (myDQElemPtr: DrvQElPtr): LongInt;
TYPE
   FlagPtr = ^LongInt;  {pointer to the queue element flag bytes}
VAR
   myQFlagsPtr:   FlagPtr;
BEGIN
   {Just subtract 4 from the queue element pointer.}
   myQFlagsPtr := FlagPtr(ORD4(myDQElemPtr) - 4);
   GetDriveFlags := myQFlagsPtr^;
END;
The GetDriveFlags function defined Listing 2-11 takes a pointer to a drive queue element as a parameter. You can get a queue element pointer for a particular volume by walking the drive queue until you find a queue element whose dQDrive field contains the same value as the vcbDrvNum field of that volume's VCB. You can get a pointer to the header of the drive queue by calling the File Manager function GetDrvQHdr.

Note that the bit numbers given in this section use the standard MC68000 numbering scheme; to access the correct bit using some Pascal routines, you must reverse that numbering. For example, if you use the Toolbox BitTst routine to determine whether a particular disk is single-sided, you must test bit 24 (that is, 31 minus 7) of the returned long integer. If you use the built-in Pascal function BTST, however, you can test the indicated bit directly.

Assembly-Language Note
The global variable DrvQHdr contains the header of the drive queue.

Previous Book Contents Book Index Next

© Apple Computer, Inc.
2 JUL 1996

Get information on Apple products.
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Copyright © 2004 Apple Computer, Inc.
All rights reserved. | Terms of use | Privacy Notice