Import upstream version 1.29
[debian/tar] / doc / genfile.texi
1 @c This is part of the paxutils manual.
2 @c Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc.
3 @c Written by Sergey Poznyakoff
4 @c This file is distributed under GFDL 1.1 or any later version
5 @c published by the Free Software Foundation.
6
7 @cindex genfile
8     This appendix describes @command{genfile}, an auxiliary program
9 used in the GNU tar testsuite. If you are not interested in developing
10 GNU tar, skip this appendix.
11
12     Initially, @command{genfile} was used to generate data files for
13 the testsuite, hence its name. However, new operation modes were being
14 implemented as the testsuite grew more sophisticated, and now
15 @command{genfile} is a multi-purpose instrument.
16
17     There are three basic operation modes:
18
19 @table @asis
20 @item File Generation
21     This is the default mode. In this mode, @command{genfile}
22 generates data files.
23
24 @item File Status
25     In this mode @command{genfile} displays status of specified files.
26
27 @item Synchronous Execution.
28     In this mode @command{genfile} executes the given program with
29 @option{--checkpoint} option and executes a set of actions when
30 specified checkpoints are reached.
31 @end table
32
33 @menu
34 * Generate Mode::     File Generation Mode.
35 * Status Mode::       File Status Mode.
36 * Exec Mode::         Synchronous Execution mode.
37 @end menu
38
39 @node Generate Mode
40 @appendixsec Generate Mode
41
42 @cindex Generate Mode, @command{genfile}
43 @cindex @command{genfile}, generate mode
44 @cindex @command{genfile}, create file
45     In this mode @command{genfile} creates a data file for the test
46 suite. The size of the file is given with the @option{--length}
47 (@option{-l}) option. By default the file contents is written to the
48 standard output, this can be changed using @option{--file}
49 (@option{-f}) command line option. Thus, the following two commands
50 are equivalent:
51
52 @smallexample
53 @group
54 genfile --length 100 > outfile
55 genfile --length 100 --file outfile
56 @end group
57 @end smallexample
58
59     If @option{--length} is not given, @command{genfile} will
60 generate an empty (zero-length) file.
61
62 @cindex @command{genfile}, seeking to a given offset
63     The command line option @option{--seek=@var{N}} istructs @command{genfile}
64 to skip the given number of bytes (@var{N}) in the output file before
65 writing to it.  It is similar to the @option{seek=@var{N}} of the
66 @command{dd} utility.
67
68 @cindex @command{genfile}, reading a list of file names
69     You can instruct @command{genfile} to create several files at one
70 go, by giving it @option{--files-from} (@option{-T}) option followed
71 by a name of file containing a list of file names. Using dash
72 (@samp{-}) instead of the file name causes @command{genfile} to read
73 file list from the standard input. For example:
74
75 @smallexample
76 @group
77 # Read file names from file @file{file.list}
78 genfile --files-from file.list
79 # Read file names from standard input
80 genfile --files-from -
81 @end group
82 @end smallexample
83
84 @cindex File lists separated by NUL characters
85     The list file is supposed to contain one file name per line. To
86 use file lists separated by ASCII NUL character, use @option{--null}
87 (@option{-0}) command line option:
88
89 @smallexample
90 genfile --null --files-from file.list
91 @end smallexample
92
93 @cindex pattern, @command{genfile}
94     The default data pattern for filling the generated file consists
95 of first 256 letters of ASCII code, repeated enough times to fill the
96 entire file. This behavior can be changed with @option{--pattern}
97 option. This option takes a mandatory argument, specifying pattern
98 name to use. Currently two patterns are implemented:
99
100 @table @option
101 @item --pattern=default
102     The default pattern as described above.
103
104 @item --pattern=zero
105     Fills the file with zeroes.
106 @end table
107
108     If no file name was given, the program exits with the code
109 @code{0}.  Otherwise, it exits with @code{0} only if it was able to
110 create a file of the specified length.
111
112 @cindex Sparse files, creating using @command{genfile}
113 @cindex @command{genfile}, creating sparse files
114     Special option @option{--sparse} (@option{-s}) instructs
115 @command{genfile} to create a sparse file. Sparse files consist of
116 @dfn{data fragments}, separated by @dfn{holes} or blocks of zeros. On
117 many operating systems, actual disk storage is not allocated for
118 holes, but they are counted in the length of the file. To create a
119 sparse file, @command{genfile} should know where to put data fragments,
120 and what data to use to fill them. So, when @option{--sparse} is given
121 the rest of the command line specifies a so-called @dfn{file map}.
122
123     The file map consists of any number of @dfn{fragment
124 descriptors}. Each descriptor is composed of two values: a number,
125 specifying fragment offset from the end of the previous fragment or,
126 for the very first fragment, from the beginning of the file, and
127 @dfn{contents string}, that specifies the pattern to fill the fragment
128 with. File offset can be suffixed with the following quantifiers:
129
130 @table @samp
131 @item k
132 @itemx K
133 The number is expressed in kilobytes.
134 @item m
135 @itemx M
136 The number is expressed in megabytes.
137 @item g
138 @itemx G
139 The number is expressed in gigabytes.
140 @end table
141
142     Contents string can be either a fragment size or a pattern.
143 Fragment size is a decimal number, prefixed with an equals sign.  It
144 can be suffixed with a quantifier, as discussed above.  If fragment
145 size is given, the fragment of that size will be filled with the
146 currently selected pattern (@pxref{Generate Mode, --pattern}) and
147 written to the file.  
148
149     A pattern is a string of arbitrary ASCII characters.  For each
150 of them, @command{genfile} will generate a @dfn{block} of data,
151 filled with that character and will write it to the fragment. The size
152 of block is given by @option{--block-size} option. It defaults to 512.
153 Thus, if pattern consists of @var{n} characters, the resulting file
154 fragment will contain @code{@var{n}*@var{block-size}} bytes of data.
155
156     The last fragment descriptor can have only file offset part. In this
157 case @command{genfile} will create a hole at the end of the file up to
158 the given offset.
159
160     A dash appearing as a fragment descriptor instructs
161 @command{genfile} to read file map from the standard input.  Each line
162 of input should consist of fragment offset and contents string,
163 separated by any amount of whitespace.
164
165     For example, consider the following invocation:
166
167 @smallexample
168 genfile --sparse --file sparsefile 0 ABCD 1M EFGHI 2000K
169 @end smallexample
170
171 @noindent
172 It will create 3101184-bytes long file of the following structure:
173
174 @multitable @columnfractions .35 .20 .45
175 @item Offset  @tab Length       @tab Contents
176 @item 0       @tab 4*512=2048   @tab Four 512-byte blocks, filled with
177 letters @samp{A}, @samp{B}, @samp{C} and @samp{D}.
178 @item 2048    @tab 1046528      @tab Zero bytes
179 @item 1050624 @tab 5*512=2560   @tab Five blocks, filled with letters
180 @samp{E}, @samp{F}, @samp{G}, @samp{H}, @samp{I}.
181 @item 1053184  @tab 2048000     @tab Zero bytes
182 @end multitable
183
184 @cindex --quite, option
185     The exit code of @command{genfile --sparse} command is @code{0}
186 only if created file is actually sparse.  If it is not, the
187 appropriate error message is displayed and the command exists with
188 code @code{1}.  The @option{--quite} (@option{-q}) option suppresses
189 this behavior.  If @option{--quite} is given, @command{genfile
190 --sparse} exits with code @code{0} if it was able to create the file,
191 whether the resulting file is sparse or not.
192
193 @node Status Mode
194 @appendixsec Status Mode
195
196     In status mode, @command{genfile} prints file system status for
197 each file specified in the command line. This mode is toggled by
198 @option{--stat} (@option{-S}) command line option. An optional argument to this
199 option specifies output @dfn{format}: a comma-separated list of
200 @code{struct stat} fields to be displayed. This list can contain
201 following identifiers:
202
203 @table @asis
204 @item name
205     The file name.
206
207 @item dev
208 @itemx st_dev
209     Device number in decimal.
210
211 @item ino
212 @itemx st_ino
213     Inode number.
214
215 @item mode[.@var{number}]
216 @itemx st_mode[.@var{number}]
217
218 @FIXME{Should we also support @samp{%} notations as in stat(1)?}
219
220     File mode in octal.  Optional @var{number} specifies octal mask to
221 be applied to the mode before outputting.  For example, @code{--stat
222 mode.777} will preserve lower nine bits of it.  Notice, that you can
223 use any punctuation character in place of @samp{.}.
224
225 @item nlink
226 @itemx st_nlink
227     Number of hard links.
228
229 @item uid
230 @itemx st_uid
231     User ID of owner.
232
233 @item gid
234 @itemx st_gid
235     Group ID of owner.
236
237 @item size
238 @itemx st_size
239     File size in decimal.
240
241 @item blksize
242 @itemx st_blksize
243     The size in bytes of each file block.
244
245 @item blocks
246 @itemx st_blocks
247     Number of blocks allocated.
248
249 @item atime
250 @itemx st_atime
251     Time of last access.
252
253 @item mtime
254 @itemx st_mtime
255     Time of last modification
256
257 @item ctime
258 @itemx st_ctime
259     Time of last status change
260
261 @item sparse
262     A boolean value indicating whether the file is @samp{sparse}.
263 @end table
264
265     Modification times are displayed in @acronym{UTC} as
266 @acronym{UNIX} timestamps, unless suffixed with @samp{H} (for
267 ``human-readable''), as in @samp{ctimeH}, in which case usual
268 @code{tar tv} output format is used.
269
270     The default output format is: @samp{name,dev,ino,mode,
271 nlink,uid,gid,size,blksize,blocks,atime,mtime,ctime}.
272
273     For example, the following command will display file names and
274 corresponding times of last access for each file in the current working
275 directory:
276
277 @smallexample
278 genfile --stat=name,atime *
279 @end smallexample
280
281 @node Exec Mode
282 @appendixsec Exec Mode
283
284 @cindex Exec Mode, @command{genfile}
285     This mode is designed for testing the behavior of @code{paxutils}
286 commands when some of the files change during archiving. It is an
287 experimental mode.
288
289     The @samp{Exec Mode} is toggled by @option{--run} command line
290 option (or its alias @option{-r}). The non-optional arguments to
291 @command{getopt} give the command line to be executed. Normally,
292 it should contain at least the @option{--checkpoint} option.
293
294     A set of options is provided for defining checkpoint values and
295 actions to be executed upon reaching them. Checkpoint values are
296 introduced with the @option{--checkpoint} command line
297 option. Argument to this option is the number of checkpoint in decimal.
298
299     Any number of @dfn{actions} may be specified after a
300 checkpoint. Available actions are
301
302 @table @option
303 @item --cut @var{file}
304 @itemx --truncate @var{file}
305     Truncate @var{file} to the size specified by previous
306 @option{--length} option (or 0, if it is not given).
307
308 @item --append @var{file}
309     Append data to @var{file}. The size of data and its pattern are
310 given by previous @option{--length} and @option{pattern} options.
311
312 @item --touch @var{file}
313     Update the access and modification times of @var{file}. These
314 timestamps are changed to the current time, unless @option{--date}
315 option was given, in which case they are changed to the specified
316 time. Argument to @option{--date} option is a date specification in
317 an almost arbitrary format (@pxref{Date input formats}).
318
319 @item --exec @var{command}
320     Execute given shell command.
321
322 @item --unlink @var{file}
323     Unlink the @var{file}.
324 @end table
325
326     Option @option{--verbose} instructs @command{genfile} to print on
327 standard output notifications about checkpoints being executed and to
328 verbosely describe exit status of the command.
329
330     While the command is being executed its standard output remains
331 connected to descriptor 1. All messages it prints to file descriptor
332 2, except checkpoint notifications, are forwarded to standard
333 error.
334
335     @command{Genfile} exits with the exit status of the executed command.
336
337     For compatibility with previous @command{genfile} versions, the
338 @option{--run} option takes an optional argument. If used this way,
339 its argument supplies the command line to be executed. There should
340 be no non-optional arguments in the @command{genfile} command line.
341
342     The actual command line is constructed by inserting
343 the @option{--checkpoint} option between the command name and its
344 first argument (if any). Due to this, the argument to @option{--run}
345 may not use traditional @command{tar} option syntax, i.e., the
346 following is wrong:
347
348 @smallexample
349 # Wrong!
350 genfile --run='tar cf foo bar'
351 @end smallexample
352
353 @noindent
354
355 Use the following syntax instead:
356
357 @smallexample
358 genfile --run='tar -cf foo bar' @var{actions}...
359 @end smallexample
360
361 The above command line is equivalent to
362
363 @smallexample
364 genfile @var{actions}... -- tar -cf foo bar
365 @end smallexample
366
367 Notice, that the use of compatibility mode is deprecated.