| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * This file is part of UBIFS. |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 2006-2008 Nokia Corporation |
|---|
| 5 | | - * |
|---|
| 6 | | - * This program is free software; you can redistribute it and/or modify it |
|---|
| 7 | | - * under the terms of the GNU General Public License version 2 as published by |
|---|
| 8 | | - * the Free Software Foundation. |
|---|
| 9 | | - * |
|---|
| 10 | | - * This program is distributed in the hope that it will be useful, but WITHOUT |
|---|
| 11 | | - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|---|
| 12 | | - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
|---|
| 13 | | - * more details. |
|---|
| 14 | | - * |
|---|
| 15 | | - * You should have received a copy of the GNU General Public License along with |
|---|
| 16 | | - * this program; if not, write to the Free Software Foundation, Inc., 51 |
|---|
| 17 | | - * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|---|
| 18 | 6 | * |
|---|
| 19 | 7 | * Authors: Artem Bityutskiy (Битюцкий Артём) |
|---|
| 20 | 8 | * Adrian Hunter |
|---|
| .. | .. |
|---|
| 165 | 153 | return "commit start node"; |
|---|
| 166 | 154 | case UBIFS_ORPH_NODE: |
|---|
| 167 | 155 | return "orphan node"; |
|---|
| 156 | + case UBIFS_AUTH_NODE: |
|---|
| 157 | + return "auth node"; |
|---|
| 168 | 158 | default: |
|---|
| 169 | 159 | return "unknown node"; |
|---|
| 170 | 160 | } |
|---|
| .. | .. |
|---|
| 542 | 532 | (unsigned long long)le64_to_cpu(orph->inos[i])); |
|---|
| 543 | 533 | break; |
|---|
| 544 | 534 | } |
|---|
| 535 | + case UBIFS_AUTH_NODE: |
|---|
| 536 | + { |
|---|
| 537 | + break; |
|---|
| 538 | + } |
|---|
| 545 | 539 | default: |
|---|
| 546 | 540 | pr_err("node type %d was not recognized\n", |
|---|
| 547 | 541 | (int)ch->node_type); |
|---|
| .. | .. |
|---|
| 821 | 815 | |
|---|
| 822 | 816 | pr_err("(pid %d) start dumping LEB %d\n", current->pid, lnum); |
|---|
| 823 | 817 | |
|---|
| 824 | | - buf = __vmalloc(c->leb_size, GFP_NOFS, PAGE_KERNEL); |
|---|
| 818 | + buf = __vmalloc(c->leb_size, GFP_NOFS); |
|---|
| 825 | 819 | if (!buf) { |
|---|
| 826 | 820 | ubifs_err(c, "cannot allocate memory for dumping LEB %d", lnum); |
|---|
| 827 | 821 | return; |
|---|
| .. | .. |
|---|
| 1598 | 1592 | err = PTR_ERR(child); |
|---|
| 1599 | 1593 | goto out_unlock; |
|---|
| 1600 | 1594 | } |
|---|
| 1601 | | - zbr->znode = child; |
|---|
| 1602 | 1595 | } |
|---|
| 1603 | 1596 | |
|---|
| 1604 | 1597 | znode = child; |
|---|
| .. | .. |
|---|
| 2745 | 2738 | struct dentry *dent = file->f_path.dentry; |
|---|
| 2746 | 2739 | int val; |
|---|
| 2747 | 2740 | |
|---|
| 2748 | | - /* |
|---|
| 2749 | | - * TODO: this is racy - the file-system might have already been |
|---|
| 2750 | | - * unmounted and we'd oops in this case. The plan is to fix it with |
|---|
| 2751 | | - * help of 'iterate_supers_type()' which we should have in v3.0: when |
|---|
| 2752 | | - * a debugfs opened, we rember FS's UUID in file->private_data. Then |
|---|
| 2753 | | - * whenever we access the FS via a debugfs file, we iterate all UBIFS |
|---|
| 2754 | | - * superblocks and fine the one with the same UUID, and take the |
|---|
| 2755 | | - * locking right. |
|---|
| 2756 | | - * |
|---|
| 2757 | | - * The other way to go suggested by Al Viro is to create a separate |
|---|
| 2758 | | - * 'ubifs-debug' file-system instead. |
|---|
| 2759 | | - */ |
|---|
| 2760 | 2741 | if (file->f_path.dentry == d->dfs_dump_lprops) { |
|---|
| 2761 | 2742 | ubifs_dump_lprops(c); |
|---|
| 2762 | 2743 | return count; |
|---|
| .. | .. |
|---|
| 2808 | 2789 | * dbg_debugfs_init_fs - initialize debugfs for UBIFS instance. |
|---|
| 2809 | 2790 | * @c: UBIFS file-system description object |
|---|
| 2810 | 2791 | * |
|---|
| 2811 | | - * This function creates all debugfs files for this instance of UBIFS. Returns |
|---|
| 2812 | | - * zero in case of success and a negative error code in case of failure. |
|---|
| 2792 | + * This function creates all debugfs files for this instance of UBIFS. |
|---|
| 2813 | 2793 | * |
|---|
| 2814 | 2794 | * Note, the only reason we have not merged this function with the |
|---|
| 2815 | 2795 | * 'ubifs_debugging_init()' function is because it is better to initialize |
|---|
| 2816 | 2796 | * debugfs interfaces at the very end of the mount process, and remove them at |
|---|
| 2817 | 2797 | * the very beginning of the mount process. |
|---|
| 2818 | 2798 | */ |
|---|
| 2819 | | -int dbg_debugfs_init_fs(struct ubifs_info *c) |
|---|
| 2799 | +void dbg_debugfs_init_fs(struct ubifs_info *c) |
|---|
| 2820 | 2800 | { |
|---|
| 2821 | | - int err, n; |
|---|
| 2801 | + int n; |
|---|
| 2822 | 2802 | const char *fname; |
|---|
| 2823 | | - struct dentry *dent; |
|---|
| 2824 | 2803 | struct ubifs_debug_info *d = c->dbg; |
|---|
| 2825 | | - |
|---|
| 2826 | | - if (!IS_ENABLED(CONFIG_DEBUG_FS)) |
|---|
| 2827 | | - return 0; |
|---|
| 2828 | 2804 | |
|---|
| 2829 | 2805 | n = snprintf(d->dfs_dir_name, UBIFS_DFS_DIR_LEN + 1, UBIFS_DFS_DIR_NAME, |
|---|
| 2830 | 2806 | c->vi.ubi_num, c->vi.vol_id); |
|---|
| 2831 | 2807 | if (n == UBIFS_DFS_DIR_LEN) { |
|---|
| 2832 | 2808 | /* The array size is too small */ |
|---|
| 2833 | | - fname = UBIFS_DFS_DIR_NAME; |
|---|
| 2834 | | - dent = ERR_PTR(-EINVAL); |
|---|
| 2835 | | - goto out; |
|---|
| 2809 | + return; |
|---|
| 2836 | 2810 | } |
|---|
| 2837 | 2811 | |
|---|
| 2838 | 2812 | fname = d->dfs_dir_name; |
|---|
| 2839 | | - dent = debugfs_create_dir(fname, dfs_rootdir); |
|---|
| 2840 | | - if (IS_ERR_OR_NULL(dent)) |
|---|
| 2841 | | - goto out; |
|---|
| 2842 | | - d->dfs_dir = dent; |
|---|
| 2813 | + d->dfs_dir = debugfs_create_dir(fname, dfs_rootdir); |
|---|
| 2843 | 2814 | |
|---|
| 2844 | 2815 | fname = "dump_lprops"; |
|---|
| 2845 | | - dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, c, &dfs_fops); |
|---|
| 2846 | | - if (IS_ERR_OR_NULL(dent)) |
|---|
| 2847 | | - goto out_remove; |
|---|
| 2848 | | - d->dfs_dump_lprops = dent; |
|---|
| 2816 | + d->dfs_dump_lprops = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, c, |
|---|
| 2817 | + &dfs_fops); |
|---|
| 2849 | 2818 | |
|---|
| 2850 | 2819 | fname = "dump_budg"; |
|---|
| 2851 | | - dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, c, &dfs_fops); |
|---|
| 2852 | | - if (IS_ERR_OR_NULL(dent)) |
|---|
| 2853 | | - goto out_remove; |
|---|
| 2854 | | - d->dfs_dump_budg = dent; |
|---|
| 2820 | + d->dfs_dump_budg = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, c, |
|---|
| 2821 | + &dfs_fops); |
|---|
| 2855 | 2822 | |
|---|
| 2856 | 2823 | fname = "dump_tnc"; |
|---|
| 2857 | | - dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, c, &dfs_fops); |
|---|
| 2858 | | - if (IS_ERR_OR_NULL(dent)) |
|---|
| 2859 | | - goto out_remove; |
|---|
| 2860 | | - d->dfs_dump_tnc = dent; |
|---|
| 2824 | + d->dfs_dump_tnc = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, c, |
|---|
| 2825 | + &dfs_fops); |
|---|
| 2861 | 2826 | |
|---|
| 2862 | 2827 | fname = "chk_general"; |
|---|
| 2863 | | - dent = debugfs_create_file(fname, S_IRUSR | S_IWUSR, d->dfs_dir, c, |
|---|
| 2864 | | - &dfs_fops); |
|---|
| 2865 | | - if (IS_ERR_OR_NULL(dent)) |
|---|
| 2866 | | - goto out_remove; |
|---|
| 2867 | | - d->dfs_chk_gen = dent; |
|---|
| 2828 | + d->dfs_chk_gen = debugfs_create_file(fname, S_IRUSR | S_IWUSR, |
|---|
| 2829 | + d->dfs_dir, c, &dfs_fops); |
|---|
| 2868 | 2830 | |
|---|
| 2869 | 2831 | fname = "chk_index"; |
|---|
| 2870 | | - dent = debugfs_create_file(fname, S_IRUSR | S_IWUSR, d->dfs_dir, c, |
|---|
| 2871 | | - &dfs_fops); |
|---|
| 2872 | | - if (IS_ERR_OR_NULL(dent)) |
|---|
| 2873 | | - goto out_remove; |
|---|
| 2874 | | - d->dfs_chk_index = dent; |
|---|
| 2832 | + d->dfs_chk_index = debugfs_create_file(fname, S_IRUSR | S_IWUSR, |
|---|
| 2833 | + d->dfs_dir, c, &dfs_fops); |
|---|
| 2875 | 2834 | |
|---|
| 2876 | 2835 | fname = "chk_orphans"; |
|---|
| 2877 | | - dent = debugfs_create_file(fname, S_IRUSR | S_IWUSR, d->dfs_dir, c, |
|---|
| 2878 | | - &dfs_fops); |
|---|
| 2879 | | - if (IS_ERR_OR_NULL(dent)) |
|---|
| 2880 | | - goto out_remove; |
|---|
| 2881 | | - d->dfs_chk_orph = dent; |
|---|
| 2836 | + d->dfs_chk_orph = debugfs_create_file(fname, S_IRUSR | S_IWUSR, |
|---|
| 2837 | + d->dfs_dir, c, &dfs_fops); |
|---|
| 2882 | 2838 | |
|---|
| 2883 | 2839 | fname = "chk_lprops"; |
|---|
| 2884 | | - dent = debugfs_create_file(fname, S_IRUSR | S_IWUSR, d->dfs_dir, c, |
|---|
| 2885 | | - &dfs_fops); |
|---|
| 2886 | | - if (IS_ERR_OR_NULL(dent)) |
|---|
| 2887 | | - goto out_remove; |
|---|
| 2888 | | - d->dfs_chk_lprops = dent; |
|---|
| 2840 | + d->dfs_chk_lprops = debugfs_create_file(fname, S_IRUSR | S_IWUSR, |
|---|
| 2841 | + d->dfs_dir, c, &dfs_fops); |
|---|
| 2889 | 2842 | |
|---|
| 2890 | 2843 | fname = "chk_fs"; |
|---|
| 2891 | | - dent = debugfs_create_file(fname, S_IRUSR | S_IWUSR, d->dfs_dir, c, |
|---|
| 2892 | | - &dfs_fops); |
|---|
| 2893 | | - if (IS_ERR_OR_NULL(dent)) |
|---|
| 2894 | | - goto out_remove; |
|---|
| 2895 | | - d->dfs_chk_fs = dent; |
|---|
| 2844 | + d->dfs_chk_fs = debugfs_create_file(fname, S_IRUSR | S_IWUSR, |
|---|
| 2845 | + d->dfs_dir, c, &dfs_fops); |
|---|
| 2896 | 2846 | |
|---|
| 2897 | 2847 | fname = "tst_recovery"; |
|---|
| 2898 | | - dent = debugfs_create_file(fname, S_IRUSR | S_IWUSR, d->dfs_dir, c, |
|---|
| 2899 | | - &dfs_fops); |
|---|
| 2900 | | - if (IS_ERR_OR_NULL(dent)) |
|---|
| 2901 | | - goto out_remove; |
|---|
| 2902 | | - d->dfs_tst_rcvry = dent; |
|---|
| 2848 | + d->dfs_tst_rcvry = debugfs_create_file(fname, S_IRUSR | S_IWUSR, |
|---|
| 2849 | + d->dfs_dir, c, &dfs_fops); |
|---|
| 2903 | 2850 | |
|---|
| 2904 | 2851 | fname = "ro_error"; |
|---|
| 2905 | | - dent = debugfs_create_file(fname, S_IRUSR | S_IWUSR, d->dfs_dir, c, |
|---|
| 2906 | | - &dfs_fops); |
|---|
| 2907 | | - if (IS_ERR_OR_NULL(dent)) |
|---|
| 2908 | | - goto out_remove; |
|---|
| 2909 | | - d->dfs_ro_error = dent; |
|---|
| 2910 | | - |
|---|
| 2911 | | - return 0; |
|---|
| 2912 | | - |
|---|
| 2913 | | -out_remove: |
|---|
| 2914 | | - debugfs_remove_recursive(d->dfs_dir); |
|---|
| 2915 | | -out: |
|---|
| 2916 | | - err = dent ? PTR_ERR(dent) : -ENODEV; |
|---|
| 2917 | | - ubifs_err(c, "cannot create \"%s\" debugfs file or directory, error %d\n", |
|---|
| 2918 | | - fname, err); |
|---|
| 2919 | | - return err; |
|---|
| 2852 | + d->dfs_ro_error = debugfs_create_file(fname, S_IRUSR | S_IWUSR, |
|---|
| 2853 | + d->dfs_dir, c, &dfs_fops); |
|---|
| 2920 | 2854 | } |
|---|
| 2921 | 2855 | |
|---|
| 2922 | 2856 | /** |
|---|
| .. | .. |
|---|
| 2925 | 2859 | */ |
|---|
| 2926 | 2860 | void dbg_debugfs_exit_fs(struct ubifs_info *c) |
|---|
| 2927 | 2861 | { |
|---|
| 2928 | | - if (IS_ENABLED(CONFIG_DEBUG_FS)) |
|---|
| 2929 | | - debugfs_remove_recursive(c->dbg->dfs_dir); |
|---|
| 2862 | + debugfs_remove_recursive(c->dbg->dfs_dir); |
|---|
| 2930 | 2863 | } |
|---|
| 2931 | 2864 | |
|---|
| 2932 | 2865 | struct ubifs_global_debug_info ubifs_dbg; |
|---|
| .. | .. |
|---|
| 3002 | 2935 | * |
|---|
| 3003 | 2936 | * UBIFS uses debugfs file-system to expose various debugging knobs to |
|---|
| 3004 | 2937 | * user-space. This function creates "ubifs" directory in the debugfs |
|---|
| 3005 | | - * file-system. Returns zero in case of success and a negative error code in |
|---|
| 3006 | | - * case of failure. |
|---|
| 2938 | + * file-system. |
|---|
| 3007 | 2939 | */ |
|---|
| 3008 | | -int dbg_debugfs_init(void) |
|---|
| 2940 | +void dbg_debugfs_init(void) |
|---|
| 3009 | 2941 | { |
|---|
| 3010 | | - int err; |
|---|
| 3011 | 2942 | const char *fname; |
|---|
| 3012 | | - struct dentry *dent; |
|---|
| 3013 | | - |
|---|
| 3014 | | - if (!IS_ENABLED(CONFIG_DEBUG_FS)) |
|---|
| 3015 | | - return 0; |
|---|
| 3016 | 2943 | |
|---|
| 3017 | 2944 | fname = "ubifs"; |
|---|
| 3018 | | - dent = debugfs_create_dir(fname, NULL); |
|---|
| 3019 | | - if (IS_ERR_OR_NULL(dent)) |
|---|
| 3020 | | - goto out; |
|---|
| 3021 | | - dfs_rootdir = dent; |
|---|
| 2945 | + dfs_rootdir = debugfs_create_dir(fname, NULL); |
|---|
| 3022 | 2946 | |
|---|
| 3023 | 2947 | fname = "chk_general"; |
|---|
| 3024 | | - dent = debugfs_create_file(fname, S_IRUSR | S_IWUSR, dfs_rootdir, NULL, |
|---|
| 3025 | | - &dfs_global_fops); |
|---|
| 3026 | | - if (IS_ERR_OR_NULL(dent)) |
|---|
| 3027 | | - goto out_remove; |
|---|
| 3028 | | - dfs_chk_gen = dent; |
|---|
| 2948 | + dfs_chk_gen = debugfs_create_file(fname, S_IRUSR | S_IWUSR, dfs_rootdir, |
|---|
| 2949 | + NULL, &dfs_global_fops); |
|---|
| 3029 | 2950 | |
|---|
| 3030 | 2951 | fname = "chk_index"; |
|---|
| 3031 | | - dent = debugfs_create_file(fname, S_IRUSR | S_IWUSR, dfs_rootdir, NULL, |
|---|
| 3032 | | - &dfs_global_fops); |
|---|
| 3033 | | - if (IS_ERR_OR_NULL(dent)) |
|---|
| 3034 | | - goto out_remove; |
|---|
| 3035 | | - dfs_chk_index = dent; |
|---|
| 2952 | + dfs_chk_index = debugfs_create_file(fname, S_IRUSR | S_IWUSR, |
|---|
| 2953 | + dfs_rootdir, NULL, &dfs_global_fops); |
|---|
| 3036 | 2954 | |
|---|
| 3037 | 2955 | fname = "chk_orphans"; |
|---|
| 3038 | | - dent = debugfs_create_file(fname, S_IRUSR | S_IWUSR, dfs_rootdir, NULL, |
|---|
| 3039 | | - &dfs_global_fops); |
|---|
| 3040 | | - if (IS_ERR_OR_NULL(dent)) |
|---|
| 3041 | | - goto out_remove; |
|---|
| 3042 | | - dfs_chk_orph = dent; |
|---|
| 2956 | + dfs_chk_orph = debugfs_create_file(fname, S_IRUSR | S_IWUSR, |
|---|
| 2957 | + dfs_rootdir, NULL, &dfs_global_fops); |
|---|
| 3043 | 2958 | |
|---|
| 3044 | 2959 | fname = "chk_lprops"; |
|---|
| 3045 | | - dent = debugfs_create_file(fname, S_IRUSR | S_IWUSR, dfs_rootdir, NULL, |
|---|
| 3046 | | - &dfs_global_fops); |
|---|
| 3047 | | - if (IS_ERR_OR_NULL(dent)) |
|---|
| 3048 | | - goto out_remove; |
|---|
| 3049 | | - dfs_chk_lprops = dent; |
|---|
| 2960 | + dfs_chk_lprops = debugfs_create_file(fname, S_IRUSR | S_IWUSR, |
|---|
| 2961 | + dfs_rootdir, NULL, &dfs_global_fops); |
|---|
| 3050 | 2962 | |
|---|
| 3051 | 2963 | fname = "chk_fs"; |
|---|
| 3052 | | - dent = debugfs_create_file(fname, S_IRUSR | S_IWUSR, dfs_rootdir, NULL, |
|---|
| 3053 | | - &dfs_global_fops); |
|---|
| 3054 | | - if (IS_ERR_OR_NULL(dent)) |
|---|
| 3055 | | - goto out_remove; |
|---|
| 3056 | | - dfs_chk_fs = dent; |
|---|
| 2964 | + dfs_chk_fs = debugfs_create_file(fname, S_IRUSR | S_IWUSR, dfs_rootdir, |
|---|
| 2965 | + NULL, &dfs_global_fops); |
|---|
| 3057 | 2966 | |
|---|
| 3058 | 2967 | fname = "tst_recovery"; |
|---|
| 3059 | | - dent = debugfs_create_file(fname, S_IRUSR | S_IWUSR, dfs_rootdir, NULL, |
|---|
| 3060 | | - &dfs_global_fops); |
|---|
| 3061 | | - if (IS_ERR_OR_NULL(dent)) |
|---|
| 3062 | | - goto out_remove; |
|---|
| 3063 | | - dfs_tst_rcvry = dent; |
|---|
| 3064 | | - |
|---|
| 3065 | | - return 0; |
|---|
| 3066 | | - |
|---|
| 3067 | | -out_remove: |
|---|
| 3068 | | - debugfs_remove_recursive(dfs_rootdir); |
|---|
| 3069 | | -out: |
|---|
| 3070 | | - err = dent ? PTR_ERR(dent) : -ENODEV; |
|---|
| 3071 | | - pr_err("UBIFS error (pid %d): cannot create \"%s\" debugfs file or directory, error %d\n", |
|---|
| 3072 | | - current->pid, fname, err); |
|---|
| 3073 | | - return err; |
|---|
| 2968 | + dfs_tst_rcvry = debugfs_create_file(fname, S_IRUSR | S_IWUSR, |
|---|
| 2969 | + dfs_rootdir, NULL, &dfs_global_fops); |
|---|
| 3074 | 2970 | } |
|---|
| 3075 | 2971 | |
|---|
| 3076 | 2972 | /** |
|---|
| .. | .. |
|---|
| 3078 | 2974 | */ |
|---|
| 3079 | 2975 | void dbg_debugfs_exit(void) |
|---|
| 3080 | 2976 | { |
|---|
| 3081 | | - if (IS_ENABLED(CONFIG_DEBUG_FS)) |
|---|
| 3082 | | - debugfs_remove_recursive(dfs_rootdir); |
|---|
| 2977 | + debugfs_remove_recursive(dfs_rootdir); |
|---|
| 3083 | 2978 | } |
|---|
| 3084 | 2979 | |
|---|
| 3085 | 2980 | void ubifs_assert_failed(struct ubifs_info *c, const char *expr, |
|---|