diff options
Diffstat (limited to 'archival/tar.c')
-rw-r--r-- | archival/tar.c | 107 |
1 files changed, 67 insertions, 40 deletions
diff --git a/archival/tar.c b/archival/tar.c index 344c9de..f49fb12 100644 --- a/archival/tar.c +++ b/archival/tar.c @@ -48,37 +48,6 @@ #if ENABLE_FEATURE_TAR_CREATE -/* Tar file constants */ - -#define TAR_BLOCK_SIZE 512 - -/* POSIX tar Header Block, from POSIX 1003.1-1990 */ -#define NAME_SIZE 100 -#define NAME_SIZE_STR "100" -typedef struct TarHeader { /* byte offset */ - char name[NAME_SIZE]; /* 0-99 */ - char mode[8]; /* 100-107 */ - char uid[8]; /* 108-115 */ - char gid[8]; /* 116-123 */ - char size[12]; /* 124-135 */ - char mtime[12]; /* 136-147 */ - char chksum[8]; /* 148-155 */ - char typeflag; /* 156-156 */ - char linkname[NAME_SIZE]; /* 157-256 */ - /* POSIX: "ustar" NUL "00" */ - /* GNU tar: "ustar " NUL */ - /* Normally it's defined as magic[6] followed by - * version[2], but we put them together to save code. - */ - char magic[8]; /* 257-264 */ - char uname[32]; /* 265-296 */ - char gname[32]; /* 297-328 */ - char devmajor[8]; /* 329-336 */ - char devminor[8]; /* 337-344 */ - char prefix[155]; /* 345-499 */ - char padding[12]; /* 500-512 (pad to exactly TAR_BLOCK_SIZE) */ -} TarHeader; - /* ** writeTarFile(), writeFileToTarball(), and writeTarHeader() are ** the only functions that deal with the HardLinkInfo structure. @@ -193,7 +162,7 @@ static void putOctal(char *cp, int len, off_t value) } #define PUT_OCTAL(a, b) putOctal((a), sizeof(a), (b)) -static void chksum_and_xwrite(int fd, struct TarHeader* hp) +static void chksum_and_xwrite(int fd, struct tar_header_t* hp) { /* POSIX says that checksum is done on unsigned bytes * (Sun and HP-UX gets it wrong... more details in @@ -235,7 +204,7 @@ static void writeLongname(int fd, int type, const char *name, int dir) "00000000000", "00000000000", }; - struct TarHeader header; + struct tar_header_t header; int size; dir = !!dir; /* normalize: 0/1 */ @@ -262,17 +231,13 @@ static void writeLongname(int fd, int type, const char *name, int dir) #endif /* Write out a tar header for the specified file/directory/whatever */ -void BUG_tar_header_size(void); static int writeTarHeader(struct TarBallInfo *tbInfo, const char *header_name, const char *fileName, struct stat *statbuf) { - struct TarHeader header; - - if (sizeof(header) != 512) - BUG_tar_header_size(); - - memset(&header, 0, sizeof(struct TarHeader)); + struct tar_header_t header; + memset(&header, 0, sizeof(header)); + strncpy(header.name, header_name, sizeof(header.name)); /* POSIX says to mask mode with 07777. */ @@ -738,6 +703,68 @@ static void handle_SIGCHLD(int status) } #endif +//usage:#define tar_trivial_usage +//usage: "-[" IF_FEATURE_TAR_CREATE("c") "xt" IF_FEATURE_SEAMLESS_GZ("z") +//usage: IF_FEATURE_SEAMLESS_BZ2("j") IF_FEATURE_SEAMLESS_LZMA("a") +//usage: IF_FEATURE_SEAMLESS_Z("Z") IF_FEATURE_TAR_NOPRESERVE_TIME("m") "vO] " +//usage: IF_FEATURE_TAR_FROM("[-X FILE] ") +//usage: "[-f TARFILE] [-C DIR] [FILE]..." +//usage:#define tar_full_usage "\n\n" +//usage: IF_FEATURE_TAR_CREATE("Create, extract, ") +//usage: IF_NOT_FEATURE_TAR_CREATE("Extract ") +//usage: "or list files from a tar file\n" +//usage: "\nOperation:" +//usage: IF_FEATURE_TAR_CREATE( +//usage: "\n c Create" +//usage: ) +//usage: "\n x Extract" +//usage: "\n t List" +//usage: "\nOptions:" +//usage: "\n f Name of TARFILE ('-' for stdin/out)" +//usage: "\n C Change to DIR before operation" +//usage: "\n v Verbose" +//usage: IF_FEATURE_SEAMLESS_GZ( +//usage: "\n z (De)compress using gzip" +//usage: ) +//usage: IF_FEATURE_SEAMLESS_BZ2( +//usage: "\n j (De)compress using bzip2" +//usage: ) +//usage: IF_FEATURE_SEAMLESS_LZMA( +//usage: "\n a (De)compress using lzma" +//usage: ) +//usage: IF_FEATURE_SEAMLESS_Z( +//usage: "\n Z (De)compress using compress" +//usage: ) +//usage: "\n O Extract to stdout" +//usage: IF_FEATURE_TAR_CREATE( +//usage: "\n h Follow symlinks" +//usage: ) +//usage: IF_FEATURE_TAR_NOPRESERVE_TIME( +//usage: "\n m Don't restore mtime" +//usage: ) +//usage: IF_FEATURE_TAR_FROM( +//usage: IF_FEATURE_TAR_LONG_OPTIONS( +//usage: "\n exclude File to exclude" +//usage: ) +//usage: "\n X File with names to exclude" +//usage: "\n T File with names to include" +//usage: ) +//usage: +//usage:#define tar_example_usage +//usage: "$ zcat /tmp/tarball.tar.gz | tar -xf -\n" +//usage: "$ tar -cf /tmp/tarball.tar /usr/local\n" + +// Supported but aren't in --help: +// o no-same-owner +// p same-permissions +// k keep-old +// numeric-owner +// no-same-permissions +// overwrite +//IF_FEATURE_TAR_TO_COMMAND( +// to-command +//) + enum { OPTBIT_KEEP_OLD = 8, IF_FEATURE_TAR_CREATE( OPTBIT_CREATE ,) |