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...


In reply to Custom ioctl on Linux? by wjblack

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.