4da 12.05.2012 07:59 darkstar

Хозяйке на заметку:

Пач against 2.6.34.7 чтобы создавалось устройство /dev/one, которое возвращает 0xFF при чтении из него.

diff --git a/drivers/char/mem.c b/drivers/char/mem.c
index 53dd7d0..21590ae 100644
--- a/drivers/char/mem.c
+++ b/drivers/char/mem.c
@@ -789,6 +789,24 @@ static ssize_t read_zero(struct file *file, char __user *buf,
return written ? written : -EFAULT;
}

+static ssize_t read_one(struct file * file, char __user * buf,
+ size_t count, loff_t *ppos)
+{
+ size_t written;
+ unsigned long unwritten;
+ static int one = ~0;
+
+ for (written = 0; written < count; written++) {
+ unwritten = copy_to_user(&buf[written], &one, 1);
+ if (unwritten)
+ break;
+ cond_resched();
+ }
+
+ return written ? written : -EFAULT;
+}
+
+
static int mmap_zero(struct file *file, struct vm_area_struct *vma)
{
#ifndef CONFIG_MMU
@@ -860,6 +878,10 @@ static int open_port(struct inode * inode, struct file * filp)
#define open_mem open_port
#define open_kmem open_mem
#define open_oldmem open_mem
+#define one_lseek null_lseek
+#define write_one write_null
+#define mmap_one mmap_zero
+

#ifndef ARCH_HAS_DEV_MEM
static const struct file_operations mem_fops = {
@@ -930,6 +952,13 @@ static const struct file_operations oldmem_fops = {
};
#endif

+static const struct file_operations one_fops = {
+ .llseek = one_lseek,
+ .read = read_one,
+ .write = write_one,
+ .mmap = mmap_one,
+};
+
static ssize_t kmsg_write(struct file *file, const char __user *buf,
size_t count, loff_t *ppos)
{
@@ -977,6 +1006,7 @@ static const struct memdev {
#ifdef CONFIG_CRASH_DUMP
[12] = { "oldmem", 0, &oldmem_fops, NULL },
#endif
+ [13] = { "one", 0, &one_fops, NULL },
};

static int memory_open(struct inode *inode, struct file *filp)

1. eurekafag 12.05.2012 11:25 Home

one_fops

Do you really want to delete ?