[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

F.1 Generate Mode

In this mode genfile creates a data file for the test suite. The size of the file is given with the ‘--length’ (‘-l’) option. By default the file contents is written to the standard output, this can be changed using ‘--file’ (‘-f’) command line option. Thus, the following two commands are equivalent:

genfile --length 100 > outfile
genfile --length 100 --file outfile

If ‘--length’ is not given, genfile will generate an empty (zero-length) file.

The command line option ‘--seek=N’ istructs genfile to skip the given number of bytes (N) in the output file before writing to it. It is similar to the ‘seek=N’ of the dd utility.

You can instruct genfile to create several files at one go, by giving it ‘--files-from’ (‘-T’) option followed by a name of file containing a list of file names. Using dash (‘-’) instead of the file name causes genfile to read file list from the standard input. For example:

# Read file names from file ‘file.list’
genfile --files-from file.list
# Read file names from standard input
genfile --files-from -

The list file is supposed to contain one file name per line. To use file lists separated by ASCII NUL character, use ‘--null’ (‘-0’) command line option:

genfile --null --files-from file.list

The default data pattern for filling the generated file consists of first 256 letters of ASCII code, repeated enough times to fill the entire file. This behavior can be changed with ‘--pattern’ option. This option takes a mandatory argument, specifying pattern name to use. Currently two patterns are implemented:


The default pattern as described above.


Fills the file with zeroes.

If no file name was given, the program exits with the code 0. Otherwise, it exits with 0 only if it was able to create a file of the specified length.

Special option ‘--sparse’ (‘-s’) instructs genfile to create a sparse file. Sparse files consist of data fragments, separated by holes or blocks of zeros. On many operating systems, actual disk storage is not allocated for holes, but they are counted in the length of the file. To create a sparse file, genfile should know where to put data fragments, and what data to use to fill them. So, when ‘--sparse’ is given the rest of the command line specifies a so-called file map.

The file map consists of any number of fragment descriptors. Each descriptor is composed of two values: a number, specifying fragment offset from the end of the previous fragment or, for the very first fragment, from the beginning of the file, and contents string, that specifies the pattern to fill the fragment with. File offset can be suffixed with the following quantifiers:


The number is expressed in kilobytes.


The number is expressed in megabytes.


The number is expressed in gigabytes.

Contents string can be either a fragment size or a pattern. Fragment size is a decimal number, prefixed with an equals sign. It can be suffixed with a quantifier, as discussed above. If fragment size is given, the fragment of that size will be filled with the currently selected pattern (see section –pattern) and written to the file.

A pattern is a string of arbitrary ASCII characters. For each of them, genfile will generate a block of data, filled with that character and will write it to the fragment. The size of block is given by ‘--block-size’ option. It defaults to 512. Thus, if pattern consists of n characters, the resulting file fragment will contain n*block-size bytes of data.

The last fragment descriptor can have only file offset part. In this case genfile will create a hole at the end of the file up to the given offset.

A dash appearing as a fragment descriptor instructs genfile to read file map from the standard input. Each line of input should consist of fragment offset and contents string, separated by any amount of whitespace.

For example, consider the following invocation:

genfile --sparse --file sparsefile 0 ABCD 1M EFGHI 2000K

It will create 3101184-bytes long file of the following structure:

04*512=2048Four 512-byte blocks, filled with letters ‘A’, ‘B’, ‘C’ and ‘D’.
20481046528Zero bytes
10506245*512=2560Five blocks, filled with letters ‘E’, ‘F’, ‘G’, ‘H’, ‘I’.
10531842048000Zero bytes

The exit code of genfile --sparse command is 0 only if created file is actually sparse. If it is not, the appropriate error message is displayed and the command exists with code 1. The ‘--quite’ (‘-q’) option suppresses this behavior. If ‘--quite’ is given, genfile --sparse exits with code 0 if it was able to create the file, whether the resulting file is sparse or not.

[ << ] [ < ] [ Up ] [ > ] [ >> ]

This document was generated on August 23, 2023 using texi2html 5.0.