SD Core Solo for Linux LS2.0-0

sdidx, the Index Relocation Tool

Reporting where a hashed file's indexes are kept, moving them to another directory or back, pointing a file at indexes you have moved yourself, and deleting them: every option, and what each does to the disk.

An index on an SD hashed file lives in an extra file beside the data, %2 for the file's first index, %3 for the next, up to 32 in all. Normally it sits in the data file's own directory. An index can instead be kept in another directory, relocated, which is how an index is put on a faster or larger disk. The data file's header records where. sdidx is the stand-alone program that reads and changes that record and moves the files. It works on the files on disk, not through SD.

You can relocate an index at creation from SD: create.index file field pathname path. sdidx is for everything after that, and for the case where SD is not running.

The short version#

sdidx -q ~/SDCoreSolo/user_accounts/sduser/orders  # where are its indexes?

Where it is and who can run it#

~/SDCoreSolo/bin/sdidx (or bin/sdidx under the --home you gave the installer). It is not on your PATH, so type the full path. It opens the file's %0 for read and write even to answer -q, so you need write access to the file even to ask where its indexes are (on a copy with the write permission removed, -q prints Cannot open data file [13] and exits 1). Run it as yourself, the user who owns the SD directory: SD Core Solo for Linux has no other. Files it creates (-m copies the index to a new file) belong to whoever runs it, with that user's umask, so do not run it as root: a run as root leaves root-owned index files in your tree that you cannot then write, and Solo itself refuses to run as root for the same reason.

It needs no configuration file and takes no option other than the mode.

The command line#

sdidx -d datapath             delete the indexes
sdidx -m datapath {akpath}    move the indexes to akpath (or back, if omitted)
sdidx -p datapath {akpath}    set the index path in the header, move nothing
sdidx -q datapath             report where the indexes are
sdidx datapath                the same as -q

Give exactly one mode. Letters are not case sensitive, and only the second character of a word is read, so -qx is -q. Anything else, two modes, an extra argument or no path prints the five usage lines above and exits 1. A datapath is the OS path of the file's directory, not an SD file name. A path that does not exist, or is not an SD hashed file, gives Cannot open data file [2] and exit 1.

Every run prints the banner. Success exits 0; any failure exits 1.

-q, report#

$ sdidx -q orders
Indices are not relocated
$ sdidx plain
File has no indices
$ sdidx orders          (after a move)
Index directory is /tmp/sdi_demo/orders.idx

The three answers are the only ones. It changes nothing.

-m, move#

$ sdidx -m orders /tmp/sdi_demo/orders.idx
Moving index subfile 2
Indices have been moved

What it does, in order: refuses if the file is open in SD; stops with Indices are already at this location if akpath is where they are; checks that each index file really belongs to this data file (it compares a creation stamp in both headers, and says Index subfile n does not appear to belong to the data file or Incorrect magic number if not); refuses with akpath already exists if the target is there; creates the target directory, and any missing parents (a/b/c was made from nothing); copies each index file to the new place; writes the new path into the data header; then deletes the old index files. If it stops before the header is written, the copy at the target is left behind and the file is as before.

If the target directory cannot be made, it says so and changes nothing. It prints Cannot create directory akpath: and the reason on standard output, and ends with status 1. The reason is the operating system's (for a parent you cannot write: Permission denied), or a file of that name exists when a component of the path is a file. akpath in the message is the whole path as you typed it, not the component that failed, and the indexes and the header are where they were. (An ordinary user meets the first on a parent with mode 555 and the second on a path through a regular file.)

-p, point#

-p writes the path into the header and moves nothing. Use it when you have moved the index files yourself (or restored them elsewhere) and only the header is out of date.

-d, delete#

$ echo y | sdidx -d o4
Delete the index files in /tmp/sdi_demo/o4.idx (Y/N)? All indices deleted

The result is a file with no indexes: the header's index map is cleared. To get the indexes back you create them and build them again with create.index and build.index.

The check that SD does not have the file open#

sdidx attaches to SD's shared memory when SD is running and looks through the table of open files for the data directory's resolved path. If it finds one in use it prints File is currently open within SD and exits 1, for every mode, -q included. While a program in SD has the file open, sdidx -q and -m on it are refused; after the program closes the file they work.

That is all it does. It does not look for a file held by another program, by sdfix or by sdconv, and when SD is not running it checks nothing. Do not run it while any of those has the file.

What it will not do#