1

In Linux shell, a user can access a device driver, via its device file as the interface.

When a Linux C programmer want to access a driver in his C program, does he also access the driver, via its device file as the interface?

In other words, is a device file the interface to a device driver only in shell but not in a C program, or in both?

  • This is more a question for Stackoverflow. – Hauke Laging Jan 10 '15 at 21:15
1

AFAIK device files are the only option for userland processes to get access to devices. The kernel doesn't care whether that process is a shell.

C programs have an option for fine-tuning the device access: the ioctl call:

man 2 ioctl:

int ioctl(int d, unsigned long request, ...);

Maybe there is a shell wrapper for that but I am not aware of any.

> 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}) = 0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.