[openbeos] Re: parallel driver

  • From: philippe.houdoin@xxxxxxx
  • To: openbeos@xxxxxxxxxxxxx
  • Date: Thu, 28 Mar 2002 17:05:19 +0100 (MET)

>> Bear in mind that the ioctl in R5 seems to be broken as it 
>> doesn't always pass back the correct error value, so we're 
>> having to add parameters to all the structures to pass the 
>> error value back.
>
> I didn't know about this, is it experience or did you read 
> about this elsewhere ? Btw This is one thing to be corrected 
> in R1 :)

From experience.
In a /dev/misc/test R5 driver control hook code:

swith(op) {
case MY_DRIVER_OP:
  return B_BAD_VALUE;
...
};

In a userland app:

int fd, rc;
fd = open("/dev/misc/test", O_RDWR);
if (fd < 0)
  return;
rc = ioctl(fd, MY_DRIVER_OP, NULL, 0);
printf("ioctl() returns %d\n", rc);
close(fd);

Under both vanilla and BONE R5 BeOS kernels, you will get:
"ioctl() returns -1".

But... B_BAD_VALUE != B_ERROR ;-)

In fact, it's not a BUG at all. 
From ioctl() man page:
[...]
RETURN VALUE
  Usually, on success zero is returned. 
  A few ioctls use the return value as an output parameter and return a 
  nonnegative value on success. On error, -1 is returned, and errno is 
  set appropriately. 

It's just something to remember when you plan to use heavily ioctl() 
to communicate with a driver code: you can't use the ioctl() returns value 
to sent back a meaningfull result code.

So, one more thing to NOT fix for R1. :-p

-Philippe.

Other related posts: