1 /* POSIX extended headers for tar.
3 Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by the
7 Free Software Foundation; either version 2, or (at your option) any later
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
13 Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
31 #if !HAVE_DECL_STRTOIMAX && !defined strtoimax
32 intmax_t strtoimax ();
34 #if !HAVE_DECL_STRTOUMAX && !defined strtoumax
35 uintmax_t strtoumax ();
38 static bool xheader_protected_pattern_p (char const *pattern
);
39 static bool xheader_protected_keyword_p (char const *keyword
);
40 static void xheader_set_single_keyword (char *) __attribute__ ((noreturn
));
42 /* Used by xheader_finish() */
43 static void code_string (char const *string
, char const *keyword
,
44 struct xheader
*xhdr
);
45 static void extended_header_init (void);
47 /* Number of global headers written so far. */
48 static size_t global_header_count
;
49 /* FIXME: Possibly it should be reset after changing the volume.
50 POSIX %n specification says that it is expanded to the sequence
51 number of current global header in *the* archive. However, for
52 multi-volume archives this will yield duplicate header names
53 in different volumes, which I'd like to avoid. The best way
54 to solve this would be to use per-archive header count as required
55 by POSIX *and* set globexthdr.name to, say,
56 $TMPDIR/GlobalHead.%p.$NUMVOLUME.%n.
58 However it should wait until buffer.c is finally rewritten */
60 enum { BILLION
= 1000000000, LOG10_BILLION
= 9 };
67 struct keyword_list
*next
;
73 /* List of keyword patterns set by delete= option */
74 static struct keyword_list
*keyword_pattern_list
;
76 /* List of keyword/value pairs set by `keyword=value' option */
77 static struct keyword_list
*keyword_global_override_list
;
79 /* List of keyword/value pairs set by `keyword:=value' option */
80 static struct keyword_list
*keyword_override_list
;
82 /* List of keyword/value pairs decoded from the last 'g' type header */
83 static struct keyword_list
*global_header_override_list
;
85 /* Template for the name field of an 'x' type header */
86 static char *exthdr_name
;
88 /* Template for the name field of a 'g' type header */
89 static char *globexthdr_name
;
92 xheader_keyword_deleted_p (const char *kw
)
94 struct keyword_list
*kp
;
96 for (kp
= keyword_pattern_list
; kp
; kp
= kp
->next
)
97 if (fnmatch (kp
->pattern
, kw
, 0) == 0)
103 xheader_keyword_override_p (const char *keyword
)
105 struct keyword_list
*kp
;
107 for (kp
= keyword_override_list
; kp
; kp
= kp
->next
)
108 if (strcmp (kp
->pattern
, keyword
) == 0)
114 xheader_list_append (struct keyword_list
**root
, char const *kw
,
117 struct keyword_list
*kp
= xmalloc (sizeof *kp
);
118 kp
->pattern
= xstrdup (kw
);
119 kp
->value
= value
? xstrdup (value
) : NULL
;
125 xheader_list_destroy (struct keyword_list
**root
)
129 struct keyword_list
*kw
= *root
;
132 struct keyword_list
*next
= kw
->next
;
143 xheader_set_single_keyword (char *kw
)
145 USAGE_ERROR ((0, 0, _("Keyword %s is unknown or not yet imlemented"), kw
));
149 xheader_set_keyword_equal (char *kw
, char *eq
)
160 while (p
> kw
&& isspace (*p
))
165 for (p
= eq
+ 1; *p
&& isspace (*p
); p
++)
168 if (strcmp (kw
, "delete") == 0)
170 if (xheader_protected_pattern_p (p
))
171 USAGE_ERROR ((0, 0, _("Pattern %s cannot be used"), quote (p
)));
172 xheader_list_append (&keyword_pattern_list
, p
, NULL
);
174 else if (strcmp (kw
, "exthdr.name") == 0)
175 assign_string (&exthdr_name
, p
);
176 else if (strcmp (kw
, "globexthdr.name") == 0)
177 assign_string (&globexthdr_name
, p
);
180 if (xheader_protected_keyword_p (kw
))
181 USAGE_ERROR ((0, 0, _("Keyword %s cannot be overridden"), kw
));
183 xheader_list_append (&keyword_global_override_list
, kw
, p
);
185 xheader_list_append (&keyword_override_list
, kw
, p
);
190 xheader_set_option (char *string
)
193 for (token
= strtok (string
, ","); token
; token
= strtok (NULL
, ","))
195 char *p
= strchr (token
, '=');
197 xheader_set_single_keyword (token
);
199 xheader_set_keyword_equal (token
, p
);
204 string Includes: Replaced By:
205 %d The directory name of the file,
206 equivalent to the result of the
207 dirname utility on the translated
209 %f The filename of the file, equivalent
210 to the result of the basename
211 utility on the translated file name.
212 %p The process ID of the pax process.
213 %% A '%' character. */
216 xheader_format_name (struct tar_stat_info
*st
, const char *fmt
, bool allow_n
)
219 size_t len
= strlen (fmt
);
224 char pidbuf
[UINTMAX_STRSIZE_BOUND
];
226 char nbuf
[UINTMAX_STRSIZE_BOUND
];
227 char const *nptr
= NULL
;
229 for (p
= fmt
; *p
&& (p
= strchr (p
, '%')); )
240 dir
= safer_name_suffix (dir_name (st
->orig_file_name
),
241 false, absolute_names_option
);
242 len
+= strlen (dir
) - 1;
249 base
= base_name (st
->orig_file_name
);
250 len
+= strlen (base
) - 1;
255 pptr
= umaxtostr (getpid (), pidbuf
);
256 len
+= pidbuf
+ sizeof pidbuf
- 1 - pptr
- 1;
262 nptr
= umaxtostr (global_header_count
+ 1, nbuf
);
263 len
+= nbuf
+ sizeof nbuf
- 1 - nptr
- 1;
270 buf
= xmalloc (len
+ 1);
271 for (q
= buf
, p
= fmt
; *p
; )
290 q
= stpcpy (q
, base
);
295 q
= stpcpy (q
, pptr
);
302 q
= stpcpy (q
, nptr
);
305 /* else fall through */
317 /* Do not allow it to end in a slash */
318 while (q
> buf
&& ISSLASH (q
[-1]))
325 xheader_xhdr_name (struct tar_stat_info
*st
)
328 assign_string (&exthdr_name
, "%d/PaxHeaders.%p/%f");
329 return xheader_format_name (st
, exthdr_name
, false);
332 #define GLOBAL_HEADER_TEMPLATE "/GlobalHead.%p.%n"
335 xheader_ghdr_name (void)
337 if (!globexthdr_name
)
340 const char *tmp
= getenv ("TMPDIR");
343 len
= strlen (tmp
) + sizeof (GLOBAL_HEADER_TEMPLATE
); /* Includes nul */
344 globexthdr_name
= xmalloc (len
);
345 strcpy(globexthdr_name
, tmp
);
346 strcat(globexthdr_name
, GLOBAL_HEADER_TEMPLATE
);
349 return xheader_format_name (NULL
, globexthdr_name
, true);
353 xheader_write (char type
, char *name
, struct xheader
*xhdr
)
360 header
= start_private_header (name
, size
);
361 header
->header
.typeflag
= type
;
363 simple_finish_header (header
);
371 header
= find_next_block ();
375 memcpy (header
->buffer
, p
, len
);
377 memset (header
->buffer
+ len
, 0, BLOCKSIZE
- len
);
380 set_next_block_after (header
);
383 xheader_destroy (xhdr
);
387 xheader_write_global (void)
390 struct keyword_list
*kp
;
392 if (!keyword_global_override_list
)
395 extended_header_init ();
396 for (kp
= keyword_global_override_list
; kp
; kp
= kp
->next
)
397 code_string (kp
->value
, kp
->pattern
, &extended_header
);
398 xheader_finish (&extended_header
);
399 xheader_write (XGLTYPE
, name
= xheader_ghdr_name (),
402 global_header_count
++;
406 /* General Interface */
411 void (*coder
) (struct tar_stat_info
const *, char const *,
412 struct xheader
*, void *data
);
413 void (*decoder
) (struct tar_stat_info
*, char const *);
417 /* This declaration must be extern, because ISO C99 section 6.9.2
418 prohibits a tentative definition that has both internal linkage and
419 incomplete type. If we made it static, we'd have to declare its
420 size which would be a maintenance pain; if we put its initializer
421 here, we'd need a boatload of forward declarations, which would be
422 even more of a pain. */
423 extern struct xhdr_tab
const xhdr_tab
[];
425 static struct xhdr_tab
const *
426 locate_handler (char const *keyword
)
428 struct xhdr_tab
const *p
;
430 for (p
= xhdr_tab
; p
->keyword
; p
++)
431 if (strcmp (p
->keyword
, keyword
) == 0)
437 xheader_protected_pattern_p (const char *pattern
)
439 struct xhdr_tab
const *p
;
441 for (p
= xhdr_tab
; p
->keyword
; p
++)
442 if (p
->protect
&& fnmatch (pattern
, p
->keyword
, 0) == 0)
448 xheader_protected_keyword_p (const char *keyword
)
450 struct xhdr_tab
const *p
;
452 for (p
= xhdr_tab
; p
->keyword
; p
++)
453 if (p
->protect
&& strcmp (p
->keyword
, keyword
) == 0)
458 /* Decode a single extended header record, advancing *PTR to the next record.
459 Return true on success, false otherwise. */
461 decode_record (char **ptr
,
462 void (*handler
) (void *, char const *, char const *),
467 unsigned long int len
;
471 size_t len_max
= extended_header
.buffer
+ extended_header
.size
- start
;
473 while (*p
== ' ' || *p
== '\t')
479 ERROR ((0, 0, _("Malformed extended header: missing length")));
484 len
= strtoul (p
, &len_lim
, 10);
488 int len_len
= len_lim
- p
;
489 ERROR ((0, 0, _("Extended header length %*s is out of range"),
496 for (p
= len_lim
; *p
== ' ' || *p
== '\t'; p
++)
501 _("Malformed extended header: missing blank after length")));
507 if (! (p
&& p
< nextp
))
509 ERROR ((0, 0, _("Malformed extended header: missing equal sign")));
513 if (nextp
[-1] != '\n')
515 ERROR ((0, 0, _("Malformed extended header: missing newline")));
519 *p
= nextp
[-1] = '\0';
520 handler (data
, keyword
, p
+ 1);
528 run_override_list (struct keyword_list
*kp
, struct tar_stat_info
*st
)
530 for (; kp
; kp
= kp
->next
)
532 struct xhdr_tab
const *t
= locate_handler (kp
->pattern
);
534 t
->decoder (st
, kp
->value
);
539 decx (void *data
, char const *keyword
, char const *value
)
541 struct xhdr_tab
const *t
;
542 struct tar_stat_info
*st
= data
;
544 if (xheader_keyword_deleted_p (keyword
)
545 || xheader_keyword_override_p (keyword
))
548 t
= locate_handler (keyword
);
550 t
->decoder (st
, value
);
554 xheader_decode (struct tar_stat_info
*st
)
556 run_override_list (keyword_global_override_list
, st
);
557 run_override_list (global_header_override_list
, st
);
559 if (extended_header
.size
)
561 char *p
= extended_header
.buffer
+ BLOCKSIZE
;
562 while (decode_record (&p
, decx
, st
))
565 run_override_list (keyword_override_list
, st
);
569 decg (void *data
, char const *keyword
, char const *value
)
571 struct keyword_list
**kwl
= data
;
572 xheader_list_append (kwl
, keyword
, value
);
576 xheader_decode_global (void)
578 if (extended_header
.size
)
580 char *p
= extended_header
.buffer
+ BLOCKSIZE
;
582 xheader_list_destroy (&global_header_override_list
);
583 while (decode_record (&p
, decg
, &global_header_override_list
))
589 extended_header_init (void)
591 if (!extended_header
.stk
)
593 extended_header
.stk
= xmalloc (sizeof *extended_header
.stk
);
594 obstack_init (extended_header
.stk
);
599 xheader_store (char const *keyword
, struct tar_stat_info
const *st
, void *data
)
601 struct xhdr_tab
const *t
;
603 if (extended_header
.buffer
)
605 t
= locate_handler (keyword
);
608 if (xheader_keyword_deleted_p (keyword
)
609 || xheader_keyword_override_p (keyword
))
611 extended_header_init ();
612 t
->coder (st
, keyword
, &extended_header
, data
);
616 xheader_read (union block
*p
, size_t size
)
621 free (extended_header
.buffer
);
623 extended_header
.size
= size
;
624 nblocks
= (size
+ BLOCKSIZE
- 1) / BLOCKSIZE
;
625 extended_header
.buffer
= xmalloc (size
+ 1);
626 extended_header
.buffer
[size
] = '\0';
635 memcpy (&extended_header
.buffer
[j
], p
->buffer
, len
);
636 set_next_block_after (p
);
638 p
= find_next_block ();
647 xheader_print (struct xheader
*xhdr
, char const *keyword
, char const *value
)
649 size_t len
= strlen (keyword
) + strlen (value
) + 3; /* ' ' + '=' + '\n' */
652 char nbuf
[UINTMAX_STRSIZE_BOUND
];
658 np
= umaxtostr (len
+ p
, nbuf
);
659 n
= nbuf
+ sizeof nbuf
- 1 - np
;
663 obstack_grow (xhdr
->stk
, np
, n
);
664 obstack_1grow (xhdr
->stk
, ' ');
665 obstack_grow (xhdr
->stk
, keyword
, strlen (keyword
));
666 obstack_1grow (xhdr
->stk
, '=');
667 obstack_grow (xhdr
->stk
, value
, strlen (value
));
668 obstack_1grow (xhdr
->stk
, '\n');
672 xheader_finish (struct xheader
*xhdr
)
674 struct keyword_list
*kp
;
676 for (kp
= keyword_override_list
; kp
; kp
= kp
->next
)
677 code_string (kp
->value
, kp
->pattern
, xhdr
);
679 obstack_1grow (xhdr
->stk
, 0);
680 xhdr
->buffer
= obstack_finish (xhdr
->stk
);
681 xhdr
->size
= strlen (xhdr
->buffer
);
685 xheader_destroy (struct xheader
*xhdr
)
689 obstack_free (xhdr
->stk
, NULL
);
700 /* Implementations */
703 out_of_range_header (char const *keyword
, char const *value
,
704 uintmax_t minus_minval
, uintmax_t maxval
)
706 char minval_buf
[UINTMAX_STRSIZE_BOUND
+ 1];
707 char maxval_buf
[UINTMAX_STRSIZE_BOUND
];
708 char *minval_string
= umaxtostr (minus_minval
, minval_buf
+ 1);
709 char *maxval_string
= umaxtostr (maxval
, maxval_buf
);
711 *--minval_string
= '-';
713 /* TRANSLATORS: The first %s is the pax extended header keyword
714 (atime, gid, etc.). */
715 ERROR ((0, 0, _("Extended header %s=%s is out of range %s..%s"),
716 keyword
, value
, minval_string
, maxval_string
));
720 code_string (char const *string
, char const *keyword
, struct xheader
*xhdr
)
723 if (!utf8_convert (true, string
, &outstr
))
725 /* FIXME: report error */
726 outstr
= xstrdup (string
);
728 xheader_print (xhdr
, keyword
, outstr
);
733 decode_string (char **string
, char const *arg
)
740 if (!utf8_convert (false, arg
, string
))
742 /* FIXME: report error and act accordingly to --pax invalid=UTF-8 */
743 assign_string (string
, arg
);
748 code_time (struct timespec t
, char const *keyword
, struct xheader
*xhdr
)
752 char sbuf
[1/*"-"*/ + UINTMAX_STRSIZE_BOUND
+ 1/*"."*/ + LOG10_BILLION
];
754 bool negative
= s
< 0;
756 if (negative
&& ns
!= 0)
762 np
= umaxtostr (negative
? - (uintmax_t) s
: (uintmax_t) s
, sbuf
+ 1);
765 code_ns_fraction (ns
, sbuf
+ UINTMAX_STRSIZE_BOUND
);
766 xheader_print (xhdr
, keyword
, np
);
770 decode_time (struct timespec
*ts
, char const *arg
, char const *keyword
)
773 unsigned long int ns
= 0;
776 bool negative
= *arg
== '-';
780 if (ISDIGIT (arg
[negative
]))
784 intmax_t i
= strtoimax (arg
, &arg_lim
, 10);
785 if (TYPE_SIGNED (time_t) ? i
< TYPE_MINIMUM (time_t) : i
< 0)
791 uintmax_t i
= strtoumax (arg
, &arg_lim
, 10);
792 if (TYPE_MAXIMUM (time_t) < i
)
805 bool trailing_nonzero
= false;
807 while (ISDIGIT (*++p
))
808 if (digits
< LOG10_BILLION
)
810 ns
= 10 * ns
+ (*p
- '0');
814 trailing_nonzero
|= *p
!= '0';
816 while (digits
++ < LOG10_BILLION
)
821 /* Convert "-1.10000000000001" to s == -2, ns == 89999999.
822 I.e., truncate time stamps towards minus infinity while
823 converting them to internal form. */
824 ns
+= trailing_nonzero
;
827 if (s
== TYPE_MINIMUM (time_t))
843 ERROR ((0, 0, _("Malformed extended header: invalid %s=%s"),
848 out_of_range_header (keyword
, arg
, - (uintmax_t) TYPE_MINIMUM (time_t),
849 TYPE_MAXIMUM (time_t));
854 code_num (uintmax_t value
, char const *keyword
, struct xheader
*xhdr
)
856 char sbuf
[UINTMAX_STRSIZE_BOUND
];
857 xheader_print (xhdr
, keyword
, umaxtostr (value
, sbuf
));
861 decode_num (uintmax_t *num
, char const *arg
, uintmax_t maxval
,
867 if (! (ISDIGIT (*arg
)
868 && (errno
= 0, u
= strtoumax (arg
, &arg_lim
, 10), !*arg_lim
)))
870 ERROR ((0, 0, _("Malformed extended header: invalid %s=%s"),
875 if (! (u
<= maxval
&& errno
!= ERANGE
))
877 out_of_range_header (keyword
, arg
, 0, maxval
);
886 dummy_coder (struct tar_stat_info
const *st
__attribute__ ((unused
)),
887 char const *keyword
__attribute__ ((unused
)),
888 struct xheader
*xhdr
__attribute__ ((unused
)),
889 void *data
__attribute__ ((unused
)))
894 dummy_decoder (struct tar_stat_info
*st
__attribute__ ((unused
)),
895 char const *arg
__attribute__ ((unused
)))
900 atime_coder (struct tar_stat_info
const *st
, char const *keyword
,
901 struct xheader
*xhdr
, void *data
__attribute__ ((unused
)))
903 code_time (get_stat_atime (&st
->stat
), keyword
, xhdr
);
907 atime_decoder (struct tar_stat_info
*st
, char const *arg
)
910 if (decode_time (&ts
, arg
, "atime"))
911 set_stat_atime (&st
->stat
, ts
);
915 gid_coder (struct tar_stat_info
const *st
, char const *keyword
,
916 struct xheader
*xhdr
, void *data
__attribute__ ((unused
)))
918 code_num (st
->stat
.st_gid
, keyword
, xhdr
);
922 gid_decoder (struct tar_stat_info
*st
, char const *arg
)
925 if (decode_num (&u
, arg
, TYPE_MAXIMUM (gid_t
), "gid"))
930 gname_coder (struct tar_stat_info
const *st
, char const *keyword
,
931 struct xheader
*xhdr
, void *data
__attribute__ ((unused
)))
933 code_string (st
->gname
, keyword
, xhdr
);
937 gname_decoder (struct tar_stat_info
*st
, char const *arg
)
939 decode_string (&st
->gname
, arg
);
943 linkpath_coder (struct tar_stat_info
const *st
, char const *keyword
,
944 struct xheader
*xhdr
, void *data
__attribute__ ((unused
)))
946 code_string (st
->link_name
, keyword
, xhdr
);
950 linkpath_decoder (struct tar_stat_info
*st
, char const *arg
)
952 decode_string (&st
->link_name
, arg
);
956 ctime_coder (struct tar_stat_info
const *st
, char const *keyword
,
957 struct xheader
*xhdr
, void *data
__attribute__ ((unused
)))
959 code_time (get_stat_ctime (&st
->stat
), keyword
, xhdr
);
963 ctime_decoder (struct tar_stat_info
*st
, char const *arg
)
966 if (decode_time (&ts
, arg
, "ctime"))
967 set_stat_ctime (&st
->stat
, ts
);
971 mtime_coder (struct tar_stat_info
const *st
, char const *keyword
,
972 struct xheader
*xhdr
, void *data
__attribute__ ((unused
)))
974 code_time (get_stat_mtime (&st
->stat
), keyword
, xhdr
);
978 mtime_decoder (struct tar_stat_info
*st
, char const *arg
)
981 if (decode_time (&ts
, arg
, "mtime"))
982 set_stat_mtime (&st
->stat
, ts
);
986 path_coder (struct tar_stat_info
const *st
, char const *keyword
,
987 struct xheader
*xhdr
, void *data
__attribute__ ((unused
)))
989 code_string (st
->file_name
, keyword
, xhdr
);
993 path_decoder (struct tar_stat_info
*st
, char const *arg
)
995 decode_string (&st
->orig_file_name
, arg
);
996 decode_string (&st
->file_name
, arg
);
997 st
->had_trailing_slash
= strip_trailing_slashes (st
->file_name
);
1001 size_coder (struct tar_stat_info
const *st
, char const *keyword
,
1002 struct xheader
*xhdr
, void *data
__attribute__ ((unused
)))
1004 code_num (st
->stat
.st_size
, keyword
, xhdr
);
1008 size_decoder (struct tar_stat_info
*st
, char const *arg
)
1011 if (decode_num (&u
, arg
, TYPE_MAXIMUM (off_t
), "size"))
1012 st
->stat
.st_size
= u
;
1016 uid_coder (struct tar_stat_info
const *st
, char const *keyword
,
1017 struct xheader
*xhdr
, void *data
__attribute__ ((unused
)))
1019 code_num (st
->stat
.st_uid
, keyword
, xhdr
);
1023 uid_decoder (struct tar_stat_info
*st
, char const *arg
)
1026 if (decode_num (&u
, arg
, TYPE_MAXIMUM (uid_t
), "uid"))
1027 st
->stat
.st_uid
= u
;
1031 uname_coder (struct tar_stat_info
const *st
, char const *keyword
,
1032 struct xheader
*xhdr
, void *data
__attribute__ ((unused
)))
1034 code_string (st
->uname
, keyword
, xhdr
);
1038 uname_decoder (struct tar_stat_info
*st
, char const *arg
)
1040 decode_string (&st
->uname
, arg
);
1044 sparse_size_coder (struct tar_stat_info
const *st
, char const *keyword
,
1045 struct xheader
*xhdr
, void *data
)
1047 size_coder (st
, keyword
, xhdr
, data
);
1051 sparse_size_decoder (struct tar_stat_info
*st
, char const *arg
)
1054 if (decode_num (&u
, arg
, TYPE_MAXIMUM (off_t
), "GNU.sparse.size"))
1055 st
->stat
.st_size
= u
;
1059 sparse_numblocks_coder (struct tar_stat_info
const *st
, char const *keyword
,
1060 struct xheader
*xhdr
,
1061 void *data
__attribute__ ((unused
)))
1063 code_num (st
->sparse_map_avail
, keyword
, xhdr
);
1067 sparse_numblocks_decoder (struct tar_stat_info
*st
, char const *arg
)
1070 if (decode_num (&u
, arg
, SIZE_MAX
, "GNU.sparse.numblocks"))
1072 st
->sparse_map_size
= u
;
1073 st
->sparse_map
= xcalloc (u
, sizeof st
->sparse_map
[0]);
1074 st
->sparse_map_avail
= 0;
1079 sparse_offset_coder (struct tar_stat_info
const *st
, char const *keyword
,
1080 struct xheader
*xhdr
, void *data
)
1083 code_num (st
->sparse_map
[*pi
].offset
, keyword
, xhdr
);
1087 sparse_offset_decoder (struct tar_stat_info
*st
, char const *arg
)
1090 if (decode_num (&u
, arg
, TYPE_MAXIMUM (off_t
), "GNU.sparse.offset"))
1092 if (st
->sparse_map_avail
< st
->sparse_map_size
)
1093 st
->sparse_map
[st
->sparse_map_avail
].offset
= u
;
1095 ERROR ((0, 0, _("Malformed extended header: excess %s=%s"),
1096 "GNU.sparse.offset", arg
));
1101 sparse_numbytes_coder (struct tar_stat_info
const *st
, char const *keyword
,
1102 struct xheader
*xhdr
, void *data
)
1105 code_num (st
->sparse_map
[*pi
].numbytes
, keyword
, xhdr
);
1109 sparse_numbytes_decoder (struct tar_stat_info
*st
, char const *arg
)
1112 if (decode_num (&u
, arg
, SIZE_MAX
, "GNU.sparse.numbytes"))
1114 if (st
->sparse_map_avail
< st
->sparse_map_size
)
1115 st
->sparse_map
[st
->sparse_map_avail
++].numbytes
= u
;
1117 ERROR ((0, 0, _("Malformed extended header: excess %s=%s"),
1118 "GNU.sparse.numbytes", arg
));
1122 struct xhdr_tab
const xhdr_tab
[] = {
1123 { "atime", atime_coder
, atime_decoder
, false },
1124 { "comment", dummy_coder
, dummy_decoder
, false },
1125 { "charset", dummy_coder
, dummy_decoder
, false },
1126 { "ctime", ctime_coder
, ctime_decoder
, false },
1127 { "gid", gid_coder
, gid_decoder
, false },
1128 { "gname", gname_coder
, gname_decoder
, false },
1129 { "linkpath", linkpath_coder
, linkpath_decoder
, false },
1130 { "mtime", mtime_coder
, mtime_decoder
, false },
1131 { "path", path_coder
, path_decoder
, false },
1132 { "size", size_coder
, size_decoder
, false },
1133 { "uid", uid_coder
, uid_decoder
, false },
1134 { "uname", uname_coder
, uname_decoder
, false },
1136 /* Sparse file handling */
1137 { "GNU.sparse.size", sparse_size_coder
, sparse_size_decoder
, true },
1138 { "GNU.sparse.numblocks", sparse_numblocks_coder
, sparse_numblocks_decoder
,
1140 { "GNU.sparse.offset", sparse_offset_coder
, sparse_offset_decoder
,
1142 { "GNU.sparse.numbytes", sparse_numbytes_coder
, sparse_numbytes_decoder
,
1145 #if 0 /* GNU private keywords (not yet implemented) */
1147 /* The next directory entry actually contains the names of files
1148 that were in the directory at the time the dump was made.
1149 Supersedes GNUTYPE_DUMPDIR header type. */
1150 { "GNU.dump.name", dump_name_coder
, dump_name_decoder
, false },
1151 { "GNU.dump.status", dump_status_coder
, dump_status_decoder
, false },
1153 /* Keeps the tape/volume header. May be present only in the global headers.
1154 Equivalent to GNUTYPE_VOLHDR. */
1155 { "GNU.volume.header", volume_header_coder
, volume_header_decoder
, false },
1157 /* These may be present in a first global header of the archive.
1158 They provide the same functionality as GNUTYPE_MULTIVOL header.
1159 The GNU.volume.size keeps the real_s_sizeleft value, which is
1160 otherwise kept in the size field of a multivolume header. The
1161 GNU.volume.offset keeps the offset of the start of this volume,
1162 otherwise kept in oldgnu_header.offset. */
1163 { "GNU.volume.size", volume_size_coder
, volume_size_decoder
, false },
1164 { "GNU.volume.offset", volume_offset_coder
, volume_offset_decoder
, false },
1167 { NULL
, NULL
, NULL
, false }