summaryrefslogtreecommitdiffstats
path: root/tarlz.h
diff options
context:
space:
mode:
Diffstat (limited to 'tarlz.h')
-rw-r--r--tarlz.h87
1 files changed, 67 insertions, 20 deletions
diff --git a/tarlz.h b/tarlz.h
index 196ecb1..0eb0572 100644
--- a/tarlz.h
+++ b/tarlz.h
@@ -15,6 +15,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#define max_file_size ( LLONG_MAX - header_size )
enum { header_size = 512 };
typedef uint8_t Tar_header[header_size];
@@ -104,7 +105,7 @@ class Extended // stores metadata from/for extended records
{
std::string linkpath_; // these are the real metadata
std::string path_;
- unsigned long long file_size_;
+ long long file_size_; // >= 0 && <= max_file_size
// cached sizes; if full_size_ < 0 they must be recalculated
mutable long long edsize_; // extended data size
@@ -137,15 +138,15 @@ public:
const std::string & linkpath() const { return linkpath_; }
const std::string & path() const { return path_; }
- unsigned long long file_size() const { return file_size_; }
- unsigned long long get_file_size_and_reset( const Tar_header header );
+ long long file_size() const { return file_size_; }
+ long long get_file_size_and_reset( const Tar_header header );
void linkpath( const char * const lp ) { linkpath_ = lp; full_size_ = -1; }
void path( const char * const p ) { path_ = p; full_size_ = -1; }
- void file_size( const unsigned long long fs )
- { file_size_ = fs; full_size_ = -1; }
+ void file_size( const long long fs ) { full_size_ = -1;
+ file_size_ = ( fs >= 0 && fs <= max_file_size ) ? fs : 0; }
- unsigned long long full_size() const
+ long long full_size() const
{ if( full_size_ < 0 ) calculate_sizes(); return full_size_; }
bool crc_present() const { return crc_present_; }
@@ -303,8 +304,18 @@ const char * const bad_magic_msg = "Bad magic number (file not in lzip format)."
const char * const bad_dict_msg = "Invalid dictionary size in member header.";
const char * const corrupt_mm_msg = "Corrupt header in multimember file.";
const char * const trailing_msg = "Trailing data not allowed.";
+const char * const bad_hdr_msg = "Corrupt or invalid tar header.";
+const char * const gblrec_msg = "Error in global extended records.";
+const char * const extrec_msg = "Error in extended records.";
+const char * const mcrc_msg = "Missing CRC in extended records.";
+const char * const end_msg = "Archive ends unexpectedly.";
const char * const mem_msg = "Not enough memory.";
const char * const mem_msg2 = "Not enough memory. Try a lower compression level.";
+const char * const fv_msg1 = "Format violation: extended header followed by EOF blocks.";
+const char * const fv_msg2 = "Format violation: extended header followed by global header.";
+const char * const fv_msg3 = "Format violation: consecutive extended headers found.";
+const char * const posix_msg = "This does not look like a POSIX tar archive.";
+const char * const posix_lz_msg = "This does not look like a POSIX tar.lz archive.";
// defined in create.cc
enum Solidity { no_solid, bsolid, dsolid, asolid, solid };
@@ -312,14 +323,14 @@ extern int cl_owner;
extern int cl_group;
extern int cl_data_size;
extern Solidity solidity;
+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,
const int size );
bool write_eof_records( const int outfd, const bool compressed );
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, unsigned long long & file_size,
- const int flag );
+ Tar_header header, long long & file_size, const int flag );
bool block_is_full( const Extended & extended,
const unsigned long long file_size,
unsigned long long & partial_data_size );
@@ -329,7 +340,7 @@ unsigned ustar_chksum( const uint8_t * const header );
bool verify_ustar_chksum( const uint8_t * const header );
bool has_lz_ext( const std::string & name );
class Arg_parser;
-int concatenate( std::string archive_name, const Arg_parser & 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 int num_workers,
@@ -337,10 +348,29 @@ int encode( const std::string & archive_name, const Arg_parser & parser,
const bool dereference );
// defined in create_lz.cc
-int encode_lz( const Arg_parser & parser, const int dictionary_size,
- const int match_len_limit, const int num_workers,
- const int outfd, const int out_slots, const int debug_level,
- const bool dereference );
+int encode_lz( const char * const archive_namep, const Arg_parser & parser,
+ const int dictionary_size, const int match_len_limit,
+ const int num_workers, const int outfd, const int out_slots,
+ const int debug_level, const bool dereference );
+
+// defined in delete.cc
+class Lzip_index;
+bool safe_seek( const int fd, const long long pos );
+int tail_copy( const char * const archive_namep, const Arg_parser & parser,
+ std::vector< char > & name_pending,
+ const Lzip_index & lzip_index, const long long istream_pos,
+ const int infd, const int outfd, int retval );
+int delete_members( const std::string & archive_name, const Arg_parser & parser,
+ const int filenames, const bool missing_crc,
+ const bool permissive );
+
+// defined in delete_lz.cc
+int delete_members_lz( const char * const archive_namep,
+ const Arg_parser & parser,
+ std::vector< char > & name_pending,
+ const Lzip_index & lzip_index,
+ const int filenames, const int infd, const int outfd,
+ const bool missing_crc, const bool permissive );
// defined in exclude.cc
namespace Exclude {
@@ -349,11 +379,13 @@ bool excluded( const char * const filename );
} // end namespace Exclude
// defined in extract.cc
-enum Program_mode { m_none, m_append, m_concatenate, m_create, m_diff,
- m_extract, m_list };
+enum Program_mode { m_none, m_append, m_concatenate, m_create, m_delete,
+ m_diff, m_extract, m_list };
bool block_is_zero( const uint8_t * const buf, const int size );
bool format_member_name( const Extended & extended, const Tar_header header,
Resizable_buffer & rbuf, const bool long_format );
+bool show_member_name( const Extended & extended, const Tar_header header,
+ const int vlevel, Resizable_buffer & rbuf );
bool compare_prefix_dir( const char * const dir, const char * const name );
bool compare_tslash( const char * const name1, const char * const name2 );
int readblock( const int fd, uint8_t * const buf, const int size );
@@ -378,11 +410,26 @@ void xbroadcast( pthread_cond_t * const cond );
bool check_skip_filename( const Arg_parser & parser,
std::vector< char > & name_pending,
const char * const filename, const int filenames );
-class Lzip_index;
-int list_lz( const Arg_parser & parser, std::vector< char > & name_pending,
- const Lzip_index & lzip_index, const int filenames,
- const int debug_level, const int infd, const int num_workers,
- const bool missing_crc, const bool permissive );
+struct LZ_Decoder;
+int archive_read_lz( LZ_Decoder * const decoder, const int infd,
+ long long & file_pos, const long long member_end,
+ const long long cdata_size, uint8_t * const buf,
+ const int size, const char ** msg );
+int parse_records_lz( LZ_Decoder * const decoder, const int infd,
+ long long & file_pos, const long long member_end,
+ const long long cdata_size, long long & data_pos,
+ Extended & extended, const Tar_header header,
+ Resizable_buffer & rbuf, const char ** msg,
+ const bool permissive );
+int skip_member_lz( LZ_Decoder * const decoder, const int infd,
+ long long & file_pos, const long long member_end,
+ const long long cdata_size, long long & data_pos,
+ long long rest, const char ** msg );
+int list_lz( const char * const archive_namep, const Arg_parser & parser,
+ std::vector< char > & name_pending, const Lzip_index & lzip_index,
+ const int filenames, const int debug_level, const int infd,
+ const int num_workers, const bool missing_crc,
+ const bool permissive );
// defined in lzip_index.cc
int seek_read( const int fd, uint8_t * const buf, const int size,