summaryrefslogtreecommitdiff
path: root/pidevice/pidevice.c
diff options
context:
space:
mode:
Diffstat (limited to 'pidevice/pidevice.c')
-rw-r--r--pidevice/pidevice.c55
1 files changed, 25 insertions, 30 deletions
diff --git a/pidevice/pidevice.c b/pidevice/pidevice.c
index 3c5d3b4..d7edc4e 100644
--- a/pidevice/pidevice.c
+++ b/pidevice/pidevice.c
@@ -13,17 +13,15 @@ static char devname[] = "pidevice";
static char modname[] = "pidevice.ko";
static dev_t mydev = 0;
static struct cdev cdev;
-static struct task_struct *mytask;
-static struct task_struct *parent;
static int count = 1;
int pidev_open(struct inode *i, struct file *filp)
{
count = 1;
- printk(KERN_ALERT "Device (%d-%d) opened\n",
+ printk(KERN_ALERT "pidev_open: device (%d-%d) opened\n",
imajor(i), iminor(i));
- printk(KERN_ALERT "Mode: %c%c\n", filp->f_mode & FMODE_READ ? 'R' : '-',
+ printk(KERN_ALERT "pidev_open: mode %c%c\n", filp->f_mode & FMODE_READ ? 'R' : '-',
filp->f_mode & FMODE_WRITE ? 'W' : '-');
return 0;
}
@@ -32,7 +30,8 @@ ssize_t pidev_read(struct file *filp, char __user *buf,
size_t len, loff_t *off)
{
if (count--) {
- copy_to_user(buf, modname, 12);
+ if (copy_to_user(buf, modname, 12))
+ printk(KERN_ALERT "pidev_read: error reading from (__user) %p\n", buf);
return 12;
} else {
return 0;
@@ -43,62 +42,58 @@ ssize_t pidev_write(struct file *filp, const char __user *buf,
size_t len, loff_t *off)
{
char localbuf[40];
- copy_from_user(localbuf, buf, 40);
+ if (copy_from_user(localbuf, buf, 40))
+ printk(KERN_ALERT "pidev_write: error writing in (__user) %p\n", buf);
localbuf[len] = '\0';
- printk(KERN_ALERT "Recibido: %s", localbuf);
+ printk(KERN_ALERT "pidev_write: received: %s", localbuf);
return -EPERM;
}
+long pidev_ioctl(struct file *filp, unsigned msg, unsigned long param)
+{
+ printk(KERN_ALERT "pidev_ioctl: received msg %d / param %ld\n", msg, param);
+ return 0;
+}
+
struct file_operations fops = {
.owner = THIS_MODULE,
.open = pidev_open,
.read = pidev_read,
.write = pidev_write,
+ .unlocked_ioctl = pidev_ioctl,
};
-static void show_processes(void)
-{
- mytask = current;
- parent = mytask->parent;
-
- while (mytask->pid != parent->pid) {
- printk(KERN_ALERT "current: %s (%d) - parent: %s (%d)\n",
- mytask->comm, mytask->pid, parent->comm, parent->pid);
- mytask = mytask->parent;
- parent = mytask->parent;
- }
-}
-
-static int __init init(void)
+static int __init pidev_init(void)
{
int err;
- printk(KERN_ALERT "%s loaded by %s (%d)\n",
+ printk(KERN_ALERT "pidev_init: %s loaded by %s (%d)\n",
modname, current->comm, current->pid);
if ((err = alloc_chrdev_region(&mydev, 0, 1, devname)))
- printk(KERN_ALERT "ERROR in alloc_chrdev_region: %d\n", err);
+ printk(KERN_ALERT "pidev_init: error %d in alloc_chrdev_region\n", err);
else
- printk(KERN_ALERT "%s successfully registered with %d %d numbers\n",
- devname, MAJOR(mydev), MINOR(mydev));
+ printk(KERN_ALERT "pidev_init: %s successfully registered with"
+ "%d %d numbers\n", devname, MAJOR(mydev), MINOR(mydev));
cdev_init(&cdev, &fops);
cdev.owner = THIS_MODULE;
if ((err = cdev_add(&cdev, mydev, 1)))
- printk(KERN_ALERT "ERROR in cdev_add: %d\n", err);
+ printk(KERN_ALERT "pidev_init: error %d in cdev_add\n", err);
return 0;
}
-static void __exit exit(void)
+static void __exit pidev_exit(void)
{
unregister_chrdev_region(mydev, 1);
cdev_del(&cdev);
- printk(KERN_ALERT "%s unloaded\n", modname);
+ printk(KERN_ALERT "pidev_exit: %s unloaded\n", modname);
}
-module_init(init);
-module_exit(exit);
+module_init(pidev_init);
+module_exit(pidev_exit);
MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Guillermo Ramos");