Disabling auto-refresh of game list by default, as it is causing bugs sometimes
[open-ps2-loader.git] / modules / hdd / ps2hdd / journal.c
blob5480057065dcccb720a9417117f7ed09054a2e27
1 /*
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
14 #include "hdd.h"
16 // Globals
17 apa_journal_t journalBuf;
20 int journalFlush(u32 device)
21 {// this write any thing that in are journal buffer :)
22 if(atadFlushCache(device))
23 return -EIO;
24 if(atadDmaTransfer(device, &journalBuf, APA_SECTOR_APAL, 1, ATAD_MODE_WRITE))
25 return -EIO;
26 if(atadFlushCache(device))
27 return -EIO;
28 return 0;
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))
43 return -EIO;
44 journalBuf.sectors[journalBuf.num]=clink->sector;
45 journalBuf.num++;
46 return 0;
49 int journalResetore(u32 device)
50 { // copys apa headers from apal to apa system
51 int i;
52 u32 sector;
53 apa_cache *clink;
55 dprintf1("ps2hdd: checking log...\n");
56 if(atadDmaTransfer(device, &journalBuf, APA_SECTOR_APAL, sizeof(apa_journal_t)/512, ATAD_MODE_READ)){
57 journalReset(device);
58 return -EIO;
60 if(journalBuf.magic==APAL_MAGIC)
62 if(journalBuf.num==0)
63 return 0;
64 clink=cacheGetFree();
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))
68 break;
69 if(atadDmaTransfer(device, clink->header, journalBuf.sectors[i], 2, ATAD_MODE_WRITE))
70 break;
72 cacheAdd(clink);
73 return journalReset(device);// only do if journal..
75 memset(&journalBuf, 0, sizeof(apa_journal_t));// safe e
76 journalBuf.magic=APAL_MAGIC;
77 return 0;//-EINVAL;