]> Dogcows Code - chaz/tar/commitdiff
Implement the --show-snapshot-field-ranges option
authorNathan Stratton Treadway <nathanst@ontko.com>
Sun, 15 Sep 2013 13:02:30 +0000 (16:02 +0300)
committerSergey Poznyakoff <gray@gnu.org.ua>
Sun, 15 Sep 2013 13:02:30 +0000 (16:02 +0300)
* src/common.h (show_snapshot_field_ranges): New prototype.
* src/incremen.c (show_snapshot_field_ranges): New function.
* src/tar.c: New option --show-snapshot-field-ranges.
* doc/snapshot.texi: Document the --show-snapshot-field-ranges
option.
* doc/tar.texi: Likewise.

doc/snapshot.texi
doc/tar.texi
src/common.h
src/incremen.c
src/tar.c

index 03da663163b64bce52060dd37408cf70ab04bce7..ed394a47df5d96eeb1ffb0f350d28206ff2241cf 100644 (file)
@@ -94,7 +94,6 @@ as with @samp{format 0}.
 
 @cindex format 2, snapshot file
 @cindex snapshot file, format 2
-@FIXME{}
 @item
   @samp{Format 2} snapshot file begins with a format identifier, as described for
 version 1, e.g.:
@@ -108,7 +107,7 @@ records, separated by null (@acronym{ASCII} 0)
 characters. Thus, in contrast to the previous formats, format 2
 snapshot is a binary file.
 
-  First two records are decimal numbers, representing the
+  First two records are decimal integers, representing the
 time of the last backup.  First number is the number of seconds, the
 second one is the number of nanoseconds, since the beginning of the
 epoch.  These are followed by arbitrary number of directory records.
@@ -116,17 +115,18 @@ epoch.  These are followed by arbitrary number of directory records.
   Each @dfn{directory record} contains a set of metadata describing a
 particular directory.  Parts of a directory record are delimited with
 @acronym{ASCII} 0 characters.  The following table describes each
-part.  The @dfn{Number} type in this table stands for a decimal number
-in @acronym{ASCII} notation.
+part.  The @dfn{Number} type in this table stands for a decimal integer
+in @acronym{ASCII} notation.  (Negative values are preceeded with a "-"
+character, while positive values have no leading punctuation.)
 
-@multitable @columnfractions 0.2 0.2 0.6
+@multitable @columnfractions 0.25 0.15 0.6
 @headitem Field @tab Type @tab Description
 @item nfs @tab Character @tab @samp{1} if the directory is located on
 an @acronym{NFS}-mounted partition, or @samp{0} otherwise;
-@item mtime-sec @tab Number @tab Modification time, seconds;
-@item mtime-nano @tab Number @tab Modification time, nanoseconds;
-@item dev-no @tab Number @tab Device number;
-@item i-no @tab Number @tab I-node number;
+@item timestamp_sec @tab Number @tab Modification time, seconds;
+@item timestamp_nsec @tab Number @tab Modification time, nanoseconds;
+@item dev @tab Number @tab Device number;
+@item ino @tab Number @tab I-node number;
 @item name @tab String @tab Directory name; in contrast to the
 previous versions it is not quoted;
 @item contents @tab Dumpdir @tab Contents of the directory;
@@ -137,6 +137,28 @@ previous versions it is not quoted;
   Dumpdirs stored in snapshot files contain only records of types
 @samp{Y}, @samp{N} and @samp{D}.
 
+@cindex snapshot file field ranges
+@opindex show-snapshot-field-ranges
+The specific range of values allowed in each of the @dfn{Number} fields
+depends on the underlying C datatypes as determined when @command{tar}
+is compiled.  To see the specific ranges allowed for a particular
+@command{tar} binary, you can use the
+@option{--show-snapshot-field-ranges} option:
+
+@smallexample
+$ @kbd{tar --show-shapshot-field-ranges}
+This tar's snapshot file field ranges are
+   (field name      => [ min, max ]):
+
+    nfs             => [ 0, 1 ],
+    timestamp_sec   => [ -9223372036854775808, 9223372036854775807 ],
+    timestamp_nsec  => [ 0, 999999999 ],
+    dev             => [ 0, 18446744073709551615 ],
+    ino             => [ 0, 18446744073709551615 ],
+@end smallexample
+
+(This example is from a GNU/Linux x86_64 system.)
+
 @end enumerate
 
 @c End of snapshot.texi
index 26611745020b90f9006b88053993a80ea1359d7d..ddfa055e47e570a1c00956e3d9b3f71a62274351 100644 (file)
@@ -3251,7 +3251,7 @@ $ @kbd{tar --show-defaults}
 
 @noindent
 Notice, that this option outputs only one line.  The example output
-above has been split to fit page boundaries.
+above has been split to fit page boundaries. @xref{defaults}.
 
 @opsummary{show-omitted-dirs}
 @item --show-omitted-dirs
@@ -3259,6 +3259,13 @@ above has been split to fit page boundaries.
 Instructs @command{tar} to mention the directories it is skipping when
 operating on a @command{tar} archive.  @xref{show-omitted-dirs}.
 
+@opsummary{show-snapshot-field-ranges}
+@item --show-snapshot-field-ranges
+
+Displays the range of values allowed by this version of @command{tar}
+for each field in the snapshot file, then exits successfully.
+@xref{Snapshot Files}.
+
 @opsummary{show-transformed-names}
 @opsummary{show-stored-names}
 @item --show-transformed-names
index ccf27c33522307f177e763b15b4bffbfd4be6163..723ad9028748506468e4dd57c8036e89509a155b 100644 (file)
@@ -524,6 +524,7 @@ void rebase_directory (struct directory *dir,
                       const char *repl, size_t rlen);
 
 void append_incremental_renames (struct directory *dir);
+void show_snapshot_field_ranges (void);
 void read_directory_file (void);
 void write_directory_file (void);
 void purge_directory (char const *directory_name);
index 8aeefbeda86b403cb07399df6bdaba35d42ced6e..07e757adfa4f97a9313cceb9b4f31ea376d735bf 100644 (file)
@@ -1268,6 +1268,51 @@ read_incr_db_2 (void)
                _("Unexpected EOF in snapshot file")));
 }
 
+/* Display (to stdout) the range of allowed values for each field
+   in the snapshot file.  The array below should be kept in sync
+   with any changes made to the read_num() calls in the parsing
+   loop inside read_incr_db_2().
+
+   (This function is invoked via the --show-snapshot-field-ranges
+   command line option.) */
+
+struct field_range
+{
+  char const *fieldname;
+  intmax_t min_val;
+  uintmax_t max_val;
+};
+
+static struct field_range const field_ranges[] = {
+  { "nfs", 0, 1 },
+  { "timestamp_sec", TYPE_MINIMUM (time_t), TYPE_MAXIMUM (time_t) },
+  { "timestamp_nsec", 0, BILLION - 1 },
+  { "dev", TYPE_MINIMUM (dev_t), TYPE_MAXIMUM (dev_t) },
+  { "ino", TYPE_MINIMUM (ino_t), TYPE_MAXIMUM (ino_t) },
+  { NULL, 0, 0 }
+};
+
+void
+show_snapshot_field_ranges (void)
+{
+  struct field_range const *p;
+  char minbuf[max (SYSINT_BUFSIZE, INT_BUFSIZE_BOUND (intmax_t))];
+  char maxbuf[max (SYSINT_BUFSIZE, INT_BUFSIZE_BOUND (uintmax_t))];
+
+  printf("This tar's snapshot file field ranges are\n");
+  printf ("   (%-15s => [ %s, %s ]):\n\n", "field name", "min", "max");
+
+  for (p=field_ranges; p->fieldname != NULL; p++)
+    {
+      printf ("    %-15s => [ %s, %s ],\n", p->fieldname,
+             sysinttostr (p->min_val, p->min_val, p->max_val, minbuf),
+             sysinttostr (p->max_val, p->min_val, p->max_val, maxbuf));
+
+    }
+
+  printf("\n");
+}
+
 /* Read incremental snapshot file (directory file).
    If the file has older incremental version, make sure that it is processed
    correctly and that tar will use the most conservative backup method among
index 9d20fa0fa142bb40e66cde768dd8afcb38aadde4..5a4ed60ee6090d1529ad73fe38daf11ee3d1dd77 100644 (file)
--- a/src/tar.c
+++ b/src/tar.c
@@ -337,6 +337,7 @@ enum
   SELINUX_CONTEXT_OPTION,
   SHOW_DEFAULTS_OPTION,
   SHOW_OMITTED_DIRS_OPTION,
+  SHOW_SNAPSHOT_FIELD_RANGES_OPTION,
   SHOW_TRANSFORMED_NAMES_OPTION,
   SKIP_OLD_FILES_OPTION,
   SPARSE_VERSION_OPTION,
@@ -805,6 +806,8 @@ static struct argp_option options[] = {
   {"confirmation", 0, 0, OPTION_ALIAS, NULL, GRID+1 },
   {"show-defaults", SHOW_DEFAULTS_OPTION, 0, 0,
    N_("show tar defaults"), GRID+1 },
+  {"show-snapshot-field-ranges", SHOW_SNAPSHOT_FIELD_RANGES_OPTION, 0, 0,
+   N_("show valid ranges for snapshot-file fields"), GRID+1 },
   {"show-omitted-dirs", SHOW_OMITTED_DIRS_OPTION, 0, 0,
    N_("when listing or extracting, list each directory that does not match search criteria"), GRID+1 },
   {"show-transformed-names", SHOW_TRANSFORMED_NAMES_OPTION, 0, 0,
@@ -1949,6 +1952,11 @@ parse_opt (int key, char *arg, struct argp_state *state)
        exit (0);
       }
 
+    case SHOW_SNAPSHOT_FIELD_RANGES_OPTION:
+      show_snapshot_field_ranges ();
+      close_stdout ();
+      exit (0);
+
     case STRIP_COMPONENTS_OPTION:
       {
        uintmax_t u;
This page took 0.031681 seconds and 4 git commands to generate.