summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeoff Levand <geoffrey.levand@am.sony.com>2007-08-28 20:18:12 -0700
committerGeoff Levand <geoffrey.levand@am.sony.com>2007-08-28 20:18:12 -0700
commit0c02b0f9093f68ec7277adec13b0e85ed9928fcc (patch)
treedd355d7e64b2e03b3504e2b7c0e536f05725eab1
parent278dbfb4aa7c6b1ed1a61ff9793ee3a176ba5490 (diff)
downloadps3-utils-0c02b0f9093f68ec7277adec13b0e85ed9928fcc.tar.gz
Add database iterators.
-rw-r--r--lib/flash-db.c596
-rw-r--r--lib/ps3-flash.h13
-rw-r--r--ps3-flash-util.c11
3 files changed, 365 insertions, 255 deletions
diff --git a/lib/flash-db.c b/lib/flash-db.c
index d3c0220..f60ba58 100644
--- a/lib/flash-db.c
+++ b/lib/flash-db.c
@@ -40,7 +40,17 @@ struct entry {
uint64_t value;
};
-static const struct os_area_db_id empty_id = {0, 0};
+struct iterator {
+ const struct os_area_db *db;
+ struct os_area_db_id match_id;
+ struct index *idx;
+ struct index *last_idx;
+ union {
+ uint64_t *value_64;
+ uint32_t *value_32;
+ uint16_t *value_16;
+ };
+};
static unsigned int align_up(unsigned int val, unsigned int size)
{
@@ -68,89 +78,86 @@ static uint64_t *value_array_64(const struct os_area_db *db)
}
/**
- * enumerate_64 - Helper to find and operate on 64 bit entries.
+ * for_each_64_match - Iterator for 64 bit entries.
*
* A NULL value for id can be used to match all entries.
* OS_AREA_DB_OWNER_ANY and OS_AREA_DB_KEY_ANY can be used to match all.
*/
-static int enumerate_64(struct os_area_db *db,
- const struct os_area_db_id *id,
- int (*fn)(void *inst, struct index *idx, uint64_t *value),
- void *inst)
-{
- int result = 0;
- struct index *idx;
- const struct index *end;
- uint64_t *value;
-
- for (idx = index_array_64(db),
- end = index_array_64(db) + db->count_64,
- value = value_array_64(db); idx < end; idx++, value++) {
-
- //DBG("%s:%d: try (%d:%d) %llxh\n", __func__, __LINE__,
- // idx->owner, idx->key,
- // (unsigned long long)*value);
-
- if (id && id->owner != OS_AREA_DB_OWNER_ANY
- && id->owner != (int)idx->owner)
- continue;
- if (id && id->key != OS_AREA_DB_KEY_ANY
- && id->key != (int)idx->key)
- continue;
-
- result = fn(inst, idx, value);
+static int for_each_64_match(const struct os_area_db *db,
+ const struct os_area_db_id *match_id, struct iterator *i)
+{
+next:
+ if (!i->db) {
+ i->db = db;
+ i->match_id = match_id ? *match_id : os_area_db_any_id;
+ i->idx = index_array_64(db);
+ i->last_idx = i->idx + db->count_64;
+ i->value_64 = value_array_64(db);
+ } else {
+ i->idx++;
+ i->value_64++;
+ }
- if (result) {
- //DBG("%s:%d: quiting (%d:%d)\n", __func__, __LINE__,
- // idx->owner, idx->key);
- break;
- }
+ if (i->idx >= i->last_idx) {
+ DBG("%s:%d: reached end\n", __func__, __LINE__);
+ return 0;
}
- //DBG("%s:%d: done\n", __func__, __LINE__);
+ if (i->match_id.owner != OS_AREA_DB_OWNER_ANY
+ && i->match_id.owner != (int)i->idx->owner)
+ goto next;
+ if (i->match_id.key != OS_AREA_DB_KEY_ANY
+ && i->match_id.key != (int)i->idx->key)
+ goto next;
+
+ return 1;
+}
- return (result < 0) ? -1 : 0;
+static int for_each_64(const struct os_area_db *db, struct iterator *i)
+{
+ return for_each_64_match(db, NULL, i);
}
-static int callback_delete_64(__attribute__((unused)) void *inst,
- struct index *idx, uint64_t *value)
+/**
+ * enumerate_64 - Helper to find and operate on 64 bit entries.
+ */
+
+static int enumerate_64(struct os_area_db *db,
+ const struct os_area_db_id *id,
+ int (*fn)(void *inst, struct index *idx, uint64_t *value),
+ void *inst)
{
- DBG("%s:%d: got (%d:%d) %llxh\n", __func__, __LINE__,
- idx->owner, idx->key, (unsigned long long)*value);
+ struct iterator i;
- idx->owner = 0;
- idx->key = 0;
- *value = 0;
+ for (i.db = NULL; for_each_64_match(db, id, &i); )
+ if (fn(inst, i.idx, i.value_64))
+ break;
return 0;
}
static int delete_64(struct os_area_db *db, const struct os_area_db_id *id)
{
//DBG("%s:%d: (%d:%d)\n", __func__, __LINE__, id->owner, id->key);
- return enumerate_64(db, id, callback_delete_64, NULL);
-}
-
-static int callback_set_64(void *inst, struct index *idx, uint64_t *value)
-{
- const struct entry *e = inst;
-
- DBG("%s:%d: got (%d:%d) %llxh\n", __func__, __LINE__,
- idx->owner, idx->key, (unsigned long long)*value);
+ struct iterator i;
- idx->owner = e->id.owner;
- idx->key = e->id.key;
- *value = e->value;
+ for (i.db = NULL; for_each_64_match(db, id, &i); ) {
- DBG("%s:%d: set (%d:%d) <= %llxh\n", __func__, __LINE__,
- e->id.owner, e->id.key, (unsigned long long)e->value);
- return 1;
+ DBG("%s:%d: got (%d:%d) %llxh\n", __func__, __LINE__,
+ i.idx->owner, i.idx->key,
+ (unsigned long long)*i.value_64);
+
+ i.idx->owner = 0;
+ i.idx->key = 0;
+ *i.value_64 = 0;
+ }
+ return 0;
}
int os_area_db_set_64(struct os_area_db *db, const struct os_area_db_id *id,
uint64_t value)
{
- struct entry e = {*id, value};
+ struct iterator i;
DBG("%s:%d: (%d:%d) <= %llxh\n", __func__, __LINE__,
id->owner, id->key, (unsigned long long)value);
@@ -163,7 +170,42 @@ int os_area_db_set_64(struct os_area_db *db, const struct os_area_db_id *id,
}
os_area_db_remove(db, id);
- return enumerate_64(db, &empty_id, callback_set_64, &e);
+
+ i.db = NULL;
+ if (for_each_64_match(db, &os_area_db_empty_id, &i)) {
+
+ DBG("%s:%d: got (%d:%d) %llxh\n", __func__, __LINE__,
+ i.idx->owner, i.idx->key,
+ (unsigned long long)*i.value_64);
+
+ i.idx->owner = id->owner;
+ i.idx->key = id->key;
+ *i.value_64 = value;
+
+ DBG("%s:%d: set (%d:%d) <= %llxh\n", __func__, __LINE__,
+ i.idx->owner, i.idx->key,
+ (unsigned long long)*i.value_64);
+ return 0;
+ }
+ fprintf(stderr, "%s:%d: database full.\n",
+ __func__, __LINE__);
+ return -1;
+}
+
+static int get_64(const struct os_area_db *db,
+ const struct os_area_db_id *id, uint64_t *value)
+{
+ struct iterator i;
+
+ i.db = NULL;
+ if (for_each_64_match(db, id, &i)) {
+ *value = *i.value_64;
+ DBG("%s:%d: found %lld\n", __func__, __LINE__,
+ (long long int)*i.value_64);
+ return 0;
+ }
+ DBG("%s:%d: not found\n", __func__, __LINE__);
+ return -1;
}
/* 32 bit */
@@ -187,89 +229,69 @@ static uint32_t *value_array_32(const struct os_area_db *db)
}
/**
- * enumerate_32 - Helper to find and operate on 32 bit entries.
+ * for_each_32_match - Iterator for 32 bit entries.
*
* A NULL value for id can be used to match all entries.
* OS_AREA_DB_OWNER_ANY and OS_AREA_DB_KEY_ANY can be used to match all.
*/
-static int enumerate_32(struct os_area_db *db,
- const struct os_area_db_id *id,
- int (*fn)(void *inst, struct index *idx, uint32_t *value),
- void *inst)
-{
- int result = 0;
- struct index *idx;
- const struct index *end;
- uint32_t *value;
-
- for (idx = index_array_32(db),
- end = index_array_32(db) + db->count_32,
- value = value_array_32(db); idx < end; idx++, value++) {
-
- //DBG("%s:%d: try (%d:%d) %llxh\n", __func__, __LINE__,
- // idx->owner, idx->key,
- // (unsigned long long)*value);
-
- if (id && id->owner != OS_AREA_DB_OWNER_ANY
- && id->owner != (int)idx->owner)
- continue;
- if (id && id->key != OS_AREA_DB_KEY_ANY
- && id->key != (int)idx->key)
- continue;
-
- result = fn(inst, idx, value);
+static int for_each_32_match(const struct os_area_db *db,
+ const struct os_area_db_id *match_id, struct iterator *i)
+{
+next:
+ if (!i->db) {
+ i->db = db;
+ i->match_id = match_id ? *match_id : os_area_db_any_id;
+ i->idx = index_array_32(db);
+ i->last_idx = i->idx + db->count_32;
+ i->value_32 = value_array_32(db);
+ } else {
+ i->idx++;
+ i->value_32++;
+ }
- if (result) {
- //DBG("%s:%d: quiting (%d:%d)\n", __func__, __LINE__,
- // idx->owner, idx->key);
- break;
- }
+ if (i->idx >= i->last_idx) {
+ DBG("%s:%d: reached end\n", __func__, __LINE__);
+ return 0;
}
- //DBG("%s:%d: done\n", __func__, __LINE__);
+ if (i->match_id.owner != OS_AREA_DB_OWNER_ANY
+ && i->match_id.owner != (int)i->idx->owner)
+ goto next;
+ if (i->match_id.key != OS_AREA_DB_KEY_ANY
+ && i->match_id.key != (int)i->idx->key)
+ goto next;
- return (result < 0) ? -1 : 0;
+ return 1;
}
-static int callback_delete_32(__attribute__((unused)) void *inst,
- struct index *idx, uint32_t *value)
+static int for_each_32(const struct os_area_db *db, struct iterator *i)
{
- DBG("%s:%d: got (%d:%d) %llxh\n", __func__, __LINE__,
- idx->owner, idx->key, (unsigned long long)*value);
-
- idx->owner = 0;
- idx->key = 0;
- *value = 0;
- return 0;
+ return for_each_32_match(db, NULL, i);
}
static int delete_32(struct os_area_db *db, const struct os_area_db_id *id)
{
//DBG("%s:%d: (%d:%d)\n", __func__, __LINE__, id->owner, id->key);
- return enumerate_32(db, id, callback_delete_32, NULL);
-}
+ struct iterator i;
-static int callback_set_32(void *inst, struct index *idx, uint32_t *value)
-{
- const struct entry *e = inst;
-
- DBG("%s:%d: got (%d:%d) %llxh\n", __func__, __LINE__,
- idx->owner, idx->key, (unsigned long long)*value);
+ for (i.db = NULL; for_each_32_match(db, id, &i); ) {
- idx->owner = e->id.owner;
- idx->key = e->id.key;
- *value = e->value;
-
- DBG("%s:%d: set (%d:%d) <= %llxh\n", __func__, __LINE__,
- e->id.owner, e->id.key, (unsigned long long)e->value);
- return 1;
+ DBG("%s:%d: got (%d:%d) %llxh\n", __func__, __LINE__,
+ i.idx->owner, i.idx->key,
+ (unsigned long long)*i.value_32);
+
+ i.idx->owner = 0;
+ i.idx->key = 0;
+ *i.value_32 = 0;
+ }
+ return 0;
}
int os_area_db_set_32(struct os_area_db *db, const struct os_area_db_id *id,
uint32_t value)
{
- struct entry e = {*id, value};
+ struct iterator i;
DBG("%s:%d: (%d:%d) <= %llxh\n", __func__, __LINE__,
id->owner, id->key, (unsigned long long)value);
@@ -282,7 +304,42 @@ int os_area_db_set_32(struct os_area_db *db, const struct os_area_db_id *id,
}
os_area_db_remove(db, id);
- return enumerate_32(db, &empty_id, callback_set_32, &e);
+
+ i.db = NULL;
+ if (for_each_32_match(db, &os_area_db_empty_id, &i)) {
+
+ DBG("%s:%d: got (%d:%d) %llxh\n", __func__, __LINE__,
+ i.idx->owner, i.idx->key,
+ (unsigned long long)*i.value_32);
+
+ i.idx->owner = id->owner;
+ i.idx->key = id->key;
+ *i.value_32 = value;
+
+ DBG("%s:%d: set (%d:%d) <= %llxh\n", __func__, __LINE__,
+ i.idx->owner, i.idx->key,
+ (unsigned long long)*i.value_32);
+ return 0;
+ }
+ fprintf(stderr, "%s:%d: database full.\n",
+ __func__, __LINE__);
+ return -1;
+}
+
+static int get_32(const struct os_area_db *db,
+ const struct os_area_db_id *id, uint32_t *value)
+{
+ struct iterator i;
+
+ i.db = NULL;
+ if (for_each_32_match(db, id, &i)) {
+ *value = *i.value_32;
+ DBG("%s:%d: found %lld\n", __func__, __LINE__,
+ (long long int)*i.value_32);
+ return 0;
+ }
+ DBG("%s:%d: not found\n", __func__, __LINE__);
+ return -1;
}
/* 16 bit */
@@ -306,89 +363,69 @@ static uint16_t *value_array_16(const struct os_area_db *db)
}
/**
- * enumerate_16 - Helper to find and operate on 16 bit entries.
+ * for_each_16_match - Iterator for 16 bit entries.
*
* A NULL value for id can be used to match all entries.
* OS_AREA_DB_OWNER_ANY and OS_AREA_DB_KEY_ANY can be used to match all.
*/
-static int enumerate_16(struct os_area_db *db,
- const struct os_area_db_id *id,
- int (*fn)(void *inst, struct index *idx, uint16_t *value),
- void *inst)
-{
- int result = 0;
- struct index *idx;
- const struct index *end;
- uint16_t *value;
-
- for (idx = index_array_16(db),
- end = index_array_16(db) + db->count_16,
- value = value_array_16(db); idx < end; idx++, value++) {
-
- //DBG("%s:%d: try (%d:%d) %llxh\n", __func__, __LINE__,
- // idx->owner, idx->key,
- // (unsigned long long)*value);
-
- if (id && id->owner != OS_AREA_DB_OWNER_ANY
- && id->owner != (int)idx->owner)
- continue;
- if (id && id->key != OS_AREA_DB_KEY_ANY
- && id->key != (int)idx->key)
- continue;
-
- result = fn(inst, idx, value);
+static int for_each_16_match(const struct os_area_db *db,
+ const struct os_area_db_id *match_id, struct iterator *i)
+{
+next:
+ if (!i->db) {
+ i->db = db;
+ i->match_id = match_id ? *match_id : os_area_db_any_id;
+ i->idx = index_array_16(db);
+ i->last_idx = i->idx + db->count_16;
+ i->value_16 = value_array_16(db);
+ } else {
+ i->idx++;
+ i->value_16++;
+ }
- if (result) {
- //DBG("%s:%d: quiting (%d:%d)\n", __func__, __LINE__,
- // idx->owner, idx->key);
- break;
- }
+ if (i->idx >= i->last_idx) {
+ DBG("%s:%d: reached end\n", __func__, __LINE__);
+ return 0;
}
- //DBG("%s:%d: done\n", __func__, __LINE__);
+ if (i->match_id.owner != OS_AREA_DB_OWNER_ANY
+ && i->match_id.owner != (int)i->idx->owner)
+ goto next;
+ if (i->match_id.key != OS_AREA_DB_KEY_ANY
+ && i->match_id.key != (int)i->idx->key)
+ goto next;
- return (result < 0) ? -1 : 0;
+ return 1;
}
-static int callback_delete_16(__attribute__((unused)) void *inst,
- struct index *idx, uint16_t *value)
+static int for_each_16(const struct os_area_db *db, struct iterator *i)
{
- DBG("%s:%d: got (%d:%d) %llxh\n", __func__, __LINE__,
- idx->owner, idx->key, (unsigned long long)*value);
-
- idx->owner = 0;
- idx->key = 0;
- *value = 0;
- return 0;
+ return for_each_16_match(db, NULL, i);
}
static int delete_16(struct os_area_db *db, const struct os_area_db_id *id)
{
//DBG("%s:%d: (%d:%d)\n", __func__, __LINE__, id->owner, id->key);
- return enumerate_16(db, id, callback_delete_16, NULL);
-}
-
-static int callback_set_16(void *inst, struct index *idx, uint16_t *value)
-{
- const struct entry *e = inst;
+ struct iterator i;
- DBG("%s:%d: got (%d:%d) %llxh\n", __func__, __LINE__,
- idx->owner, idx->key, (unsigned long long)*value);
+ for (i.db = NULL; for_each_16_match(db, id, &i); ) {
- idx->owner = e->id.owner;
- idx->key = e->id.key;
- *value = e->value;
-
- DBG("%s:%d: set (%d:%d) <= %llxh\n", __func__, __LINE__,
- e->id.owner, e->id.key, (unsigned long long)e->value);
- return 1;
+ DBG("%s:%d: got (%d:%d) %llxh\n", __func__, __LINE__,
+ i.idx->owner, i.idx->key,
+ (unsigned long long)*i.value_16);
+
+ i.idx->owner = 0;
+ i.idx->key = 0;
+ *i.value_16 = 0;
+ }
+ return 0;
}
int os_area_db_set_16(struct os_area_db *db, const struct os_area_db_id *id,
uint16_t value)
{
- struct entry e = {*id, value};
+ struct iterator i;
DBG("%s:%d: (%d:%d) <= %llxh\n", __func__, __LINE__,
id->owner, id->key, (unsigned long long)value);
@@ -401,9 +438,43 @@ int os_area_db_set_16(struct os_area_db *db, const struct os_area_db_id *id,
}
os_area_db_remove(db, id);
- return enumerate_16(db, &empty_id, callback_set_16, &e);
+
+ i.db = NULL;
+ if (for_each_16_match(db, &os_area_db_empty_id, &i)) {
+
+ DBG("%s:%d: got (%d:%d) %llxh\n", __func__, __LINE__,
+ i.idx->owner, i.idx->key,
+ (unsigned long long)*i.value_16);
+
+ i.idx->owner = id->owner;
+ i.idx->key = id->key;
+ *i.value_16 = value;
+
+ DBG("%s:%d: set (%d:%d) <= %llxh\n", __func__, __LINE__,
+ i.idx->owner, i.idx->key,
+ (unsigned long long)*i.value_16);
+ return 0;
+ }
+ fprintf(stderr, "%s:%d: database full.\n",
+ __func__, __LINE__);
+ return -1;
}
+static int get_16(const struct os_area_db *db,
+ const struct os_area_db_id *id, uint16_t *value)
+{
+ struct iterator i;
+
+ i.db = NULL;
+ if (for_each_16_match(db, id, &i)) {
+ *value = *i.value_16;
+ DBG("%s:%d: found %lld\n", __func__, __LINE__,
+ (long long int)*i.value_16);
+ return 0;
+ }
+ DBG("%s:%d: not found\n", __func__, __LINE__);
+ return -1;
+}
/**
* os_area_db_remove - Remove an entry from the database.
@@ -519,91 +590,127 @@ int os_area_db_write(const struct os_area_db *db, const struct os_area_header *h
return 0;
}
-
-int os_area_db_get(struct os_area_db *db,
+int os_area_db_get(const struct os_area_db *db,
const struct os_area_db_id *id, uint64_t *value)
{
- return -1;
-}
-
-static int callback_print_64(void *inst, struct index *idx, uint64_t *value)
-{
- unsigned int *c = inst;
- const char *p = (const char *)value;
- char s[9];
+ int result;
+ uint32_t tmp_32;
+ uint16_t tmp_16;
- s[0] = (p[0] < 127 && p[0] > 31) ? p[0] : '.';
- s[1] = (p[1] < 127 && p[1] > 31) ? p[1] : '.';
- s[2] = (p[2] < 127 && p[2] > 31) ? p[2] : '.';
- s[3] = (p[3] < 127 && p[3] > 31) ? p[3] : '.';
- s[4] = (p[4] < 127 && p[4] > 31) ? p[4] : '.';
- s[5] = (p[5] < 127 && p[5] > 31) ? p[5] : '.';
- s[6] = (p[6] < 127 && p[6] > 31) ? p[6] : '.';
- s[7] = (p[7] < 127 && p[7] > 31) ? p[7] : '.';
- s[8] = 0;
+ result = get_64(db, id, value);
+ if (!result)
+ return result;
- printf(" 64[%2u] (%d:%d): %llxh(%llu) - %s\n", *c,
- idx->owner, idx->key,
- (unsigned long long)*value,
- (unsigned long long)*value, s);
+ result = get_32(db, id, &tmp_32);
+ *value = tmp_32;
+ if (!result)
+ return result;
- (*c)++;
- return 0;
+ result = get_16(db, id, &tmp_16);
+ *value = tmp_16;
+ return result;
}
-static int callback_print_32(void *inst, struct index *idx, uint32_t *value)
+int os_area_db_get_rtc_diff(const struct os_area_db *db, int64_t *rtc_diff)
{
- unsigned int *c = inst;
- const char *p = (const char *)value;
- char s[9];
+ static const struct os_area_db_id id = {
+ .owner = OS_AREA_DB_OWNER_LINUX,
+ .key = OS_AREA_DB_KEY_RTC_DIFF
+ };
+
+ return get_64(db, &id, (uint64_t*)rtc_diff);
+}
- s[0] = (p[0] < 127 && p[0] > 31) ? p[0] : '.';
- s[1] = (p[1] < 127 && p[1] > 31) ? p[1] : '.';
- s[2] = (p[2] < 127 && p[2] > 31) ? p[2] : '.';
- s[3] = (p[3] < 127 && p[3] > 31) ? p[3] : '.';
- s[4] = 0;
+int os_area_db_get_video_mode(const struct os_area_db *db,
+ unsigned int *video_mode)
+{
+ static const struct os_area_db_id id = {
+ .owner = OS_AREA_DB_OWNER_LINUX,
+ .key = OS_AREA_DB_KEY_VIDEO_MODE
+ };
+
+ return get_64(db, &id, (uint64_t*)video_mode);
+}
- printf(" 32[%2u] (%d:%d): %lxh(%lu) - %s\n", *c,
- idx->owner, idx->key,
- (unsigned long)*value,
- (unsigned long)*value, s);
+static void print_64(const struct os_area_db *db,
+ const struct os_area_db_id *const id)
+{
+ struct iterator i;
+ unsigned int c;
- (*c)++;
- return 0;
+ for (c = 0, i.db = NULL; for_each_64_match(db, id, &i); c++) {
+ const char *p = (const char *)i.value_64;
+ char s[9];
+
+ s[0] = (p[0] < 127 && p[0] > 31) ? p[0] : '.';
+ s[1] = (p[1] < 127 && p[1] > 31) ? p[1] : '.';
+ s[2] = (p[2] < 127 && p[2] > 31) ? p[2] : '.';
+ s[3] = (p[3] < 127 && p[3] > 31) ? p[3] : '.';
+ s[4] = (p[4] < 127 && p[4] > 31) ? p[4] : '.';
+ s[5] = (p[5] < 127 && p[5] > 31) ? p[5] : '.';
+ s[6] = (p[6] < 127 && p[6] > 31) ? p[6] : '.';
+ s[7] = (p[7] < 127 && p[7] > 31) ? p[7] : '.';
+ s[8] = 0;
+
+ printf(" 64[%2u] (%d:%d): %llxh(%llu) - %s\n", c,
+ i.idx->owner, i.idx->key,
+ (unsigned long long)*i.value_64,
+ (unsigned long long)*i.value_64, s);
+ }
}
-static int callback_print_16(void *inst, struct index *idx, uint16_t *value)
+static void print_32(const struct os_area_db *db,
+ const struct os_area_db_id *const id)
{
- unsigned int *c = inst;
- const char *p = (const char *)value;
- char s[9];
+ struct iterator i;
+ unsigned int c;
- s[0] = (p[0] < 127 && p[0] > 31) ? p[0] : '.';
- s[1] = (p[1] < 127 && p[1] > 31) ? p[1] : '.';
- s[2] = 0;
+ for (c = 0, i.db = NULL; for_each_32_match(db, id, &i); c++) {
+ const char *p = (const char *)i.value_32;
+ char s[9];
- printf(" 16[%2u] (%d:%d): %xh(%u) - %s\n", *c,
- idx->owner, idx->key,
- (unsigned int)*value,
- (unsigned int)*value, s);
+ s[0] = (p[0] < 127 && p[0] > 31) ? p[0] : '.';
+ s[1] = (p[1] < 127 && p[1] > 31) ? p[1] : '.';
+ s[2] = (p[2] < 127 && p[2] > 31) ? p[2] : '.';
+ s[3] = (p[3] < 127 && p[3] > 31) ? p[3] : '.';
+ s[4] = 0;
- (*c)++;
- return 0;
+ printf(" 32[%2u] (%d:%d): %lxh(%lu) - %s\n", c,
+ i.idx->owner, i.idx->key,
+ (unsigned long)*i.value_32,
+ (unsigned long)*i.value_32, s);
+ }
}
-void os_area_db_print(const struct os_area_db *db,
+static void print_16(const struct os_area_db *db,
const struct os_area_db_id *const id)
{
+ struct iterator i;
unsigned int c;
+ for (c = 0, i.db = NULL; for_each_16_match(db, id, &i); c++) {
+ const char *p = (const char *)i.value_16;
+ char s[9];
+
+ s[0] = (p[0] < 127 && p[0] > 31) ? p[0] : '.';
+ s[1] = (p[1] < 127 && p[1] > 31) ? p[1] : '.';
+ s[2] = 0;
+
+ printf(" 16[%2u] (%d:%d): %xh(%u) - %s\n", c,
+ i.idx->owner, i.idx->key,
+ (unsigned int)*i.value_16,
+ (unsigned int)*i.value_16, s);
+ }
+}
+
+void os_area_db_print(const struct os_area_db *db,
+ const struct os_area_db_id *const id)
+{
DBG("%s:%d: (%d:%d)\n", __func__, __LINE__, id->owner, id->key);
- c = 0;
- enumerate_64((struct os_area_db *)db, id, callback_print_64, &c);
- c = 0;
- enumerate_32((struct os_area_db *)db, id, callback_print_32, &c);
- c = 0;
- enumerate_16((struct os_area_db *)db, id, callback_print_16, &c);
+ print_64(db, id);
+ print_32(db, id);
+ print_16(db, id);
}
void os_area_db_init(struct os_area_db *db)
@@ -664,17 +771,6 @@ int os_area_db_format(struct os_area_db *db, const struct os_area_header *h,
return result;
}
-int os_area_db_get_rtc_diff(const struct os_area_db *db, uint64_t *rtc_diff)
-{
- return -1;
-}
-
-int os_area_db_get_video_mode(const struct os_area_db *db,
- unsigned int *video_mode)
-{
- return -1;
-}
-
int os_area_db_list_owners(char *buf, unsigned int size)
{
return snprintf(buf, size,
diff --git a/lib/ps3-flash.h b/lib/ps3-flash.h
index 2b8ccb5..3ce54d6 100644
--- a/lib/ps3-flash.h
+++ b/lib/ps3-flash.h
@@ -38,7 +38,7 @@ enum os_area_ldr_format {
* struct os_area_header - os area header segment.
* @magic_num: Always 'cell_ext_os_area'.
* @hdr_version: Header format version number.
- * @other_os_data_offset: Starting segment number of other os data area.
+ * @db_area_offset: Starting segment number of other os database area.
* @ldr_area_offset: Starting segment number of bootloader image area.
* @ldr_format: HEADER_LDR_FORMAT flag.
* @ldr_size: Size of bootloader image in bytes.
@@ -74,7 +74,7 @@ enum {
* struct os_area_params - os area params segment.
* @boot_flag: User preference of operating system, PARAM_BOOT_FLAG flag.
* @num_params: Number of params in this (params) segment.
- * @rtc_diff: Difference in seconds between 1970 and the ps3 rtc value.
+ * @rtc_diff: Difference in seconds between game os wall time and the ps3 rtc value.
* @av_multi_out: User preference of AV output, PARAM_AV_MULTI_OUT flag.
* @ctrl_button: User preference of controller button config, PARAM_CTRL_BUTTON
* flag.
@@ -201,6 +201,11 @@ struct os_area_db_id {
int key;
};
+static const struct os_area_db_id os_area_db_empty_id =
+ {OS_AREA_DB_OWNER_NONE, OS_AREA_DB_KEY_NONE};
+static const struct os_area_db_id os_area_db_any_id =
+ {OS_AREA_DB_OWNER_ANY, OS_AREA_DB_KEY_ANY};
+
#if defined(__cplusplus)
extern "C" {
#endif
@@ -211,7 +216,7 @@ int os_area_db_write(const struct os_area_db *db, const struct os_area_header *h
FILE *dev);
void os_area_db_init(struct os_area_db *db);
int os_area_db_verify(const struct os_area_db *db);
-int os_area_db_get(struct os_area_db *db, const struct os_area_db_id *id,
+int os_area_db_get(const struct os_area_db *db, const struct os_area_db_id *id,
uint64_t *value);
int os_area_db_remove(struct os_area_db *db, const struct os_area_db_id *id);
int os_area_db_set_64(struct os_area_db *db, const struct os_area_db_id *id,
@@ -224,7 +229,7 @@ void os_area_db_print(const struct os_area_db *db,
const struct os_area_db_id *id);
int os_area_db_format(struct os_area_db *db, const struct os_area_header *h,
FILE *dev);
-int os_area_db_get_rtc_diff(const struct os_area_db *db, uint64_t *rtc_diff);
+int os_area_db_get_rtc_diff(const struct os_area_db *db, int64_t *rtc_diff);
int os_area_db_get_video_mode(const struct os_area_db *db,
unsigned int *video_mode);
int os_area_db_list_owners(char *buf, unsigned int size);
diff --git a/ps3-flash-util.c b/ps3-flash-util.c
index cbe1826..b3aef21 100644
--- a/ps3-flash-util.c
+++ b/ps3-flash-util.c
@@ -127,14 +127,23 @@ static void opts_dump(const struct opts* opts)
static void show_settings(const struct os_area_header *h,
const struct os_area_params *p, const struct os_area_db *db)
{
+ int64_t rtc_diff;
+
printf(PS3_UTILS_VERSION);
os_area_header_dump(h, " header ", 1);
os_area_params_dump(p, " param ", 2);
if (!db)
printf(" db :3: not found\n");
- else
+ else {
+ int result;
+
os_area_db_dump_header(db, " db ", 3);
+
+ result = os_area_db_get_rtc_diff(db, &rtc_diff);
+ if(!result)
+ printf(" rtc :4: %lld\n", (long long int)rtc_diff);
+ }
}
static int write_image(FILE *dev, struct os_area_header *h, const char *image)