aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/filesystems/seq_file.txt
diff options
context:
space:
mode:
authorRob Jones <rob.jones@codethink.co.uk>2014-09-07 14:24:40 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-09-07 18:21:13 -0400
commit77be4daf4e65eb1da70e6623ec61ecde62f5de95 (patch)
treef1f86c8ad25db5f9755d32afecd131785b6e25f9 /Documentation/filesystems/seq_file.txt
parent6fef37c9a7f15eb18d726e845f1bdff5809bd3f8 (diff)
Documentation: seq_file: Document seq_open_private(), seq_release_private()
Despite the fact that these functions have been around for years, they are little used (only 15 uses in 13 files at the preseht time) even though many other files use work-arounds to achieve the same result. By documenting them, hopefully they will become more widely used. Signed-off-by: Rob Jones <rob.jones@codethink.co.uk> Acked-by: Steven Whitehouse <swhiteho@redhat.com> Signed-off-by: Randy Dunlap <rdunlap@infradead.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'Documentation/filesystems/seq_file.txt')
-rw-r--r--Documentation/filesystems/seq_file.txt33
1 files changed, 33 insertions, 0 deletions
diff --git a/Documentation/filesystems/seq_file.txt b/Documentation/filesystems/seq_file.txt
index 1fe0ccb1af55..8ea3e90ace07 100644
--- a/Documentation/filesystems/seq_file.txt
+++ b/Documentation/filesystems/seq_file.txt
@@ -235,6 +235,39 @@ be used for more than one file, you can store an arbitrary pointer in the
235private field of the seq_file structure; that value can then be retrieved 235private field of the seq_file structure; that value can then be retrieved
236by the iterator functions. 236by the iterator functions.
237 237
238There is also a wrapper function to seq_open() called seq_open_private(). It
239kmallocs a zero filled block of memory and stores a pointer to it in the
240private field of the seq_file structure, returning 0 on success. The
241block size is specified in a third parameter to the function, e.g.:
242
243 static int ct_open(struct inode *inode, struct file *file)
244 {
245 return seq_open_private(file, &ct_seq_ops,
246 sizeof(struct mystruct));
247 }
248
249There is also a variant function, __seq_open_private(), which is functionally
250identical except that, if successful, it returns the pointer to the allocated
251memory block, allowing further initialisation e.g.:
252
253 static int ct_open(struct inode *inode, struct file *file)
254 {
255 struct mystruct *p =
256 __seq_open_private(file, &ct_seq_ops, sizeof(*p));
257
258 if (!p)
259 return -ENOMEM;
260
261 p->foo = bar; /* initialize my stuff */
262 ...
263 p->baz = true;
264
265 return 0;
266 }
267
268A corresponding close function, seq_release_private() is available which
269frees the memory allocated in the corresponding open.
270
238The other operations of interest - read(), llseek(), and release() - are 271The other operations of interest - read(), llseek(), and release() - are
239all implemented by the seq_file code itself. So a virtual file's 272all implemented by the seq_file code itself. So a virtual file's
240file_operations structure will look like: 273file_operations structure will look like: