Cursory analyses of CBM readdir bug (was: [cc65] Re: readdir bug)

From: Spiro Trikaliotis <ml-cc651trikaliotis.net>
Date: 2012-09-22 20:15:15
Hello,

just a short follow-up for the reasons of this behaviour:

* On Fri, Sep 14, 2012 at 04:39:59PM +0200 I wrote:
 
> The dir file is not real file. Instead, it is implemented somehow
> "hacky" in the 1541. As normally, it is LOADed into RAM, this bug does
> not happen as LOAD reads the dir byte after byte, without any
> intervening actions. BUT: The test programs (Oliver's as well as mine)
> do other operations, which trigger the bug.

The directory read routine uses the same "directory file matcher" that
is also used when using other commands, or opening a file.

Thus, when an LOAD "$",8 is issued (or the equivalent), the 1541
rewrites it to LOAD "$:*",8 (cf. an older post by me).

Now, the 1541 analyses the command line, reads in the "*" and configures
the "directory" matcher to find all files that look like "*" - that is,
all files.

The directory read routine now matches one file after the other against
this matcher. If it matches (here, all do), then that file is output to
the directory channel.


If you read another file in between (for example, LOAD "file1",8), then
the matcher is reconfigured to find "file1". After the file has been
found, the matcher of the directory routine has switched to "file1".

Thus, subsequent calls do not find any more directory entries. Even
worse, the routine is so much confused because other variables have been
rewritten that it even outputs the directory header again. (I did not
check all the details, I only had a cursory look)


Now, you may ask, why do we still read 8 entries? I expect it to be
because the directory routine does not output one byte after the other;
instead, it fills a buffer and then lets the normal file processing take
place. This buffer has room for exactly 8 entries. Thus, after 8 entries
have been read, the next buffer to be filled gets confused and thus
outputs wrong bytes.

Again, this is a very cursory view, but it makes sense now.

Regards,
Spiro.

-- 
Spiro R. Trikaliotis
http://www.trikaliotis.net/
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Sat Sep 22 20:15:57 2012

This archive was generated by hypermail 2.1.8 : 2012-09-22 20:16:01 CEST