Re: Newbie Query about raw devices
phil-news-nospam_at_ipal.net
Date: 03/29/05
- Next message: Bryan Batten: "Re: how to write() a double"
- Previous message: xxx_at_hotmail.com: "Re: how to write() a double"
- In reply to: Draw: "Newbie Query about raw devices"
- Next in thread: Peter T. Breuer: "Re: Newbie Query about raw devices"
- Reply: Peter T. Breuer: "Re: Newbie Query about raw devices"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 29 Mar 2005 00:22:37 GMT
In comp.os.linux.development.system Draw <drawoh@rediffmail.com> wrote:
| I have been trying to write a program to write to a block device,
| basically my SCSI disks. I am able to do it fine by directly using the
| block device "/dev/sdb", but I read this will involve the kernel's
| buffer cache, so I decided that I should write to the device raw(avoid
| buffering). So I used a different program, binding my /dev/raw/raw1 to
| the block device where I wanted to write and all that, but I seem not
| able to read or write, I allocated a page aligned buffer then wrote
| the buffer to the raw device and then tried to read it back from the
| device only to find that the data was not written, but I am confused,
| the write should have returned an error in that case, but it didn't(or
| is read the culprit? but then it didn't report an error either). So
| just to make sure I am doing everything right, I looked at the manpage
| of 'raw'(a little more carefully). This is what I found in the bugs
| section:
open("/dev/sdb",O_WRONLY|O_DIRECT);
| *********START
| Raw I/O devices do not maintain cache coherency with the Linux block
| device buffer cache. If you use raw I/O to overwrite data already in
| the buffer cache, the buffer cache will no longer correspond to the
| contents of the actual storage device underneath. This is deliberate,
| but is regarded either a bug or a feature depending on who you ask!
| *********END
| Does this mean that even when I am using the raw interface, I am still
| writing through the buffer cache? This is what I wanted to avoid.
Based on the wording, it sounds like subsequent reads will get the old
data still in the buffer cache. The raw device should pass around the
buffer cache, going directly from process VM while still in RAM to the
actual device.
I'd hope something would at least invalidate the cached copy so that any
subsequent read will force reading back from the device.
| BTW, are there any sample programs that demonstrate raw IO on Linux
| floating around in cyberspace? Would really appreciate it anyone could
| point me to a working sample. If you wanna look at what my program
| does, I have posted it on these very groups a few hours ago, and they
| are visible right now(author 'Draw').
I have something I wrote years ago called "syncwrite". It used O_SYNC.
I'm going to be making an O_DIRECT version of it, eventually.
-- ----------------------------------------------------------------------------- | Phil Howard KA9WGN | http://linuxhomepage.com/ http://ham.org/ | | (first name) at ipal.net | http://phil.ipal.org/ http://ka9wgn.ham.org/ | -----------------------------------------------------------------------------
- Next message: Bryan Batten: "Re: how to write() a double"
- Previous message: xxx_at_hotmail.com: "Re: how to write() a double"
- In reply to: Draw: "Newbie Query about raw devices"
- Next in thread: Peter T. Breuer: "Re: Newbie Query about raw devices"
- Reply: Peter T. Breuer: "Re: Newbie Query about raw devices"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|