diff options
author | amw <none@none> | 2007-10-25 16:34:29 -0700 |
---|---|---|
committer | amw <none@none> | 2007-10-25 16:34:29 -0700 |
commit | da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0 (patch) | |
tree | 65be91fb78a6a66183197595333f2e8aafb4640a /usr/src/cmd/compress/compress.c | |
parent | e845e33dd0d1aea22db7edaa8c7d43955d24609b (diff) | |
download | illumos-joyent-da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0.tar.gz |
PSARC/2007/218 caller_context_t in all VOPs
PSARC/2007/227 VFS Feature Registration and ACL on Create
PSARC/2007/244 ZFS Case-insensitive support
PSARC/2007/315 Extensible Attribute Interfaces
PSARC/2007/394 ls(1) new command line options '-/' and '-%': CIFS system attributes support
PSARC/2007/403 Modified Access Checks for CIFS
PSARC/2007/410 Add system attribute support to chmod(1)
PSARC/2007/432 CIFS system attributes support for cp(1), pack(1), unpack(1), compress(1) and uncompress(1)
PSARC/2007/444 Rescind SETTABLE Attribute
PSARC/2007/459 CIFS system attributes support for cpio(1), pax(1), tar(1)
PSARC/2007/546 Update utilities to match CIFS system attributes changes.
PSARC/2007/560 ZFS sharesmb property
4890717 want append-only files
6417428 Case-insensitive file system name lookup to support CIFS
6417435 DOS attributes and additional timestamps to support for CIFS
6417442 File system quarantined and modified attributes to support an integrated Anti-Virus service
6417453 FS boolean property for rejecting/allowing invalid UTF-8 sequences in file names
6473733 RFE: Need support for open-deny modes
6473755 RFE: Need ability to reconcile oplock and delegation conflicts
6494624 sharemgr needs to support CIFS shares better
6546705 All vnode operations need to pass caller_context_t
6546706 Need VOP_SETATTR/VOP_GETATTR to support new, optional attributes
6546893 Solaris system attribute support
6550962 ZFS ACL inheritance needs to be enhanced to support Automatic Inheritance
6553589 RFE: VFS Feature Registration facility
6553770 RFE: ZFS support for ACL-on-CREATE (PSARC 2007/227)
6565581 ls(1) should support file system attributes proposed in PSARC/2007/315
6566784 NTFS streams are not copied along with the files.
6576205 cp(1), pack(1) and compress(1) should support file system attributes proposed in PSARC/2007/315
6578875 RFE: kernel interfaces for nbmand need improvement
6578883 RFE: VOP_SHRLOCK needs additional access types
6578885 chmod(1) should support file system attributes proposed in PSARC/2007/315
6578886 RFE: disallow nbmand state to change on remount
6583349 ACL parser needs to support audit/alarm ACE types
6590347 tar(1) should support filesystem attributes proposed in PSARC/2007/315
6597357 *tar* xv@ doesn't show the hidden directory even though it is restored
6597360 *tar* should re-init xattr info if openat() fails during extraction of and extended attribute
6597368 *tar* cannot restore hard linked extended attributes
6597374 *tar* doesn't display "x " when hard linked attributes are restored
6597375 *tar* extended attribute header off by one
6614861 *cpio* incorrectly archives extended system attributes with -@
6614896 *pax* incorrectly archives extended system attributes with -@
6615225 *tar* incorrectly archives extended system attributes with -@
6617183 CIFS Service - PSARC 2006/715
Diffstat (limited to 'usr/src/cmd/compress/compress.c')
-rw-r--r-- | usr/src/cmd/compress/compress.c | 165 |
1 files changed, 64 insertions, 101 deletions
diff --git a/usr/src/cmd/compress/compress.c b/usr/src/cmd/compress/compress.c index fd08c406b9..de8e62b704 100644 --- a/usr/src/cmd/compress/compress.c +++ b/usr/src/cmd/compress/compress.c @@ -116,30 +116,20 @@ static char_type magic_header[] = { "\037\235" }; /* 1F 9D */ static char rcs_ident[] = "$Header: compress.c,v 4.0 85/07/30 12:50:00 joe Release $"; -#include <stdio.h> #include <ctype.h> #include <signal.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <unistd.h> #include <sys/param.h> -#include <stdlib.h> /* XCU4 */ -#include <limits.h> -#include <libintl.h> #include <locale.h> #include <langinfo.h> -#include <string.h> #include <sys/acl.h> #include <utime.h> #include <libgen.h> #include <setjmp.h> -#include <strings.h> -#include <fcntl.h> -#include <dirent.h> #include <aclutils.h> -#include <errno.h> +#include <libcmdutils.h> #include "getresponse.h" + static int n_bits; /* number of bits/code */ static int maxbits = BITS; /* user settable max # bits/code */ static code_int maxcode; /* maximum code, given n_bits */ @@ -246,7 +236,6 @@ static void oops(); static void output(code_int); static void prratio(FILE *, count_long, count_long); static void version(void); -static int mv_xattrs(char *, char *, int); #ifdef DEBUG static int in_stack(int, int); @@ -287,6 +276,10 @@ static count_long bytes_out; /* length of compressed output */ code_int sorttab[1<<BITS]; /* sorted pointers into htab */ #endif +/* Extended system attribute support */ + +static int saflg = 0; + /* * ************************************************************* * TAG( main ) @@ -294,7 +287,7 @@ code_int sorttab[1<<BITS]; /* sorted pointers into htab */ * Algorithm from "A Technique for High Performance Data Compression", * Terry A. Welch, IEEE Computer Vol 17, No 6 (June 1984), pp 8-19. * - * Usage: compress [-dfvc] [-b bits] [file ...] + * Usage: compress [-dfvc/] [-b bits] [file ...] * Inputs: * -d: If given, decompression is done instead. * @@ -307,6 +300,8 @@ code_int sorttab[1<<BITS]; /* sorted pointers into htab */ * If -f is not used, the user will be prompted if stdin is * a tty, otherwise, the output file will not be overwritten. * + * -/ Copies extended attributes and extended system attributes. + * * -v: Write compression statistics * * file ...: Files to be compressed. If none specified, stdin @@ -397,9 +392,9 @@ main(int argc, char *argv[]) * if a string is left, must be an input filename. */ #ifdef DEBUG - optstr = "b:cCdDfFnqvV"; + optstr = "b:cCdDfFnqvV/"; #else - optstr = "b:cCdfFnqvV"; + optstr = "b:cCdfFnqvV/"; #endif while ((ch = getopt(argc, argv, optstr)) != EOF) { @@ -466,6 +461,9 @@ main(int argc, char *argv[]) qflg++; quiet = 1; break; + case '/': + saflg++; + break; default: (void) fprintf(stderr, gettext( "Unknown flag: '%c'\n"), optopt); @@ -797,7 +795,9 @@ main(int argc, char *argv[]) } } if (!use_stdout) { - if (pathconf(ofname, _PC_XATTR_EXISTS) == 1) { + if ((pathconf(ofname, _PC_XATTR_EXISTS) == 1) || + (saflg && sysattr_support(ofname, + _PC_SATTR_EXISTS) == 1)) { (void) unlink(ofname); } /* Open output file */ @@ -1582,6 +1582,13 @@ copystat(char *ifname, struct stat *ifstat, char *ofname) struct utimbuf timep; acl_t *aclp = NULL; int error; + int sattr_exist = 0; + int xattr_exist = 0; + + if (pathconf(ifname, _PC_XATTR_EXISTS) == 1) + xattr_exist = 1; + if (saflg && sysattr_support(ifname, _PC_SATTR_EXISTS) == 1) + sattr_exist = 1; if (fclose(outp)) { perror(ofname); @@ -1618,20 +1625,34 @@ copystat(char *ifname, struct stat *ifstat, char *ofname) " -- file unchanged")); newline_needed = 1; } - } else if ((pathconf(ifname, _PC_XATTR_EXISTS) == 1) && - (mv_xattrs(ifname, ofname, 0) < 0)) { + } else if ((xattr_exist || sattr_exist) && + (mv_xattrs(progname, ifname, ofname, sattr_exist, 0) + != 0)) { (void) fprintf(stderr, gettext( - "%s: -- cannot preserve extended attributes, " - "file unchanged"), ifname); + "%s: -- cannot preserve extended attributes or " + "system attributes, file unchanged"), ifname); newline_needed = 1; /* Move attributes back ... */ - (void) mv_xattrs(ofname, ifname, 1); + xattr_exist = 0; + sattr_exist = 0; + if (pathconf(ofname, _PC_XATTR_EXISTS) == 1) + xattr_exist = 1; + if (saflg && sysattr_support(ofname, _PC_SATTR_EXISTS) == 1) + sattr_exist = 1; + if (sattr_exist || xattr_exist) + (void) mv_xattrs(progname, ofname, ifname, + sattr_exist, 1); perm_stat = 1; - } else { /* ***** Successful Compression ***** */ + } else { /* ***** Successful Compression ***** */ mode = ifstat->st_mode & 07777; - if (chmod(ofname, mode)) /* Copy modes */ + if (chmod(ofname, mode)) { /* Copy modes */ + if (errno == EPERM) { + (void) fprintf(stderr, + gettext("failed to chmod %s" + "- permisssion denied\n"), ofname); + } perror(ofname); - + } error = acl_get(ifname, ACL_NO_TRIVIAL, &aclp); if (error != 0) { (void) fprintf(stderr, gettext( @@ -1640,7 +1661,8 @@ copystat(char *ifname, struct stat *ifstat, char *ofname) perm_stat = 1; } if (aclp && (acl_set(ofname, aclp) < 0)) { - (void) fprintf(stderr, gettext("%s: failed to set acl " + (void) fprintf(stderr, + gettext("%s: failed to set acl " "entries\n"), ofname); perm_stat = 1; } @@ -1655,8 +1677,14 @@ copystat(char *ifname, struct stat *ifstat, char *ofname) timep.modtime = ifstat->st_mtime; /* Update last accessed and modified times */ (void) utime(ofname, &timep); - if (unlink(ifname)) /* Remove input file */ + if (unlink(ifname)) { /* Remove input file */ + if (errno == EPERM) { + (void) fprintf(stderr, + gettext("failed to remove %s" + "- permisssion denied\n"), ifname); + } perror(ifname); + } if (!quiet) { (void) fprintf(stderr, gettext( " -- replaced with %s"), ofname); @@ -1668,6 +1696,11 @@ copystat(char *ifname, struct stat *ifstat, char *ofname) /* Unsuccessful return -- one of the tests failed */ if (ofname[0] != '\0') { if (unlink(ofname)) { + if (errno == EPERM) { + (void) fprintf(stderr, + gettext("failed to remove %s" + "- permisssion denied\n"), ifname); + } perror(ofname); } @@ -1804,16 +1837,16 @@ Usage() { #ifdef DEBUG (void) fprintf(stderr, - "Usage: compress [-dDVfc] [-b maxbits] [file ...]\n"); + "Usage: compress [-dDVfc/] [-b maxbits] [file ...]\n"); #else if (strcmp(progname, "compress") == 0) { (void) fprintf(stderr, gettext( - "Usage: compress [-fv] [-b maxbits] [file ...]\n"\ - " compress [-cfv] [-b maxbits] [file]\n")); + "Usage: compress [-fv/] [-b maxbits] [file ...]\n"\ + " compress c [-fv] [-b maxbits] [file]\n")); } else if (strcmp(progname, "uncompress") == 0) (void) fprintf(stderr, gettext( - "Usage: uncompress [-cfv] [file ...]\n")); + "Usage: uncompress [-fv] [-c || -/] [file ...]\n")); else if (strcmp(progname, "zcat") == 0) (void) fprintf(stderr, gettext("Usage: zcat [file ...]\n")); @@ -1872,73 +1905,3 @@ addDotZ(char *fn, size_t fnsize) return (0); } - -/* - * mv_xattrs - move (via renameat) all of the extended attributes - * associated with the file infile to the file outfile. - * This function returns 0 on success and -1 on error. - */ -static int -mv_xattrs(char *infile, char *outfile, int silent) -{ - int indfd, outdfd, tmpfd; - DIR *dirp = NULL; - struct dirent *dp = NULL; - int error = 0; - char *etext; - - indfd = outdfd = tmpfd = -1; - - if ((indfd = attropen(infile, ".", O_RDONLY)) == -1) { - etext = gettext("cannot open source"); - error = -1; - goto out; - } - - if ((outdfd = attropen(outfile, ".", O_RDONLY)) == -1) { - etext = gettext("cannot open target"); - error = -1; - goto out; - } - - if ((tmpfd = dup(indfd)) == -1) { - etext = gettext("cannot dup descriptor"); - error = -1; - goto out; - - } - if ((dirp = fdopendir(tmpfd)) == NULL) { - etext = gettext("cannot access source"); - error = -1; - goto out; - } - - while (dp = readdir(dirp)) { - if ((dp->d_name[0] == '.' && dp->d_name[1] == '\0') || - (dp->d_name[0] == '.' && dp->d_name[1] == '.' && - dp->d_name[2] == '\0')) - continue; - if ((renameat(indfd, dp->d_name, outdfd, dp->d_name)) == -1) { - etext = dp->d_name; - error = -1; - goto out; - } - } -out: - if (error == -1 && silent == 0) { - if (quiet) { - (void) fprintf(stderr, "%s: ", infile); - } else { - (void) fprintf(stderr, ", "); - } - (void) fprintf(stderr, gettext("extended attribute error: ")); - perror(etext); - } - if (dirp) - (void) closedir(dirp); - if (indfd != -1) - (void) close(indfd); - if (outdfd != -1) - (void) close(outdfd); - return (error); -} |