genfile.texi 10 KB

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