wjblack has asked for the wisdom of the Perl Monks concerning the following question:
I have a weird device that I'm using ioctl to talk to (on Linux 2.6). The code in C to do what I want is:
int f = open("/dev/plcm_drv", O_RDWR); printf("%x\n", ioctl(f, 0xC, 0) );
Simple and straightforward--I'm just sending ioctl # 0xC to the driver and printing out the response. Works every time. The equivalent code in Perl is (I believe):
sysopen(DEVICE, "/dev/plcm_drv", O_RDWR); print sprintf("%x", ioctl(DEVICE, 0xC, 0)) . "\n";
The driver, however, never receives the ioctl (I put some debug code in the driver that printk's whenever it gets an ioctl). The driver does receive the TCGETS ioctl from sysopen (with which it responds "Operation not supported" as expected). $! after the ioctl is "Invalid argument".
The strace tells a similar story:
Working (C, ioctl 0xC): open("/dev/plcm_drv", O_RDWR) = 3 ioctl(3, 0xc, 0) = 142 Working (Perl, ioctl 1): open("/dev/plcm_drv", O_RDWR|O_LARGEFILE) = 3 ioctl(3, SNDCTL_TMR_TIMEBASE or TCGETS, 0xff86b540) = -1 EOPNOTSUPP (O +peration not supported) _llseek(3, 0, [0], SEEK_CUR) = 0 fstat64(3, {st_mode=S_IFCHR|0644, st_rdev=makedev(241, 0), ...}) = 0 fcntl64(3, F_SETFD, FD_CLOEXEC) = 0 ioctl(3, FIBMAP, 0) = 0 close(3) = 0 Not Working (Perl, ioctl 0xC): open("/dev/plcm_drv", O_RDWR|O_LARGEFILE) = 3 ioctl(3, SNDCTL_TMR_TIMEBASE or TCGETS, 0xffe34310) = -1 EOPNOTSUPP (O +peration not supported) _llseek(3, 0, [0], SEEK_CUR) = 0 fstat64(3, {st_mode=S_IFCHR|0644, st_rdev=makedev(241, 0), ...}) = 0 fcntl64(3, F_SETFD, FD_CLOEXEC) = 0 ioctl(3, 0xc, 0) = -1 EINVAL (Invalid argument) close(3) = 0
So to sum up:
Any thoughts as to why 0xC is being blocked? I'd rather not have to have a trivial C helper app for this...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Custom ioctl on Linux?
by wjblack (Initiate) on Feb 26, 2010 at 04:17 UTC | |
|
Re: Custom ioctl on Linux?
by bot403 (Beadle) on Feb 25, 2010 at 16:45 UTC |