summaryrefslogtreecommitdiff
path: root/archival/tar.c
diff options
context:
space:
mode:
Diffstat (limited to 'archival/tar.c')
-rw-r--r--archival/tar.c107
1 files changed, 67 insertions, 40 deletions
diff --git a/archival/tar.c b/archival/tar.c
index 344c9dea4..f49fb129e 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -48,37 +48,6 @@
48 48
49#if ENABLE_FEATURE_TAR_CREATE 49#if ENABLE_FEATURE_TAR_CREATE
50 50
51/* Tar file constants */
52
53#define TAR_BLOCK_SIZE 512
54
55/* POSIX tar Header Block, from POSIX 1003.1-1990 */
56#define NAME_SIZE 100
57#define NAME_SIZE_STR "100"
58typedef struct TarHeader { /* byte offset */
59 char name[NAME_SIZE]; /* 0-99 */
60 char mode[8]; /* 100-107 */
61 char uid[8]; /* 108-115 */
62 char gid[8]; /* 116-123 */
63 char size[12]; /* 124-135 */
64 char mtime[12]; /* 136-147 */
65 char chksum[8]; /* 148-155 */
66 char typeflag; /* 156-156 */
67 char linkname[NAME_SIZE]; /* 157-256 */
68 /* POSIX: "ustar" NUL "00" */
69 /* GNU tar: "ustar " NUL */
70 /* Normally it's defined as magic[6] followed by
71 * version[2], but we put them together to save code.
72 */
73 char magic[8]; /* 257-264 */
74 char uname[32]; /* 265-296 */
75 char gname[32]; /* 297-328 */
76 char devmajor[8]; /* 329-336 */
77 char devminor[8]; /* 337-344 */
78 char prefix[155]; /* 345-499 */
79 char padding[12]; /* 500-512 (pad to exactly TAR_BLOCK_SIZE) */
80} TarHeader;
81
82/* 51/*
83** writeTarFile(), writeFileToTarball(), and writeTarHeader() are 52** writeTarFile(), writeFileToTarball(), and writeTarHeader() are
84** the only functions that deal with the HardLinkInfo structure. 53** the only functions that deal with the HardLinkInfo structure.
@@ -193,7 +162,7 @@ static void putOctal(char *cp, int len, off_t value)
193} 162}
194#define PUT_OCTAL(a, b) putOctal((a), sizeof(a), (b)) 163#define PUT_OCTAL(a, b) putOctal((a), sizeof(a), (b))
195 164
196static void chksum_and_xwrite(int fd, struct TarHeader* hp) 165static void chksum_and_xwrite(int fd, struct tar_header_t* hp)
197{ 166{
198 /* POSIX says that checksum is done on unsigned bytes 167 /* POSIX says that checksum is done on unsigned bytes
199 * (Sun and HP-UX gets it wrong... more details in 168 * (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)
235 "00000000000", 204 "00000000000",
236 "00000000000", 205 "00000000000",
237 }; 206 };
238 struct TarHeader header; 207 struct tar_header_t header;
239 int size; 208 int size;
240 209
241 dir = !!dir; /* normalize: 0/1 */ 210 dir = !!dir; /* normalize: 0/1 */
@@ -262,17 +231,13 @@ static void writeLongname(int fd, int type, const char *name, int dir)
262#endif 231#endif
263 232
264/* Write out a tar header for the specified file/directory/whatever */ 233/* Write out a tar header for the specified file/directory/whatever */
265void BUG_tar_header_size(void);
266static int writeTarHeader(struct TarBallInfo *tbInfo, 234static int writeTarHeader(struct TarBallInfo *tbInfo,
267 const char *header_name, const char *fileName, struct stat *statbuf) 235 const char *header_name, const char *fileName, struct stat *statbuf)
268{ 236{
269 struct TarHeader header; 237 struct tar_header_t header;
270
271 if (sizeof(header) != 512)
272 BUG_tar_header_size();
273
274 memset(&header, 0, sizeof(struct TarHeader));
275 238
239 memset(&header, 0, sizeof(header));
240
276 strncpy(header.name, header_name, sizeof(header.name)); 241 strncpy(header.name, header_name, sizeof(header.name));
277 242
278 /* POSIX says to mask mode with 07777. */ 243 /* POSIX says to mask mode with 07777. */
@@ -738,6 +703,68 @@ static void handle_SIGCHLD(int status)
738} 703}
739#endif 704#endif
740 705
706//usage:#define tar_trivial_usage
707//usage: "-[" IF_FEATURE_TAR_CREATE("c") "xt" IF_FEATURE_SEAMLESS_GZ("z")
708//usage: IF_FEATURE_SEAMLESS_BZ2("j") IF_FEATURE_SEAMLESS_LZMA("a")
709//usage: IF_FEATURE_SEAMLESS_Z("Z") IF_FEATURE_TAR_NOPRESERVE_TIME("m") "vO] "
710//usage: IF_FEATURE_TAR_FROM("[-X FILE] ")
711//usage: "[-f TARFILE] [-C DIR] [FILE]..."
712//usage:#define tar_full_usage "\n\n"
713//usage: IF_FEATURE_TAR_CREATE("Create, extract, ")
714//usage: IF_NOT_FEATURE_TAR_CREATE("Extract ")
715//usage: "or list files from a tar file\n"
716//usage: "\nOperation:"
717//usage: IF_FEATURE_TAR_CREATE(
718//usage: "\n c Create"
719//usage: )
720//usage: "\n x Extract"
721//usage: "\n t List"
722//usage: "\nOptions:"
723//usage: "\n f Name of TARFILE ('-' for stdin/out)"
724//usage: "\n C Change to DIR before operation"
725//usage: "\n v Verbose"
726//usage: IF_FEATURE_SEAMLESS_GZ(
727//usage: "\n z (De)compress using gzip"
728//usage: )
729//usage: IF_FEATURE_SEAMLESS_BZ2(
730//usage: "\n j (De)compress using bzip2"
731//usage: )
732//usage: IF_FEATURE_SEAMLESS_LZMA(
733//usage: "\n a (De)compress using lzma"
734//usage: )
735//usage: IF_FEATURE_SEAMLESS_Z(
736//usage: "\n Z (De)compress using compress"
737//usage: )
738//usage: "\n O Extract to stdout"
739//usage: IF_FEATURE_TAR_CREATE(
740//usage: "\n h Follow symlinks"
741//usage: )
742//usage: IF_FEATURE_TAR_NOPRESERVE_TIME(
743//usage: "\n m Don't restore mtime"
744//usage: )
745//usage: IF_FEATURE_TAR_FROM(
746//usage: IF_FEATURE_TAR_LONG_OPTIONS(
747//usage: "\n exclude File to exclude"
748//usage: )
749//usage: "\n X File with names to exclude"
750//usage: "\n T File with names to include"
751//usage: )
752//usage:
753//usage:#define tar_example_usage
754//usage: "$ zcat /tmp/tarball.tar.gz | tar -xf -\n"
755//usage: "$ tar -cf /tmp/tarball.tar /usr/local\n"
756
757// Supported but aren't in --help:
758// o no-same-owner
759// p same-permissions
760// k keep-old
761// numeric-owner
762// no-same-permissions
763// overwrite
764//IF_FEATURE_TAR_TO_COMMAND(
765// to-command
766//)
767
741enum { 768enum {
742 OPTBIT_KEEP_OLD = 8, 769 OPTBIT_KEEP_OLD = 8,
743 IF_FEATURE_TAR_CREATE( OPTBIT_CREATE ,) 770 IF_FEATURE_TAR_CREATE( OPTBIT_CREATE ,)