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)
225 int i, nmlen = strlen(name), sfxlen;
228 for (cp = comps; cp < comps + nelem(comps); cp++)
229 for (i = 0; i < nelem(cp->sfx) && cp->sfx[i]; i++) {
230 sfxlen = strlen(cp->sfx[i]);
231 if (nmlen > sfxlen &&
232 strcmp(cp->sfx[i], name + nmlen - sfxlen) == 0)
235 return docompress? comps: nil;
239 * push a filter, cmd, onto fd. if input, it's an input descriptor.
240 * returns a descriptor to replace fd, or -1 on error.
243 push(int fd, char *cmd, int input, Pushstate *ps)
251 if (fd < 0 || pipe(pifds) < 0)
259 dup(pifds[Wr], Stdout);
261 dup(pifds[Rd], Stdin);
262 close(pifds[input? Rd: Wr]);
263 dup(fd, (input? Stdin: Stdout));
266 s_append(s, "/bin/");
268 execl(s_to_c(s), cmd, nil);
269 sysfatal("can't exec %s: %r", cmd);
271 nfd = pifds[input? Rd: Wr];
272 close(pifds[input? Wr: Rd]);
281 pushclose(Pushstate *ps)
285 if (ps->fd < 0 || ps->rfd < 0 || !ps->open)
290 while ((wm = wait()) != nil && wm->pid != ps->kid)
292 return wm? wm->msg: nil;
296 * block-buffer management
303 tpblk = malloc(Tblock * nblock);
304 assert(tpblk != nil);
305 endblk = tpblk + nblock;
309 * (re)fill block buffers from archive. `justhdr' means we don't care
310 * about the data before the next header block.
313 refill(int ar, char *bufs, int justhdr)
316 unsigned bytes = Tblock * nblock;
317 static int done, first = 1, seekable;
322 blkoff = seek(ar, 0, 1); /* note position for `tar r' */
324 seekable = blkoff >= 0;
325 /* try to size non-pipe input at first read */
326 if (first && usefile && !fixednblock) {
327 n = eread(arname, ar, bufs, bytes);
329 sysfatal("EOF reading archive %s: %r", arname);
332 sysfatal("%s: archive block size (%d) error", arname, i);
336 fprint(2, "%s: blocking = %d\n", argv0, nblock);
337 endblk = (Hdr *)bufs + nblock;
340 } else if (justhdr && seekable && nexthdr - blkoff >= bytes) {
341 /* optimisation for huge archive members on seekable media */
342 if (seek(ar, bytes, 1) < 0)
343 sysfatal("can't seek on archive %s: %r", arname);
346 n = ereadn(arname, ar, bufs, bytes);
350 sysfatal("unexpected EOF reading archive %s", arname);
352 sysfatal("partial block read from archive %s", arname);
355 memset(bufs + n, 0, bytes - n);
361 getblk(int ar, Refill rfp, int justhdr)
363 if (curblk == nil || curblk >= endblk) { /* input block exhausted? */
364 if (rfp != nil && (*rfp)(ar, (char *)tpblk, justhdr) == nil)
372 getblkrd(int ar, int justhdr)
374 return getblk(ar, refill, justhdr);
380 return getblk(ar, nil, Alldata);
386 Hdr *hp = getblke(ar);
389 memset(hp->data, 0, Tblock);
394 * how many block buffers are available, starting at the address
395 * just returned by getblk*?
400 int n = endblk - (curblk - 1);
402 return n > max? max: n;
406 * indicate that one is done with the last block obtained from getblke
407 * and it is now available to be written into the archive.
412 unsigned bytes = Tblock * nblock;
414 /* if writing end-of-archive, aid compression (good hygiene too) */
416 memset(curblk, 0, (char *)endblk - (char *)curblk);
417 ewrite(arname, ar, tpblk, bytes);
423 if (curblk >= endblk)
435 putreadblks(int ar, int blks)
442 putblkmany(int ar, int blks)
454 * modifies hp->chksum but restores it; important for the last block of the
455 * old archive when updating with `tar rf archive'
462 uchar *cp = hp->data;
463 char oldsum[sizeof hp->chksum];
465 memmove(oldsum, hp->chksum, sizeof oldsum);
466 memset(hp->chksum, ' ', sizeof hp->chksum);
469 memmove(hp->chksum, oldsum, sizeof oldsum);
476 return strcmp(hp->magic, "ustar") == 0;
480 * s is at most n bytes long, but need not be NUL-terminated.
481 * if shorter than n bytes, all bytes after the first NUL must also
485 strnlen(char *s, int n)
487 return s[n - 1] != '\0'? n: strlen(s);
490 /* set fullname from header */
496 static char fullnamebuf[2+Maxname+1]; /* 2+ for ./ on relative names */
498 fullname = fullnamebuf+2;
499 namlen = strnlen(hp->name, sizeof hp->name);
500 if (hp->prefix[0] == '\0' || !isustar(hp)) { /* old-style name? */
501 memmove(fullname, hp->name, namlen);
502 fullname[namlen] = '\0';
506 /* name is in two pieces */
507 pfxlen = strnlen(hp->prefix, sizeof hp->prefix);
508 memmove(fullname, hp->prefix, pfxlen);
509 fullname[pfxlen] = '/';
510 memmove(fullname + pfxlen + 1, hp->name, namlen);
511 fullname[pfxlen + 1 + namlen] = '\0';
518 /* the mode test is ugly but sometimes necessary */
519 return hp->linkflag == LF_DIR ||
520 strrchr(name(hp), '\0')[-1] == '/' ||
521 (strtoul(hp->mode, nil, 8)&0170000) == 040000;
527 return name(hp)[0] == '\0';
532 getbe(uchar *src, int size)
545 putbe(uchar *dest, uvlong vl, int size)
547 for (dest += size; size-- > 0; vl >>= 8)
552 * cautious parsing of octal numbers as ascii strings in
553 * a tar header block. this is particularly important for
554 * trusting the checksum when trying to resync.
557 hdrotoull(char *st, char *end, uvlong errval, char *name, char *field)
561 for (numb = st; (*numb == ' ' || *numb == '\0') && numb < end; numb++)
563 if (numb < end && isascii(*numb) && isdigit(*numb))
564 return strtoull(numb, nil, 8);
565 else if (numb >= end)
566 fprint(2, "%s: %s: empty %s in header\n", argv0, name, field);
568 fprint(2, "%s: %s: %s: non-numeric %s in header\n",
569 argv0, name, numb, field);
574 * return the nominal size from the header block, which is not always the
575 * size in the archive (the archive size may be zero for some file types
576 * regardless of the nominal size).
578 * gnu and freebsd tars are now recording vlongs as big-endian binary
579 * with a flag in byte 0 to indicate this, which permits file sizes up to
580 * 2^64-1 (actually 2^80-1 but our file sizes are vlongs) rather than 2^33-1.
587 if((uchar)hp->size[0] == Binnegsz) {
588 fprint(2, "%s: %s: negative length, which is insane\n",
591 } else if((uchar)hp->size[0] == Binsize) {
592 p = (uchar *)hp->size + sizeof hp->size - 1 -
593 sizeof(vlong); /* -1 for terminating space */
597 return hdrotoull(hp->size, hp->size + sizeof hp->size, 0,
602 * return the number of bytes recorded in the archive.
607 if(isdir(hp) || islink(hp->linkflag))
613 parsecksum(char *cksum, char *name)
617 return hdrotoull(cksum, cksum + sizeof hp->chksum, (uvlong)-1LL,
627 hp = getblkrd(ar, Alldata);
629 sysfatal("unexpected EOF instead of archive header in %s",
631 if (eotar(hp)) /* end-of-archive block? */
634 hdrcksum = parsecksum(hp->chksum, name(hp));
635 if (hdrcksum == -1 || chksum(hp) != hdrcksum) {
637 sysfatal("bad archive header checksum in %s: "
638 "name %.100s...; expected %#luo got %#luo",
639 arname, hp->name, hdrcksum, chksum(hp));
640 fprint(2, "%s: skipping past archive header with bad checksum in %s...",
643 hp = getblkrd(ar, Alldata);
645 sysfatal("unexpected EOF looking for archive header in %s",
647 hdrcksum = parsecksum(hp->chksum, name(hp));
648 } while (hdrcksum == -1 || chksum(hp) != hdrcksum);
649 fprint(2, "found %s\n", name(hp));
651 nexthdr += Tblock*(1 + BYTES2TBLKS(arsize(hp)));
660 * if name is longer than Namsiz bytes, try to split it at a slash and fit the
661 * pieces into hp->prefix and hp->name.
664 putfullname(Hdr *hp, char *name)
668 String *slname = nil;
672 s_append(slname, name);
673 s_append(slname, "/"); /* posix requires this */
674 name = s_to_c(slname);
677 namlen = strlen(name);
678 if (namlen <= Namsiz) {
679 strncpy(hp->name, name, Namsiz);
680 hp->prefix[0] = '\0'; /* ustar paranoia */
684 if (!posix || namlen > Maxname) {
685 fprint(2, "%s: name too long for tar header: %s\n",
690 * try various splits until one results in pieces that fit into the
691 * appropriate fields of the header. look for slashes from right
692 * to left, in the hopes of putting the largest part of the name into
693 * hp->prefix, which is larger than hp->name.
695 sl = strrchr(name, '/');
698 if (pfxlen <= sizeof hp->prefix && namlen-1 - pfxlen <= Namsiz)
702 sl = strrchr(name, '/');
706 fprint(2, "%s: name can't be split to fit tar header: %s\n",
711 strncpy(hp->prefix, name, sizeof hp->prefix);
713 strncpy(hp->name, sl, sizeof hp->name);
720 mkhdr(Hdr *hp, Dir *dir, char *file)
725 * some of these fields run together, so we format them left-to-right
726 * and don't use snprint.
728 sprint(hp->mode, "%6lo ", dir->mode & 0777);
729 sprint(hp->uid, "%6o ", aruid);
730 sprint(hp->gid, "%6o ", argid);
731 if (dir->length >= (Off)1<<32) {
736 fprint(2, "%s: storing large sizes in \"base 256\"\n", argv0);
738 hp->size[0] = Binsize;
739 /* emit so-called `base 256' representation of size */
740 putbe((uchar *)hp->size+1, dir->length, sizeof hp->size - 2);
741 hp->size[sizeof hp->size - 1] = ' ';
743 sprint(hp->size, "%11lluo ", dir->length);
744 sprint(hp->mtime, "%11luo ", dir->mtime);
745 hp->linkflag = (dir->mode&DMDIR? LF_DIR: LF_PLAIN1);
746 r = putfullname(hp, file);
748 strncpy(hp->magic, "ustar", sizeof hp->magic);
749 strncpy(hp->version, "00", sizeof hp->version);
750 strncpy(hp->uname, dir->uid, sizeof hp->uname);
751 strncpy(hp->gname, dir->gid, sizeof hp->gname);
753 sprint(hp->chksum, "%6luo", chksum(hp));
757 static void addtoar(int ar, char *file, char *shortf);
760 addtreetoar(int ar, char *file, char *shortf, int fd)
764 String *name = s_new();
766 n = dirreadall(fd, &dirents);
768 fprint(2, "%s: dirreadall %s: %r\n", argv0, file);
773 if (chdir(shortf) < 0)
774 sysfatal("chdir %s: %r", file);
776 fprint(2, "chdir %s\t# %s\n", shortf, file);
778 for (dent = dirents; dent < dirents + n; dent++) {
780 s_append(name, file);
782 s_append(name, dent->name);
783 addtoar(ar, s_to_c(name), dent->name);
789 * this assumes that shortf is just one component, which is true
790 * during directory descent, but not necessarily true of command-line
791 * arguments. Our caller (or addtoar's) must reset the working
792 * directory if necessary.
795 sysfatal("chdir %s/..: %r", file);
797 fprint(2, "chdir ..\n");
801 addtoar(int ar, char *file, char *shortf)
804 long bytes, blksread;
810 if (shortf[0] == '#') {
812 s_append(name, "./");
813 s_append(name, shortf);
814 shortf = s_to_c(name);
818 fprint(2, "opening %s # %s\n", shortf, file);
819 fd = open(shortf, OREAD);
821 fprint(2, "%s: can't open %s: %r\n", argv0, file);
828 sysfatal("can't fstat %s: %r", file);
831 isdir = (dir->qid.type & QTDIR) != 0;
832 if (mkhdr(hbp, dir, file) < 0) {
842 blksleft = BYTES2TBLKS(dir->length);
846 addtreetoar(ar, file, shortf, fd);
848 for (; blksleft > 0; blksleft -= blksread) {
850 blksread = gothowmany(blksleft);
851 assert(blksread >= 0);
852 bytes = blksread * Tblock;
853 n = ereadn(file, fd, hbp->data, bytes);
856 * ignore EOF. zero any partial block to aid
857 * compression and emergency recovery of data.
860 memset(hbp->data + n, 0, bytes - n);
861 putblkmany(ar, blksread);
865 fprint(2, "%s\n", file);
875 ulong blksleft, blksread;
878 Compress *comp = nil;
881 if (usefile && docreate) {
882 ar = create(usefile, OWRITE, 0666);
884 comp = compmethod(usefile);
886 ar = open(usefile, ORDWR);
890 ar = push(ar, comp->comp, Output, &ps);
892 sysfatal("can't open archive %s: %r", usefile);
894 if (usefile && !docreate) {
895 /* skip quickly to the end */
896 while ((hp = readhdr(ar)) != nil) {
898 for (blksleft = BYTES2TBLKS(bytes);
899 blksleft > 0 && getblkrd(ar, Justnxthdr) != nil;
900 blksleft -= blksread) {
901 blksread = gothowmany(blksleft);
902 putreadblks(ar, blksread);
906 * we have just read the end-of-archive Tblock.
907 * now seek back over the (big) archive block containing it,
908 * and back up curblk ptr over end-of-archive Tblock in memory.
910 if (seek(ar, blkoff, 0) < 0)
911 sysfatal("can't seek back over end-of-archive in %s: %r",
916 for (i = 0; argv[i] != nil; i++) {
917 addtoar(ar, argv[i], argv[i]);
918 chdir(origdir); /* for correctness & profiling */
921 /* write end-of-archive marker */
928 return pushclose(&ps);
938 /* is pfx a file-name prefix of name? */
940 prefix(char *name, char *pfx)
942 char clpfx[Maxlongname+1];
943 int pfxlen = strlen(pfx);
945 clpfx[Maxlongname] = '\0';
946 strncpy(clpfx, pfx, Maxlongname);
948 return strncmp(clpfx, name, pfxlen) == 0 &&
949 (name[pfxlen] == '\0' || name[pfxlen] == '/');
953 match(char *name, char **argv)
955 char clname[Maxlongname+1];
960 clname[Maxlongname] = '\0';
961 strncpy(clname, name, Maxlongname);
963 for (i = 0; argv[i] != nil; i++)
964 if (prefix(clname, argv[i]))
970 cantcreate(char *s, int mode)
976 * Always print about files. Only print about directories
977 * we haven't printed about. (Assumes archive is ordered
982 /* already printed this directory */
983 if(strcmp(s, last) == 0)
985 /* printed a higher directory, so printed this one */
987 if(memcmp(s, last, len) == 0 && last[len] == '/')
994 fprint(2, "%s: can't create %s: %r\n", argv0, s);
1002 if (access(s, AEXIST) == 0)
1004 f = create(s, OREAD, DMDIR | 0777);
1008 cantcreate(s, DMDIR);
1020 while (!err && (p = strchr(p+1, '/')) != nil) {
1022 err = (access(s, AEXIST) < 0 && makedir(s) < 0);
1028 /* Call access but preserve the error string. */
1030 xaccess(char *name, int mode)
1036 errstr(err, sizeof err);
1037 rv = access(name, mode);
1038 errstr(err, sizeof err);
1043 openfname(Hdr *hp, char *fname, int dir, int mode)
1049 switch (hp->linkflag) {
1054 fprint(2, "%s: can't make (sym)link %s\n",
1058 fprint(2, "%s: can't make fifo %s\n", argv0, fname);
1061 if (!keepexisting || access(fname, AEXIST) < 0) {
1062 int rw = (dir? OREAD: OWRITE);
1064 fd = create(fname, rw, mode);
1067 fd = create(fname, rw, mode);
1069 if (fd < 0 && (!dir || xaccess(fname, AEXIST) < 0))
1070 cantcreate(fname, mode);
1072 if (fd >= 0 && verbose)
1073 fprint(2, "%s\n", fname);
1079 /* copy from archive to file system (or nowhere for table-of-contents) */
1081 copyfromar(int ar, int fd, char *fname, ulong blksleft, Off bytes)
1087 if (blksleft == 0 || bytes < 0)
1089 for (; blksleft > 0; blksleft -= blksread) {
1090 hbp = getblkrd(ar, (fd >= 0? Alldata: Justnxthdr));
1092 sysfatal("unexpected EOF on archive extracting %s from %s",
1094 blksread = gothowmany(blksleft);
1095 if (blksread <= 0) {
1096 fprint(2, "%s: got %ld blocks reading %s!\n",
1097 argv0, blksread, fname);
1100 wrbytes = Tblock*blksread;
1104 assert(wrbytes >= 0);
1106 ewrite(fname, fd, hbp->data, wrbytes);
1107 putreadblks(ar, blksread);
1112 fprint(2, "%s: %lld bytes uncopied at EOF on archive %s; "
1113 "%s not fully extracted\n", argv0, bytes, arname, fname);
1117 wrmeta(int fd, Hdr *hp, long mtime, int mode) /* update metadata */
1136 * copy a file from the archive into the filesystem.
1137 * fname is result of name(), so has two extra bytes at beginning.
1140 extract1(int ar, Hdr *hp, char *fname)
1142 int fd = -1, dir = 0;
1143 long mtime = strtol(hp->mtime, nil, 8);
1144 ulong mode = strtoul(hp->mode, nil, 8) & 0777;
1145 Off bytes = hdrsize(hp); /* for printing */
1146 ulong blksleft = BYTES2TBLKS(arsize(hp));
1148 /* fiddle name, figure out mode and blocks */
1153 switch (hp->linkflag) {
1164 else if(fname[0] == '#'){
1170 fd = openfname(hp, fname, dir, mode);
1172 char *cp = ctime(mtime);
1174 print("%M %8lld %-12.12s %-4.4s %s\n",
1175 mode, bytes, cp+4, cp+24, fname);
1177 print("%s\n", fname);
1179 copyfromar(ar, fd, fname, blksleft, bytes);
1181 /* touch up meta data and close */
1184 * directories should be wstated *after* we're done
1185 * creating files in them, but we don't do that.
1188 wrmeta(fd, hp, mtime, mode);
1194 skip(int ar, Hdr *hp, char *fname)
1196 ulong blksleft, blksread;
1199 for (blksleft = BYTES2TBLKS(arsize(hp)); blksleft > 0;
1200 blksleft -= blksread) {
1201 hbp = getblkrd(ar, Justnxthdr);
1203 sysfatal("unexpected EOF on archive extracting %s from %s",
1205 blksread = gothowmany(blksleft);
1206 putreadblks(ar, blksread);
1211 getname(int ar, Hdr *hp)
1213 static char namebuf[Maxlongname+1], *nextname = nil;
1214 ulong blksleft, blksread;
1218 if(nextname != nil && nextname[0] != '\0'){
1219 fname = nextname, nextname = nil;
1223 if(hp->linkflag == LF_LONGNAME){
1225 for (blksleft = BYTES2TBLKS(arsize(hp)); blksleft > 0;
1226 blksleft -= blksread) {
1227 hp = getblkrd(ar, Alldata);
1229 sysfatal("unexpected EOF on archive reading %s from %s",
1231 blksread = gothowmany(blksleft);
1232 n = &namebuf[Maxlongname] - p;
1233 if(Tblock*blksread < n)
1234 n = Tblock*blksread;
1235 memmove(p, hp->data, n);
1237 putreadblks(ar, blksread);
1243 namebuf[Maxlongname] = '\0';
1244 strncpy(namebuf, fname, Maxlongname);
1251 extract(char **argv)
1256 Compress *comp = nil;
1260 ar = open(usefile, OREAD);
1261 comp = compmethod(usefile);
1265 ar = push(ar, comp->decomp, Input, &ps);
1267 sysfatal("can't open archive %s: %r", usefile);
1269 while ((hp = readhdr(ar)) != nil) {
1270 longname = getname(ar, hp);
1273 if (match(longname, argv))
1274 extract1(ar, hp, longname);
1276 skip(ar, hp, longname);
1280 return pushclose(&ps);
1287 main(int argc, char *argv[])
1292 fmtinstall('M', dirmodefmt);
1300 usefile = arname = EARGF(usage());
1303 argid = strtoul(EARGF(usage()), 0, 0);
1311 case 'm': /* compatibility */
1336 aruid = strtoul(EARGF(usage()), 0, 0);
1350 fprint(2, "tar: unknown letter %C\n", TARGC());
1355 if (argc < 0 || errflg)
1362 ret = extract(argv);
1365 if (getwd(origdir, sizeof origdir) == nil)
1366 strcpy(origdir, "/tmp");
1367 ret = replace(argv);