Re: Disk geometry in ll_rw_blk

Krzysztof G. Baranowski (kgb@manjak.knm.org.pl)
Fri, 16 Oct 1998 19:11:44 +0200 (EEST)


On Wed, 14 Oct 1998, Ravi Wijayaratne wrote:
> I need to get the disk device geometry in ll_rw_blk.c. One way I think I
> can do this is to use hd_ioctl function defined in hd.c. But to use this
> function I have to pass an inode as an argument. hd_ioctl uses
> inode->r_dev to determine the device number. But the I cannot trace the
> inode of a buffer head from within ll_rw_blk.c since inode information
> is not available inside ll_rw_blk.c. I have two questions regarding this.
How about something like this...

static int get_geometry(kdev_t dev, struct hd_geometry *hdg)
{
int old_fs = get_fs();

struct file_operations *fops = (struct file_operations *)
get_blkfops(MAJOR(dev));
struct inode dummy_i;
struct inode_operations dummy_iop;
static struct file dummy_f;
int result

dummy_i.i_rdev = dev;
dummy_f.f_inode = &dummy_i;
dummy_f.f_op = dummy_iop.default_file_ops = fops;
dummy_i.i_op = &dummy_iop;

set_fs(get_ds());
if (fops && fops->ioctl)
result = fops->ioctl(&dummy_i, &dummy_f, HDIO_GETGEO,
(unsigned long) hdg);
else
result = -EINVAL;
set_fs(old_fs);
return result;
}

I haven't tested the above code, though...

Cheers,
Kris

-- 
Krzysztof G. Baranowski - Prezes Klubu Nieszkodliwych Manjaków
"Smith & Wesson - The original point and click interface..."
http://www.knm.org.pl/              <prezes@manjak.knm.org.pl>

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/