diff options
author | Michael Ellerman <michael@ellerman.id.au> | 2006-03-07 05:41:59 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2006-03-20 16:42:59 -0500 |
commit | dd308bc355a1aa4f202fe9a3133b6c676cb9606c (patch) | |
tree | accab2f0576da81d5e0ccfdbcc07f25a2a232008 /fs | |
parent | c516865cfbac0d862d4888df91793ad1e74ffd58 (diff) |
[PATCH] debugfs: Add debugfs_create_blob() helper for exporting binary data
I wanted to export a binary blob via debugfs, and although it was pretty easy
it seems like it'd be easier if there was a helper for it. It's a pity we need
the wrapper struct but I can't see a cleaner way to do it.
Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/debugfs/file.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c index d575452cd9f7..40c4fc973fad 100644 --- a/fs/debugfs/file.c +++ b/fs/debugfs/file.c | |||
@@ -251,3 +251,49 @@ struct dentry *debugfs_create_bool(const char *name, mode_t mode, | |||
251 | } | 251 | } |
252 | EXPORT_SYMBOL_GPL(debugfs_create_bool); | 252 | EXPORT_SYMBOL_GPL(debugfs_create_bool); |
253 | 253 | ||
254 | static ssize_t read_file_blob(struct file *file, char __user *user_buf, | ||
255 | size_t count, loff_t *ppos) | ||
256 | { | ||
257 | struct debugfs_blob_wrapper *blob = file->private_data; | ||
258 | return simple_read_from_buffer(user_buf, count, ppos, blob->data, | ||
259 | blob->size); | ||
260 | } | ||
261 | |||
262 | static struct file_operations fops_blob = { | ||
263 | .read = read_file_blob, | ||
264 | .open = default_open, | ||
265 | }; | ||
266 | |||
267 | /** | ||
268 | * debugfs_create_blob - create a file in the debugfs filesystem that is | ||
269 | * used to read and write a binary blob. | ||
270 | * | ||
271 | * @name: a pointer to a string containing the name of the file to create. | ||
272 | * @mode: the permission that the file should have | ||
273 | * @parent: a pointer to the parent dentry for this file. This should be a | ||
274 | * directory dentry if set. If this paramater is NULL, then the | ||
275 | * file will be created in the root of the debugfs filesystem. | ||
276 | * @blob: a pointer to a struct debugfs_blob_wrapper which contains a pointer | ||
277 | * to the blob data and the size of the data. | ||
278 | * | ||
279 | * This function creates a file in debugfs with the given name that exports | ||
280 | * @blob->data as a binary blob. If the @mode variable is so set it can be | ||
281 | * read from. Writing is not supported. | ||
282 | * | ||
283 | * This function will return a pointer to a dentry if it succeeds. This | ||
284 | * pointer must be passed to the debugfs_remove() function when the file is | ||
285 | * to be removed (no automatic cleanup happens if your module is unloaded, | ||
286 | * you are responsible here.) If an error occurs, NULL will be returned. | ||
287 | * | ||
288 | * If debugfs is not enabled in the kernel, the value -ENODEV will be | ||
289 | * returned. It is not wise to check for this value, but rather, check for | ||
290 | * NULL or !NULL instead as to eliminate the need for #ifdef in the calling | ||
291 | * code. | ||
292 | */ | ||
293 | struct dentry *debugfs_create_blob(const char *name, mode_t mode, | ||
294 | struct dentry *parent, | ||
295 | struct debugfs_blob_wrapper *blob) | ||
296 | { | ||
297 | return debugfs_create_file(name, mode, parent, blob, &fops_blob); | ||
298 | } | ||
299 | EXPORT_SYMBOL_GPL(debugfs_create_blob); | ||