1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
// --------------------------------------------------------------------------
//
// File
// Name: bbackupobjdump.cpp
// Purpose: Dump contents of backup objects
// Created: 3/5/04
//
// --------------------------------------------------------------------------
#include "Box.h"
#include <cstdio>
#include <cstring>
#include "MainHelper.h"
#include "FileStream.h"
#include "BackupStoreDirectory.h"
#include "BackupStoreFile.h"
#include "BackupStoreObjectMagic.h"
#include "MemLeakFindOn.h"
// --------------------------------------------------------------------------
//
// Function
// Name: int main(int, const char *[])
// Purpose: Main fn for bbackupobjdump
// Created: 3/5/04
//
// --------------------------------------------------------------------------
int main(int argc, const char *argv[])
{
MAINHELPER_START
if(argc != 2)
{
::printf("Input file not specified.\nUsage: bbackupobjdump <input file>\n");
return 1;
}
// Open file
FileStream file(argv[1]);
// Read magic number
uint32_t signature;
if(file.Read(&signature, sizeof(signature)) != sizeof(signature))
{
// Too short, can't read signature from it
return false;
}
// Seek back to beginning
file.Seek(0, IOStream::SeekType_Absolute);
// Then... check depending on the type
switch(ntohl(signature))
{
case OBJECTMAGIC_FILE_MAGIC_VALUE_V1:
#ifndef BOX_DISABLE_BACKWARDS_COMPATIBILITY_BACKUPSTOREFILE
case OBJECTMAGIC_FILE_MAGIC_VALUE_V0:
#endif
BackupStoreFile::DumpFile(stdout, false, file);
break;
case OBJECTMAGIC_DIR_MAGIC_VALUE:
{
BackupStoreDirectory dir;
dir.ReadFromStream(file, IOStream::TimeOutInfinite);
dir.Dump(stdout, false);
if(dir.CheckAndFix())
{
::printf("Directory didn't pass checking\n");
}
}
break;
default:
::printf("File does not appear to be a valid box backup object.\n");
break;
}
MAINHELPER_END
}
|