Checking the integrity of a keyed file

kfcheck

Check the integrity of a keyed file


SYNTAX

kfcheck [-dhlqs] [-F tempfile] filename [filename]… | -iname [-iname]… filename

Verifies the integrity of keyed files and secondary indexes, reporting any damage and returning a count of the number of records in the file. The program may be run from the command line or by the Sculptor File Manager program ( Keyed file->Check menu option).

The kfcheck program verifies a keyed file index by checking that all record pointers are unique, and that any missing pointers belong to deleted records. Command line flags allow the program to be run with various options, including the checking of secondary indexes.

The kfcheck program should be run every time the system is switched on or, if the system is kept permanently on, it should be run once each day. It should also be run immediately after a system crash.

If kfcheck reports damage to a file index, use the kfri program to rebuild it from the data file. This program may also be used to rebuild secondary indexes. If the main file index is intact, the kfbuild program may be used to rebuild the secondary indexes from the main file index. Alternatively, undamaged files may be retrieved from a backup source. If the data file is also damaged, this is the only means of retrieval available.

Unless the -q option was used kfcheck reports an undamaged file using one of the following forms:

Checking filename - Okay (n records)

No damage found - record count given


Checking filename - Okay (n records + n deleted)

If the -d option was used, the number of deleted records is also reported.


filename

The name of the file to be checked. kfcheck accepts multiple filenames for checking provided that the -i option is not used. This option is for the purpose of specifying a particular secondary index or indexes to be checked, and may only be used if a single filename is specified.

Each filename should be the name of a Sculptor index file. The path must be specified if the file is not in the current working directory. The files are checked one by one in the order listed. Inclusion of the .k extension is optional. Use of the .k extension enables kfcheck to verify all the files in a directory; the form:

kfcheck *.k

can be used to achieve this.

[-dhlqs]
-iname
-F tempfile

Command line options.


Command line options

Option flags may be combined into a single flag string (-dsl3) or listed separately (-d -s -l3)

-d

Displays a count of deleted records as well as checked records. As Sculptor automatically reuses deleted record space, this number will reduce to zero as new records are inserted.

-h

Displays a help screen listing these options and the levels of integrity check available. No other action is taken, even if filenames and other flags are present.

-F tempfile

Places all messages that would normally be displayed on the terminal in the named file and suppresses all questions.

-iname

Specifies a secondary index to be checked (in addition to the main index, which is always checked). This option is only available if a single filename is specified. However, several different indexes for the specified file may be selected in this way, by repeating the -i option:

kfcheck -iname -inamefilename

This option is useful only in those cases where specific indexes are to be checked, and others excluded. To check all secondary indexes, use the -l flag to set a check level of 2 or higher.

-ln

Sets the integrity check level. l is the lower case letter L, and n must be a single integer in the range 0-4. The higher the integer, the more comprehensive the check, and the longer it takes to perform. The default is level 4 (full comprehensive check at all levels).

Integrity levels are cumulative, so that a check at level 2 automatically performs the checks at levels 0 and 1. The meanings of each level are:

0

Check file lengths and index header records.

1

Check the integrity of the main index.

2

Check the integrity of any secondary indexes.

3

Check the data file and secondary index key counts.

4

Read and check keys in secondary indexes (default).

A level 4 check is very comprehensive, and will take a long time when run on a large file which has several secondary indexes. A level 3 check will find all serious errors, and is adequate for checking file integrity on a daily basis. It is recommended however that a level 4 check is run once a week.

-q

Suppresses the output of all messages other than errors.

-s

Tells kfcheck to stop if any error condition is encountered. If more than one file name is specified, or if a wildcard character (such as *.k) is used, the error code returned refers to the last file processed only. This option is particularly useful if kfcheck is being run from within an automated routine. kfcheck stops on error and exits with a value indicating the error found. The error codes which may be returned are:

0

no error found

1

file is damaged

nnn

operating system error nnn encountered


Error messages

Invalid integrity level (range 0-4)

The level specified in a -ln option was invalid. n must be a single integer in the range 0-4.


name” : Not a secondary index

The secondary index “name” specified in a -i option was not found.


Checking filename - DAMAGED

There is damage to the index file named, which no longer relates accurately to the data file which it is supposed to index. Rebuild the index file from the data file using the kfri program. If the data file itself is damaged, it must be restored from a backup source.


Data dictionary is damaged

Restore the data dictionary (.d) file, and only this file, from the last backup. The data dictionary contains static information, and is not updated by applications. If the application has technical support, contact the support team.


File length not multiple of record length

This is fixed automatically by kfcheck, in order to avoid further damage. However, it has possible that records have been lost. The safest action is to restore from the last backup.


Key data wrong in record

The -l1 (or higher) option was specified, and the index file and data file key data are not identical. Use kfri to rebuild the index.


Incorrect number of keys in index
Index file length error
Index header record is corrupt
Keys missing from index
Out of range key count
Root index block in free chain

If any of these error messages is generated, run the kfri program to rebuild the index.

Various other error messages which may be generated relate to pointers which are missing, corrupt, out of range or duplicated. Unless kfcheck has also reported the error as FIXED, run the kfri program to rebuild the index from the data file. If in doubt, contact Sculptor Ltd. Please have details to hand of the error messages which were generated.


EXAMPLES

  1. Check all files in the directory “data”, placing messages in the file ‘tmpcheck’:

    kfcheck -F tmpcheck data\*.k
    
  2. Check the file “pairs” and three specified secondary indexes:

    kfcheck -iprx1 -iprx2 -iprx3 pairs
    
  3. Perform a level 0 check on two files, stopping if an error is found:

    kfcheck -s -l0 crystals diamonds
    
  4. Check all files and secondary indexes in current directory:

    kfcheck -l2 *.k
    
  5. Perform a level 3 check on a single file, reporting number of del eted records:

    kfcheck -d -l3 orders
    

RELATED TOPICS

Keyed file utilities

Sculptor keyed files

Data dictionary editor

File Manager

kfri