www.beck-ipc.com

@CHIP-RTOS - CHKDSK Shell Command Operation


    IPC@CHIP® Documentation Index

CHKDSK

The primary function of the CHKDSK command is to survey the disk's File Allocation Table (FAT) to determine if any clusters are allocated which do not belong to any file or directory. Such clusters are considered "lost".   Lost clusters can result from power being lost at the moment a file or directory was being updated on the disk.

For external drives, a status message indicating whether or not the "Clusters are aligned/misaligned with device flash pages " will appear, provided that the device driver in use offers the required extended service.   Currently this alignment check is only applied to SD cards.   If misaligned, a FORMAT action is recommended in order to slightly improve the card's performance and reduce the wear resulting from writes.

When CHKDSK is used with the /F command line option, the FAT entries for lost clusters will be marked free to restore them to the disk's available free space.

CHKDSK can be invoked using the BIOS_ExecuteExt() API with results reported in a DiskStatS object allocated by the user.

Assuming that no critical errors (e.g. "File system resources not available") occur during the CHKDSK operation, a count of lost and bad clusters will be reported to the console upon completion of the scan. For large drives, this scan may require some significant time.   The demand for system memory can be high for large drives with a high number of clusters (requirement: 1 byte per 8 clusters).

The CHKDSK scan also checks for various other fault conditions within the disk's FAT.   The following set of messages may appear if any of these unlikely faults are detected.

Invalid cluster numbers:

    FAT entries must be either particular flag values or reference an existing cluster number.   This is the number of cluster numbers read from the FAT which were neither.   When the /F command line option is used, these FAT entries will be changed to terminate the respective file's cluster chain at this point.
Corrupt long file names (LFN):
    Long file names are stored in directories over multiple directory entries preceding the entry for which a long name applies.   For each file (or directory) found whose long file name was corrupt, this count will be incremented.   When the /F command line option is used, these LFN nodes will be deleted.   The corresponding file then will only have its short 8.3 alias name to go by.
Bad LFN DIR nodes:
    This is the number of long file name entries which were invalid.   When the /F command line option is used, these LFN nodes will be marked as deleted.
Invalid . or .. directory entry:
    This count is incremented each time a . directory node does not reference that directories own first cluster or when the .. directory entry does not reference the parent directory's first cluster In either case, when the /F command line option is used, these link nodes will be corrected to reference the proper cluster.
FAT0/FAT1 mismatch:
    For drives with more than a single FAT, the FAT0 and FAT1 are compared block by block. These should match. Any mismatches are reported. When the /F command line option is used, the FAT0 block will be copied into FAT1 for any mismatching sectors. If the block write verify done here indicates that the write was not successful, a count with a "FAT block write failure" message will appear.

If any of the following unexpected errors is reported, then a disk reformat is recommended.   (The CHKDSK /F command line option does not remedy these faults.)

Cluster in use but not allocated:

    A first cluster in a directory or file was not marked in the FAT as allocated.
The . or .. directory entry repeated:
    Each directory must have at most one self (.) reference and one parent directory (..) reference.   This error count is incremented when ever multiple occurrences of either of these special directory link nodes is seen.
Clusters in more than a single chain:
    This is the number of times where a FAT entry references a cluster which has already been referenced by some other FAT entry.   This is an illegal condition.
Directory depth limit exceeded:
    This is the number of times that the subdirectory depth exceeded the limit placed on the file system by the maximum path string length limit of 260 characters.   This error being detected is highly unlikely.   It will cause the remainder of the CHKDSK operation to be incomplete.
Infinite loop in file's cluster chain:
    This count is incremented for each file encountered which had a cluster chain which closed on itself.
File too short:
    A file's cluster chain was not long enough to provide the number of bytes stated in that file's directory node.
File too long:
    A file's cluster chain was longer than the number of bytes stated in that file's directory node.




End of document