From b03934fb029e8d345c3b933960577e28ee3df619 Mon Sep 17 00:00:00 2001 From: yutaka Date: Wed, 16 Apr 2008 09:55:42 +0000 Subject: [PATCH] =?UTF-8?q?=E3=83=87=E3=83=BC=E3=82=BF=E3=83=99=E3=83=BC?= =?UTF-8?q?=E3=82=B9=E3=81=AB=E4=BD=99=E5=88=86=E3=81=AA=E3=83=98=E3=83=83?= =?UTF-8?q?=E3=83=80=E3=81=8C=E8=BF=BD=E5=8A=A0=E3=81=A7=E3=81=8D=E3=82=8B?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB=E3=80=81=E3=83=95=E3=82=A1=E3=82=A4?= =?UTF-8?q?=E3=83=AB=E5=90=8D=E3=81=AE=E4=BB=A3=E3=82=8F=E3=82=8A=E3=81=AB?= =?UTF-8?q?=E3=82=B7=E3=83=BC=E3=82=AF=E6=B8=88=E3=81=BFFSFile=E3=82=92?= =?UTF-8?q?=E5=8F=96=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/TwlIPL/trunk@1163 b08762b0-b915-fc4b-9d8c-17b2551a87ff --- build/libraries_sysmenu/dht/common/src/dht.c | 42 ++++--------------- .../sysmenu/common/src/pxi.c | 14 +++++-- build/tests/CheckDSHashTable/src/main.c | 15 +++++-- include/sysmenu/dht/dht.h | 5 ++- 4 files changed, 33 insertions(+), 43 deletions(-) diff --git a/build/libraries_sysmenu/dht/common/src/dht.c b/build/libraries_sysmenu/dht/common/src/dht.c index 9a9eafb6..9700914e 100644 --- a/build/libraries_sysmenu/dht/common/src/dht.c +++ b/build/libraries_sysmenu/dht/common/src/dht.c @@ -139,67 +139,41 @@ BOOL DHT_CheckDatabase(const DHTFile* pDHT) return TRUE; } -BOOL DHT_PrepareDatabase(DHTFile* pDHT, const char* filepath) +BOOL DHT_PrepareDatabase(DHTFile* pDHT, FSFile* fp) { - FSFile file; s32 result; s32 length; u8 title[4] = { 'H','N','G','A' }; PROFILE_INIT(); - if ( filepath ) + if ( fp ) { - // ファイルオープン - PROFILE_COUNT(); - if (!FS_OpenFileEx(&file, filepath, FS_FILEMODE_R)) - { - OS_TPrintf("Cannot open %s.\n", filepath); - return FALSE; - } // ヘッダ読み込み PROFILE_COUNT(); - result = FS_ReadFile(&file, &pDHT->header, sizeof(DHTHeader)); + result = FS_ReadFile(fp, &pDHT->header, sizeof(DHTHeader)); if ( result != sizeof(DHTHeader) ) { - OS_TPrintf("Cannot read the header of %s (result=%d).\n", filepath, result); + OS_TPrintf("Cannot read the DHT header (result=%d).\n", result); return FALSE; } - // magic_codeが HNGA のときはROM_Header分だけシークし直す - if ( pDHT->header.magic_code == *(u32*)title ) - { - if ( !FS_SeekFile(&file, sizeof(ROM_Header), FS_SEEK_SET) ) - { - OS_TPrintf("Cannot seek to the header of %s.\n", filepath); - return FALSE; - } - // 再びヘッダ読み込み - result = FS_ReadFile(&file, &pDHT->header, sizeof(DHTHeader)); - if ( result != sizeof(DHTHeader) ) - { - OS_TPrintf("Cannot read the header of %s (result=%d).\n", filepath, result); - return FALSE; - } - } - // サイズチェック PROFILE_COUNT(); length = (s32)DHT_GetDatabaseLength(pDHT); - if ( FS_GetFileLength(&file) < length ) // パディングがあり得る + if ( FS_GetFileLength(fp) < length ) // パディングがあり得る { - OS_TPrintf("Invalid %s size (%d < %d).\n", filepath, FS_GetFileLength(&file), length); + OS_TPrintf("Invalid DHT file size (%d < %d).\n", FS_GetFileLength(fp), length); return FALSE; } // ヘッダ分を削除 length -= sizeof(DHTHeader); // データベース読み込み PROFILE_COUNT(); - result = FS_ReadFile(&file, pDHT->database, length); + result = FS_ReadFile(fp, pDHT->database, length); if ( result != length ) { - OS_TPrintf("Cannot read the database of %s (result=%d).\n", filepath, result); + OS_TPrintf("Cannot read the DHT database (result=%d).\n", result); return FALSE; } - FS_CloseFile(&file); } // データベースの検証 diff --git a/build/libraries_sysmenu/sysmenu/common/src/pxi.c b/build/libraries_sysmenu/sysmenu/common/src/pxi.c index 71993d8b..21732693 100644 --- a/build/libraries_sysmenu/sysmenu/common/src/pxi.c +++ b/build/libraries_sysmenu/sysmenu/common/src/pxi.c @@ -104,7 +104,7 @@ void SYSM_InitPXI( u32 mcu_prio ) #ifdef SDK_ARM9 static BOOL GetDatabaseFilepath(char *path) { - u8 title[4] = { 'H','N','G','A' }; + u8 title[4] = { 'H','N','H','A' }; #if( USE_LCFG_STRING == 0 ) char *title0 = "HNGA"; @@ -154,8 +154,16 @@ void SYSMi_PrepareDatabase(void) char path[256]; if ( GetDatabaseFilepath( path ) ) { - DHT_PrepareDatabase(dht, path); - DC_FlushRange(dht, DHT_GetDatabaseLength(dht)); + FSFile file; + if ( FS_OpenFileEx(&file, path, FS_FILEMODE_R) ) + { + if ( FS_SeekFile(&file, sizeof(ROM_Header), FS_SEEK_SET) ) + { + DHT_PrepareDatabase(dht, &file); + DC_FlushRange(dht, DHT_GetDatabaseLength(dht)); + } + FS_CloseFile(&file); + } } else { diff --git a/build/tests/CheckDSHashTable/src/main.c b/build/tests/CheckDSHashTable/src/main.c index edb9f5ac..1bb58226 100644 --- a/build/tests/CheckDSHashTable/src/main.c +++ b/build/tests/CheckDSHashTable/src/main.c @@ -183,11 +183,18 @@ void TwlMain(void) (void)GX_VBlankIntr(TRUE); FS_Init(FS_DMA_NOT_USE); - - // 署名ロード - if ( !DHT_PrepareDatabase(dht, HASH_PATH) ) { - OS_TPanic("Cannot prepare the database.\n"); + FSFile file; + if ( !FS_OpenFileEx(&file, HASH_PATH, FS_FILEMODE_R) ) + { + OS_TPanic("Cannot open %s.\n", HASH_PATH); + } + // 署名ロード + if ( !DHT_PrepareDatabase(dht, &file) ) + { + OS_TPanic("Cannot prepare the database.\n"); + } + FS_CloseFile(&file); } // 本番 diff --git a/include/sysmenu/dht/dht.h b/include/sysmenu/dht/dht.h index 2bb112ce..1cb2457b 100644 --- a/include/sysmenu/dht/dht.h +++ b/include/sysmenu/dht/dht.h @@ -65,11 +65,12 @@ BOOL DHT_CheckDatabase(const DHTFile* pDHT); Description: FS関数を利用して全データベースを読み込みと検証を行う Arguments: pDHT 全データベースの格納先 - filepath ファイルパス (NULLで格納済みと判定(真贋チェックのみ)) + fp ファイル構造体へのポインタ + DHTHeaderの先頭までシーク済みである必要がある Returns: 成功すればTRUE *---------------------------------------------------------------------------*/ -BOOL DHT_PrepareDatabase(DHTFile* pDHT, const char* filepath); +BOOL DHT_PrepareDatabase(DHTFile* pDHT, FSFile* fp); /*---------------------------------------------------------------------------* Name: DHT_GetDatabase