我正在尝试从用户空间打开一个proc文件,所以我可以写入它,但是当我打开它时,我得到Permission denied
。下面是我如何创建proc文件。我已经尝试过使用权限,但我似乎无法让它工作。
struct proc_dir_entry procDir = NULL;
struct proc_dir_entry infofile = NULL;
static struct seq_operations seqOps = {
.start = seqStart,
.next = seqNext,
.stop = seqStop,
.show = seqShow
};
static int open(struct inode *inode, struct file *fp)
{
return seq_open(fp, &seqOps);
}
static const struct file_operations fops = {
.owner = THIS_MODULE,
.open = open,
.read = read,
.write = write,
.llseek = lseek,
.release = single_release,
};
static int __init app_init(void)
{
procDir = proc_mkdir("app", NULL);
infofile = proc_create("info", 0, procDir, &fops);
//infofile = proc_create("info", 777, procDir, &fops); // also tried this
}
以下是我尝试从用户空间打开它的方法。
fopen("/proc/app/info", "wb+");
模块加载正常,当我运行ls /proc/app/
时,proc文件结构就在那里。谢谢,任何帮助表示赞赏!