diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2014-12-01 15:02:38 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2014-12-01 15:02:38 +0200 |
commit | 3945f9db44c935608caa5f084fd7f67ae59ee9e1 (patch) | |
tree | 40dc48c8b3a8872bb8aaafdc9af1133a11d4e460 | |
parent | 4900a5e7be9ad90fda7c4743fd31613ceb0eda05 (diff) | |
download | cpio-3945f9db44c935608caa5f084fd7f67ae59ee9e1.tar.gz cpio-3945f9db44c935608caa5f084fd7f67ae59ee9e1.tar.bz2 |
New options to create device and inode-independent archives.
* src/util.c (inode_val): New member trans_inode
(find_inode_val): New function.
(find_inode_file): Rewrite using the above.
(add_inode): Initialize the trans_inode member
depending on the value of renumber_inodes_option.
(get_inode_and_dev): New function.
(stat_to_cpio): Use get_inode_and_dev.
(arf_stores_inode_p): New function.
* src/extern.h (renumber_inodes_option)
(ignore_devno_option): New externs.
* src/global.c (renumber_inodes_option)
(ignore_devno_option): New variables.
* src/main.c: Add new options.
* NEWS: Document changes.
* doc/cpio.1: Document new options.
* doc/cpio.texi: Likewise.
-rw-r--r-- | NEWS | 13 | ||||
-rw-r--r-- | doc/cpio.1 | 15 | ||||
-rw-r--r-- | doc/cpio.texi | 9 | ||||
-rw-r--r-- | src/extern.h | 8 | ||||
-rw-r--r-- | src/global.c | 4 | ||||
-rw-r--r-- | src/main.c | 34 | ||||
-rw-r--r-- | src/util.c | 84 |
7 files changed, 150 insertions, 17 deletions
@@ -1,2 +1,2 @@ -GNU cpio NEWS -- history of user-visible changes. 2014-01-30 +GNU cpio NEWS -- history of user-visible changes. 2014-12-01 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2009, @@ -11,3 +11,14 @@ Version 2.11.90 - Git * Manpages are installed by make install. +* New options for copy-out mode: +** --ignore-devno +Store 0 in the device number fields, instead of the actual device +number. + +** --renumber-inodes +Renumber inodes when storing them in the archive. + +** --device-independent or --reproducible +Create reproducible archives. This is equivalent to +--ignore-devno --renumber-inodes. @@ -15,3 +15,3 @@ .\" along with GNU cpio. If not, see <http://www.gnu.org/licenses/>. -.TH CPIO 1 "January 30, 2014" "CPIO" "GNU CPIO" +.TH CPIO 1 "December 1, 2014" "CPIO" "GNU CPIO" .SH NAME @@ -31,3 +31,3 @@ cpio \- copy files to and from archives [\fB\-\-force\-local\fR] [\fB\-\-rsh\-command=\fICOMMAND\fR] -< \fIname-list\fR [\fB>\fR \fIarchive\fR] +\fB<\fR \fIname-list\fR [\fB>\fR \fIarchive\fR] @@ -264,2 +264,10 @@ Append to an existing archive. .TP +.BR \-\-device\-independent ", " \-\-reproducible +Create reproducible archives. This is equivalent to +.BR "\-\-ignore\-devno \-\-renumber\-inodes" . +.TP +.B \-\-ignore\-devno +Store 0 in the device number field of each archive member, instead of +the actual device number. +.TP \fB\-O\fR [[\fIUSER\fB@\fR]\fIHOST\fB:\fR]\fIARCHIVE-NAME\fR @@ -271,2 +279,5 @@ The output archive name can be specified wither using this option, or using \fB\-F\fR (\fB\-\-file\fR), but not both. +.TP +.B \-\-renumber\-inodes +Renumber inodes when storing them in the archive. .SS Operation modifiers valid only in copy-pass mode diff --git a/doc/cpio.texi b/doc/cpio.texi index c1cf11b..dee3c13 100644 --- a/doc/cpio.texi +++ b/doc/cpio.texi @@ -463,2 +463,6 @@ Set the I/O block size to the given @var{number} of bytes. Create leading directories where needed. +@item --device-independent +@itemx --reproducible +Create reproducible archives. This is equivalent to +@option{--ignore-devno --renumber-inodes}. @item -D @var{dir} @@ -485,2 +489,5 @@ Use given archive format. @xref{format}, for a list of available formats. +@item --ignore-devno +Store 0 in the device number field of each archive member, instead of +the actual device number. @item -l @@ -514,2 +521,4 @@ Use @var{command} instead of @command{rsh} to access remote archives. Interactively rename files +@item --renumber-inodes +Renumber inodes when storing them in the archive. @item -R diff --git a/src/extern.h b/src/extern.h index 92117cd..da16794 100644 --- a/src/extern.h +++ b/src/extern.h @@ -58,2 +58,4 @@ extern unsigned int warn_option; extern mode_t newdir_umask; +extern int renumber_inodes_option; +extern int ignore_devno_option; @@ -173,4 +175,4 @@ char *find_inode_file (ino_t node_num, unsigned long major_num, unsigned long minor_num); -void add_inode (ino_t node_num, char *file_name, - unsigned long major_num, unsigned long minor_num); +struct inode_val *add_inode (ino_t node_num, char *file_name, + unsigned long major_num, unsigned long minor_num); int open_archive (char *file); @@ -220 +222,3 @@ void apply_delayed_set_stat (void); +int arf_stores_inode_p (enum archive_format arf); + diff --git a/src/global.c b/src/global.c index c699f6e..0449193 100644 --- a/src/global.c +++ b/src/global.c @@ -197 +197,5 @@ void (*copy_function) () = 0; char *change_directory_option; + +int renumber_inodes_option; +int ignore_devno_option; + @@ -60,3 +60,6 @@ enum cpio_options { BLOCK_SIZE_OPTION, - TO_STDOUT_OPTION + TO_STDOUT_OPTION, + RENUMBER_INODES_OPTION, + IGNORE_DEVNO_OPTION, + DEVICE_INDEPENDENT_OPTION }; @@ -192,2 +195,9 @@ static struct argp_option options[] = { N_("Archive filename to use instead of standard output. Optional USER and HOST specify the user and host names in case of a remote archive"), GRID+1 }, + {"renumber-inodes", RENUMBER_INODES_OPTION, NULL, 0, + N_("Renumber inodes") }, + {"ignore-devno", IGNORE_DEVNO_OPTION, NULL, 0, + N_("Don't store device numbers") }, + {"device-independent", DEVICE_INDEPENDENT_OPTION, NULL, 0, + N_("Create device-independent (reproducible) archives") }, + {"reproducible", 0, NULL, OPTION_ALIAS }, #undef GRID @@ -443,3 +453,15 @@ crc newc odc bin ustar tar (all-caps also recognized)"), arg)); break; - + + case IGNORE_DEVNO_OPTION: + ignore_devno_option = 1; + break; + + case RENUMBER_INODES_OPTION: + renumber_inodes_option = 1; + break; + + case DEVICE_INDEPENDENT_OPTION: + ignore_devno_option = renumber_inodes_option = 1; + break; + case RSH_COMMAND_OPTION: @@ -594,2 +616,4 @@ process_args (int argc, char *argv[]) CHECK_USAGE (output_archive_name, "-O", "--extract"); + CHECK_USAGE (renumber_inodes_option, "--renumber-inodes", "--extract"); + CHECK_USAGE (ignore_devno_option, "--ignore-devno", "--extract"); if (to_stdout_option) @@ -651,2 +675,5 @@ process_args (int argc, char *argv[]) archive_name = output_archive_name; + + if (!arf_stores_inode_p (archive_format)) + renumber_inodes_option = ignore_devno_option = 0; } @@ -677,2 +704,5 @@ process_args (int argc, char *argv[]) CHECK_USAGE (to_stdout_option, "--to-stdout", "--pass-through"); + CHECK_USAGE (renumber_inodes_option, "--renumber-inodes", + "--pass-through"); + CHECK_USAGE (ignore_devno_option, "--ignore-devno", "--pass-through"); @@ -694,2 +694,3 @@ struct inode_val unsigned long minor_num; + ino_t trans_inode; char *file_name; @@ -717,4 +718,4 @@ inode_val_compare (const void *val1, const void *val2) -char * -find_inode_file (ino_t node_num, unsigned long major_num, +static struct inode_val * +find_inode_val (ino_t node_num, unsigned long major_num, unsigned long minor_num) @@ -730,3 +731,10 @@ find_inode_file (ino_t node_num, unsigned long major_num, sample.minor_num = minor_num; - ival = hash_lookup (hash_table, &sample); + return hash_lookup (hash_table, &sample); +} + +char * +find_inode_file (ino_t node_num, unsigned long major_num, + unsigned long minor_num) +{ + struct inode_val *ival = find_inode_val (node_num, major_num, minor_num); return ival ? ival->file_name : NULL; @@ -736,3 +744,5 @@ find_inode_file (ino_t node_num, unsigned long major_num, -void +static ino_t next_inode; + +struct inode_val * add_inode (ino_t node_num, char *file_name, unsigned long major_num, @@ -741,3 +751,3 @@ add_inode (ino_t node_num, char *file_name, unsigned long major_num, struct inode_val *temp; - struct inode_val *e; + struct inode_val *e = NULL; @@ -748,3 +758,8 @@ add_inode (ino_t node_num, char *file_name, unsigned long major_num, temp->minor_num = minor_num; - temp->file_name = xstrdup (file_name); + temp->file_name = file_name ? xstrdup (file_name) : NULL; + + if (renumber_inodes_option) + temp->trans_inode = next_inode++; + else + temp->trans_inode = temp->inode; @@ -755,3 +770,35 @@ add_inode (ino_t node_num, char *file_name, unsigned long major_num, xalloc_die (); - /* FIXME: e is not used */ + return e; +} + +static ino_t +get_inode_and_dev (struct cpio_file_stat *hdr, struct stat *st) +{ + if (renumber_inodes_option) + { + if (st->st_nlink > 1) + { + struct inode_val *ival = find_inode_val (st->st_ino, + major (st->st_dev), + minor (st->st_dev)); + if (!ival) + ival = add_inode (st->st_ino, NULL, + major (st->st_dev), minor (st->st_dev)); + hdr->c_ino = ival->trans_inode; + } + else + hdr->c_ino = next_inode++; + } + else + hdr->c_ino = st->st_ino; + if (ignore_devno_option) + { + hdr->c_dev_maj = 0; + hdr->c_dev_min = 0; + } + else + { + hdr->c_dev_maj = major (st->st_dev); + hdr->c_dev_min = minor (st->st_dev); + } } @@ -1213,5 +1260,4 @@ stat_to_cpio (struct cpio_file_stat *hdr, struct stat *st) { - hdr->c_dev_maj = major (st->st_dev); - hdr->c_dev_min = minor (st->st_dev); - hdr->c_ino = st->st_ino; + get_inode_and_dev (hdr, st); + /* For POSIX systems that don't define the S_IF macros, @@ -1622,2 +1668,3 @@ change_dir () exit (PAXEXIT_FAILURE); + if (chdir (change_directory_option) == 0) @@ -1629 +1676,18 @@ change_dir () } + +/* Return true if the archive format ARF stores inode numbers */ +int +arf_stores_inode_p (enum archive_format arf) +{ + switch (arf) + { + case arf_tar: + case arf_ustar: + return 0; + + default: + break; + } + return 1; +} + |