Currently i doing like
int len =0; len += sprintf(buf+len,"\n %s by speeDy \n", "TestModule" ); // to print module name
and its da code for /proc module , how to do show when i want too print it from /dev like # "cat /dev/myTestDev"
you want to implement a character device?
you can use sprintf() the same way as before, because that only formats a string and doesn't do I/O. for the rest, read chapter 3 of http://lwn.net/Kernel/LDD3/
You should read the chapter strcmp told you to, but I'll try to make it simple:
First, you'll likely need the following functions:
static int device_open(struct inode *, struct file *); static int device_release(struct inode *, struct file *); static ssize_t device_read(struct file *, char *, size_t, loff_t *); static ssize_t device_write(struct file *, const char *, size_t, loff_t *);
Then you'll declare a file_operations structure, as follows:
static struct file_operations fops = { .read = device_read, .write = device_write, .open = device_open, .release = device_release };
Now you'll have to implement those functions accordingly, to deal with which each action as specified.
To have that string displayed when you `cat /dev/myTestDev`, your device_read() should use "put_user()" to send the data over user space.
char device
you want to implement a character device?
you can use sprintf() the same way as before, because that only formats a string and doesn't do I/O. for the rest, read chapter 3 of http://lwn.net/Kernel/LDD3/
How to copy from K to U
You should read the chapter strcmp told you to, but I'll try to make it simple:
First, you'll likely need the following functions:
static int device_open(struct inode *, struct file *);
static int device_release(struct inode *, struct file *);
static ssize_t device_read(struct file *, char *, size_t, loff_t *);
static ssize_t device_write(struct file *, const char *, size_t, loff_t *);
Then you'll declare a file_operations structure, as follows:
static struct file_operations fops = {
.read = device_read,
.write = device_write,
.open = device_open,
.release = device_release
};
Now you'll have to implement those functions accordingly, to deal with which each action as specified.
To have that string displayed when you `cat /dev/myTestDev`, your device_read() should use "put_user()" to send the data over user space.