Re: create_proc_info_entry

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2007/5/31, Thomas De Schampheleire <patrickdepinguin@xxxxxxxxx>:
2007/5/31, Greg Donald <gdonald@xxxxxxxxx>:
> When I use create_proc_info_entry thusly:
>
> create_proc_info_entry( "foo/bar", 0, 0, show_foo_bar );
>
> The signature of the show_foo_bar function seems required to be:
>
> static int show_foo_bar( char *buffer, char **start, off_t offset, int length )
>
> If I change that whatsoever I get this warning: function declaration
> isn't a prototype, when it is called.  Ok, but what if I just want my
> proc info entry to display something really static, like say, the
> integer 17?
>
> static int show_foo_bar( char *buffer, char **start, off_t offset, int length )
> {
>   int size;
>   size = 17;
>   return size;
> }
>
> And then I do:
>
> > cat /proc/foo/bar
> ?UU0
>
> But that's not the integer 17.
>

IIRC (didn't look this up recently and it's been a while), the return
value should be the number of characters actually written, so the
caller (the reader of your proc entry) knows whether an error occurs,
or how long the buffer is.

In order to write 17, you should use something like
int len;
int size = 17;
len = snprintf(buffer, sizeof(int), "%d", size)
return len;

I think my original example is not completely correct: sizeof(int)
probably needs to be the number of characters written, in this case 2
if you print "17".


I think in order to be correct, you should also handle the offset and
start values correctly.

HTH,
Thomas

>
> --
> Greg Donald
> http://destiney.com/
>
> --
> To unsubscribe from this list: send an email with
> "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
> Please read the FAQ at http://kernelnewbies.org/FAQ
>
>


--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux