aboutsummaryrefslogtreecommitdiffstats
path: root/fs/debugfs/file.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/debugfs/file.c')
-rw-r--r--fs/debugfs/file.c50
1 files changed, 48 insertions, 2 deletions
diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c
index d575452cd9f7..66a505422e5c 100644
--- a/fs/debugfs/file.c
+++ b/fs/debugfs/file.c
@@ -39,7 +39,7 @@ static int default_open(struct inode *inode, struct file *file)
39 return 0; 39 return 0;
40} 40}
41 41
42struct file_operations debugfs_file_operations = { 42const struct file_operations debugfs_file_operations = {
43 .read = default_read_file, 43 .read = default_read_file,
44 .write = default_write_file, 44 .write = default_write_file,
45 .open = default_open, 45 .open = default_open,
@@ -213,7 +213,7 @@ static ssize_t write_file_bool(struct file *file, const char __user *user_buf,
213 return count; 213 return count;
214} 214}
215 215
216static struct file_operations fops_bool = { 216static const struct file_operations fops_bool = {
217 .read = read_file_bool, 217 .read = read_file_bool,
218 .write = write_file_bool, 218 .write = write_file_bool,
219 .open = default_open, 219 .open = default_open,
@@ -251,3 +251,49 @@ struct dentry *debugfs_create_bool(const char *name, mode_t mode,
251} 251}
252EXPORT_SYMBOL_GPL(debugfs_create_bool); 252EXPORT_SYMBOL_GPL(debugfs_create_bool);
253 253
254static 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
262static 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 */
293struct 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}
299EXPORT_SYMBOL_GPL(debugfs_create_blob);