diff options
Diffstat (limited to 'usr/src')
-rw-r--r-- | usr/src/cmd/file/magic | 2 | ||||
-rw-r--r-- | usr/src/cmd/tar/tar.c | 99 | ||||
-rw-r--r-- | usr/src/man/man1/tar.1 | 96 |
3 files changed, 116 insertions, 81 deletions
diff --git a/usr/src/cmd/file/magic b/usr/src/cmd/file/magic index bf73432cbf..f6e945b8c3 100644 --- a/usr/src/cmd/file/magic +++ b/usr/src/cmd/file/magic @@ -617,3 +617,5 @@ >8 string jpx JPEG 2000 w/ extensions (.JPX) [ISO 15444-2] >8 string mp42 v2 [ISO 14496-14] 4 string moov QuickTime MOV file + +0 string \375\067\172\130\132\000 xz compressed data diff --git a/usr/src/cmd/tar/tar.c b/usr/src/cmd/tar/tar.c index d6e39db1dd..690cdf71c6 100644 --- a/usr/src/cmd/tar/tar.c +++ b/usr/src/cmd/tar/tar.c @@ -20,6 +20,7 @@ */ /* * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright 2012 Milan Jurik. All rights reserved. */ /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ @@ -548,9 +549,10 @@ static void compress_back(void); static void decompress_file(void); static pid_t uncompress_file(void); static void *compress_malloc(size_t); -static void check_compression(); -static char *bz_suffix(); -static char *gz_suffix(); +static void check_compression(void); +static char *bz_suffix(void); +static char *gz_suffix(void); +static char *xz_suffix(void); static char *add_suffix(); static void wait_pid(pid_t); @@ -572,6 +574,7 @@ static int Dflag; /* Data change flag */ static int jflag; /* flag to use 'bzip2' */ static int zflag; /* flag to use 'gzip' */ static int Zflag; /* flag to use 'compress' */ +static int Jflag; /* flag to use 'xz' */ /* Trusted Extensions */ static int Tflag; /* Trusted Extensions attr flags */ @@ -693,17 +696,21 @@ int waitaround = 0; /* wait for rendezvous with the debugger */ #define BZIP "/usr/bin/bzip2" #define GZIP "/usr/bin/gzip" #define COMPRESS "/usr/bin/compress" +#define XZ "/usr/bin/xz" #define BZCAT "/usr/bin/bzcat" #define GZCAT "/usr/bin/gzcat" #define ZCAT "/usr/bin/zcat" -#define GS 8 /* number of valid 'gzip' sufixes */ -#define BS 4 /* number of valid 'bzip2' sufixes */ +#define XZCAT "/usr/bin/xzcat" +#define GSUF 8 /* number of valid 'gzip' sufixes */ +#define BSUF 4 /* number of valid 'bzip2' sufixes */ +#define XSUF 1 /* number of valid 'xz' suffixes */ static char *compress_opt; /* compression type */ static char *gsuffix[] = {".gz", "-gz", ".z", "-z", "_z", ".Z", ".tgz", ".taz"}; static char *bsuffix[] = {".bz2", ".bz", ".tbz2", ".tbz"}; +static char *xsuffix[] = {".xz"}; static char *suffix; @@ -897,13 +904,16 @@ main(int argc, char *argv[]) pflag++; /* also set flag for ACL */ break; case 'j': /* compession "bzip2" */ - jflag++; + jflag = 1; break; case 'z': /* compression "gzip" */ - zflag++; + zflag = 1; break; case 'Z': /* compression "compress" */ - Zflag++; + Zflag = 1; + break; + case 'J': /* compression "xz" */ + Jflag = 1; break; default: (void) fprintf(stderr, gettext( @@ -919,10 +929,9 @@ main(int argc, char *argv[]) usage(); } if (cflag) { - if ((zflag && jflag) || (zflag && Zflag) || - (jflag && Zflag)) { + if ((jflag + zflag + Zflag + Jflag) > 1) { (void) fprintf(stderr, gettext( - "tar: specify only one of [jzZ] to " + "tar: specify only one of [jJzZ] to " "create a compressed file.\n")); usage(); } @@ -1004,6 +1013,9 @@ main(int argc, char *argv[]) compress_opt = compress_malloc(strlen(COMPRESS) + 1); (void) strcpy(compress_opt, COMPRESS); + } else if (Jflag) { + compress_opt = compress_malloc(strlen(XZ) + 1); + (void) strcpy(compress_opt, XZ); } } else { /* @@ -1167,7 +1179,7 @@ usage(void) #else "Usage: tar {c|r|t|u|x}[BDeEFhilmnopPTvw[0-7]][bf][X...] " #endif /* O_XATTR */ - "[j|z|Z] " + "[j|J|z|Z] " "[blocksize] [tarfile] [size] [exclude-file...] " "{file | -I include-file | -C directory file}...\n")); done(1); @@ -9174,18 +9186,16 @@ compress_back() #define GZIP_MAGIC "\037\213" #define BZIP_MAGIC "BZh" #define COMP_MAGIC "\037\235" +#define XZ_MAGIC "\375\067\172\130\132\000" void -check_compression() +check_compression(void) { - char magic[2]; - char buf[16]; + char magic[16]; FILE *fp; if ((fp = fopen(usefile, "r")) != NULL) { - (void) fread(buf, sizeof (char), 6, fp); - magic[0] = buf[0]; - magic[1] = buf[1]; + (void) fread(magic, sizeof (char), 6, fp); (void) fclose(fp); } @@ -9213,6 +9223,14 @@ check_compression() compress_opt = compress_malloc(strlen(COMPRESS) + 1); (void) strcpy(compress_opt, COMPRESS); } + } else if (memcmp(magic, XZ_MAGIC, 6) == 0) { + if (xflag || tflag) { + compress_opt = compress_malloc(strlen(XZCAT) + 1); + (void) strcpy(compress_opt, XZCAT); + } else if (uflag || rflag) { + compress_opt = compress_malloc(strlen(XZ) + 1); + (void) strcpy(compress_opt, XZ); + } } } @@ -9235,6 +9253,11 @@ add_suffix() strlcat(tfname, bsuffix[0], sizeof (tfname)); return (bsuffix[0]); } + } else if (strcmp(compress_opt, XZ) == 0) { + if ((suffix = xz_suffix()) == NULL) { + strlcat(tfname, xsuffix[0], sizeof (tfname)); + return (xsuffix[0]); + } } return (NULL); } @@ -9330,40 +9353,44 @@ uncompress_file(void) return (0); /*NOTREACHED*/ } -/* Checking valid 'bzip2' suffix */ +/* Checking suffix validity */ char * -bz_suffix() +check_suffix(char **suf, int size) { int i; int slen; int nlen = strlen(usefile); - for (i = 0; i < BS; i++) { - slen = strlen(bsuffix[i]); + for (i = 0; i < size; i++) { + slen = strlen(suf[i]); if (nlen < slen) return (NULL); - if (strcmp(usefile + nlen - slen, bsuffix[i]) == 0) - return (bsuffix[i]); + if (strcmp(usefile + nlen - slen, suf[i]) == 0) + return (suf[i]); } return (NULL); + +} + +/* Checking valid 'bzip2' suffix */ +char * +bz_suffix(void) +{ + return (check_suffix(bsuffix, BSUF)); } /* Checking valid 'gzip' suffix */ char * -gz_suffix() +gz_suffix(void) { - int i; - int slen; - int nlen = strlen(usefile); + return (check_suffix(gsuffix, GSUF)); +} - for (i = 0; i < GS; i++) { - slen = strlen(gsuffix[i]); - if (nlen < slen) - return (NULL); - if (strcmp(usefile + nlen - slen, gsuffix[i]) == 0) - return (gsuffix[i]); - } - return (NULL); +/* Checking valid 'xz' suffix */ +char * +xz_suffix(void) +{ + return (check_suffix(xsuffix, XSUF)); } void * diff --git a/usr/src/man/man1/tar.1 b/usr/src/man/man1/tar.1 index cbf3aebccc..d7d0b773c3 100644 --- a/usr/src/man/man1/tar.1 +++ b/usr/src/man/man1/tar.1 @@ -1,6 +1,7 @@ '\" te .\" Copyright 1989 AT&T .\" Copyright (c) 2006, Sun Microsystems, Inc. All Rights Reserved +.\" Copyright 2012 Milan Jurik. All rights reserved. .\" Portions Copyright (c) 1992, X/Open Company Limited All Rights Reserved .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at .\" http://www.opengroup.org/bookstore/. @@ -9,39 +10,39 @@ .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License. .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner] -.TH TAR 1 "Oct 26, 2007" +.TH TAR 1 "May 9, 2012" .SH NAME tar \- create tape archives and add or extract files .SH SYNOPSIS .LP .nf -\fBtar\fR c[BDeEFhilnopPqTvw@/[0-7]][bfk][X...] [\fIblocksize\fR] +\fBtar\fR c[BDeEFhilnopPqTvw@/[0-7]][bfk][X...][j|J|z|Z] [\fIblocksize\fR] [\fItarfile\fR] [\fIsize\fR] [\fIexclude-file\fR]... {\fIfile\fR | \(miI \fIinclude-file\fR | \(miC \fIdirectory\fR \fIfile\fR}... .fi .LP .nf -\fBtar\fR r[BDeEFhilnqTvw@/[0-7]][bfk] [\fIblocksize\fR] [\fItarfile\fR] +\fBtar\fR r[BDeEFhilnqTvw@/[0-7]][bfk][j|J|z|Z] [\fIblocksize\fR] [\fItarfile\fR] [\fIsize\fR] {\fIfile\fR | \(miI \fIinclude-file\fR | \(miC \fIdirectory\fR \fIfile\fR}... .fi .LP .nf -\fBtar\fR t[BeFhilnqTv[0-7]][fk][X...] [\fItarfile\fR] [\fIsize\fR] +\fBtar\fR t[BeFhilnqTv[0-7]][fk][X...][j|J|z|Z] [\fItarfile\fR] [\fIsize\fR] [\fIexclude-file\fR]... {\fIfile\fR | \(miI \fIinclude-file\fR}... .fi .LP .nf -\fBtar\fR u[BDeEFhilnqTvw@/[0-7]][bfk] [\fIblocksize\fR] [\fItarfile\fR] +\fBtar\fR u[BDeEFhilnqTvw@/[0-7]][bfk][j|J|z|Z] [\fIblocksize\fR] [\fItarfile\fR] [\fIsize\fR] \fIfile\fR... .fi .LP .nf -\fBtar\fR x[BeFhilmnopqTvw@/[0-7]][fk][X...] [\fItarfile\fR] [\fIsize\fR] +\fBtar\fR x[BeFhilmnopqTvw@/[0-7]][fk][X...][j|J|z|Z] [\fItarfile\fR] [\fIsize\fR] [\fIexclude-file\fR]... [\fIfile\fR]... .fi @@ -397,6 +398,26 @@ Ignore directory checksum errors. .sp .ne 2 .na +\fB\fBj\fR\fR +.ad +.sp .6 +.RS 4n +Use \fBbzip2\fR for compressing or decompressing the archives. +.RE + +.sp +.ne 2 +.na +\fB\fBJ\fR\fR +.ad +.sp .6 +.RS 4n +Use \fBxz\fR for compressing or decompressing the archives. +.RE + +.sp +.ne 2 +.na \fB\fBk\fR \fIsize\fR\fR .ad .sp .6 @@ -589,6 +610,26 @@ included files. If a file is specified in both the \fIexclude-file\fR and the .sp .ne 2 .na +\fB\fBz\fR\fR +.ad +.sp .6 +.RS 4n +Use \fBgzip\fR for compressing or decompressing the archives. +.RE + +.sp +.ne 2 +.na +\fB\fBZ\fR\fR +.ad +.sp .6 +.RS 4n +Use \fBcompress\fR for compressing or decompressing the archives. +.RE + +.sp +.ne 2 +.na \fB\fB@\fR\fR .ad .sp .6 @@ -952,42 +993,6 @@ tar: tape read error .SH ENVIRONMENT VARIABLES .sp -.ne 2 -.na -\fB\fBSYSV3\fR\fR -.ad -.sp .6 -.RS 4n -This variable is used to override the default behavior of \fBtar\fR, provide -compatibility with INTERACTIVE UNIX Systems and SCO UNIX installation scripts, -and should not be used in new scripts. (It is intended for compatibility -purposes only.) When set, the following function modifiers behave differently: -.sp -.ne 2 -.na -\fB\fBF\fR \fIfilename\fR\fR -.ad -.sp .6 -.RS 4n -Uses \fIfilename\fR to obtain a list of command line switches and files on -which to operate. -.RE - -.sp -.ne 2 -.na -\fB\fBe\fR\fR -.ad -.sp .6 -.RS 4n -Prevents files from being split across volumes. If there is insufficient room -on one volume, \fBtar\fR prompts for a new volume. If the file does not fit on -the new volume, \fBtar\fR exits with an error. -.RE - -.RE - -.sp .LP See \fBenviron\fR(5) for descriptions of the following environment variables that affect the execution of \fBtar\fR: \fBLC_COLLATE\fR, \fBLC_CTYPE\fR, @@ -1160,9 +1165,10 @@ Interface Stability Committed .SH SEE ALSO .sp .LP -\fBar\fR(1), \fBbasename\fR(1), \fBcd\fR(1), \fBchown\fR(1), \fBcpio\fR(1), -\fBcsh\fR(1), \fBdirname\fR(1), \fBfind\fR(1), \fBls\fR(1), \fBmt\fR(1), -\fBpax\fR(1), \fBsetfacl\fR(1), \fBumask\fR(1), \fBmknod\fR(1M), +\fBar\fR(1), \fBbasename\fR(1), \fBbzip2\fR(1), \fBcd\fR(1), \fBchown\fR(1), +\fBcompress\fR)(1), \fBcpio\fR(1), \fBcsh\fR(1), \fBdirname\fR(1), +\fBfind\fR(1), \fBgzip\fR(1), \fBls\fR(1), \fBmt\fR(1), \fBpax\fR(1), +\fBsetfacl\fR(1), \fBumask\fR(1), \fBxz\fR(1), \fBmknod\fR(1M), \fBarchives.h\fR(3HEAD), \fBattributes\fR(5), \fBenviron\fR(5), \fBfsattr\fR(5), \fBlargefile\fR(5), \fBmtio\fR(7I) .SH DIAGNOSTICS |