diff options
-rw-r--r-- | Documentation/filesystems/seq_file.txt | 33 |
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 | |||
235 | private field of the seq_file structure; that value can then be retrieved | 235 | private field of the seq_file structure; that value can then be retrieved |
236 | by the iterator functions. | 236 | by the iterator functions. |
237 | 237 | ||
238 | There is also a wrapper function to seq_open() called seq_open_private(). It | ||
239 | kmallocs a zero filled block of memory and stores a pointer to it in the | ||
240 | private field of the seq_file structure, returning 0 on success. The | ||
241 | block 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 | |||
249 | There is also a variant function, __seq_open_private(), which is functionally | ||
250 | identical except that, if successful, it returns the pointer to the allocated | ||
251 | memory 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 | |||
268 | A corresponding close function, seq_release_private() is available which | ||
269 | frees the memory allocated in the corresponding open. | ||
270 | |||
238 | The other operations of interest - read(), llseek(), and release() - are | 271 | The other operations of interest - read(), llseek(), and release() - are |
239 | all implemented by the seq_file code itself. So a virtual file's | 272 | all implemented by the seq_file code itself. So a virtual file's |
240 | file_operations structure will look like: | 273 | file_operations structure will look like: |