Page 1 of 1

FDD cache

Posted: Mon Oct 24, 2005 7:55 am
by HanzZ
Hi :),
I am writing floppy driver and he goes right. But i have one problem.
If I read some sectors from floopy => change diskette => and read sectors again, I will get the same sectors (sectors from first diskette..not from second diskette)...
I think, that problem is with cache of floppy... How can I delete data from cache... If problem is otherwhere, tell me ;)

thanks ;)

(I am OS novice ;) )

Re:FDD cache

Posted: Mon Oct 24, 2005 10:50 am
by Pype.Clicker
well, you may want to force your user to tell the system when they remove the floppy ... or check if the "disk changed" status is somehow reliable ...

Re:FDD cache

Posted: Mon Oct 24, 2005 7:13 pm
by Xardfir
Do it the DOS way. It's slow but reliable.

On any non-sequential operation read track 0.
Compare the volume number ID with the previous request, if it doesn't match then put up a box demanding the previous disk.
If the user hits cancel, try to exit gracefully. Apple 2, Commodore and CP/M all suffered problems because they didn't check the disk.

I would also reccommend not using the floppy controllers 'disk change' feature. A lot of mass produced floppy drives don't implement it correctly. The only way to make sure (if you want to use it) is have the user change disks during installation of your OS and then decide. Microsoft Backup for MSDOS did this, and only 1 of 3 computers I used Backup on supported the disk change notification correctly.

Re:FDD cache

Posted: Tue Oct 25, 2005 3:15 am
by Pype.Clicker
The alternative being to be unix-like: user mounts floppy before she can access it and knows (because she read the f*** manual) that if she changes the floppy without unmounting first, Bad Things (tm) are going to occur ...

Now of course, if your average user looks more like Mr. Anykey, your system will be unusable for him ... all depend. Do you expect Mr. Anykey to know how to insert a floppy in 2005, anyway ?

(writing this post makes me feels the urge to start a USB support for clicker :)

Re:FDD cache

Posted: Tue Oct 25, 2005 7:38 am
by HanzZ
thanks ;D
now I can detect floppy disk change, but I don't know, what I have to do, when i detect disk change... how can i clear cache memory in floppy controller? I haven't any idea...

Re:FDD cache

Posted: Tue Oct 25, 2005 8:02 am
by Solar
Xardfir wrote: On any non-sequential operation read track 0.
Compare the volume number ID with the previous request, if it doesn't match then put up a box demanding the previous disk.
If the user hits cancel, try to exit gracefully. Apple 2, Commodore and CP/M all suffered problems because they didn't check the disk.
Ahem... I assume you refer to Commodore PC.

Commodore Amiga checked the volume ID of the disk every three seconds or so. That allowed to sense disk changes automatically, and if there were unwritten buffers, it popped a requester asking you to insert the previous disk or lose data.

Re:FDD cache

Posted: Tue Oct 25, 2005 8:05 am
by Pype.Clicker
Well, that all depends on how you built your cache. I assume you don't simply grab 1.44 MB of physical ram for floppy caching, right ? you have something like

Code: Select all

struct FloppyCache {
    FloppyTrack *cache[TRACKS_ON_DISK];
    // initialize this with NULLs
};

void fillCache(struct FloppyCache* fc, trackno)
{
    if (fc->cache[trackno]) return; // in cache already;
    fc->cache[trackno]=alloc(MEM_DMA_CAPABLE,sizeof(FloppyTrack));
    floppy_load_track(fc->cache[trackno],trackno);
    return;
}

void clearCache(struct FloppyCache *fc)
{
    for (int i=0;i<TRACK_ON_DISK;i++) {
        if (fc->cache[i]) free(fc->cache[i]);
        fc->cache[i]=NULL;
    }
}

Re:FDD cache

Posted: Tue Oct 25, 2005 9:31 pm
by Xardfir
Hiya,
@ Solar:
My apologies for my Commodore ambiguity (I have adopted 3 Amiga 500's myself). My reference was to the less capable 1541/2 and 1570 series of Commodore disk drives running their own version of Commodore Dos.
The only redeeming feature of the 1570 was that it could write CP/M disks which could be read on a PC (using CP/M 86).

@ HanzZ:
As for caching, might I suggest looking at the DMA page in the OSFAQ, as it provides a way of using the DMA to supply a track cache for the floppy disk in hardware. Less code for you to write, let the hardware do the work.

Re:FDD cache

Posted: Tue Oct 25, 2005 10:27 pm
by Brendan
Hi,
Xardfir wrote:The only redeeming feature of the 1570 was that it could write CP/M disks which could be read on a PC (using CP/M 86).
These disk drives aren't disk drives - they're more like mini file servers (you could connect several computers to one of them, and the computer/s send commands rather than messing about with low level sector addressing stuff).

They also made better use of the media (more sectors on outer tracks) and allowed custom code to be uploaded.


Cheers,

Brendan