0

I am having trouble reading a proc file that is larger than the buffer. I have looked at these 2 questions and I think I am missing something. Am I using the buffer_location pointer incorrectly?

How can I read large data from proc file?

how read to the end of /proc file

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;
}

However my procfile_read doesnt get called again, like I thought. What am I doing wrong?

Community
  • 1
  • 1
whwright
  • 531
  • 2
  • 7
  • 21

1 Answers1

0

You're forgetting to set the eof return paramater.

*eof = 0;
return ret;

Until, of course, you have no more data to send, in which case set *eof = 1;

Peter
  • 14,559
  • 35
  • 55