[英]Write to debugfs from Linux Kernel Module
我已經成功地在匹配路徑中創建了一個dentry
,但是現在我該如何實際編寫呢?
struct dentry* log_dir = debugfs_create_dir ("my_module", NULL);
struct dentry* log_file = debugfs_create_dir ("log", 0777, log_dir, NULL, NULL);
我想說,關於您需要做什么的最佳參考是內核源代碼樹中的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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.