From: <ny...@us...> - 2007-01-17 18:00:52
|
Revision: 267 http://svn.sourceforge.net/pmplib/?rev=267&view=rev Author: nyaochi Date: 2007-01-17 10:00:48 -0800 (Wed, 17 Jan 2007) Log Message: ----------- Use offset tables in db.dat for reading. It seems that db.dat has abandoned records according to my analysis with iriver plus 3. We cannot read the records sequentially. Modified Paths: -------------- trunk/pmplib/lib/pmp_iriverplus3/dat.c Modified: trunk/pmplib/lib/pmp_iriverplus3/dat.c =================================================================== --- trunk/pmplib/lib/pmp_iriverplus3/dat.c 2007-01-17 17:44:42 UTC (rev 266) +++ trunk/pmplib/lib/pmp_iriverplus3/dat.c 2007-01-17 18:00:48 UTC (rev 267) @@ -110,25 +110,11 @@ return size; } -static size_t dat_entry_serialize(dat_entry_t* entry, uint8_t* block, uint8_t* q, uint32_t start, int is_storing) +static size_t dat_entry_serialize(dat_entry_t* entry, uint8_t* block, int is_storing) { int i; uint8_t *p = block; - uint32_t offset; - /* - * Serialize offset address of this entry. - * entry->offset: The offset address in the whole db.dat buffer (e.g., 0x00020123) - * offset (written in db.dat): The one within the chunk (e.g., 0x00000123) - */ - if (is_storing) { - offset = entry->offset - start; - q -= serialize_uint32be(q, &offset, is_storing); - } else { - q -= serialize_uint32be(q, &offset, is_storing); - entry->offset = offset + start; - } - /* Serialize all fields in this entry. */ for (i = 0;i < entry->num_fields;++i) { ip3db_variant_t* var = &entry->fields[i]; @@ -236,10 +222,14 @@ /* Read the new records. */ for (i = 0;i < header->num_entries;++i) { + uint32_t offset = 0; dat_entry_t* entry = &list->entries[list->num_entries+i]; - entry->offset = (uint32_t)(p - buffer); /* compute the current offset address */ - p += dat_entry_serialize(entry, p, q, start, 0); - q -= sizeof(uint32_t); + + /* Read the offset table. */ + q -= serialize_uint32be(q, &offset, 0); + entry->offset = offset + start; + + p += dat_entry_serialize(entry, buffer + entry->offset, 0); } list->num_entries += header->num_entries; @@ -259,14 +249,18 @@ /* Write records. */ while (i < list->num_entries) { + uint32_t offset = 0; size_t free_space = (size_t)(q-p); dat_entry_t* entry = &list->entries[i]; if (free_space < dat_entry_size(entry)) { break; } entry->offset = (uint32_t)(p - buffer); /* compute the current offset address */ - p += dat_entry_serialize(entry, p, q, start, 1); - q -= sizeof(uint32_t); + + offset = entry->offset - start; + q -= serialize_uint32be(q, &offset, 1); + + p += dat_entry_serialize(entry, p, 1); header->num_entries++; i++; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |