annotate src/dumpblocks.c @ 46:b2a7f2e0926a

more fixes for 64 bit format
author carl
date Sat, 12 Jan 2008 15:20:53 -0800
parents c508ee15dfca
children f66078abed38
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1 #include <stdio.h>
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
2 #include <stdlib.h>
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
3 #include <unistd.h>
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
4 #include "libpst.h"
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
5 #include "define.h"
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
6
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
7 #define OUT_BUF 20
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
8 int main(int argc, char **argv) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
9 pst_file pstfile;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
10 pst_index_ll *ptr;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
11 char *outdir=NULL, *file=NULL, *outname=NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
12 unsigned char *buf=NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
13 int c;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
14 FILE *fp;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
15
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
16 while ((c=getopt(argc, argv, "o:"))!=-1) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
17 switch(c) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
18 case 'o':
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
19 outdir=optarg;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
20 break;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
21 default:
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
22 printf("Unknown switch %c\n", c);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
23 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
24 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
25 if (optind < argc) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
26 file = argv[optind];
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
27 } else {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
28 printf("Usage: dumpblocks [options] pstfile\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
29 printf("\tcopies the datablocks from the pst file into seperate files\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
30 printf("Options: \n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
31 printf("\t-o target\tSpecify the output directory\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
32 exit(1);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
33 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
34 DEBUG_INIT("dumpblocks.log");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
35 DEBUG_REGISTER_CLOSE();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
36 DEBUG_ENT("main");
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 16
diff changeset
37
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
38 printf("Opening file %s\n",file);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
39 if (pst_open(&pstfile, file, "r")) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
40 printf("Failed to open file %s\n", file);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
41 exit(1);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
42 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
43
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
44 printf("Reading Indexes\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
45 if (pst_load_index(&pstfile)) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
46 printf("Failed to load indexes in file %s\n", argv[1]);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
47 exit(1);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
48 }
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 16
diff changeset
49
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
50 if (outdir != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
51 if (chdir(outdir)) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
52 printf("Failed to change into directory %s\n", outdir);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
53 exit(1);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
54 }
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 16
diff changeset
55
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
56 ptr = pstfile.i_head;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
57 outname = (char*) xmalloc(OUT_BUF);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
58 printf("Saving blocks\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
59 while (ptr != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
60 /* if (pstfile.encryption == PST_ENC) {
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 16
diff changeset
61 c = pst_ff_getIDblock_dec(&pstfile, ptr->id, buf);
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
62 } else {*/
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
63 if ((ptr->id & 0x02)==0 && pstfile.encryption == PST_ENC) {
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 16
diff changeset
64 c = pst_ff_getIDblock_dec(&pstfile, ptr->id, &buf);
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
65 } else {
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 16
diff changeset
66 c = pst_ff_getIDblock(&pstfile, ptr->id, &buf);
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
67 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
68
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
69 if (c > 0) {
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 16
diff changeset
70 snprintf(outname, OUT_BUF, "%llx", ptr->id);
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
71 if ((fp = fopen(outname, "wb")) == NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
72 printf("Failed to open file %s\n", outname);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
73 continue;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
74 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
75 fwrite(buf, 1, c, fp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
76 fclose(fp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
77 } else {
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 16
diff changeset
78 printf("Failed to read block id %#llx\n", ptr->id);
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
79 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
80 ptr = ptr->next;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
81 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
82 pst_close(&pstfile);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
83 DEBUG_RET();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
84 return 0;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
85 }