1
// This file is part of par2cmdline (a PAR 2.0 compatible file verification and
2
// repair tool). See http://parchive.sourceforge.net for details of PAR 2.0.
4
// Copyright (c) 2003 Peter Brian Clements
6
// par2cmdline is free software; you can redistribute it and/or modify
7
// it under the terms of the GNU General Public License as published by
8
// the Free Software Foundation; either version 2 of the License, or
9
// (at your option) any later version.
11
// par2cmdline is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
// GNU General Public License for more details.
16
// You should have received a copy of the GNU General Public License
17
// along with this program; if not, write to the Free Software
18
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20
#ifndef __DATABLOCK_H__
21
#define __DATABLOCK_H__
25
// A Data Block is a block of data of a specific length at a specific
26
// offset in a specific file.
28
// It may be either a block of data in a source file from which recovery
29
// data is being computed, a block of recovery data in a recovery file, or
30
// a block in a target file that is being reconstructed.
39
// Set the length of the block
40
void SetLength(u64 length);
42
// Set the location of the block
43
void SetLocation(DiskFile *diskfile, u64 offset);
44
void ClearLocation(void);
47
// Check to see if the location of the block has been set
48
bool IsSet(void) const;
50
// Which disk file is this data block in
51
DiskFile* GetDiskFile(void) const;
53
// What offset is the block located at
54
u64 GetOffset(void) const;
56
// What is the length of this block
57
u64 GetLength(void) const;
60
// Open the disk file if it is not already open (so that it can be read)
63
// Read some of the data from disk into memory.
64
bool ReadData(u64 position, size_t size, void *buffer);
66
// Write some of the data from memory to disk
67
bool WriteData(u64 position, size_t size, const void *buffer, size_t &wrote);
70
DiskFile *diskfile; // Which disk file is the block associated with
71
u64 offset; // What is the file offset
72
u64 length; // How large is the block
76
// Construct the data block
77
inline DataBlock::DataBlock(void)
84
// Destroy the data block
85
inline DataBlock::~DataBlock(void)
89
// Set the length of the block
90
inline void DataBlock::SetLength(u64 _length)
95
// Set the location of the block
96
inline void DataBlock::SetLocation(DiskFile *_diskfile, u64 _offset)
102
// Clear the location of the block
103
inline void DataBlock::ClearLocation(void)
109
// Check to see of the location is known
110
inline bool DataBlock::IsSet(void) const
112
return (diskfile != 0);
115
// Which disk file is this data block in
116
inline DiskFile* DataBlock::GetDiskFile(void) const
121
// What offset is the block located at
122
inline u64 DataBlock::GetOffset(void) const
127
// What is the length of this block
128
inline u64 DataBlock::GetLength(void) const
133
#endif // __DATABLOCK_H__