## Name

DCHECK — Check Disk File Structure

## Synopsis

`dcheck` [ `-opts` ] `devnam`

## Description

It is possible for sectors on a disk to be marked as being allocated but in fact are not actually associated with a file or the disk's free space. This can happen if a disk is removed from a drive while files are still open, or if a directory which still contains files is deleted (see the section called “Deleting Directory Files”). Dcheck is a diagnostic that can be used to detect this condition, as well as the general integrity of the directory/file linkages.

Dcheck is given as a parameter the name of the disk device to be checked. After verifying and printing some vital file structure parameters, dcheck follows pointers down the disk's file system tree to all directories and files on the disk. As it does so, it verifies the integrity of the file descriptor sectors, reports any discrepancies in the directory/file linkages, and builds a sector allocation map from the segment list associated with each file. If any file descriptor sectors (FDs) describe a segment with a cluster not within the file structure of the disk, a message is reported like:

    *** Bad FD segment ($xxxxxx-$yyyyyy) for file: pathlist

This indicates that a segment starting at sector xxxxxx and ending at sector yyyyyy cannot really be on this disk. Because there is a good chance the entire FD is bad if any of it's segment descriptors are bad, the allocation map is not updated for corrupt FDs.

While building the allocation map, dcheck also makes sure that each disk cluster appears only once and only once in the file structure. If this condition is detected, dcheck will display a message like:

    Cluster $xxxxxx was previously allocated

This message indicates that cluster xxxxxx has been found at least once before in the file structure. The message may be printed more than once if a cluster appears in a segment in more than one file.

The newly created allocation map is then compared to the allocation map stored on the disk, and any differences are reported in messages like:

    Cluster $xxxxxx in allocation map but not in file structure
    Cluster $xxxxxx in file structure but not in allocation map

The first message indicates sector number xxxxxx (hexadecimal) was found not to be part of the file system, but was marked as allocated in the disk's allocation map. In addition to the causes mentioned in the first paragraph, some sectors may have been excluded from the allocation map by the FORMAT program because they were defective or they may be the last few sectors of the disk, the sum of which was too small to comprise a cluster.

The second message indicates that the cluster starting at sector xxxxxx is part of the file structure but is not marked as allocated in the disk's allocation map. It is possible that this cluster may be allocated to another file later, overwriting the contents of the cluster with data from the newly allocated file. Any clusters that have been reported as “previously allocated” by dcheck as described above surely have this problem.

Available dcheck options are:

-w=`path` | pathlist to directory for work files
-p | print pathlists for questionable clusters
-m | save allocation map work files
-b | suppress listing of unused clusters
-s | display count of files and directories only
-o | print dcheck's valid options

The “-s” option causes dcheck to display a count of files and directories only; only FDs are checked for validity. The “-b” option suppresses listing of clusters allocated but not in file structure. The “-p” option causes dcheck to make a second pass through the file structure printing the pathlists for any clusters that dcheck finds as “already allocated” or “in file structure but not in allocation map”. The “-w=” option tells dcheck where to locate it's allocation map work file(s). The pathlist specified must be a FULL pathlist to a directory. The directory “/D0” is used is used if “-w” is not specified. It is recommended that this pathlist NOT be located on the disk being dchecked if the disk's file structure integrity is in doubt.

Dcheck builds its disk allocation map in a file called `pathlist`/DCHECKpp0, where `pathlist` is as specified by the “-w=” option and pp is the process number in hexadecimal. Each bit in this bitmap file corresponds to a cluster of sectors on the disk. If the “-p” option appears on the command line, dcheck creates a second bitmap file (`pathlist`/DCHECKpp1) that has a bit set for each cluster dcheck finds as “previously allocated” or “in file structure but not in allocation map” while building the allocation map. Dcheck then makes another pass through the directory structure to determine the pathlists for these questionable clusters. These bitmap work files may be saved by specifying the “-m” option on the command line.

## Restrictions

For best results, dcheck should have exclusive access to the disk being checked. Otherwise dcheck may be fooled if the disk allocation map changes while it is building its bitmap file from the changing file structure. Dcheck cannot process disks with a directory depth greater than 39 levels.

For more information see: the section called “Physical File Organization”, the section called “Deleting Directory Files”, format, 6.1 of OS-9 Systems Programmer's Manual

## Examples

    OS9: dcheck /d2   (workfile is on /D0)

    Volume - 'My system disk' on device /d2
    $009A bytes in allocation map
    1 sector per cluster
    $0004D0 total sectors on media
    Sector $000002 is start of root directory FD
    $0010 sectors used for id, allocation map and root directory
    Building allocation map work file...
    Checking allocation map file...

    'My system disk' file structure is intact
    1 directory
    2 files

    OS9: dcheck -mpw=/d2 /d0
    Volume - 'System disk' on device /d0
    $0046 bytes in allocation map
    1 sector per cluster
    $00022A total sectors on media
    Sector $000002 is start of root directory FD
    $0010 sectors used for id, allocation map and root directory
    Building allocation map work file...
    Cluster $00040 was previously allocated
    *** Bad FD segment ($111111-$23A6F0) for file: /d0/test/junky.file
    Checking allocation map file...
    Cluster $000038 in file structure but not in allocation map
    Cluster $00003B in file structure but not in allocation map
    Cluster $0001B9 in allocation map but not in file structure
    Cluster $0001BB in allocation map but not in file structure

    Pathlists for questionable clusters:
    Cluster $000038 in path: /d0/OS9boot
    Cluster $00003B in path: /d0/OS9boot
    Cluster $000040 in path: /d0/OS9boot
    Cluster $000040 in path: /d0/test/double.file

    1 previously allocated clusters found
    2 clusters in file structure but not in allocation map
    2 clusters in allocation map but not in file structure
    1 bad file descriptor sector

    'System disk' file structure is not intact
    5 directories
    25 files