From 369155893c884ef22d5b45d99c5510583aac2d8a Mon Sep 17 00:00:00 2001 From: Steve Wise Date: Tue, 11 Oct 2016 12:18:24 -0700 Subject: [PATCH] compat-3.19: add debugfs_create_file_size() function Create compat/compat-3.19.c and add debugfs_create_file_size(). Signed-off-by: Steve Wise --- compat/Makefile | 1 + compat/compat-4.0.c | 46 ++++++++++++++++++++++++++++++++++++++ include/linux/compat-2.6.h | 1 + include/linux/compat-4.0.h | 31 +++++++++++++++++++++++++ 4 files changed, 79 insertions(+) create mode 100644 compat/compat-4.0.c create mode 100644 include/linux/compat-4.0.h diff --git a/compat/Makefile b/compat/Makefile index 7e0ba4f..4de8583 100644 --- a/compat/Makefile +++ b/compat/Makefile @@ -56,6 +56,7 @@ compat-$(CONFIG_COMPAT_KERNEL_3_13) += compat-3.13.o compat-$(CONFIG_COMPAT_KERNEL_3_15) += compat-3.15.o compat-$(CONFIG_COMPAT_KERNEL_3_16) += compat-3.16.o compat-$(CONFIG_COMPAT_KERNEL_3_18) += compat-3.18.o +compat-$(CONFIG_COMPAT_KERNEL_4_0) += compat-4.0.o compat-$(CONFIG_COMPAT_CORDIC) += cordic.o compat-$(CONFIG_COMPAT_CRC8) += crc8.o diff --git a/compat/compat-4.0.c b/compat/compat-4.0.c new file mode 100644 index 0000000..f5d4005 --- /dev/null +++ b/compat/compat-4.0.c @@ -0,0 +1,46 @@ +#include +#include +#include +#include +#include +#include + +/** + * debugfs_create_file_size - create a file in the debugfs filesystem + * @name: a pointer to a string containing the name of the file to create. + * @mode: the permission that the file should have. + * @parent: a pointer to the parent dentry for this file. This should be a + * directory dentry if set. If this parameter is NULL, then the + * file will be created in the root of the debugfs filesystem. + * @data: a pointer to something that the caller will want to get to later + * on. The inode.i_private pointer will point to this value on + * the open() call. + * @fops: a pointer to a struct file_operations that should be used for + * this file. + * @file_size: initial file size + * + * This is the basic "create a file" function for debugfs. It allows for a + * wide range of flexibility in creating a file, or a directory (if you want + * to create a directory, the debugfs_create_dir() function is + * recommended to be used instead.) + * + * This function will return a pointer to a dentry if it succeeds. This + * pointer must be passed to the debugfs_remove() function when the file is + * to be removed (no automatic cleanup happens if your module is unloaded, + * you are responsible here.) If an error occurs, %NULL will be returned. + * + * If debugfs is not enabled in the kernel, the value -%ENODEV will be + * returned. + */ +struct dentry *debugfs_create_file_size(const char *name, umode_t mode, + struct dentry *parent, void *data, + const struct file_operations *fops, + loff_t file_size) +{ + struct dentry *de = debugfs_create_file(name, mode, parent, data, fops); + + if (de) + d_inode(de)->i_size = file_size; + return de; +} +EXPORT_SYMBOL_GPL(debugfs_create_file_size); diff --git a/include/linux/compat-2.6.h b/include/linux/compat-2.6.h index 8c7273b..ef8ccf5 100644 --- a/include/linux/compat-2.6.h +++ b/include/linux/compat-2.6.h @@ -75,6 +75,7 @@ void backport_dependency_symbol(void); #include #include #include +#include #include #endif /* LINUX_26_COMPAT_H */ diff --git a/include/linux/compat-4.0.h b/include/linux/compat-4.0.h new file mode 100644 index 0000000..9aae4ad --- /dev/null +++ b/include/linux/compat-4.0.h @@ -0,0 +1,31 @@ +#ifndef LINUX_4_0_COMPAT_H +#define LINUX_4_0_COMPAT_H + +#include + +#if (LINUX_VERSION_CODE < KERNEL_VERSION(4,0,0)) + +#include + +/** + * d_inode - Get the actual inode of this dentry + * @dentry: The dentry to query + * + * This is the helper normal filesystems should use to get at their own inodes + * in their own dentries and ignore the layering superimposed upon them. + */ +static inline struct inode *d_inode(const struct dentry *dentry) +{ + return dentry->d_inode; +} + +#define debugfs_create_file_size LINUX_BACKPORT(debugfs_create_file_size) + +struct dentry *debugfs_create_file_size(const char *name, umode_t mode, + struct dentry *parent, void *data, + const struct file_operations *fops, + loff_t file_size); + +#endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(4,0,0)) */ + +#endif /* LINUX_4.0_COMPAT_H */ -- 2.41.0