ReactOS  0.4.13-dev-100-gc8611ae
bzip2recover.c File Reference
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
Include dependency graph for bzip2recover.c:

Go to the source code of this file.

Classes

struct  BitStream
 

Macros

#define MaybeUInt64_FMT   "%u"
 
#define True   ((Bool)1)
 
#define False   ((Bool)0)
 
#define BZ_MAX_FILENAME   2000
 
#define BZ_HDR_B   0x42 /* 'B' */
 
#define BZ_HDR_Z   0x5a /* 'Z' */
 
#define BZ_HDR_h   0x68 /* 'h' */
 
#define BZ_HDR_0   0x30 /* '0' */
 
#define BZ_SPLIT_SYM   '/' /* path splitter on Unix platform */
 
#define BLOCK_HEADER_HI   0x00003141UL
 
#define BLOCK_HEADER_LO   0x59265359UL
 
#define BLOCK_ENDMARK_HI   0x00001772UL
 
#define BLOCK_ENDMARK_LO   0x45385090UL
 
#define BZ_MAX_HANDLED_BLOCKS   50000
 

Typedefs

typedef unsigned int MaybeUInt64
 
typedef unsigned int UInt32
 
typedef int Int32
 
typedef unsigned char UChar
 
typedef char Char
 
typedef unsigned char Bool
 

Functions

static void readError (void)
 
static void writeError (void)
 
static void mallocFail (Int32 n)
 
static void tooManyBlocks (Int32 max_handled_blocks)
 
static BitStreambsOpenReadStream (FILE *stream)
 
static BitStreambsOpenWriteStream (FILE *stream)
 
static void bsPutBit (BitStream *bs, Int32 bit)
 
static Int32 bsGetBit (BitStream *bs)
 
static void bsClose (BitStream *bs)
 
static void bsPutUChar (BitStream *bs, UChar c)
 
static void bsPutUInt32 (BitStream *bs, UInt32 c)
 
static Bool endsInBz2 (Char *name)
 
Int32 main (Int32 argc, Char **argv)
 

Variables

Char inFileName [BZ_MAX_FILENAME]
 
Char outFileName [BZ_MAX_FILENAME]
 
Char progName [BZ_MAX_FILENAME]
 
MaybeUInt64 bytesOut = 0
 
MaybeUInt64 bytesIn = 0
 
MaybeUInt64 bStart [BZ_MAX_HANDLED_BLOCKS]
 
MaybeUInt64 bEnd [BZ_MAX_HANDLED_BLOCKS]
 
MaybeUInt64 rbStart [BZ_MAX_HANDLED_BLOCKS]
 
MaybeUInt64 rbEnd [BZ_MAX_HANDLED_BLOCKS]
 

Macro Definition Documentation

◆ BLOCK_ENDMARK_HI

#define BLOCK_ENDMARK_HI   0x00001772UL

Definition at line 287 of file bzip2recover.c.

◆ BLOCK_ENDMARK_LO

#define BLOCK_ENDMARK_LO   0x45385090UL

Definition at line 288 of file bzip2recover.c.

◆ BLOCK_HEADER_HI

#define BLOCK_HEADER_HI   0x00003141UL

Definition at line 284 of file bzip2recover.c.

◆ BLOCK_HEADER_LO

#define BLOCK_HEADER_LO   0x59265359UL

Definition at line 285 of file bzip2recover.c.

◆ BZ_HDR_0

#define BZ_HDR_0   0x30 /* '0' */

Definition at line 77 of file bzip2recover.c.

◆ BZ_HDR_B

#define BZ_HDR_B   0x42 /* 'B' */

Definition at line 74 of file bzip2recover.c.

◆ BZ_HDR_h

#define BZ_HDR_h   0x68 /* 'h' */

Definition at line 76 of file bzip2recover.c.

◆ BZ_HDR_Z

#define BZ_HDR_Z   0x5a /* 'Z' */

Definition at line 75 of file bzip2recover.c.

◆ BZ_MAX_FILENAME

#define BZ_MAX_FILENAME   2000

Definition at line 60 of file bzip2recover.c.

◆ BZ_MAX_HANDLED_BLOCKS

#define BZ_MAX_HANDLED_BLOCKS   50000

Definition at line 294 of file bzip2recover.c.

◆ BZ_SPLIT_SYM

#define BZ_SPLIT_SYM   '/' /* path splitter on Unix platform */

Definition at line 281 of file bzip2recover.c.

◆ False

#define False   ((Bool)0)

Definition at line 57 of file bzip2recover.c.

◆ MaybeUInt64_FMT

#define MaybeUInt64_FMT   "%u"

Definition at line 47 of file bzip2recover.c.

◆ True

#define True   ((Bool)1)

Definition at line 56 of file bzip2recover.c.

Typedef Documentation

◆ Bool

typedef unsigned char Bool

Definition at line 55 of file bzip2recover.c.

◆ Char

typedef char Char

Definition at line 54 of file bzip2recover.c.

◆ Int32

typedef int Int32

Definition at line 52 of file bzip2recover.c.

◆ MaybeUInt64

typedef unsigned int MaybeUInt64

Definition at line 46 of file bzip2recover.c.

◆ UChar

typedef unsigned char UChar

Definition at line 53 of file bzip2recover.c.

◆ UInt32

typedef unsigned int UInt32

Definition at line 51 of file bzip2recover.c.

Function Documentation

◆ bsClose()

static void bsClose ( BitStream bs)
static

Definition at line 218 of file bzip2recover.c.

219 {
220  Int32 retVal;
221 
222  if ( bs->mode == 'w' ) {
223  while ( bs->buffLive < 8 ) {
224  bs->buffLive++;
225  bs->buffer <<= 1;
226  };
227  retVal = putc ( (UChar) (bs->buffer), bs->handle );
228  if (retVal == EOF) writeError();
229  bytesOut++;
230  retVal = fflush ( bs->handle );
231  if (retVal == EOF) writeError();
232  }
233  retVal = fclose ( bs->handle );
234  if (retVal == EOF) {
235  if (bs->mode == 'w') writeError(); else readError();
236  }
237  free ( bs );
238 }
#define free
Definition: debug_ros.c:5
BYTE UChar
Definition: chm_lib.c:102
static void readError(void)
Definition: bzip2recover.c:85
static void writeError(void)
Definition: bzip2recover.c:98
_Check_return_opt_ _CRTIMP int __cdecl putc(_In_ int _Ch, _Inout_ FILE *_File)
MaybeUInt64 bytesOut
Definition: bzip2recover.c:66
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_opt_ _CRTIMP int __cdecl fflush(_Inout_opt_ FILE *_File)
LONG Int32
Definition: chm_lib.c:105
#define EOF
Definition: stdio.h:24
static struct msdos_boot_sector bs
Definition: mkdosfs.c:539

Referenced by main().

◆ bsGetBit()

static Int32 bsGetBit ( BitStream bs)
static

Definition at line 199 of file bzip2recover.c.

200 {
201  if (bs->buffLive > 0) {
202  bs->buffLive --;
203  return ( ((bs->buffer) >> (bs->buffLive)) & 0x1 );
204  } else {
205  Int32 retVal = getc ( bs->handle );
206  if ( retVal == EOF ) {
207  if (errno != 0) readError();
208  return 2;
209  }
210  bs->buffLive = 7;
211  bs->buffer = retVal;
212  return ( ((bs->buffer) >> 7) & 0x1 );
213  }
214 }
_In_ CLIPOBJ _In_ BRUSHOBJ _In_ LONG x1
Definition: winddi.h:3706
_Check_return_ _CRTIMP int __cdecl getc(_Inout_ FILE *_File)
int errno
static void readError(void)
Definition: bzip2recover.c:85
LONG Int32
Definition: chm_lib.c:105
#define EOF
Definition: stdio.h:24
static struct msdos_boot_sector bs
Definition: mkdosfs.c:539

Referenced by main().

◆ bsOpenReadStream()

static BitStream* bsOpenReadStream ( FILE stream)
static

Definition at line 154 of file bzip2recover.c.

155 {
156  BitStream *bs = malloc ( sizeof(BitStream) );
157  if (bs == NULL) mallocFail ( sizeof(BitStream) );
158  bs->handle = stream;
159  bs->buffer = 0;
160  bs->buffLive = 0;
161  bs->mode = 'r';
162  return bs;
163 }
smooth NULL
Definition: ftsmooth.c:416
GLuint GLuint stream
Definition: glext.h:7522
#define malloc
Definition: debug_ros.c:4
static struct msdos_boot_sector bs
Definition: mkdosfs.c:539
static void mallocFail(Int32 n)
Definition: bzip2recover.c:111

Referenced by main().

◆ bsOpenWriteStream()

static BitStream* bsOpenWriteStream ( FILE stream)
static

Definition at line 167 of file bzip2recover.c.

168 {
169  BitStream *bs = malloc ( sizeof(BitStream) );
170  if (bs == NULL) mallocFail ( sizeof(BitStream) );
171  bs->handle = stream;
172  bs->buffer = 0;
173  bs->buffLive = 0;
174  bs->mode = 'w';
175  return bs;
176 }
smooth NULL
Definition: ftsmooth.c:416
GLuint GLuint stream
Definition: glext.h:7522
#define malloc
Definition: debug_ros.c:4
static struct msdos_boot_sector bs
Definition: mkdosfs.c:539
static void mallocFail(Int32 n)
Definition: bzip2recover.c:111

Referenced by main().

◆ bsPutBit()

static void bsPutBit ( BitStream bs,
Int32  bit 
)
static

Definition at line 180 of file bzip2recover.c.

181 {
182  if (bs->buffLive == 8) {
183  Int32 retVal = putc ( (UChar) bs->buffer, bs->handle );
184  if (retVal == EOF) writeError();
185  bytesOut++;
186  bs->buffLive = 1;
187  bs->buffer = bit & 0x1;
188  } else {
189  bs->buffer = ( (bs->buffer << 1) | (bit & 0x1) );
190  bs->buffLive++;
191  };
192 }
_In_ CLIPOBJ _In_ BRUSHOBJ _In_ LONG x1
Definition: winddi.h:3706
BYTE UChar
Definition: chm_lib.c:102
static void writeError(void)
Definition: bzip2recover.c:98
_Check_return_opt_ _CRTIMP int __cdecl putc(_In_ int _Ch, _Inout_ FILE *_File)
MaybeUInt64 bytesOut
Definition: bzip2recover.c:66
LONG Int32
Definition: chm_lib.c:105
#define EOF
Definition: stdio.h:24
static struct msdos_boot_sector bs
Definition: mkdosfs.c:539

Referenced by bsPutUChar(), bsPutUInt32(), and main().

◆ bsPutUChar()

static void bsPutUChar ( BitStream bs,
UChar  c 
)
static

Definition at line 242 of file bzip2recover.c.

243 {
244  Int32 i;
245  for (i = 7; i >= 0; i--)
246  bsPutBit ( bs, (((UInt32) c) >> i) & 0x1 );
247 }
DWORD UInt32
Definition: chm_lib.c:106
_In_ CLIPOBJ _In_ BRUSHOBJ _In_ LONG x1
Definition: winddi.h:3706
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static void bsPutBit(BitStream *bs, Int32 bit)
Definition: bzip2recover.c:180
const GLubyte * c
Definition: glext.h:8905
LONG Int32
Definition: chm_lib.c:105
static struct msdos_boot_sector bs
Definition: mkdosfs.c:539

Referenced by main().

◆ bsPutUInt32()

static void bsPutUInt32 ( BitStream bs,
UInt32  c 
)
static

Definition at line 251 of file bzip2recover.c.

252 {
253  Int32 i;
254 
255  for (i = 31; i >= 0; i--)
256  bsPutBit ( bs, (c >> i) & 0x1 );
257 }
_In_ CLIPOBJ _In_ BRUSHOBJ _In_ LONG x1
Definition: winddi.h:3706
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static void bsPutBit(BitStream *bs, Int32 bit)
Definition: bzip2recover.c:180
const GLubyte * c
Definition: glext.h:8905
LONG Int32
Definition: chm_lib.c:105
static struct msdos_boot_sector bs
Definition: mkdosfs.c:539

Referenced by main().

◆ endsInBz2()

static Bool endsInBz2 ( Char name)
static

Definition at line 261 of file bzip2recover.c.

262 {
263  Int32 n = strlen ( name );
264  if (n <= 4) return False;
265  return
266  (name[n-4] == '.' &&
267  name[n-3] == 'b' &&
268  name[n-2] == 'z' &&
269  name[n-1] == '2');
270 }
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
GLdouble n
Definition: glext.h:7729
#define False
Definition: bzip2recover.c:57
LONG Int32
Definition: chm_lib.c:105
Definition: name.c:36

Referenced by main().

◆ main()

Int32 main ( Int32 argc  ,
Char **  argv 
)

Definition at line 301 of file bzip2recover.c.

302 {
303  FILE* inFile;
304  FILE* outFile;
305  BitStream* bsIn, *bsWr;
306  Int32 b, wrBlock, currBlock, rbCtr;
307  MaybeUInt64 bitsRead;
308 
309  UInt32 buffHi, buffLo, blockCRC;
310  Char* p;
311 
312  strcpy ( progName, argv[0] );
313  inFileName[0] = outFileName[0] = 0;
314 
315  fprintf ( stderr,
316  "bzip2recover 1.0.6: extracts blocks from damaged .bz2 files.\n" );
317 
318  if (argc != 2) {
319  fprintf ( stderr, "%s: usage is `%s damaged_file_name'.\n",
320  progName, progName );
321  switch (sizeof(MaybeUInt64)) {
322  case 8:
323  fprintf(stderr,
324  "\trestrictions on size of recovered file: None\n");
325  break;
326  case 4:
327  fprintf(stderr,
328  "\trestrictions on size of recovered file: 512 MB\n");
329  fprintf(stderr,
330  "\tto circumvent, recompile with MaybeUInt64 as an\n"
331  "\tunsigned 64-bit int.\n");
332  break;
333  default:
334  fprintf(stderr,
335  "\tsizeof(MaybeUInt64) is not 4 or 8 -- "
336  "configuration error.\n");
337  break;
338  }
339  exit(1);
340  }
341 
342  if (strlen(argv[1]) >= BZ_MAX_FILENAME-20) {
343  fprintf ( stderr,
344  "%s: supplied filename is suspiciously (>= %d chars) long. Bye!\n",
345  progName, (int)strlen(argv[1]) );
346  exit(1);
347  }
348 
349  strcpy ( inFileName, argv[1] );
350 
351  inFile = fopen ( inFileName, "rb" );
352  if (inFile == NULL) {
353  fprintf ( stderr, "%s: can't read `%s'\n", progName, inFileName );
354  exit(1);
355  }
356 
357  bsIn = bsOpenReadStream ( inFile );
358  fprintf ( stderr, "%s: searching for block boundaries ...\n", progName );
359 
360  bitsRead = 0;
361  buffHi = buffLo = 0;
362  currBlock = 0;
363  bStart[currBlock] = 0;
364 
365  rbCtr = 0;
366 
367  while (True) {
368  b = bsGetBit ( bsIn );
369  bitsRead++;
370  if (b == 2) {
371  if (bitsRead >= bStart[currBlock] &&
372  (bitsRead - bStart[currBlock]) >= 40) {
373  bEnd[currBlock] = bitsRead-1;
374  if (currBlock > 0)
375  fprintf ( stderr, " block %d runs from " MaybeUInt64_FMT
376  " to " MaybeUInt64_FMT " (incomplete)\n",
377  currBlock, bStart[currBlock], bEnd[currBlock] );
378  } else
379  currBlock--;
380  break;
381  }
382  buffHi = (buffHi << 1) | (buffLo >> 31);
383  buffLo = (buffLo << 1) | (b & 1);
384  if ( ( (buffHi & 0x0000ffff) == BLOCK_HEADER_HI
385  && buffLo == BLOCK_HEADER_LO)
386  ||
387  ( (buffHi & 0x0000ffff) == BLOCK_ENDMARK_HI
388  && buffLo == BLOCK_ENDMARK_LO)
389  ) {
390  if (bitsRead > 49) {
391  bEnd[currBlock] = bitsRead-49;
392  } else {
393  bEnd[currBlock] = 0;
394  }
395  if (currBlock > 0 &&
396  (bEnd[currBlock] - bStart[currBlock]) >= 130) {
397  fprintf ( stderr, " block %d runs from " MaybeUInt64_FMT
398  " to " MaybeUInt64_FMT "\n",
399  rbCtr+1, bStart[currBlock], bEnd[currBlock] );
400  rbStart[rbCtr] = bStart[currBlock];
401  rbEnd[rbCtr] = bEnd[currBlock];
402  rbCtr++;
403  }
404  if (currBlock >= BZ_MAX_HANDLED_BLOCKS)
406  currBlock++;
407 
408  bStart[currBlock] = bitsRead;
409  }
410  }
411 
412  bsClose ( bsIn );
413 
414  /*-- identified blocks run from 1 to rbCtr inclusive. --*/
415 
416  if (rbCtr < 1) {
417  fprintf ( stderr,
418  "%s: sorry, I couldn't find any block boundaries.\n",
419  progName );
420  exit(1);
421  };
422 
423  fprintf ( stderr, "%s: splitting into blocks\n", progName );
424 
425  inFile = fopen ( inFileName, "rb" );
426  if (inFile == NULL) {
427  fprintf ( stderr, "%s: can't open `%s'\n", progName, inFileName );
428  exit(1);
429  }
430  bsIn = bsOpenReadStream ( inFile );
431 
432  /*-- placate gcc's dataflow analyser --*/
433  blockCRC = 0; bsWr = 0;
434 
435  bitsRead = 0;
436  outFile = NULL;
437  wrBlock = 0;
438  while (True) {
439  b = bsGetBit(bsIn);
440  if (b == 2) break;
441  buffHi = (buffHi << 1) | (buffLo >> 31);
442  buffLo = (buffLo << 1) | (b & 1);
443  if (bitsRead == 47+rbStart[wrBlock])
444  blockCRC = (buffHi << 16) | (buffLo >> 16);
445 
446  if (outFile != NULL && bitsRead >= rbStart[wrBlock]
447  && bitsRead <= rbEnd[wrBlock]) {
448  bsPutBit ( bsWr, b );
449  }
450 
451  bitsRead++;
452 
453  if (bitsRead == rbEnd[wrBlock]+1) {
454  if (outFile != NULL) {
455  bsPutUChar ( bsWr, 0x17 ); bsPutUChar ( bsWr, 0x72 );
456  bsPutUChar ( bsWr, 0x45 ); bsPutUChar ( bsWr, 0x38 );
457  bsPutUChar ( bsWr, 0x50 ); bsPutUChar ( bsWr, 0x90 );
458  bsPutUInt32 ( bsWr, blockCRC );
459  bsClose ( bsWr );
460  }
461  if (wrBlock >= rbCtr) break;
462  wrBlock++;
463  } else
464  if (bitsRead == rbStart[wrBlock]) {
465  /* Create the output file name, correctly handling leading paths.
466  (31.10.2001 by Sergey E. Kusikov) */
467  Char* split;
468  Int32 ofs, k;
469  for (k = 0; k < BZ_MAX_FILENAME; k++)
470  outFileName[k] = 0;
473  if (split == NULL) {
474  split = outFileName;
475  } else {
476  ++split;
477  }
478  /* Now split points to the start of the basename. */
479  ofs = split - outFileName;
480  sprintf (split, "rec%5d", wrBlock+1);
481  for (p = split; *p != 0; p++) if (*p == ' ') *p = '0';
482  strcat (outFileName, inFileName + ofs);
483 
484  if ( !endsInBz2(outFileName)) strcat ( outFileName, ".bz2" );
485 
486  fprintf ( stderr, " writing block %d to `%s' ...\n",
487  wrBlock+1, outFileName );
488 
489  outFile = fopen ( outFileName, "wb" );
490  if (outFile == NULL) {
491  fprintf ( stderr, "%s: can't write `%s'\n",
493  exit(1);
494  }
495  bsWr = bsOpenWriteStream ( outFile );
496  bsPutUChar ( bsWr, BZ_HDR_B );
497  bsPutUChar ( bsWr, BZ_HDR_Z );
498  bsPutUChar ( bsWr, BZ_HDR_h );
499  bsPutUChar ( bsWr, BZ_HDR_0 + 9 );
500  bsPutUChar ( bsWr, 0x31 ); bsPutUChar ( bsWr, 0x41 );
501  bsPutUChar ( bsWr, 0x59 ); bsPutUChar ( bsWr, 0x26 );
502  bsPutUChar ( bsWr, 0x53 ); bsPutUChar ( bsWr, 0x59 );
503  }
504  }
505 
506  fprintf ( stderr, "%s: finished\n", progName );
507  return 0;
508 }
MaybeUInt64 rbStart[BZ_MAX_HANDLED_BLOCKS]
Definition: bzip2recover.c:298
static int argc
Definition: ServiceArgs.c:12
Char inFileName[BZ_MAX_FILENAME]
Definition: bzip2recover.c:62
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
MaybeUInt64 rbEnd[BZ_MAX_HANDLED_BLOCKS]
Definition: bzip2recover.c:299
DWORD UInt32
Definition: chm_lib.c:106
static void bsPutUInt32(BitStream *bs, UInt32 c)
Definition: bzip2recover.c:251
#define BZ_HDR_B
Definition: bzip2recover.c:74
#define BLOCK_HEADER_HI
Definition: bzip2recover.c:284
MaybeUInt64 bStart[BZ_MAX_HANDLED_BLOCKS]
Definition: bzip2recover.c:296
static Bool endsInBz2(Char *name)
Definition: bzip2recover.c:261
_Check_return_ _CRTIMP _CONST_RETURN char *__cdecl strrchr(_In_z_ const char *_Str, _In_ int _Ch)
#define argv
Definition: mplay32.c:18
#define BZ_HDR_h
Definition: bzip2recover.c:76
#define sprintf(buf, format,...)
Definition: sprintf.c:55
#define BZ_HDR_0
Definition: bzip2recover.c:77
Char progName[BZ_MAX_FILENAME]
Definition: bzip2recover.c:64
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
static BitStream * bsOpenReadStream(FILE *stream)
Definition: bzip2recover.c:154
char Char
Definition: bzip2.c:161
#define BZ_HDR_Z
Definition: bzip2recover.c:75
static void bsPutBit(BitStream *bs, Int32 bit)
Definition: bzip2recover.c:180
smooth NULL
Definition: ftsmooth.c:416
#define b
Definition: ke_i.h:79
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
static BitStream * bsOpenWriteStream(FILE *stream)
Definition: bzip2recover.c:167
#define BZ_MAX_FILENAME
Definition: bzip2recover.c:60
static LPSTR * split(LPSTR s, LPINT args)
Definition: cmdcons.c:163
#define MaybeUInt64_FMT
Definition: bzip2recover.c:47
Char outFileName[BZ_MAX_FILENAME]
Definition: bzip2recover.c:63
#define True
Definition: bzip2recover.c:56
#define BLOCK_ENDMARK_HI
Definition: bzip2recover.c:287
static Int32 bsGetBit(BitStream *bs)
Definition: bzip2recover.c:199
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
MaybeUInt64 bEnd[BZ_MAX_HANDLED_BLOCKS]
Definition: bzip2recover.c:297
static void tooManyBlocks(Int32 max_handled_blocks)
Definition: bzip2recover.c:123
static void bsClose(BitStream *bs)
Definition: bzip2recover.c:218
static void bsPutUChar(BitStream *bs, UChar c)
Definition: bzip2recover.c:242
LONG Int32
Definition: chm_lib.c:105
unsigned int MaybeUInt64
Definition: bzip2recover.c:46
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
FILE * stderr
void exit(int exitcode)
Definition: _exit.c:33
GLfloat GLfloat p
Definition: glext.h:8902
#define BLOCK_HEADER_LO
Definition: bzip2recover.c:285
#define BZ_MAX_HANDLED_BLOCKS
Definition: bzip2recover.c:294
int k
Definition: mpi.c:3369
#define BZ_SPLIT_SYM
Definition: bzip2recover.c:281
#define BLOCK_ENDMARK_LO
Definition: bzip2recover.c:288

◆ mallocFail()

static void mallocFail ( Int32  n)
static

Definition at line 111 of file bzip2recover.c.

112 {
113  fprintf ( stderr,
114  "%s: malloc failed on request for %d bytes.\n",
115  progName, n );
116  fprintf ( stderr, "%s: warning: output file(s) may be incomplete.\n",
117  progName );
118  exit ( 1 );
119 }
GLdouble n
Definition: glext.h:7729
Char progName[BZ_MAX_FILENAME]
Definition: bzip2recover.c:64
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
FILE * stderr
void exit(int exitcode)
Definition: _exit.c:33

Referenced by bsOpenReadStream(), and bsOpenWriteStream().

◆ readError()

static void readError ( void  )
static

Definition at line 85 of file bzip2recover.c.

86 {
87  fprintf ( stderr,
88  "%s: I/O error reading `%s', possible reason follows.\n",
90  perror ( progName );
91  fprintf ( stderr, "%s: warning: output file(s) may be incomplete.\n",
92  progName );
93  exit ( 1 );
94 }
Char inFileName[BZ_MAX_FILENAME]
Definition: bzip2recover.c:62
Char progName[BZ_MAX_FILENAME]
Definition: bzip2recover.c:64
_CRTIMP void __cdecl perror(_In_opt_z_ const char *_ErrMsg)
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
FILE * stderr
void exit(int exitcode)
Definition: _exit.c:33

Referenced by bsClose(), and bsGetBit().

◆ tooManyBlocks()

static void tooManyBlocks ( Int32  max_handled_blocks)
static

Definition at line 123 of file bzip2recover.c.

124 {
125  fprintf ( stderr,
126  "%s: `%s' appears to contain more than %d blocks\n",
127  progName, inFileName, max_handled_blocks );
128  fprintf ( stderr,
129  "%s: and cannot be handled. To fix, increase\n",
130  progName );
131  fprintf ( stderr,
132  "%s: BZ_MAX_HANDLED_BLOCKS in bzip2recover.c, and recompile.\n",
133  progName );
134  exit ( 1 );
135 }
Char inFileName[BZ_MAX_FILENAME]
Definition: bzip2recover.c:62
Char progName[BZ_MAX_FILENAME]
Definition: bzip2recover.c:64
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
FILE * stderr
void exit(int exitcode)
Definition: _exit.c:33

Referenced by main().

◆ writeError()

static void writeError ( void  )
static

Definition at line 98 of file bzip2recover.c.

99 {
100  fprintf ( stderr,
101  "%s: I/O error reading `%s', possible reason follows.\n",
102  progName, inFileName );
103  perror ( progName );
104  fprintf ( stderr, "%s: warning: output file(s) may be incomplete.\n",
105  progName );
106  exit ( 1 );
107 }
Char inFileName[BZ_MAX_FILENAME]
Definition: bzip2recover.c:62
Char progName[BZ_MAX_FILENAME]
Definition: bzip2recover.c:64
_CRTIMP void __cdecl perror(_In_opt_z_ const char *_ErrMsg)
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
FILE * stderr
void exit(int exitcode)
Definition: _exit.c:33

Referenced by bsClose(), and bsPutBit().

Variable Documentation

◆ bEnd

◆ bStart

◆ bytesIn

MaybeUInt64 bytesIn = 0

Definition at line 67 of file bzip2recover.c.

◆ bytesOut

MaybeUInt64 bytesOut = 0

Definition at line 66 of file bzip2recover.c.

Referenced by bsClose(), and bsPutBit().

◆ inFileName

Char inFileName[BZ_MAX_FILENAME]

Definition at line 62 of file bzip2recover.c.

Referenced by main(), readError(), tooManyBlocks(), and writeError().

◆ outFileName

Char outFileName[BZ_MAX_FILENAME]

Definition at line 63 of file bzip2recover.c.

Referenced by main().

◆ progName

Char progName[BZ_MAX_FILENAME]

Definition at line 64 of file bzip2recover.c.

Referenced by main(), mallocFail(), readError(), tooManyBlocks(), and writeError().

◆ rbEnd

Definition at line 299 of file bzip2recover.c.

Referenced by main().

◆ rbStart

Definition at line 298 of file bzip2recover.c.

Referenced by main().