3 #=======================================================================
5 # File ID: 7046da86-f743-11dd-8d25-000475e441b9
6 # Creates loads of files in the current directory. Used for
7 # stresstesting file systems and stuff.
10 # ©opyleft 2004– Øyvind A. Holm <sunny@sunbase.org>
11 # License: GNU General Public License version 2 or later, see end of
12 # file for legal stuff.
13 #=======================================================================
18 use Time
::HiRes
qw{ gettimeofday
};
37 $progname =~ s/^.*\/(.*?)$/$1/;
38 our $VERSION = "0.00";
40 Getopt
::Long
::Configure
("bundling");
43 "char=s" => \
$Opt{'char'},
44 "count|c=i" => \
$Opt{'count'},
45 "debug" => \
$Opt{'debug'},
46 "extension|e=s" => \
$Opt{'extension'},
47 "help|h" => \
$Opt{'help'},
48 "verbose|v+" => \
$Opt{'verbose'},
49 "version" => \
$Opt{'version'},
51 ) || die("$progname: Option error. Use -h for help.\n");
53 $Opt{'debug'} && ($Debug = 1);
54 $Opt{'help'} && usage
(0);
55 if ($Opt{'version'}) {
60 $Opt{'count'} && $Opt{'count'}++;
65 die("$progname: No directory specified. Use \"$progname -h\" for help.\n");
68 my ($char_start, $char_end);
70 if (length($Opt{'char'})) {
71 my $Str = $Opt{'char'};
72 if ($Str =~ /^(\d+)-(\d+)$/) {
73 ($char_start, $char_end) = ($1, $2);
74 if ($char_start > 255 || $char_start > 255) {
75 die("$progname: Invalid character value in --char value, " .
76 "has to be in range 0-255.\n");
81 for my $Curr (@ARGV) {
82 D
("\$Curr = '$Curr'");
83 $Retval ||= fill_directory
($Curr);
84 D
("After fill_directory(i'$Curr')");
93 my $start_time = gettimeofday
;
94 my $total_created = 0;
97 D
("fill_directory(\"$Dir\")");
100 warn("$progname: $Dir: Cannot create directory: $!\n");
105 if (defined($char_start) && defined($char_end)) {
106 D
("char_start = '$char_start', char_end = '$char_end'");
107 for ($a = $char_start; $a <= $char_end; $a++) {
108 my $hex_val = sprintf("%02x", $a);
109 my $File = sprintf("%s/%s_%c%s", $Dir, ${hex_val
}, $a, $Opt{'extension'});
110 D
("a = '$a', File = '$File'");
111 unless (open(FP
, ">$File")) {
112 warn("$progname: $File: Cannot create file: $!\n");
119 for ($a = 1; $a != $Opt{'count'}; $a++) {
120 my $File = "$Dir/$a$Opt{'extension'}";
121 unless (open(FP
, ">$File")) {
122 warn("$0: $File: Cannot create file: $!");
129 my $end_time = gettimeofday
;
130 my $total_time = $end_time - $start_time;
133 printf("$Dir: Created %u file%s in %.6f second%s%s.\n",
135 $total_created == 1 ?
"" : "s",
137 $total_time == 1 ?
"" : "s",
139 ?
sprintf(", %.2f files/second on average",
140 $total_created / $total_time)
148 # Print program version {{{
149 print("$progname v$VERSION\n");
154 # Send the help message to stdout {{{
157 if ($Opt{'verbose'}) {
163 Usage: $progname [options] directory [directories [...]]
165 Creates loads of empty files in the specified directories. Used for file
166 system profiling and other interesting stuff.
171 Stop after x files are created.
173 Create files with filenames containing bytes in the area specified
176 Use x as extension of the created files.
180 Increase level of verbosity. Can be repeated.
182 Print version information.
184 Print debugging messages.
192 # Print a status message to stderr based on verbosity level {{{
193 my ($verbose_level, $Txt) = @_;
195 if ($Opt{'verbose'} >= $verbose_level) {
196 print(STDERR
"$progname: $Txt\n");
202 # Print a debugging message {{{
204 my @call_info = caller;
205 chomp(my $Txt = shift);
206 my $File = $call_info[1];
208 $File =~ s
#^.*/(.*?)$#$1#;
209 print(STDERR
"$File:$call_info[2] $$ $Txt\n");
216 # Plain Old Documentation (POD) {{{
226 [options] [file [files [...]]]
236 =item B<-h>, B<--help>
238 Print a brief help summary.
240 =item B<-v>, B<--verbose>
242 Increase level of verbosity. Can be repeated.
246 Print version information.
250 Print debugging messages.
260 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
264 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
265 This is free software; see the file F<COPYING> for legalese stuff.
269 This program is free software: you can redistribute it and/or modify it
270 under the terms of the GNU General Public License as published by the
271 Free Software Foundation, either version 2 of the License, or (at your
272 option) any later version.
274 This program is distributed in the hope that it will be useful, but
275 WITHOUT ANY WARRANTY; without even the implied warranty of
276 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
277 See the GNU General Public License for more details.
279 You should have received a copy of the GNU General Public License along
281 If not, see L<http://www.gnu.org/licenses/>.
289 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :