1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
| #include "toa_proc.h"
#include <linux/fs.h> #include <linux/proc_fs.h> #include <linux/seq_file.h>
static inline bool is_writable(unsigned flags) { return (flags & O_WRONLY) || (flags & O_RDWR) || (flags & O_CREAT) || (flags & O_TRUNC) || (flags & O_APPEND); }
static int toa_proc_enable_show(struct seq_file *m, void *v) { seq_printf(m, "%d\n", is_ftrace_hook_enabled()); return 0; }
static int toa_proc_enable_open(struct inode *inode, struct file *filp) { return single_open(filp, toa_proc_enable_show, inode->i_private); }
static ssize_t toa_proc_enable_write(struct file *file, const char __user *buffer, size_t count, loff_t *pos) { char mode;
if (count > 0) { if (get_user(mode, buffer)) return -EFAULT;
if (mode == '1') { } else if (mode == '0') { } }
return count; }
static int toa_proc_debug_info_show(struct seq_file *m, void *v) { seq_printf(m, "ftrace hook\n"); return 0; }
static int toa_proc_debug_info_open(struct inode *inode, struct file *filp) { return single_open(filp, toa_proc_debug_info_show, inode->i_private); }
struct toa_proc_t { struct proc_dir_entry *main_dir; struct proc_dir_entry *enable_file; struct file_operations enable_fops; struct proc_dir_entry *debug_info_file; struct file_operations debug_info_fops; };
static struct toa_proc_t s_toa_proc = { .debug_info_file = NULL, .debug_info_fops = { .open = toa_proc_debug_info_open, .read = seq_read, .llseek = seq_lseek, .release = single_release, }, .enable_file = NULL, .enable_fops = { .open = toa_proc_enable_open, .read = seq_read, .write = toa_proc_enable_write, .llseek = seq_lseek, .release = single_release, }, .main_dir = NULL, };
int toa_proc_init(void) { int ret = 0;
if (s_toa_proc.main_dir) { return -EEXIST; } s_toa_proc.main_dir = proc_mkdir("sdp-toa", NULL); if (!s_toa_proc.main_dir) { return -EBUSY; }
s_toa_proc.enable_file = proc_create("enable", 0644, s_toa_proc.main_dir, &s_toa_proc.enable_fops); if (!s_toa_proc.enable_file) { ret = -EBUSY; goto err_clean; }
s_toa_proc.debug_info_file = proc_create("debug_info", 0444, s_toa_proc.main_dir, &s_toa_proc.debug_info_fops); if (!s_toa_proc.debug_info_file) { ret = -EBUSY; goto err_clean; }
return 0; err_clean: toa_proc_exit(); return ret; }
void toa_proc_exit(void) { if (s_toa_proc.debug_info_file) { proc_remove(s_toa_proc.debug_info_file); s_toa_proc.debug_info_file = NULL; }
if (s_toa_proc.enable_file) { proc_remove(s_toa_proc.enable_file); s_toa_proc.enable_file = NULL; }
if (s_toa_proc.main_dir) { proc_remove(s_toa_proc.main_dir); s_toa_proc.main_dir = NULL; } }
|