diff options
author | Artem Bityutskiy <Artem.Bityutskiy@nokia.com> | 2011-06-03 02:58:23 -0400 |
---|---|---|
committer | Artem Bityutskiy <dedekind1@gmail.com> | 2011-07-04 03:54:32 -0400 |
commit | 28488fc28aa39815b78c2cbeaaf25f33fef92ce8 (patch) | |
tree | b2f50655effb1e067af15b22c91f591173e3761c /fs/ubifs/debug.c | |
parent | 7dae997de62bbd78f12305bf10019ec8f1103bd4 (diff) |
UBIFS: introduce debugfs helpers
Separate out pieces of code from the debugfs file read/write functions and
create separate 'interpret_user_input()'/'provide_user_output()' helpers. These
helpers will be needed in one of the following patches, so this is just a
preparational change.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Diffstat (limited to 'fs/ubifs/debug.c')
-rw-r--r-- | fs/ubifs/debug.c | 76 |
1 files changed, 56 insertions, 20 deletions
diff --git a/fs/ubifs/debug.c b/fs/ubifs/debug.c index 24a85073ac6c..b98638eb0fcb 100644 --- a/fs/ubifs/debug.c +++ b/fs/ubifs/debug.c | |||
@@ -2820,13 +2820,39 @@ static int dfs_file_open(struct inode *inode, struct file *file) | |||
2820 | return nonseekable_open(inode, file); | 2820 | return nonseekable_open(inode, file); |
2821 | } | 2821 | } |
2822 | 2822 | ||
2823 | /** | ||
2824 | * provide_user_output - provide output to the user reading a debugfs file. | ||
2825 | * @val: boolean value for the answer | ||
2826 | * @u: the buffer to store the answer at | ||
2827 | * @count: size of the buffer | ||
2828 | * @ppos: position in the @u output buffer | ||
2829 | * | ||
2830 | * This is a simple helper function which stores @val boolean value in the user | ||
2831 | * buffer when the user reads one of UBIFS debugfs files. Returns amount of | ||
2832 | * bytes written to @u in case of success and a negative error code in case of | ||
2833 | * failure. | ||
2834 | */ | ||
2835 | static int provide_user_output(int val, char __user *u, size_t count, | ||
2836 | loff_t *ppos) | ||
2837 | { | ||
2838 | char buf[3]; | ||
2839 | |||
2840 | if (val) | ||
2841 | buf[0] = '1'; | ||
2842 | else | ||
2843 | buf[0] = '0'; | ||
2844 | buf[1] = '\n'; | ||
2845 | buf[2] = 0x00; | ||
2846 | |||
2847 | return simple_read_from_buffer(u, count, ppos, buf, 2); | ||
2848 | } | ||
2849 | |||
2823 | static ssize_t dfs_file_read(struct file *file, char __user *u, size_t count, | 2850 | static ssize_t dfs_file_read(struct file *file, char __user *u, size_t count, |
2824 | loff_t *ppos) | 2851 | loff_t *ppos) |
2825 | { | 2852 | { |
2826 | struct dentry *dent = file->f_path.dentry; | 2853 | struct dentry *dent = file->f_path.dentry; |
2827 | struct ubifs_info *c = file->private_data; | 2854 | struct ubifs_info *c = file->private_data; |
2828 | struct ubifs_debug_info *d = c->dbg; | 2855 | struct ubifs_debug_info *d = c->dbg; |
2829 | char buf[3]; | ||
2830 | int val; | 2856 | int val; |
2831 | 2857 | ||
2832 | if (dent == d->dfs_chk_gen) | 2858 | if (dent == d->dfs_chk_gen) |
@@ -2844,14 +2870,33 @@ static ssize_t dfs_file_read(struct file *file, char __user *u, size_t count, | |||
2844 | else | 2870 | else |
2845 | return -EINVAL; | 2871 | return -EINVAL; |
2846 | 2872 | ||
2847 | if (val) | 2873 | return provide_user_output(val, u, count, ppos); |
2848 | buf[0] = '1'; | 2874 | } |
2849 | else | ||
2850 | buf[0] = '0'; | ||
2851 | buf[1] = '\n'; | ||
2852 | buf[2] = 0x00; | ||
2853 | 2875 | ||
2854 | return simple_read_from_buffer(u, count, ppos, buf, 2); | 2876 | /** |
2877 | * interpret_user_input - interpret user debugfs file input. | ||
2878 | * @u: user-provided buffer with the input | ||
2879 | * @count: buffer size | ||
2880 | * | ||
2881 | * This is a helper function which interpret user input to a boolean UBIFS | ||
2882 | * debugfs file. Returns %0 or %1 in case of success and a negative error code | ||
2883 | * in case of failure. | ||
2884 | */ | ||
2885 | static int interpret_user_input(const char __user *u, size_t count) | ||
2886 | { | ||
2887 | size_t buf_size; | ||
2888 | char buf[8]; | ||
2889 | |||
2890 | buf_size = min_t(size_t, count, (sizeof(buf) - 1)); | ||
2891 | if (copy_from_user(buf, u, buf_size)) | ||
2892 | return -EFAULT; | ||
2893 | |||
2894 | if (buf[0] == '1') | ||
2895 | return 1; | ||
2896 | else if (buf[0] == '0') | ||
2897 | return 0; | ||
2898 | |||
2899 | return -EINVAL; | ||
2855 | } | 2900 | } |
2856 | 2901 | ||
2857 | static ssize_t dfs_file_write(struct file *file, const char __user *u, | 2902 | static ssize_t dfs_file_write(struct file *file, const char __user *u, |
@@ -2860,8 +2905,6 @@ static ssize_t dfs_file_write(struct file *file, const char __user *u, | |||
2860 | struct ubifs_info *c = file->private_data; | 2905 | struct ubifs_info *c = file->private_data; |
2861 | struct ubifs_debug_info *d = c->dbg; | 2906 | struct ubifs_debug_info *d = c->dbg; |
2862 | struct dentry *dent = file->f_path.dentry; | 2907 | struct dentry *dent = file->f_path.dentry; |
2863 | size_t buf_size; | ||
2864 | char buf[8]; | ||
2865 | int val; | 2908 | int val; |
2866 | 2909 | ||
2867 | /* | 2910 | /* |
@@ -2891,16 +2934,9 @@ static ssize_t dfs_file_write(struct file *file, const char __user *u, | |||
2891 | return count; | 2934 | return count; |
2892 | } | 2935 | } |
2893 | 2936 | ||
2894 | buf_size = min_t(size_t, count, (sizeof(buf) - 1)); | 2937 | val = interpret_user_input(u, count); |
2895 | if (copy_from_user(buf, u, buf_size)) | 2938 | if (val < 0) |
2896 | return -EFAULT; | 2939 | return val; |
2897 | |||
2898 | if (buf[0] == '1') | ||
2899 | val = 1; | ||
2900 | else if (buf[0] == '0') | ||
2901 | val = 0; | ||
2902 | else | ||
2903 | return -EINVAL; | ||
2904 | 2940 | ||
2905 | if (dent == d->dfs_chk_gen) | 2941 | if (dent == d->dfs_chk_gen) |
2906 | d->chk_gen = val; | 2942 | d->chk_gen = val; |