SD Core Solo for Linux LS2.0-0

sdfix, the File Check Tool

Checking a hashed file's structure on disk, repairing what it can, recovering space and clearing dead space: when to run it, every option, and what it does to the file.

sdfix is a stand-alone program, not an SD command. It reads and, with the right options, rewrites the files of an SD hashed file directly on disk, without going through SD. Use it when you suspect a file's structure is damaged (after a crash, a full disk, a restore from a bad copy), or to give a file back disk space it no longer needs. It has no effect on a file that is sound.

The short version#

back up the file, close it everywhere (or stop SD), then:
~/SDCoreSolo/bin/sdfix ~/SDCoreSolo/user_accounts/sduser/orders    # a check; changes nothing

Where it is and who can run it#

~/SDCoreSolo/bin/sdfix (or bin/sdfix under the --home you gave the installer). It is not on your PATH, so type the full path. The program opens the file's subfiles for read and write: you need write access to them, even for a check, which you have for everything under your own SD directory. Without it the file is reported as No SD hashed files found matching given name(s) (a copy with the write permission removed), which is easy to misread as "not an SD file".

Do not run it as root, or with sudo. New files are created with the owner and umask of whoever runs the program. -R writes a new overflow subfile (%1) and renames it into place, so after a run as root that file belongs to root and you may no longer be able to write it; SD Core Solo for Linux itself refuses to run as root for the same reason.

It reads the configuration file named by the environment variable SD_CONFIG or else sd.conf in the SD directory (Solo finds that directory from the program's own path), and stops with "path not found" if it cannot read it. The only item it looks at is DEBUG (see Interactive mode).

The command line#

sdfix {options} pathname ...

A pathname is the file's directory, as an operating system path, not an SD file name and not a VOC entry. Options start with -, may be joined in one word (-BF), and are not case sensitive. Several files may be named; each is processed in turn. A path that is not an SD hashed file is skipped, with only the line SDFIX processed: name Status: 1, and if none was found the program says No SD hashed files found matching given name(s).

Option What it does
-C Check the file. This is the default when no other mode is given.
-F Check, and fix every error it knows how to fix, without asking. Not combinable with -Q.
-Q Check, and ask Fix? at each error it knows how to fix. Answer y or n. Not combinable with -F.
-R Recover disk space: shrink the primary subfile and rewrite the overflow subfile with the free blocks squeezed out. Not combinable with -F or -Q: -r cannot be combined with -f or -q: run the fix first, then -r on its own, status 1, and the file is not touched. Add -C or -Z to make it check first.
-Z Clear the dead space at the end of each group (implies -C). Writes to the file.
-B No progress bar. Use it when you log or redirect, since the bar is drawn with carriage returns.
-V Verbose. Changes the output of -R only; it does nothing to a check. Not listed in the usage text.
-L Log everything the program prints, except the banner, to sdfix.log in the current directory.
-Lname The same, to the file name. The rest of the word is the name, so put -L last in a joined word (-BLcheck.log). An existing log is overwritten.
-I Interactive mode. Refused unless the configuration file sets DEBUG with bit 2 on. Not listed in the usage text. See below.

The usage text printed for a bad option names only -F, -L, -Q, -R and -Z; -B, -C, -V and -I work but are not listed.

Exit status. The program's status is 0 if every pathname could be processed and 1 if any of them could not: it was not a hashed file, was open in SD, could not be opened, had a path too long for its index subfile names, or its overflow subfile had a wrong magic number (the status is that of every pathname, so a refused file followed by a good one still ends 1). Finding and even fixing errors gives 0. Each file also prints a line SDFIX processed: name Status: n.

A path of 252 characters or more is refused: The path is too long: the name of the last index subfile does not fit in 255 characters, Status: 1, and nothing more is read. The check looks for index subfiles under all 32 possible names, and with a path this long the names of AK 8 and up do not fit. The same applies to the relocated index directory, if the header names one.

Paging, and what happens when input runs out#

Output stops every 24 lines with Press return to continue... (the program reads standard input one character; q quits, s stops paging). The Fix? and Dump and rebuild questions also read standard input.

If standard input ends while -Q is asking Fix?, the end of input is taken as n: the program prints Fix? N (end of input), repairs nothing, and carries on with the check without waiting for any further answer. At the Press return pause the end of input means "stop paging". The Dump and rebuild question uses the same routine. To answer the questions from a script, feed every answer, starting with s to stop the paging: printf 'sY' | sdfix -B -Q file.

A check, with nothing wrong#

$ sdfix zzcust
[ SDFIX LS2.0-0   Copyright, Ladybridge Systems, 2007.  All rights reserved. ]

Processing zzcust
Checking file header...
Checking data groups...
*************************-------------------------| 1/2**************************************************| 2/2
Checking free chain...
Checking for unreferenced blocks...
0 overflow blocks allocated, 0 on free chain
 SDFIX processed:  zzcust   Status: 0

The row of asterisks is the progress bar: it is redrawn on one line and appears like this when the output is captured. A file that has indexes adds Checking AK 0, Checking AK free chain and Checking I-type chain.

Fixing errors#

Suppose a file's minimum modulus and its header record count are wrong. A check reports them and changes nothing:

Minimum modulus is invalid (1660944384)
Record count error: Actual 000000000040, file header (adjusted) 000117440511

With -Q, answering n and then y:

Minimum modulus is invalid (1660944384)
Fix? N
Record count error: Actual 000000000040, file header (adjusted) 000117440511
Fix? Y
   Corrected by updating header

The first error is still there on the next run; the second is gone. -F does the same for every error, with no questions (Corrected by resetting to 1). Which errors can be fixed, and how, is on the next page of this set, sdfix: what it checks and repairs. That page also covers the dump-and-rebuild of mis-hashed groups, interactive mode, and what the tool will not do.

Recovering space with -R#

A file that once held 3,000 records and now holds 305 keeps all the disk it grew to: %0 was 428,032 bytes and %1 223,232.

$ sdfix -B -R zzbig
Processing zzbig
Recovering space
Overflow subfile contracted to 32768 bytes
 SDFIX processed:  zzbig   Status: 0

Afterwards %0 was 69,632 bytes and %1 32,768. The 305 records were read back through SD and all were present and the right length (the five long records among them). -V adds a line for every block it moves.

-R rewrites the file in place and is the most dangerous option.

Clearing dead space with -Z#

When a record is deleted or shortened, the bytes after the used part of a block keep their old text. -Z zeroes them. It does not change a record. It makes a file compress better and stops old text lingering in a backup, and the file works the same without it.

$ sdfix -B -Z zzbig
...
Dead space cleared in 18 block(s)
...
$ sdfix -B -Z zzbig
Dead space cleared in 0 block(s)

It walks the groups in the primary subfile and the overflow blocks chained from them. It does not clear free overflow blocks (those on the free chain), and it does not visit the blocks that hold a large record's data. Unlike a plain check it writes, so back up and close the file first, as for -F.

Writing it down#

Give -L when a run matters, so there is a record:

sdfix -B -F -Lfix-20261019.log ~/SDCoreSolo/user_accounts/sduser/orders

The log has everything but the banner and the progress bar, and the lines SDFIX processed: name Status: n.