2 #include <linux/slab.h>
3 #include <linux/debugfs.h>
4 #include <linux/module.h>
5 #include <asm/uaccess.h>
6 #include <master/swap_debugfs.h>
8 #include "uihv_module.h"
10 static const char UIHV_FOLDER[] = "uihv";
11 static const char UIHV_PATH[] = "path";
12 static const char UIHV_APP_INFO[] = "app_info";
14 static struct dentry *uihv_root;
18 /* ===========================================================================
20 * ===========================================================================
24 static ssize_t uihv_path_write(struct file *file, const char __user *buf,
25 size_t len, loff_t *ppos)
30 path = kmalloc(len, GFP_KERNEL);
33 goto uihv_path_write_out;
36 if (copy_from_user(path, buf, len)) {
38 goto uihv_path_write_out;
43 if (uihv_set_handler(path) != 0) {
44 printk(UIHV_PREFIX "Cannot set ui viewer path %s\n", path);
46 goto uihv_path_write_out;
51 printk(UIHV_PREFIX "Set ui viewer path %s\n", path);
59 static const struct file_operations uihv_path_file_ops = {
61 .write = uihv_path_write,
70 * 0x00000d60:/bin/app_sample
72 static int uihv_add_app_info(const char *buf, size_t len)
76 unsigned long main_addr;
77 const char fmt[] = "%%lx:/%%%ds";
80 n = snprintf(fmt_buf, sizeof(fmt_buf), fmt, PATH_MAX - 2);
84 app_path = kmalloc(PATH_MAX, GFP_KERNEL);
88 n = sscanf(buf, fmt_buf, &main_addr, app_path + 1);
95 printk(UIHV_PREFIX "Set ui viewer app path %s, main offset 0x%lx\n", app_path, main_addr);
97 ret = uihv_data_set(app_path, main_addr);
104 static ssize_t write_uihv_app_info(struct file *file,
105 const char __user *user_buf,
106 size_t len, loff_t *ppos)
111 buf = kmalloc(len, GFP_KERNEL);
117 if (copy_from_user(buf, user_buf, len)) {
124 if (uihv_add_app_info(buf, len))
133 static const struct file_operations uihv_app_info_file_ops = {
134 .owner = THIS_MODULE,
135 .write = write_uihv_app_info,
139 int uihv_dfs_init(void)
141 struct dentry *swap_dentry, *root, *path, *app_info;
145 if (!debugfs_initialized())
149 swap_dentry = swap_debugfs_getdir();
154 root = debugfs_create_dir(UIHV_FOLDER, swap_dentry);
155 if (IS_ERR_OR_NULL(root))
160 path = debugfs_create_file(UIHV_PATH, UIHV_DEFAULT_PERMS, root,
161 NULL, &uihv_path_file_ops);
162 if (IS_ERR_OR_NULL(path)) {
167 app_info = debugfs_create_file(UIHV_APP_INFO, UIHV_DEFAULT_PERMS,
168 root, NULL, &uihv_app_info_file_ops);
169 if (IS_ERR_OR_NULL(app_info)) {
177 debugfs_remove_recursive(root);
180 printk(UIHV_PREFIX "Debugfs initialization failure: %d\n", ret);
185 void uihv_dfs_exit(void)
188 debugfs_remove_recursive(uihv_root);