Re: by default, does seq_file start() routine start at zero offset?

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

 




 but i don't think that answers my question -- sure, i'll honour the
provided value, but what *is* that provided value by default?  in
every example i've seen, it seems to be clear that that example will
work properly only if that original start offset is zero.

 the code in fs/proc/devices.c is a good example.  if that initial
offset was something other than zero, the output would be totally
screwed and miss printing some lines, no?

Yes, screwed 8^)

Consider an ordered array, If *pos != 0, you could return data using *pos as a simple byte offset or you could use *pos as an element offset into your array (it's up to you). 

My usage right now involves returning arrayed kernel data expressed as XML, I allow for the user to skip into the array (by elements) if they choose to on some tables and others I allow them only to start at the beginning. In these cases, if *pos != 0, I return NULL (for the start*() methods).
If the next*() method is offset past the end of my array, I return NULL, otherwise I increment *pos (as most generic examples will show).

*pos is really just a tool for the user. If you want your data to behave as a "normal" block file, you have the onus to provide the mechanism for indexing into your data with *pos and maintain the position of *pos. Expect the unexpected. If I recall correctly, perusing the source code for seq_file (it's a real mess!) shows that *pos is not forced to zero.


-Bruce


rday
--


========================================================================
Robert P. J. Day                               Waterloo, Ontario, CANADA

       Linux Consulting, Training and Annoying Kernel Pedantry.

Web page:                                          http://crashcourse.ca
Twitter:                                       http://twitter.com/rpjday
"Kernel Newbie Corner" column @ linux.com:          http://cli.gs/WG6WYX
========================================================================


[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