void LTDCInitCache(U8 size_in_U1s) { LTCacheBlk *tempc; U8 i,cnt; BoolU4 old_preempt=Preempt(OFF); AFree(ltcd_base); AFree(ltdc_hash_table); if (size_in_U1s<0x2000) { ltcd_base=NULL; ltdc_hash_table=NULL; Preempt(old_preempt); return; } ltcd_base=AMAlloc(size_in_U1s); ltdc_next_lru=<dc_next_lru; ltdc_last_lru=<dc_next_lru; cnt=MSize(ltcd_base)/sizeof(LTCacheBlk); ltdc_size=cnt*BLK_SIZE; for (i=0;inext_hash=tempc; tempc->last_hash=tempc; tempc->flags=0; } ltdc_hash_table=AMAlloc(LTDC_TABLE_SIZE<<4); for (i=0;inext_hash=tempc; tempc->last_hash=tempc; } Preempt(old_preempt); } U8 LTDCHash(U8 blk) { U8 i=blk & (LTDC_TABLE_SIZE-1); return ltdc_hash_table+i<<4-offset(LTCacheBlk.next_hash); } void LTDCRemQue(LTCacheBlk *tempc) { BoolU4 old_preempt=Preempt(OFF); if (!ltcd_base) { Preempt(old_preempt); return; } RemQue(tempc); tempc->next_hash->last_hash=tempc->last_hash; tempc->last_hash->next_hash=tempc->next_hash; Preempt(old_preempt); } void LTDCInsQue(LTCacheBlk *tempc) { LTCacheBlk *temp_n,*temp_l; BoolU4 old_preempt=Preempt(OFF); if (!ltcd_base) { Preempt(old_preempt); return; } InsQue(tempc,ltdc_last_lru); temp_l=LTDCHash(tempc->blk); temp_n=temp_l->next_hash; tempc->last_hash=temp_l; tempc->next_hash=temp_n; temp_l->next_hash=tempc; temp_n->last_hash=tempc; Preempt(old_preempt); } LTCacheBlk *LTDCFindBlk(LTPartition *p,U8 blk) { BoolU4 old_preempt=Preempt(OFF); LTCacheBlk *tempc, *tempc1=LTDCHash(blk); if (!ltcd_base) { Preempt(old_preempt); return NULL; } tempc=tempc1->next_hash; while (tempc!=tempc1) { if (tempc->p==p && tempc->blk==blk) { Preempt(old_preempt); return tempc; } tempc=tempc->next_hash; } Preempt(old_preempt); return NULL; } void *LTDCAdd(LTPartition *p,U1 *buf, U8 blk, U8 cnt) { LTCacheBlk *tempc; BoolU4 old_preempt=Preempt(OFF); if (!ltcd_base) { Preempt(old_preempt); return NULL; } while (cnt--) { tempc=LTDCFindBlk(p,blk); if (!tempc) tempc=ltdc_next_lru; LTDCRemQue(tempc); MemCpy(&tempc->body,buf,BLK_SIZE); tempc->p=p; tempc->blk=blk++; LTDCInsQue(tempc); buf+=BLK_SIZE; } Preempt(old_preempt); } void LTDCInvalidate(LTPartition *p) { BoolU4 old_preempt=Preempt(OFF); LTCacheBlk *tempc=ltdc_last_lru,*tempc1; if (!ltcd_base) { Preempt(old_preempt); return NULL; } while (tempc!=<dc_next_lru) { tempc1=tempc->last_lru; if (tempc->p==p) { LTDCRemQue(tempc); tempc->p=NULL; tempc->blk=0; tempc->next_hash=tempc; tempc->last_hash=tempc; InsQue(tempc,ltdc_last_lru); } tempc=tempc1; } Preempt(old_preempt); return NULL; } void RCache(LTPartition *p,U1 **buf, U8 *blk, U8 *cnt) { BoolU4 old_preempt=Preempt(OFF); LTCacheBlk *tempc; if (!ltcd_base) { Preempt(old_preempt); return NULL; } while (*cnt) { tempc=LTDCFindBlk(p,*blk); if (tempc) { MemCpy(*buf,&tempc->body,BLK_SIZE); *cnt-=1; *buf+=BLK_SIZE; *blk+=1; } else break; } while (*cnt) { tempc=LTDCFindBlk(p,*blk+*cnt-1); if (tempc) { MemCpy(*buf+(*cnt-1)<body,BLK_SIZE); *cnt-=1; } else break; } Preempt(old_preempt); } BoolU8 RAMRBlks(LTPartition *p,U1 *buf,U8 blk,U8 cnt) { LTBlkDev *bdev=p->bdev; CheckLTBlkDev(bdev); MemCpy(buf,bdev->RAM_disk+blk<bdev; CheckLTBlkDev(bdev); MemCpy(bdev->RAM_disk+blk<bdev; CheckLTBlkDev(bdev); if (!bdev->f) throw(EXCEPT_PARTITION,5); if (!FRBlks(bdev->f,buf,blk,cnt)) throw(EXCEPT_PARTITION,6); FSync(bdev->f); return TRUE; } BoolU8 FileWBlks(LTPartition *p,U1 *buf,U8 blk,U8 cnt) { LTBlkDev *bdev=p->bdev; CheckLTBlkDev(bdev); if (!bdev->f) throw(EXCEPT_PARTITION,7); if (!FWBlks(bdev->f,buf,blk,cnt)) throw(EXCEPT_PARTITION,8); FSync(bdev->f); return TRUE; } BoolU8 NonLTFileRBlks(LTPartition *p,U1 *buf,U8 blk,U8 cnt) { LTBlkDev *bdev=p->bdev; LTPartition *bp=DriveToPartition(bdev->non_lt_drive); CheckLTBlkDev(bdev); return bp->RBlks(bp,buf,blk,cnt); } BoolU8 NonLTFileWBlks(LTPartition *p,U1 *buf,U8 blk,U8 cnt) { LTBlkDev *bdev=p->bdev; LTPartition *bp=DriveToPartition(bdev->non_lt_drive); CheckLTBlkDev(bdev); return bp->WBlks(bp,buf,blk,cnt); }