]> git.openfabrics.org - ~aditr/compat.git/commitdiff
compat-3.19: add debugfs_create_file_size() function
authorSteve Wise <swise@opengridcomputing.com>
Tue, 11 Oct 2016 19:18:24 +0000 (12:18 -0700)
committerroot <root@stevo3.asicdesigners.com>
Tue, 11 Oct 2016 19:18:24 +0000 (12:18 -0700)
Create compat/compat-3.19.c and add debugfs_create_file_size().

Signed-off-by: Steve Wise <swise@opengridcomputing.com>
compat/Makefile
compat/compat-4.0.c [new file with mode: 0644]
include/linux/compat-2.6.h
include/linux/compat-4.0.h [new file with mode: 0644]

index 7e0ba4fb4e642132032a2c4800598b01f59d915f..4de858337fd298c7c1322dc9cff95c45ea75cb55 100644 (file)
@@ -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 (file)
index 0000000..f5d4005
--- /dev/null
@@ -0,0 +1,46 @@
+#include <linux/debugfs.h>
+#include <linux/fs.h>
+#include <linux/export.h>
+#include <linux/kernel.h>
+#include <linux/dcache.h>
+#include <linux/compat.h>
+
+/**
+ * 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);
index 8c7273b1140738c42bd6b31ac806dcabeed127a6..ef8ccf5f7dbb7c11019f9dd8e6a7949e665261e2 100644 (file)
@@ -75,6 +75,7 @@ void backport_dependency_symbol(void);
 #include <linux/compat-3.15.h>
 #include <linux/compat-3.16.h>
 #include <linux/compat-3.17.h>
+#include <linux/compat-4.0.h>
 #include <linux/compat-4.5.h>
 
 #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 (file)
index 0000000..9aae4ad
--- /dev/null
@@ -0,0 +1,31 @@
+#ifndef LINUX_4_0_COMPAT_H
+#define LINUX_4_0_COMPAT_H
+
+#include <linux/version.h>
+
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(4,0,0))
+
+#include <linux/dcache.h>
+
+/**
+ * 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 */