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 | |
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>
-rw-r--r-- | fs/debugfs/file.c | 46 | ||||
-rw-r--r-- | include/linux/debugfs.h | 15 |
2 files changed, 61 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); | ||
diff --git a/include/linux/debugfs.h b/include/linux/debugfs.h index a5fa6a6eede8..4b0428e335be 100644 --- a/include/linux/debugfs.h +++ b/include/linux/debugfs.h | |||
@@ -21,6 +21,11 @@ | |||
21 | 21 | ||
22 | struct file_operations; | 22 | struct file_operations; |
23 | 23 | ||
24 | struct debugfs_blob_wrapper { | ||
25 | void *data; | ||
26 | unsigned long size; | ||
27 | }; | ||
28 | |||
24 | #if defined(CONFIG_DEBUG_FS) | 29 | #if defined(CONFIG_DEBUG_FS) |
25 | struct dentry *debugfs_create_file(const char *name, mode_t mode, | 30 | struct dentry *debugfs_create_file(const char *name, mode_t mode, |
26 | struct dentry *parent, void *data, | 31 | struct dentry *parent, void *data, |
@@ -39,6 +44,9 @@ struct dentry *debugfs_create_u32(const char *name, mode_t mode, | |||
39 | struct dentry *debugfs_create_bool(const char *name, mode_t mode, | 44 | struct dentry *debugfs_create_bool(const char *name, mode_t mode, |
40 | struct dentry *parent, u32 *value); | 45 | struct dentry *parent, u32 *value); |
41 | 46 | ||
47 | struct dentry *debugfs_create_blob(const char *name, mode_t mode, | ||
48 | struct dentry *parent, | ||
49 | struct debugfs_blob_wrapper *blob); | ||
42 | #else | 50 | #else |
43 | 51 | ||
44 | #include <linux/err.h> | 52 | #include <linux/err.h> |
@@ -94,6 +102,13 @@ static inline struct dentry *debugfs_create_bool(const char *name, mode_t mode, | |||
94 | return ERR_PTR(-ENODEV); | 102 | return ERR_PTR(-ENODEV); |
95 | } | 103 | } |
96 | 104 | ||
105 | static inline struct dentry *debugfs_create_blob(const char *name, mode_t mode, | ||
106 | struct dentry *parent, | ||
107 | struct debugfs_blob_wrapper *blob) | ||
108 | { | ||
109 | return ERR_PTR(-ENODEV); | ||
110 | } | ||
111 | |||
97 | #endif | 112 | #endif |
98 | 113 | ||
99 | #endif | 114 | #endif |