chhx001
chhx001

Reputation: 109

How to open another device in a linux module?

For example , I have a '/dev/a' as a cdev. Now I want to write a module 'b' and before 'b' is registered , I need to send a message to 'a' so that 'a' will be started. I used to do it by ioctl() in an application, but now I want to do it in module 'b'. open() can't be used in the module, so how can I open 'a' in module 'b'?

Upvotes: 1

Views: 2574

Answers (2)

Mohit Rohilla
Mohit Rohilla

Reputation: 108

To open a device you should use open system call in linux and check the list of available devices for example /dev/ttyUSB0 or /dev/ttyS0 etc. and open it and you will get a descriptor to write and read on to the device is you open a device to communicate.

int fd;
fd=open(“/dev/ttyUSB0”, O_RDWR);

To know the further details follow this link.

Upvotes: 0

Jeegar Patel
Jeegar Patel

Reputation: 27240

You can open this way

struct file* test;
test = filp_open("/dev/targetDevice",O_RDWR,0);

Now in call ioctl

test->f_op->unlocked_ioctl(test,IOCTL_MACRO,params);

Upvotes: 4

Related Questions