comparison src/libpst.c @ 75:987aa872294e stable-0-6-11

Use ftello/fseeko to properly handle large files. Document and properly use datasize field in b5 blocks. Fix some MSVC compile issues and collect MSVC dependencies into one place.
author Carl Byington <carl@five-ten-sg.com>
date Tue, 03 Jun 2008 12:00:58 -0700
parents 3cb02cb1e6cd
children 56fa05fd5271
comparison
equal deleted inserted replaced
74:6f82d13e9300 75:987aa872294e
971 } 971 }
972 } 972 }
973 // When duplicates found, just update the info.... perhaps this is correct functionality 973 // When duplicates found, just update the info.... perhaps this is correct functionality
974 DEBUG_INDEX(("Searching for existing record\n")); 974 DEBUG_INDEX(("Searching for existing record\n"));
975 if (desc_rec.d_id <= *high_id && (d_ptr = pst_getDptr(pf, desc_rec.d_id))) { 975 if (desc_rec.d_id <= *high_id && (d_ptr = pst_getDptr(pf, desc_rec.d_id))) {
976 uint64_t bigzero = 0;
976 DEBUG_INDEX(("Updating Existing Values\n")); 977 DEBUG_INDEX(("Updating Existing Values\n"));
977 d_ptr->list_index = pst_getID(pf, desc_rec.list_id); 978 d_ptr->list_index = pst_getID(pf, desc_rec.list_id);
978 d_ptr->desc = pst_getID(pf, desc_rec.desc_id); 979 d_ptr->desc = pst_getID(pf, desc_rec.desc_id);
979 DEBUG_INDEX(("\tdesc = %#llx\tlist_index=%#llx\n", 980 DEBUG_INDEX(("\tdesc = %#llx\tlist_index=%#llx\n",
980 (d_ptr->desc==NULL?0LL:d_ptr->desc->id), 981 (d_ptr->desc==NULL ? bigzero : d_ptr->desc->id),
981 (d_ptr->list_index==NULL?0LL:d_ptr->list_index->id))); 982 (d_ptr->list_index==NULL ? bigzero : d_ptr->list_index->id)));
982 if (d_ptr->parent && desc_rec.parent_id != d_ptr->parent->id) { 983 if (d_ptr->parent && desc_rec.parent_id != d_ptr->parent->id) {
983 DEBUG_INDEX(("WARNING -- Parent of record has changed. Moving it\n")); 984 DEBUG_INDEX(("WARNING -- Parent of record has changed. Moving it\n"));
984 //hmmm, we must move the record. 985 //hmmm, we must move the record.
985 // first we must remove from current location 986 // first we must remove from current location
986 // change previous record to point next to our next 987 // change previous record to point next to our next
1404 LE16_CPU(table_rec.type); 1405 LE16_CPU(table_rec.type);
1405 LE16_CPU(table_rec.ref_type); 1406 LE16_CPU(table_rec.ref_type);
1406 LE32_CPU(table_rec.value); 1407 LE32_CPU(table_rec.value);
1407 DEBUG_EMAIL(("table_rec (type=%#hx, ref_type=%#hx, value=%#x)\n", table_rec.type, table_rec.ref_type, table_rec.value)); 1408 DEBUG_EMAIL(("table_rec (type=%#hx, ref_type=%#hx, value=%#x)\n", table_rec.type, table_rec.ref_type, table_rec.value));
1408 1409
1409 if (table_rec.type != (uint16_t)0x02B5) { 1410 if ((table_rec.type != (uint16_t)0x02B5) || (table_rec.ref_type != 6)) {
1410 WARN(("Unknown second block constant - %#hx for id %#llx\n", table_rec.type, block_id)); 1411 WARN(("Unknown second block constant - %#hx %#hx for id %#llx\n", table_rec.type, table_rec.ref_type, block_id));
1411 DEBUG_HEXDUMPC(buf, sizeof(table_rec), 0x10);
1412 freeall(&subblocks, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7); 1412 freeall(&subblocks, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7);
1413 DEBUG_RET(); 1413 DEBUG_RET();
1414 return NULL; 1414 return NULL;
1415 } 1415 }
1416 1416
1466 } 1466 }
1467 memcpy(&table_rec, block_offset4.from, sizeof(table_rec)); 1467 memcpy(&table_rec, block_offset4.from, sizeof(table_rec));
1468 LE16_CPU(table_rec.type); 1468 LE16_CPU(table_rec.type);
1469 LE16_CPU(table_rec.ref_type); 1469 LE16_CPU(table_rec.ref_type);
1470 LE32_CPU(table_rec.value); 1470 LE32_CPU(table_rec.value);
1471 DEBUG_EMAIL(("table_rec (type=%#hx, ref_type=%#hx, value=%#x)\n", table_rec.type, table_rec.ref_type, table_rec.value));
1471 1472
1472 if (table_rec.type != (uint16_t)0x04B5) { // different constant than a type 1 record 1473 if (table_rec.type != (uint16_t)0x04B5) { // different constant than a type 1 record
1473 WARN(("Unknown second block constant - %#hx for id %#llx\n", table_rec.type, block_id)); 1474 WARN(("Unknown second block constant - %#hx for id %#llx\n", table_rec.type, block_id));
1474 freeall(&subblocks, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7); 1475 freeall(&subblocks, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7);
1475 DEBUG_RET(); 1476 DEBUG_RET();
1480 DEBUG_WARN(("internal error (7c.b5.desc offset %#x) in reading block id %#llx\n", table_rec.value, block_id)); 1481 DEBUG_WARN(("internal error (7c.b5.desc offset %#x) in reading block id %#llx\n", table_rec.value, block_id));
1481 freeall(&subblocks, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7); 1482 freeall(&subblocks, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7);
1482 DEBUG_RET(); 1483 DEBUG_RET();
1483 return NULL; 1484 return NULL;
1484 } 1485 }
1485 num_recs = (block_offset5.to - block_offset5.from) / 6; // this will give the number of records in this block 1486
1487 // this will give the number of records in this block
1488 num_recs = (block_offset5.to - block_offset5.from) / (4 + table_rec.ref_type);
1486 1489
1487 if (pst_getBlockOffsetPointer(pf, i2_head, &subblocks, seven_c_blk.ind2_offset, &block_offset6)) { 1490 if (pst_getBlockOffsetPointer(pf, i2_head, &subblocks, seven_c_blk.ind2_offset, &block_offset6)) {
1488 DEBUG_WARN(("internal error (7c.ind2 offset %#x) in reading block id %#x\n", seven_c_blk.ind2_offset, block_id)); 1491 DEBUG_WARN(("internal error (7c.ind2 offset %#x) in reading block id %#x\n", seven_c_blk.ind2_offset, block_id));
1489 freeall(&subblocks, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7); 1492 freeall(&subblocks, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7);
1490 DEBUG_RET(); 1493 DEBUG_RET();
1493 ind2_ptr = block_offset6.from; 1496 ind2_ptr = block_offset6.from;
1494 ind2_end = block_offset6.to; 1497 ind2_end = block_offset6.to;
1495 } 1498 }
1496 else { 1499 else {
1497 WARN(("ERROR: Unknown block constant - %#hx for id %#llx\n", block_hdr.type, block_id)); 1500 WARN(("ERROR: Unknown block constant - %#hx for id %#llx\n", block_hdr.type, block_id));
1498 DEBUG_HEXDUMPC(buf, read_size,0x10);
1499 freeall(&subblocks, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7); 1501 freeall(&subblocks, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7);
1500 DEBUG_RET(); 1502 DEBUG_RET();
1501 return NULL; 1503 return NULL;
1502 } 1504 }
1503 1505
4283 // p->readcount = 1; 4285 // p->readcount = 1;
4284 // } 4286 // }
4285 // DEBUG_MAIN(("pst file old offset %#llx old size %#x read count %i offset %#llx size %#x\n", 4287 // DEBUG_MAIN(("pst file old offset %#llx old size %#x read count %i offset %#llx size %#x\n",
4286 // p->offset, p->size, p->readcount, pos, size)); 4288 // p->offset, p->size, p->readcount, pos, size));
4287 4289
4288 if (fseek(pf->fp, pos, SEEK_SET) == -1) { 4290 if (fseeko(pf->fp, pos, SEEK_SET) == -1) {
4289 DEBUG_RET(); 4291 DEBUG_RET();
4290 return 0; 4292 return 0;
4291 } 4293 }
4292 rc = fread(buf, (size_t)1, size, pf->fp); 4294 rc = fread(buf, (size_t)1, size, pf->fp);
4293 DEBUG_RET(); 4295 DEBUG_RET();