UltraScan III
us_tar.h
Go to the documentation of this file.
1 #ifndef US_TAR_H
2 #define US_TAR_H
3 
4 #include <QtCore>
5 #include "us_extern.h"
6 
7 // Error codes
8 
9 #define TAR_OK 0
10 #define TAR_CANNOTCREATE 1
11 #define TAR_NOTFOUND 2
12 #define TAR_CANTSTAT 3
13 #define TAR_FILENAMETOOLONG 4
14 #define TAR_INTERNAL 5
15 #define TAR_READERROR 6
16 #define TAR_WRITEERROR 7
17 #define TAR_ARCHIVEERROR 8
18 #define TAR_MKDIRFAILED 9
19 
23 {
24  public:
25  US_Tar();
26 
33  int create ( const QString&, const QString&, QStringList* = 0 );
34 
41  int create ( const QString&, const QStringList&,
42  QStringList* = 0 );
43 
49  int extract( const QString&, QStringList* = 0 );
50 
56  int list ( const QString&, QStringList& );
57 
62  QString explain( const int );
63 
64  private:
65 
66  // Class variables
67  int ofd; // Output file descriptor
68  int ifd; // Input file descriptor
69 
70  typedef struct posix_header
71  { /* byte offset */
72  char name[100]; /* 0 */
73  char mode[8]; /* 100 */
74  char uid[8]; /* 108 */
75  char gid[8]; /* 116 */
76  char size[12]; /* 124 */
77  char mtime[12]; /* 136 */
78  char chksum[8]; /* 148 */
79  char typeflag; /* 156 */
80  char linkname[100]; /* 157 */
81  char magic[6]; /* 257 */
82  char version[2]; /* 263 */
83  char uname[32]; /* 265 */
84  char gname[32]; /* 297 */
85  char devmajor[8]; /* 329 */
86  char devminor[8]; /* 337 */
87  char prefix[155]; /* 345 */
88  char undefined[12]; /* 500 */
89  } posix_header;
90 
91 #define BLOCK_SIZE 512
92 #define BLOCKING_FACTOR 20
93 
94  union
95  {
97  unsigned char h[ BLOCK_SIZE ];
98  } tar_header;
99 
100  unsigned char buffer[ BLOCK_SIZE * BLOCKING_FACTOR ];
101 
105 
106  // Internal methods
107 
108  void process_dir ( const QString&, QStringList& );
109  void write_file ( const QString& );
110  void write_long_filename ( const QString& );
111  void flush_buffer ( void );
112  void archive_end ( void );
113  bool validate_header ( void );
114  void read_block ( void );
115  QString get_long_filename ( void );
116  QString format_permissions ( const unsigned int, const bool );
117  QString format_datetime ( const unsigned int );
118 };
119 #endif
120