LinuxPPC-Dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* Error while opennig device file
@ 2005-06-15 16:19 Garcia Jérémie
  2005-06-15 17:26 ` Eugene Surovegin
  0 siblings, 1 reply; 3+ messages in thread
From: Garcia Jérémie @ 2005-06-15 16:19 UTC (permalink / raw)
  To: linuxppc-dev

Hi everybody,
I'd like to have your opinion on such a stupid question. Indeed, it must =
be very easy to see but
I can't find out what goes on.
I'm writing a device driver. In the init_module(), I register it with =
TEST_DEV_MAJOR =3D 122=20

ret_val =3D register_chrdev(TEST_DEV_MAJOR, TEST_DEV_PROC_NAME, =
&lcd_fops);

In the user space, I have a programm that creates two device files using =
the same major number but with=20
different minor numbers:

ret_val =3D system("mknod -m 777 /dev/Test1 c 122 1");
ret_val =3D system("mknod -m 777 /dev/Test1 c 122 2");

Then I try to open both files :
file_desc1 =3D open("/dev/test1", O_RDWR);
file_desc2 =3D open("/dev/test2", O_RDWR);

Unfortunately, I go through an error on the second open. It seems that I =
can't get those 2 files opened
at the same time. I'm a newbie in linux kernel development, so could you =
explain me why?
What I want to do is to have 2 device files that use the same driver =
module. In my module, I test the minor number
and handle an array of 2 structures (1 for each minor number).
For example, it could represent 2 communication channels ; I could have =
1 device file by channel on which I
could do read/write operation. My module will write/read in array[0] for =
channel 0 and in array[1] for channel 1.

Tks a lot and sorry for such a question but nobody can help me there and =
I can't find out browsing forums and books...

^ permalink raw reply	[flat|nested] 3+ messages in thread
* RE : RE : Error while opennig device file
@ 2005-06-16  8:35 Garcia Jérémie
  2005-06-16  9:23 ` Marcin Dawidowicz
  0 siblings, 1 reply; 3+ messages in thread
From: Garcia Jérémie @ 2005-06-16  8:35 UTC (permalink / raw)
  To: Dustin Lang, Eugene Surovegin; +Cc: linuxppc-dev

Hi everybody! I'm gonna give you all the info you asked me:

[Dustin]
>> does it work from the command line?  Do both mknod commands work?
--> Yes both mknod seem to work from the command line since they are =
both created
    root@10.16.9.232:~# mknod -m 777 /dev/test1 c 122 1
    root@10.16.9.232:~# mknod -m 777 /dev/test2 c 122 2           =20
That looks good

>> When you "ls -l /dev/test{1,2}" , what do you get?=20
--> root@10.16.9.232:~# ls -l /dev/test{1,2}
    crwxrwxrwx    1 root     root     122,   1 Jun 16  2005 /dev/test1
    crwxrwxrwx    1 root     root     122,   2 Jun 16  2005 /dev/test2
That looks good

>> What happens when you "cat /dev/test1" ?
--> root@10.16.9.232:~# cat /dev/test1
    cat: /dev/test1: No such device
That is ok, isn't it?

>> What happens when you "echo > /dev/test1" ?   =20
--> root@10.16.9.232:~# echo > /dev/test1
    bash: /dev/test1: No such device
That is ok, isn't it?

[Eugene]
>> How does open routine for your device look like?
-->
static int test_open(struct inode *inode , struct file *file)
{
  int ret_val =3D 0;
 =20
  if (Device_open !=3D 0)
    return -EBUSY;
 =20
  Device_open++;
  printk("%d minor number!\n",MINOR(inode->i_rdev)); =20
  MOD_INC_USE_COUNT;

  return ret_val;
}

Very traditionnal...

>> What error do you get on second open?
--> I trace the execution of my programm and get the following :
First opened succeeded, open() return code : 3    =20
Can't open second file, open() return code : -1 , errno =3D 16

Looking in the errno.h, we have :
#define	EBUSY		16	/* Device or resource busy */


If tou need more tell me.
Tks again for your help guys!


-------- Message d'origine--------
De: Dustin Lang [mailto:dalang@cs.ubc.ca]
Date: mer. 15/06/2005 20:16
=C0: Eugene Surovegin
Cc: Garcia J=E9r=E9mie; linuxppc-dev@ozlabs.org
Objet : Re: RE : Error while opennig device file
=20

Also - does it work from the command line?  Do both mknod commands work? =

When you "ls -l /dev/test{1,2}" , what do you get?  What happens when =
you=20
"cat /dev/test1" or "echo > /dev/test1" ?

Cheers,
dstn.


>> I'm sorry but this is a "copy to mail" error.
>> Here is the right code:
>>
>> ret_val =3D system("mknod -m 777 /dev/test1 c 122 1");
>> ret_val =3D system("mknod -m 777 /dev/test2 c 122 2");
>>
>> file_desc1 =3D open("/dev/test1", O_RDWR);
>> file_desc2 =3D open("/dev/test2", O_RDWR);

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-06-16  9:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-06-15 16:19 Error while opennig device file Garcia Jérémie
2005-06-15 17:26 ` Eugene Surovegin
  -- strict thread matches above, loose matches on Subject: below --
2005-06-16  8:35 RE : RE : " Garcia Jérémie
2005-06-16  9:23 ` Marcin Dawidowicz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox