diff options
Diffstat (limited to 'tarlz.h')
-rw-r--r-- | tarlz.h | 65 |
1 files changed, 51 insertions, 14 deletions
@@ -15,6 +15,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include <climits> +#include <cstring> +#include <string> +#include <vector> +#include <stdint.h> #include <sys/types.h> #define max_file_size ( LLONG_MAX - header_size ) @@ -41,7 +46,7 @@ enum Typeflag { const uint8_t ustar_magic[magic_l] = { 0x75, 0x73, 0x74, 0x61, 0x72, 0 }; // "ustar\0" -inline bool verify_ustar_magic( const uint8_t * const header ) +inline bool verify_ustar_magic( const Tar_header header ) { return std::memcmp( header + magic_o, ustar_magic, magic_l ) == 0; } inline void init_tar_header( Tar_header header ) // set magic and version @@ -106,7 +111,10 @@ public: } return true; } - char * operator()() const { return p; } + char * operator()() { return p; } + const char * operator()() const { return p; } + uint8_t * u8() { return (uint8_t *)p; } + const uint8_t * u8() const { return (const uint8_t *)p; } unsigned long size() const { return size_; } }; @@ -222,6 +230,25 @@ public: }; +struct Lzma_options + { + int dictionary_size; // 4 KiB .. 512 MiB + int match_len_limit; // 5 .. 273 + }; +const Lzma_options option_mapping[] = + { + { 65535, 16 }, // -0 + { 1 << 20, 5 }, // -1 + { 3 << 19, 6 }, // -2 + { 1 << 21, 8 }, // -3 + { 3 << 20, 12 }, // -4 + { 1 << 22, 20 }, // -5 + { 1 << 23, 36 }, // -6 + { 1 << 24, 68 }, // -7 + { 3 << 23, 132 }, // -8 + { 1 << 25, 273 } }; // -9 + + enum { min_dictionary_bits = 12, min_dictionary_size = 1 << min_dictionary_bits, @@ -324,39 +351,44 @@ struct Lzip_trailer }; -enum Program_mode { m_none, m_append, m_concatenate, m_create, m_delete, - m_diff, m_extract, m_list }; +enum Program_mode { m_none, m_append, m_compress, m_concatenate, m_create, + m_delete, m_diff, m_extract, m_list }; enum Solidity { no_solid, bsolid, dsolid, asolid, solid }; class Arg_parser; struct Cl_options // command line options { const Arg_parser & parser; std::string archive_name; + std::string output_filename; long long mtime; Program_mode program_mode; Solidity solidity; int data_size; int debug_level; - int filenames; int level; // compression level, < 0 means uncompressed + int num_files; int num_workers; // start this many worker threads int out_slots; int owner; int group; bool dereference; + bool filenames_given; bool ignore_ids; bool keep_damaged; bool missing_crc; bool permissive; bool preserve_permissions; + bool warn_newer; Cl_options( const Arg_parser & ap ) : parser( ap ), mtime( -1 ), program_mode( m_none ), solidity( bsolid ), - data_size( 0 ), debug_level( 0 ), filenames( 0 ), level( 6 ), + data_size( 0 ), debug_level( 0 ), level( 6 ), num_files( 0 ), num_workers( -1 ), out_slots( 64 ), owner( -1 ), group( -1 ), - dereference( false ), ignore_ids( false ), keep_damaged( false ), - missing_crc( false ), permissive( false ), preserve_permissions( false ) - {} + dereference( false ), filenames_given( false ), ignore_ids( false ), + keep_damaged( false ), missing_crc( false ), permissive( false ), + preserve_permissions( false ), warn_newer( false ) {} + + bool to_stdout() const { return output_filename == "-"; } }; @@ -404,6 +436,9 @@ bool check_skip_filename( const Cl_options & cl_opts, mode_t get_umask(); bool make_path( const std::string & name ); +// defined in compress.cc +int compress( Cl_options & cl_opts ); + // defined in create.cc bool copy_file( const int infd, const int outfd, const long long max_size = -1 ); bool writeblock_wrapper( const int outfd, const uint8_t * const buffer, @@ -413,13 +448,14 @@ const char * remove_leading_dotslash( const char * const filename, const bool dotdot = false ); bool fill_headers( const char * const filename, Extended & extended, Tar_header header, long long & file_size, const int flag ); -bool block_is_full( const Extended & extended, +bool block_is_full( const long long extended_size, const unsigned long long file_size, + const unsigned long long target_size, unsigned long long & partial_data_size ); void set_error_status( const int retval ); int final_exit_status( int retval, const bool show_msg = true ); -unsigned ustar_chksum( const uint8_t * const header ); -bool verify_ustar_chksum( const uint8_t * const header ); +unsigned ustar_chksum( const Tar_header header ); +bool verify_ustar_chksum( const Tar_header header ); bool has_lz_ext( const std::string & name ); int concatenate( const Cl_options & cl_opts ); int encode( Cl_options & cl_opts ); @@ -472,13 +508,14 @@ int seek_read( const int fd, uint8_t * const buf, const int size, // defined in main.cc extern int verbosity; +extern const char * const program_name; struct stat; int hstat( const char * const filename, struct stat * const st, const bool dereference ); int open_instream( const std::string & name ); int open_outstream( const std::string & name, const bool create = true, - Resizable_buffer * const rbufp = 0 ); -void cleanup_and_fail( const int retval = 1 ); // terminate the program + Resizable_buffer * const rbufp = 0, const bool force = true ); +void exit_fail_mt( const int retval = 1 ); // terminate the program void show_error( const char * const msg, const int errcode = 0, const bool help = false ); void format_file_error( std::string & estr, const char * const filename, |