File System Specifications

FAT32 is a derivative of the FAT file system that supports drives over 2GB. Because FAT32 drives can contain more than 65,526 clusters, smaller clusters are used than on large FAT16 drives, resulting in more efficient allocation of space on the drive.

The 32-bit FAT includes four bytes per cluster within the File Allocation Table. This differs from FAT16 and FAT12 in that those files systems contain 2 bytes and 1.5 bytes within the File Allocation Table, respectively.

Note that the high 4 bits of the 32-bit values in the FAT32 File Allocation Table are reserved and are not part of the cluster number. Therefore, applications which directly read a FAT32 File Allocation Table must mask off these bits, and preserve them when writing new values.

File System Cluster Limits:

System	Cluster Limit
FAT12	Less than 4086 clusters
FAT16	Between 4096 and 65526 clusters
FAT32	Greater than 65526 clusters.


Boot Sector and Bootstrap Modifications

Reserved Sectors

FAT32 drives contain more reserved sectors than FAT16 or FAT12 drives. The number of reserved sectors is usually 32, but can vary.

Boot Sector Modifications

Since a FAT32 BIOS Parameter Block (BPB) is larger than a standard BPB., the boot record on FAT32 drives is greater than 1 sector.

Also, there is a sector in the reserved area on FAT32 drives that contains values for the count of free clusters and the cluster number of the most recently allocated cluster. These values are members of the BIGFATBOOTFSINFO structure which is contained within this sector. These additional fields allow the system to initialize the values without having to read the entire File Allocation Table.

Root Directory

The root directory on a FAT32 drive is not stored in a fixed location as it is on FAT16 and FAT12 drives. On FAT32 drives, the root directory is an ordinary cluster chain. The A_BF_BPB_RootDirStrtClus field in the BPB contains the number of the first cluster in the root directory. This allows the root directory to grow as needed. In addition, the BPB_RootEntries field of the BPB is ignored on a FAT32 drive. As a result, the size of the "old" root directory (after the last FAT) is zero clusters.

Sectors Per FAT

The A_BF_BPB_SectorsPerFAT field in the BPB is always zero on a FAT32 drive


FAT Mirroring

On all FAT drives, there may be multiple copies of the FAT. If an error occurs reading the primary copy, the file system will attempt to read from the backup copies. On FAT16 and FAT12 drives, the first FAT is always the primary copy and a modification will automatically be written to all copies. However, on FAT32 drives, FAT mirroring can be disabled, and a FAT other than the first one can be the primary (or "active") copy of the FAT.

Mirroring is enabled by clearing bit 0x0080 in the extdpb_flags field of a FAT32 Drive Parameter Block (DPB).

When Enabled (bit 0x0080 clear) :

Whenever a File Allocation Table sector is written, it will also be written to every other FAT.

Also, with mirroring enabled, a FAT sector can be read from any FAT.

A FAT32 drive with multiple FATs will behave the same as FAT16 and FAT12 drives with multiple FATs. That is, the multiple FATs are backups of each other.

When Disabled (bit 0x0080 set)

Only one of the File Allocation Tables is active. This is the one specified by bits 0 through 3 of the extdpb_flags field of the DPB. The other FATs are ignored.

This allows better handling of a drive with a bad sector in one of the FATs. If a bad sector exists, access to the damaged FAT can be completely disabled. Then, a new FAT can be built in one of the inactive FATs and then made accessible by changing the active FAT value in the extdpb_flags field.


Partition Types

The following are all valid partition types and their corresponding values for use in the Part_FileSystem field of the s_partition structure.

Partition Types

Value	Description
PART_UNKNOWN(00h)	Unknown
PART_DOS2_FAT(01h)	12-bit FAT. Partition smaller than 10MB.
PART_DOS3_FAT(04h)	16-bit FAT. Partition smaller that 32MB.
PART_EXTENDED(05h)	Extended MS-DOS Partition.
PART_DOS4_FAT(06h)	16-bit FAT. Partition larger than or equal to 32MB.
PART_DOS32(0Bh)	32-bit FAT. Partition up to 2047GB.
PART_DOS32X(0Ch)	Same as 0Bh, but uses Logical Block Address Int 13h extensions.
PART_DOSX13(0Eh)	Same as 06h, but uses Logical Block Address Int 13h extensions.
PART_DOSX13X(0Fh)	Same as 05h, but uses Logical Block Address Int 13h extensions.


Reference Overview

This section provides information about the following functions and structures, which are new to MS-DOS 7.1 and Windows 95 (build 950b) and later..

Interrupt 21h Functions

Get_ExtDPB	Function 7302h
Get_ExtFreeSpace	Function 7303h
Set_DPBForFormat	Function 7304h
Set_DPBForFormat Sub-functions:	SetDPB_SetAllocInfo
	SetDPB_SetDPBFrmBPB
	SetDPB_ForceMediaChng
	SetDPB_GetSetActFATandMirr
	SetDPB_GetSetRootDirClus
Ext_ABSDiskReadWrite	Function 7305h
Set Device Parameters	Function 440Dh Minor Code 40h
Write Track on Logical Drive	Function 440Dh Minor Code 41h
Format Track on Logical Drive	Function 440Dh Minor Code 42h
Set Media ID	Function 440Dh Minor Code 46h
Set Access Flag	Function 440Dh Minor Code 47h
Lock/Unlock Removable Media	Function 440Dh Minor Code 48h
Eject Removable Media	Function 440Dh Minor Code 49h
Get Device Parameters	Function 440Dh Minor Code 60h
Read Track on Logical Drive	Function 440Dh Minor Code 61h
Verify Track on Logical Drive	Function 440Dh Minor Code 62h
Get Media ID	Function 440Dh Minor Code 66h
Get Access Flag	Function 440Dh Minor Code 67h
Sense Media Type	Function 440Dh Minor Code 68h
Get Drive Map Info	Function 440Dh Minor Code 6Fh
Get First Cluster	Function 440Dh Minor Code 71h
Extended Open	Function 6Ch
Additionally, the FAT32 file system introduces some limitations to other existing functions.

Superseded Functions
Get Default DPB	Interrupt 21h Function 1Fh
Get DPB	Interrupt 21h Function 32h
Get Disk Free Space	Interrupt 21h Function 36h
Absolute Disk Read/Write	Interrupts 25h/26h
New Structures

Overview of new structures

FAT32 BIOS Parameter Block (BPB)

BIGFATBOOTFSINFO

Drive Parameter Block (DPB)

EA_DEVICEPARAMETERS

ExtGetDskFreSpcStruc

s_partition

SDPDFormatStruc


Int 21h Function 7302h Get_ExtDPB

Buffer   dw  ?

DriveDPB DPB <>

BufferSize equ sizeof DPB + sizeof WORD

...

mov  dx, seg Buffer

mov  es, dx

mov  di, offset Buffer  ;See Below

mov  dl, DriveNum       ;See Below

mov  cx, BufferSize     ;See Below.

mov  ax, 7302h          ;Get_ExtDPB

int  21h

jc  error_handler       ;carry set means error

Returns a copy of the extended Drive Parameter Block (DPB) for any valid drive.

•	Clears the carry flag, and returns a copy of the DPB to ES:DI. The copy is a WORD equal to the size (in bytes) of the extended DPB, followed by the extended DPB itself (see EA_DEVICEPARAMETERS).

DriveNum

The 1-based drive number (0=default; 1=A, 2=B, etc.).

Buffer

The address of the buffer at ES:DI to receive the WORD (the size value) followed by the copy of the extended DPB.

BufferSize

The size of the buffer, in bytes.

The size value returned by this function represents the size of the DPB only. It does not include the two bytes of the size field itself.

This call will not work when the VDEF file system is mounted on the drive (e.g. during formatting).


Int 21h Function 7303h Get_ExtFreeSpace

mov  dx, seg Buffer

mov  es, dx

mov  di, offset Buffer    ;See Below

mov  es:[di].ExtGetDskFreSpcStruc.ExtFree_Level, ExpectLevel

mov  cx, BufferSize       ;See Below

mov  dx, seg DriveName    ;See Below

mov  ds, dx

mov  dx, offset DriveName ;See Below.

mov  ax, 7303h            ;Get_ExtFreeSpace

int  21h

jc  error_handler         ;carry set means error

Returns the total and free disk space.

•	Clears the carry flag and returns the total and free disk space of the specified drive, in the form of an ExtGetDskFreSpcStruc structure, to a buffer at ES:DI. This buffer should be initialized to the level value the application expects to receive.

Buffer

The address of the buffer at ES:DI to receive the disk space information

BufferSize

The size (in bytes) of the buffer.

DriveName

The address of a null terminated string at DS:DX. In real mode, this must be in standard form ("C:\"). In Windows, either the standard name or a universal naming convention form ("\\Server\Share") is acceptable.


Int 21h Function 7304h Set_DPBForFormat

mov  dx, seg Buffer

mov  es, dx

mov  di, offset Buffer   ;See Below

mov  es:[di].SDPDFormatStruc.SetDPB_Level, ExpectLevel   ;See Below

mov  ax, word ptr Value1 ; initialize SDPDFormatStruc values.

                         ; See specific sub-function for details.

mov  word ptr es:[di].SDPDFormatStruc.SetDPB_Value1, ax

mov  ax, word ptr Value1 + 2

mov  word ptr es:[di].SDPDFormatStruc.SetDPB_Value1+2, ax

mov  ax, word ptr SubFunction

mov  word ptr es:[di].SDPDFormatStruc.SetDPB_Function, ax

mov  word ptr es:[di].SDPDFormatStruc.SetDPB_Function+2, 0

mov  dl, DriveNum       ;See Below

mov  cx, BufferSize     ;See Below

mov  ax, 7304h          ;Set_DPBForFormat

int 21h

Implements a sub-function to perform DPB operations.

•	There are five sub-functions that can be implemented. The buffer at ES:DI should contain a SDPDFormatStruc structure. The value in the DWORD field, SetDPB_Function, determines which sub-function is called.

Buffer

The address of a buffer containing a SDPDFormatStruc structure at ES:DI.

ExpectLevel

The expected return level value. This should be 0.

BufferSize

The size of the buffer, in bytes.

DriveNum

The 1-based drive number (0=default; 1=A, 2=B, etc.).

Selecting a Sub-Function:

The value in the SetDPB_Function field of the SDPDFormatStruc structure determines which sub-function is implemented.

0	SetDPB_SetAllocInfo
1	SetDPB_SetDPBFrmBPB
2	SetDPB_ForceMediaChng
3	SetDPB_GetSetActFATandMirr
4	SetDPB_GetSetRootDirClus
It is important to be aware of the state of the file system when using this call. If sectors of the drive are cached, or if there are files open, the function may produce unexpected results. To avoid this, ensure that the application closes all files and calls DiskReset to flush and invalidate any caches.

The SDPDFormatStruc also contains four ULONG fields: SetDPB_Value1, SetDPB_Value2, SetDPB_Value3, and SetDPB_Value4. These should be set appropriately according to the requirements for each of the sub-functions.


SetDPB_SetAllocInfo

This sub-function is called when the SetDPB_Function field of the SDPDFormatStruc structure is set to 0.

The assembler calling sequence for all Int 21h 7304h sub-functions is virtually identical. See the main listing for a sample. (Int 21h Function 7304h Set_DPBForFormat)

Sets the dpb_free_cnt and dpb_next_free fields in the DPB.

•	Clears the carry flag and sets the dpb_free_cnt and dpb_next_free fields in the DPB based upon the values in the SetDPB_Value1 and SetDPB_Value2 fields within the Set_DPB_ForFormat structure.

SetDPB_Value1 Setting 	Result within DPB

0 	No changes made to dpb_free_cnt field

0xFFFFFFFF 	dpb_free_cnt set to unknown.

(any other value) 	If a valid cluster count for the drive, sets dpb_free_cnt to the specified value.

The free cluster count cannot be explicitly set to zero by this call. This can only be done by setting SetDPB_Value1 to 0xFFFFFFFF, which forces the free space to be re-computed. Also, setting this value improperly will cause the free count value to be reported improperly by GetDiskFreeSpace. Therefore, the settings of 0 or 0xFFFFFFFF are recommended.

SetDPB_Value2 Setting	Result within DPB

0	No changes made to dpb_next_free field.

0xFFFFFFFF	dpb_next_free set to force cluster search to begin at the beginning of the FAT.

(any other value)	If a valid cluster number for the drive, sets dpb_next_free to the given value. This causes the search for free clusters to begin at the specified cluster.


SetDPB_SetDPBFrmBPB

This sub-function is called when the SetDPB_Function field of the SDPDFormatStruc structure is set to 1.

The assembler calling sequence for all Int 21h 7304h sub-functions is virtually identical. See the main listing for a sample. (Int 21h Function 7304h Set_DPBForFormat)

Rebuilds the file system drive DPB from a passed-in BPB.

•	The SetDPB_Value2 setting in the SDPDFormatStruc is a DWORD pointer to the BPB.

The BPB that is pointed to by SetDPB_Value2 can be in original or FAT32 format

The drive parameters are often held inside the device driver for the drive as well. As a result, this call should always be accompanied by a call to Int 21h Function 440Dh Minor Code 40h Set Device Parameters


SetDPB_ForceMediaChng

This sub-function is called when the SetDPB_Function field of the SDPDFormatStruc structure is set to 2.

The assembler calling sequence for all Int 21h 7304h sub-functions is virtually identical. See the main listing for a sample. (Int 21h Function 7304h Set_DPBForFormat)

•	Sets a flag which causes the next MS-DOS access to the drive to call the BUILD_DPD routine in the drive's device driver.

This is similar to the SetDPB_SetDPBFrmBPB call, except that the BPB is obtained from the device driver instead of a passed-in parameter.

The function does not take effect on this call. Rather, it takes effect upon the next access to the drive. Therefore, users should immediately follow this with some other Int 21h call to the drive (e.g. Int 21h Function 7303h Get_ExtFreeSpace).

As a side effect of this call, the next access to the drive also causes dpb_next_free (or extdpb_next_free) to be reset to 2, and the dpb_free_cnt to be reset to 0xFFFFFFFF.


SetDPB_GetSetActFATandMirr

This sub-function is called when the SetDPB_Function field of the SDPDFormatStruc structure is set to 3.

The assembler calling sequence for all Int 21h 7304h sub-functions is virtually identical. See the main listing for a sample. (Int 21h Function 7304h Set_DPBForFormat)

Allows the active FAT and FAT mirror properties of a FAT32 drive to be read and changed. This call is invalid on FAT12 and FAT16 drives.

•	If unsuccessful, the carry flag is set and ERROR_GEN_FAILURE (error code 31) is returned to AX. This indicates that a disk error occurred during the attempt to write. In this case, the DPB mirror property is changed, but not properly written to disk. If this occurs, the caller should re-write the value returned to SetDBP_Value2 to attempt to undo the change.

SetDPB_Value1

The SetDPB_Value1 field in the SPDPFormatStruc structure determines the SET behavior. If this is set to 0xFFFFFFFF, then no changes are made and the ActiveFat and FAT mirror property are returned to SetDPB_Value2.

Failure Conditions:

The low four bits of this value are the zero-based ActiveFAT number. If the ActiveFAT number is greater than or equal to the number of FATs on the drive, the call will fail.

Bit 0x00000080 is the "Disable FAT Mirror" bit. If any bits other than 0x80 and the low four bits are set, the call will fail.

If the FAT Mirror is enabled (bit 0x80 clear) and the ActiveFAT value specified in SetDPB_Value1 is not zero, the call will fail.

SetDPB_Value2

Used as a return field for the previous ActiveFAT and FAT mirror properties. Bits 0 - 3 indicate the active FAT number, bit 7 indicates the mirror state, and all other bits are reserved. If SetDPB_Value1 is 0xFFFFFFFF, the previous state is also the current state.

Bit 7	Description
Set	Enable FAT Mirroring
Clear	Disable FAT Mirroring
Side Effects of Set Form:

The BPB(s) and boot sector(s) of the drive are also written. This is because the ActiveFAT and FAT mirror properties are also stored in the BPB.

If the FAT Mirror is being enabled (i.e. the current state has bit 0x80 set, and SetDPB_Value1 has bit 0x80 clear) this call will copy the active FAT sectors to all of the other FATs. This process can be very slow.

Note that the device driver may also contain these values as part of its current device parameters. This call will have no effect on the FAT Mirror properties held by the device driver. As a result, the set form of the call should be immediately followed by a SetDeviceParameters Generic IOCTL to set the current BPB that the BuildBPB routine of the device returns.

Next Free DPB variable is reset to 2, and the Free Count DPB is reset to 0xFFFFFFFF.


SetDPB_GetSetRootDirClus

This sub-function is called when the SetDPB_Function field of the SDPDFormatStruc structure is set to 4.

The assembler calling sequence for all Int 21h 7304h sub-functions is virtually identical. See the main listing for a sample. (Int 21h Function 7304h Set_DPBForFormat)

Allows the first cluster of the root directory of a FAT32 drive to be read and changed. This call is invalid on FAT12 and FAT16 drives.

•	If unsuccessful, carry flag is set and ERROR_GEN_FAILURE (error code 31) is returned to AX. This indicates that a disk error occurred during the attempt to write. In this case, the DPB root directory property is changed, but not properly written to disk. If this occurs, the caller should re-write the value returned to SetDBP_Value2 to attempt to undo the change.

Since the start cluster of the root directory is also stored in the BPB(s) in the boot sector(s) of the drive, this call re-writes these boot sector(s) as a side effect.

Note that the device driver may also contain these values as part of its current device parameters. This call will have no effect on the FAT Mirror properties held by the device driver. Because of this, the set form of the call should be immediately followed by a SetDeviceParameters Generic IOCTL to set the current BPB that the BuildBPB routine of the device returns.

SetDPB_Value1

This field in the SPDPFormatStruc specifies the SET behavior. If the value is 0xFFFFFFFF, then no changes are made and the current root directory first cluster number is returned in SetDPB_Value2.

The value is range checked. It must be >=2 and <= to the maximum valid cluster number for the drive.

SetDPB_Value2

This field in the SPDPFormatStruc is used as a return field where the previous root directory first cluster is held. When SetDPB_Value1 is 0xFFFFFFFF, the previous cluster is also the current root directory cluster.


Int 21h Function 7305h Ext_ABSDiskReadWrite

mov  si, 6001h          ;write normal file data. SI=0 for read

                        ;see below for additional write values

mov  cx, -1             ;cx must be -1

mov  dx, seg Buffer

mov  ds, dx

mov  bx, offset Buffer  ;See Below

mov  dl, DriveNum       ;See Below

mov  ax, 7305h          ;Ext_ABSDiskReadWrite

int 21h

jc  error_handler       ;carry set means error

Allows "raw" disk read/write to FAT32, FAT16, and FAT12 drives. This call replaces Int 25h/26h.

•	Clears the carry flag when successful. Otherwise, the carry flag is set, and AX is set with the error code as it is documented for Int 25h/26h.

Buffer

Points to a DISKIO structure that contains the starting sector count of sectors, and address of the buffer to receive the data. The structure should be initialized according to Int 25h/26h documentation. The DISKIO structure has the following form:

DISKIO  STRUC

    diStartSector   dd  ?   ;sector number to start

    diSectors       dw  ?   ;number of sectors

    diBuffer        dd  ?   ;address of buffer

DISKIO  ENDS

DriveNum

The 1-based drive number (0=default; 1=A, 2=B, etc.).

This function operates the same as Int 25h/26h, with the following exceptions:

CX must = -1 (only the 32-bit starting sector number form is allowed).

The drive number is 1-based (0 = default drive) and is specified in DL instead of AL.

This call does not leave a flags word on the stack like Interrupts 25h and 26h.

This call modifies only the AX register and the flags.

Bit 0 of SI specifies whether the call is to do a READ (INT 0x25) or a WRITE (INT 0x26):

Read and Write Modes:

SI bit 0 clear	READ
SI bit 0 set	WRITE
In Write Mode:

When bit 0 of SI is set (i.e. WRITE mode), bits 13, 14 and 15 of SI categorize what type of data is being written:

15	14	13	Description
0	0	0	Other/Unknown
0	0	1	FAT data
0	1	0	Directory Data
0	1	1	Normal File Data
1	x	x	Reserved. Bit 15 must be 0.
All other bits of SI (1 through 12) are reserved and must be 0.

This info provides information to apps (like compression drivers) so that they can manage the data write properly. For example, many compression drivers won't compress directory data.

Warnings:

Do not set these flags in an attempt to get a compression driver to write data uncompressed on a compressed drive. Compression drivers are not the only things that will make use of these flags.

Do not set the flags improperly, this information is ONLY supposed to be used to indicate what "type" the data is.


IOCTL Function Update Overview

All IOCTL functions have been modified to accept a new device category value (CH = 48h) for FAT32 drives. Both the 08h and 48h forms of each function accept identical parameters, with the exception of the following two functions.

Set Device Parameters	Function 440Dh Minor Code 40h
Get Device Parameters	Function 440Dh Minor Code 60h
The above two functions accept slightly different parameters than their 08h counterparts. The 48h forms accept a pointer to pointer to an EA_DEVICEPARAMETERS structure (instead of DEVICEPARAMS).

The DeviceCat variable, which calling code specifies in CH, now supports a new value, 48h, for use on FAT32 drives (the 48h form generally works on FAT16 and FAT12 media as well):

Value	Description

08h 	FAT16 or FAT12 drive.

48h 	FAT32, FAT16 or FAT12 drive.

In some cases, the two forms of the call (48h and 08h) are interchangeable. However, this is not universal. As a result, applications that make the 48h form of the function must be prepared to fall back on the 08h form in case of failure. Please refer to each specific function for information regarding these values.

IOCTL Functions

Set Device Parameters	Function 440Dh Minor Code 40h
Write Track on Logical Drive	Function 440Dh Minor Code 41h
Format Track on Logical Drive	Function 440Dh Minor Code 42h
Set Media ID	Function 440Dh Minor Code 46h
Set Access Flag	Function 440Dh Minor Code 47h
Lock/Unlock Removable Media	Function 440Dh Minor Code 48h
Eject Removable Media	Function 440Dh Minor Code 49h
Get Device Parameters	Function 440Dh Minor Code 60h
Read Track on Logical Drive	Function 440Dh Minor Code 61h
Verify Track on Logical Drive	Function 440Dh Minor Code 62h
Get Media ID	Function 440Dh Minor Code 66h
Get Access Flag	Function 440Dh Minor Code 67h
Sense Media Type	Function 440Dh Minor Code 68h
Get Drive Map Info	Function 440Dh Minor Code 6Fh
Get First Cluster	Function 440Dh Minor Code 71h


Int 21h Function 440Dh Minor Code 40h Set Device Parameters

mov  bx, Drive           ;0 = default, 1 = A, 2 = B, etc.

mov  ch, DeviceCat       ;See Below

mov  cl, 40h             ;Set Device Parameters

mov  dx, seg DriveDP

mov  ds, dx

mov  dx, offset DriveDP  ;ds:dx points to a device parameters structure

mov  ax, 440Dh           ;IOCTL for Block Device

int  21h

jc  error_handler       ;carry set means error

Set Device Parameters (Function 440Dh Minor Code 40h) sets the device parameters for the specified block device.

•	If the function is successful, the carry flag is clear. Otherwise, the carry flag is set and the AX register contains an error value, which may be one of the following:

Value 	Name

0001h 	ERROR_INVALID_FUNCTION

0002h 	ERROR_FILE_NOT_FOUND

0005h 	ERROR_ACCESS_DENIED

Set Device Parameters returns 0002h (ERROR_FILE_NOT_FOUND) if the specified drive number is invalid.

If the number of sectors specified in the applicable device parameters structure is not zero, a TRACKLAYOUT structure, specifying the size of each sector, must follow the device parameters structure.

The device parameters structure is a DEVICEPARAMS structure in the case of a FAT16 or FAT12 drive. For FAT32 drives, this is an EA_DEVICEPARAMETERS structure.

Drive

Specifies the drive that parameters are being set for (0 = default drive, 1 = A, 2 = B, etc.).

DeviceCat

Specifies the expected format of device parameters information structure.

Value	Expected Device Parameters Structure
08h	DEVICEPARAMS (FAT16 or FAT12 drive. Will fail on FAT32 drives.)
48h	EA_DEVICEPARAMETERS (FAT32, FAT16 or FAT12.)
Please note: Because this call may be implemented in the device driver, the 48h form of this call may fail on FAT16 or FAT12 media. Therefore, applications making the 48h form of this call must fall back on the 08h form if the 48h call fails.

DriveDP

Points to the applicable device parameters structure that contains the parameters for the specified block device. The format of the expected device parameters is indicated in the above DeviceCat field.


Int 21h Function 440Dh Minor Code 41h Write Track on Logical Drive

mov     bx, Drive               ;0 = default, 1 = A, 2 = B, etc.

mov     ch, DeviceCat           ;See Below

mov     cl, 41h                 ;Write Track on Logical Drive

mov     dx, seg WriteBlock

mov     ds, dx

mov     dx, offset WriteBlock   ;ds:dx points to RWBLOCK structure

mov     ax, 440Dh               ;IOCTL for Block Device

int     21h

jc      error_handler           ;carry set means error

Write Track on Logical Drive (Function 440Dh Minor Code 41h) writes data from a buffer to a track on the specified device.

•	If the function is successful, the carry flag is clear. Otherwise, the carry flag is set and the AX register contains an error value, which may be one of the following:

Value 	Name

0001h 	ERROR_INVALID_FUNCTION

0002h 	ERROR_FILE_NOT_FOUND

0005h 	ERROR_ACCESS_DENIED

Write Track on Logical Drive returns 0002h (ERROR_FILE_NOT_FOUND) if the specified drive number is invalid.

Drive

Specifies the drive information is to be written to (0 = default drive, 1 = A, 2 = B, etc.).

DeviceCat

Specifies a FAT16, FAT12 or FAT32 drive.

Value	Description

08h 	FAT16 or FAT12 drive. (Will fail on FAT32 drives.)

48h 	FAT32, FAT16, or FAT12 drive.

Please note: Because this call may be implemented in the device driver, the 48h form of this call may fail on FAT16 or FAT12 media. Therefore, applications making the 48h form of this call must fall back on the 08h form if the 48h call fails.

WriteBlock

Points to an RWBLOCK structure that contains information that specifies the sectors to be written to. The rwBuffer field must contain the address of the buffer that contains the data to write to the disk. The RWBLOCK structure has the following form:

RWBLOCK STRUC

    rwSpecFunc      db  0  ;special functions (must be zero)

    rwHead          dw  ?  ;head to read/write

    rwCylinder      dw  ?  ;cylinder to read/write

    rwFirstSector   dw  ?  ;first sector to read/write

    rwSectors       dw  ?  ;number of sectors to read/write

    rwBuffer        dd  ?  ;address of buffer for read/write data

RWBLOCK ENDS


Int 21h Function 440Dh Minor Code 42h Format Track on Logical Drive

mov     bx, Drive                 ;0 = default, 1 = A, 2 = B, etc.

mov     ch, DeviceCat             ;See Below

mov     cl, 42h                   ;Format Track on Logical Drive

mov     dx, seg FormatBlock

mov     ds, dx

mov     dx, offset FormatBlock    ;ds:dx points to FVBLOCK structure

mov     ax, 440Dh                 ;IOCTL for Block Device

int     21h

jc      error_handler             ;carry set means error

Format Track on Logical Drive (Function 440Dh Minor Code 42h) formats and verifies a track on the specified device.

•	If the fvSpecFunc field in the FVBLOCK structure is 1, the carry flag is clear and the fvSpecFunc field is set to one of the following values:

Value 	Meaning

0 	ROM support for given format combination

1 	No ROM support

2 	Illegal format combination

3 	No media present

If the fvSpecFunc field is 0 and the function is successful, the carry flag is clear. Otherwise, the carry flag is set and the AX register contains an error value, which may be one of the following:

Value 	Name

0001h 	ERROR_INVALID_FUNCTION

0002h 	ERROR_FILE_NOT_FOUND

0005h 	ERROR_ACCESS_DENIED

Format Track on Logical Drive returns 0002h (ERROR_FILE_NOT_FOUND) if the specified drive number is invalid.

Drive

Specifies the drive on which the track is to be formatted and verified (0 = default drive, 1 = A, 2 = B, etc.).

DeviceCat

Specifies a FAT16, FAT12 or FAT32 drive.

Value	Description

08h 	FAT16 or FAT12 drive. (Will fail on FAT32 drives.)

48h 	FAT32, FAT16, or FAT12 drive.

Please note: Because this call may be implemented in the device driver, the 48h form of this call may fail on FAT16 or FAT12 media. Therefore, applications making the 48h form of this call must fall back on the 08h form if the 48h call fails.

FormatBlock

Points to an FVBLOCK structure that specifies the head and cylinder to format. The FVBLOCK structure has the following form:

FVBLOCK STRUC

    fvSpecFunc    db  0   ;special functions

    fvHead        dw  ?   ;head to format/verify

    fvCylinder    dw  ?   ;cylinder to format/verify

    fvTracks      dw  ?   ;tracks to format/verify

FVBLOCK ENDS

The fvSpecFunc field can be 0, 1, or 2. The fvTracks field is ignored.


Int 21h Function 440Dh Minor Code 46h Set Media ID

mov     bx, Drive               ;0 = default, 1 = A, 2 = B, etc.

mov     ch, DeviceCat           ;See Below

mov     cl, 46h                 ;Set Media ID

mov     dx, seg MediaID

mov     ds, dx

mov     dx, offset MediaID      ;ds:dx points to MID structure

mov     ax, 440Dh               ;IOCTL for Block  Device

int     21h

jc      error_handler           ;carry set means error

Set Media ID (Function 440Dh Minor Code 46h) sets the volume label, serial number, and file system for the specified drive.

•	If the function is successful, the carry flag is clear. Otherwise, the carry flag is set and the AX register contains an error value, which may be one of the following:

Value 	Name

0001h 	ERROR_INVALID_FUNCTION

0002h 	ERROR_FILE_NOT_FOUND

0005h 	ERROR_ACCESS_DENIED

This function returns 0002h (ERROR_FILE_NOT_FOUND) if the specified drive number is invalid.

Drive

Specifies the drive for which identification is to be set (0 = default drive, 1 = A, 2 = B, etc.).

DeviceCat

Specifies a FAT16, FAT12 or FAT32 drive.

Value	Description

08h 	FAT16 or FAT12 drive. (Will fail on FAT32 drives.)

48h 	FAT32, FAT16, or FAT12 drive.

Please note: Because this call may be implemented in the device driver, the 48h form of this call may fail on FAT16 or FAT12 media. Therefore, applications making the 48h form of this call must fall back on the 08h form if the 48h call fails.

MediaID

Points to a MID structure that contains information that uniquely identifies a disk or other storage medium. The MID structure has the following form:

MID STRUC

    midInfoLevel   dw  0           ;information level

    midSerialNum   dd  ?           ;serial number

    midVolLabel    db  11 dup (?)  ;ASCII volume label

    midFileSysType db  8 dup (?)   ;file system type

MID ENDS


Int 21h Function 440Dh Minor Code 47h Set Access Flag

mov     bx, Drive               ;0 = default, 1 = A, 2 = B, etc.

mov     ch, DeviceCat           ;See Below

mov     cl, 47h                 ;Set Access Flag

mov     dx, seg SpecialFunc

mov     ds, dx

mov     dx, offset SpecialFunc  ;ds:dx points to SPECIALFUNC structure

mov     ax, 440Dh               ;IOCTL for Block Device

int     21h

jc      error_handler           ;carry set means error

Set Access Flag (Function 440Dh Minor Code 47h) sets the access flag for the specified drive.

•	If the function is successful, the carry flag is clear. Otherwise the carry flag is set, and the AX register contains an error value, which may be one of the following:

Value 	Name

0001h 	ERROR_INVALID_FUNCTION

0002h 	ERROR_FILE_NOT_FOUND

0005h 	ERROR_ACCESS_DENIED

This function returns 0002h (ERROR_FILE_NOT_FOUND) if the specified drive number is invalid.

Drive

Specifies the drive for which the access flag is to be set (0 = default drive, 1 = A, 2 = B, etc.).

DeviceCat

Specifies a FAT16, FAT12 or FAT32 drive.

Value	Description

08h 	FAT16 or FAT12 drive. (Will fail on FAT32 drives.)

48h 	FAT32, FAT16, or FAT12 drive.

Please note: Because this call may be implemented in the device driver, the 48h form of this call may fail on FAT16 or FAT12 media. Therefore, applications making the 48h form of this call must fall back on the 08h form if the 48h call fails.

SpecialFunc

Points to a SPECIALFUNC structure that contains information that specifies the state of the access flag. The SPECIALFUNC structure has the following form:

SPECIALFUNC STRUC

    sfFunction  db  0   ;special function (must be 0)

    sfAccessFlg db  ?   ;access flag, 0 if access blocked

                        ;"unformatted"

SPECIALFUNC ENDS


Int 21h Function 440Dh Minor Code 48h Lock/Unlock Removable Media

mov ax, 440Dh           ; Generic IOCTL

mov bx, DriveNum        ; See Below

mov ch, DeviceCat       ; See Below

mov cl, 48h             ; Lock or Unlock Removable Media

mov dx, seg ParamBlock  ; See Below

mov ds, dx

mov dx, offset ParamBlock

int 21h

jc  error_handler       ; Carry set means error

Locks or unlocks the volume in the given drive (preventing or permitting its removal) or returns the locked status of the given drive.

•	Clears the carry flag and copies the number of pending locks on the given drive to the NumLocks member of the PARAMBLOCK structure if successful. Otherwise, the function sets the carry flag and sets the AX register to one of the following error values:

Value	Description
01h	The function is not supported.
B0h	The volume is not locked in the drive.
B2h	The volume is not removable.
B4h	The lock count has been exceeded.
DriveNum

Drive to lock or unlock. This parameter can be 0 for default drive, 1 for A, 2 for B, and so on.

DeviceCat

Specifies a FAT16, FAT12 or FAT32 drive.

Value	Description

08h 	FAT32, FAT16 or FAT12 drive.

48h 	FAT32, FAT16, or FAT12 drive.

Please note: Because this call may be implemented in the device driver, the 48h form of this call may fail on FAT16 or FAT12 media. Therefore, applications making the 48h form of this call must fall back on the 08h form if the 48h call fails.

ParamBlock

Address of a PARAMBLOCK structure that specifies the operation to carry out and receives a count of the number of locks on the drive.


Int 21h Function 440Dh Minor Code 49h Eject Removable Media

mov ax, 440Dh      ; Generic IOCTL

mov bx, DriveNum   ; See Below

mov ch, DeviceCat  ; See Below

mov cl,            ; Eject Removable Media

int 21h

jc  error_handler  ; Carry set means error

Ejects the specified media.

•	Clears the carry flag if successful. Otherwise, the function sets the carry flag and sets the AX register to one of the following error values:

01h	The function is not supported.
B1h	The volume is locked in the drive.
B2h	The volume is not removable.
B5h	The valid eject request has failed.
DriveNum

Drive to eject. This parameter can be 0 for default drive, 1 for A, 2 for B, and so on.

DeviceCat

Specifies a FAT16, FAT12 or FAT32 drive.

Value	Description

08h 	FAT16 or FAT12 drive.

48h 	FAT32, FAT16, or FAT12 drive.

Please note: Because this call may be implemented in the device driver, the 48h form of this call may fail on FAT16 or FAT12 media. Therefore, applications making the 48h form of this call must fall back on the 08h form if the 48h call fails.

If a given physical drive has more than one logical volume, all volumes must be unlocked by using Int 21h Function 440Dh Minor Code 48h Lock/Unlock Removable Media before the drive will eject.


Int 21h Function 440Dh Minor Code 60h Get Device Parameters

mov  bx, Drive           ;0 = default, 1 = A, 2 = B, etc.

mov  ch, DeviceCat       ;See Below

mov  cl, 60h             ;Get Device Parameters

mov  dx, seg DriveDP

mov  ds, dx

mov  dx, offset DriveDP  ;ds:dx points to a device paramters structure

mov  ax, 440Dh           ;IOCTL for Block Device

int  21h

jc   error_handler       ;carry set means error

Get Device Parameters (Function 440Dh Minor Code 60h) returns the device parameters for the specified block device.

•	If the function is successful, the carry flag is clear. Otherwise, the carry flag is set and the AX register contains an error value, which may be one of the following:

Value 	Name

0001h 	ERROR_INVALID_FUNCTION

0002h 	ERROR_FILE_NOT_FOUND

0005h 	ERROR_ACCESS_DENIED

Get Device Parameters returns 0002h (ERROR_FILE_NOT_FOUND) if the specified drive number is invalid.

Drive

Specifies the drive for which parameters are requested (0 = default drive, 1 = A, 2 = B, etc.).

DeviceCat

Specifies the expected format of device parameters information structure.

Value	Expected Device Parameters Structure
08h	DEVICEPARAMS (FAT16 or FAT12 drive. Will fail on FAT32 drives.)
48h	EA_DEVICEPARAMETERS (FAT32, FAT16 or FAT12.)
Please note: Because this call may be implemented in the device driver, the 48h form of this call may fail on FAT16 or FAT12 media. Therefore, applications making the 48h form of this call must fall back on the 08h form if the 48h call fails.

DriveDP

Points to the applicable device parameters structure that contains the parameters for the specified block device. The format of the expected device parameters is indicated in the above DeviceCat field.

The special functions field in the device parameters structure determines whether the function retrieves current or default information. If the field is set to 1, the function retrieves information about the current medium in the drive; if the field is set to 0, the function retrieves information about the default medium for the drive.


Int 21h Function 440Dh Minor Code 61h Read Track on Logical Drive

mov     bx, Drive               ;0 = default, 1 = A, 2 = B, etc.

mov     ch, DeviceCat           ;See Below

mov     cl, 61h                 ;Read Track on Logical Drive

mov     dx, seg ReadBlock

mov     ds, dx

mov     dx, offset ReadBlock    ;ds:dx points to RWBLOCK structure

mov     ax, 440Dh               ;IOCTL for Block Device

int     21h

jc      error_handler           ;carry set means error

Read Track on Logical Drive (Function 440Dh Minor Code 61h) reads data from a track on the specified device and places the data in memory.

•	If the function is successful, the carry flag is clear. Otherwise, the carry flag is set and the AX register contains an error value, which may be one of the following:

Value 	Name

0001h 	ERROR_INVALID_FUNCTION

0002h 	ERROR_FILE_NOT_FOUND

0005h 	ERROR_ACCESS_DENIED

Read Track on Logical Drive returns 0002h (ERROR_FILE_NOT_FOUND) if the specified drive number is invalid.

Drive

Specifies the drive to be read from (0 = default drive, 1 = A, 2 = B, etc.).

DeviceCat

Specifies a FAT16, FAT12 or FAT32 drive.

Value	Description

08h 	FAT16 or FAT12 drive. (Will fail on a FAT32 drive).

48h 	FAT32, FAT16, or FAT12 drive.

Please note: Because this call may be implemented in the device driver, the 48h form of this call may fail on FAT16 or FAT12 media. Therefore, applications making the 48h form of this call must fall back on the 08h form if the 48h call fails.

ReadBlock

Points to an RWBLOCK structure that contains information that specifies the sectors to be read from. The RWBLOCK structure has the following form:

RWBLOCK STRUC

    rwSpecFunc      db  0  ;special functions (must be zero)

    rwHead          dw  ?  ;head to read/write

    rwCylinder      dw  ?  ;cylinder to read/write

    rwFirstSector   dw  ?  ;first sector to read/write

    rwSectors       dw  ?  ;number of sectors to read/write

    rwBuffer        dd  ?  ;address of buffer for read/write data

RWBLOCK ENDS


Int 21h Function 440Dh Minor Code 62h Verify Track on Logical Drive

mov     bx, Drive                 ;0 = default, 1 = A, 2 = B, etc.

mov     ch, 08h                   ;device category (must be 08h)

mov     cl, 62h                   ;Verify Track on Logical Drive

mov     dx, seg VerifyBlock

mov     ds, dx

mov     dx, offset VerifyBlock    ;ds:dx points to FVBLOCK structure

mov     ax, 440Dh                 ;IOCTL for Block Device

int     21h

jc      error_handler             ;carry set means error

Verify Track on Logical Drive (Function 440Dh Minor Code 62h) verifies a track on the specified device.

•	If the function is successful, the carry flag is clear. Otherwise, the carry flag is set and the AX register contains an error value, which may be one of the following:

Value 	Name

0001h 	ERROR_INVALID_FUNCTION

0002h 	ERROR_FILE_NOT_FOUND

0005h 	ERROR_ACCESS_DENIED

Verify Track on Logical Drive returns 0002h (ERROR_FILE_NOT_FOUND) if the specified drive number is invalid.

Drive

Specifies the drive on which the track is to be verified (0 = default drive, 1 = A, 2 = B, etc.).

DeviceCat

Specifies a FAT16, FAT12 or FAT32 drive.

Value	Description

08h 	FAT16 or FAT12 drive. (Will fail on a FAT32 drive).

48h 	FAT32, FAT16, or FAT12 drive.

Please note: Because this call may be implemented in the device driver, the 48h form of this call may fail on FAT16 or FAT12 media. Therefore, applications making the 48h form of this call must fall back on the 08h form if the 48h call fails.

VerifyBlock

Points to an FVBLOCK structure that specifies the head and cylinder to verify. The FVBLOCK structure has the following form:

FVBLOCK STRUC

    fvSpecFunc    db  0   ;special functions

    fvHead        dw  ?   ;head to format/verify

    fvCylinder    dw  ?   ;cylinder to format/verify

    fvTracks      dw  ?   ;tracks to format/verify

FVBLOCK ENDS

The fvSpecFunc field can be 0 or 2.


Int 21h Function 440Dh Minor Code 66h Get Media ID

mov     bx, Drive            ;0 = default, 1 = A, 2 = B, etc.

mov     ch, 08h              ;device category (must be 08h)

mov     cl, 66h              ;Get Media ID

mov     dx, seg MediaID

mov     ds, dx

mov     dx, offset MediaID   ;ds:dx points to MID structure

mov     ax, 440Dh            ;IOCTL for Block Device

int     21h

jc      error_handler        ;carry set means error

Get Media ID (Function 440Dh Minor Code 66h) returns the volume label, serial number and file system for the specified drive.

•	If the function is successful, the carry flag is clear, and the parameter block (a MID structure) is filled in with information about the disk. Otherwise, the carry flag is set and the AX register contains an error value, which may be one of the following:

Value 	Name

0001h 	ERROR_INVALID_FUNCTION

0002h 	ERROR_FILE_NOT_FOUND

0005h 	ERROR_ACCESS_DENIED

Get Media ID returns 0002h (ERROR_FILE_NOT_FOUND) if the specified drive number is invalid.

Drive

Specifies the drive for which information is to be returned (0 = default drive, 1 = A, 2 = B, etc.).

DeviceCat

Specifies a FAT16, FAT12 or FAT32 drive.

Value	Description

08h 	FAT32, FAT16 or FAT12 drive.

48h 	FAT32, FAT16, or FAT12 drive.

Please note: Because this call may be implemented in the device driver, the 48h form of this call may fail on FAT16 or FAT12 media. Therefore, applications making the 48h form of this call must fall back on the 08h form if the 48h call fails.

MediaID

Points to a MID structure that receives information that uniquely identifies a disk or other storage medium. The MID structure has the following form:

MID STRUC

    midInfoLevel   dw  0           ;information level

    midSerialNum   dd  ?           ;serial number

    midVolLabel    db  11 dup (?)  ;ASCII volume label

    midFileSysType db  8 dup (?)   ;file system type

MID ENDS


Int 21h Function 440Dh Minor Code 67h Get Access Flag

mov     bx, Drive               ;0 = default, 1 = A, 2 = B, etc.

mov     ch, DeviceCat           ;See Below

mov     cl, 67h                 ;Get Access Flag

mov     dx, seg SpecialFunc

mov     ds, dx

mov     dx, offset SpecialFunc  ;ds:dx points to SPECIALFUNC structure

mov     ax, 440Dh               ;IOCTL for Block Device

int     21h

jc      error_handler           ;carry set means error

Get Access Flag (Function 440Dh Minor Code 67h) retrieves the access flag for the specified drive.

•	If the function is successful, the carry flag is clear. Otherwise, the carry flag is set and the AX register contains an error value, which may be one of the following:

Value 	Name

0001h 	ERROR_INVALID_FUNCTION

0002h 	ERROR_FILE_NOT_FOUND

0005h 	ERROR_ACCESS_DENIED

Get Access Flag returns 0002h (ERROR_FILE_NOT_FOUND) if the specified drive number is invalid.

Drive

Specifies the drive for which the access flag is to be retrieved (0 = default drive, 1 = A, 2 = B, etc.).

DeviceCat

Specifies a FAT16, FAT12 or FAT32 drive.

08h 	FAT32, FAT16 or FAT12 drive.

48h 	FAT32, FAT16, or FAT12 drive.

Please note: Because this call may be implemented in the device driver, the 48h form of this call may fail on FAT16 or FAT12 media. Therefore, applications making the 48h form of this call must fall back on the 08h form if the 48h call fails.

SpecialFunc

Points to a SPECIALFUNC structure that receives the state of the access flag. The SPECIALFUNC structure has the following form:

SPECIALFUNC STRUC

    sfFunction  db  0   ;special function (must be 0)

    sfAccessFlg db  ?   ;access flag, 0 if access blocked

                        ;"unformatted"

SPECIALFUNC ENDS


Int 21h Function 440Dh Minor Code 68h Sense Media Type

mov     bx, Drive               ;0 = default, 1 = A, 2 = B, etc.

mov     ch, DeviceCat           ;See Below

mov     cl, 68h                 ;Sense Media Type

mov     dx, seg Media

mov     ds, dx

mov     dx, offset Media        ;ds:dx points to buffer for media type

mov     ax, 440Dh               ;IOCTL for Block Device

int     21h

jc      error_handler           ;carry set means error

Sense Media Type (Function 440Dh Minor Code 68h) returns the media type for the specified block device.

•	If the function is successful, the carry flag is clear. Otherwise, the carry flag is set and the AX register contains an error value, which may be one of the following:

Value 	Name

0001h 	ERROR_INVALID_FUNCTION

0005h 	ERROR_ACCESS_DENIED

This function may also return a device-dependent error value as specified by the device driver.

Sense Media Type returns 0005h (ERROR_ACCESS_DENIED) if the media type for the specified drive cannot be determined or the given drive is not ready. Programs can use Get Extended Error (Function 59h) to retrieve additional information about the error.

Drive

Specifies the drive for which parameters are requested (0 = default drive, 1 = A, 2 = B, etc.).

DeviceCat

Specifies a FAT16, FAT12 or FAT32 drive.

08h 	FAT32, FAT16 or FAT12 drive.

48h 	FAT32, FAT16, or FAT12 drive.

Please note: Because this call may be implemented in the device driver, the 48h form of this call may fail on FAT16 or FAT12 media. Therefore, applications making the 48h form of this call must fall back on the 08h form if the 48h call fails.

Media

Points to a 2-byte buffer that receives information on the media type for the given drive. The buffer has the following form:

Offset	Description
00h	Receives a value specifying whether the media type is the default value. This byte is set to 01h for the default media type and to 00h for any other media type.
01h	Receives a value specifying the media type. This byte is set to 02h for 720K disks, 07h for 1.44-MB disks, and 09h for 2.88-MB disks.


Int 21h Function 440Dh Minor Code 6Fh Get Drive Map Info

mov ax, 440Dh             ; Generic IOCTL

mov bx, DriveNum          ; See Below

mov ch, DeviceCat         ; See Below

mov cl, 6Fh               ; Get Drive Map Info

mov dx, seg DriveMapInfo  ; See below

mov ds, dx

mov dx, offset DriveMapInfo

int 21h

jc  error_handler         ; Carry set means error

Retrieves information about the specified drive. This call only works under Windows 95. It will fail if called under MS-DOS.

DriveNum

Drive to obtain information about. This parameter can be 0 for the default drive, 1 for A, 2 for B, and so on.

DeviceCat

Specifies a FAT16, FAT12 or FAT32 drive.

08h 	FAT32, FAT16 or FAT12 drive.

48h 	FAT32, FAT16, or FAT12 drive.

Please note: Because this call may be implemented in the device driver, the 48h form of this call may fail on FAT16 or FAT12 media. Therefore, applications making the 48h form of this call must fall back on the 08h form if the 48h call fails.

DriveMapInfo

Address of the DRIVE_MAP_INFO structure that receives information about the specified drive. The DRIVE_MAP_INFO structure has the following form:

DRIVE_MAP_INFO    struc

    dmiAllocationLength   db ?

    dmiInfoLength         db ?

    dmiFlags              db ?

    dmiInt13Unit          db ?

    dmiAssociatedDriveMap dd ?

    dmiPartitionStartRBA  dq ?

DRIVE_MAP_INFO    ends


Int 21h Function 440Dh Minor Code 71h Get First Cluster

mov ax, 440Dh            ; Generic IOCTL

mov bx, CharSet          ; See Below

mov ch, DeviceCat        ; See Below

mov cl, 71h              ; Get First Cluster

mov dx, seg PathName     ; See Below

mov ds, dx

mov dx, offset PathName

int 21h

jc error_handler         ; Carry set means error

Retrieves the first cluster of the specified file or directory. This function is only supported by Windows 95. It will fail if called under MS-DOS.

•	Clears the carry flag and sets DX:AX to the first cluster number if successful. Otherwise, the function sets the carry flag and returns either the ERROR_INVALID_FUNCTION or ERROR_ACCESS_DENIED value in AX.

CharSet

Character set of PathName. This parameter must be one of these values:

BCS_WANSI (0) 	Windows ANSI character set

BCS_OEM (1) 	Current OEM character set

BCS_UNICODE (2) 	Unicode character set

DeviceCat

Specifies a FAT16, FAT12 or FAT32 drive.

08h 	FAT32, FAT16 or FAT12 drive.

48h 	FAT32, FAT16, or FAT12 drive.

Please note: Because this call may be implemented in the device driver, the 48h form of this call may fail on FAT16 or FAT12 media. Therefore, applications making the 48h form of this call must fall back on the 08h form if the 48h call fails.

PathName

Address of a null-terminated string containing the path of the file or directory to retrieve the first cluster for.

The first cluster of a file is the first cluster of the FAT cluster chain describing the data associated with the file. The first cluster of a directory is the first cluster of the FAT cluster chain associated with the directory. It is the cluster that contains the "." and ".." entries. The function finds any file or directory regardless of attribute (system, hidden, or read-only). It does not find volume labels.

It is the calling application's responsibility to check to see if the returned cluster number is valid.

if((MAKELONG(regAX,regDX) < 2L) || (MAKELONG(regAX,regDX) > maxClus))

    bInvalidNum = TRUE;

else

    bInvalidNum = FALSE;

In the preceding example, the maxClus variable is the maximum legal cluster number, as a DWORD type, computed from the drive parameters.


Int 21h Function 6Ch Extended Open

mov ah, 6Ch             ; Extended Open/Create

mov bx, ModeAndFlags    ; See Below

mov cx, Attributes      ; See Below

mov dx, Action          ; Action to take

mov si, seg Filename    ; See Below

mov ds, si

mov si, offset Filename

int 21h

jc error_handler        ; Carry set means error

mov [Handle], ax        ; file handle

mov [ActionTaken], cx   ; action taken to open file

Opens or creates a file having the given name and attributes.

•	Clears the carry flag, copies the file handle to the AX register, and sets CX to one of the following values if successful:

ACTION_OPENED (0001h)

ACTION_CREATED_OPENED (0002h)

ACTION_REPLACED_OPENED (0003h)

Otherwise, this function sets the carry flag and sets the AX register to one of the following error values:

ERROR_INVALID_FUNCTION (0001h)

ERROR_FILE_NOT_FOUND (0002h)

ERROR_PATH_NOT_FOUND (0003h)

ERROR_TOO_MANY_OPEN_FILES (0004h)

ERROR_ACCESS_DENIED (0005h)

ModeAndFlags

Combination of access mode, sharing mode, and open flags. This parameter can be one value each from the access and sharing modes and any combination of open flags:

Access mode

OPEN_ACCESS_READONLY (0000h)

Opens the file for reading only.

OPEN_ACCESS_WRITEONLY (0001h)

Opens the file for writing only.

OPEN_ACCESS_READWRITE (0002h)

Opens the file for reading and writing.

0003h

Reserved; do not use.

OPEN_ACCESS_RO_NOMODLASTACCESS (0004h)

Opens the file for reading only without modifying the file's last access date.

Sharing mode

OPEN_SHARE_COMPATIBLE (0000h)

Opens the file with compatibility mode, allowing any process on a given computer to open the file any number of times.

OPEN_SHARE_DENYREADWRITE (0010h)

Opens the file and denies both read and write access to other processes.

OPEN_SHARE_DENYWRITE (0020h)

Opens the file and denies write access to other processes.

OPEN_SHARE_DENYREAD (0030h)

Opens the file and denies read access to other processes.

OPEN_SHARE_DENYNONE (0040h)

Opens the file without denying read or write access to other processes, but no process may open the file with compatibility mode.

Open flags

OPEN_FLAGS_NOINHERIT (0080h)

If this flag is set, a child process created with Load and Execute Program (Interrupt 21h Function 4B00h) does not inherit the file handle. If the handle is needed by the child process, the parent process must pass the handle value to the child process. If this flag is not set, child processes inherit the file handle.

EXTENDED_SIZE (1000h)

If this flag is set, the file is opened in extended mode. This allows access to files up to 4GB - 1 byte. Access includes open and create functions.

OPEN_FLAGS_NOCRITERR (2000h)

If a critical error occurs while MS-DOS is opening this file, Critical-Error Handler (Interrupt 24h) is not called. Instead, MS-DOS simply returns an error value to the program.

OPEN_FLAGS_COMMIT (4000h)

After each write operation, MS-DOS commits the file (flushes the contents of the cache buffer to disk).

Attributes

Attributes for files that are created or truncated. This parameter may be a combination of these values:

FILE_ATTRIBUTE_NORMAL (0000h)

The file can be read from or written to. This value is valid only if used alone.

FILE_ATTRIBUTE_READONLY (0001h)

The file can be read from, but not written to.

FILE_ATTRIBUTE_HIDDEN (0002h)

The file is hidden and does not appear in an ordinary directory listing.

FILE_ATTRIBUTE_SYSTEM (0004h)

The file is part of the operating system or is used exclusively by it.

FILE_ATTRIBUTE_VOLUME (0008h)

The name specified by Filename is used as the volume label for the current medium.

FILE_ATTRIBUTE_ARCHIVE (0020h)

The file is an archive file. Applications use this value to mark files for backup or removal.

Action

Action to take it the file exists or does not exist. This parameter can be a combination of these values:

FILE_CREATE (0010h)

Creates a new file if it does not already exist or fails if the file already exists.

FILE_OPEN (0001h)

Opens the file. The function fails if the file does not exist.

FILE_TRUNCATE (0002h)

Opens the file and truncates it to zero length (replaces the existing file). The function fails if the file does not exist.

The only valid combinations are FILE_CREATE combined with FILE_OPEN or FILE_CREATE combined with FILE_TRUNCATE.

Filename

Address of a null-terminated string specifying the name of the file to be opened or created. The name must be in the standard MS-DOS 8.3 filename format. The string must be a valid path for the volume associated with the given drive.

This function does not support long filenames. If the specified name is too long, this function truncates the name to the standard 8.3 format following the same naming scheme that the system uses when creating an alias for a long filename.

A file on a remote directory -- that is, a directory on the network -- cannot be opened, unless appropriate permissions for the directory exist.


Limitations of Some Existing Functions

The following functions have limitations on FAT32 media:

File Control Block Functions

Open and Create functions will only work for creating a volume label on a FAT32 drive. However, FCB find_first/next, delete, and rename will work on FAT32 media.

Handle-Based File Write Functions

To grow a file to a size greater than 2GB - 1bytes in size, the file must be opened with Int 21h Function 6Ch Extended Open using the new EXTENDED_SIZE flag. If such a file is not opened in extended mode using this flag, write functions will fail, receiving ERROR_ACCESS_DENIED (0005h).

Handle-Based File Open and Create Functions

To open a file to a size greater than 2GB - 1bytes in size, the file must be opened with Int 21h Function 6Ch Extended Open using the new EXTENDED_SIZE flag. However, truncation of a file using an old style create will not fail.


Superseded Functions Overview

The following functions have been superseded:

Interrupt 21h Function 1Fh Get Default DPB:

Superseded by Int 21h Function 7302h Get_ExtDPB.

Interrupt 21h Function 32h Get DPB:

Superseded by Int 21h Function 7302h Get_ExtDPB.

Interrupt 21h Function36h Get Disk Free Space:

If total or free disk space is greater than 2GB - 32k, then 2GB - 32k is returned. This function is superseded by Int 21h Function 7303h Get_ExtFreeSpace.

Interrupts 25h/26h Absolute Disk Read / Write:

Superseded by Int 21h Function 7305h Ext_ABSDiskReadWrite. These functions fail on FAT32 drives. This is to prevent non-FAT32 compatible software from being able to access FAT32 media.


New Structures Overview

With the addition of the FAT32 file system, the BPB, DPB, and DEVICEPARAMS structures were superseded by equivalent structures that accommodate FAT32 information. Additionally, subordinate structures have been implemented to support the FAT32 file system main structures.

Please note that many data structures in this document are listed as reserved. This indicates that user is not to assume values for or modify these fields. They are used by the file system itself and are not available for any enhancements.

New Structures:

FAT32 BIOS Parameter Block (BPB)

BIGFATBOOTFSINFO

Drive Parameter Block (DPB)

EA_DEVICEPARAMETERS

ExtGetDskFreSpcStruc

s_partition

SDPDFormatStruc


FAT32 BIOS Parameter Block (BPB)

The BPB for FAT32 drives is an extended version of the FAT16/FAT12 BPB. It contains identical information to a standard BPB, but also includes several extra fields for FAT32 specific information.

A_BF_BPB    STRUC

    A_BF_BPB_BytesPerSector       DW    ?

    A_BF_BPB_SectorsPerCluster    DB    ?

    A_BF_BPB_ReservedSectors      DW    ?

    A_BF_BPB_NumberOfFATs         DB    ?

    A_BF_BPB_RootEntries          DW    ?

    A_BF_BPB_TotalSectors         DW    ?

    A_BF_BPB_MediaDescriptor      DB    ?

    A_BF_BPB_SectorsPerFAT        DW    ?

    A_BF_BPB_SectorsPerTrack      DW    ?

    A_BF_BPB_Heads                DW    ?

    A_BF_BPB_HiddenSectors        DW    ?

    A_BF_BPB_HiddenSectorsHigh    DW    ?

    A_BF_BPB_BigTotalSectors      DW    ?

    A_BF_BPB_BigTotalSectorsHigh  DW    ?

    A_BF_BPB_BigSectorsPerFat     DW    ?

    A_BF_BPB_BigSectorsPerFatHi   DW    ?

    A_BF_BPB_ExtFlags             DW    ?

    A_BF_BPB_FS_Version           DW    ?

    A_BF_BPB_RootDirStrtClus      DW    ?

    A_BF_BPB_RootDirStrtClusHi    DW    ?

    A_BF_BPB_FSInfoSec            DW    ?

    A_BF_BPB_BkUpBootSec          DW    ?

    A_BF_BPB_Reserved             DW    6 DUP (?)

A_BF_BPB    ENDS

A_BF_BPB_BytesPerSector

The number of bytes per sector.

A_BF_BPB_SectorsPerCluster

The Number of sectors per cluster.

A_BF_BPB_ReservedSectors

The number of reserved sectors, beginning with sector 0.

A_BF_BPB_NumberOfFATs

The number of File Allocation Tables.

A_BF_BPB_RootEntries

This field is ignored on FAT32 drives.

A_BF_BPB_TotalSectors

The size of the partition, in sectors.

A_BF_BPB_MediaDescriptor

The media descriptor. Values in this field are identical to standard BPB.

A_BF_BPB_SectorsPerFAT

The number of sectors per FAT.

Note: This field will always be zero in a FAT32 BPB.

A_BF_BPB_SectorsPerTrack

The number of sectors per track.

A_BF_BPB_Heads

The number of read/write heads on the drive.

A_BF_BPB_HiddenSectors

The number of hidden sectors on the drive.

A_BF_BPB_HiddenSectorsHigh

The high word of the hidden sectors value.

A_BF_BPB_BigTotalSectors

The total number of sectors on the FAT32 drive.

A_BF_BPB_BigTotalSectorsHigh

The high word of the FAT32 total sectors value.

A_BF_BPB_BigSectorsPerFat

The number of sectors per FAT on the FAT32 drive.

A_BF_BPB_BigSectorsPerFatHi

The high word of the FAT32 sectors per FAT value.

A_BF_BPBExtFlags

Flags describing the drive. Bit 8 of this field indicates whether or not writes to the active FAT will be written to all copies of the FAT. The low 4 bits of this field contain the 0-based FAT number of the Active FAT, but are only meaningful if bit 8 is set. This field can contain a combination of the following values.

Value	Description
BGBPB_F_ActiveFATMsk (000Fh)	Mask for low four bits.
BGBPB_F_NoFATMirror (0080h)	Mask indicating FAT mirroring state. If set, mirroring is disabled. If clear, FAT mirroring is enabled.
Bits 4-6 and 8-15 are reserved.

A_BF_BPB_FS_Version

The file system version number of the FAT32 drive. The high byte represents he major version, and the low byte represents the minor version.

A_BF_BPB_RootDirStrtClus

The cluster number of the first cluster of the root directory of the FAT32 drive.

A_BF_BPB_RootDirStrtClusHi

The high word of the FAT32 starting cluster number.

A_BF_BPB_FSInfoSec

The sector number of the file system information sector. The file system info sector contains a BIGFATBOOTFSINFO structure. This field is set to 0FFFFh if there is no FSINFO sector. Otherwise, this value must be non-zero and less than the reserved sector count.

A_BF_BPB_BkUpBootSec

The sector number of the backup boot sector. This field is set to 0FFFFh if there is no backup boot sector. Otherwise, this value must be non-zero and less than the reserved sector count.

A_BF_BPB_Reserved

Reserved field. Do not use.


BIGFATBOOTFSINFO Structure

Contains information about the file system.

BIGFATBOOTFSINFO STRUC

    bfFSInf_Sig               DD    ?

    bfFSInf_free_clus_cnt     DD    ?

    bfFSInf_next_free_clus    DD    ?

    bfFSInf_resvd             DD    3 DUP (?)

BIGFATBOOTFSINFO ENDS

bfFSInf_Sig

The signature of the file system information sector. This value is FSINFOSIG (0x61417272L).

bfFSInf_free_clus_cnt

The count of free clusters on the drive. This is -1 when the count is unknown.

bfFSInf_next_free_clus

The cluster number of the cluster that was most recently allocated.

bfFSInf_resvd

Reserved field. Do not use.


New Drive Parameter Block (DPB) Structure

The DPB was extended to include FAT32 information.

DPB STRUC

    dpb_drive            DB    ?

    dpb_unit             DB    ?

    dpb_sector_size      DW    ?

    dpb_cluster_mask     DB    ?

    dpb_cluster_shift    DB    ?

    dpb_first_fat        DW    ?

    dpb_fat_count        DB    ?

    dpb_root_entries     DW    ?

    dpb_first_sector     DW    ?

    dpb_max_cluster      DW    ?

    dpb_fat_size         DW    ?

    dpb_dir_sector       DW    ?

    dpb_driver_addr      DD    ?

    dpb_media            DB    ?

ifdef NOTFAT32

    dpb_first_access     DB    ?

else

    dpb_flags            DB    ?

endif

    dpb_next_dpb         DD    ?

    dpb_next_free        DW    ?

    dpb_free_cnt         DW    ?

ifndef NOTFAT32

    extdpb_free_cnt_hi   DW    ?

    extdpb_flags         DW    ?

    extdpb_FSInfoSec     DW    ?

    extdpb_BkUpBootSec   DW    ?

    extdpb_first_sector  DD    ?

    extdpb_max_cluster   DD    ?

    extdpb_fat_size      DD    ?

    extdpb_root_clus     DD    ?

    extdpb_next_free     DD    ?

endif

DPB ENDS

dpb_drive

The drive number (0 = A, 1 = B, etc.).

dpb_unit

Specifies the unit number. The device driver uses the unit number to distinguish the specified drive from the other drives it supports.

dpb_sector_size

The size of each sector, in bytes.

dpb_cluster_mask

The number of sectors per cluster minus 1.

dpb_cluster_shift

The number of sectors per cluster, expressed as a power of 2.

dpb_first_fat

The sector number of the first sector containing the file allocation table (FAT).

dpb_fat_count

The number of FATs on the drive.

dpb_root_entries

The number of entries in the root directory.

dpb_first_sector

The sector number of the first sector in the first cluster.

dpb_max_cluster

The number of clusters on the drive plus 1. This field is undefined for FAT32 drives.

dpb_fat_size

The number of sectors occupied by each FAT. The value of zero indicates a FAT32 drive.

dpb_dir_sector

The sector number of the first sector containing the root directory. This field is undefined for FAT32 drives.

dpb_reserved2

Reserved field. Do not use.

dpb_media

Specifies the media descriptor for the medium in the specified drive.

reserved

Reserved field. Do not use.

dpb_first_access

Indicates whether the medium in the drive has been accessed. This field is initialized to -1 to force a media check the first time this DPB is used.

dpb_reserved3

Reserved field. Do not use.

dpb_next_free

The cluster number of the most recently allocated cluster.

dpb_free_cnt

The number of free clusters on the medium. This field is 0FFFFh if the number is unknown.

extdpb_free_cnt_hi

The high word of free count.

extdpb_flags

Flags describing the drive. The low 4 bits of this field contain the 0-based FAT number of the Active FAT. This field can contain a combination of the following values.

Value	Description
BGBPB_F_ActiveFATMsk (000Fh)	Mask for low four bits.
BGBPB_F_NoFATMirror (0080h)	Do not Mirror active FAT to inactive FATs.
Bits 4-6 and 8-15 are reserved.

extdpb_FSInfoSec

The sector number of the file system information sector. This field is set to 0FFFFh if there is no FSINFO sector. Otherwise, this value must be non-zero and less than the reserved sector count.

extdpb_BkUpBootSec

The sector number of the backup boot sector. This field is set to 0FFFFh if there is no backup boot sector. Otherwise, this value must be non-zero and less than the reserved sector count.

extdpb_first_sector

The first sector of the first cluster.

extdpb_max_cluster

The number of clusters on the drive plus 1.

extdpb_fat_size

The number of sectors occupied by the FAT.

extdpb_root_clus

The cluster number of the first cluster in the root directory.

extdpb_next_free

The number of the cluster that was most recently allocated.


EA_DEVICEPARAMETERS Structure

The equivalent of the DEVICEPARAMS structure, but includes FAT32 specific information.

EA_DEVICEPARAMETERS STRUC

    EDP_SPECIALFUNCTIONS     DB     ?

    EDP_DEVICETYPE           DB     ?

    EDP_DEVICEATTRIBUTES     DW     ?

    EDP_CYLINDERS            DW     ?

    EDP_MEDIATYPE            DB     ?

    EDP_BPB                  DB     SIZE A_BF_BPB DUP (?)

    EDP_RESERVED1            DB     32 DUP (?)

    EDP_TRACKTABLEENTRIES    DW     ?

    EDP_SECTORTABLE          DB MAX_SECTORS_IN_TRACK * SIZE A_SECTORTABLE DUP (?)

EA_DEVICEPARAMETERS ENDS

This structure is identical to DEVICEPARAMS, but includes a FAT32 BPB instead of a standard BPB, followed by a 32 byte reserved field.


ExtGetDskFreSpcStruc

A structure used by Int 21h Function 7303h Get_ExtFreeSpace. The structure is used to contain information about the drive's total and free disk space.

ExtGetDskFreSpcStruc STRUC

    ExtFree_Size                      DW    ?

    ExtFree_Level                     DW    ?

    ExtFree_SectorsPerCluster         DD    ?

    ExtFree_BytesPerSector            DD    ?

    ExtFree_AvailableClusters         DD    ?

    ExtFree_TotalClusters             DD    ?

    ExtFree_AvailablePhysSectors      DD    ?

    ExtFree_TotalPhysSectors          DD    ?

    ExtFree_AvailableAllocationUnits  DD    ?

    ExtFree_TotalAllocationUnits      DD    ?

    ExtFree_Rsvd                      DD    2 DUP (?)

ExtGetDskFreSpcStruc ENDS

ExtFree_Size

The true size of the drive. Get_ExtFreeSpace returns the value to this field.

ExtFree_Level

An input and return level value. This should be initialized to zero.

ExtFree_SectorsPerCluster

The number of sectors per cluster.

ExtFree_BytesPerSector

The number of bytes per sector.

ExtFree_AvailClusters

The number of available clusters.

ExtFree_TotalClusters

The total number of clusters on the drive.

ExtFree_AvailablePhysSectors

The number of physical sectors available on the drive, without adjustment for compression.

ExtFree_TotalPhysSectors

The total number of physical sectors on the drive, without adjustment for compression.

ExtFree_AvailableAllocationUnits

The number of available allocation units on the drive, without adjustment for compression.

ExtFree_TotalAllocationUnits

The total number of allocation units on the drive, without adjustment for compression.

ExtFree_Rsvd

Reserved field.


s_partition Structure

Note that values for head and track are 0-based, whereas sector values are 1-based.

s_partition    STRUC

    Part_BootInd        DB    ?

    Part_FirstHead      DB    ?

    Part_FirstSector    DB    ?

    Part_FirstTrack     DB    ?

    Part_FileSystem     DB    ?

    Part_LastHead       DB    ?

    Part_LastSector     DB    ?

    Part_LastTrack      DB    ?

    Part_StartSector    DD    ?

    Part_NumSectors     DD    ?

s_partition    ENDS

Part_BootInd

Specifies whether the partition is bootable or not. This value could be set to PART_BOOTABLE (80h), or PART_NON_BOOTABLE(00h). The first one designated as PART_BOOTABLE is the boot partition. All others are not.

Part_FirstHead

The first head of this partition This is a 0-based number representing offset from the beginning of the disk. The partition includes this head.

Part_FirstSector

The first sector of this partition. This is a 1-based, 6-bit number representing offset from the beginning of the disk.. The partition includes this sector. Bits 0 through 5 specify the 6-bit value; bits 6 and 7 are used with the Part_FirstTrack field.

Part_FirstTrack

The first track of this partition. This is a 0-based, 10-bit number that represents offset from the beginning of the disk. The partition includes this track (from Part_FirstHead). The high 2 bits of this value are specified by bits 6 and 7 of the Part_FirstSector field.

PartFileSystem

Specifies the file system for this partition. The following are acceptable values:

Value	Description
PART_UNKNOWN(00h)	Unknown
PART_DOS2_FAT(01h)	12-bit FAT. Partition smaller than 10MB.
PART_DOS3_FAT(04h)	16-bit FAT. Partition smaller that 32MB.
PART_EXTENDED(05h)	Extended MS-DOS Partition.
PART_DOS4_FAT(06h)	16-bit FAT. Partition larger than or equal to 32MB.
PART_DOS32(0Bh)	32-bit FAT. Partition up to 2047GB.
PART_DOS32X(0Ch)	Same as 0Bh, but uses Logical Block Address Int 13h extensions.
PART_DOSX13(0Eh)	Same as 06h, but uses Logical Block Address Int 13h extensions.
PART_DOSX13X(0Fh)	Same as 05h, but uses Logical Block Address Int 13h extensions.
Part_LastHead

The last head of this partition. This is a 0-based number that represents offset from the beginning of the disk. The partition includes this head.

Part_LastSector

The last sector of this partition. This is a 1-based, 6-bit number representing offset from the beginning of the disk.. The partition includes this sector. Bits 0 through 5 specify the 6-bit value; bits 6 and 7 are used with the Part_LastTrack field.

Part_LastTrack

The last track of this partition. This is a 0-based, 10-bit number that represents offset from the beginning of the disk. The partition includes this track. The high 2 bits of this value are specified by bits 6 and 7 of the Part_LastSector field.

Part_StartSector

Specifies the 1-based number of the first sector on the disk. This value may not be accurate for extended partitions. It is recommended to use the Part_FirstSector value for extended partitions.

Part_NumSectors

The 1-based number of sectors in the partition.


SDPDFormatStruc Structure

Structure used to hold information on executing the various sub-functions of Int 21h Function 7304h Set_DPBForFormat

SDPDFormatStruc STRUC

    SetDPB_Size        DW    ?

    SetDPB_Level       DW    ?

    SetDPB_Function    DD    ?

    SetDPB_Value1      DD    ?

    SetDPB_Value2      DD    ?

    SetDPB_Value3      DD    ?

    SetDPB_Value4      DD    ?

SDPDFormatStruc ENDS

SetDPB_Size

A return value field for the sub-functions. This is not an input field.

SetDPB_Level

An input and return level value field. This should be set to 0.

SetDPB_Funtion

Specifies which sub-function will be implemented. The acceptable values are as follows:

0	SetDPB_SetAllocInfo
1	SetDPB_SetDPBFrmBPB
2	SetDPB_ForceMediaChng
3	SetDPB_GetSetActFATandMirr
4	SetDPB_GetSetRootDirClus
SetDPB_Value1

Input field for sub-function. See specific sub-function for details.

SetDPB_Value2

Input field for sub-function. See specific sub-function for details.

SetDPB_Value3

Input field for sub-function. See specific sub-function for details.

SetDPB_Value4

Input field for sub-function. See specific sub-function for details.