Project

General

Profile

Feature #356 ยป xz.patch

suggested fix - Milan Jurik, 2012-05-12 01:55 PM

View differences:

new/usr/src/cmd/file/magic Sat May 12 11:45:04 2012
617 617
>8	string	jpx		JPEG 2000 w/ extensions (.JPX) [ISO 15444-2]
618 618
>8	string	mp42		v2 [ISO 14496-14]
619 619
4	string	moov		QuickTime MOV file
620

  
621
0	string		\375\067\172\130\132\000	xz compressed data
620
-- old/usr/src/cmd/tar/tar.c	Sat May 12 11:45:06 2012
622
++ new/usr/src/cmd/tar/tar.c	Sat May 12 11:45:05 2012
......
20 20
 */
21 21
/*
22 22
 * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
23
 * Copyright 2012 Milan Jurik. All rights reserved.
23 24
 */
24 25

  
25 26
/*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
......
548 549
static void decompress_file(void);
549 550
static pid_t uncompress_file(void);
550 551
static void *compress_malloc(size_t);
551
static void check_compression();
552
static char *bz_suffix();
553
static char *gz_suffix();
552
static void check_compression(void);
553
static char *bz_suffix(void);
554
static char *gz_suffix(void);
555
static char *xz_suffix(void);
554 556
static char *add_suffix();
555 557
static void wait_pid(pid_t);
556 558

  
......
572 574
static	int	jflag;			/* flag to use 'bzip2' */
573 575
static	int	zflag;			/* flag to use 'gzip' */
574 576
static	int	Zflag;			/* flag to use 'compress' */
577
static	int	Jflag;			/* flag to use 'xz' */
575 578

  
576 579
/* Trusted Extensions */
577 580
static	int	Tflag;			/* Trusted Extensions attr flags */
......
693 696
#define	BZIP		"/usr/bin/bzip2"
694 697
#define	GZIP		"/usr/bin/gzip"
695 698
#define	COMPRESS	"/usr/bin/compress"
699
#define	XZ		"/usr/bin/xz"
696 700
#define	BZCAT		"/usr/bin/bzcat"
697 701
#define	GZCAT		"/usr/bin/gzcat"
698 702
#define	ZCAT		"/usr/bin/zcat"
699
#define	GS		8		/* number of valid 'gzip' sufixes */
700
#define	BS		4		/* number of valid 'bzip2' sufixes */
703
#define	XZCAT		"/usr/bin/xzcat"
704
#define	GSUF		8	/* number of valid 'gzip' sufixes */
705
#define	BSUF		4	/* number of valid 'bzip2' sufixes */
706
#define	XSUF		1	/* number of valid 'xz' suffixes */
701 707

  
702 708
static	char		*compress_opt; 	/* compression type */
703 709

  
704 710
static	char		*gsuffix[] = {".gz", "-gz", ".z", "-z", "_z", ".Z",
705 711
			".tgz", ".taz"};
706 712
static	char		*bsuffix[] = {".bz2", ".bz", ".tbz2", ".tbz"};
713
static	char		*xsuffix[] = {".xz"};
707 714
static	char		*suffix;
708 715

  
709 716

  
......
897 904
			pflag++;	/* also set flag for ACL */
898 905
			break;
899 906
		case 'j':		/* compession "bzip2" */
900
			jflag++;
907
			jflag = 1;
901 908
			break;
902 909
		case 'z':		/* compression "gzip" */
903
			zflag++;
910
			zflag = 1;
904 911
			break;
905 912
		case 'Z':		/* compression "compress" */
906
			Zflag++;
913
			Zflag = 1;
907 914
			break;
915
		case 'J':		/* compression "xz" */
916
			Jflag = 1;
917
			break;
908 918
		default:
909 919
			(void) fprintf(stderr, gettext(
910 920
			"tar: %c: unknown function modifier\n"), *cp);
......
919 929
		usage();
920 930
	}
921 931
	if (cflag) {
922
		if ((zflag && jflag) || (zflag && Zflag) ||
923
		    (jflag && Zflag)) {
932
		if ((jflag + zflag + Zflag + Jflag) > 1) {
924 933
			(void) fprintf(stderr, gettext(
925
			    "tar: specify only one of [jzZ] to "
934
			    "tar: specify only one of [jJzZ] to "
926 935
			    "create a compressed file.\n"));
927 936
			usage();
928 937
		}
......
1004 1013
				compress_opt =
1005 1014
				    compress_malloc(strlen(COMPRESS) + 1);
1006 1015
				(void) strcpy(compress_opt, COMPRESS);
1016
			} else if (Jflag) {
1017
				compress_opt = compress_malloc(strlen(XZ) + 1);
1018
				(void) strcpy(compress_opt, XZ);
1007 1019
			}
1008 1020
		} else {
1009 1021
			/*
......
1167 1179
#else
1168 1180
	    "Usage: tar {c|r|t|u|x}[BDeEFhilmnopPTvw[0-7]][bf][X...] "
1169 1181
#endif	/* O_XATTR */
1170
	    "[j|z|Z] "
1182
	    "[j|J|z|Z] "
1171 1183
	    "[blocksize] [tarfile] [size] [exclude-file...] "
1172 1184
	    "{file | -I include-file | -C directory file}...\n"));
1173 1185
	done(1);
......
9174 9186
#define	GZIP_MAGIC	"\037\213"
9175 9187
#define	BZIP_MAGIC	"BZh"
9176 9188
#define	COMP_MAGIC	"\037\235"
9189
#define	XZ_MAGIC	"\375\067\172\130\132\000"
9177 9190

  
9178 9191
void
9179
check_compression()
9192
check_compression(void)
9180 9193
{
9181
	char 	magic[2];
9182
	char	buf[16];
9194
	char 	magic[16];
9183 9195
	FILE	*fp;
9184 9196

  
9185 9197
	if ((fp = fopen(usefile, "r")) != NULL) {
9186
		(void) fread(buf, sizeof (char), 6, fp);
9187
		magic[0] = buf[0];
9188
		magic[1] = buf[1];
9198
		(void) fread(magic, sizeof (char), 6, fp);
9189 9199
		(void) fclose(fp);
9190 9200
	}
9191 9201

  
......
9213 9223
			compress_opt = compress_malloc(strlen(COMPRESS) + 1);
9214 9224
			(void) strcpy(compress_opt, COMPRESS);
9215 9225
		}
9226
	} else if (memcmp(magic, XZ_MAGIC, 6) == 0) {
9227
		if (xflag || tflag) {
9228
			compress_opt = compress_malloc(strlen(XZCAT) + 1);
9229
			(void) strcpy(compress_opt, XZCAT);
9230
		} else if (uflag || rflag) {
9231
			compress_opt = compress_malloc(strlen(XZ) + 1);
9232
			(void) strcpy(compress_opt, XZ);
9233
		}
9216 9234
	}
9217 9235
}
9218 9236

  
......
9235 9253
			strlcat(tfname, bsuffix[0], sizeof (tfname));
9236 9254
			return (bsuffix[0]);
9237 9255
		}
9256
	} else if (strcmp(compress_opt, XZ) == 0) {
9257
		if ((suffix = xz_suffix()) == NULL) {
9258
			strlcat(tfname, xsuffix[0], sizeof (tfname));
9259
			return (xsuffix[0]);
9260
		}
9238 9261
	}
9239 9262
	return (NULL);
9240 9263
}
......
9330 9353
	return (0);	/*NOTREACHED*/
9331 9354
}
9332 9355

  
9333
/* Checking valid 'bzip2' suffix */
9356
/* Checking suffix validity */
9334 9357
char *
9335
bz_suffix()
9358
check_suffix(char **suf, int size)
9336 9359
{
9337 9360
	int 	i;
9338 9361
	int	slen;
9339 9362
	int	nlen = strlen(usefile);
9340 9363

  
9341
	for (i = 0; i < BS; i++) {
9342
		slen = strlen(bsuffix[i]);
9364
	for (i = 0; i < size; i++) {
9365
		slen = strlen(suf[i]);
9343 9366
		if (nlen < slen)
9344 9367
			return (NULL);
9345
		if (strcmp(usefile + nlen - slen, bsuffix[i]) == 0)
9346
			return (bsuffix[i]);
9368
		if (strcmp(usefile + nlen - slen, suf[i]) == 0)
9369
			return (suf[i]);
9347 9370
	}
9348 9371
	return (NULL);
9372

  
9349 9373
}
9350 9374

  
9375
/* Checking valid 'bzip2' suffix */
9376
char *
9377
bz_suffix(void)
9378
{
9379
	return (check_suffix(bsuffix, BSUF));
9380
}
9381

  
9351 9382
/* Checking valid 'gzip' suffix */
9352 9383
char *
9353
gz_suffix()
9384
gz_suffix(void)
9354 9385
{
9355
	int 	i;
9356
	int	slen;
9357
	int	nlen = strlen(usefile);
9386
	return (check_suffix(gsuffix, GSUF));
9387
}
9358 9388

  
9359
	for (i = 0; i < GS; i++) {
9360
		slen = strlen(gsuffix[i]);
9361
		if (nlen < slen)
9362
			return (NULL);
9363
		if (strcmp(usefile + nlen - slen, gsuffix[i]) == 0)
9364
			return (gsuffix[i]);
9365
	}
9366
	return (NULL);
9389
/* Checking valid 'xz' suffix */
9390
char *
9391
xz_suffix(void)
9392
{
9393
	return (check_suffix(xsuffix, XSUF));
9367 9394
}
9368 9395

  
9369 9396
void *
9370
-- old/usr/src/man/man1/tar.1	Sat May 12 11:45:08 2012
9397
++ new/usr/src/man/man1/tar.1	Sat May 12 11:45:07 2012
......
1 1
'\" te
2 2
.\" Copyright 1989 AT&T
3 3
.\" Copyright (c) 2006, Sun Microsystems, Inc. All Rights Reserved
4
.\" Copyright 2012 Milan Jurik. All rights reserved.
4 5
.\" Portions Copyright (c) 1992, X/Open Company Limited All Rights Reserved
5 6
.\" 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
6 7
.\" http://www.opengroup.org/bookstore/.
......
9 10
.\" 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.
10 11
.\" 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.
11 12
.\" 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]
12
.TH TAR 1 "Oct 26, 2007"
13
.TH TAR 1 "May 9, 2012"
13 14
.SH NAME
14 15
tar \- create tape archives and add or extract files
15 16
.SH SYNOPSIS
16 17
.LP
17 18
.nf
18
\fBtar\fR c[BDeEFhilnopPqTvw@/[0-7]][bfk][X...] [\fIblocksize\fR]
19
\fBtar\fR c[BDeEFhilnopPqTvw@/[0-7]][bfk][X...][j|J|z|Z] [\fIblocksize\fR]
19 20
     [\fItarfile\fR] [\fIsize\fR] [\fIexclude-file\fR]...
20 21
     {\fIfile\fR | \(miI \fIinclude-file\fR | \(miC \fIdirectory\fR \fIfile\fR}...
21 22
.fi
22 23

  
23 24
.LP
24 25
.nf
25
\fBtar\fR r[BDeEFhilnqTvw@/[0-7]][bfk] [\fIblocksize\fR] [\fItarfile\fR]
26
\fBtar\fR r[BDeEFhilnqTvw@/[0-7]][bfk][j|J|z|Z] [\fIblocksize\fR] [\fItarfile\fR]
26 27
     [\fIsize\fR]
27 28
     {\fIfile\fR | \(miI \fIinclude-file\fR | \(miC \fIdirectory\fR \fIfile\fR}...
28 29
.fi
29 30

  
30 31
.LP
31 32
.nf
32
\fBtar\fR t[BeFhilnqTv[0-7]][fk][X...] [\fItarfile\fR] [\fIsize\fR]
33
\fBtar\fR t[BeFhilnqTv[0-7]][fk][X...][j|J|z|Z] [\fItarfile\fR] [\fIsize\fR]
33 34
     [\fIexclude-file\fR]... {\fIfile\fR | \(miI \fIinclude-file\fR}...
34 35
.fi
35 36

  
36 37
.LP
37 38
.nf
38
\fBtar\fR u[BDeEFhilnqTvw@/[0-7]][bfk] [\fIblocksize\fR] [\fItarfile\fR]
39
\fBtar\fR u[BDeEFhilnqTvw@/[0-7]][bfk][j|J|z|Z] [\fIblocksize\fR] [\fItarfile\fR]
39 40
     [\fIsize\fR] \fIfile\fR...
40 41
.fi
41 42

  
42 43
.LP
43 44
.nf
44
\fBtar\fR x[BeFhilmnopqTvw@/[0-7]][fk][X...] [\fItarfile\fR] [\fIsize\fR]
45
\fBtar\fR x[BeFhilmnopqTvw@/[0-7]][fk][X...][j|J|z|Z] [\fItarfile\fR] [\fIsize\fR]
45 46
     [\fIexclude-file\fR]... [\fIfile\fR]...
46 47
.fi
47 48

  
......
397 398
.sp
398 399
.ne 2
399 400
.na
401
\fB\fBj\fR\fR
402
.ad
403
.sp .6
404
.RS 4n
405
Use \fBbzip2\fR for compressing or decompressing the archives.
406
.RE
407

  
408
.sp
409
.ne 2
410
.na
411
\fB\fBJ\fR\fR
412
.ad
413
.sp .6
414
.RS 4n
415
Use \fBxz\fR for compressing or decompressing the archives.
416
.RE
417

  
418
.sp
419
.ne 2
420
.na
400 421
\fB\fBk\fR \fIsize\fR\fR
401 422
.ad
402 423
.sp .6
......
589 610
.sp
590 611
.ne 2
591 612
.na
613
\fB\fBz\fR\fR
614
.ad
615
.sp .6
616
.RS 4n
617
Use \fBgzip\fR for compressing or decompressing the archives.
618
.RE
619

  
620
.sp
621
.ne 2
622
.na
623
\fB\fBZ\fR\fR
624
.ad
625
.sp .6
626
.RS 4n
627
Use \fBcompress\fR for compressing or decompressing the archives.
628
.RE
629

  
630
.sp
631
.ne 2
632
.na
592 633
\fB\fB@\fR\fR
593 634
.ad
594 635
.sp .6
......
952 993

  
953 994
.SH ENVIRONMENT VARIABLES
954 995
.sp
955
.ne 2
956
.na
957
\fB\fBSYSV3\fR\fR
958
.ad
959
.sp .6
960
.RS 4n
961
This variable is used to override the default behavior of \fBtar\fR, provide
962
compatibility with INTERACTIVE UNIX Systems and SCO UNIX installation scripts,
963
and should not be used in new scripts. (It is intended for compatibility
964
purposes only.) When set, the following function modifiers behave differently:
965
.sp
966
.ne 2
967
.na
968
\fB\fBF\fR \fIfilename\fR\fR
969
.ad
970
.sp .6
971
.RS 4n
972
Uses \fIfilename\fR to obtain a list of command line switches and files on
973
which to operate.
974
.RE
975

  
976
.sp
977
.ne 2
978
.na
979
\fB\fBe\fR\fR
980
.ad
981
.sp .6
982
.RS 4n
983
Prevents files from being split across volumes. If there is insufficient room
984
on one volume, \fBtar\fR prompts for a new volume. If the file does not fit on
985
the new volume, \fBtar\fR exits with an error.
986
.RE
987

  
988
.RE
989

  
990
.sp
991 996
.LP
992 997
See \fBenviron\fR(5) for descriptions of the following environment variables
993 998
that affect the execution of \fBtar\fR: \fBLC_COLLATE\fR, \fBLC_CTYPE\fR,
......
1160 1165
.SH SEE ALSO
1161 1166
.sp
1162 1167
.LP
1163
\fBar\fR(1), \fBbasename\fR(1), \fBcd\fR(1), \fBchown\fR(1), \fBcpio\fR(1),
1164
\fBcsh\fR(1), \fBdirname\fR(1), \fBfind\fR(1), \fBls\fR(1), \fBmt\fR(1),
1165
\fBpax\fR(1), \fBsetfacl\fR(1), \fBumask\fR(1), \fBmknod\fR(1M),
1168
\fBar\fR(1), \fBbasename\fR(1), \fBbzip2\fR(1), \fBcd\fR(1), \fBchown\fR(1),
1169
\fBcompress\fR)(1), \fBcpio\fR(1), \fBcsh\fR(1), \fBdirname\fR(1), 
1170
\fBfind\fR(1), \fBgzip\fR(1), \fBls\fR(1), \fBmt\fR(1), \fBpax\fR(1),
1171
\fBsetfacl\fR(1), \fBumask\fR(1), \fBxz\fR(1), \fBmknod\fR(1M),
1166 1172
\fBarchives.h\fR(3HEAD), \fBattributes\fR(5), \fBenviron\fR(5),
1167 1173
\fBfsattr\fR(5), \fBlargefile\fR(5), \fBmtio\fR(7I)
1168 1174
.SH DIAGNOSTICS
    (1-1/1)