summaryrefslogtreecommitdiffstats
path: root/tarlz.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2018-12-28 09:51:38 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2018-12-28 09:51:38 +0000
commit48fe8b80e2592f26cae686b0b99547b76018aeb1 (patch)
tree5391d0686afd42f555af3f66f948998077e6a508 /tarlz.h
parentAdding upstream version 0.4. (diff)
downloadtarlz-48fe8b80e2592f26cae686b0b99547b76018aeb1.tar.xz
tarlz-48fe8b80e2592f26cae686b0b99547b76018aeb1.zip
Adding upstream version 0.8.upstream/0.8
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--tarlz.h70
1 files changed, 68 insertions, 2 deletions
diff --git a/tarlz.h b/tarlz.h
index 3bb10c9..bc84c53 100644
--- a/tarlz.h
+++ b/tarlz.h
@@ -32,7 +32,8 @@ enum Lengths {
enum Typeflag {
tf_regular = '0', tf_link = '1', tf_symlink = '2', tf_chardev = '3',
- tf_blockdev = '4', tf_directory = '5', tf_fifo = '6', tf_hiperf = '7' };
+ tf_blockdev = '4', tf_directory = '5', tf_fifo = '6', tf_hiperf = '7',
+ tf_extended = 'x' };
const uint8_t ustar_magic[magic_l] =
{ 0x75, 0x73, 0x74, 0x61, 0x72, 0 }; // "ustar\0"
@@ -41,6 +42,68 @@ inline bool verify_ustar_magic( const uint8_t * const buf )
{ return std::memcmp( buf + magic_o, ustar_magic, magic_l ) == 0; }
+class CRC32C // Uses CRC32-C (Castagnoli) polynomial.
+ {
+ uint32_t data[256]; // Table of CRCs of all 8-bit messages.
+
+public:
+ CRC32C()
+ {
+ for( unsigned n = 0; n < 256; ++n )
+ {
+ unsigned c = n;
+ for( int k = 0; k < 8; ++k )
+ { if( c & 1 ) c = 0x82F63B78U ^ ( c >> 1 ); else c >>= 1; }
+ data[n] = c;
+ }
+ }
+
+ void update_buf( uint32_t & crc, const uint8_t * const buffer,
+ const int size ) const
+ {
+ uint32_t c = crc;
+ for( int i = 0; i < size; ++i )
+ c = data[(c^buffer[i])&0xFF] ^ ( c >> 8 );
+ crc = c;
+ }
+
+ // Calculates the crc of size bytes except a window of 8 bytes at pos
+ uint32_t windowed_crc( const uint8_t * const buffer, const int pos,
+ const int size ) const
+ {
+ uint32_t crc = 0xFFFFFFFFU;
+ update_buf( crc, buffer, pos );
+ update_buf( crc, buffer + pos + 8, size - pos - 8 );
+ return crc ^ 0xFFFFFFFFU;
+ }
+ };
+
+extern const CRC32C crc32c;
+
+
+// Round "size" to the next multiple of header size (512).
+//
+inline unsigned long long round_up( unsigned long long size )
+ {
+ const int rem = size % header_size;
+ const int padding = rem ? header_size - rem : 0;
+ return size + padding;
+ }
+
+
+struct Extended // stores metadata from/for extended records
+ {
+ std::string linkpath;
+ std::string path;
+ unsigned long long size;
+ bool crc_present;
+ Extended() : size( 0 ), crc_present( false ) {}
+ void reset()
+ { linkpath.clear(); path.clear(); size = 0; crc_present = false; }
+ bool empty() { return linkpath.empty() && path.empty() && size == 0; }
+ bool parse( const int infd, const Tar_header header, const bool permissive );
+ };
+
// defined in create.cc
extern int cl_owner;
extern int cl_group;
@@ -48,12 +111,15 @@ extern int cl_solid;
unsigned ustar_chksum( const uint8_t * const buf );
bool verify_ustar_chksum( const uint8_t * const buf );
class Arg_parser;
+int concatenate( const std::string & archive_name, const Arg_parser & parser,
+ const int filenames );
int encode( const std::string & archive_name, const Arg_parser & parser,
const int filenames, const int level, const bool append );
// defined in extract.cc
int decode( const std::string & archive_name, const Arg_parser & parser,
- const int filenames, const bool listing );
+ const int filenames, const bool keep_damaged, const bool listing,
+ const bool missing_crc, const bool permissive );
// defined in main.cc
extern int verbosity;