How can I open a raw disk file and write to it. I have to write a
program which will
write few gigs of data to both raw disk and a cooked file to compare
the write
performance.
Which functions to use for that.
Can't you use the usual functions for both? At least on Unix like systems.
Untested ...
----------------------------------8<---------------------------------
#!perl
use strict;
use warnings;
my $rawdisk = '/dev/hdb2';
my $cookedfile = '/tmp/foo';
write_gigabytes($rawdisk);
write_gigabytes($cookedfile);
sub write_gigabytes {
my $targetname = shift;
my $start=time;
open my $fh, '>', $targetname
or die "Unable to open '$targetname' for writing because $!\n";
print $fh 'a few gigs of data'
or die "Unable to write to '$targetname' because $!\n";
close $fh
or die "Unable to close '$targetname' because $!\n";
print "writing a few gigs of data to '$targetname' took ",
time-$start, "s.\n";
}
----------------------------------8<---------------------------------
Even assuming the above is remotely like a functional perl program, I
have doubts that this sort of exercise will measure anything useful.
P.S. the point of the above is not to identify I/O operations suited to
the OP's real problem domain but to illustrate that on some platforms
the O/S presents a fairly consistent file-like interface for all sorts
of odd things. I can't remember if /dev/hdb2 is likely to be character
mode or block mode, or whether either case would prevent the above
program from "working".