Repository navigation
Copying files into a large image was slow to the point of being unusable under a
virtual machine, and a freshly created empty directory could not be entered in
Total Commander. Both are fixed.
Polski opis projektu: README.pl.md
Why copying was slow
Copying twenty files into a 16 MB image took a few seconds in Double Commander on
macOS and was estimated at two hours in Total Commander under Parallels on
Apple Silicon. The difference was not the amount of data but the number of system
calls: a 16 MB image is 65535 sectors, and the code read and wrote one sector at
a time — 65535 individual calls on every open and every save. Each call costs a
fraction of a microsecond on a local disk, which is why it never showed on macOS;
run the same calls through x64 emulation on ARM Windows, with an antivirus
scanner in the path, and the same work takes hours.
Three changes, measured on a 16 MB image:
| Before | After | |
|---|---|---|
| Listing a directory of 24 entries | 26 ms | 2 ms |
| 120 custom-column cells (24 rows × 5 fields) | 2611 ms | 72 ms |
| Copying 20 files in | 1973 ms | 123 ms |
- Bulk reads and writes. Short boot sectors still go one by one — they occupy
128 bytes in the file but a full sector in memory — and everything after them is
one read and one write. - Only changed sectors are written. A save used to write the whole image
through a temporary file. Changed sectors are now found by comparing against the
state at load time — a comparison rather than dirty flags, because the file
system code writes straight through a sector pointer and a single missed flag
would be silent data loss. The cost is atomicity: an interrupted write now
leaves the image partly changed, where the temporary-file route left the
original untouched. Only the plugins enable this;atrtoolkeeps the safe
route, since one command is one save there and there is nothing to gain. - The image is not re-read for every panel cell. Custom columns are a file
system plugin feature, and the file manager asks for each field of each row in a
separate call — every one of which used to load the whole image. Entering a
directory of 24 files meant 120 loads, close to two gigabytes of reading. The
columns only need the directory entry, so the listing and the image bytes are
now cached, keyed by the file's size and modification time so that changing the
image from outside — withatrtool, for instance — invalidates the cache by
itself. Access is guarded by a lock, because the file manager reads columns from
a separate thread.
Entering an empty directory in Total Commander
A newly created directory could not be opened in Total Commander: clicking it did
nothing, with no message. It worked in Double Commander, so the fault was in the
protocol rather than in reading the image.
FsFindFirst has no first entry to return for an empty directory, so it returns
an invalid handle — exactly what it returns on failure. Total Commander tells the
two apart by the last error code: ERROR_NO_MORE_FILES means "empty" and the
panel simply shows nothing, anything else means "cannot open" and entry is refused
silently. The plugin never set that code. Double Commander treats an invalid
handle as an empty directory, which is why the defect was invisible there.
Empty directories now report ERROR_NO_MORE_FILES, and genuine failures — a bad
path, an image that will not open, an exception — report ERROR_PATH_NOT_FOUND,
so a broken image is reported as broken instead of appearing empty.
One subtlety worth recording, because the first fix did not work: freeing memory
overwrites the last error code on Windows, and local strings and objects are
finalized after the last statement of a function — that is, after the
SetLastError call. The listing body now returns its status through a thread
variable and the exported wrapper, which has no managed locals of its own, sets
the code. A test asserting the error code on Windows caught the first attempt;
without it the defect would have shipped twice with the same symptom, since the
whole path is compiled out on macOS.
Tests
Two additions guard what plain pass/fail results cannot see:
- a counter of actual image loads, asserted against 125 column queries — a
regression here would show up only as time, never as a wrong answer; - the empty-directory path end to end: create a directory, enter it, check the
error code (on Windows), copy a file into it.
The 1705-image corpus still round-trips identically — 1689 byte-for-byte, none
differing — which is what makes the rewritten read and write paths safe to trust.
The WFX harness is at 115 checks.