29int apaCacheInit(u32 size)
44 cacheBuf->next=cacheBuf;
45 cacheBuf->tail=cacheBuf;
46 for(i=1; i<size+1;i++, header++){
47 cacheBuf[i].header=header;
48 cacheBuf[i].device=-1;
49 apaCacheLink(cacheBuf->tail, &cacheBuf[i]);
54int apaCacheDeinit(
void)
59 for(i=1; i<cacheSize+1;i++){
61 apaFreeMem(cacheBuf[i].header);
67 apaFreeMem(cacheBuf[1].header);
77 cnew->next=clink->next;
78 clink->next->tail=cnew;
84 clink->tail->next=clink->next;
85 clink->next->tail=clink->tail;
93 err=apaWriteHeader(clink->device, clink->header, clink->sector);
95 err=apaReadHeader(clink->device, clink->header, clink->sector);
99 APA_PRINTF(APA_DRV_NAME
": error: disk err %d on device %ld, sector %ld, type %d\n",
100 err, clink->device, clink->sector, type);
102 apaSaveError(clink->device, clink->header, APA_SECTOR_SECTOR_ERROR, clink->sector);
104 clink->flags&=~APA_CACHE_FLAG_DIRTY;
110 if(clink->flags&APA_CACHE_FLAG_DIRTY)
111 apaCacheTransfer(clink, APA_IO_MODE_WRITE);
114int apaCacheFlushAllDirty(s32 device)
118 for(i=1;i<cacheSize+1;i++){
119 if((cacheBuf[i].flags & APA_CACHE_FLAG_DIRTY) && cacheBuf[i].device==device)
120 apaJournalWrite(&cacheBuf[i]);
122 apaJournalFlush(device);
124 for(i=1;i<cacheSize+1;i++){
125 if((cacheBuf[i].flags & APA_CACHE_FLAG_DIRTY) && cacheBuf[i].device==device)
126 apaCacheTransfer(&cacheBuf[i], APA_IO_MODE_WRITE);
128 return apaJournalReset(device);
131apa_cache_t *apaCacheGetHeader(s32 device, u32 sector, u32 mode,
int *result)
137 for(i=1;i<cacheSize+1;i++){
138 if(cacheBuf[i].sector==sector &&
139 cacheBuf[i].device==device){
147 clink=apaCacheUnLink(clink);
151 if((cacheBuf->tail==cacheBuf) &&
152 (cacheBuf->tail==cacheBuf->tail->next)){
153 APA_PRINTF(APA_DRV_NAME
": error: free buffer empty\n");
157 clink=cacheBuf->next;
158 if(clink->flags & APA_CACHE_FLAG_DIRTY)
159 APA_PRINTF(APA_DRV_NAME
": error: dirty buffer allocated\n");
162 clink->device=device;
163 clink->sector=sector;
164 clink=apaCacheUnLink(clink);
173 if((*result=apaCacheTransfer(clink, APA_IO_MODE_READ))<0){
176 apaCacheLink(cacheBuf, clink);
186 APA_PRINTF(APA_DRV_NAME
": error: null buffer returned\n");
190 APA_PRINTF(APA_DRV_NAME
": error: unused cache returned\n");
193 if(clink->flags & APA_CACHE_FLAG_DIRTY)
194 APA_PRINTF(APA_DRV_NAME
": error: dirty buffer returned\n");
197 apaCacheLink(cacheBuf->tail, clink);
205 if((cacheBuf->tail==cacheBuf) &&
206 (cacheBuf->tail==cacheBuf->tail->next)){
207 APA_PRINTF(APA_DRV_NAME
": error: free buffer empty\n");
210 cnext=cacheBuf->next;
211 if(cnext->flags & APA_CACHE_FLAG_DIRTY)
212 APA_PRINTF(APA_DRV_NAME
": error: dirty buffer allocated\n");
217 return apaCacheUnLink(cnext);