我无法读取大于缓冲区的 proc 文件。我看过这两个问题,我想我遗漏了一些东西。我是否错误地使用了 buffer_location 指针?
int procfile_read(char *buffer, char **buffer_location, off_t offset, int buffer_length, int *eof, void *data) {
int ret;
//this function reads a data structure and fills the char* messages
read_log();
if( strlen(messages) < buffer_length ) {
//if the string is less than the size of the buffer read it all
memcpy(buffer, messages, strlen(messages)+1);
ret = strlen(messages)+1;
kfree(messages);
}
else {
//read just the buffer_length
memcpy(buffer, messages, buffer_length);
//move the messages char * up for the next read
char *temp = kmalloc(strlen(messages)-buffer_length+1, GFP_KERNEL);
strcpy(temp, messages+buffer_length);
kfree(messages);
messages = temp;
//from the question linked above I am putting my first lump of data
//into the buffer, setting *buffer_location = buffer, and returning buffer_length
*buffer_location = buffer;
ret = buffer_length;
}
return ret;
}
然而,我的 procfile_read 不会再被调用,就像我想的那样。我究竟做错了什么?