recoverypacket.h

Go to the documentation of this file.
00001 // This file is part of par2cmdline (a PAR 2.0 compatible file verification and
00002 // repair tool). See https://parchive.sourceforge.net for details of PAR 2.0.
00003 //
00004 // Copyright (c) 2003 Peter Brian Clements
00005 //
00006 // par2cmdline is free software; you can redistribute it and/or modify
00007 // it under the terms of the GNU General Public License as published by
00008 // the Free Software Foundation; either version 2 of the License, or
00009 // (at your option) any later version.
00010 //
00011 // par2cmdline is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014 // GNU General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU General Public License
00017 // along with this program; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00019 
00020 #ifndef __RECOVERYPACKET_H__
00021 #define __RECOVERYPACKET_H__
00022 
00023 // The RecoveryPacket object is used to access a specific recovery
00024 // packet within a recovery file (for when creating them, or using
00025 // them during a repair operation).
00026 
00027 // Because the actual recovery data for the packet may be large, the
00028 // RecoveryPacket object only contains a copy of packet header and
00029 // exponent value for the block and uses a DataBlock object for
00030 // all accesses to the actual recovery data in the packet.
00031 
00032 class RecoveryPacket
00033 {
00034 public:
00035   RecoveryPacket(void);
00036   ~RecoveryPacket(void);
00037 
00038 public:
00039   // Create a recovery packet for a specified file.
00040   void Create(DiskFile      *diskfile,  // Which file will the packet be stored in
00041               u64            offset,    // At what offset will the packet be stored
00042               u64            blocksize, // How much recovery data will it contain
00043               u32            exponent,  // What exponent value will be used
00044               const MD5Hash &setid);    // What is the SetId
00045   // Write some data to the recovery data block and update the recovery packet.
00046   bool WriteData(u64         position,  // Relative position within the data block
00047                  size_t      size,      // Size of data to write to block
00048                  const void *buffer);   // Buffer containing the data to write
00049   // Finish computing the hash of the recovery packet and write the header to disk.
00050   bool WriteHeader(void);
00051 
00052 public:
00053   // Load a recovery packet from a specified file
00054   bool Load(DiskFile *diskfile, u64 offset, PACKET_HEADER &header);
00055 
00056 public:
00057   // Get the lenght of the packet.
00058   u64 PacketLength(void) const;
00059 
00060   // The the exponent of the packet.
00061   u32 Exponent(void) const;
00062 
00063   // The length of the recovery data
00064   u64 BlockSize(void) const;
00065 
00066   // The data block
00067   DataBlock* GetDataBlock(void);
00068 
00069 protected:
00070   DiskFile           *diskfile;       // The specific file that this packet is stored in
00071   u64                 offset;         // The offset at which the packet is stored
00072 
00073   RECOVERYBLOCKPACKET packet;         // The packet (excluding the actual recovery data)
00074 
00075   MD5Context         *packetcontext;  // MD5 Context used to compute the packet hash
00076 
00077   DataBlock           datablock;      // The recovery data block.
00078 };
00079 
00080 inline u64 RecoveryPacket::PacketLength(void) const
00081 {
00082   return packet.header.length;
00083 }
00084 
00085 inline u32 RecoveryPacket::Exponent(void) const
00086 {
00087   return packet.exponent;
00088 }
00089 
00090 inline u64 RecoveryPacket::BlockSize(void) const
00091 {
00092   return packet.header.length - sizeof(packet);
00093 }
00094 
00095 inline DataBlock* RecoveryPacket::GetDataBlock(void)
00096 {
00097   return &datablock;
00098 }
00099 
00100 #endif // __RECOVERYPACKET_H__

Generated on Sun Oct 12 01:45:30 2008 for NNTPGrab by  1.5.4