浏览代码

Allow for size suffixes in -L and --record-size options.

* src/tar.c (TAR_SIZE_SUFFIXES): New define.
(parse_opt): Allow for size suffixes in arguments to
-L and --record-size options.
* NEWS, doc/tar.texi: Update.
Sergey Poznyakoff 14 年之前
父节点
当前提交
c1b30c268f
共有 3 个文件被更改,包括 66 次插入16 次删除
  1. 6 1
      NEWS
  2. 49 12
      doc/tar.texi
  3. 11 3
      src/tar.c

+ 6 - 1
NEWS

@@ -1,4 +1,4 @@
-GNU tar NEWS - User visible changes. 2010-03-28
+GNU tar NEWS - User visible changes. 2010-07-16
 Please send GNU tar bug reports to <[email protected]>
 Please send GNU tar bug reports to <[email protected]>
 
 
 
 
@@ -48,6 +48,11 @@ update of an archive:
 
 
 This did not work in previous versions, in spite of what the docs said.  
 This did not work in previous versions, in spite of what the docs said.  
 
 
+** --record-size and --tape-length (-L) options
+
+Usual size suffixes are allowed for these options.  For example,
+-L10k stands for a 10 kilobyte tape length. 
+
 ** Fix dead loop on extracting existing symlinks with the -k option.
 ** Fix dead loop on extracting existing symlinks with the -k option.
 
 
 
 

+ 49 - 12
doc/tar.texi

@@ -3153,10 +3153,13 @@ Specifies that @command{tar} should reblock its input, for reading
 from pipes on systems with buggy implementations.  @xref{Reading}.
 from pipes on systems with buggy implementations.  @xref{Reading}.
 
 
 @opsummary{record-size}
 @opsummary{record-size}
-@item --record-size=@var{size}
+@item --record-size=@var{size}[@var{suf}]
 
 
 Instructs @command{tar} to use @var{size} bytes per record when accessing the
 Instructs @command{tar} to use @var{size} bytes per record when accessing the
-archive.  @xref{Blocking Factor}.
+archive.  The argument can be suffixed with a @dfn{size suffix}, e.g.
+@option{--record-size=10K} for 10 Kilobytes.  @xref{size-suffixes},
+for a list of valid suffixes.   @xref{Blocking Factor}, for a detailed
+description of this option.
 
 
 @opsummary{recursion}
 @opsummary{recursion}
 @item --recursion
 @item --recursion
@@ -3306,11 +3309,15 @@ Alters the suffix @command{tar} uses when backing up files from the default
 @samp{~}.  @xref{backup}.
 @samp{~}.  @xref{backup}.
 
 
 @opsummary{tape-length}
 @opsummary{tape-length}
-@item --tape-length=@var{num}
-@itemx -L @var{num}
+@item --tape-length=@var{num}[@var{suf}]
+@itemx -L @var{num}[@var{suf}]
 
 
 Specifies the length of tapes that @command{tar} is writing as being
 Specifies the length of tapes that @command{tar} is writing as being
-@w{@var{num} x 1024} bytes long.  @xref{Using Multiple Tapes}.
+@w{@var{num} x 1024} bytes long.  If optional @var{suf} is given, it
+specifies a multiplicative factor to be used instead of 1024.  For
+example, @samp{-L2M} means 2 megabytes.  @xref{size-suffixes}, for a
+list of allowed suffixes.  @xref{Using Multiple Tapes}, for a detailed
+discussion of this option.
 
 
 @opsummary{test-label}
 @opsummary{test-label}
 @item --test-label
 @item --test-label
@@ -10345,8 +10352,27 @@ that may be larger than will fit on the medium used to hold it.
 
 
 @xopindex{tape-length, short description}
 @xopindex{tape-length, short description}
 @item -L @var{num}
 @item -L @var{num}
-@itemx --tape-length=@var{num}
-Change tape after writing @var{num} x 1024 bytes.
+@itemx --tape-length=@var{size}[@var{suf}]
+Change tape after writing @var{size} units of data.  Unless @var{suf} is
+given, @var{size} is treated as kilobytes, i.e. @samp{@var{size} x
+1024} bytes.  The following suffixes alter this behavior:
+
+@float Table, size-suffixes
+@caption{Size Suffixes}
+@multitable @columnfractions 0.2 0.3 0.3
+@headitem Suffix @tab Units            @tab Byte Equivalent
+@item b          @tab Blocks           @tab @var{size} x 512
+@item B          @tab Kilobytes        @tab @var{size} x 1024
+@item c          @tab Bytes            @tab @var{size}
+@item G          @tab Gigabytes        @tab @var{size} x 1024^3
+@item K          @tab Kilobytes        @tab @var{size} x 1024
+@item k          @tab Kilobytes        @tab @var{size} x 1024
+@item M          @tab Megabytes        @tab @var{size} x 1024^2
+@item P          @tab Petabytes        @tab @var{size} x 1024^5
+@item T          @tab Terabytes        @tab @var{size} x 1024^4
+@item w          @tab Words            @tab @var{size} x 2
+@end multitable
+@end float
 
 
 This option might be useful when your tape drivers do not properly
 This option might be useful when your tape drivers do not properly
 detect end of physical tapes.  By being slightly conservative on the
 detect end of physical tapes.  By being slightly conservative on the
@@ -11154,15 +11180,26 @@ tape:
 @anchor{tape-length}
 @anchor{tape-length}
 @table @option
 @table @option
 @opindex tape-length
 @opindex tape-length
-@item --tape-length=@var{size}
-@itemx -L @var{size}
-Set maximum length of a volume.  The @var{size} argument should then
-be the usable size of the tape in units of 1024 bytes.  This option
-selects @option{--multi-volume} automatically.  For example:
+@item --tape-length=@var{size}[@var{suf}]
+@itemx -L @var{size}[@var{suf}]
+Set maximum length of a volume.  The @var{suf}, if given, specifies
+units in which @var{size} is expressed, e.g. @samp{2M} mean 2
+megabytes (@pxref{size-suffixes}, for a list of allowed size
+suffixes).  Without @var{suf}, units of 1024 bytes (kilobyte) are
+assumed.
+
+This option selects @option{--multi-volume} automatically.  For example:
 
 
 @smallexample
 @smallexample
 $ @kbd{tar --create --tape-length=41943040 --file=/dev/tape @var{files}}
 $ @kbd{tar --create --tape-length=41943040 --file=/dev/tape @var{files}}
 @end smallexample
 @end smallexample
+
+@noindent
+or, which is equivalent:
+
+@smallexample
+$ @kbd{tar --create --tape-length=4G --file=/dev/tape @var{files}}
+@end smallexample
 @end table
 @end table
 
 
 @anchor{change volume prompt}
 @anchor{change volume prompt}

+ 11 - 3
src/tar.c

@@ -1364,6 +1364,8 @@ expand_pax_option (struct tar_args *targs, const char *arg)
 }
 }
 
 
 
 
+#define TAR_SIZE_SUFFIXES "bBcGgkKMmPTtw"
+
 static error_t
 static error_t
 parse_opt (int key, char *arg, struct argp_state *state)
 parse_opt (int key, char *arg, struct argp_state *state)
 {
 {
@@ -1506,10 +1508,15 @@ parse_opt (int key, char *arg, struct argp_state *state)
     case 'L':
     case 'L':
       {
       {
 	uintmax_t u;
 	uintmax_t u;
-	if (xstrtoumax (arg, 0, 10, &u, "") != LONGINT_OK)
+	char *p;
+	
+	if (xstrtoumax (arg, &p, 10, &u, TAR_SIZE_SUFFIXES) != LONGINT_OK)
 	  USAGE_ERROR ((0, 0, "%s: %s", quotearg_colon (arg),
 	  USAGE_ERROR ((0, 0, "%s: %s", quotearg_colon (arg),
 			_("Invalid tape length")));
 			_("Invalid tape length")));
-	tape_length_option = 1024 * (tarlong) u;
+	if (p > arg && !strchr (TAR_SIZE_SUFFIXES, p[-1]))
+	  tape_length_option = 1024 * (tarlong) u;
+	else
+	  tape_length_option = (tarlong) u;
 	multi_volume_option = true;
 	multi_volume_option = true;
       }
       }
       break;
       break;
@@ -1961,7 +1968,8 @@ parse_opt (int key, char *arg, struct argp_state *state)
     case RECORD_SIZE_OPTION:
     case RECORD_SIZE_OPTION:
       {
       {
 	uintmax_t u;
 	uintmax_t u;
-	if (! (xstrtoumax (arg, 0, 10, &u, "") == LONGINT_OK
+	
+	if (! (xstrtoumax (arg, NULL, 10, &u, TAR_SIZE_SUFFIXES) == LONGINT_OK
 	       && u == (size_t) u))
 	       && u == (size_t) u))
 	  USAGE_ERROR ((0, 0, "%s: %s", quotearg_colon (arg),
 	  USAGE_ERROR ((0, 0, "%s: %s", quotearg_colon (arg),
 			_("Invalid record size")));
 			_("Invalid record size")));