The write function is defined in the same file and is, as of now,
unimplemented apart from the following.
static int write(char *s){
printk("write function\n");
return 0;
}
2010/1/12 Chetan Nanda <[email protected]>
>
>
> On Tue, Jan 12, 2010 at 4:55 AM, Sam Carter <[email protected]>wrote:
>
>> I've just installed strace and run as you advised although there is no
>> extra information on top of the 'No such device or address'. Does my driver
>> and loader code look right?
>>
>> Thanks for the continued support, Sam
>>
>
> Where is your read/write function defined? there may be some error in these
> functions.
>
> ~cnanda
>
>
>> 2010/1/8 Durga Prasad <[email protected]>
>>
>> On quick glance, do you know what is throwing up the error?
>>> Can you do 'strace -vv cat .. '
>>>
>>>
>>>
>>> ------------------------------
>>> *From:* Sam Carter <[email protected]>
>>> *To:* Daniel Baluta <[email protected]>
>>> *Cc:* kernelnewbies <[email protected]>
>>> *Sent:* Fri, January 8, 2010 6:02:54 PM
>>> *Subject:* Re: 'No such device or address' when writing to device driver
>>>
>>> Hi all,
>>>
>>> Thanks for the responses. Here is the load/unload part of my driver.
>>>
>>> #include <linux/init.h>
>>> #include <linux/module.h>
>>> #include <linux/kernel.h>
>>> #include <linux/sched.h>
>>> #include <linux/version.h>
>>> #include <linux/types.h>
>>> #include <linux/fs.h>
>>> #include <linux/string.h>
>>> #include <linux/dirent.h>
>>> #include <asm/uaccess.h>
>>> #include <linux/cdev.h>
>>>
>>> #include "memo.h"
>>>
>>> static int __init memo(void);
>>> static void __exit cleanup(void);
>>>
>>> static int ioctlManager(int i);
>>> static int read(void);
>>> static int write(char *s);
>>> static int testDirent(int is64bit, int length, void *p);
>>> static int modulePrint(char *s);
>>> int dev, result;
>>>
>>> struct cdev *memoc;
>>>
>>> static struct file_operations fops = {
>>> .owner = THIS_MODULE,
>>> .llseek = NULL,
>>> .read = read,
>>> .write = write,
>>> .ioctl = ioctlManager,
>>> .open = NULL,
>>> .release = NULL,
>>> };
>>>
>>> extern void (*interceptor)(int, int, void *);
>>>
>>> static int __init memo(void){
>>> if(MAJOR){
>>> dev = MKDEV(MAJOR, MINOR);
>>> result = register_chrdev_region(dev, number_of_devices, "memo");
>>> }else{
>>> result = alloc_chrdev_region(&dev, MINOR, number_of_devices,
>>> "memo");
>>> }
>>> memoc = cdev_alloc();
>>> cdev_init(memoc, &fops);
>>> memoc->owner = THIS_MODULE;
>>> if(cdev_add(memoc, 249, 1) < 0){
>>> printk("cdev device registration failed\n");
>>> }else{
>>> printk("cdev device registration success\n");
>>> }
>>>
>>> printk(KERN_INFO "- Module interceptor loaded -\n");
>>> interceptor = testDirent;
>>> if(result < 0){
>>> printk(KERN_WARNING "memo: can't get major/minor numbers");
>>> return result;
>>> }else{
>>> return 0;
>>> }
>>> }
>>>
>>> static void __exit cleanup(void){
>>> int i = 0;
>>> unregister_chrdev_region(dev, number_of_devices);
>>> cdev_del(memoc);
>>> interceptor = NULL;
>>> printk(KERN_INFO "- Module interceptor cleanup -%d\n",i);
>>> }
>>>
>>> And here is the load script I'm using to load the module.
>>>
>>> module="memo"
>>> device="memo"
>>> mode="664"
>>>
>>> #if grep -q '^staff:' /etc/group; then
>>> # group="staff"
>>> #else
>>> # group="wheel"
>>> #fi
>>> group="root"
>>> /sbin/insmod ./$module.ko $* || exit 1
>>>
>>> rm -f /dev/${device}
>>>
>>> major=$(awk "\$2==\"$module\" {print \$1}" /proc/devices)
>>>
>>> mknod /dev/${device} c $major 0
>>> chgrp $group /dev/${device}
>>> chmod $mode /dev/${device}
>>>
>>> As far as I'm aware the Major/Minor numbers match up fine. With ls -l
>>> /dev, the major is 249, which is the same as in /proc/devices once I've
>>> loaded the module. Hope this helps someone find the problem.
>>>
>>> Sam
>>>
>>> 2010/1/8 Daniel Baluta <[email protected]>
>>>
>>>> On Thu, Jan 7, 2010 at 3:31 AM, Sam Carter <[email protected]>
>>>> wrote:
>>>> > Hi all,
>>>> >
>>>> > I'm trying to write a simple char driver following the 'Linux Device
>>>> > Drivers' book from O' Reilly. My driver appears in /proc/devices and
>>>> under
>>>> > lsmod. I've been trying to register the device fops table so I can
>>>> > read/write to it, however when I try to cat some data to it in
>>>> /dev/myDevice
>>>> > I get the error 'No such device or address'. The device does appear on
>>>> the
>>>> > list with ls /dev/.
>>>> >
>>>> > Can anyone help me find the source of this problem? Thanks in advance.
>>>>
>>>>
>>>> Is the major/minor number of /dev/myDevice the same with major/minor
>>>> allocated in your driver ?
>>>> Can you post a pointer to your code?
>>>>
>>>> thanks,
>>>> Daniel.
>>>>
>>>
>>>
>>>
>>
>