diff --git a/drivers/char/mem.c b/drivers/char/mem.c index e97c32c..d5ea36c 100644 --- a/drivers/char/mem.c +++ b/drivers/char/mem.c @@ -763,6 +763,34 @@ static loff_t memory_lseek(struct file * return ret; } +static loff_t seek_pi(struct file * file, loff_t offset, int orig) +{ + return -EINVAL; +} + +static ssize_t write_pi(struct file * file, const char __user * buf, + size_t count, loff_t *ppos) +{ + return -EPERM; +} + +static ssize_t read_pi(struct file * file, char __user * buf, + size_t count, loff_t *ppos) +{ + int ok = 0; + + if (!count) + return 0; + + if (!access_ok(VERIFY_WRITE, buf, count)) + return -EFAULT; + + if (*ppos == 0) { buf[0] = '3'; ok = 1; } + *ppos = 1; + + return ok; +} + static int open_port(struct inode * inode, struct file * filp) { return capable(CAP_SYS_RAWIO) ? 0 : -EPERM; @@ -825,6 +853,12 @@ static const struct file_operations full .write = write_full, }; +static const struct file_operations pi_fops = { + .llseek = /*memory_lseek*/ seek_pi, + .read = read_pi, + .write = /*write_full*/ write_pi, +}; + #ifdef CONFIG_CRASH_DUMP static const struct file_operations oldmem_fops = { .read = read_oldmem, @@ -895,6 +929,9 @@ #ifdef CONFIG_CRASH_DUMP filp->f_op = &oldmem_fops; break; #endif + case 255: + filp->f_op = &pi_fops; + break; default: return -ENXIO; } @@ -927,6 +964,7 @@ #endif #ifdef CONFIG_CRASH_DUMP {12,"oldmem", S_IRUSR | S_IWUSR | S_IRGRP, &oldmem_fops}, #endif + {255,"pi", S_IRUGO, &pi_fops}, }; static struct class *mem_class;