2 # _____ ___ ____ ___ ____
3 # ____| | ____| | | |____|
4 # | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5 #-----------------------------------------------------------------------
6 # Copyright 2001-2004, ps2dev - http://www.ps2dev.org
7 # Licenced under Academic Free License version 2.0
8 # Review ps2sdk README & LICENSE files for further details.
10 # $Id: journal.c 577 2004-09-14 14:41:46Z pixel $
11 # APA journal related routines
17 apa_journal_t journalBuf
;
20 int journalFlush(u32 device
)
21 {// this write any thing that in are journal buffer :)
22 if(atadFlushCache(device
))
24 if(atadDmaTransfer(device
, &journalBuf
, APA_SECTOR_APAL
, 1, ATAD_MODE_WRITE
))
26 if(atadFlushCache(device
))
31 int journalReset(u32 device
)
33 memset(&journalBuf
, 0, sizeof(apa_journal_t
));
34 journalBuf
.magic
=APAL_MAGIC
;
35 return journalFlush(device
);
38 int journalWrite(apa_cache
*clink
)
40 clink
->header
->checksum
=journalCheckSum(clink
->header
);
41 if(atadDmaTransfer(clink
->device
, clink
->header
,
42 (journalBuf
.num
<< 1)+APA_SECTOR_APAL_HEADERS
, 2, ATAD_MODE_WRITE
))
44 journalBuf
.sectors
[journalBuf
.num
]=clink
->sector
;
49 int journalResetore(u32 device
)
50 { // copys apa headers from apal to apa system
55 dprintf1("ps2hdd: checking log...\n");
56 if(atadDmaTransfer(device
, &journalBuf
, APA_SECTOR_APAL
, sizeof(apa_journal_t
)/512, ATAD_MODE_READ
)){
60 if(journalBuf
.magic
==APAL_MAGIC
)
65 for(i
=0, sector
=APA_SECTOR_APAL_HEADERS
;i
<journalBuf
.num
;i
++, sector
+=2)
67 if(atadDmaTransfer(device
, clink
->header
, sector
, 2, ATAD_MODE_READ
))
69 if(atadDmaTransfer(device
, clink
->header
, journalBuf
.sectors
[i
], 2, ATAD_MODE_WRITE
))
73 return journalReset(device
);// only do if journal..
75 memset(&journalBuf
, 0, sizeof(apa_journal_t
));// safe e
76 journalBuf
.magic
=APAL_MAGIC
;