在Linux中,用户可以通过设备文件作为接口访问设备驱动程序。
当Linux C程序员想要访问C程序中的驱动程序时,他是否也通过其设备文件作为接口访问驱动程序?
换句话说,设备文件是设备驱动程序的接口,只是在shell中,而不是在C程序中,还是两者都是?
发布于 2015-01-10 21:22:55
AFAIK设备文件是用户进程访问设备的唯一选项。内核并不关心这个进程是否是一个shell。
C程序可以选择微调设备访问:ioctl调用:
man 2 ioctl:
int ioctl(int d, unsigned long request, ...);也许有一个外壳包装,但我不知道任何。
> strace fdisk -l /dev/sda
[...]
open("/dev/sda", O_RDONLY|O_CLOEXEC) = 3
[...]
ioctl(3, BLKGETSIZE64, 500107862016) = 0
[...]
ioctl(3, CDROM_GET_CAPABILITY or SNDRV_SEQ_IOCTL_UNSUBSCRIBE_PORT, 0) = -1 ENOTTY (Inappropriate ioctl for device)
ioctl(3, BLKALIGNOFF, 0) = 0
ioctl(3, BLKIOMIN, 4096) = 0
ioctl(3, BLKIOOPT, 0) = 0
ioctl(3, BLKPBSZGET, 4096) = 0
ioctl(3, BLKSSZGET, 512) = 0
ioctl(3, BLKSSZGET, 512) = 0
uname({sys="Linux", node="inno", ...}) = 0
ioctl(3, BLKGETSIZE64, 500107862016) = 0
ioctl(3, HDIO_GETGEO, {heads=255, sectors=63, cylinders=60801, start=0}) = 0https://unix.stackexchange.com/questions/178498
复制相似问题