Skip to content

Commit e112af9

Browse files
committed
gather data
1 parent 13768f5 commit e112af9

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

adfrescue.cc

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <stdio.h>
22
#include <stdlib.h>
3+
#include <string.h>
34
#include <sys/stat.h>
45
#include <sys/types.h>
56

@@ -44,7 +45,9 @@ int main( int argc, char *argv[] ) {
4445

4546
// block chain tables
4647
int *bs = (int*)calloc(size/BSIZE,sizeof(int)); // sequence number
48+
int *next = (int*)calloc(size/BSIZE,sizeof(int)); // next datablock
4749
char *ck = (char*)calloc(size/BSIZE,1); // verified checksum
50+
char *used = (char*)calloc(size/BSIZE,1); // is this block used by any file?
4851

4952
// read entire file
5053
FILE *in = fopen(argv[1],"rb");
@@ -78,6 +81,10 @@ int main( int argc, char *argv[] ) {
7881
// scan blocks
7982
int sectype, self;
8083
for( int i=0; i<size; i+=BSIZE ) {
84+
used[i/BSIZE] = 0;
85+
next[i/BSIZE] = -1;
86+
bs[i/BSIZE] = 0;
87+
8188
sectype = get4(i+BSIZE-4);
8289
self = get4(i+4)*BSIZE;
8390

@@ -91,35 +98,63 @@ int main( int argc, char *argv[] ) {
9198

9299
// data block
93100
if( get4(i) == 8 ) {
94-
// store sequence number
101+
// store sequence number (1...nblocks)
95102
bs[i/BSIZE] = get4(i+8);
103+
// next data block in chain
104+
next[i/BSIZE] = get4(i+16);
96105
}
97106
} else {
98107
if( i/BSIZE > 1 )
99108
ck[i/BSIZE] = 0;
100109
}
101110
}
102111

103-
// 2nd PASS check files
112+
// 2nd PASS check and dump files for which we found header blocks
104113
for (int j=0; j<nfile; ++j)
105114
{
106115
int i = fileheaders[j];
107116

108117
int nblocks = get4(i+8);
109-
printf( "%d: '%s' (%d blocks, first=%d)\n", i/BSIZE, getString(i+BSIZE-79,30), nblocks, get4(i+16) );
118+
int filesize = get4(i+BSIZE-188);
119+
printf( "%d: '%s' (%d bytes)\n", i/BSIZE, getString(i+BSIZE-79,30), filesize);
120+
121+
unsigned char *filedata = (unsigned char*)malloc(filesize);
122+
int fileptr = 0;
110123

111124
int broken = 0;
112125
for (int k=0; k<nblocks; ++k)
113126
{
127+
//
114128
int dblock = get4(i+BSIZE-204-k*4);
115129
if (ck[dblock] == 0) broken++;
130+
131+
// copy localsize bytes
132+
int localsize = get4(dblock*BSIZE+12);
133+
if (fileptr+localsize >= filesize)
134+
{
135+
printf("More data than expected!");
136+
return 1;
137+
}
138+
memcpy(&filedata[fileptr], &data[dblock*BSIZE+24], localsize);
139+
fileptr += localsize;
140+
141+
// flag this block as used
142+
used[dblock] = 1;
116143
}
117144
if (broken==0)
118145
printf("ALL OK!\n");
119146
else
120147
printf("contains %d broken blocks out of %d :-(\n", broken, nblocks);
148+
149+
char fname[1000] = "dummy.dat";
150+
FILE *out = fopen(fname, "rb");
151+
fclose(out);
152+
153+
free(filedata);
121154
}
122155

156+
// 3rd PASS check and dump files for which we found NO header blocks
157+
123158
/*
124159
125160
// write chains

0 commit comments

Comments
 (0)