建立乙個簡單的debugfs檔案系統節點

2021-07-25 16:04:35 字數 933 閱讀 3014

有時為了除錯方便,需要建立乙個檔案節點,供上層呼叫,下面是乙個較簡單的例子;

可以在其基礎上,稍加修改名字,即可使用。

static ssize_t usb_hnp_show(struct file *file, char __user *user_buf,

size_t count, loff_t *ppos)

dev_err(&udev->dev, "zsm %s\n", __func__);

return ret;

}static ssize_t usb_hnp_store(struct file *file,

const char __user *user_buf, size_t count,

loff_t *ppos)

dev_err(&udev->dev, "zsm %s\n", __func__);

buf_size = min(count, (size_t)(sizeof(buf)-1));

if (copy_from_user(buf, user_buf, buf_size))

buf[buf_size] = 0;

return buf_size;

}static const struct file_operations usb_hnp_node_fops = ;

註冊部分**可以放在乙個probe函式裡,如下:

struct dentry *usb_hnp_dentry;

usb_hnp_dentry = debugfs_create_file("enable_usb_hnp",

s_irugo, null, null, &usb_hnp_node_fops);

編譯執行後,生成的目錄在

/sys/kernel/debug/ 下。

建立乙個簡單的執行緒

handle createthread in opt lpsecurity attributes lpthreadattributes,security attributes 結構指定了這個執行緒的安全屬性,如果填 null 則就以預設的安全描述子建立,並且返回的控制代碼不會被繼承。in size ...

建立乙個簡單的畫板

1.cv.createtrackbar 有5個引數 滑動條的名字 視窗的名字 數值的最小值 數值的最大值 函式2.cv.gettrackbarpos 有2個引數 滑動條的名字 視窗的名字 函式的返回值是滑動條的數值。import cv2 as cv import numpy as np def no...

建立乙個簡單的systemverilog程式

作為乙個物件導向的語言,免不了來乙個國際慣例 hello world!下面是完整的 program tb initial begin display hello,world endendprogram 用modelsim進行編譯和執行 hello,world 解釋 跟c語言的main函式類似,sv語...