2 * tar - `tape archiver', actually usable on any medium.
3 * POSIX "ustar" compliant when extracting, and by default when creating.
4 * this tar attempts to read and write multiple Tblock-byte blocks
5 * at once to and from the filesystem, and does not copy blocks
12 #include <fcall.h> /* for %M */
16 * modified versions of those in libc.h; scans only the first arg for
17 * keyletters and options.
20 (argv0 || (argv0 = *argv)), argv++, argc--;\
26 while(*_args && (_args += chartorune(&_argc, _args)))\
28 #define TARGEND SET(_argt); USED(_argt);USED(_argc);USED(_args); \
30 USED(argv); USED(argc); }
31 #define TARGC() (_argc)
33 #define ROUNDUP(a, b) (((a) + (b) - 1)/(b))
34 #define BYTES2TBLKS(bytes) ROUNDUP(bytes, Tblock)
36 /* read big-endian binary integers; args must be (uchar *) */
37 #define G2BEBYTE(x) (((x)[0]<<8) | (x)[1])
38 #define G3BEBYTE(x) (((x)[0]<<16) | ((x)[1]<<8) | (x)[2])
39 #define G4BEBYTE(x) (((x)[0]<<24) | ((x)[1]<<16) | ((x)[2]<<8) | (x)[3])
40 #define G8BEBYTE(x) (((vlong)G4BEBYTE(x)<<32) | (u32int)G4BEBYTE((x)+4))
43 typedef char *(*Refill)(int ar, char *bufs, int justhdr);
45 enum { Stdin, Stdout, Stderr };
46 enum { Rd, Wr }; /* pipe fd-array indices */
47 enum { Output, Input };
48 enum { None, Toc, Xtract, Replace };
49 enum { Alldata, Justnxthdr };
53 Maxpfx = 155, /* from POSIX */
54 Maxname = Namsiz + 1 + Maxpfx,
56 Binsize = 0x80, /* flag in size[0], from gnu: positive binary size */
57 Binnegsz = 0xff, /* flag in size[0]: negative binary size */
59 Nblock = 40, /* maximum blocksize */
60 Dblock = 20, /* default blocksize */
64 /* POSIX link flags */
70 LF_SYMLINK2 = 's', /* 4BSD used this */
77 /* 'A' - 'Z' are reserved for custom implementations */
79 LF_LONGNAME = 'L', /* GNU extenstion */
83 #define islink(lf) (isreallink(lf) || issymlink(lf))
84 #define isreallink(lf) ((lf) == LF_LINK)
85 #define issymlink(lf) ((lf) == LF_SYMLINK1 || (lf) == LF_SYMLINK2)
98 char linkname[Namsiz];
100 /* rest are defined by POSIX's ustar format; see p1003.2b */
101 char magic[6]; /* "ustar" */
107 char prefix[Maxpfx]; /* if non-null, path= prefix "/" name */
117 static Compress comps[] = {
118 "gzip", "gunzip", { ".tar.gz", ".tgz" }, /* default */
119 "compress", "uncompress", { ".tar.Z", ".tz" },
120 "bzip2", "bunzip2", { ".tar.bz", ".tbz",
121 ".tar.bz2",".tbz2" },
126 int fd; /* original fd */
127 int rfd; /* replacement fd */
132 #define OTHER(rdwr) ((rdwr) == Rd? Wr: Rd)
135 static int fixednblock;
137 static int posix = 1;
141 static int relative = 1;
144 static int docompress;
145 static int keepexisting;
146 static int ignerrs; /* flag: ignore i/o errors if possible */
147 static Off blkoff; /* offset of the current archive block (not Tblock) */
150 static int nblock = Dblock;
152 static char *usefile, *arname = "archive";
153 static char origdir[Maxlongname+1];
154 static Hdr *tpblk, *endblk;
160 fprint(2, "usage: %s {crtx}[PRTfgikmpsuvz] [archive] [file1 file2...]\n",
165 /* I/O, with error retry or exit */
168 cope(char *name, int fd, void *buf, long len, Off off)
170 fprint(2, "%s: %serror reading %s: %r\n", argv0,
171 (ignerrs? "ignoring ": ""), name);
175 /* pretend we read len bytes of zeroes */
177 if (off >= 0) /* seekable? */
178 seek(fd, off + len, 0);
183 eread(char *name, int fd, void *buf, long len)
188 off = seek(fd, 0, 1); /* for coping with errors */
189 rd = read(fd, buf, len);
191 rd = cope(name, fd, buf, len, off);
196 ereadn(char *name, int fd, void *buf, long len)
201 off = seek(fd, 0, 1);
202 rd = readn(fd, buf, len);
204 rd = cope(name, fd, buf, len, off);
209 ewrite(char *name, int fd, void *buf, long len)
214 rd = write(fd, buf, len);
216 sysfatal("error writing %s: %r", name);
223 compmethod(char *name)
226 int i, nmlen, sfxlen;
229 nmlen = strlen(name);
230 for (cp = comps; cp < comps + nelem(comps); cp++) {
231 for (i = 0; i < nelem(cp->sfx) && cp->sfx[i]; i++) {
232 sfxlen = strlen(cp->sfx[i]);
233 if (nmlen > sfxlen &&
234 strcmp(cp->sfx[i], name + nmlen - sfxlen) == 0)
239 return docompress? comps: nil;
243 * push a filter, cmd, onto fd. if input, it's an input descriptor.
244 * returns a descriptor to replace fd, or -1 on error.
247 push(int fd, char *cmd, int input, Pushstate *ps)
255 if (fd < 0 || pipe(pifds) < 0)
263 dup(pifds[Wr], Stdout);
265 dup(pifds[Rd], Stdin);
266 close(pifds[input? Rd: Wr]);
267 dup(fd, (input? Stdin: Stdout));
270 s_append(s, "/bin/");
272 execl(s_to_c(s), cmd, nil);
273 sysfatal("can't exec %s: %r", cmd);
275 nfd = pifds[input? Rd: Wr];
276 close(pifds[input? Wr: Rd]);
285 pushclose(Pushstate *ps)
289 if (ps->fd < 0 || ps->rfd < 0 || !ps->open)
294 while ((wm = wait()) != nil && wm->pid != ps->kid)
296 return wm? wm->msg: nil;
300 * block-buffer management
307 tpblk = malloc(Tblock * nblock);
308 assert(tpblk != nil);
309 endblk = tpblk + nblock;
313 * (re)fill block buffers from archive. `justhdr' means we don't care
314 * about the data before the next header block.
317 refill(int ar, char *bufs, int justhdr)
320 unsigned bytes = Tblock * nblock;
321 static int done, first = 1, seekable;
326 blkoff = seek(ar, 0, 1); /* note position for `tar r' */
328 seekable = blkoff >= 0;
329 /* try to size non-pipe input at first read */
330 if (first && usefile && !fixednblock) {
331 n = eread(arname, ar, bufs, bytes);
333 sysfatal("EOF reading archive %s: %r", arname);
336 sysfatal("%s: archive block size (%d) error", arname, i);
340 fprint(2, "%s: blocking = %d\n", argv0, nblock);
341 endblk = (Hdr *)bufs + nblock;
344 } else if (justhdr && seekable && nexthdr - blkoff >= bytes) {
345 /* optimisation for huge archive members on seekable media */
346 if (seek(ar, bytes, 1) < 0)
347 sysfatal("can't seek on archive %s: %r", arname);
350 n = ereadn(arname, ar, bufs, bytes);
354 sysfatal("unexpected EOF reading archive %s", arname);
356 sysfatal("partial block read from archive %s", arname);
359 memset(bufs + n, 0, bytes - n);
365 getblk(int ar, Refill rfp, int justhdr)
367 if (curblk == nil || curblk >= endblk) { /* input block exhausted? */
368 if (rfp != nil && (*rfp)(ar, (char *)tpblk, justhdr) == nil)
376 getblkrd(int ar, int justhdr)
378 return getblk(ar, refill, justhdr);
384 return getblk(ar, nil, Alldata);
390 Hdr *hp = getblke(ar);
393 memset(hp->data, 0, Tblock);
398 * how many block buffers are available, starting at the address
399 * just returned by getblk*?
404 int n = endblk - (curblk - 1);
406 return n > max? max: n;
410 * indicate that one is done with the last block obtained from getblke
411 * and it is now available to be written into the archive.
416 unsigned bytes = Tblock * nblock;
418 /* if writing end-of-archive, aid compression (good hygiene too) */
420 memset(curblk, 0, (char *)endblk - (char *)curblk);
421 ewrite(arname, ar, tpblk, bytes);
427 if (curblk >= endblk)
439 putreadblks(int ar, int blks)
446 putblkmany(int ar, int blks)
458 * modifies hp->chksum but restores it; important for the last block of the
459 * old archive when updating with `tar rf archive'
466 uchar *cp = hp->data;
467 char oldsum[sizeof hp->chksum];
469 memmove(oldsum, hp->chksum, sizeof oldsum);
470 memset(hp->chksum, ' ', sizeof hp->chksum);
473 memmove(hp->chksum, oldsum, sizeof oldsum);
480 return strcmp(hp->magic, "ustar") == 0;
484 * s is at most n bytes long, but need not be NUL-terminated.
485 * if shorter than n bytes, all bytes after the first NUL must also
489 strnlen(char *s, int n)
491 return s[n - 1] != '\0'? n: strlen(s);
494 /* set fullname from header */
500 static char fullnamebuf[2+Maxname+1]; /* 2+ for ./ on relative names */
502 fullname = fullnamebuf+2;
503 namlen = strnlen(hp->name, sizeof hp->name);
504 if (hp->prefix[0] == '\0' || !isustar(hp)) { /* old-style name? */
505 memmove(fullname, hp->name, namlen);
506 fullname[namlen] = '\0';
510 /* name is in two pieces */
511 pfxlen = strnlen(hp->prefix, sizeof hp->prefix);
512 memmove(fullname, hp->prefix, pfxlen);
513 fullname[pfxlen] = '/';
514 memmove(fullname + pfxlen + 1, hp->name, namlen);
515 fullname[pfxlen + 1 + namlen] = '\0';
522 /* the mode test is ugly but sometimes necessary */
523 return hp->linkflag == LF_DIR ||
524 strrchr(name(hp), '\0')[-1] == '/' ||
525 (strtoul(hp->mode, nil, 8)&0170000) == 040000;
531 return name(hp)[0] == '\0';
536 getbe(uchar *src, int size)
549 putbe(uchar *dest, uvlong vl, int size)
551 for (dest += size; size-- > 0; vl >>= 8)
556 * cautious parsing of octal numbers as ascii strings in
557 * a tar header block. this is particularly important for
558 * trusting the checksum when trying to resync.
561 hdrotoull(char *st, char *end, uvlong errval, char *name, char *field)
565 for (numb = st; (*numb == ' ' || *numb == '\0') && numb < end; numb++)
567 if (numb < end && isascii(*numb) && isdigit(*numb))
568 return strtoull(numb, nil, 8);
569 else if (numb >= end)
570 fprint(2, "%s: %s: empty %s in header\n", argv0, name, field);
572 fprint(2, "%s: %s: %s: non-numeric %s in header\n",
573 argv0, name, numb, field);
578 * return the nominal size from the header block, which is not always the
579 * size in the archive (the archive size may be zero for some file types
580 * regardless of the nominal size).
582 * gnu and freebsd tars are now recording vlongs as big-endian binary
583 * with a flag in byte 0 to indicate this, which permits file sizes up to
584 * 2^64-1 (actually 2^80-1 but our file sizes are vlongs) rather than 2^33-1.
591 if((uchar)hp->size[0] == Binnegsz) {
592 fprint(2, "%s: %s: negative length, which is insane\n",
595 } else if((uchar)hp->size[0] == Binsize) {
596 p = (uchar *)hp->size + sizeof hp->size - 1 -
597 sizeof(vlong); /* -1 for terminating space */
601 return hdrotoull(hp->size, hp->size + sizeof hp->size, 0,
606 * return the number of bytes recorded in the archive.
611 if(isdir(hp) || islink(hp->linkflag))
617 parsecksum(char *cksum, char *name)
621 return hdrotoull(cksum, cksum + sizeof hp->chksum, (uvlong)-1LL,
631 hp = getblkrd(ar, Alldata);
633 sysfatal("unexpected EOF instead of archive header in %s",
635 if (eotar(hp)) /* end-of-archive block? */
638 hdrcksum = parsecksum(hp->chksum, name(hp));
639 if (hdrcksum == -1 || chksum(hp) != hdrcksum) {
641 sysfatal("bad archive header checksum in %s: "
642 "name %.100s...; expected %#luo got %#luo",
643 arname, hp->name, hdrcksum, chksum(hp));
644 fprint(2, "%s: skipping past archive header with bad checksum in %s...",
647 hp = getblkrd(ar, Alldata);
649 sysfatal("unexpected EOF looking for archive header in %s",
651 hdrcksum = parsecksum(hp->chksum, name(hp));
652 } while (hdrcksum == -1 || chksum(hp) != hdrcksum);
653 fprint(2, "found %s\n", name(hp));
655 nexthdr += Tblock*(1 + BYTES2TBLKS(arsize(hp)));
664 * if name is longer than Namsiz bytes, try to split it at a slash and fit the
665 * pieces into hp->prefix and hp->name.
668 putfullname(Hdr *hp, char *name)
672 String *slname = nil;
676 s_append(slname, name);
677 s_append(slname, "/"); /* posix requires this */
678 name = s_to_c(slname);
681 namlen = strlen(name);
682 if (namlen <= Namsiz) {
683 strncpy(hp->name, name, Namsiz);
684 hp->prefix[0] = '\0'; /* ustar paranoia */
688 if (!posix || namlen > Maxname) {
689 fprint(2, "%s: name too long for tar header: %s\n",
694 * try various splits until one results in pieces that fit into the
695 * appropriate fields of the header. look for slashes from right
696 * to left, in the hopes of putting the largest part of the name into
697 * hp->prefix, which is larger than hp->name.
699 sl = strrchr(name, '/');
702 if (pfxlen <= sizeof hp->prefix && namlen-1 - pfxlen <= Namsiz)
706 sl = strrchr(name, '/');
710 fprint(2, "%s: name can't be split to fit tar header: %s\n",
715 strncpy(hp->prefix, name, sizeof hp->prefix);
717 strncpy(hp->name, sl, sizeof hp->name);
724 mkhdr(Hdr *hp, Dir *dir, char *file)
729 * some of these fields run together, so we format them left-to-right
730 * and don't use snprint.
732 sprint(hp->mode, "%6lo ", dir->mode & 0777);
733 sprint(hp->uid, "%6o ", aruid);
734 sprint(hp->gid, "%6o ", argid);
735 if (dir->length >= (Off)1<<32) {
740 fprint(2, "%s: storing large sizes in \"base 256\"\n", argv0);
742 hp->size[0] = Binsize;
743 /* emit so-called `base 256' representation of size */
744 putbe((uchar *)hp->size+1, dir->length, sizeof hp->size - 2);
745 hp->size[sizeof hp->size - 1] = ' ';
747 sprint(hp->size, "%11lluo ", dir->length);
748 sprint(hp->mtime, "%11luo ", dir->mtime);
749 hp->linkflag = (dir->mode&DMDIR? LF_DIR: LF_PLAIN1);
750 r = putfullname(hp, file);
752 strncpy(hp->magic, "ustar", sizeof hp->magic);
753 strncpy(hp->version, "00", sizeof hp->version);
754 strncpy(hp->uname, dir->uid, sizeof hp->uname);
755 strncpy(hp->gname, dir->gid, sizeof hp->gname);
757 sprint(hp->chksum, "%6luo", chksum(hp));
761 static void addtoar(int ar, char *file, char *shortf);
764 addtreetoar(int ar, char *file, char *shortf, int fd)
768 String *name = s_new();
770 n = dirreadall(fd, &dirents);
772 fprint(2, "%s: dirreadall %s: %r\n", argv0, file);
777 if (chdir(shortf) < 0)
778 sysfatal("chdir %s: %r", file);
780 fprint(2, "chdir %s\t# %s\n", shortf, file);
782 for (dent = dirents; dent < dirents + n; dent++) {
784 s_append(name, file);
786 s_append(name, dent->name);
787 addtoar(ar, s_to_c(name), dent->name);
793 * this assumes that shortf is just one component, which is true
794 * during directory descent, but not necessarily true of command-line
795 * arguments. Our caller (or addtoar's) must reset the working
796 * directory if necessary.
799 sysfatal("chdir %s/..: %r", file);
801 fprint(2, "chdir ..\n");
805 addtoar(int ar, char *file, char *shortf)
808 long bytes, blksread;
814 if (shortf[0] == '#') {
816 s_append(name, "./");
817 s_append(name, shortf);
818 shortf = s_to_c(name);
822 fprint(2, "opening %s # %s\n", shortf, file);
823 fd = open(shortf, OREAD);
825 fprint(2, "%s: can't open %s: %r\n", argv0, file);
832 sysfatal("can't fstat %s: %r", file);
835 isdir = (dir->qid.type & QTDIR) != 0;
836 if (mkhdr(hbp, dir, file) < 0) {
846 blksleft = BYTES2TBLKS(dir->length);
850 addtreetoar(ar, file, shortf, fd);
852 for (; blksleft > 0; blksleft -= blksread) {
854 blksread = gothowmany(blksleft);
855 assert(blksread >= 0);
856 bytes = blksread * Tblock;
857 n = ereadn(file, fd, hbp->data, bytes);
860 * ignore EOF. zero any partial block to aid
861 * compression and emergency recovery of data.
864 memset(hbp->data + n, 0, bytes - n);
865 putblkmany(ar, blksread);
869 fprint(2, "%s\n", file);
879 ulong blksleft, blksread;
882 Compress *comp = nil;
885 if (usefile && docreate)
886 ar = create(usefile, OWRITE, 0666);
888 ar = open(usefile, ORDWR);
891 if (docreate && docompress) {
892 comp = compmethod(usefile);
894 ar = push(ar, comp->comp, Output, &ps);
897 sysfatal("can't open archive %s: %r", usefile);
899 if (usefile && !docreate) {
900 /* skip quickly to the end */
901 while ((hp = readhdr(ar)) != nil) {
903 for (blksleft = BYTES2TBLKS(bytes);
904 blksleft > 0 && getblkrd(ar, Justnxthdr) != nil;
905 blksleft -= blksread) {
906 blksread = gothowmany(blksleft);
907 putreadblks(ar, blksread);
911 * we have just read the end-of-archive Tblock.
912 * now seek back over the (big) archive block containing it,
913 * and back up curblk ptr over end-of-archive Tblock in memory.
915 if (seek(ar, blkoff, 0) < 0)
916 sysfatal("can't seek back over end-of-archive in %s: %r",
921 for (i = 0; argv[i] != nil; i++) {
922 addtoar(ar, argv[i], argv[i]);
923 chdir(origdir); /* for correctness & profiling */
926 /* write end-of-archive marker */
933 return pushclose(&ps);
943 /* is pfx a file-name prefix of name? */
945 prefix(char *name, char *pfx)
947 char clpfx[Maxlongname+1];
948 int pfxlen = strlen(pfx);
950 clpfx[Maxlongname] = '\0';
951 strncpy(clpfx, pfx, Maxlongname);
953 return strncmp(clpfx, name, pfxlen) == 0 &&
954 (name[pfxlen] == '\0' || name[pfxlen] == '/');
958 match(char *name, char **argv)
960 char clname[Maxlongname+1];
965 clname[Maxlongname] = '\0';
966 strncpy(clname, name, Maxlongname);
968 for (i = 0; argv[i] != nil; i++)
969 if (prefix(clname, argv[i]))
975 cantcreate(char *s, int mode)
981 * Always print about files. Only print about directories
982 * we haven't printed about. (Assumes archive is ordered
987 /* already printed this directory */
988 if(strcmp(s, last) == 0)
990 /* printed a higher directory, so printed this one */
992 if(memcmp(s, last, len) == 0 && last[len] == '/')
999 fprint(2, "%s: can't create %s: %r\n", argv0, s);
1007 if (access(s, AEXIST) == 0)
1009 f = create(s, OREAD, DMDIR | 0777);
1013 cantcreate(s, DMDIR);
1025 while (!err && (p = strchr(p+1, '/')) != nil) {
1027 err = (access(s, AEXIST) < 0 && makedir(s) < 0);
1033 /* Call access but preserve the error string. */
1035 xaccess(char *name, int mode)
1041 errstr(err, sizeof err);
1042 rv = access(name, mode);
1043 errstr(err, sizeof err);
1048 openfname(Hdr *hp, char *fname, int dir, int mode)
1054 switch (hp->linkflag) {
1059 fprint(2, "%s: can't make (sym)link %s\n",
1063 fprint(2, "%s: can't make fifo %s\n", argv0, fname);
1066 if (!keepexisting || access(fname, AEXIST) < 0) {
1067 int rw = (dir? OREAD: OWRITE);
1069 fd = create(fname, rw, mode);
1072 fd = create(fname, rw, mode);
1074 if (fd < 0 && (!dir || xaccess(fname, AEXIST) < 0))
1075 cantcreate(fname, mode);
1077 if (fd >= 0 && verbose)
1078 fprint(2, "%s\n", fname);
1084 /* copy from archive to file system (or nowhere for table-of-contents) */
1086 copyfromar(int ar, int fd, char *fname, ulong blksleft, Off bytes)
1092 if (blksleft == 0 || bytes < 0)
1094 for (; blksleft > 0; blksleft -= blksread) {
1095 hbp = getblkrd(ar, (fd >= 0? Alldata: Justnxthdr));
1097 sysfatal("unexpected EOF on archive extracting %s from %s",
1099 blksread = gothowmany(blksleft);
1100 if (blksread <= 0) {
1101 fprint(2, "%s: got %ld blocks reading %s!\n",
1102 argv0, blksread, fname);
1105 wrbytes = Tblock*blksread;
1109 assert(wrbytes >= 0);
1111 ewrite(fname, fd, hbp->data, wrbytes);
1112 putreadblks(ar, blksread);
1117 fprint(2, "%s: %lld bytes uncopied at EOF on archive %s; "
1118 "%s not fully extracted\n", argv0, bytes, arname, fname);
1122 wrmeta(int fd, Hdr *hp, long mtime, int mode) /* update metadata */
1141 * copy a file from the archive into the filesystem.
1142 * fname is result of name(), so has two extra bytes at beginning.
1145 extract1(int ar, Hdr *hp, char *fname)
1147 int fd = -1, dir = 0;
1148 long mtime = strtol(hp->mtime, nil, 8);
1149 ulong mode = strtoul(hp->mode, nil, 8) & 0777;
1150 Off bytes = hdrsize(hp); /* for printing */
1151 ulong blksleft = BYTES2TBLKS(arsize(hp));
1153 /* fiddle name, figure out mode and blocks */
1158 switch (hp->linkflag) {
1169 else if(fname[0] == '#'){
1175 fd = openfname(hp, fname, dir, mode);
1177 char *cp = ctime(mtime);
1179 print("%M %8lld %-12.12s %-4.4s %s\n",
1180 mode, bytes, cp+4, cp+24, fname);
1182 print("%s\n", fname);
1184 copyfromar(ar, fd, fname, blksleft, bytes);
1186 /* touch up meta data and close */
1189 * directories should be wstated *after* we're done
1190 * creating files in them, but we don't do that.
1193 wrmeta(fd, hp, mtime, mode);
1199 skip(int ar, Hdr *hp, char *fname)
1201 ulong blksleft, blksread;
1204 for (blksleft = BYTES2TBLKS(arsize(hp)); blksleft > 0;
1205 blksleft -= blksread) {
1206 hbp = getblkrd(ar, Justnxthdr);
1208 sysfatal("unexpected EOF on archive extracting %s from %s",
1210 blksread = gothowmany(blksleft);
1211 putreadblks(ar, blksread);
1216 getname(int ar, Hdr *hp)
1218 static char namebuf[Maxlongname+1], *nextname = nil;
1219 ulong blksleft, blksread;
1223 if(nextname != nil && nextname[0] != '\0'){
1224 fname = nextname, nextname = nil;
1228 if(hp->linkflag == LF_LONGNAME){
1230 for (blksleft = BYTES2TBLKS(arsize(hp)); blksleft > 0;
1231 blksleft -= blksread) {
1232 hp = getblkrd(ar, Alldata);
1234 sysfatal("unexpected EOF on archive reading %s from %s",
1236 blksread = gothowmany(blksleft);
1237 n = &namebuf[Maxlongname] - p;
1238 if(Tblock*blksread < n)
1239 n = Tblock*blksread;
1240 memmove(p, hp->data, n);
1242 putreadblks(ar, blksread);
1248 namebuf[Maxlongname] = '\0';
1249 strncpy(namebuf, fname, Maxlongname);
1256 extract(char **argv)
1265 ar = open(usefile, OREAD);
1268 comp = compmethod(usefile);
1270 ar = push(ar, comp->decomp, Input, &ps);
1272 sysfatal("can't open archive %s: %r", usefile);
1274 while ((hp = readhdr(ar)) != nil) {
1275 longname = getname(ar, hp);
1278 if (match(longname, argv))
1279 extract1(ar, hp, longname);
1281 skip(ar, hp, longname);
1285 return pushclose(&ps);
1292 main(int argc, char *argv[])
1297 fmtinstall('M', dirmodefmt);
1305 usefile = arname = EARGF(usage());
1308 argid = strtoul(EARGF(usage()), 0, 0);
1316 case 'm': /* compatibility */
1341 aruid = strtoul(EARGF(usage()), 0, 0);
1355 fprint(2, "tar: unknown letter %C\n", TARGC());
1360 if (argc < 0 || errflg)
1367 ret = extract(argv);
1370 if (getwd(origdir, sizeof origdir) == nil)
1371 strcpy(origdir, "/tmp");
1372 ret = replace(argv);