<br><br><div class="gmail_quote">On Wed, Nov 9, 2011 at 7:22 PM, Alexandru Juncu <span dir="ltr"><<a href="mailto:alex.juncu@rosedu.org">alex.juncu@rosedu.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">On Wed, Nov 9, 2011 at 3:41 PM, Daniel Hilst Selli<br>
<<a href="mailto:danielhilst@gmail.com">danielhilst@gmail.com</a>> wrote:<br>
> I'm trying to create a example char device. The example compiles fine,<br>
> but when I try to "cat" I got "No such device or address". I have<br>
> reviewed the code thousend times and can't see what I'm missing<br>
><br>
> Here is the code -> <a href="http://pastebin.com/Td03U0fK" target="_blank">http://pastebin.com/Td03U0fK</a><br>
><br>
> The read method is not good, I know, but is never called.<br>
><br>
> I use my own running kenrel to test, I know that is danger. I'm building<br>
> a qemu enviroment to test this better.<br>
><br>
> Here is uname -a:<br>
> Linux archlinux 3.0-ARCH #1 SMP PREEMPT Fri Oct 7 11:35:34 CEST 2011<br>
> x86_64 Intel(R) Core(TM) i3 CPU M 370 @ 2.40GHz GenuineIntel GNU/Linux<br>
><br>
> Any idea?<br>
><br>
> Thanks<br>
<br>
</div>You tried to 'cat' a /dev/my_device file, right?<br>
Was that device file created with the mknod command?<br>
<font color="#888888"><br>
--<br>
Alexandru Juncu<br>
<br>
ROSEdu<br>
<a href="http://rosedu.org" target="_blank">http://rosedu.org</a><br>
</font><div><div></div><div class="h5"><br>
_______________________________________________<br>
Kernelnewbies mailing list<br>
<a href="mailto:Kernelnewbies@kernelnewbies.org">Kernelnewbies@kernelnewbies.org</a><br>
<a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
</div></div></blockquote></div><br><br>Hello Daniel,<br><br>I had the look at the code. The issue is with the cdev_add() call in init_gcdev() function.<br><br>int cdev_add(struct cdev *p, dev_t dev, unsigned count) is the prototype<br>
<br>Now the problem was <b>instead of passing second argument of type dev_t you were passing minor number macro.<br><br></b>Fix : - Do following additions : -<br><br>1. static int major; // Declare a global major no var.<br>
<br>2. In init_gcdev() after call to alloc_chrdev_region() get major no and store in major var.<br><br>major = MAJOR(gcdev->dev);<br><br>3. Replace cdev_add() call like this : -<br><br> cdev_add(&gcdev->cdev, MKDEV(major, FIRST_MINOR), 1);<br>
<br>Now its running and your read methos is getting called.<br><br>Hello Alexandru,<br><br>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"<br>
<br>Regards,<br>Rohan Puri<br>