par2creator.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 // Modifications for concurrent processing, Unicode support, and hierarchial
00021 // directory support are Copyright (c) 2007-2008 Vincent Tan.
00022 // Search for "#if WANT_CONCURRENT" for concurrent code.
00023 // Concurrent processing utilises Intel Thread Building Blocks 2.0,
00024 // Copyright (c) 2007 Intel Corp.
00025 
00026 #ifndef __PAR2CREATOR_H__
00027 #define __PAR2CREATOR_H__
00028 
00029 class MainPacket;
00030 class CreatorPacket;
00031 class CriticalPacket;
00032 
00033 class Par2Creator
00034 {
00035 public:
00036   Par2Creator(void);
00037   ~Par2Creator(void);
00038 
00039   // Create recovery files from the source files specified on the command line
00040   Result Process(const CommandLine &commandline);
00041 
00042 protected:
00043   // Steps in the creation process:
00044 
00045 #if WANT_CONCURRENT
00046 public:
00047   void ProcessDataForOutputIndex(u32 outputstartindex, u32 outputendindex, size_t blocklength, u32 inputblock);
00048  #if WANT_CONCURRENT_PAR2_FILE_OPENING
00049   Par2CreatorSourceFile* OpenSourceFile(const CommandLine::ExtraFile &extrafile);
00050  #endif
00051 protected:
00052 #endif
00053 
00054   // Compute block size from block count or vice versa depending on which was
00055   // specified on the command line
00056   bool ComputeBlockSizeAndBlockCount(const list<:extrafile> &extrafiles);
00057 
00058   // Determine how many recovery blocks to create based on the source block
00059   // count and the requested level of redundancy.
00060   bool ComputeRecoveryBlockCount(u32 redundancy);
00061 
00062   // Determine how much recovery data can be computed on one pass
00063   bool CalculateProcessBlockSize(size_t memorylimit);
00064 
00065   // Determine how many recovery files to create.
00066   bool ComputeRecoveryFileCount(void);
00067 
00068   // Open all of the source files, compute the Hashes and CRC values, and store
00069   // the results in the file verification and file description packets.
00070   bool OpenSourceFiles(const list<:extrafile> &extrafiles);
00071 
00072   // Create the main packet and determine the set_id_hash to use with all packets
00073   bool CreateMainPacket(void);
00074 
00075   // Create the creator packet.
00076   bool CreateCreatorPacket(void);
00077 
00078   // Initialise all of the source blocks ready to start reading data from the source files.
00079   bool CreateSourceBlocks(void);
00080 
00081   // Create all of the output files and allocate all packets to appropriate file offets.
00082   bool InitialiseOutputFiles(string par2filename);
00083 
00084   // Allocate memory buffers for reading and writing data to disk.
00085   bool AllocateBuffers(void);
00086 
00087   // Compute the Reed Solomon matrix
00088   bool ComputeRSMatrix(void);
00089 
00090   // Read source data, process it through the RS matrix and write it to disk.
00091   bool ProcessData(u64 blockoffset, size_t blocklength);
00092 
00093   // Finish computation of the recovery packets and write the headers to disk.
00094   bool WriteRecoveryPacketHeaders(void);
00095 
00096   // Finish computing the full file hash values of the source files
00097   bool FinishFileHashComputation(void);
00098 
00099   // Fill in all remaining details in the critical packets.
00100   bool FinishCriticalPackets(void);
00101 
00102   // Write all other critical packets to disk.
00103   bool WriteCriticalPackets(void);
00104 
00105   // Close all files.
00106   bool CloseFiles(void);
00107 
00108 protected:
00109   CommandLine::NoiseLevel noiselevel; // How noisy we should be
00110 
00111   u64 blocksize;      // The size of each block.
00112   size_t chunksize;   // How much of each block will be processed at a 
00113                       // time (due to memory constraints).
00114 
00115   void *inputbuffer;  // chunksize
00116   void *outputbuffer; // chunksize * recoveryblockcount
00117   
00118   u32 sourcefilecount;   // Number of source files for which recovery data will be computed.
00119   u32 sourceblockcount;  // Total number of data blocks that the source files will be
00120                          // virtualy sliced into.
00121 
00122   u64 largestfilesize;   // The size of the largest source file
00123 
00124   CommandLine::Scheme recoveryfilescheme;  // What scheme will be used to select the
00125                                            // sizes for the recovery files.
00126   
00127   u32 recoveryfilecount;  // The number of recovery files that will be created
00128   u32 recoveryblockcount; // The number of recovery blocks that will be placed
00129                           // in the recovery files.
00130 
00131   u32 firstrecoveryblock; // The lowest exponent value to use for the recovery blocks.
00132 
00133   MainPacket    *mainpacket;    // The main packet
00134   CreatorPacket *creatorpacket; // The creator packet
00135 
00136   vector sourcefiles;  // Array containing details of the source files
00137                                                // as well as the file verification and file
00138                                                // description packets for them.
00139   vector          sourceblocks;     // Array with one entry for every source block.
00140 
00141   vector           recoveryfiles;    // Array with one entry for every recovery file.
00142   vector     recoverypackets;  // Array with one entry for every recovery packet.
00143 
00144   list      criticalpackets;  // A list of all of the critical packets.
00145   list  criticalpacketentries; // A list of which critical packet will
00146                                                     // be written to which recovery file.
00147 
00148   ReedSolomon rs;   // The Reed Solomon matrix.
00149 
00150 #if WANT_CONCURRENT
00151   tbb::atomic          progress;                // How much data has been processed.
00152 #else
00153   u64 progress;     // How much data has been processed.
00154 #endif
00155   u64 totaldata;    // Total amount of data to be processed.
00156 
00157   bool deferhashcomputation; // If we have enough memory to compute all recovery data
00158                              // in one pass, then we can defer the computation of
00159                              // the full file hash and block crc and hashes until
00160                              // the recovery data is computed.
00161 
00162 #if WANT_CONCURRENT
00163   unsigned                  concurrent_processing_level;
00164   tbb::mutex                cout_mutex;
00165   tbb::atomic          cout_in_use; // this is used to display % done w/o blocking a thread
00166   tbb::tick_count           last_cout;   // when cout was used for output
00167 #endif
00168 };
00169 
00170 #endif // __PAR2CREATOR_H__

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