comparison src/libpst.c @ 102:8c4482be0b4c

remove unreachable code
author Carl Byington <carl@five-ten-sg.com>
date Sun, 05 Oct 2008 11:54:37 -0700
parents 1fc33da23175
children 0af0bbe166e1
comparison
equal deleted inserted replaced
101:1fc33da23175 102:8c4482be0b4c
354 } 354 }
355 355
356 356
357 int pst_load_index (pst_file *pf) { 357 int pst_load_index (pst_file *pf) {
358 int x; 358 int x;
359 uint64_t y;
360 DEBUG_ENT("pst_load_index"); 359 DEBUG_ENT("pst_load_index");
361 if (!pf) { 360 if (!pf) {
362 WARN(("Cannot load index for a NULL pst_file\n")); 361 WARN(("Cannot load index for a NULL pst_file\n"));
363 DEBUG_RET(); 362 DEBUG_RET();
364 return -1; 363 return -1;
365 } 364 }
366 365
367 x = pst_build_id_ptr(pf, pf->index1, 0, pf->index1_back, 0, UINT64_MAX); 366 x = pst_build_id_ptr(pf, pf->index1, 0, pf->index1_back, 0, UINT64_MAX);
368 DEBUG_INDEX(("build id ptr returns %i\n", x)); 367 DEBUG_INDEX(("build id ptr returns %i\n", x));
369 368
370 y = 0; 369 x = pst_build_desc_ptr(pf, pf->index2, 0, pf->index2_back, (uint64_t)0x21, UINT64_MAX);
371 x = pst_build_desc_ptr(pf, pf->index2, 0, pf->index2_back, &y, (uint64_t)0x21, UINT64_MAX);
372 DEBUG_INDEX(("build desc ptr returns %i\n", x)); 370 DEBUG_INDEX(("build desc ptr returns %i\n", x));
373 371
374 DEBUG_CODE((void)pst_printDptr(pf, pf->d_head);); 372 DEBUG_CODE((void)pst_printDptr(pf, pf->d_head););
375 DEBUG_RET(); 373 DEBUG_RET();
376 return 0; 374 return 0;
894 parent->no_child++; 892 parent->no_child++;
895 node->parent = parent; 893 node->parent = parent;
896 add_descriptor_to_list(node, &parent->child, &parent->child_tail); 894 add_descriptor_to_list(node, &parent->child, &parent->child_tail);
897 } 895 }
898 else { 896 else {
899 //DEBUG_INDEX(("No parent %#"PRIx64", have an orphan child %#"PRIx64"\n", node->parent_id, node->id)); 897 DEBUG_INDEX(("No parent %#"PRIx64", have an orphan child %#"PRIx64"\n", node->parent_id, node->id));
900 add_descriptor_to_list(node, &pf->d_head, &pf->d_tail); 898 add_descriptor_to_list(node, &pf->d_head, &pf->d_tail);
901 } 899 }
902 } 900 }
903 } 901 }
904 902
905 903
906 int pst_build_desc_ptr (pst_file *pf, off_t offset, int32_t depth, uint64_t linku1, uint64_t *high_id, uint64_t start_val, uint64_t end_val) { 904 int pst_build_desc_ptr (pst_file *pf, off_t offset, int32_t depth, uint64_t linku1, uint64_t start_val, uint64_t end_val) {
907 struct pst_table_ptr_structn table, table2; 905 struct pst_table_ptr_structn table, table2;
908 pst_descn desc_rec; 906 pst_descn desc_rec;
909 pst_desc_ll *d_ptr=NULL, *parent=NULL; 907 pst_desc_ll *d_ptr=NULL, *parent=NULL;
910 int32_t x, item_count; 908 int32_t item_count;
911 uint64_t old = start_val; 909 uint64_t old = start_val;
910 int x;
912 char *buf = NULL, *bptr; 911 char *buf = NULL, *bptr;
913 912
914 DEBUG_ENT("pst_build_desc_ptr"); 913 DEBUG_ENT("pst_build_desc_ptr");
915 DEBUG_INDEX(("offset %#"PRIx64" depth %i linku1 %#"PRIx64" start %#"PRIx64" end %#"PRIx64"\n", offset, depth, linku1, start_val, end_val)); 914 DEBUG_INDEX(("offset %#"PRIx64" depth %i linku1 %#"PRIx64" start %#"PRIx64" end %#"PRIx64"\n", offset, depth, linku1, start_val, end_val));
916 if (end_val <= start_val) { 915 if (end_val <= start_val) {
942 DEBUG_WARN(("Item count %i too large, max is %i\n", item_count, DESC_COUNT_MAX)); 941 DEBUG_WARN(("Item count %i too large, max is %i\n", item_count, DESC_COUNT_MAX));
943 if (buf) free(buf); 942 if (buf) free(buf);
944 DEBUG_RET(); 943 DEBUG_RET();
945 return -1; 944 return -1;
946 } 945 }
947 x = 0; 946 for (x=0; x<item_count; x++) {
948 while (x < item_count) {
949 bptr += pst_decode_desc(pf, &desc_rec, bptr); 947 bptr += pst_decode_desc(pf, &desc_rec, bptr);
950 x++;
951 if (desc_rec.d_id == 0) break;
952 DEBUG_INDEX(("[%i] Item(%#x) = [d_id = %#"PRIx64", desc_id = %#"PRIx64", list_id = %#"PRIx64", parent_id = %#x]\n", 948 DEBUG_INDEX(("[%i] Item(%#x) = [d_id = %#"PRIx64", desc_id = %#"PRIx64", list_id = %#"PRIx64", parent_id = %#x]\n",
953 depth, x, desc_rec.d_id, desc_rec.desc_id, desc_rec.list_id, desc_rec.parent_id)); 949 depth, x, desc_rec.d_id, desc_rec.desc_id, desc_rec.list_id, desc_rec.parent_id));
954 if ((desc_rec.d_id >= end_val) || (desc_rec.d_id < old)) { 950 if ((desc_rec.d_id >= end_val) || (desc_rec.d_id < old)) {
955 DEBUG_WARN(("This item isn't right. Must be corruption, or I got it wrong!\n")); 951 DEBUG_WARN(("This item isn't right. Must be corruption, or I got it wrong!\n"));
956 DEBUG_HEXDUMPC(buf, DESC_BLOCK_SIZE, 16); 952 DEBUG_HEXDUMPC(buf, DESC_BLOCK_SIZE, 16);
957 if (buf) free(buf); 953 if (buf) free(buf);
958 DEBUG_RET(); 954 DEBUG_RET();
959 return -1; 955 return -1;
960 } 956 }
961 old = desc_rec.d_id; 957 old = desc_rec.d_id;
962 if (x == (int32_t)1) { // first entry 958 if (x == 0) { // first entry
963 if (start_val && (desc_rec.d_id != start_val)) { 959 if (start_val && (desc_rec.d_id != start_val)) {
964 DEBUG_WARN(("This item isn't right. Must be corruption, or I got it wrong!\n")); 960 DEBUG_WARN(("This item isn't right. Must be corruption, or I got it wrong!\n"));
965 if (buf) free(buf); 961 if (buf) free(buf);
966 DEBUG_RET(); 962 DEBUG_RET();
967 return -1; 963 return -1;
968 } 964 }
969 } 965 }
970 // When duplicates found, just update the info.... perhaps this is correct functionality 966 DEBUG_INDEX(("New Record %#"PRIx64" with parent %#x\n", desc_rec.d_id, desc_rec.parent_id));
971 DEBUG_INDEX(("Searching for existing record %#"PRIx64"\n", desc_rec.d_id)); 967 d_ptr = (pst_desc_ll*) xmalloc(sizeof(pst_desc_ll));
972 if (desc_rec.d_id <= *high_id && (d_ptr = pst_getDptr(pf, desc_rec.d_id))) { 968 d_ptr->id = desc_rec.d_id;
973 // This is probably unreachable code, originally written when the 969 d_ptr->parent_id = desc_rec.parent_id;
974 // tree walking code was broken since it did not know about the node 970 d_ptr->list_index = pst_getID(pf, desc_rec.list_id);
975 // count. It always processed all the items in the node, even unused 971 d_ptr->desc = pst_getID(pf, desc_rec.desc_id);
976 // items, and that probably made it look like there were duplicate 972 d_ptr->prev = NULL;
977 // entries. 973 d_ptr->next = NULL;
978 uint64_t bigzero = 0; 974 d_ptr->parent = NULL;
979 DEBUG_INDEX(("Updating Existing Values\n")); 975 d_ptr->child = NULL;
980 d_ptr->list_index = pst_getID(pf, desc_rec.list_id); 976 d_ptr->child_tail = NULL;
981 d_ptr->desc = pst_getID(pf, desc_rec.desc_id); 977 d_ptr->no_child = 0;
982 DEBUG_INDEX(("\tdesc = %#"PRIx64"\tlist_index=%#"PRIx64"\n", 978 record_descriptor(pf, d_ptr); // add to the global tree
983 (d_ptr->desc==NULL ? bigzero : d_ptr->desc->id), 979 //DEBUG_INDEX(("dump parent descriptor tree\n")); //!!
984 (d_ptr->list_index==NULL ? bigzero : d_ptr->list_index->id))); 980 //d_ptr = pst_getDptr(pf, (uint64_t)-1); //!!
985 if (d_ptr->parent && desc_rec.parent_id != d_ptr->parent->id) {
986 DEBUG_INDEX(("WARNING -- Parent of record has changed. Moving it\n"));
987 //hmmm, we must move the record.
988 // first we must remove from current location
989 // change previous record to point next to our next
990 // if no previous, then use parent's child
991 // if no parent then change pf->d_head;
992 // change next's prev to our prev
993 // if no next then change parent's child_tail
994 // if no parent then change pf->d_tail
995 if (d_ptr->prev)
996 d_ptr->prev->next = d_ptr->next;
997 else if (d_ptr->parent)
998 d_ptr->parent->child = d_ptr->next;
999 else
1000 pf->d_head = d_ptr->next;
1001
1002 if (d_ptr->next)
1003 d_ptr->next->prev = d_ptr->prev;
1004 else if (d_ptr->parent)
1005 d_ptr->parent->child_tail = d_ptr->prev;
1006 else
1007 pf->d_tail = d_ptr->prev;
1008
1009 d_ptr->parent_id = desc_rec.parent_id;
1010 d_ptr->prev = NULL;
1011 d_ptr->next = NULL;
1012 d_ptr->parent = NULL;
1013 record_descriptor(pf, d_ptr); // add to the global tree
1014 }
1015 } else {
1016 if (*high_id < desc_rec.d_id) {
1017 DEBUG_INDEX(("Updating New High\n"));
1018 *high_id = desc_rec.d_id;
1019 }
1020 DEBUG_INDEX(("New Record %#"PRIx64" with parent %#x\n", desc_rec.d_id, desc_rec.parent_id));
1021 d_ptr = (pst_desc_ll*) xmalloc(sizeof(pst_desc_ll));
1022 d_ptr->id = desc_rec.d_id;
1023 d_ptr->parent_id = desc_rec.parent_id;
1024 d_ptr->list_index = pst_getID(pf, desc_rec.list_id);
1025 d_ptr->desc = pst_getID(pf, desc_rec.desc_id);
1026 d_ptr->prev = NULL;
1027 d_ptr->next = NULL;
1028 d_ptr->parent = NULL;
1029 d_ptr->child = NULL;
1030 d_ptr->child_tail = NULL;
1031 d_ptr->no_child = 0;
1032 record_descriptor(pf, d_ptr); // add to the global tree
1033 //DEBUG_INDEX(("dump parent descriptor tree\n")); //!!
1034 //d_ptr = pst_getDptr(pf, (uint64_t)-1); //!!
1035 }
1036 } 981 }
1037 } else { 982 } else {
1038 // this node contains node pointers 983 // this node contains node pointers
1039 DEBUG_HEXDUMPC(buf, DESC_BLOCK_SIZE, ITEM_SIZE32); 984 DEBUG_HEXDUMPC(buf, DESC_BLOCK_SIZE, ITEM_SIZE32);
1040 if (item_count > INDEX_COUNT_MAX) { 985 if (item_count > INDEX_COUNT_MAX) {
1041 DEBUG_WARN(("Item count %i too large, max is %i\n", item_count, INDEX_COUNT_MAX)); 986 DEBUG_WARN(("Item count %i too large, max is %i\n", item_count, INDEX_COUNT_MAX));
1042 if (buf) free(buf); 987 if (buf) free(buf);
1043 DEBUG_RET(); 988 DEBUG_RET();
1044 return -1; 989 return -1;
1045 } 990 }
1046 x = 0; 991 for (x=0; x<item_count; x++) {
1047 while (x < item_count) {
1048 bptr += pst_decode_table(pf, &table, bptr); 992 bptr += pst_decode_table(pf, &table, bptr);
1049 x++;
1050 if (table.start == 0) break; 993 if (table.start == 0) break;
1051 if (x < item_count) { 994 if (x < (item_count-1)) {
1052 (void)pst_decode_table(pf, &table2, bptr); 995 (void)pst_decode_table(pf, &table2, bptr);
1053 } 996 }
1054 else { 997 else {
1055 table2.start = end_val; 998 table2.start = end_val;
1056 } 999 }
1061 if (buf) free(buf); 1004 if (buf) free(buf);
1062 DEBUG_RET(); 1005 DEBUG_RET();
1063 return -1; 1006 return -1;
1064 } 1007 }
1065 old = table.start; 1008 old = table.start;
1066 if (x == (int32_t)1) { // first entry 1009 if (x == 0) { // first entry
1067 if (start_val && (table.start != start_val)) { 1010 if (start_val && (table.start != start_val)) {
1068 DEBUG_WARN(("This table isn't right. Must be corruption, or I got it wrong!\n")); 1011 DEBUG_WARN(("This table isn't right. Must be corruption, or I got it wrong!\n"));
1069 if (buf) free(buf); 1012 if (buf) free(buf);
1070 DEBUG_RET(); 1013 DEBUG_RET();
1071 return -1; 1014 return -1;
1072 } 1015 }
1073 } 1016 }
1074 (void)pst_build_desc_ptr(pf, table.offset, depth+1, table.u1, high_id, table.start, table2.start); 1017 (void)pst_build_desc_ptr(pf, table.offset, depth+1, table.u1, table.start, table2.start);
1075 } 1018 }
1076 } 1019 }
1077 if (buf) free(buf); 1020 if (buf) free(buf);
1078 DEBUG_RET(); 1021 DEBUG_RET();
1079 return 0; 1022 return 0;