From: Frank T Lofaro (fl0p+@andrew.cmu.edu)
Date: 05/01/93


From: Frank T Lofaro <fl0p+@andrew.cmu.edu>
Subject: How do I read/write a disk block from within the kernel?
Date: Sat,  1 May 1993 16:54:36 -0400


        I am trying to implement raw devices (e.g. /dev/rhda?) for Linux. I
know how to find out what block and device to read, and how to pass data
to/from the user, and how to write device drivers. I've used the
drivers.doc file (very useful!). What I have a problem with is trying to
call ll_rw_block() without calling getblk first (which uses the system
buffer cache, which defeats the purpose of raw devices). I set up the
dev, blocknr, etc, but don't know what else needs to be set. I tried
setting b_data in the buffer head struct, but still get panics in the hd
interrupt routine (bad dereferences). I think I might have to set
bh->b_this_page or something. I'd need to know how.

        So what should I do to read/write in/out a disk block from buffers
local to the procedure I'm doing it in? Do I still need to brelse()
afterwards? Or do I have to write my own brelse()? It isn't too hard to
steal code from bread() and brelse(). Should I just initialize my own
local free list, and call grow_buffers() on that? Should I steal code
from that, and hack that?

        Please no flames, saying we don't need raw devices. I think for some
setups (particularly those with low memory), programs that do random
access (e.g. fsck/efsck/e2fsck/xfsck) might perform better, and hose the
system less by not evicting the current contents of the buffer cache for
blocks that won't be accessed again. Anyway, it would be nice to have
for completeness (all other un*x's I know of have it)

        Any help or insight is much appreciated. Thanks.

        I'm losing my net access May 12, so I'll need to know by then
preferably. I'll probably have net access again midsummer or by fall.