From 9c33abac953e24f0cd61ca9ca40e59168ae65d06 Mon Sep 17 00:00:00 2001 From: gatieme Date: Sat, 25 Mar 2017 18:16:24 +0800 Subject: [PATCH] debugfs... --- study/debug/debugfs/README.md | 37 ++++++ study/debug/debugfs/debugfs/Makefile | 81 +++++++++++++ study/debug/debugfs/debugfs/my_debugfs.c | 106 ++++++++++++++++++ study/{ => debug}/proc/README.md | 0 .../proc/create_proc_entry/Makefile | 0 .../proc/create_proc_entry/README.md | 0 .../proc/create_proc_entry/hello_proc.c | 0 .../proc/create_proc_entry/hello_proc.c.bak | 0 .../{ => debug}/proc/create_proc_entry/jif.c | 0 .../{ => debug}/proc/create_proc_entry/test.c | 0 .../proc/create_proc_entry/test2.c | 0 study/{ => debug}/proc/proc_create/3.c | 0 study/{ => debug}/proc/proc_create/Makefile | 0 study/{ => debug}/proc/proc_create/jif.c | 0 study/{ => debug}/proc/proc_create/test.c | 0 study/{ => debug}/proc/proc_create/test2.c | 0 .../proc/proc_create_data/Makefile | 0 study/{ => debug}/proc/proc_create_data/jif.c | 0 study/{ => debug}/proc/proc_final/Makefile | 0 study/{ => debug}/proc/proc_final/common.h | 0 study/{ => debug}/proc/proc_final/config.h | 0 study/{ => debug}/proc/proc_final/main.c | 0 study/{ => debug}/proc/proc_final/main.h | 0 study/{ => debug}/proc/proc_final/ro.c | 0 study/{ => debug}/proc/proc_final/rw.c | 0 study/{ => debug}/proc/proc_final/wo.c | 0 study/{ => debug}/proc/seq_file_exam/Makefile | 0 .../proc/seq_file_exam/seq_file_exam.c | 0 28 files changed, 224 insertions(+) create mode 100644 study/debug/debugfs/README.md create mode 100644 study/debug/debugfs/debugfs/Makefile create mode 100644 study/debug/debugfs/debugfs/my_debugfs.c rename study/{ => debug}/proc/README.md (100%) rename study/{ => debug}/proc/create_proc_entry/Makefile (100%) rename study/{ => debug}/proc/create_proc_entry/README.md (100%) rename study/{ => debug}/proc/create_proc_entry/hello_proc.c (100%) rename study/{ => debug}/proc/create_proc_entry/hello_proc.c.bak (100%) rename study/{ => debug}/proc/create_proc_entry/jif.c (100%) rename study/{ => debug}/proc/create_proc_entry/test.c (100%) rename study/{ => debug}/proc/create_proc_entry/test2.c (100%) rename study/{ => debug}/proc/proc_create/3.c (100%) rename study/{ => debug}/proc/proc_create/Makefile (100%) rename study/{ => debug}/proc/proc_create/jif.c (100%) rename study/{ => debug}/proc/proc_create/test.c (100%) rename study/{ => debug}/proc/proc_create/test2.c (100%) rename study/{ => debug}/proc/proc_create_data/Makefile (100%) rename study/{ => debug}/proc/proc_create_data/jif.c (100%) rename study/{ => debug}/proc/proc_final/Makefile (100%) rename study/{ => debug}/proc/proc_final/common.h (100%) rename study/{ => debug}/proc/proc_final/config.h (100%) rename study/{ => debug}/proc/proc_final/main.c (100%) rename study/{ => debug}/proc/proc_final/main.h (100%) rename study/{ => debug}/proc/proc_final/ro.c (100%) rename study/{ => debug}/proc/proc_final/rw.c (100%) rename study/{ => debug}/proc/proc_final/wo.c (100%) rename study/{ => debug}/proc/seq_file_exam/Makefile (100%) rename study/{ => debug}/proc/seq_file_exam/seq_file_exam.c (100%) diff --git a/study/debug/debugfs/README.md b/study/debug/debugfs/README.md new file mode 100644 index 0000000..40f10b0 --- /dev/null +++ b/study/debug/debugfs/README.md @@ -0,0 +1,37 @@ +You-Get--基于Python3的开源网络视频下载工具 +======= + +| CSDN | GitHub | +|:----:|:------:| +| [You-Get--基于Python3的开源网络视频下载工具](http://blog.csdn.net/gatieme/article/details/61623891) | [`AderXCoding/system/tools/you-get`](https://github.com/gatieme/AderXCoding/tree/master/system/tools/you-get) | + +
+知识共享许可协议 +本作品采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可, 转载请注明出处, 谢谢合作 +
+ + +[Linux内核里的DebugFS](http://www.cnblogs.com/wwang/archive/2011/01/17/1937609.html) + +[Debugging the Linux Kernel with debugfs](http://opensourceforu.com/2010/10/debugging-linux-kernel-with-debugfs/) + +[debugfs-seq_file](http://lxr.free-electrons.com/source/drivers/base/power/wakeup.c) + + +[Linux Debugfs文件系统介绍及使用](http://blog.sina.com.cn/s/blog_40d2f1c80100p7u2.html) + +[Linux 文件系统:procfs, sysfs, debugfs 用法简介](http://www.tinylab.org/show-the-usage-of-procfs-sysfs-debugfs/) + +[用户空间与内核空间数据交换的方式(1)------debugfs](http://www.cnblogs.com/hoys/archive/2011/04/10/2011124.html) + + +[Linux 运用debugfs调试方法](http://www.xuebuyuan.com/1023006.html) + + +误删恢复 +---- +[linux 删除文件和目录与恢复详解](http://www.111cn.net/sys/linux/47629.htm) + +
+ +知识共享许可协议本作品采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可, 转载请注明出处, 谢谢合作. diff --git a/study/debug/debugfs/debugfs/Makefile b/study/debug/debugfs/debugfs/Makefile new file mode 100644 index 0000000..7f8d7ec --- /dev/null +++ b/study/debug/debugfs/debugfs/Makefile @@ -0,0 +1,81 @@ +# ------------------------------------------------------------------------------ +# +# Makefile for the LDD-LinuxDeviceDrivers. +# +# Author: gatieme +# Create: 2016-07-29 15:50:46 +# Last modified: 2016-07-29 16:10:29 +# Description: +# This program is loaded as a kernel(v2.6.18 or later) module. +# Use "make install" to load it into kernel. +# Use "make remove" to remove the module out of kernel. +# +# ------------------------------------------------------------------------------ + + +ROOT=.. +#PLATFORM=$(shell $(ROOT)/systype.sh) +#include $(ROOT)/Make.defines.$(PLATFORM) + +# my driver description +DRIVER_VERSION := "1.0.0" +DRIVER_AUTHOR := "Gatieme @ AderStep Inc..." +DRIVER_DESC := "Linux input module for Elo MultiTouch(MT) devices" +DRIVER_LICENSE := "Dual BSD/GPL" + + +MODULE_NAME := my_debugfs +MODCFLAGS:=-O6 -Wall -DMODULE -D__KERNEL__ -DLINUX -std=c99 + + + +ifneq ($(KERNELRELEASE),) + +#CFG_FLAGS += -O2 -I./ +#EXTRA_CFLAGS += $(C_FLAGS) $(CFG_INC) $(CFG_INC) + + + +obj-m := $(MODULE_NAME).o #print_vmarea.o + +else + +KERNELDIR ?= /lib/modules/$(shell uname -r)/build + +PWD := $(shell pwd) + +modules: + make -C $(KERNELDIR) M=$(PWD) modules + +modules_install: + make -C $(KERNELDIR) M=$(PWD) modules_install + + + +insmod: + sudo insmod $(MODULE_NAME).ko + +reinsmod: + sudo rmmod $(MODULE_NAME) + sudo insmod $(MODULE_NAME).ko + +github: + cd $(ROOT) && make github + +rmmod: + sudo rmmod $(MODULE_NAME) + +test : + sudo ../injector/memInjector -l stack -m random -t word_0 --time 1 --timeout 3 -p 1 + +clean: + make -C $(KERNELDIR) M=$(PWD) clean + rm -f modules.order Module.symvers Module.markers + +.PHNOY: + modules modules_install clean + + + +endif + diff --git a/study/debug/debugfs/debugfs/my_debugfs.c b/study/debug/debugfs/debugfs/my_debugfs.c new file mode 100644 index 0000000..a72329a --- /dev/null +++ b/study/debug/debugfs/debugfs/my_debugfs.c @@ -0,0 +1,106 @@ +#include +#include +#include +#include +#include + +struct dentry *my_debugfs_root; + +u8 a = 0; +char hello[32] = "Hello world!\n"; +struct debugfs_blob_wrapper b; + +static int c_open(struct inode *inode, struct file *filp) +{ + filp->private_data = inode->i_private; + return 0; +} + +static ssize_t c_read(struct file *filp, char __user *buffer, + size_t count, loff_t *ppos) +{ + if (*ppos >= 32) + return 0; + if (*ppos + count > 32) + count = 32 - *ppos; + + if (copy_to_user(buffer, hello + *ppos, count)) + return -EFAULT; + + *ppos += count; + + return count; +} + +static ssize_t c_write(struct file *filp, const char __user *buffer, + size_t count, loff_t *ppos) +{ + if (*ppos >= 32) + return 0; + if (*ppos + count > 32) + count = 32 - *ppos; + + if (copy_from_user(hello + *ppos, buffer, count)) + return -EFAULT; + + *ppos += count; + + return count; +} + +struct file_operations c_fops = { + .owner = THIS_MODULE, + .open = c_open, + .read = c_read, + .write = c_write, +}; + +static int __init mydebugfs_init(void) +{ + struct dentry *sub_dir, *r_a, *r_b, *s_c; + + printk(KERN_INFO "mydebugfs_init\n"); + + my_debugfs_root = debugfs_create_dir("mydebug", NULL); + if (!my_debugfs_root) + return -ENOENT; + + r_a = debugfs_create_u8("a", 0644, my_debugfs_root, &a); + if (!r_a) + goto Fail; + + b.data = (void *)hello; + b.size = strlen(hello) + 1; + r_b = debugfs_create_blob("b", 0644, my_debugfs_root, &b); + if (!r_b) + goto Fail; + + sub_dir = debugfs_create_dir("subdir", my_debugfs_root); + if (!sub_dir) + goto Fail; + + s_c = debugfs_create_file("c", 0644, sub_dir, NULL, &c_fops); + if (!s_c) + goto Fail; + + return 0; + +Fail: + debugfs_remove_recursive(my_debugfs_root); + my_debugfs_root = NULL; + return -ENOENT; +} + +static void __exit mydebugfs_exit(void) +{ + printk(KERN_INFO "mydebugfs_exit\n"); + debugfs_remove_recursive(my_debugfs_root); + + return; +} + +module_init(mydebugfs_init); +module_exit(mydebugfs_exit); + +MODULE_LICENSE("GPL"); + diff --git a/study/proc/README.md b/study/debug/proc/README.md similarity index 100% rename from study/proc/README.md rename to study/debug/proc/README.md diff --git a/study/proc/create_proc_entry/Makefile b/study/debug/proc/create_proc_entry/Makefile similarity index 100% rename from study/proc/create_proc_entry/Makefile rename to study/debug/proc/create_proc_entry/Makefile diff --git a/study/proc/create_proc_entry/README.md b/study/debug/proc/create_proc_entry/README.md similarity index 100% rename from study/proc/create_proc_entry/README.md rename to study/debug/proc/create_proc_entry/README.md diff --git a/study/proc/create_proc_entry/hello_proc.c b/study/debug/proc/create_proc_entry/hello_proc.c similarity index 100% rename from study/proc/create_proc_entry/hello_proc.c rename to study/debug/proc/create_proc_entry/hello_proc.c diff --git a/study/proc/create_proc_entry/hello_proc.c.bak b/study/debug/proc/create_proc_entry/hello_proc.c.bak similarity index 100% rename from study/proc/create_proc_entry/hello_proc.c.bak rename to study/debug/proc/create_proc_entry/hello_proc.c.bak diff --git a/study/proc/create_proc_entry/jif.c b/study/debug/proc/create_proc_entry/jif.c similarity index 100% rename from study/proc/create_proc_entry/jif.c rename to study/debug/proc/create_proc_entry/jif.c diff --git a/study/proc/create_proc_entry/test.c b/study/debug/proc/create_proc_entry/test.c similarity index 100% rename from study/proc/create_proc_entry/test.c rename to study/debug/proc/create_proc_entry/test.c diff --git a/study/proc/create_proc_entry/test2.c b/study/debug/proc/create_proc_entry/test2.c similarity index 100% rename from study/proc/create_proc_entry/test2.c rename to study/debug/proc/create_proc_entry/test2.c diff --git a/study/proc/proc_create/3.c b/study/debug/proc/proc_create/3.c similarity index 100% rename from study/proc/proc_create/3.c rename to study/debug/proc/proc_create/3.c diff --git a/study/proc/proc_create/Makefile b/study/debug/proc/proc_create/Makefile similarity index 100% rename from study/proc/proc_create/Makefile rename to study/debug/proc/proc_create/Makefile diff --git a/study/proc/proc_create/jif.c b/study/debug/proc/proc_create/jif.c similarity index 100% rename from study/proc/proc_create/jif.c rename to study/debug/proc/proc_create/jif.c diff --git a/study/proc/proc_create/test.c b/study/debug/proc/proc_create/test.c similarity index 100% rename from study/proc/proc_create/test.c rename to study/debug/proc/proc_create/test.c diff --git a/study/proc/proc_create/test2.c b/study/debug/proc/proc_create/test2.c similarity index 100% rename from study/proc/proc_create/test2.c rename to study/debug/proc/proc_create/test2.c diff --git a/study/proc/proc_create_data/Makefile b/study/debug/proc/proc_create_data/Makefile similarity index 100% rename from study/proc/proc_create_data/Makefile rename to study/debug/proc/proc_create_data/Makefile diff --git a/study/proc/proc_create_data/jif.c b/study/debug/proc/proc_create_data/jif.c similarity index 100% rename from study/proc/proc_create_data/jif.c rename to study/debug/proc/proc_create_data/jif.c diff --git a/study/proc/proc_final/Makefile b/study/debug/proc/proc_final/Makefile similarity index 100% rename from study/proc/proc_final/Makefile rename to study/debug/proc/proc_final/Makefile diff --git a/study/proc/proc_final/common.h b/study/debug/proc/proc_final/common.h similarity index 100% rename from study/proc/proc_final/common.h rename to study/debug/proc/proc_final/common.h diff --git a/study/proc/proc_final/config.h b/study/debug/proc/proc_final/config.h similarity index 100% rename from study/proc/proc_final/config.h rename to study/debug/proc/proc_final/config.h diff --git a/study/proc/proc_final/main.c b/study/debug/proc/proc_final/main.c similarity index 100% rename from study/proc/proc_final/main.c rename to study/debug/proc/proc_final/main.c diff --git a/study/proc/proc_final/main.h b/study/debug/proc/proc_final/main.h similarity index 100% rename from study/proc/proc_final/main.h rename to study/debug/proc/proc_final/main.h diff --git a/study/proc/proc_final/ro.c b/study/debug/proc/proc_final/ro.c similarity index 100% rename from study/proc/proc_final/ro.c rename to study/debug/proc/proc_final/ro.c diff --git a/study/proc/proc_final/rw.c b/study/debug/proc/proc_final/rw.c similarity index 100% rename from study/proc/proc_final/rw.c rename to study/debug/proc/proc_final/rw.c diff --git a/study/proc/proc_final/wo.c b/study/debug/proc/proc_final/wo.c similarity index 100% rename from study/proc/proc_final/wo.c rename to study/debug/proc/proc_final/wo.c diff --git a/study/proc/seq_file_exam/Makefile b/study/debug/proc/seq_file_exam/Makefile similarity index 100% rename from study/proc/seq_file_exam/Makefile rename to study/debug/proc/seq_file_exam/Makefile diff --git a/study/proc/seq_file_exam/seq_file_exam.c b/study/debug/proc/seq_file_exam/seq_file_exam.c similarity index 100% rename from study/proc/seq_file_exam/seq_file_exam.c rename to study/debug/proc/seq_file_exam/seq_file_exam.c