void write_directory_file (void) { FILE *fp = listed_incremental_stream; char buf[UINTMAX_STRSIZE_BOUND]; char *s; if (! fp) return; if (fseeko (fp, 0L, SEEK_SET) != 0) seek_error (listed_incremental_option); if (sys_truncate (fileno (fp)) != 0) truncate_error (listed_incremental_option); fprintf (fp, "%s-%s-%d\n", PACKAGE_NAME, PACKAGE_VERSION, TAR_INCREMENTAL_VERSION); s = (TYPE_SIGNED (time_t) ? imaxtostr (start_time.tv_sec, buf) : umaxtostr (start_time.tv_sec, buf)); fwrite (s, strlen (s) + 1, 1, fp); s = umaxtostr (start_time.tv_nsec, buf); fwrite (s, strlen (s) + 1, 1, fp); if (! ferror (fp) && directory_table) hash_do_for_each (directory_table, write_directory_file_entry, fp); if (ferror (fp)) write_error (listed_incremental_option); if (fclose (fp) != 0) close_error (listed_incremental_option); }
static int mpz_out_str (FILE *stream, int base, mpz_t z) { char buf[INT_BUFSIZE_BOUND (intmax_t)]; (void) base; return fputs (imaxtostr (z[0], buf), stream) != EOF; }
static char * mpz_get_str (char const *str, int base, mpz_t z) { char buf[INT_BUFSIZE_BOUND (intmax_t)]; (void) str; (void) base; return xstrdup (imaxtostr (z[0], buf)); }
extern char * uid_to_name (uid_t uid) { char buf[INT_BUFSIZE_BOUND (intmax_t)]; struct passwd *pwd = getpwuid (uid); return xstrdup (pwd ? pwd->pw_name : TYPE_SIGNED (uid_t) ? imaxtostr (uid, buf) : umaxtostr (uid, buf)); }
extern char * gid_to_name (gid_t gid) { char buf[INT_BUFSIZE_BOUND (intmax_t)]; struct group *grp = getgrgid (gid); return xstrdup (grp ? grp->gr_name : TYPE_SIGNED (gid_t) ? imaxtostr (gid, buf) : umaxtostr (gid, buf)); }
char * sysinttostr (uintmax_t value, intmax_t minval, uintmax_t maxval, char buf[SYSINT_BUFSIZE]) { if (value <= maxval) return umaxtostr (value, buf); else { intmax_t i = value - minval; return imaxtostr (i + minval, buf); } }
static void out_of_range_header (char const *keyword, char const *value, intmax_t minval, uintmax_t maxval) { char minval_buf[INT_BUFSIZE_BOUND (intmax_t)]; char maxval_buf[UINTMAX_STRSIZE_BOUND]; char *minval_string = imaxtostr (minval, minval_buf); char *maxval_string = umaxtostr (maxval, maxval_buf); /* TRANSLATORS: The first %s is the pax extended header keyword (atime, gid, etc.). */ ERROR ((0, 0, _("Extended header %s=%s is out of range %s..%s"), keyword, value, minval_string, maxval_string)); }
/* Output incremental data for the directory ENTRY to the file DATA. Return nonzero if successful, preserving errno on write failure. */ static bool write_directory_file_entry (void *entry, void *data) { struct directory const *directory = entry; FILE *fp = data; if (DIR_IS_FOUND (directory)) { char buf[SYSINT_BUFSIZE]; char const *s; s = DIR_IS_NFS (directory) ? "1" : "0"; fwrite (s, 2, 1, fp); s = sysinttostr (directory->mtime.tv_sec, TYPE_MINIMUM (time_t), TYPE_MAXIMUM (time_t), buf); fwrite (s, strlen (s) + 1, 1, fp); s = imaxtostr (directory->mtime.tv_nsec, buf); fwrite (s, strlen (s) + 1, 1, fp); s = sysinttostr (directory->device_number, TYPE_MINIMUM (dev_t), TYPE_MAXIMUM (dev_t), buf); fwrite (s, strlen (s) + 1, 1, fp); s = sysinttostr (directory->inode_number, TYPE_MINIMUM (ino_t), TYPE_MAXIMUM (ino_t), buf); fwrite (s, strlen (s) + 1, 1, fp); fwrite (directory->name, strlen (directory->name) + 1, 1, fp); if (directory->dump) { const char *p; struct dumpdir_iter *itr; for (p = dumpdir_first (directory->dump, 0, &itr); p; p = dumpdir_next (itr)) fwrite (p, strlen (p) + 1, 1, fp); free (itr); } fwrite ("\0\0", 2, 1, fp); } return ! ferror (fp); }
/* Output incremental data for the directory ENTRY to the file DATA. Return nonzero if successful, preserving errno on write failure. */ static bool write_directory_file_entry (void *entry, void *data) { struct directory const *directory = entry; FILE *fp = data; if (DIR_IS_FOUND (directory)) { char buf[UINTMAX_STRSIZE_BOUND]; char *s; s = DIR_IS_NFS (directory) ? "1" : "0"; fwrite (s, 2, 1, fp); s = (TYPE_SIGNED (time_t) ? imaxtostr (directory->mtime.tv_sec, buf) : umaxtostr (directory->mtime.tv_sec, buf)); fwrite (s, strlen (s) + 1, 1, fp); s = umaxtostr (directory->mtime.tv_nsec, buf); fwrite (s, strlen (s) + 1, 1, fp); s = umaxtostr (directory->device_number, buf); fwrite (s, strlen (s) + 1, 1, fp); s = umaxtostr (directory->inode_number, buf); fwrite (s, strlen (s) + 1, 1, fp); fwrite (directory->name, strlen (directory->name) + 1, 1, fp); if (directory->dump) { const char *p; dumpdir_iter_t itr; for (p = dumpdir_first (directory->dump, 0, &itr); p; p = dumpdir_next (itr)) fwrite (p, strlen (p) + 1, 1, fp); free (itr); } fwrite ("\0\0", 2, 1, fp); } return ! ferror (fp); }
static bool read_num (FILE *fp, char const *fieldname, intmax_t min_val, uintmax_t max_val, intmax_t *pval) { int i; char buf[INT_BUFSIZE_BOUND (intmax_t)]; char offbuf[INT_BUFSIZE_BOUND (off_t)]; char minbuf[INT_BUFSIZE_BOUND (intmax_t)]; char maxbuf[INT_BUFSIZE_BOUND (intmax_t)]; int conversion_errno; int c = getc (fp); bool negative = c == '-'; for (i = 0; (i == 0 && negative) || ISDIGIT (c); i++) { buf[i] = c; if (i == sizeof buf - 1) FATAL_ERROR ((0, 0, _("%s: byte %s: %s %.*s... too long"), quotearg_colon (listed_incremental_option), offtostr (ftello (fp), offbuf), fieldname, i + 1, buf)); c = getc (fp); } buf[i] = 0; if (c < 0) { if (ferror (fp)) read_fatal (listed_incremental_option); if (i != 0) FATAL_ERROR ((0, 0, "%s: %s", quotearg_colon (listed_incremental_option), _("Unexpected EOF in snapshot file"))); return false; } if (c) { unsigned uc = c; FATAL_ERROR ((0, 0, _("%s: byte %s: %s %s followed by invalid byte 0x%02x"), quotearg_colon (listed_incremental_option), offtostr (ftello (fp), offbuf), fieldname, buf, uc)); } *pval = strtosysint (buf, NULL, min_val, max_val); conversion_errno = errno; switch (conversion_errno) { case ERANGE: FATAL_ERROR ((0, conversion_errno, _("%s: byte %s: (valid range %s..%s)\n\t%s %s"), quotearg_colon (listed_incremental_option), offtostr (ftello (fp), offbuf), imaxtostr (min_val, minbuf), umaxtostr (max_val, maxbuf), fieldname, buf)); default: FATAL_ERROR ((0, conversion_errno, _("%s: byte %s: %s %s"), quotearg_colon (listed_incremental_option), offtostr (ftello (fp), offbuf), fieldname, buf)); case 0: break; } return true; }