列出目录下的文件的内核模块
来源:互联网 发布:linux gdb调试 编辑:程序博客网 时间:2024/04/29 18:36
在调试一个文件系统时,需要看看挂载后文件系统的目录,写了一个列文件的内核模块。
使用方法:
insmod fs_test.ko path='/dev'
默认路径是/。 该模块不会被插入内核,列完目录后退出。
fs_test.h
#ifndef __FS_TEST_H__#define __FS_TEST_H__#define FS_TEST_DEBUG#define MY_MODULE_NAME "fs_test"#define MY_MODULE_LICENSE "GPL"#define MY_MODULE_AUTHOR "Hansel He"#define MY_MODULE_DESCRIPTION "Support File System Debug"/*------------------------------------------------*/#ifdef FS_TEST_DEBUG#define FM_PRINTF(fmt, arg...) printk("[fs_test: %s():%d] " fmt, __FUNCTION__, __LINE__, ##arg)#define FM_PRINTFN(fmt, arg...) FM_PRINTF(fmt "\n", ##arg)#else#define FM_PRINTF(fmt, arg...)#define FM_PRINTFN(fmt, arg...)#endif/*---------------------------------------*/typedef struct { int count;}FS_TEST_DATA;#endif
fs_test_main.c
/**************************************************************************************** * File:fs_test.c * * Description:FS Debug Module * Version:1.0 * * * * * Change Log: * * Date By Description * =========== ======== ============================================================= * 2011.12.03 HanselCreate ****************************************************************************************/#include <linux/config.h>#include <linux/module.h>#include <linux/types.h>#include <linux/errno.h>#include <linux/version.h>#include <linux/proc_fs.h>#include <linux/init.h>#include <linux/string.h>#include <linux/fs.h>#include <linux/syscalls.h>#include <linux/dirent.h>#include <linux/file.h>#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)#include <linux/moduleparam.h>#endif#include "fs_test.h"//extern unsigned long simple_strtoul(const char *cp,char **endp,unsigned int base);/*----------------------------------------------*/static char *path = "/";/*********************************************************************************************//*********************************************************************************************/static int ls_filldir(void * __buf, const char * name, int namlen, loff_t offset, ino_t ino, unsigned int d_type){ FS_TEST_DATA *data = (FS_TEST_DATA*)__buf; printk("#%d name=%s, type=%u\n", data->count++, name, d_type); return 0;}static int fs_ls(char * dir_path){ struct file * file;int err = 0; FS_TEST_DATA data = {0}; file = filp_open((const char __user *) dir_path, O_RDONLY|O_DIRECTORY, 0);if (IS_ERR(file)){err = -EBADF; printk("Error: unable to get file struct for path %s \n", dir_path); goto no_file;}err = vfs_readdir(file, ls_filldir, &data); if (err < 0){ printk("Error: vfs_readdir() return %d.\n", err);goto ls_out; } err = 0;ls_out: filp_close(file, 0);no_file: return err;}static int __initmod_init(void){ int ret = 0; ret = fs_ls(path); // not insert modereturn -1;}static void mod_exit(void){}module_init(mod_init);module_exit(mod_exit);module_param(path, charp, 0);MODULE_LICENSE(MY_MODULE_LICENSE);MODULE_AUTHOR(MY_MODULE_AUTHOR);MODULE_DESCRIPTION(MY_MODULE_DESCRIPTION);
- 列出目录下的文件的内核模块
- 列出目录下的文件
- 列出目录下的文件
- 列出某个目录下的所有文件
- 列出文件或目录下的文件名
- Delphi 列出目录下的文件
- PYTHON 列出指定目录下的文件
- 列出目录下的所有文件
- 列出指定目录下的文件
- 递归列出目录下的所有文件
- python列出目录下所有的文件
- python 列出文件目录下的文件名
- java列出指定目录下的文件
- java列出目录下的所有文件
- java列出目录下的所有文件
- 列出一个目录下的所有文件
- python 列出目录下的文件
- 列出某个目录下的所有文件和列出某目录下所有的子目录
- 七夕怀念
- 归并排序(java实现)
- Hash算法
- 各种数据库对应的jar包、驱动类名和URL格式
- 爱是永久相思情
- 列出目录下的文件的内核模块
- {"当 IDENTITY_INSERT 设置为 OFF 时,不能向表 'OrderList' 中的标识列插入显式值"}
- 套接字地址结构
- sql convert日期转换
- 汉字编码对照表(gb2312/unicode/utf8)
- 好久没有写博客了
- java mail(另一种方式)
- 心醉七夕
- Ubuntu Server 启用root用户,设置root密码