home *** CD-ROM | disk | FTP | other *** search
- #include <exec/types.h>
- #include <exec/execbase.h>
- #include <exec/nodes.h>
- #include <exec/resident.h>
- #include <exec/errors.h>
- #include <exec/semaphores.h>
- #include <devices/trackdisk.h>
-
- /*
- * Set SysBase to a local variable, that loads directly from 4 when it
- * has to be reloaded
- */
- #define BASE_EXT_DECL
- #define BASE_NAME (*(void **)4)
- #include <inline/exec.h>
-
- #include "device.h"
-
- /*
- * read a block from the cache, if it's stored there.
- * On success, return 1, else return 0.
- */
- int
- lookup_cache (struct scsi_unit *su, ulong block_num, ubyte *buf)
- {
- int i;
- struct cache_cb *ccb;
-
- for (i = 0, ccb = su->scu_ccb; i < CCB_PER_UNIT; ++i, ++ccb)
- {
- /* if the block is valid and the block number is right ? */
- if (ccb->ccb_usage>=0 && ccb->ccb_block_num == block_num)
- {
- CopyMem(ccb->ccb_buf, buf, UNIT_SEC_SIZE);
- ++ccb->ccb_usage;
- return 1;
- }
- }
- return 0;
- }
-
- /*
- * write a block into the cache. use the least used position
- */
- void
- update_cache (struct scsi_unit *su, long block_num, ubyte *buf)
- {
- int i, min_usage;
- struct cache_cb *ccb, *min_ccb;
-
- min_usage = 0x7fffffff; /* I'm pretty sure some ccb will beat this:-)) */
-
- for (i = 0, min_ccb = ccb = su->scu_ccb; i < CCB_PER_UNIT; ++i, ++ccb)
- {
- if (ccb->ccb_block_num == block_num)
- {
- /* in that case the usage-count doesn't matter, we update
- * "our" block .*/
- ++ccb->ccb_usage;
- CopyMem(buf, ccb->ccb_buf, UNIT_SEC_SIZE);
- return;
- }
- if (ccb->ccb_usage < min_usage)
- {
- min_usage = ccb->ccb_usage;
- min_ccb = ccb;
- }
- }
- /* so we'll have to overwrite the least used slot */
- min_ccb->ccb_block_num = block_num;
- min_ccb->ccb_usage = 0;
- CopyMem(buf, min_ccb->ccb_buf, UNIT_SEC_SIZE);
- }
-
- /*
- * This invalidates all cache blocks of this unit. Use this, if
- * you have a multi-block write, as its faster to invalidate the cache
- * than to split up the write to fit into our cache-management...
- */
- void
- invalidate_cache (struct scsi_unit *su)
- {
- int i;
- struct cache_cb *ccb;
-
- for (i = 0, ccb = su->scu_ccb; i < CCB_PER_UNIT; ++i, ++ccb)
- ccb->ccb_usage = -1;
- }
-
-