[LCP]Getting list of IDE-drives from kernel?
Steve Baker
ice at mama.indstate.edu
Wed Dec 11 05:00:02 UTC 2002
"Aron Stansvik" <elvstone at home.se> wrote:
> How do I get a list of connected IDE-drives directly out of the kernel, wit=
> hout having to use /proc, using an ioctl()-call or similar. I can't find =
> a suitable ioctl()-call in 'man ioctl_list' (I heard ioctl() is disliked =
> among kernel people for organisational reasons, but anyway). I'm new to p=
> rogramming C in linux. Thanks in advance.
You might want to look at the source for say, fdisk or some other program
that does it, but I think you'll find that they use the proc interface. If
you wanted at information in /proc/sys you could use sysctl() instead, but
sysctl() is not what you're looking for in this specific case. The ioctl()
interface is very poorly documented and I imagine that man page is badly out
of date (mine is for kernel 1.3.27)
Alternatively I suppose if you're running the program with sufficient
privledges you could do a test open on each /dev/hd_ device and see if it
succeeds, although that does not help distinguish between hard drives and
cd-roms. I suppose that perhaps the ioctl() HDIO_GET_IDENTITY might help with
that (info that hdparm -i <dev> returns), look in /usr/include/linux/hdreg.h.
- Steve
More information about the linuxCprogramming
mailing list