[SOLVED] IIO: Why cannot open same iio device node twice ?
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I would like to open two file descriptors of IIO device node - /dev/iio:device0
int fd1 = open("/dev/iio:device0",O_RDONLY);
int fd2 = open("/dev/iio:device0",O_RDONLY);
But, only first open call succeeds. The second open calls fails with error "Device or Resource busy".
In normal input device, we can open as many event node file descriptors as we like.
int fd1 = open("/dev/input/event1");
int fd2 = open("/dev/input/event1");
Both calls succeeds for input subsystem case.
So, why restriction is present in IIO subsystem ?
Why cannot open same iio device node as many times as desired ?
Thank you!
Last edited by Aniroop Mathur; 08-02-2014 at 07:38 AM.
Reason: need to correct subject
It is mentioned on the Linux man page,
"They refer to the same open file descriptors and thus share file offset and file status flags;
for example, if the file offset is modified by using lseek(2) on one of the descriptors, the offset is also changed for the other."
So, "dup" only duplicates the the fd but I need two different file descriptors so that I can read the data independently.
Thanks!
Last edited by Aniroop Mathur; 08-01-2014 at 10:30 AM.
After discussing with IIO community,
below is the reason why same iio device node cannot be opened twice:
Basically IIO is a different design for the userspace interfaces.
IIO mainly deals with much faster devices so overhead of description of data
has been removed to avoid overhead in kernel.
static int iio_chrdev_open(struct inode *inode, struct file *filp)
{
...
if (test_and_set_bit(IIO_BUSY_BIT_POS, &indio_dev->flags))
return -EBUSY;
...
}
So, we get ebusy error upon opening same iio device node again.
If we comment this line, we will be able to get multiple fds successfully.
But currently, there is no support of multiple fds in iio for read
operation i.e. if we read data using one fd, the offset for other fd will also change
because they actually act as only one fd.
So two open fds will not be able to work independently.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.