2013-10-23 3 views
0

버퍼보다 ​​큰 proc 파일을 읽는 데 문제가 있습니다. 나는이 2 가지 질문을 보았고 나는 뭔가를 놓치고 있다고 생각한다. buffer_location 포인터를 잘못 사용하고 있습니까? 내가 생각처럼 how read to the end of /proc fileprocfile 끝까지 읽는 데 문제가 있습니다

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

How can I read large data from proc file?

는 다시 전화를받을 나던. 내가 도대체 ​​뭘 잘못하고있는 겁니까?

답변

0

eof return 매개 변수를 설정하는 것을 잊어 버리는 것입니다.

*eof = 0; 
return ret; 

까지, 물론, 당신은 더 이상 보낼 데이터가없는 경우는 *eof = 1;

을 설정하는