这是我的第一个内核,在下面的示例程序中,我创建了一个简单的 proc/文件系统。每当我对内核进行分类时,我都会看到 READ 被调用 3 次。想知道它为什么这样做。
出来,代码如下。
cat /proc/myKernel
dmesg | grep -i myKernel
myKernel: Read (/proc/myKernel) called
myKernel: Read (/proc/myKernel) called
myKernel: Read (/proc/myKernel) called
int myKernel_read( char *buffer, char **bufferLocation, off_t offset, int bufferLength, int *eof, void *data )
{
int ret = 0;
u64 msrvalue;
printk(KERN_INFO "myKernel: Read (/proc/%s) called\n", procFile_name);
ret = sprintf(buffer, "Hello World\n");
return ret;
}
static int __init myKernel_init(void)
{
entry = create_proc_entry(procFile_name, 0644, NULL);
if(!entry)
printk(KERN_INFO "myKernel: error registering proc control file\n");
else
{
entry->read_proc = myKernel_read;
}
return 0;
}