LDD-Tricks

/proc

/proc filesystem is a special, software-created filesystem that is used by the kernel to export information to the world.
If you want to work with /proc, include <linux/proc_fs.h>.
We don't suggest you create a file in /proc, but if do want to do this, do the following steps:
Implement your read_proc function
int (*read_proc)(char *page, char **start, off_t offset, int count, int *eof, void *data);
Connect the read_proc to an entry in /proc hierarchy with create_proc_read_entry
struct proc_dir_entry *create_proc_read_entry(const char *name, mode_t mode,
                   struct proc_dir_entry *base,read_proc_t *read_proc, void *data);
while remove_proc_entry does the contrary.
 
Debug

Add macros in header files:
 1 #undef PDEBUG /* undef it, just in case */
 2 #ifdef SCULL_DEBUG
 3 #ifdef __KERNEL__
 4 /* This one if debugging is on, and kernel space */ 
 5 #define PDEBUG(fmt, args...) printk( KERN_DEBUG "scull: " fmt, ## args)
 6 #else  /* This one for user space */ 
 7 #define PDEBUG(fmt, args...) fprintf(stderr, fmt, ## args)
 8 #endif
 9 #else
10 #define PDEBUG(fmt, args...) /* not debugging: nothing */
11 #endif
12 #undef PDEBUGG
13 #define PDEBUGG(fmt, args...) /* nothing: it's a placeholder */
Add following lines to makefile:
1 # Comment/uncomment the following line to disable/enable debugging
2 DEBUG = y
3 # Add your debugging flag (or not) to CFLAGS
4 ifeq ($(DEBUG),y)
5     DEBFLAGS = -O -g -DSCULL_DEBUG # "-O" is needed to expand inlines
6 else   
7     DEBFLAGS = -O2
8 endif
9 CFLAGS += $(DEBFLAGS)

 

 
posted @ 2018-11-07 10:46  glob  阅读(136)  评论(0编辑  收藏  举报