Implement the --show-snapshot-field-ranges option

* 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.
This commit is contained in:
Nathan Stratton Treadway
2013-09-15 16:02:30 +03:00
committed by Sergey Poznyakoff
parent 738fb9c2f4
commit 751b61ab25
5 changed files with 93 additions and 10 deletions
+1
View 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);
+45
View 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
+8
View File
@@ -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;