On Time RTOS-32 Documentation
Welcome
RTTarget-32
RTKernel-32
RTFiles-32
RTFiles-32 Programming Manual
RTFiles-32 Reference Manual
Introduction
General File I/O
Information about Files
File Attributes
Directories
Finding Files
File Name Operations
Disk and Volume Management
Function RTFResetDisk
Function RTFGetDiskInfoEx
Function RTFGetPartitionInfo
Function RTFSetVolumeLabel
Function RTFFormat
Function RTFFormatExFAT
Function RTFCheckDisk
Function RTFCheckDiskBufferSize
Function RTFCreateMasterBootRecord
Function RTFSplitPartition
Function RTFCreateGPTPartition
Function RTFSplitGPTPartition
Function RTFCreateBackupGPT
Function RTFCreateBootSector
Function RTFGetDeviceIndex
Function RTFDeviceIoControl
Function RTFPartitionSectors
Function RTFPartitionStart
Miscellaneous File Functions
Raw I/O Functions
Functions for Debugging
Device Dependent Functions
Obsolete Functions
Disk Device Driver API
MTD Device Driver API
RTFiles-32 Error Codes
Code Page Reference
RTIP-32
RTPEG-32
RTUSB-32
|
Function RTFCheckDisk
RTFCheckDisk checks and optionally fixes file system errors on a FAT or exFAT formatted logical drive:
typedef DWORD (__cdecl * RTFCheckDiskCallback)(DWORD Flag,
const char * Path,
const RTFDOSDirEntry * FileInfo,
DWORD N1,
DWORD N2);
int RTFCheckDisk(const char * DriveName,
void * Buffer,
UINT BufferSize,
RTFCheckDiskCallback ErrorHandler,
DWORD Flags);
ParametersDriveNamePointer to a valid file name (e.g., a root directory such as "C:\"). Only the name's drive information is evaluated.
BufferPointer to temporary storage RTFCheckDisk can use. Parameter BufferSize specifies how large the buffer is. If this parameter or BufferSize is 0, RTFCheckDisk allocates the required buffer from the heap.
BufferSizeSize in bytes of the buffer pointed to by parameter Buffer. This parameter should be equal to or larger than the value returned by function RTFCheckDiskBufferSize. If this parameter or Buffer is 0, RTFCheckDisk allocates the required buffer from the heap.
ErrorHandlerCallback function RTFCheckDisk will call for progress information or when a problem has been detected. This parameter may be NULL if RTFCheckDisk should always apply the default fix method and no progress information is required. More information about the error handler callback is given below.
FlagsThe Flags parameter specifies which checks and fix method (if any) are to be applied. At most one flag out of each group in the list below may be specified. Note that if several checks are specified, they are performed in the sequence given below:
Value |
Meaning |
RTF_CHK_FAT_MISMATCH
RTF_CHK_FAT_MISMATCH_1
RTF_CHK_FAT_MISMATCH_2 |
RTFDiskCheck should compare the master FAT against a backup FAT, if one or more such backups are present. RTF_CHK_FAT_MISMATCH specifies no default fix if a mismatch is found. RTF_CHK_FAT_MISMATCH_1 would use the first FAT while RTF_CHK_FAT_MISMATCH_2 would use a backup FAT to fix the mismatch. This check is not performed on exFAT volumes. |
RTF_CHK_INVALID_DIR
RTF_CHK_INVALID_DIR_DELETE |
RTFDiskCheck should check all directory entries for invalid file name characters, invalid attribute combinations, and invalid starting cluster values. RTF_CHK_INVALID_DIR_DELETE will delete any such files in the directory, but not their FAT entries. Orphaned clusters of the FAT can still be recovered using the RTF_CHK_LOST_CLUSTER check. RTFDiskCheck does not delete the clusters of files with invalid directory entries because the complete directory entry might be corrupted, including the FirstCluster value of each directory entry. In this case, RTFCheckDisk would delete random clusters, possibly corrupting intact files. |
RTF_CHK_INVALID_CLUSTER
RTF_CHK_INVALID_CLUSTER_TRUNC
RTF_CHK_INVALID_CLUSTER_DELETE |
RTFDiskCheck should check for any invalid cluster values in the FAT chain of each file. If RTF_CHK_INVALID_CLUSTER_TRUNC is specified, the FAT chain is truncated one cluster before the invalid cluster. RTF_CHK_INVALID_CLUSTER_DELETE deletes the file. In both cases, no clusters are deallocated in the FAT. The no longer referenced FAT chain will be reported as lost clusters if one of the RTF_CHK_LOST_CLUSTER... flags is specified. RTF_CHK_INVALID_CLUSTER_TRUNC can cause subsequent file size errors. |
RTF_CHK_CROSSLINK
RTF_CHK_CROSSLINK_TRUNC
RTF_CHK_CROSSLINK_DELETE |
RTFDiskCheck should look for cluster chain cross links (clusters referenced by more than one files or cluster chain loops). RTF_CHK_CROSSLINK_TRUNC causes the cluster chain to be terminated immediately before the cross-link. RTF_CHK_CROSSLINK_DELETE deletes the file. In both cases, no clusters are deallocated. The no longer referenced FAT chain will be reported as lost clusters if one of the RTF_CHK_LOST_CLUSTER... flags is specified. RTF_CHK_CROSSLINK_TRUNC can cause subsequent file size errors. |
RTF_CHK_FILESIZE_SMALL
RTF_CHK_FILESIZE_SMALL_TRUNC
RTF_CHK_FILESIZE_SMALL_DELETE |
RTFDiskCheck should check that a file does not occupy more clusters in the FAT than required according to the file's size given in the directory entry. Note that RTFExtend deliberately creates such preallocated long cluster chains. When RTF_CHK_FILESIZE_SMALL_TRUNC is specified, RTFDiskCheck fixes the problem by truncating the FAT chain such that it is no longer than required to hold the file's size bytes. RTF_CHK_FILESIZE_SMALL_DELETE, on the other hand, will delete the file. In both cases, no clusters are deallocated in the FAT. The no longer referenced FAT chain of the truncated or deleted file will be reported as lost clusters if one of the RTF_CHK_LOST_CLUSTER... flags is specified. |
RTF_CHK_FILESIZE_LARGE
RTF_CHK_FILESIZE_LARGE_TRUNC
RTF_CHK_FILESIZE_LARGE_DELETE |
RTFDiskCheck should check that a file size does not specify more bytes than are available in the file's FAT cluster chain. When RTF_CHK_FILESIZE_LARGE_TRUNC is specified, RTFDiskCheck fixes the problem by modifying the file size in the file's directory entry to reflect the length of the cluster chain in the FAT. RTF_CHK_FILESIZE_LARGE_DELETE will delete the file. If the file is deleted, no clusters are deallocated in the FAT. The no longer referenced FAT chain will be reported as lost clusters if one of the RTF_CHK_LOST_CLUSTER... flags is specified. |
RTF_CHK_LONG_FILENAME
RTF_CHK_LONG_FILENAME_REMOVE |
RTFDiskCheck should look for invalid of orphaned FAT long file name directory entries. If RTF_CHK_LONG_FILENAME_REMOVE is specified, such directory entries are freed. No files are deleted by this fix. Even if the long file name belongs to a still existing file (which is unlikely) the file is still addressable by its short name. This check is not performed on exFAT volumes. |
RTF_CHK_LOST_CLUSTER
RTF_CHK_LOST_CLUSTER_FREE |
RTFDiskCheck should look for lost clusters (clusters are marked as occupied in the FAT, but no file references them). If RTF_CHK_LOST_CLUSTER_FREE is specified, such clusters are freed. |
RTF_CHK_BITMAP
RTF_CHK_BITMAP_FIX |
RTFDiskCheck should compare the exFAT cluster bitmap with data it has found in the directories and the FAT. If RTF_CHK_BITMAP_FIX is applied, the bitmap is corrected. This flag group is ignored on FAT volumes. |
RTF_CHK_VERBOSE |
RTFDiskCheck should call the ErrorHandler callback for progress information. More information about the error handler is given below. |
RTF_CHK_ABORT |
RTF_CHK_ABORT should never be supplied as a parameter to RTFDiskCheck. However, it may be used as a return code from the ErrorHandler callback to immediately abort disk checking. RTFDiskCheck can take several minutes on large disks hosting many files, so aborting a long disk check may be desirable in some situations. Note that you should use RTF_CHK_VERBOSE to ensure that the ErrorHandler callback is called frequently to give the application a chance to abort. When RTFCheckDisk is aborted using this method, it returns RTF_ABORTED. |
return valueIf the function succeeds, the return value is RTF_NO_ERROR. If it fails, the return value is a negative error code. Note that RTF_NO_ERROR is also returned if errors have been found. An error is only returned if RTFCheckDisk was unable to complete, for example, due to a device driver error or the operation was aborted.
When RTFCheckDisk detects a file system error, it will call the ErrorHandler callback supplied by the application. The error handler can then decide if and how the error is to be fixed. The Flags parameter to the error handler corresponds to the Flags parameter passed to RTFCheckDisk with all flags of other checks masked out. The error handler must return the Flags value which RTFCheckDisk should use to fix (or not fix) the error. If it merely returns the Flags value passed to it, the default fix strategy as specified in the RTFCheckDisk call will be applied. This is the behavior RTFCheckDisk exhibits when a NULL error handler is supplied. Return value 0 can always be used if no fix is to be applied.
An error handler receives additional information about the error passed as parameters. It can, for example, display this information to the user and prompt for a fix strategy. The error handler's parameter interpretation depends on the error being reported:
Flags Value |
Other Parameters |
RTF_CHK_FAT_MISMATCH
RTF_CHK_FAT_MISMATCH_1
RTF_CHK_FAT_MISMATCH_2 |
Parameter Path points to the logical disk drive name (e.g. "\\.\C:") of the drive on which the error has been found. Parameters N1 and N2 are the physical sector indices of the FAT sectors which do not (but should) match. N1 is a sector of the master FAT. |
RTF_CHK_INVALID_DIR
RTF_CHK_INVALID_DIR_DELETE |
Parameter Path points to the full name of the file with the bad directory entry. Parameter FileInfo points to the erroneous directory entry. |
RTF_CHK_INVALID_CLUSTER
RTF_CHK_INVALID_CLUSTER_FREE |
Parameter Path points to the full name of the file referencing the invalid cluster. Parameter FileInfo points to its directory entry. Parameter N1 is the cluster index at which the offending cluster value was found. |
RTF_CHK_CROSSLINK
RTF_CHK_CROSSLINK_TRUNC
RTF_CHK_CROSSLINK_DELETE |
Parameter Path points to the full name of the file with the cross-link. Parameter FileInfo points to its directory entry. Parameter N1 specifies the cluster on which the file is cross-linked. |
RTF_CHK_FILESIZE_SMALL
RTF_CHK_FILESIZE_SMALL_TRUNC
RTF_CHK_FILESIZE_SMALL_DELETE |
Parameter Path points to the full name of the file with the suspect file size. Parameter FileInfo points to its directory entry. Parameter N1 is the file's size according to the directory entry while parameter N2 is its size according to the FAT. |
RTF_CHK_FILESIZE_LARGE
RTF_CHK_FILESIZE_LARGE_TRUNC
RTF_CHK_FILESIZE_LARGE_DELETE |
Parameter Path points to the full name of the file with the suspect file size. Parameter FileInfo points to its directory entry. Parameter N1 is the file's size according to the directory entry while parameter N2 is its size according to the FAT. |
RTF_CHK_LONG_FILENAME
RTF_CHK_LONG_FILENAME_REMOVE |
Parameter Path points to the full path of the invalid long file name. Only the part after the last backslash is invalid and would be removed. |
RTF_CHK_LOST_CLUSTER
RTF_CHK_LOST_CLUSTER_FREE |
Parameter Path points to the logical disk drive name (e.g. "\\.\C:") of the drive on which the error has been found. Parameter N1 is the first cluster of the lost cluster chain and N2 is its length in clusters. |
RTF_CHK_BITMAP
RTF_CHK_BITMAP_FIX |
Parameter Path points to the logical disk drive name (e.g. "\\.\C:") of the drive on which the error has been found. Parameter N1 is the first cluster of the not matching bitmap entry and N2 is its length in clusters. |
RTF_CHK_VERBOSE |
When the error handler's Flags parameter is equal to RTF_CHK_VERBOSE, no errors are reported. Rather, parameter Path points to a directory name being checked or one of the following text strings:
checking FAT...
searching lost clusters...
|
Demo programs RTFCmd and RTFCmdMT use RTFCheckDisk with a custom error handler.
Function RTFFormatExFAT
Function RTFCheckDiskBufferSize
|