LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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


Reply
  Search this Thread
Old 07-31-2014, 12:01 PM   #1
Aniroop Mathur
LQ Newbie
 
Registered: Mar 2014
Location: Noida, India
Posts: 16

Rep: Reputation: Disabled
IIO: Why cannot open same iio device node twice ?


Hello !

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
 
Old 08-01-2014, 06:19 AM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,140

Rep: Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263
http://linux.die.net/man/2/dup
 
Old 08-01-2014, 07:10 AM   #3
Aniroop Mathur
LQ Newbie
 
Registered: Mar 2014
Location: Noida, India
Posts: 16

Original Poster
Rep: Reputation: Disabled
Hello Smallpond,

I checked the above suggested link - http://linux.die.net/man/2/dup
But it does not solve the problem.

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.
 
Old 08-13-2014, 09:01 AM   #4
Aniroop Mathur
LQ Newbie
 
Registered: Mar 2014
Location: Noida, India
Posts: 16

Original Poster
Rep: Reputation: Disabled
Hello,

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.

Thanks !
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how many open file descriptors do I dare use? hydraMax Programming 1 02-23-2012 07:39 PM
Getting nr of open file descriptors in processes without loop over fd-directory. herthh Linux - General 1 09-04-2011 12:55 PM
how kernel resolves file descriptors when you do open() or read() alankar Linux - Kernel 2 09-04-2009 12:35 AM
Testing Whether A Device Node Is Open Or Locked Woodsman Slackware 2 02-18-2009 07:34 PM
How to find out the number of open file descriptors? skie_knite007 Programming 2 12-11-2005 10:23 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:03 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration