我已经成功地在匹配路径中创建了一个dentry,但是现在我如何在那里实际编写代码呢?
struct dentry* log_dir = debugfs_create_dir ("my_module", NULL);
struct dentry* log_file = debugfs_create_dir ("log", 0777, log_dir, NULL, NULL);发布于 2017-02-15 05:00:13
我想说,您需要做的最好的参考资料是内核源代码树中的debugfs.txt文档文件。
我还假设您在这里的代码示例中犯了一个错误:
struct dentry* log_file = debugfs_create_dir ("log", 0777, log_dir, NULL, NULL);因为看起来您正在尝试创建一个文件,而不是另一个目录。所以我猜你想要做的更像这样:
struct dentry* log_file = debugfs_create_file("log", 0777, log_dir, NULL, &log_fops);其中log_fops可能是这样的:
static const struct file_operations log_fops = {
.owner = THIS_MODULE,
.read = log_read,
.write = log_write, /* maybe you don't need this */
};当然,您还需要实现log_read和log_write函数:
ssize_t log_read(struct file *file, char __user *buff, size_t count, loff_t *offset);
ssize_t log_write(struct file *file, const char __user *buff, size_t count, loff_t *offset);https://stackoverflow.com/questions/42235800
复制相似问题