Mercurial > hg > toybox
annotate toys/pending/tar.c @ 1720:ceb208839770 draft
Quick cleanup pass on tar.
author | Rob Landley <rob@landley.net> |
---|---|
date | Tue, 03 Mar 2015 22:06:55 -0600 |
parents | a471f338b055 |
children |
rev | line source |
---|---|
1379
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
1 /* tar.c - create/extract archives |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
2 * |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
3 * Copyright 2014 Ashwini Kumar <ak.ashwini81@gmail.com> |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
4 * |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
5 * USTAR interchange format is of interest in |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
6 * See http://http://pubs.opengroup.org/onlinepubs/9699919799/utilities/pax.html |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
7 * For writing to external program |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
8 * http://www.gnu.org/software/tar/manual/html_node/Writing-to-an-External-Program.html |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
9 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
10 USE_TAR(NEWTOY(tar, "&(no-recursion)(numeric-owner)(no-same-permissions)(overwrite)(exclude)*(to-command):o(no-same-owner)p(same-permissions)k(keep-old)c(create)|h(dereference)x(extract)|t(list)|v(verbose)z(gzip)O(to-stdout)m(touch)X(exclude-from)*T(files-from)*C(directory):f(file):[!txc]", TOYFLAG_USR|TOYFLAG_BIN)) |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
11 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
12 config TAR |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
13 bool "tar" |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
14 default n |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
15 help |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
16 usage: tar -[cxtzhmvO] [-X FILE] [-T FILE] [-f TARFILE] [-C DIR] |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
17 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
18 Create, extract, or list files from a tar file |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
19 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
20 Operation: |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
21 c Create |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
22 f Name of TARFILE ('-' for stdin/out) |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
23 h Follow symlinks |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
24 m Don't restore mtime |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
25 t List |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
26 v Verbose |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
27 x Extract |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
28 z (De)compress using gzip |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
29 C Change to DIR before operation |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
30 O Extract to stdout |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
31 exclude=FILE File to exclude |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
32 X File with names to exclude |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
33 T File with names to include |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
34 */ |
1720 | 35 |
1379
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
36 #define FOR_tar |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
37 #include "toys.h" |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
38 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
39 GLOBALS( |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
40 char *fname; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
41 char *dir; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
42 struct arg_list *inc_file; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
43 struct arg_list *exc_file; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
44 char *tocmd; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
45 struct arg_list *exc; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
46 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
47 struct arg_list *inc, *pass; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
48 void *inodes, *handle; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
49 ) |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
50 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
51 struct tar_hdr { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
52 char name[100], mode[8], uid[8], gid[8],size[12], mtime[12], chksum[8], |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
53 type, link[100], magic[8], uname[32], gname[32], major[8], minor[8], |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
54 prefix[155], padd[12]; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
55 }; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
56 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
57 struct file_header { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
58 char *name, *link_target, *uname, *gname; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
59 off_t size; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
60 uid_t uid; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
61 gid_t gid; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
62 mode_t mode; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
63 time_t mtime; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
64 dev_t device; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
65 }; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
66 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
67 struct archive_handler { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
68 int src_fd; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
69 struct file_header file_hdr; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
70 off_t offset; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
71 void (*extract_handler)(struct archive_handler*); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
72 }; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
73 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
74 struct inode_list { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
75 struct inode_list *next; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
76 char *arg; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
77 ino_t ino; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
78 dev_t dev; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
79 }; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
80 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
81 static void copy_in_out(int src, int dst, off_t size) |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
82 { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
83 int i, rd, rem = size%512, cnt; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
84 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
85 cnt = size/512 + (rem?1:0); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
86 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
87 for (i = 0; i < cnt; i++) { |
1433
00c20f410c46
Patches to commands for issues reported from static analysis tool.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
1379
diff
changeset
|
88 rd = (i == cnt-1 && rem) ? rem : 512; |
00c20f410c46
Patches to commands for issues reported from static analysis tool.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
1379
diff
changeset
|
89 xreadall(src, toybuf, rd); |
1379
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
90 writeall(dst, toybuf, rd); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
91 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
92 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
93 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
94 //convert to octal |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
95 static void itoo(char *str, int len, off_t val) |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
96 { |
1433
00c20f410c46
Patches to commands for issues reported from static analysis tool.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
1379
diff
changeset
|
97 char *t, tmp[sizeof(off_t)*3+1]; |
1715
a471f338b055
fix format problems in tar.c
Elliott Hughes <enh@google.com>
parents:
1640
diff
changeset
|
98 int cnt = sprintf(tmp, "%0*llo", len, (unsigned long long)val); |
1379
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
99 |
1433
00c20f410c46
Patches to commands for issues reported from static analysis tool.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
1379
diff
changeset
|
100 t = tmp + cnt - len; |
1379
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
101 if (*t == '0') t++; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
102 memcpy(str, t, len); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
103 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
104 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
105 static struct inode_list *seen_inode(void **list, struct stat *st, char *name) |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
106 { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
107 if (!st) llist_traverse(*list, llist_free_arg); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
108 else if (!S_ISDIR(st->st_mode) && st->st_nlink > 1) { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
109 struct inode_list *new; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
110 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
111 for (new = *list; new; new = new->next) |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
112 if(new->ino == st->st_ino && new->dev == st->st_dev) |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
113 return new; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
114 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
115 new = xzalloc(sizeof(*new)); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
116 new->ino = st->st_ino; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
117 new->dev = st->st_dev; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
118 new->arg = xstrdup(name); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
119 new->next = *list; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
120 *list = new; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
121 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
122 return 0; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
123 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
124 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
125 static void write_longname(struct archive_handler *tar, char *name, char type) |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
126 { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
127 struct tar_hdr tmp; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
128 unsigned int sum = 0; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
129 int i, sz = strlen(name) +1; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
130 char buf[512] = {0,}; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
131 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
132 memset(&tmp, 0, sizeof(tmp)); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
133 strcpy(tmp.name, "././@LongLink"); |
1715
a471f338b055
fix format problems in tar.c
Elliott Hughes <enh@google.com>
parents:
1640
diff
changeset
|
134 sprintf(tmp.mode, "%0*d", (int)sizeof(tmp.mode)-1, 0); |
a471f338b055
fix format problems in tar.c
Elliott Hughes <enh@google.com>
parents:
1640
diff
changeset
|
135 sprintf(tmp.uid, "%0*d", (int)sizeof(tmp.uid)-1, 0); |
a471f338b055
fix format problems in tar.c
Elliott Hughes <enh@google.com>
parents:
1640
diff
changeset
|
136 sprintf(tmp.gid, "%0*d", (int)sizeof(tmp.gid)-1, 0); |
a471f338b055
fix format problems in tar.c
Elliott Hughes <enh@google.com>
parents:
1640
diff
changeset
|
137 sprintf(tmp.size, "%0*d", (int)sizeof(tmp.size)-1, 0); |
a471f338b055
fix format problems in tar.c
Elliott Hughes <enh@google.com>
parents:
1640
diff
changeset
|
138 sprintf(tmp.mtime, "%0*d", (int)sizeof(tmp.mtime)-1, 0); |
1379
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
139 itoo(tmp.size, sizeof(tmp.size), sz); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
140 tmp.type = type; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
141 memset(tmp.chksum, ' ', 8); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
142 strcpy(tmp.magic, "ustar "); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
143 for (i= 0; i < 512; i++) sum += (unsigned int)((char*)&tmp)[i]; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
144 itoo(tmp.chksum, sizeof(tmp.chksum)-1, sum); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
145 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
146 writeall(tar->src_fd, (void*) &tmp, sizeof(tmp)); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
147 //write name to archive |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
148 writeall(tar->src_fd, name, sz); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
149 if (sz%512) writeall(tar->src_fd, buf, (512-(sz%512))); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
150 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
151 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
152 static int filter(struct arg_list *lst, char *name) |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
153 { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
154 struct arg_list *cur; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
155 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
156 for (cur = lst; cur; cur = cur->next) |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
157 if (!fnmatch(cur->arg, name, 1<<3)) return 1; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
158 return 0; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
159 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
160 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
161 static void add_file(struct archive_handler *tar, char **nam, struct stat *st) |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
162 { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
163 struct tar_hdr hdr; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
164 struct passwd *pw; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
165 struct group *gr; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
166 struct inode_list *node; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
167 int i, fd =-1; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
168 char *c, *p, *name = *nam, *lnk, *hname, buf[512] = {0,}; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
169 unsigned int sum = 0; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
170 static int warn = 1; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
171 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
172 for (p = name; *p; p++) |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
173 if ((p == name || p[-1] == '/') && *p != '/' |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
174 && filter(TT.exc, p)) return; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
175 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
176 if (S_ISDIR(st->st_mode) && name[strlen(name)-1] != '/') { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
177 lnk = xmprintf("%s/",name); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
178 free(name); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
179 *nam = name = lnk; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
180 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
181 hname = name; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
182 //remove leading '/' or relative path '../' component |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
183 if (*hname == '/') hname++; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
184 if (!*hname) return; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
185 while ((c = strstr(hname, "../"))) hname = c + 3; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
186 if (warn && hname != name) { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
187 printf("removing leading '%.*s' " |
1715
a471f338b055
fix format problems in tar.c
Elliott Hughes <enh@google.com>
parents:
1640
diff
changeset
|
188 "from member names\n", (int)(hname-name), name); |
1379
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
189 warn = 0; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
190 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
191 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
192 memset(&hdr, 0, sizeof(hdr)); |
1640
41efba077b75
Switch a lot of strncpy() calls to xstrncpy().
Rob Landley <rob@landley.net>
parents:
1433
diff
changeset
|
193 xstrncpy(hdr.name, hname, sizeof(hdr.name)); |
1379
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
194 itoo(hdr.mode, sizeof(hdr.mode), st->st_mode &07777); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
195 itoo(hdr.uid, sizeof(hdr.uid), st->st_uid); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
196 itoo(hdr.gid, sizeof(hdr.gid), st->st_gid); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
197 itoo(hdr.size, sizeof(hdr.size), 0); //set size later |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
198 itoo(hdr.mtime, sizeof(hdr.mtime), st->st_mtime); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
199 for (i=0; i<sizeof(hdr.chksum); i++) hdr.chksum[i] = ' '; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
200 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
201 if ((node = seen_inode(&TT.inodes, st, hname))) { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
202 //this is a hard link |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
203 hdr.type = '1'; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
204 if (strlen(node->arg) > sizeof(hdr.link)) |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
205 write_longname(tar, hname, 'K'); //write longname LINK |
1640
41efba077b75
Switch a lot of strncpy() calls to xstrncpy().
Rob Landley <rob@landley.net>
parents:
1433
diff
changeset
|
206 xstrncpy(hdr.link, node->arg, sizeof(hdr.link)); |
1379
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
207 } else if (S_ISREG(st->st_mode)) { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
208 hdr.type = '0'; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
209 if (st->st_size <= (off_t)0777777777777LL) |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
210 itoo(hdr.size, sizeof(hdr.size), st->st_size); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
211 else { |
1715
a471f338b055
fix format problems in tar.c
Elliott Hughes <enh@google.com>
parents:
1640
diff
changeset
|
212 error_msg("can't store file '%s' of size '%lld'\n", |
a471f338b055
fix format problems in tar.c
Elliott Hughes <enh@google.com>
parents:
1640
diff
changeset
|
213 hname, (unsigned long long)st->st_size); |
1379
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
214 return; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
215 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
216 } else if (S_ISLNK(st->st_mode)) { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
217 hdr.type = '2'; //'K' long link |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
218 if (!(lnk = xreadlink(name))) { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
219 perror_msg("readlink"); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
220 return; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
221 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
222 if (strlen(lnk) > sizeof(hdr.link)) |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
223 write_longname(tar, hname, 'K'); //write longname LINK |
1640
41efba077b75
Switch a lot of strncpy() calls to xstrncpy().
Rob Landley <rob@landley.net>
parents:
1433
diff
changeset
|
224 xstrncpy(hdr.link, lnk, sizeof(hdr.link)); |
1379
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
225 free(lnk); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
226 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
227 else if (S_ISDIR(st->st_mode)) hdr.type = '5'; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
228 else if (S_ISFIFO(st->st_mode)) hdr.type = '6'; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
229 else if (S_ISBLK(st->st_mode) || S_ISCHR(st->st_mode)) { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
230 hdr.type = (S_ISCHR(st->st_mode))?'3':'4'; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
231 itoo(hdr.major, sizeof(hdr.major), major(st->st_rdev)); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
232 itoo(hdr.minor, sizeof(hdr.minor), minor(st->st_rdev)); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
233 } else { |
1715
a471f338b055
fix format problems in tar.c
Elliott Hughes <enh@google.com>
parents:
1640
diff
changeset
|
234 error_msg("unknown file type '%o'", st->st_mode & S_IFMT); |
1379
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
235 return; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
236 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
237 if (strlen(hname) > sizeof(hdr.name)) |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
238 write_longname(tar, hname, 'L'); //write longname NAME |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
239 strcpy(hdr.magic, "ustar "); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
240 if ((pw = getpwuid(st->st_uid))) |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
241 snprintf(hdr.uname, sizeof(hdr.uname), "%s", pw->pw_name); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
242 else snprintf(hdr.uname, sizeof(hdr.uname), "%d", st->st_uid); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
243 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
244 if ((gr = getgrgid(st->st_gid))) |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
245 snprintf(hdr.gname, sizeof(hdr.gname), "%s", gr->gr_name); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
246 else snprintf(hdr.gname, sizeof(hdr.gname), "%d", st->st_gid); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
247 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
248 //calculate chksum. |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
249 for (i= 0; i < 512; i++) sum += (unsigned int)((char*)&hdr)[i]; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
250 itoo(hdr.chksum, sizeof(hdr.chksum)-1, sum); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
251 if (toys.optflags & FLAG_v) printf("%s\n",hname); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
252 writeall(tar->src_fd, (void*)&hdr, 512); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
253 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
254 //write actual data to archive |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
255 if (hdr.type != '0') return; //nothing to write |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
256 if ((fd = open(name, O_RDONLY)) < 0) { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
257 perror_msg("can't open '%s'", name); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
258 return; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
259 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
260 copy_in_out(fd, tar->src_fd, st->st_size); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
261 if (st->st_size%512) writeall(tar->src_fd, buf, (512-(st->st_size%512))); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
262 close(fd); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
263 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
264 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
265 static int add_to_tar(struct dirtree *node) |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
266 { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
267 struct stat st; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
268 char *path; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
269 struct archive_handler *hdl = (struct archive_handler*)TT.handle; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
270 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
271 if (!fstat(hdl->src_fd, &st) && st.st_dev == node->st.st_dev |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
272 && st.st_ino == node->st.st_ino) { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
273 error_msg("'%s' file is the archive; not dumped", TT.fname); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
274 return ((DIRTREE_RECURSE | ((toys.optflags & FLAG_h)?DIRTREE_SYMFOLLOW:0))); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
275 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
276 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
277 if (node->parent && !dirtree_notdotdot(node)) return 0; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
278 path = dirtree_path(node, 0); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
279 add_file(hdl, &path, &(node->st)); //path may be modified |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
280 free(path); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
281 if (toys.optflags & FLAG_no_recursion) return 0; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
282 return ((DIRTREE_RECURSE | ((toys.optflags & FLAG_h)?DIRTREE_SYMFOLLOW:0))); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
283 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
284 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
285 static void compress_stream(struct archive_handler *tar_hdl) |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
286 { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
287 int pipefd[2]; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
288 pid_t cpid; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
289 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
290 if (pipe(pipefd) == -1) error_exit("pipe"); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
291 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
292 signal(SIGPIPE, SIG_IGN); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
293 cpid = fork(); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
294 if (cpid == -1) perror_exit("fork"); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
295 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
296 if (!cpid) { /* Child reads from pipe */ |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
297 char *argv[] = {"gzip", "-f", NULL}; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
298 xclose(pipefd[1]); /* Close unused write*/ |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
299 dup2(pipefd[0], 0); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
300 dup2(tar_hdl->src_fd, 1); //write to tar fd |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
301 xexec(argv); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
302 } else { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
303 xclose(pipefd[0]); /* Close unused read end */ |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
304 dup2(pipefd[1], tar_hdl->src_fd); //write to pipe |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
305 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
306 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
307 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
308 static void extract_to_stdout(struct archive_handler *tar) |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
309 { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
310 struct file_header *file_hdr = &tar->file_hdr; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
311 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
312 copy_in_out(tar->src_fd, 0, file_hdr->size); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
313 tar->offset += file_hdr->size; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
314 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
315 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
316 static void extract_to_command(struct archive_handler *tar) |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
317 { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
318 int pipefd[2], status = 0; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
319 pid_t cpid; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
320 struct file_header *file_hdr = &tar->file_hdr; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
321 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
322 if (pipe(pipefd) == -1) error_exit("pipe"); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
323 if (!S_ISREG(file_hdr->mode)) return; //only regular files are supported. |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
324 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
325 cpid = fork(); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
326 if (cpid == -1) perror_exit("fork"); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
327 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
328 if (!cpid) { // Child reads from pipe |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
329 char buf[64], *argv[4] = {"sh", "-c", TT.tocmd, NULL}; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
330 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
331 setenv("TAR_FILETYPE", "f", 1); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
332 sprintf(buf, "%0o", file_hdr->mode); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
333 setenv("TAR_MODE", buf, 1); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
334 sprintf(buf, "%ld", (long)file_hdr->size); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
335 setenv("TAR_SIZE", buf, 1); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
336 setenv("TAR_FILENAME", file_hdr->name, 1); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
337 setenv("TAR_UNAME", file_hdr->uname, 1); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
338 setenv("TAR_GNAME", file_hdr->gname, 1); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
339 sprintf(buf, "%0o", (int)file_hdr->mtime); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
340 setenv("TAR_MTIME", buf, 1); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
341 sprintf(buf, "%0o", file_hdr->uid); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
342 setenv("TAR_UID", buf, 1); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
343 sprintf(buf, "%0o", file_hdr->gid); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
344 setenv("TAR_GID", buf, 1); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
345 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
346 xclose(pipefd[1]); // Close unused write |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
347 dup2(pipefd[0], 0); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
348 signal(SIGPIPE, SIG_DFL); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
349 xexec(argv); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
350 } else { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
351 xclose(pipefd[0]); // Close unused read end |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
352 copy_in_out(tar->src_fd, pipefd[1], file_hdr->size); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
353 tar->offset += file_hdr->size; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
354 xclose(pipefd[1]); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
355 waitpid(cpid, &status, 0); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
356 if (WIFSIGNALED(status)) |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
357 xprintf("tar : %d: child returned %d\n", cpid, WTERMSIG(status)); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
358 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
359 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
360 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
361 static void extract_to_disk(struct archive_handler *tar) |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
362 { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
363 int flags, dst_fd = -1; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
364 char *s; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
365 struct stat ex; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
366 struct file_header *file_hdr = &tar->file_hdr; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
367 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
368 if (file_hdr->name[strlen(file_hdr->name)-1] == '/') |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
369 file_hdr->name[strlen(file_hdr->name)-1] = 0; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
370 //Regular file with preceding path |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
371 if ((s = strrchr(file_hdr->name, '/'))) { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
372 if (mkpathat(AT_FDCWD, file_hdr->name, 00, 2) && errno !=EEXIST) { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
373 error_msg(":%s: not created", file_hdr->name); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
374 return; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
375 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
376 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
377 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
378 //remove old file, if exists |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
379 if (!(toys.optflags & FLAG_k) && !S_ISDIR(file_hdr->mode) |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
380 && !lstat( file_hdr->name, &ex)) { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
381 if (unlink(file_hdr->name)) { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
382 perror_msg("can't remove: %s",file_hdr->name); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
383 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
384 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
385 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
386 //hard link |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
387 if (S_ISREG(file_hdr->mode) && file_hdr->link_target) { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
388 if (link(file_hdr->link_target, file_hdr->name)) |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
389 perror_msg("can't link '%s' -> '%s'",file_hdr->name, file_hdr->link_target); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
390 goto COPY; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
391 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
392 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
393 switch (file_hdr->mode & S_IFMT) { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
394 case S_IFREG: |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
395 flags = O_WRONLY|O_CREAT|O_EXCL; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
396 if (toys.optflags & FLAG_overwrite) flags = O_WRONLY|O_CREAT|O_TRUNC; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
397 dst_fd = open(file_hdr->name, flags, file_hdr->mode & 07777); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
398 if (dst_fd == -1) perror_msg("%s: can't open", file_hdr->name); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
399 break; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
400 case S_IFDIR: |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
401 if ((mkdir(file_hdr->name, file_hdr->mode) == -1) && errno != EEXIST) |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
402 perror_msg("%s: can't create", file_hdr->name); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
403 break; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
404 case S_IFLNK: |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
405 if (symlink(file_hdr->link_target, file_hdr->name)) |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
406 perror_msg("can't link '%s' -> '%s'",file_hdr->name, file_hdr->link_target); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
407 break; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
408 case S_IFBLK: |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
409 case S_IFCHR: |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
410 case S_IFIFO: |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
411 if (mknod(file_hdr->name, file_hdr->mode, file_hdr->device)) |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
412 perror_msg("can't create '%s'", file_hdr->name); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
413 break; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
414 default: |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
415 printf("type not yet supported\n"); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
416 break; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
417 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
418 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
419 //copy file.... |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
420 COPY: |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
421 copy_in_out(tar->src_fd, dst_fd, file_hdr->size); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
422 tar->offset += file_hdr->size; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
423 close(dst_fd); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
424 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
425 if (S_ISLNK(file_hdr->mode)) return; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
426 if (!(toys.optflags & FLAG_o)) { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
427 //set ownership..., --no-same-owner, --numeric-owner |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
428 uid_t u = file_hdr->uid; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
429 gid_t g = file_hdr->gid; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
430 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
431 if (!(toys.optflags & FLAG_numeric_owner)) { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
432 struct group *gr = getgrnam(file_hdr->gname); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
433 struct passwd *pw = getpwnam(file_hdr->uname); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
434 if (pw) u = pw->pw_uid; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
435 if (gr) g = gr->gr_gid; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
436 } |
1720 | 437 if (chown(file_hdr->name, u, g)) |
438 perror_msg("chown %d:%d '%s'", u, g, file_hdr->name);; | |
1379
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
439 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
440 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
441 if (toys.optflags & FLAG_p) // || !(toys.optflags & FLAG_no_same_permissions)) |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
442 chmod(file_hdr->name, file_hdr->mode); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
443 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
444 //apply mtime |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
445 if (!(toys.optflags & FLAG_m)) { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
446 struct timeval times[2] = {{file_hdr->mtime, 0},{file_hdr->mtime, 0}}; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
447 utimes(file_hdr->name, times); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
448 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
449 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
450 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
451 static void add_to_list(struct arg_list **llist, char *name) |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
452 { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
453 struct arg_list **list = llist; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
454 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
455 while (*list) list=&((*list)->next); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
456 *list = xzalloc(sizeof(struct arg_list)); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
457 (*list)->arg = name; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
458 if ((name[strlen(name)-1] == '/') && strlen(name) != 1) |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
459 name[strlen(name)-1] = '\0'; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
460 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
461 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
462 static void add_from_file(struct arg_list **llist, struct arg_list *flist) |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
463 { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
464 char *line = NULL; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
465 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
466 while (flist) { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
467 int fd = 0; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
468 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
469 if (strcmp((char *)flist->arg, "-")) |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
470 fd = xopen((char *)flist->arg, O_RDONLY); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
471 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
472 while ((line = get_line(fd))) { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
473 add_to_list(llist, line); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
474 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
475 if (fd) close(fd); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
476 flist = flist->next; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
477 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
478 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
479 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
480 static struct archive_handler *init_handler() |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
481 { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
482 struct archive_handler *tar_hdl = xzalloc(sizeof(struct archive_handler)); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
483 tar_hdl->extract_handler = extract_to_disk; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
484 return tar_hdl; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
485 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
486 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
487 //convert octal to int |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
488 static int otoi(char *str, int len) |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
489 { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
490 long val; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
491 char *endp, inp[len+1]; //1 for NUL termination |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
492 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
493 memcpy(inp, str, len); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
494 inp[len] = '\0'; //nul-termination made sure |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
495 val = strtol(inp, &endp, 8); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
496 if (*endp && *endp != ' ') error_exit("invalid param"); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
497 return (int)val; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
498 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
499 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
500 static void extract_stream(struct archive_handler *tar_hdl) |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
501 { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
502 int pipefd[2]; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
503 pid_t cpid; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
504 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
505 if (pipe(pipefd) == -1) error_exit("pipe"); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
506 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
507 cpid = fork(); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
508 if (cpid == -1) perror_exit("fork"); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
509 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
510 if (!cpid) { /* Child reads from pipe */ |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
511 char *argv[] = {"gunzip", "-cf", "-", NULL}; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
512 xclose(pipefd[0]); /* Close unused read*/ |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
513 dup2(tar_hdl->src_fd, 0); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
514 dup2(pipefd[1], 1); //write to pipe |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
515 xexec(argv); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
516 } else { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
517 xclose(pipefd[1]); /* Close unused read end */ |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
518 dup2(pipefd[0], tar_hdl->src_fd); //read from pipe |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
519 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
520 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
521 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
522 static char *process_extended_hdr(struct archive_handler *tar, int size) |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
523 { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
524 char *value = NULL, *p, *buf = xzalloc(size+1); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
525 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
526 if (readall(tar->src_fd, buf, size) != size) error_exit("short read"); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
527 buf[size] = 0; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
528 tar->offset += size; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
529 p = buf; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
530 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
531 while (size) { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
532 char *key; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
533 int len, n; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
534 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
535 // extended records are of the format: "LEN NAME=VALUE\n" |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
536 sscanf(p, "%d %n", &len, &n); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
537 key = p + n; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
538 p += len; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
539 size -= len; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
540 p[-1] = 0; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
541 if (size < 0) { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
542 error_msg("corrupted extended header"); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
543 break; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
544 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
545 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
546 len = strlen("path="); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
547 if (!strncmp(key, "path=", len)) { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
548 value = key + strlen("path="); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
549 break; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
550 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
551 } |
1433
00c20f410c46
Patches to commands for issues reported from static analysis tool.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
1379
diff
changeset
|
552 if (value) value = xstrdup(value); |
00c20f410c46
Patches to commands for issues reported from static analysis tool.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
1379
diff
changeset
|
553 free(buf); |
00c20f410c46
Patches to commands for issues reported from static analysis tool.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
1379
diff
changeset
|
554 return value; |
1379
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
555 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
556 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
557 static void tar_skip(struct archive_handler *tar, int sz) |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
558 { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
559 int x; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
560 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
561 while ((x = lskip(tar->src_fd, sz))) { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
562 tar->offset += sz - x; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
563 sz = x; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
564 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
565 tar->offset += sz; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
566 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
567 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
568 static void unpack_tar(struct archive_handler *tar_hdl) |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
569 { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
570 struct tar_hdr tar; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
571 struct file_header *file_hdr; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
572 int i, j, maj, min, sz, e = 0; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
573 unsigned int cksum; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
574 unsigned char *gzMagic; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
575 char *longname = NULL, *longlink = NULL; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
576 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
577 while (1) { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
578 cksum = 0; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
579 if (tar_hdl->offset % 512) { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
580 sz = 512 - tar_hdl->offset % 512; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
581 tar_skip(tar_hdl, sz); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
582 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
583 i = readall(tar_hdl->src_fd, &tar, 512); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
584 tar_hdl->offset += i; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
585 if (i != 512) { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
586 if (i >= 2) goto CHECK_MAGIC; //may be a small (<512 byte)zipped file |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
587 error_exit("read error"); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
588 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
589 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
590 if (!tar.name[0]) { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
591 if (e) return; //end of tar 2 empty blocks |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
592 e = 1;//empty jump to next block |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
593 continue; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
594 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
595 if (strncmp(tar.magic, "ustar", 5)) { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
596 //try detecting by reading magic |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
597 CHECK_MAGIC: |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
598 gzMagic = (unsigned char*)&tar; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
599 if ((gzMagic[0] == 0x1f) && (gzMagic[1] == 0x8b) |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
600 && !lseek(tar_hdl->src_fd, -i, SEEK_CUR)) { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
601 tar_hdl->offset -= i; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
602 extract_stream(tar_hdl); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
603 continue; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
604 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
605 error_exit("invalid tar format"); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
606 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
607 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
608 for (j = 0; j<148; j++) cksum += (unsigned int)((char*)&tar)[j]; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
609 for (j = 156; j<500; j++) cksum += (unsigned int)((char*)&tar)[j]; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
610 //cksum field itself treated as ' ' |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
611 for ( j= 0; j<8; j++) cksum += (unsigned int)' '; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
612 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
613 if (cksum != otoi(tar.chksum, sizeof(tar.chksum))) error_exit("wrong cksum"); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
614 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
615 file_hdr = &tar_hdl->file_hdr; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
616 memset(file_hdr, 0, sizeof(struct file_header)); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
617 file_hdr->mode = otoi(tar.mode, sizeof(tar.mode)); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
618 file_hdr->uid = otoi(tar.uid, sizeof(tar.uid)); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
619 file_hdr->gid = otoi(tar.gid, sizeof(tar.gid)); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
620 file_hdr->size = otoi(tar.size, sizeof(tar.size)); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
621 file_hdr->mtime = otoi(tar.mtime, sizeof(tar.mtime)); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
622 file_hdr->uname = xstrdup(tar.uname); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
623 file_hdr->gname = xstrdup(tar.gname); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
624 maj = otoi(tar.major, sizeof(tar.major)); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
625 min = otoi(tar.minor, sizeof(tar.minor)); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
626 file_hdr->device = makedev(maj, min); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
627 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
628 if (tar.type <= '7') { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
629 if (tar.link[0]) { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
630 sz = sizeof(tar.link); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
631 file_hdr->link_target = xmalloc(sz + 1); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
632 memcpy(file_hdr->link_target, tar.link, sz); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
633 file_hdr->link_target[sz] = '\0'; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
634 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
635 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
636 file_hdr->name = xzalloc(256);// pathname supported size |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
637 if (tar.prefix[0]) { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
638 memcpy(file_hdr->name, tar.prefix, sizeof(tar.prefix)); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
639 sz = strlen(file_hdr->name); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
640 if (file_hdr->name[sz-1] != '/') file_hdr->name[sz] = '/'; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
641 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
642 sz = strlen(file_hdr->name); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
643 memcpy(file_hdr->name + sz, tar.name, sizeof(tar.name)); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
644 if (file_hdr->name[255]) error_exit("filename too long"); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
645 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
646 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
647 switch (tar.type) { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
648 // case '\0': |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
649 case '0': |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
650 case '7': |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
651 case '1': //Hard Link |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
652 file_hdr->mode |= S_IFREG; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
653 break; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
654 case '2': |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
655 file_hdr->mode |= S_IFLNK; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
656 break; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
657 case '3': |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
658 file_hdr->mode |= S_IFCHR; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
659 break; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
660 case '4': |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
661 file_hdr->mode |= S_IFBLK; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
662 break; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
663 case '5': |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
664 file_hdr->mode |= S_IFDIR; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
665 break; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
666 case '6': |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
667 file_hdr->mode |= S_IFIFO; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
668 break; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
669 case 'K': |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
670 longlink = xzalloc(file_hdr->size +1); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
671 xread(tar_hdl->src_fd, longlink, file_hdr->size); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
672 tar_hdl->offset += file_hdr->size; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
673 continue; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
674 case 'L': |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
675 free(longname); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
676 longname = xzalloc(file_hdr->size +1); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
677 xread(tar_hdl->src_fd, longname, file_hdr->size); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
678 tar_hdl->offset += file_hdr->size; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
679 continue; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
680 case 'D': |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
681 case 'M': |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
682 case 'N': |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
683 case 'S': |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
684 case 'V': |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
685 case 'g': // pax global header |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
686 tar_skip(tar_hdl, file_hdr->size); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
687 continue; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
688 case 'x': // pax extended header |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
689 free(longname); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
690 longname = process_extended_hdr(tar_hdl, file_hdr->size); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
691 continue; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
692 default: break; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
693 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
694 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
695 if (longname) { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
696 free(file_hdr->name); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
697 file_hdr->name = longname; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
698 longname = NULL; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
699 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
700 if (longlink) { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
701 free(file_hdr->link_target); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
702 file_hdr->link_target = longlink; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
703 longlink = NULL; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
704 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
705 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
706 if ((file_hdr->mode & S_IFREG) && |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
707 file_hdr->name[strlen(file_hdr->name)-1] == '/') { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
708 file_hdr->name[strlen(file_hdr->name)-1] = '\0'; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
709 file_hdr->mode &= ~S_IFREG; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
710 file_hdr->mode |= S_IFDIR; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
711 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
712 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
713 if ((file_hdr->link_target && *(file_hdr->link_target)) |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
714 || S_ISLNK(file_hdr->mode) || S_ISDIR(file_hdr->mode)) |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
715 file_hdr->size = 0; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
716 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
717 if (filter(TT.exc, file_hdr->name) || |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
718 (TT.inc && !filter(TT.inc, file_hdr->name))) goto SKIP; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
719 add_to_list(&TT.pass, xstrdup(file_hdr->name)); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
720 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
721 if (toys.optflags & FLAG_t) { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
722 if (toys.optflags & FLAG_v) { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
723 char perm[11]; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
724 struct tm *lc = localtime((const time_t*)&(file_hdr->mtime)); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
725 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
726 mode_to_string(file_hdr->mode, perm); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
727 printf("%s %s/%s %9ld %d-%02d-%02d %02d:%02d:%02d ",perm,file_hdr->uname, |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
728 file_hdr->gname, (long)file_hdr->size, 1900+lc->tm_year, |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
729 1+lc->tm_mon, lc->tm_mday, lc->tm_hour, lc->tm_min, lc->tm_sec); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
730 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
731 printf("%s",file_hdr->name); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
732 if (file_hdr->link_target) printf(" -> %s",file_hdr->link_target); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
733 xputc('\n'); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
734 SKIP: |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
735 tar_skip(tar_hdl, file_hdr->size); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
736 } else { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
737 if (toys.optflags & FLAG_v) printf("%s\n",file_hdr->name); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
738 tar_hdl->extract_handler(tar_hdl); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
739 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
740 free(file_hdr->name); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
741 free(file_hdr->link_target); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
742 free(file_hdr->uname); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
743 free(file_hdr->gname); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
744 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
745 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
746 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
747 void tar_main(void) |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
748 { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
749 struct archive_handler *tar_hdl; |
1720 | 750 int fd = 0; |
1379
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
751 struct arg_list *tmp; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
752 char **args = toys.optargs; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
753 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
754 if (!geteuid()) toys.optflags |= FLAG_p; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
755 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
756 for (tmp = TT.exc; tmp; tmp = tmp->next) |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
757 tmp->arg = xstrdup(tmp->arg); //freeing at the end fails otherwise |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
758 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
759 while(*args) add_to_list(&TT.inc, xstrdup(*args++)); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
760 if (toys.optflags & FLAG_X) add_from_file(&TT.exc, TT.exc_file); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
761 if (toys.optflags & FLAG_T) add_from_file(&TT.inc, TT.inc_file); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
762 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
763 if (toys.optflags & FLAG_c) { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
764 if (!TT.inc) error_exit("empty archive"); |
1720 | 765 fd = 1; |
1379
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
766 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
767 if ((toys.optflags & FLAG_f) && strcmp(TT.fname, "-")) |
1720 | 768 fd = xcreate(TT.fname, fd*(O_WRONLY|O_CREAT|O_TRUNC), 0666); |
1379
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
769 if (toys.optflags & FLAG_C) xchdir(TT.dir); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
770 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
771 tar_hdl = init_handler(); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
772 tar_hdl->src_fd = fd; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
773 |
1720 | 774 if ((toys.optflags & FLAG_x) || (toys.optflags & FLAG_t)) { |
1379
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
775 if (toys.optflags & FLAG_O) tar_hdl->extract_handler = extract_to_stdout; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
776 if (toys.optflags & FLAG_to_command) { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
777 signal(SIGPIPE, SIG_IGN); //will be using pipe between child & parent |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
778 tar_hdl->extract_handler = extract_to_command; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
779 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
780 if (toys.optflags & FLAG_z) extract_stream(tar_hdl); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
781 unpack_tar(tar_hdl); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
782 for (tmp = TT.inc; tmp; tmp = tmp->next) |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
783 if (!filter(TT.exc, tmp->arg) && !filter(TT.pass, tmp->arg)) |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
784 error_msg("'%s' not in archive", tmp->arg); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
785 } else if (toys.optflags & FLAG_c) { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
786 //create the tar here. |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
787 if (toys.optflags & FLAG_z) compress_stream(tar_hdl); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
788 for (tmp = TT.inc; tmp; tmp = tmp->next) { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
789 TT.handle = tar_hdl; |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
790 //recurse thru dir and add files to archive |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
791 struct dirtree *root = dirtree_add_node(0,tmp->arg,toys.optflags & FLAG_h); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
792 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
793 if (root) dirtree_handle_callback(root, add_to_tar); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
794 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
795 memset(toybuf, 0, 1024); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
796 writeall(tar_hdl->src_fd, toybuf, 1024); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
797 seen_inode(&TT.inodes, 0, 0); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
798 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
799 |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
800 if (CFG_TOYBOX_FREE) { |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
801 close(tar_hdl->src_fd); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
802 free(tar_hdl); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
803 llist_traverse(TT.exc, llist_free_arg); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
804 llist_traverse(TT.inc, llist_free_arg); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
805 llist_traverse(TT.pass, llist_free_arg); |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
806 } |
b02c05e64f20
TAR - this supports archive creation and extraction based on the USTAR format (described in PAX Spec). For (de)compression '-z' gzip is supported.
Ashwini Sharma <ak.ashwini1981@gmail.com>
parents:
diff
changeset
|
807 } |