diff options
author | H. Peter Anvin <hpa@zytor.com> | 2001-07-31 03:20:52 +0000 |
---|---|---|
committer | H. Peter Anvin <hpa@zytor.com> | 2001-07-31 03:20:52 +0000 |
commit | 0bb4bdb8969bc471ed7081a75cc495c8e8e61ace (patch) | |
tree | d8db77e052f7124d733865b8fd3d38632714e6f9 | |
parent | 0447c1c9916b064585fe8e0fa7e147aba1cae82b (diff) | |
download | zisofs-tools-0bb4bdb8969bc471ed7081a75cc495c8e8e61ace.tar.gz |
By default, abort if file modes, times and ownership cannot be set.
Since this isn't always possible, add new option -s/--sloppy to
suppress this error.
Fix man page typo, and add a BUGS section.
Move all command line options into common "opt" structure.
-rw-r--r-- | CHANGES | 11 | ||||
-rw-r--r-- | README | 13 | ||||
-rw-r--r-- | compress.c | 5 | ||||
-rw-r--r-- | configure.in | 1 | ||||
-rw-r--r-- | mkzftree.1 | 20 | ||||
-rw-r--r-- | mkzftree.c | 85 | ||||
-rw-r--r-- | mkzftree.h | 23 | ||||
-rw-r--r-- | util.c | 2 | ||||
-rw-r--r-- | version | 2 | ||||
-rw-r--r-- | walk.c | 27 | ||||
-rw-r--r-- | workers.c | 4 |
11 files changed, 124 insertions, 69 deletions
@@ -1,3 +1,14 @@ +News in zisofs-tools-1.0.1: + + By default, abort if file modes, times and ownership cannot be + set. Since this isn't always possible, add new option + -s/--sloppy to suppress this error. + + Fix man page typo, and add a BUGS section. + + Move all command line options into common "opt" structure. + + News in zisofs-tools-1.0: Restructured code; now split into a number of modules. @@ -1,4 +1,5 @@ - July 27, 2001 + H. Peter Anvin <hpa@zytor.com + July 29, 2001 User tools for zisofs: @@ -35,8 +36,8 @@ convert a compressed tree back to normal form. This can be used to read a zisofs CD-ROM on a machine without zisofs kernel support. This version of mkzftree supports a -p option (parallelize.) -Specifying -p and a parallelism (e.g. -p4) allows up to four files to -compress in parallel. Depending on your setup and your data set size, -this might speed things up if you are not completely I/O bound. Use --p0 to completely disable parallel execution; this is the default. - +Specifying -p and a parallelism (e.g. -p4) allows files (up to the +number specified) to compress in parallel. Depending on your setup +and your data set size, this might speed things up if you are not +completely I/O bound. Use -p0 to completely disable parallel +execution; this is the default. @@ -29,7 +29,7 @@ int block_compress_file(FILE *input, FILE *output, off_t size) char *pointer_block, *curptr; off_t position; int i; - int force_compress = force; + int force_compress = opt.force; int zerr; int err = EX_SOFTWARE; @@ -86,7 +86,8 @@ int block_compress_file(FILE *input, FILE *output, off_t size) /* All-zero block. No output */ } else { cbytes = 2*CBLOCK_SIZE; - if ( (zerr = compress2(outbuf, &cbytes, inbuf, bytes, level)) != Z_OK ) { + if ( (zerr = compress2(outbuf, &cbytes, inbuf, bytes, opt.level)) + != Z_OK ) { err = (zerr == Z_MEM_ERROR) ? EX_OSERR : EX_SOFTWARE; goto free_ptr_bail; /* Compression failure */ } diff --git a/configure.in b/configure.in index 160ed54..f44a1fa 100644 --- a/configure.in +++ b/configure.in @@ -19,6 +19,7 @@ PA_ADD_CFLAGS(-Wmissing-prototypes) PA_ADD_CFLAGS(-Wmissing-declarations) PA_ADD_CFLAGS(-Wnested-externs) PA_ADD_CFLAGS(-Winline) +PA_ADD_CFLAGS(-Wshadow) PA_ADD_CFLAGS(-Wcast-align) PA_ADD_CFLAGS(-pipe) @@ -10,7 +10,7 @@ .\" version; incorporated herein by reference. .\" .\" ----------------------------------------------------------------------- -.TH MKZFTREE "1" "27 July 2001" "zisofs-tools" "H. Peter Anvin" +.TH MKZFTREE "1" "29 July 2001" "zisofs-tools" "H. Peter Anvin" .SH NAME mkzftree \- Create a zisofs/RockRidge compressed file tree .SH SYNOPSIS @@ -62,6 +62,10 @@ allows operation on a single file. If \fI\-F\fP is specified, and \fIINPUT\fP is a symlink, the symlink will be copied rather than whatever it happens to point to. .TP +\fB\-s\fP, \fB\-\-sloppy\fP +Treat file modes, times and ownership data as less than precious +information and don't abort if they cannot be set. +.TP \fB\-v\fP, \fB\-\-verbose\fP Increase the program verbosity. .TP @@ -75,13 +79,21 @@ as specifying .IR "-V 0" . .TP \fB\-h\fP, \fB\-\-help\fP -Displays a brief help message. +Display a brief help message. .TP \fB\-w\fP, \fB\-\-version\fP Display the release version. .SH BUGS -Long options (beginning with \-\-) may not work on all systems. See the -message printed out by \fImkisofs \-h\fP. +Long options (beginning with \fI\-\-\fP) may not work on all systems. +See the message printed out by \fImkzftree \-h\fP to see if this +applies to your system. +.PP +Inode change times (ctimes) are not copied. This is a system +limitation and applies to all file copy programs. +.PP +If using the parallel option (\fI\-z\fP) the access times (atimes) on +directories may or may not be copied. If it is important that the +atimes on directories are copied exactly, avoid using \fI\-z\fP. .SH AUTHOR Written by H. Peter Anvin <hpa@zytor.com>. .SH COPYRIGHT @@ -77,14 +77,18 @@ #endif /* Command line options */ -int force = 0; /* Always compress */ -int level = 9; /* Compression level */ -int parallel = 0; /* Parallelism (0 = strictly serial) */ -int onefs = 0; /* One filesystem only */ -int onedir = 0; /* One directory only */ -int do_mkdir = 1; /* Create stub directories */ -enum verbosity verbosity = default_verbosity; /* Default verbosity */ -munger_func munger = block_compress_file; /* Default action */ +struct cmdline_options opt = { + 0, /* Force compression */ + 9, /* Compression level */ + 0, /* Parallelism (0 = strictly serial) */ + 0, /* One filesystem only */ + 0, /* One directory only */ + 1, /* Create stub directories */ + 0, /* Root may be a file */ + 0, /* Be paranoid about metadata */ + default_verbosity, /* Default verbosity */ + block_compress_file /* Default transformation function */ +}; /* Program name */ const char *program; @@ -129,6 +133,7 @@ static void usage(enum verbosity level, int err) LO(" --local ")" -l Do not recurse into subdirectoires\n" LO(" --strict-local ")" -L Same as -l, but don't create stubs dirs\n" LO(" --file ")" -F Operate possibly on a single file\n" + LO(" --sloppy ")" -s Don't abort if metadata cannot be set\n" LO(" --verbose ")" -v Increase message verbosity\n" LO(" --verbosity # ")" -V # Set message verbosity to # (default = %d)\n" LO(" --quiet ")" -q No messages, not even errors (-V 0)\n" @@ -156,59 +161,56 @@ int main(int argc, char *argv[]) const char *in, *out; struct stat st; struct utimbuf ut; - int opt, err; - int file_root = 0; + int optch, err; program = argv[0]; - while ( (opt = getopt_long(argc, argv, OPTSTRING, long_options, NULL)) + while ( (optch = getopt_long(argc, argv, OPTSTRING, long_options, NULL)) != EOF ) { - switch(opt) { + switch(optch) { case 'f': - force = 1; /* Always compress */ + opt.force = 1; /* Always compress */ break; case 'z': - if ( optarg[0] < '0' || optarg[0] > '9' || optarg[1] ) { - message(vl_error, "%s: invalid compression level: %s\n", + opt.level = opt_atoi(optarg); + if ( opt.level < 1 || opt.level > 9 ) { + message(vl_error, "%s: invalid compression level: %d\n", program, optarg); exit(EX_USAGE); - } else { - level = optarg[0] - '0'; } break; case 'v': - verbosity++; + opt.verbosity++; break; case 'V': - verbosity = opt_atoi(optarg); + opt.verbosity = opt_atoi(optarg); break; case 'q': - verbosity = vl_quiet; + opt.verbosity = vl_quiet; break; case 'u': - munger = block_uncompress_file; + opt.munger = block_uncompress_file; break; case 'p': - parallel = opt_atoi(optarg); + opt.parallel = opt_atoi(optarg); break; case 'x': - onefs = 1; - do_mkdir = 1; + opt.onefs = 1; opt.do_mkdir = 1; break; case 'l': - onedir = 1; - do_mkdir = 1; + opt.onedir = 1; opt.do_mkdir = 1; break; case 'X': - onefs = 1; - do_mkdir = 0; + opt.onefs = 1; opt.do_mkdir = 0; break; case 'L': - onedir = 1; - do_mkdir = 0; + opt.onedir = 1; opt.do_mkdir = 0; break; case 'F': - file_root = 1; + opt.file_root = 1; + break; + case 's': + opt.sloppy = 1; break; case 'h': usage(vl_quiet, 0); @@ -230,7 +232,7 @@ int main(int argc, char *argv[]) umask(077); - if ( file_root ) { + if ( opt.file_root ) { if ( lstat(in, &st) ) { message(vl_error, "%s: %s: %s\n", program, in, strerror(errno)); exit(EX_NOINPUT); @@ -256,13 +258,22 @@ int main(int argc, char *argv[]) if ( err ) exit(err); - if ( !file_root ) { - chown(out, st.st_uid, st.st_gid); - chmod(out, st.st_mode); + if ( !opt.file_root ) { + if ( chown(out, st.st_uid, st.st_gid) && !opt.sloppy ) { + message(vl_error, "%s: %s: %s", program, out, strerror(errno)); + err = EX_CANTCREAT; + } + if ( chmod(out, st.st_mode) && !opt.sloppy && !err ) { + message(vl_error, "%s: %s: %s", program, out, strerror(errno)); + err = EX_CANTCREAT; + } ut.actime = st.st_atime; ut.modtime = st.st_mtime; - utime(out, &ut); + if ( utime(out, &ut) && !opt.sloppy && !err ) { + message(vl_error, "%s: %s: %s", program, out, strerror(errno)); + err = EX_CANTCREAT; + } } - return 0; + return err; } @@ -45,20 +45,25 @@ int block_uncompress_file(FILE *, FILE *, off_t); /* mkzftree.c */ extern const char *program; /* Program name */ -extern int force; /* Always compress */ -extern int level; /* Compression level */ -extern int parallel; /* Parallelism (0 = strictly serial) */ -extern int onefs; /* One filesystem only */ -extern int onedir; /* One directory only */ -extern int do_mkdir; /* Create stub directories */ -extern munger_func munger; /* Default action */ -enum verbosity { +enum verbosity { /* Message verbosity */ vl_quiet, /* No messages */ vl_error, /* Error messages only */ vl_filename, /* Display filenames */ }; #define default_verbosity vl_error -extern enum verbosity verbosity; /* Message verbosity */ +struct cmdline_options { + int force; /* Always compress */ + int level; /* Compression level */ + int parallel; /* Parallelism (0 = strictly serial) */ + int onefs; /* One filesystem only */ + int onedir; /* One directory only */ + int do_mkdir; /* Create stub directories */ + int file_root; /* The root may be a file */ + int sloppy; /* Don't make sure metadata is set correctly */ + enum verbosity verbosity; /* Message verbosity */ + munger_func munger; /* Default action */ +}; +extern struct cmdline_options opt; /* walk.c */ int munge_tree(const char *, const char *); @@ -48,7 +48,7 @@ void message(enum verbosity level, const char *format, ...) va_list ap; va_start(ap, format); - if ( verbosity >= level ) + if ( opt.verbosity >= level ) vfprintf(stderr, format, ap); va_end(ap); } @@ -1 +1 @@ -1.0 +1.0.1 @@ -45,7 +45,7 @@ static int munge_path(const char *inpath, const char *outpath, struct stat *st) } if ( spawn_worker() ) { - err = munger(in, out, st->st_size); + err = opt.munger(in, out, st->st_size); fclose(in); fclose(out); @@ -180,10 +180,11 @@ int munge_entry(const char *in_path, const char *out_path, const struct stat *di } } else if ( S_ISDIR(st.st_mode) ) { /* Recursion: see recursion */ - if ( !onedir && (!onefs || (dirst && dirst->st_dev == st.st_dev)) ) { + if ( !opt.onedir && + (!opt.onefs || (dirst && dirst->st_dev == st.st_dev)) ) { if ( (err = munge_tree(in_path, out_path)) != 0 ) return err; - } else if ( do_mkdir ) { + } else if ( opt.do_mkdir ) { /* Create stub directories */ if ( mkdir(out_path, st.st_mode) ) { message(vl_error, "%s: %s: %s", program, out_path, strerror(errno)); @@ -245,16 +246,28 @@ int munge_entry(const char *in_path, const char *out_path, const struct stat *di /* This is done by munge_path() for files */ if ( !S_ISREG(st.st_mode) ) { #ifdef HAVE_LCHOWN - lchown(out_path, st.st_uid, st.st_gid); + if ( lchown(out_path, st.st_uid, st.st_gid) && opt.sloppy && !err ) { + message(vl_error, "%s: %s: %s", program, out_path, strerror(errno)); + err = EX_CANTCREAT; + } #endif if ( !S_ISLNK(st.st_mode) ) { #ifndef HAVE_LCHOWN - chown(out_path, st.st_uid, st.st_gid); + if ( chown(out_path, st.st_uid, st.st_gid) && !opt.sloppy && !err ) { + message(vl_error, "%s: %s: %s", program, out_path, strerror(errno)); + err = EX_CANTCREAT; + } #endif - chmod(out_path, st.st_mode); + if ( chmod(out_path, st.st_mode) && !opt.sloppy && !err ) { + message(vl_error, "%s: %s: %s", program, out_path, strerror(errno)); + err = EX_CANTCREAT; + } ut.actime = st.st_atime; ut.modtime = st.st_mtime; - utime(out_path, &ut); + if ( utime(out_path, &ut) && !opt.sloppy && !err ) { + message(vl_error, "%s: %s: %s", program, out_path, strerror(errno)); + err = EX_CANTCREAT; + } } } @@ -61,13 +61,13 @@ int spawn_worker(void) { pid_t f; - if ( parallel == 0 ) + if ( opt.parallel == 0 ) return 1; fflush(NULL); /* Wait for a work slot */ - while ( work_threads >= parallel ) + while ( work_threads >= opt.parallel ) wait_for_one_worker(); /* Spawn worker process */ |