I/O with raw disk

D

dcruncher4

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.

Thanks.
 
A

anno4000

How can I open a raw disk file and write to it. I have to write a

"Raw disk" and "file" don't go together. A raw disk has blocks and/or
bytes but no files.
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.

That has nothing to do with Perl and everything with your OS. What is
your OS? You'd best ask that question on an OS-specific group.

Anno
 
B

Ben Morrow

Quoth (e-mail address removed):
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.

Do you mean read(2)/write(2) vs. fread(3)/fwrite(3)? read(2) and
write(2) are called sysread and syswrite in Perl. See their entries in
perlfunc. You can specify that all IO to a file should use these
syscalls directly by using the :unix PerlIO layer (yes, :unix on all
platforms currently): see PerlIO for a start.

If this is not what you mean you will have to clarify.

Ben
 
R

RedGrittyBrick

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".
 
J

Josef Moellers

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.

Depending on your OS, you could (on Linux systems) use the appropriate
/dev entries for the disks, but that, too, will send it through the
buffer cache and all you measure is file system overhead.
On 2.4 kernels, you could set up /dev/raw devices to get around the
buffer cache, on 2.6 kernels you'd need to open the device with O_DIRECT.

But, as Anno pointed out, it has not much to do with Perl.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top