@@ -3064,7 +3064,7 @@ int dbg_debugfs_init_fs(struct ubifs_info *c)
30643064 debugfs_remove_recursive (d -> dfs_dir );
30653065out :
30663066 err = dent ? PTR_ERR (dent ) : - ENODEV ;
3067- ubifs_err ("cannot create \"%s\" debugfs filr or directory, error %d\n" ,
3067+ ubifs_err ("cannot create \"%s\" debugfs file or directory, error %d\n" ,
30683068 fname , err );
30693069 return err ;
30703070}
@@ -3078,6 +3078,74 @@ void dbg_debugfs_exit_fs(struct ubifs_info *c)
30783078 debugfs_remove_recursive (c -> dbg -> dfs_dir );
30793079}
30803080
3081+ struct ubifs_global_debug_info ubifs_dbg ;
3082+
3083+ static struct dentry * dfs_chk_gen ;
3084+ static struct dentry * dfs_chk_index ;
3085+ static struct dentry * dfs_chk_orph ;
3086+ static struct dentry * dfs_chk_lprops ;
3087+ static struct dentry * dfs_chk_fs ;
3088+ static struct dentry * dfs_tst_rcvry ;
3089+
3090+ static ssize_t dfs_global_file_read (struct file * file , char __user * u ,
3091+ size_t count , loff_t * ppos )
3092+ {
3093+ struct dentry * dent = file -> f_path .dentry ;
3094+ int val ;
3095+
3096+ if (dent == dfs_chk_gen )
3097+ val = ubifs_dbg .chk_gen ;
3098+ else if (dent == dfs_chk_index )
3099+ val = ubifs_dbg .chk_index ;
3100+ else if (dent == dfs_chk_orph )
3101+ val = ubifs_dbg .chk_orph ;
3102+ else if (dent == dfs_chk_lprops )
3103+ val = ubifs_dbg .chk_lprops ;
3104+ else if (dent == dfs_chk_fs )
3105+ val = ubifs_dbg .chk_fs ;
3106+ else if (dent == dfs_tst_rcvry )
3107+ val = ubifs_dbg .tst_rcvry ;
3108+ else
3109+ return - EINVAL ;
3110+
3111+ return provide_user_output (val , u , count , ppos );
3112+ }
3113+
3114+ static ssize_t dfs_global_file_write (struct file * file , const char __user * u ,
3115+ size_t count , loff_t * ppos )
3116+ {
3117+ struct dentry * dent = file -> f_path .dentry ;
3118+ int val ;
3119+
3120+ val = interpret_user_input (u , count );
3121+ if (val < 0 )
3122+ return val ;
3123+
3124+ if (dent == dfs_chk_gen )
3125+ ubifs_dbg .chk_gen = val ;
3126+ else if (dent == dfs_chk_index )
3127+ ubifs_dbg .chk_index = val ;
3128+ else if (dent == dfs_chk_orph )
3129+ ubifs_dbg .chk_orph = val ;
3130+ else if (dent == dfs_chk_lprops )
3131+ ubifs_dbg .chk_lprops = val ;
3132+ else if (dent == dfs_chk_fs )
3133+ ubifs_dbg .chk_fs = val ;
3134+ else if (dent == dfs_tst_rcvry )
3135+ ubifs_dbg .tst_rcvry = val ;
3136+ else
3137+ return - EINVAL ;
3138+
3139+ return count ;
3140+ }
3141+
3142+ static const struct file_operations dfs_global_fops = {
3143+ .read = dfs_global_file_read ,
3144+ .write = dfs_global_file_write ,
3145+ .owner = THIS_MODULE ,
3146+ .llseek = no_llseek ,
3147+ };
3148+
30813149/**
30823150 * dbg_debugfs_init - initialize debugfs file-system.
30833151 *
@@ -3088,23 +3156,75 @@ void dbg_debugfs_exit_fs(struct ubifs_info *c)
30883156 */
30893157int dbg_debugfs_init (void )
30903158{
3091- dfs_rootdir = debugfs_create_dir ("ubifs" , NULL );
3092- if (IS_ERR_OR_NULL (dfs_rootdir )) {
3093- int err = dfs_rootdir ? PTR_ERR (dfs_rootdir ) : - ENODEV ;
3094- ubifs_err ("cannot create \"ubifs\" debugfs directory, "
3095- "error %d\n" , err );
3096- return err ;
3097- }
3159+ int err ;
3160+ const char * fname ;
3161+ struct dentry * dent ;
3162+
3163+ fname = "ubifs" ;
3164+ dent = debugfs_create_dir (fname , NULL );
3165+ if (IS_ERR_OR_NULL (dent ))
3166+ goto out ;
3167+ dfs_rootdir = dent ;
3168+
3169+ fname = "chk_general" ;
3170+ dent = debugfs_create_file (fname , S_IRUSR | S_IWUSR , dfs_rootdir , NULL ,
3171+ & dfs_global_fops );
3172+ if (IS_ERR_OR_NULL (dent ))
3173+ goto out_remove ;
3174+ dfs_chk_gen = dent ;
3175+
3176+ fname = "chk_index" ;
3177+ dent = debugfs_create_file (fname , S_IRUSR | S_IWUSR , dfs_rootdir , NULL ,
3178+ & dfs_global_fops );
3179+ if (IS_ERR_OR_NULL (dent ))
3180+ goto out_remove ;
3181+ dfs_chk_index = dent ;
3182+
3183+ fname = "chk_orphans" ;
3184+ dent = debugfs_create_file (fname , S_IRUSR | S_IWUSR , dfs_rootdir , NULL ,
3185+ & dfs_global_fops );
3186+ if (IS_ERR_OR_NULL (dent ))
3187+ goto out_remove ;
3188+ dfs_chk_orph = dent ;
3189+
3190+ fname = "chk_lprops" ;
3191+ dent = debugfs_create_file (fname , S_IRUSR | S_IWUSR , dfs_rootdir , NULL ,
3192+ & dfs_global_fops );
3193+ if (IS_ERR_OR_NULL (dent ))
3194+ goto out_remove ;
3195+ dfs_chk_lprops = dent ;
3196+
3197+ fname = "chk_fs" ;
3198+ dent = debugfs_create_file (fname , S_IRUSR | S_IWUSR , dfs_rootdir , NULL ,
3199+ & dfs_global_fops );
3200+ if (IS_ERR_OR_NULL (dent ))
3201+ goto out_remove ;
3202+ dfs_chk_fs = dent ;
3203+
3204+ fname = "tst_recovery" ;
3205+ dent = debugfs_create_file (fname , S_IRUSR | S_IWUSR , dfs_rootdir , NULL ,
3206+ & dfs_global_fops );
3207+ if (IS_ERR_OR_NULL (dent ))
3208+ goto out_remove ;
3209+ dfs_tst_rcvry = dent ;
30983210
30993211 return 0 ;
3212+
3213+ out_remove :
3214+ debugfs_remove_recursive (dfs_rootdir );
3215+ out :
3216+ err = dent ? PTR_ERR (dent ) : - ENODEV ;
3217+ ubifs_err ("cannot create \"%s\" debugfs file or directory, error %d\n" ,
3218+ fname , err );
3219+ return err ;
31003220}
31013221
31023222/**
31033223 * dbg_debugfs_exit - remove the "ubifs" directory from debugfs file-system.
31043224 */
31053225void dbg_debugfs_exit (void )
31063226{
3107- debugfs_remove (dfs_rootdir );
3227+ debugfs_remove_recursive (dfs_rootdir );
31083228}
31093229
31103230/**
0 commit comments