Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2006-05

ioctl

2 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Alain Michaud

Hi,

I am trying to use the FpIOCtl in the BASEUNIX unit. Guess what? the only thing I get back is -1 !

Is there any example code available on how to talk to a kernel module?

The only kernel that I know to talk to is the one that I am trying is the one that I am writing myself. I am not too familiar with writing device drivers in C. Therefore I would apreciate if someone could sent me an example of a SIMPLE "char" module.

So far, I could register the device using

"register_chrdev(major, name, &fops)"

This seems to work, since I then see the driver in: /proc/modules /proc/devices and /sys/modules

My next step is to issue an FPIOCTL commant but the return code is -1 and the driver never sees the command.

Question:

Do I need open a "file deccriptor" in order to communicate using IOCTL? It should not be?

I have spent the week-end on this, and failed again ... My self esteem is close to nul at this point. Help please...

Thank you

Alain Michaud

Vinzent Hoefler
to Alain Michaud
Alain Michaud wrote
Do I need open a "file deccriptor" in order to communicate using IOCTL?

Yes, you have to open the device before talking to it. Or what the hell do you think, the "Handle" parameter of

|Function  FpIOCtl      (Handle:cint;Ndx: culong;Data: Pointer):cint;

is for?

As always: RTFM, reading the man page (man 2 ioctl) actually might help too:

|DESCRIPTION
| [...] The argu­ment d must be an open file descriptor. |
|RETURN VALUE
| Usually, on success zero is returned. A few ioctls use | the return value as an output parameter and return a non­ | negative value on success. On error, -1 is returned, and | errno is set appropriately.

BTW, I agree - writing device drivers sucks. I know. :-)

But checking out

http://www.freesoftwaremagazine.com/articles/drivers_linux

may be worth a try.

Regards,

Vinzent.