@@ -865,6 +865,97 @@ struct dentry *debugfs_create_bool(const char *name, umode_t mode,
865865}
866866EXPORT_SYMBOL_GPL (debugfs_create_bool );
867867
868+ ssize_t debugfs_read_file_str (struct file * file , char __user * user_buf ,
869+ size_t count , loff_t * ppos )
870+ {
871+ struct dentry * dentry = F_DENTRY (file );
872+ char * str , * copy = NULL ;
873+ int copy_len , len ;
874+ ssize_t ret ;
875+
876+ ret = debugfs_file_get (dentry );
877+ if (unlikely (ret ))
878+ return ret ;
879+
880+ str = * (char * * )file -> private_data ;
881+ len = strlen (str ) + 1 ;
882+ copy = kmalloc (len , GFP_KERNEL );
883+ if (!copy ) {
884+ debugfs_file_put (dentry );
885+ return - ENOMEM ;
886+ }
887+
888+ copy_len = strscpy (copy , str , len );
889+ debugfs_file_put (dentry );
890+ if (copy_len < 0 ) {
891+ kfree (copy );
892+ return copy_len ;
893+ }
894+
895+ copy [copy_len ] = '\n' ;
896+
897+ ret = simple_read_from_buffer (user_buf , count , ppos , copy , copy_len );
898+ kfree (copy );
899+
900+ return ret ;
901+ }
902+
903+ static ssize_t debugfs_write_file_str (struct file * file , const char __user * user_buf ,
904+ size_t count , loff_t * ppos )
905+ {
906+ /* This is really only for read-only strings */
907+ return - EINVAL ;
908+ }
909+
910+ static const struct file_operations fops_str = {
911+ .read = debugfs_read_file_str ,
912+ .write = debugfs_write_file_str ,
913+ .open = simple_open ,
914+ .llseek = default_llseek ,
915+ };
916+
917+ static const struct file_operations fops_str_ro = {
918+ .read = debugfs_read_file_str ,
919+ .open = simple_open ,
920+ .llseek = default_llseek ,
921+ };
922+
923+ static const struct file_operations fops_str_wo = {
924+ .write = debugfs_write_file_str ,
925+ .open = simple_open ,
926+ .llseek = default_llseek ,
927+ };
928+
929+ /**
930+ * debugfs_create_str - create a debugfs file that is used to read and write a string value
931+ * @name: a pointer to a string containing the name of the file to create.
932+ * @mode: the permission that the file should have
933+ * @parent: a pointer to the parent dentry for this file. This should be a
934+ * directory dentry if set. If this parameter is %NULL, then the
935+ * file will be created in the root of the debugfs filesystem.
936+ * @value: a pointer to the variable that the file should read to and write
937+ * from.
938+ *
939+ * This function creates a file in debugfs with the given name that
940+ * contains the value of the variable @value. If the @mode variable is so
941+ * set, it can be read from, and written to.
942+ *
943+ * This function will return a pointer to a dentry if it succeeds. This
944+ * pointer must be passed to the debugfs_remove() function when the file is
945+ * to be removed (no automatic cleanup happens if your module is unloaded,
946+ * you are responsible here.) If an error occurs, ERR_PTR(-ERROR) will be
947+ * returned.
948+ *
949+ * If debugfs is not enabled in the kernel, the value ERR_PTR(-ENODEV) will
950+ * be returned.
951+ */
952+ void debugfs_create_str (const char * name , umode_t mode ,
953+ struct dentry * parent , char * * value )
954+ {
955+ debugfs_create_mode_unsafe (name , mode , parent , value , & fops_str ,
956+ & fops_str_ro , & fops_str_wo );
957+ }
958+
868959static ssize_t read_file_blob (struct file * file , char __user * user_buf ,
869960 size_t count , loff_t * ppos )
870961{
0 commit comments