views:

82

answers:

2

I'm running a python program. When it get's to these lines:
f = open("/dev/bus/usb/007/005", "r")
x = fcntl.ioctl(f.fileno(), 0x84005001, '\x00' * 256)
It fails saying:
IOError: [Errno 1] Operation not permitted
What could be causing this problem?

+1  A: 

file system permissions?

what does ls -l /dev/bus/usb/007/005 say?

does cat /dev/bus/usb/007/005 work or does it report the same error?

plaisthos
output of first is:`crw-rw-rw- 1 root lp 189, 772 24.04.2010 15:58 /dev/bus/usb/007/00`the cat command prints some weird chars to the terminal.
eyecreate
Also, running as root outputs the same thing.
eyecreate
then probably the ioctl is failing. I have no deeper knowledge of usb devices and ioctls.The ioctl you are trying to do could be - only allowed by root - wrong magic number - only works on files opened r/wSorry I can only guess
plaisthos
A: 

The third argument to fcntl.ioctl, as documented here, should be either a 1024-byte string (not just 256), or, better, a possibly even-larger writeable buffer -- the underlying object could be an array.array of bytes. Unfortunately you need to know in advance how much space the result will need, but you can play it safe with a few KB (that ioctl seems to be the "get device id" code, but I'm not sure what the max result length could be).

Alex Martelli