* Char device initialization @ 2011-11-09 13:41 Daniel Hilst Selli 2011-11-09 13:52 ` Alexandru Juncu 0 siblings, 1 reply; 4+ messages in thread From: Daniel Hilst Selli @ 2011-11-09 13:41 UTC (permalink / raw) To: kernelnewbies I'm trying to create a example char device. The example compiles fine, but when I try to "cat" I got "No such device or address". I have reviewed the code thousend times and can't see what I'm missing Here is the code -> http://pastebin.com/Td03U0fK The read method is not good, I know, but is never called. I use my own running kenrel to test, I know that is danger. I'm building a qemu enviroment to test this better. Here is uname -a: Linux archlinux 3.0-ARCH #1 SMP PREEMPT Fri Oct 7 11:35:34 CEST 2011 x86_64 Intel(R) Core(TM) i3 CPU M 370 @ 2.40GHz GenuineIntel GNU/Linux Any idea? Thanks ^ permalink raw reply [flat|nested] 4+ messages in thread
* Char device initialization 2011-11-09 13:41 Char device initialization Daniel Hilst Selli @ 2011-11-09 13:52 ` Alexandru Juncu 2011-11-09 15:28 ` rohan puri 0 siblings, 1 reply; 4+ messages in thread From: Alexandru Juncu @ 2011-11-09 13:52 UTC (permalink / raw) To: kernelnewbies On Wed, Nov 9, 2011 at 3:41 PM, Daniel Hilst Selli <danielhilst@gmail.com> wrote: > I'm trying to create a example char device. The example compiles fine, > but when I try to "cat" I got "No such device or address". I have > reviewed the code thousend times and can't see what I'm missing > > Here is the code -> http://pastebin.com/Td03U0fK > > The read method is not good, I know, but is never called. > > I use my own running kenrel to test, I know that is danger. I'm building > a qemu enviroment to test this better. > > Here is uname -a: > Linux archlinux 3.0-ARCH #1 SMP PREEMPT Fri Oct 7 11:35:34 CEST 2011 > x86_64 Intel(R) Core(TM) i3 CPU M 370 @ 2.40GHz GenuineIntel GNU/Linux > > Any idea? > > Thanks You tried to 'cat' a /dev/my_device file, right? Was that device file created with the mknod command? -- Alexandru Juncu ROSEdu http://rosedu.org ^ permalink raw reply [flat|nested] 4+ messages in thread
* Char device initialization 2011-11-09 13:52 ` Alexandru Juncu @ 2011-11-09 15:28 ` rohan puri 2011-11-09 17:59 ` Daniel Hilst Selli 0 siblings, 1 reply; 4+ messages in thread From: rohan puri @ 2011-11-09 15:28 UTC (permalink / raw) To: kernelnewbies On Wed, Nov 9, 2011 at 7:22 PM, Alexandru Juncu <alex.juncu@rosedu.org>wrote: > On Wed, Nov 9, 2011 at 3:41 PM, Daniel Hilst Selli > <danielhilst@gmail.com> wrote: > > I'm trying to create a example char device. The example compiles fine, > > but when I try to "cat" I got "No such device or address". I have > > reviewed the code thousend times and can't see what I'm missing > > > > Here is the code -> http://pastebin.com/Td03U0fK > > > > The read method is not good, I know, but is never called. > > > > I use my own running kenrel to test, I know that is danger. I'm building > > a qemu enviroment to test this better. > > > > Here is uname -a: > > Linux archlinux 3.0-ARCH #1 SMP PREEMPT Fri Oct 7 11:35:34 CEST 2011 > > x86_64 Intel(R) Core(TM) i3 CPU M 370 @ 2.40GHz GenuineIntel GNU/Linux > > > > Any idea? > > > > Thanks > > You tried to 'cat' a /dev/my_device file, right? > Was that device file created with the mknod command? > > -- > Alexandru Juncu > > ROSEdu > http://rosedu.org > > _______________________________________________ > Kernelnewbies mailing list > Kernelnewbies at kernelnewbies.org > http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies > Hello Daniel, I had the look at the code. The issue is with the cdev_add() call in init_gcdev() function. int cdev_add(struct cdev *p, dev_t dev, unsigned count) is the prototype Now the problem was *instead of passing second argument of type dev_t you were passing minor number macro. *Fix : - Do following additions : - 1. static int major; // Declare a global major no var. 2. In init_gcdev() after call to alloc_chrdev_region() get major no and store in major var. major = MAJOR(gcdev->dev); 3. Replace cdev_add() call like this : - cdev_add(&gcdev->cdev, MKDEV(major, FIRST_MINOR), 1); Now its running and your read methos is getting called. Hello Alexandru, That error was due to improper args passed to cdev_add(). If device file is not present (no mknod done) error would be "No such file or dir" Regards, Rohan Puri -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20111109/e85cb3dd/attachment.html ^ permalink raw reply [flat|nested] 4+ messages in thread
* Char device initialization 2011-11-09 15:28 ` rohan puri @ 2011-11-09 17:59 ` Daniel Hilst Selli 0 siblings, 0 replies; 4+ messages in thread From: Daniel Hilst Selli @ 2011-11-09 17:59 UTC (permalink / raw) To: kernelnewbies On 11/09/2011 01:28 PM, rohan puri wrote: > > > On Wed, Nov 9, 2011 at 7:22 PM, Alexandru Juncu <alex.juncu@rosedu.org > <mailto:alex.juncu@rosedu.org>> wrote: > > On Wed, Nov 9, 2011 at 3:41 PM, Daniel Hilst Selli > <danielhilst at gmail.com <mailto:danielhilst@gmail.com>> wrote: > > I'm trying to create a example char device. The example compiles > fine, > > but when I try to "cat" I got "No such device or address". I have > > reviewed the code thousend times and can't see what I'm missing > > > > Here is the code -> http://pastebin.com/Td03U0fK > > > > The read method is not good, I know, but is never called. > > > > I use my own running kenrel to test, I know that is danger. I'm > building > > a qemu enviroment to test this better. > > > > Here is uname -a: > > Linux archlinux 3.0-ARCH #1 SMP PREEMPT Fri Oct 7 11:35:34 CEST 2011 > > x86_64 Intel(R) Core(TM) i3 CPU M 370 @ 2.40GHz GenuineIntel > GNU/Linux > > > > Any idea? > > > > Thanks > > You tried to 'cat' a /dev/my_device file, right? > Was that device file created with the mknod command? > > -- > Alexandru Juncu > > ROSEdu > http://rosedu.org > > _______________________________________________ > Kernelnewbies mailing list > Kernelnewbies at kernelnewbies.org <mailto:Kernelnewbies@kernelnewbies.org> > http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies > > > > Hello Daniel, > > I had the look at the code. The issue is with the cdev_add() call in > init_gcdev() function. > > int cdev_add(struct cdev *p, dev_t dev, unsigned count) is the prototype > > Now the problem was *instead of passing second argument of type dev_t > you were passing minor number macro. > > *Fix : - Do following additions : - > > 1. static int major; // Declare a global major no var. > > 2. In init_gcdev() after call to alloc_chrdev_region() get major no and > store in major var. > > major = MAJOR(gcdev->dev); > > 3. Replace cdev_add() call like this : - > > cdev_add(&gcdev->cdev, MKDEV(major, FIRST_MINOR), 1); > > Now its running and your read methos is getting called. > > Hello Alexandru, > > That error was due to improper args passed to cdev_add(). If device file > is not present (no mknod done) error would be "No such file or dir" > > Regards, > Rohan Puri Thanks Rohan, my fault! ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-11-09 17:59 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2011-11-09 13:41 Char device initialization Daniel Hilst Selli 2011-11-09 13:52 ` Alexandru Juncu 2011-11-09 15:28 ` rohan puri 2011-11-09 17:59 ` Daniel Hilst Selli
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).