有沒有更好的解決方案來獲取次要號碼?
我可以避免檢查內核版本嗎?
static long unlocked_ioctl(struct file *f, unsigned int o, unsigned long d)
{
#if KERNEL_VERSION(3, 18, 0) > LINUX_VERSION_CODE
struct inode* inode = f->f_dentry->d_inode;
#else
struct inode* inode = f->f_path.dentry->d_inode;
#endif
int minor = iminor(inode);
}
uj5u.com熱心網友回復:
是的,有一個更好的方法:不要費心dentry把你想要的東西當成struct file.
struct file {
union {
struct llist_node fu_llist;
struct rcu_head fu_rcuhead;
} f_u;
struct path f_path;
struct inode *f_inode; // <-- here's your inode
// ...
}
您可以f->f_inode直接訪問或使用該file_inode()功能,這樣您也可以避免內核版本檢查。
static long unlocked_ioctl(struct file *f, unsigned int o, unsigned long d)
{
int minor = iminor(file_inode(f));
// ...
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/407164.html
標籤:
上一篇:`custom_target`的`command`中的ASTERISK(*)介子語法決議器問題-Linux
下一篇:使用jq拆分/切片大型JSON
