~gaul/percona-data-recovery-tool-for-innodb/remove-librt

« back to all changes in this revision

Viewing changes to s_indexes.c

  • Committer: aleksandr.kuzminsky
  • Date: 2012-08-17 13:36:17 UTC
  • mfrom: (68.1.3 s_tools)
  • Revision ID: aleksandr.kuzminsky@bm-smm01-20120817133617-sc90ay4mds1qqc76
new tools:
 - bgrep http://debugmo.de/2009/04/bgrep-a-binary-grep/
 - s_tables
 - s_indexes

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include <string.h>
 
3
#include <errno.h>
 
4
#include <stdlib.h>
 
5
#include <stdint.h>
 
6
#include "cbuffer.h"
 
7
#include <inttypes.h>
 
8
 
 
9
int debug = 0;
 
10
 
 
11
void usage(char* p){
 
12
        fprintf(stderr, "Usage: \n\
 
13
        %s /path/to/ibdata table_id\n", p);
 
14
}
 
15
 
 
16
int main(int argc, char** argv)
 
17
{
 
18
        unsigned long int pattern_size = 12;
 
19
        byte pattern[pattern_size];
 
20
        unsigned long int cb_buffer_size = 10*1024*1024;
 
21
        unsigned long int i = 0, j, pos;
 
22
 
 
23
        uint64_t table_id = 0;
 
24
        uint64_t index_id = 0;
 
25
 
 
26
        if(argc != 3){
 
27
                usage(argv[0]);
 
28
                exit(EXIT_FAILURE);
 
29
                }
 
30
        FILE *f = fopen(argv[1], "r");
 
31
        if(f == NULL){
 
32
                fprintf(stderr, "Can't open file '%s'\n", argv[1]);
 
33
                perror("fopen()");
 
34
                usage(argv[0]);
 
35
                exit(EXIT_FAILURE);
 
36
                }
 
37
        pattern[0] = 0x00;
 
38
        pattern[1] = 0x08;
 
39
        table_id = (uint64_t)strtoull(argv[2], NULL, 10);
 
40
        for(i = 0; i < 8; i++){
 
41
                byte r = (table_id >> 8*(7 - i) );
 
42
                pattern[2 + i] = r;
 
43
                if(debug) fprintf(stderr, "pattern[%lu] = %02X\n", 2 + i, pattern[2 + i]);
 
44
                }
 
45
        pattern[10] = 0x01;
 
46
        pattern[11] = 0x08;
 
47
        if(debug){
 
48
                fprintf(stderr, "pattern size: %lu\n", pattern_size);
 
49
                fprintf(stderr, "pattern\nascii: ");
 
50
                for(i = 0; i < pattern_size; i++){
 
51
                        fprintf(stderr, "%c", pattern[i]);
 
52
                        }
 
53
                fprintf(stderr, "\n");
 
54
                fprintf(stderr, "hex: ");
 
55
                for(i = 0; i < pattern_size; i++){
 
56
                        fprintf(stderr, "%02X ", pattern[i]);
 
57
                        }
 
58
                fprintf(stderr, "\n");
 
59
                }
 
60
 
 
61
        CircularBuffer cb;
 
62
        ElemType elem;
 
63
        elem.value = 0;
 
64
        cbInit(&cb, cb_buffer_size);
 
65
 
 
66
        int pattern_found = 0;
 
67
        while(!feof(f)){
 
68
                pos = cbGetPos(&cb);
 
69
                pattern_found = 1;
 
70
                for(j = 0; j < pattern_size; j++){
 
71
                        if(cbIsEmpty(&cb)){
 
72
                                cbFill(&cb, f);
 
73
                                }
 
74
                        if(!cbIsEmpty(&cb)){
 
75
                                cbRead(&cb, &elem);
 
76
                                if(pattern[j] != elem.value){
 
77
                                        pattern_found = 0;
 
78
                                        }
 
79
                                }
 
80
                        }
 
81
                if(pattern_found){
 
82
                        if(debug) fprintf(stderr, "Pattern found\n");
 
83
                        // pattern matches if we reached here
 
84
                        // read next 8 bytes and print
 
85
                        index_id = 0;
 
86
                        for(j = 0; j < 8; j++){
 
87
                                if(cbIsEmpty(&cb)){
 
88
                                        cbFill(&cb, f);
 
89
                                        }
 
90
                                if(!cbIsEmpty(&cb)){
 
91
                                        cbRead(&cb, &elem);
 
92
                                        index_id = index_id | (elem.value << (7-j));
 
93
                                        }
 
94
                                }
 
95
                        printf("%" PRIu32 "-%" PRIu32 "\n", (uint32_t)(index_id >> 32), (uint32_t)(index_id & 0x00000000FFFFFFFF));
 
96
                        }
 
97
                else{
 
98
                        if(debug) fprintf(stderr, "Pattern not found\n");
 
99
                        cbSetPos(&cb, pos+1);
 
100
                        }
 
101
                }
 
102
        return EXIT_SUCCESS;
 
103
}