freemyipod r128 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r127‎ | r128 | r129 >
Date:00:11, 14 August 2010
Author:theseven
Status:new
Tags:
Comment:
Protect FTL functions from being called before the FTL was initialized (or after initialization failed)
Modified paths:
  • /embios/trunk/format.c (modified) (history)
  • /embios/trunk/target/ipodnano2g/ftl.c (modified) (history)

Diff [purge]

Index: embios/trunk/target/ipodnano2g/ftl.c
@@ -431,6 +431,7 @@
432432
433433
434434 static struct mutex ftl_mtx;
 435+bool ftl_initialized;
435436
436437
437438
@@ -1309,6 +1310,8 @@
13101311 uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks;
13111312 uint32_t error = 0;
13121313
 1314+ if (!ftl_initialized) return 1;
 1315+
13131316 #ifdef FTL_TRACE
13141317 DEBUGF("FTL: Reading %d sectors starting at %d", count, sector);
13151318 #endif
@@ -1969,6 +1972,8 @@
19701973 uint32_t i, j, k;
19711974 uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks;
19721975
 1976+ if (!ftl_initialized) return 1;
 1977+
19731978 #ifdef FTL_TRACE
19741979 DEBUGF("FTL: Writing %d sectors starting at %d", count, sector);
19751980 #endif
@@ -2152,6 +2157,9 @@
21532158 uint32_t i;
21542159 uint32_t rc = 0;
21552160 uint32_t ppb = ftl_nand_type->pagesperblock * ftl_banks;
 2161+
 2162+ if (!ftl_initialized) return 1;
 2163+
21562164 if (ftl_cxt.clean_flag == 1) return 0;
21572165
21582166 mutex_lock(&ftl_mtx, TIMEOUT_BLOCK);
@@ -2545,7 +2553,10 @@
25462554 if (ftl_vfl_open() == 0)
25472555 {
25482556 if (ftl_open() == 0)
 2557+ {
 2558+ ftl_initialized = true;
25492559 return 0;
 2560+ }
25502561 cprintf(CONSOLE_BOOT, "The FTL seems to be damaged. Forcing check.\n");
25512562 if (ftl_repair() != 0)
25522563 cprintf(CONSOLE_BOOT, "FTL recovery failed. Use disk mode to recover.\n");
@@ -2553,7 +2564,10 @@
25542565 {
25552566 cprintf(CONSOLE_BOOT, "FTL recovery finished. Trying to mount again...\n");
25562567 if (ftl_open() == 0)
2557 - return 0;
 2568+ {
 2569+ ftl_initialized = true;
 2570+ return 0;
 2571+ }
25582572 cprintf(CONSOLE_BOOT, "Mounting FTL failed again, use disk mode to recover.\n");
25592573 }
25602574 }
Index: embios/trunk/format.c
@@ -22,7 +22,7 @@
2323
2424 #include "global.h"
2525 #include <limits.h>
26 -#include "libc/include/string.h"
 26+#include "libc/include/string.h"
2727
2828 static const char hexdigit[] = "0123456789ABCDEF";
2929