From f75a99511ceba088d52d900d4f86a61f5855ab4a Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Sun, 21 Jul 2013 01:02:36 +0400 Subject: [PATCH 01/17] driver: fix creating of entries in proc-fs for linux 3.10 --- driver/dtrace_linux.c | 39 ++++++++++++++++++++++----------------- driver/fasttrap.c | 7 +++---- driver/fbt_linux.c | 7 +++---- driver/instr_linux.c | 7 +++---- driver/intr.c | 10 +++------- driver/proc_compat.h | 25 +++++++++++++++++++++++++ driver/systrace.c | 7 +++---- 7 files changed, 62 insertions(+), 40 deletions(-) create mode 100644 driver/proc_compat.h diff --git a/driver/dtrace_linux.c b/driver/dtrace_linux.c index ad67d58..4a7d519 100644 --- a/driver/dtrace_linux.c +++ b/driver/dtrace_linux.c @@ -17,6 +17,7 @@ #include "dtrace_linux.h" #include #include "dtrace_proto.h" +#include "proc_compat.h" #include #include @@ -2689,10 +2690,9 @@ static int proc_calc_metrics(char *page, char **start, off_t off, if (len<0) len = 0; return len; } -static int proc_dtrace_debug_read_proc(char *page, char **start, off_t off, - int count, int *eof, void *data) -{ int len; - +static ssize_t proc_dtrace_debug_read_proc(struct file *fp, char __user *buf, size_t len, loff_t *off) +{ + int len; len = snprintf(page, count, "here=%d\n" "cpuid=%d\n", @@ -2950,13 +2950,26 @@ static struct miscdevice helper_dev = { &helper_fops }; +static struct file_operations proc_dtrace_debug = { + .read = proc_dtrace_debug_read_proc +}; +static struct file_operations proc_dtrace_security = { + .read = proc_dtrace_security_read_proc +}; +static struct file_operations proc_dtrace_stats = { + .read = proc_dtrace_stats_read_proc +}; +static struct file_operations proc_dtrace_trace = { + .read = proc_dtrace_trace_read_proc, + .write = proc_dtrace_trace_write_proc +}; + /**********************************************************************/ /* This is where we start after loading the driver. */ /**********************************************************************/ static int __init dtracedrv_init(void) { int i, ret; - struct proc_dir_entry *ent; /***********************************************/ /* Create the parent directory. */ @@ -3022,18 +3035,10 @@ static struct proc_dir_entry *dir; /***********************************************/ /* Create /proc/dtrace subentries. */ /***********************************************/ - ent = create_proc_entry("debug", S_IFREG | S_IRUGO | S_IWUGO, dir); - ent->read_proc = proc_dtrace_debug_read_proc; - - ent = create_proc_entry("security", S_IFREG | S_IRUGO | S_IWUGO, dir); - ent->read_proc = proc_dtrace_security_read_proc; - - ent = create_proc_entry("stats", S_IFREG | S_IRUGO | S_IWUGO, dir); - ent->read_proc = proc_dtrace_stats_read_proc; - - ent = create_proc_entry("trace", S_IFREG | S_IRUGO | S_IWUGO, dir); - ent->read_proc = proc_dtrace_trace_read_proc; - ent->write_proc = proc_dtrace_trace_write_proc; + proc_create("debug", S_IFREG | S_IRUGO | S_IWUGO, dir, &proc_dtrace_debug); + proc_create("security", S_IFREG | S_IRUGO | S_IWUGO, dir, &proc_dtrace_security); + proc_create("stats", S_IFREG | S_IRUGO | S_IWUGO, dir, &proc_dtrace_stats); + proc_create("trace", S_IFREG | S_IRUGO | S_IWUGO, dir, &proc_dtrace_trace); /***********************************************/ /* Helper not presently implemented :-( */ diff --git a/driver/fasttrap.c b/driver/fasttrap.c index 2ce3615..52d3fdf 100644 --- a/driver/fasttrap.c +++ b/driver/fasttrap.c @@ -28,6 +28,8 @@ # if linux #include "dtrace_linux.h" +#include "proc_compat.h" + #include #include #include @@ -2471,7 +2473,6 @@ fasttrap_attach(void) { ulong_t nent = 1000; int i; - struct proc_dir_entry *ent; # if defined(sun) switch (cmd) { @@ -2570,9 +2571,7 @@ HERE(); } HERE(); - ent = create_proc_entry("dtrace/fasttrap", 0444, NULL); - if (ent) - ent->proc_fops = &fasttrap_proc_fops; + proc_create("dtrace/fasttrap", 0444, NULL, &fasttrap_proc_fops); (void) dtrace_meta_register("fasttrap", &fasttrap_mops, NULL, &fasttrap_meta_id); HERE(); diff --git a/driver/fbt_linux.c b/driver/fbt_linux.c index 613134b..6f50590 100644 --- a/driver/fbt_linux.c +++ b/driver/fbt_linux.c @@ -20,6 +20,8 @@ //#pragma ident "@(#)fbt.c 1.11 04/12/18 SMI" #include +#include "proc_compat.h" + #include #include #include @@ -1403,7 +1405,6 @@ static int initted; int fbt_init(void) { int ret; - struct proc_dir_entry *ent; ret = misc_register(&fbt_dev); if (ret) { @@ -1425,9 +1426,7 @@ int fbt_init(void) /* dtrace_invop_add(fbt_invop);*/ - ent = create_proc_entry("dtrace/fbt", 0444, NULL); - if (ent) - ent->proc_fops = &fbt_proc_fops; + proc_create("dtrace/fbt", 0444, NULL, &fbt_proc_fops); if (dtrace_register("fbt", &fbt_attr, DTRACE_PRIV_KERNEL, 0, &fbt_pops, NULL, &fbt_id)) { diff --git a/driver/instr_linux.c b/driver/instr_linux.c index 7b34903..aa829b6 100644 --- a/driver/instr_linux.c +++ b/driver/instr_linux.c @@ -21,6 +21,8 @@ /**********************************************************************/ #include +#include "proc_compat.h" + #include #include #include @@ -1109,7 +1111,6 @@ int instr_init(void) { # if !defined(__arm__) int ret; - struct proc_dir_entry *ent; ret = misc_register(&instr_dev); if (ret) { @@ -1131,9 +1132,7 @@ int instr_init(void) dtrace_invop_add(instr_invop); - ent = create_proc_entry("dtrace/instr", 0444, NULL); - if (ent) - ent->proc_fops = &instr_proc_fops; + proc_create("dtrace/instr", 0444, NULL, &instr_proc_fops); if (dtrace_register("instr", &instr_attr, DTRACE_PRIV_KERNEL, 0, &instr_pops, NULL, &instr_id)) { diff --git a/driver/intr.c b/driver/intr.c index 3eb2fe1..6699632 100644 --- a/driver/intr.c +++ b/driver/intr.c @@ -16,6 +16,7 @@ #include "dtrace_linux.h" #include #include "dtrace_proto.h" +#include "proc_compat.h" #include #include @@ -1230,7 +1231,6 @@ intr_init(void) return; # else - struct proc_dir_entry *ent; static struct x86_descriptor desc1; my_kallsyms_lookup = get_proc_addr("kallsyms_lookup"); @@ -1277,12 +1277,8 @@ static struct x86_descriptor desc1; /* Add an /proc/dtrace/idt, so we can see */ /* what it looks like from user space. */ /***********************************************/ - ent = create_proc_entry("dtrace/idt", 0444, NULL); - if (ent) - ent->proc_fops = &idt_proc_fops; - ent = create_proc_entry("dtrace/gdt", 0444, NULL); - if (ent) - ent->proc_fops = &gdt_proc_fops; + proc_create("dtrace/idt", 0444, NULL, &idt_proc_fops); + proc_create("dtrace/gdt", 0444, NULL, &gdt_proc_fops); /***********************************************/ /* Lock the page fault handler into */ diff --git a/driver/proc_compat.h b/driver/proc_compat.h new file mode 100644 index 0000000..6ee8cc0 --- /dev/null +++ b/driver/proc_compat.h @@ -0,0 +1,25 @@ + +/** + * proc compat with kernel older 3.10 + */ +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0) +inline struct proc_dir_entry* proc_create_data( + const char *name, umode_t mode, struct proc_dir_entry *parent, + const struct file_operations *proc_fops, void *data) +{ + struct proc_dir_entry *ent = create_proc_entry(name, mode, parent); + if (ent != NULL) { + ent->proc_fops = proc_fops; + ent->data = data; + } + return ent; +} + +static inline struct proc_dir_entry *proc_create( + const char *name, umode_t mode, struct proc_dir_entry *parent, + const struct file_operations *proc_fops) +{ + return proc_create_data(name, mode, parent, proc_fops, NULL); +} + +#endif diff --git a/driver/systrace.c b/driver/systrace.c index af6068d..9ccc092 100644 --- a/driver/systrace.c +++ b/driver/systrace.c @@ -72,6 +72,8 @@ Feb 2011 # undef zone # define zone linux_zone #include +#include "proc_compat.h" + #include #include #include @@ -2394,7 +2396,6 @@ static int initted; int systrace_init(void) { int ret; - struct proc_dir_entry *ent; /***********************************************/ /* This is a run-time and not a compile */ @@ -2419,9 +2420,7 @@ int systrace_init(void) systrace_attach(); - ent = create_proc_entry("dtrace/syscall", 0444, NULL); - if (ent) - ent->proc_fops = &sys_proc_fops; + proc_create("dtrace/syscall", 0444, NULL, &sys_proc_fops); return 0; } From 02f0adafd04709a295757221e7278efe2760b6c5 Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Sun, 21 Jul 2013 02:58:01 +0400 Subject: [PATCH 02/17] driver: proc: use seq_show function for basic added proc entries --- driver/dtrace_linux.c | 127 ++++++++++++++++++++++++++---------------- 1 file changed, 80 insertions(+), 47 deletions(-) diff --git a/driver/dtrace_linux.c b/driver/dtrace_linux.c index 4a7d519..ef3b475 100644 --- a/driver/dtrace_linux.c +++ b/driver/dtrace_linux.c @@ -2680,34 +2680,36 @@ dtracedrv_write(struct file *file, const char __user *buf, } return count; } -static int proc_calc_metrics(char *page, char **start, off_t off, - int count, int *eof, int len) -{ - if (len <= off+count) *eof = 1; - *start = page + off; - len -= off; - if (len>count) len = count; - if (len<0) len = 0; - return len; -} -static ssize_t proc_dtrace_debug_read_proc(struct file *fp, char __user *buf, size_t len, loff_t *off) + +/** "proc/dtrace/debug" */ +static ssize_t proc_dtrace_debug_show(struct seq_file *seq, void *v) { - int len; - len = snprintf(page, count, + seq_printf(seq, "here=%d\n" "cpuid=%d\n", dtrace_here, cpu_get_id()); - return proc_calc_metrics(page, start, off, count, eof, len); + return 0; } -static int proc_dtrace_security_read_proc(char *page, char **start, off_t off, - int count, int *eof, void *data) +static struct seq_operations proc_dtrace_debug_seq_ops = { + .show = proc_dtrace_debug_show +}; +static int proc_dtrace_debug_seq_open(struct inode *inode, struct file *file) +{ + return seq_open(file, &proc_dtrace_debug_seq_ops); +} +static struct file_operations proc_dtrace_debug = { + .owner = THIS_MODULE, + .open = proc_dtrace_debug_seq_open, + .read = seq_read +}; + +/** "proc/dtrace/security" */ +static int proc_dtrace_security_show(struct seq_file *seq, void *v) { int len = count; char tmpbuf[128]; int i; - int n = 0; int size; - char *buf = page; /***********************************************/ /* Dump out the security table. */ @@ -2734,15 +2736,27 @@ static int proc_dtrace_security_read_proc(char *page, char **start, off_t off, if (di_list[i].di_priv & DTRACE_PRIV_OWNER) strcat(tp, " priv_owner"); - size = snprintf(buf, len, "%s\n", tmpbuf); - buf += size; + size = seq_printf(seq, "%s\n", tmpbuf); len -= size; - n += size; } - return proc_calc_metrics(page, start, off, count, eof, n); + return 0; } -static int proc_dtrace_stats_read_proc(char *page, char **start, off_t off, - int count, int *eof, void *data) + +static struct seq_operations proc_dtrace_security_seq_ops = { + .show = proc_dtrace_security_show +}; +static int proc_dtrace_security_seq_open(struct inode *inode, struct file *file) +{ + return seq_open(file, &proc_dtrace_security_seq_ops); +} +static struct file_operations proc_dtrace_security = { + .owner = THIS_MODULE, + .open = sys_seq_open, + .read = seq_read +}; + +/** "proc/dtrace/stats" */ +static int proc_dtrace_stats_show(struct seq_file *seq, void *v) { int i, size; int n = 0; char *buf = page; @@ -2821,23 +2835,39 @@ static int proc_dtrace_stats_read_proc(char *page, char **start, off_t off, for (i = 0; i < MAX_DCNT && n < count; i++) { if (dcnt[i] == 0) continue; - size = snprintf(buf, count - n, "dcnt%d=%lu\n", i, dcnt[i]); - buf += size; + size = seq_nprintf(seq, "dcnt%d=%lu\n", i, dcnt[i]); n += size; - } + } for (i = 0; stats[i].name; i++) { if (stats[i].type == TYPE_LONG_LONG) - size = snprintf(buf, count - n, "%s=%llu\n", stats[i].name, *(unsigned long long *) stats[i].ptr); + seq_printf(seq, "%s=%llu\n", stats[i].name, *(unsigned long long *) stats[i].ptr); else if (stats[i].type == TYPE_LONG) - size = snprintf(buf, count - n, "%s=%lu\n", stats[i].name, *stats[i].ptr); + seq_printf(seq, "%s=%lu\n", stats[i].name, *stats[i].ptr); else - size = snprintf(buf, count - n, "%s=%d\n", stats[i].name, *(int *) stats[i].ptr); - buf += size; - n += size; + seq_printf(seq, "%s=%d\n", stats[i].name, *(int *) stats[i].ptr); } - return proc_calc_metrics(page, start, off, count, eof, n); + return 0; +} + +static struct seq_operations proc_dtrace_stats_seq_ops = { + .show = proc_dtrace_stats_show +}; +static int proc_dtrace_stats_seq_open(struct inode *inode, struct file *file) +{ + return seq_open(file, &proc_dtrace_stats_seq_ops); +} +static struct file_operations proc_dtrace_stats = { + .owner = THIS_MODULE, + .open = sys_seq_open, + .read = seq_read +}; + +/** "proc/dtrace/trace" */ +static int proc_dtrace_trace_show(struct seq_file *seq, void *v) +{ + return 0; } static int proc_dtrace_trace_read_proc(char *page, char **start, off_t off, int count, int *eof, void *data) @@ -2878,6 +2908,23 @@ static int proc_dtrace_trace_write_proc(struct file *file, const char __user *bu return count; } +static struct seq_operations proc_dtrace_trace_seq_ops = { + .show = proc_dtrace_trace_show +}; +static int proc_dtrace_trace_seq_open(struct inode *inode, struct file *file) +{ + return seq_open(file, &proc_dtrace_trace_seq_ops); +} +static struct file_operations proc_dtrace_trace = { + .owner = THIS_MODULE, + .open = sys_seq_open, + .read = seq_read, + // TODO: + // .write = proc_dtrace_trace_write_proc +}; + +/** \proc */ + static int dtracedrv_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) { int ret; int rv = 0; @@ -2950,20 +2997,6 @@ static struct miscdevice helper_dev = { &helper_fops }; -static struct file_operations proc_dtrace_debug = { - .read = proc_dtrace_debug_read_proc -}; -static struct file_operations proc_dtrace_security = { - .read = proc_dtrace_security_read_proc -}; -static struct file_operations proc_dtrace_stats = { - .read = proc_dtrace_stats_read_proc -}; -static struct file_operations proc_dtrace_trace = { - .read = proc_dtrace_trace_read_proc, - .write = proc_dtrace_trace_write_proc -}; - /**********************************************************************/ /* This is where we start after loading the driver. */ /**********************************************************************/ From 794e2757860338ff36b7cd69d2a3547fc0b3c895 Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Sun, 21 Jul 2013 03:02:56 +0400 Subject: [PATCH 03/17] driver: proc: missing include of linux/seq_file.h --- driver/dtrace_linux.c | 1 + 1 file changed, 1 insertion(+) diff --git a/driver/dtrace_linux.c b/driver/dtrace_linux.c index ef3b475..9153fca 100644 --- a/driver/dtrace_linux.c +++ b/driver/dtrace_linux.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include From 3398cb9ffff9779470f3136b5c0b9012b70c8e1c Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Sun, 21 Jul 2013 03:07:27 +0400 Subject: [PATCH 04/17] driver: debug proc: fix return value for show callback --- driver/dtrace_linux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/driver/dtrace_linux.c b/driver/dtrace_linux.c index 9153fca..fb8ac22 100644 --- a/driver/dtrace_linux.c +++ b/driver/dtrace_linux.c @@ -2683,7 +2683,7 @@ dtracedrv_write(struct file *file, const char __user *buf, } /** "proc/dtrace/debug" */ -static ssize_t proc_dtrace_debug_show(struct seq_file *seq, void *v) +static int proc_dtrace_debug_show(struct seq_file *seq, void *v) { seq_printf(seq, "here=%d\n" From 22bb56dc0976f64945b74d1845c1251e3a29a906 Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Sun, 21 Jul 2013 03:08:32 +0400 Subject: [PATCH 05/17] driver: proc_dtrace_security_show(): drop unsed variables Unstable patch --- driver/dtrace_linux.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/driver/dtrace_linux.c b/driver/dtrace_linux.c index fb8ac22..e6c9b2e 100644 --- a/driver/dtrace_linux.c +++ b/driver/dtrace_linux.c @@ -2707,15 +2707,14 @@ static struct file_operations proc_dtrace_debug = { /** "proc/dtrace/security" */ static int proc_dtrace_security_show(struct seq_file *seq, void *v) -{ int len = count; +{ char tmpbuf[128]; int i; - int size; /***********************************************/ /* Dump out the security table. */ /***********************************************/ - for (i = 0; i < di_cnt && di_list[i].di_type && len > 0; i++) { + for (i = 0; i < di_cnt && di_list[i].di_type; i++) { char *tp; char *tpend = tmpbuf + sizeof tmpbuf; strcpy(tmpbuf, @@ -2737,8 +2736,7 @@ static int proc_dtrace_security_show(struct seq_file *seq, void *v) if (di_list[i].di_priv & DTRACE_PRIV_OWNER) strcat(tp, " priv_owner"); - size = seq_printf(seq, "%s\n", tmpbuf); - len -= size; + seq_printf(seq, "%s\n", tmpbuf); } return 0; } From cc9086bd20c046e34e3d5f6faf5325a5d9fdf74f Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Sun, 21 Jul 2013 03:10:09 +0400 Subject: [PATCH 06/17] driver: fix file_operations.open callbacks --- driver/dtrace_linux.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/driver/dtrace_linux.c b/driver/dtrace_linux.c index e6c9b2e..676eb8d 100644 --- a/driver/dtrace_linux.c +++ b/driver/dtrace_linux.c @@ -2750,7 +2750,7 @@ static int proc_dtrace_security_seq_open(struct inode *inode, struct file *file) } static struct file_operations proc_dtrace_security = { .owner = THIS_MODULE, - .open = sys_seq_open, + .open = proc_dtrace_security_seq_open, .read = seq_read }; @@ -2859,7 +2859,7 @@ static int proc_dtrace_stats_seq_open(struct inode *inode, struct file *file) } static struct file_operations proc_dtrace_stats = { .owner = THIS_MODULE, - .open = sys_seq_open, + .open = proc_dtrace_stats_seq_open, .read = seq_read }; @@ -2916,7 +2916,7 @@ static int proc_dtrace_trace_seq_open(struct inode *inode, struct file *file) } static struct file_operations proc_dtrace_trace = { .owner = THIS_MODULE, - .open = sys_seq_open, + .open = proc_dtrace_trace_seq_open, .read = seq_read, // TODO: // .write = proc_dtrace_trace_write_proc From 65455a94f11aa6304ba98a8b83da66bc43eec863 Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Sun, 21 Jul 2013 03:11:18 +0400 Subject: [PATCH 07/17] driver: proc_dtrace_stats_show(): drop undefined variable usage --- driver/dtrace_linux.c | 1 - 1 file changed, 1 deletion(-) diff --git a/driver/dtrace_linux.c b/driver/dtrace_linux.c index 676eb8d..3d575f1 100644 --- a/driver/dtrace_linux.c +++ b/driver/dtrace_linux.c @@ -2758,7 +2758,6 @@ static struct file_operations proc_dtrace_security = { static int proc_dtrace_stats_show(struct seq_file *seq, void *v) { int i, size; int n = 0; - char *buf = page; extern unsigned long cnt_0x7f; extern unsigned long cnt_gpf1; extern unsigned long cnt_gpf2; From 29352e63941f18a55c0056273adb5e75a0086648 Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Sun, 21 Jul 2013 03:12:38 +0400 Subject: [PATCH 08/17] driver: proc_dtrace_stats_show(): drop deprecated variables Unstable --- driver/dtrace_linux.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/driver/dtrace_linux.c b/driver/dtrace_linux.c index 3d575f1..e675546 100644 --- a/driver/dtrace_linux.c +++ b/driver/dtrace_linux.c @@ -2756,8 +2756,7 @@ static struct file_operations proc_dtrace_security = { /** "proc/dtrace/stats" */ static int proc_dtrace_stats_show(struct seq_file *seq, void *v) -{ int i, size; - int n = 0; +{ int i; extern unsigned long cnt_0x7f; extern unsigned long cnt_gpf1; extern unsigned long cnt_gpf2; @@ -2830,11 +2829,10 @@ static int proc_dtrace_stats_show(struct seq_file *seq, void *v) {0} }; - for (i = 0; i < MAX_DCNT && n < count; i++) { + for (i = 0; i < MAX_DCNT; i++) { if (dcnt[i] == 0) continue; - size = seq_nprintf(seq, "dcnt%d=%lu\n", i, dcnt[i]); - n += size; + seq_nprintf(seq, "dcnt%d=%lu\n", i, dcnt[i]); } for (i = 0; stats[i].name; i++) { From 2f85d059c458ab549ca60291a11ac0e11ce83fe7 Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Sun, 21 Jul 2013 03:13:03 +0400 Subject: [PATCH 09/17] driver: there is no seq_nprintf() function, replace by seq_printf() --- driver/dtrace_linux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/driver/dtrace_linux.c b/driver/dtrace_linux.c index e675546..14661a8 100644 --- a/driver/dtrace_linux.c +++ b/driver/dtrace_linux.c @@ -2832,7 +2832,7 @@ static int proc_dtrace_stats_show(struct seq_file *seq, void *v) for (i = 0; i < MAX_DCNT; i++) { if (dcnt[i] == 0) continue; - seq_nprintf(seq, "dcnt%d=%lu\n", i, dcnt[i]); + seq_printf(seq, "dcnt%d=%lu\n", i, dcnt[i]); } for (i = 0; stats[i].name; i++) { From c302479ad9afbac9b75bc62141540b355e446652 Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Sun, 21 Jul 2013 03:16:42 +0400 Subject: [PATCH 10/17] driver: implement proc_dtrace_trace_write_proc() callback Possible unstable patch --- driver/dtrace_linux.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/driver/dtrace_linux.c b/driver/dtrace_linux.c index 14661a8..95c5f82 100644 --- a/driver/dtrace_linux.c +++ b/driver/dtrace_linux.c @@ -2893,9 +2893,9 @@ static int proc_dtrace_trace_read_proc(char *page, char **start, off_t off, /**********************************************************************/ /* Special hack for debugging. */ /**********************************************************************/ -static int proc_dtrace_trace_write_proc(struct file *file, const char __user *buffer, - unsigned long count, void *pda) -{ int n = count > 32 ? 32 : count; +static ssize_t proc_dtrace_trace_write_proc(struct file *fp, const char __user *buffer, size_t count, loff_t *off) +{ + int n = count > 32 ? 32 : count; dtrace_printf("proc_dtrace_trace_write_proc: %*.*s\n", n, n, buffer); if (strncmp(buffer, "stack", 5) == 0) @@ -2915,8 +2915,7 @@ static struct file_operations proc_dtrace_trace = { .owner = THIS_MODULE, .open = proc_dtrace_trace_seq_open, .read = seq_read, - // TODO: - // .write = proc_dtrace_trace_write_proc + .write = proc_dtrace_trace_write_proc }; /** \proc */ From 72a3fc6fe2f9faa1f2fa1dddd086399f93d8bd73 Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Sun, 21 Jul 2013 03:21:33 +0400 Subject: [PATCH 11/17] driver: implement proc_dtrace_trace_show() callback Possible incorrect behaviour --- driver/dtrace_linux.c | 30 +++--------------------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/driver/dtrace_linux.c b/driver/dtrace_linux.c index 95c5f82..c77583c 100644 --- a/driver/dtrace_linux.c +++ b/driver/dtrace_linux.c @@ -2863,32 +2863,8 @@ static struct file_operations proc_dtrace_stats = { /** "proc/dtrace/trace" */ static int proc_dtrace_trace_show(struct seq_file *seq, void *v) { - return 0; -} -static int proc_dtrace_trace_read_proc(char *page, char **start, off_t off, - int count, int *eof, void *data) -{ int j; - int pos = 0; - int n = 0; - char *buf = page; - - if (off >= log_bufsiz) { - *eof = 1; - return 0; - } - - j = (dbuf_i + 1) % log_bufsiz; - while (pos < off + count && n < count && j != dbuf_i) { - if (dtrace_buf[j] && pos++ >= off) { - *buf++ = dtrace_buf[j]; - n++; - } - j = (j + 1) % log_bufsiz; - } - if (j == dbuf_i) - *eof = 1; - *start = page; - return n; + // TODO: or we can use dtracedrv_read() instead + return seq_printf(seq, "%s\n", dtrace_buf); } /**********************************************************************/ /* Special hack for debugging. */ @@ -2914,7 +2890,7 @@ static int proc_dtrace_trace_seq_open(struct inode *inode, struct file *file) static struct file_operations proc_dtrace_trace = { .owner = THIS_MODULE, .open = proc_dtrace_trace_seq_open, - .read = seq_read, + .read = seq_read, // dtracedrv_read() ? .write = proc_dtrace_trace_write_proc }; From 5ca298c8fae1a317bf710bf0958a6b457a48cd57 Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Sun, 21 Jul 2013 13:55:56 +0400 Subject: [PATCH 12/17] driver: add {llseek,release} default callbacks --- driver/dtrace_linux.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/driver/dtrace_linux.c b/driver/dtrace_linux.c index c77583c..f62a55a 100644 --- a/driver/dtrace_linux.c +++ b/driver/dtrace_linux.c @@ -2702,6 +2702,8 @@ static int proc_dtrace_debug_seq_open(struct inode *inode, struct file *file) static struct file_operations proc_dtrace_debug = { .owner = THIS_MODULE, .open = proc_dtrace_debug_seq_open, + .llseek = seq_lseek, + .release = seq_release, .read = seq_read }; @@ -2751,6 +2753,8 @@ static int proc_dtrace_security_seq_open(struct inode *inode, struct file *file) static struct file_operations proc_dtrace_security = { .owner = THIS_MODULE, .open = proc_dtrace_security_seq_open, + .llseek = seq_lseek, + .release = seq_release, .read = seq_read }; @@ -2857,6 +2861,8 @@ static int proc_dtrace_stats_seq_open(struct inode *inode, struct file *file) static struct file_operations proc_dtrace_stats = { .owner = THIS_MODULE, .open = proc_dtrace_stats_seq_open, + .llseek = seq_lseek, + .release = seq_release, .read = seq_read }; @@ -2890,6 +2896,8 @@ static int proc_dtrace_trace_seq_open(struct inode *inode, struct file *file) static struct file_operations proc_dtrace_trace = { .owner = THIS_MODULE, .open = proc_dtrace_trace_seq_open, + .llseek = seq_lseek, + .release = seq_release, .read = seq_read, // dtracedrv_read() ? .write = proc_dtrace_trace_write_proc }; From 19cd89aa208941b3c664dfd6432f697124fb5e09 Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Sun, 21 Jul 2013 14:11:02 +0400 Subject: [PATCH 13/17] driver: use single_open() instead of seq_open() for proc/dtrace/debug --- driver/dtrace_linux.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/driver/dtrace_linux.c b/driver/dtrace_linux.c index f62a55a..9122604 100644 --- a/driver/dtrace_linux.c +++ b/driver/dtrace_linux.c @@ -2682,6 +2682,10 @@ dtracedrv_write(struct file *file, const char __user *buf, return count; } +/** + * "proc/dtrace" + */ + /** "proc/dtrace/debug" */ static int proc_dtrace_debug_show(struct seq_file *seq, void *v) { @@ -2692,19 +2696,16 @@ static int proc_dtrace_debug_show(struct seq_file *seq, void *v) cpu_get_id()); return 0; } -static struct seq_operations proc_dtrace_debug_seq_ops = { - .show = proc_dtrace_debug_show -}; -static int proc_dtrace_debug_seq_open(struct inode *inode, struct file *file) +static int proc_dtrace_debug_single_open(struct inode *inode, struct file *file) { - return seq_open(file, &proc_dtrace_debug_seq_ops); + return single_open(file, &proc_dtrace_debug_show, NULL); } static struct file_operations proc_dtrace_debug = { .owner = THIS_MODULE, - .open = proc_dtrace_debug_seq_open, + .open = proc_dtrace_debug_single_open, + .read = seq_read, .llseek = seq_lseek, - .release = seq_release, - .read = seq_read + .release = single_release }; /** "proc/dtrace/security" */ From 556f513e50d6259c8956543bdd0637f22b41502a Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Sun, 21 Jul 2013 14:13:26 +0400 Subject: [PATCH 14/17] driver: use single_open() instead seq_open() for /proc/dtrace/security --- driver/dtrace_linux.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/driver/dtrace_linux.c b/driver/dtrace_linux.c index 9122604..3d8315c 100644 --- a/driver/dtrace_linux.c +++ b/driver/dtrace_linux.c @@ -2744,19 +2744,16 @@ static int proc_dtrace_security_show(struct seq_file *seq, void *v) return 0; } -static struct seq_operations proc_dtrace_security_seq_ops = { - .show = proc_dtrace_security_show -}; -static int proc_dtrace_security_seq_open(struct inode *inode, struct file *file) +static int proc_dtrace_security_single_open(struct inode *inode, struct file *file) { - return seq_open(file, &proc_dtrace_security_seq_ops); + return single_open(file, &proc_dtrace_security_show, NULL); } static struct file_operations proc_dtrace_security = { .owner = THIS_MODULE, - .open = proc_dtrace_security_seq_open, + .open = proc_dtrace_security_single_open, + .read = seq_read, .llseek = seq_lseek, - .release = seq_release, - .read = seq_read + .release = single_release }; /** "proc/dtrace/stats" */ From 00c3d9f7f135cb0f03a5bcd3feb1c61b3c9d2c4e Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Sun, 21 Jul 2013 14:14:23 +0400 Subject: [PATCH 15/17] driver: use single_open() instead of seq_open() for /proc/dtrace/stats --- driver/dtrace_linux.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/driver/dtrace_linux.c b/driver/dtrace_linux.c index 3d8315c..162d204 100644 --- a/driver/dtrace_linux.c +++ b/driver/dtrace_linux.c @@ -2849,19 +2849,16 @@ static int proc_dtrace_stats_show(struct seq_file *seq, void *v) return 0; } -static struct seq_operations proc_dtrace_stats_seq_ops = { - .show = proc_dtrace_stats_show -}; -static int proc_dtrace_stats_seq_open(struct inode *inode, struct file *file) +static int proc_dtrace_stats_single_open(struct inode *inode, struct file *file) { - return seq_open(file, &proc_dtrace_stats_seq_ops); + return single_open(file, &proc_dtrace_stats_show, NULL); } static struct file_operations proc_dtrace_stats = { .owner = THIS_MODULE, - .open = proc_dtrace_stats_seq_open, + .open = proc_dtrace_stats_single_open, + .read = seq_read, .llseek = seq_lseek, - .release = seq_release, - .read = seq_read + .release = single_release }; /** "proc/dtrace/trace" */ From 9ae1fe0eef97c6462790488cc1f6bb7f688b5471 Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Sun, 21 Jul 2013 14:15:57 +0400 Subject: [PATCH 16/17] driver: use single_open() instead of seq_open() for /proc/dtrace/trace --- driver/dtrace_linux.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/driver/dtrace_linux.c b/driver/dtrace_linux.c index 162d204..759d952 100644 --- a/driver/dtrace_linux.c +++ b/driver/dtrace_linux.c @@ -2881,19 +2881,16 @@ static ssize_t proc_dtrace_trace_write_proc(struct file *fp, const char __user * return count; } -static struct seq_operations proc_dtrace_trace_seq_ops = { - .show = proc_dtrace_trace_show -}; -static int proc_dtrace_trace_seq_open(struct inode *inode, struct file *file) +static int proc_dtrace_trace_single_open(struct inode *inode, struct file *file) { - return seq_open(file, &proc_dtrace_trace_seq_ops); + return single_open(file, &proc_dtrace_trace_show, NULL); } static struct file_operations proc_dtrace_trace = { .owner = THIS_MODULE, - .open = proc_dtrace_trace_seq_open, + .open = proc_dtrace_trace_single_open, + .read = seq_read, // dtracedrv_read() ? .llseek = seq_lseek, .release = seq_release, - .read = seq_read, // dtracedrv_read() ? .write = proc_dtrace_trace_write_proc }; From 1a3208fa81ab41bd4649756662419e11c73e98f4 Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Wed, 7 Aug 2013 01:48:23 +0400 Subject: [PATCH 17/17] driver/proc: add compat functions only if kernel < 2.6.25 I remember that Paul, wrote he made a fix by him self, but I also need this, so I fixed it by myself. --- driver/proc_compat.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/driver/proc_compat.h b/driver/proc_compat.h index 6ee8cc0..62f5a7c 100644 --- a/driver/proc_compat.h +++ b/driver/proc_compat.h @@ -2,7 +2,7 @@ /** * proc compat with kernel older 3.10 */ -#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0) +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 25) inline struct proc_dir_entry* proc_create_data( const char *name, umode_t mode, struct proc_dir_entry *parent, const struct file_operations *proc_fops, void *data)