e0f4e351516170c2fed509af4d880a9d077a0ffd
[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}, i.e., a string of characters, specifying the
128 pattern to fill the fragment with. File offset can be suffixed with
129 the following quantifiers:
130
131 @table @samp
132 @item k
133 @itemx K
134 The number is expressed in kilobytes.
135 @item m
136 @itemx M
137 The number is expressed in megabytes.
138 @item g
139 @itemx G
140 The number is expressed in gigabytes.
141 @end table
142
143     For each letter in contents string @command{genfile} will generate
144 a @dfn{block} of data, filled with this letter and will write it to
145 the fragment. The size of block is given by @option{--block-size}
146 option. It defaults to 512. Thus, if the string consists of @var{n}
147 characters, the resulting file fragment will contain
148 @code{@var{n}*@var{block-size}} of data.
149
150     Last fragment descriptor can have only file offset part. In this
151 case @command{genfile} will create a hole at the end of the file up to
152 the given offset.
153
154     For example, consider the following invocation:
155
156 @smallexample
157 genfile --sparse --file sparsefile 0 ABCD 1M EFGHI 2000K
158 @end smallexample
159
160 @noindent
161 It will create 3101184-bytes long file of the following structure:
162
163 @multitable @columnfractions .35 .20 .45
164 @item Offset  @tab Length       @tab Contents
165 @item 0       @tab 4*512=2048   @tab Four 512-byte blocks, filled with
166 letters @samp{A}, @samp{B}, @samp{C} and @samp{D}.
167 @item 2048    @tab 1046528      @tab Zero bytes
168 @item 1050624 @tab 5*512=2560   @tab Five blocks, filled with letters
169 @samp{E}, @samp{F}, @samp{G}, @samp{H}, @samp{I}.
170 @item 1053184  @tab 2048000     @tab Zero bytes
171 @end multitable
172
173     The exit code of @command{genfile --status} command is @code{0}
174 only if created file is actually sparse.
175
176 @node Status Mode
177 @appendixsec Status Mode
178
179     In status mode, @command{genfile} prints file system status for
180 each file specified in the command line. This mode is toggled by
181 @option{--stat} (@option{-S}) command line option. An optional argument to this
182 option specifies output @dfn{format}: a comma-separated list of
183 @code{struct stat} fields to be displayed. This list can contain
184 following identifiers:
185
186 @table @asis
187 @item name
188     The file name.
189
190 @item dev
191 @itemx st_dev
192     Device number in decimal.
193
194 @item ino
195 @itemx st_ino
196     Inode number.
197
198 @item mode[.@var{number}]
199 @itemx st_mode[.@var{number}]
200
201 @FIXME{Should we also support @samp{%} notations as in stat(1)?}
202
203     File mode in octal.  Optional @var{number} specifies octal mask to
204 be applied to the mode before outputting.  For example, @code{--stat
205 mode.777} will preserve lower nine bits of it.  Notice, that you can
206 use any punctuation character in place of @samp{.}.
207
208 @item nlink
209 @itemx st_nlink
210     Number of hard links.
211
212 @item uid
213 @itemx st_uid
214     User ID of owner.
215
216 @item gid
217 @itemx st_gid
218     Group ID of owner.
219
220 @item size
221 @itemx st_size
222     File size in decimal.
223
224 @item blksize
225 @itemx st_blksize
226     The size in bytes of each file block.
227
228 @item blocks
229 @itemx st_blocks
230     Number of blocks allocated.
231
232 @item atime
233 @itemx st_atime
234     Time of last access.
235
236 @item mtime
237 @itemx st_mtime
238     Time of last modification
239
240 @item ctime
241 @itemx st_ctime
242     Time of last status change
243
244 @item sparse
245     A boolean value indicating whether the file is @samp{sparse}.
246 @end table
247
248     Modification times are displayed in @acronym{UTC} as
249 @acronym{UNIX} timestamps, unless suffixed with @samp{H} (for
250 ``human-readable''), as in @samp{ctimeH}, in which case usual
251 @code{tar tv} output format is used.
252
253     The default output format is: @samp{name,dev,ino,mode,
254 nlink,uid,gid,size,blksize,blocks,atime,mtime,ctime}.
255
256     For example, the following command will display file names and
257 corresponding times of last access for each file in the current working
258 directory:
259
260 @smallexample
261 genfile --stat=name,atime *
262 @end smallexample
263
264 @node Exec Mode
265 @appendixsec Exec Mode
266
267 @cindex Exec Mode, @command{genfile}
268     This mode is designed for testing the behavior of @code{paxutils}
269 commands when some of the files change during archiving. It is an
270 experimental mode.
271
272     The @samp{Exec Mode} is toggled by @option{--run} command line
273 option (or its alias @option{-r}). The non-optional arguments to
274 @command{getopt} give the command line to be executed. Normally,
275 it should contain at least the @option{--checkpoint} option.
276
277     A set of options is provided for defining checkpoint values and
278 actions to be executed upon reaching them. Checkpoint values are
279 introduced with the @option{--checkpoint} command line
280 option. Argument to this option is the number of checkpoint in decimal.
281
282     Any number of @dfn{actions} may be specified after a
283 checkpoint. Available actions are
284
285 @table @option
286 @item --cut @var{file}
287 @itemx --truncate @var{file}
288     Truncate @var{file} to the size specified by previous
289 @option{--length} option (or 0, if it is not given).
290
291 @item --append @var{file}
292     Append data to @var{file}. The size of data and its pattern are
293 given by previous @option{--length} and @option{pattern} options.
294
295 @item --touch @var{file}
296     Update the access and modification times of @var{file}. These
297 timestamps are changed to the current time, unless @option{--date}
298 option was given, in which case they are changed to the specified
299 time. Argument to @option{--date} option is a date specification in
300 an almost arbitrary format (@pxref{Date input formats}).
301
302 @item --exec @var{command}
303     Execute given shell command.
304
305 @item --unlink @var{file}
306     Unlink the @var{file}.
307 @end table
308
309     Option @option{--verbose} instructs @command{genfile} to print on
310 standard output notifications about checkpoints being executed and to
311 verbosely describe exit status of the command.
312
313     While the command is being executed its standard output remains
314 connected to descriptor 1. All messages it prints to file descriptor
315 2, except checkpoint notifications, are forwarded to standard
316 error.
317
318     @command{Genfile} exits with the exit status of the executed command.
319
320     For compatibility with previous @command{genfile} versions, the
321 @option{--run} option takes an optional argument. If used this way,
322 its argument supplies the command line to be executed. There should
323 be no non-optional arguments in the @command{genfile} command line.
324
325     The actual command line is constructed by inserting
326 the @option{--checkpoint} option between the command name and its
327 first argument (if any). Due to this, the argument to @option{--run}
328 may not use traditional @command{tar} option syntax, i.e., the
329 following is wrong:
330
331 @smallexample
332 # Wrong!
333 genfile --run='tar cf foo bar'
334 @end smallexample
335
336 @noindent
337
338 Use the following syntax instead:
339
340 @smallexample
341 genfile --run='tar -cf foo bar' @var{actions}...
342 @end smallexample
343
344 The above command line is equivalent to
345
346 @smallexample
347 genfile @var{actions}... -- tar -cf foo bar
348 @end smallexample
349
350 Notice, that the use of compatibility mode is deprecated.