Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * debug.c - NTFS kernel debug support. Part of the Linux-NTFS project.
0004  *
0005  * Copyright (c) 2001-2004 Anton Altaparmakov
0006  */
0007 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
0008 #include "debug.h"
0009 
0010 /**
0011  * __ntfs_warning - output a warning to the syslog
0012  * @function:   name of function outputting the warning
0013  * @sb:     super block of mounted ntfs filesystem
0014  * @fmt:    warning string containing format specifications
0015  * @...:    a variable number of arguments specified in @fmt
0016  *
0017  * Outputs a warning to the syslog for the mounted ntfs filesystem described
0018  * by @sb.
0019  *
0020  * @fmt and the corresponding @... is printf style format string containing
0021  * the warning string and the corresponding format arguments, respectively.
0022  *
0023  * @function is the name of the function from which __ntfs_warning is being
0024  * called.
0025  *
0026  * Note, you should be using debug.h::ntfs_warning(@sb, @fmt, @...) instead
0027  * as this provides the @function parameter automatically.
0028  */
0029 void __ntfs_warning(const char *function, const struct super_block *sb,
0030         const char *fmt, ...)
0031 {
0032     struct va_format vaf;
0033     va_list args;
0034     int flen = 0;
0035 
0036 #ifndef DEBUG
0037     if (!printk_ratelimit())
0038         return;
0039 #endif
0040     if (function)
0041         flen = strlen(function);
0042     va_start(args, fmt);
0043     vaf.fmt = fmt;
0044     vaf.va = &args;
0045     if (sb)
0046         pr_warn("(device %s): %s(): %pV\n",
0047             sb->s_id, flen ? function : "", &vaf);
0048     else
0049         pr_warn("%s(): %pV\n", flen ? function : "", &vaf);
0050     va_end(args);
0051 }
0052 
0053 /**
0054  * __ntfs_error - output an error to the syslog
0055  * @function:   name of function outputting the error
0056  * @sb:     super block of mounted ntfs filesystem
0057  * @fmt:    error string containing format specifications
0058  * @...:    a variable number of arguments specified in @fmt
0059  *
0060  * Outputs an error to the syslog for the mounted ntfs filesystem described
0061  * by @sb.
0062  *
0063  * @fmt and the corresponding @... is printf style format string containing
0064  * the error string and the corresponding format arguments, respectively.
0065  *
0066  * @function is the name of the function from which __ntfs_error is being
0067  * called.
0068  *
0069  * Note, you should be using debug.h::ntfs_error(@sb, @fmt, @...) instead
0070  * as this provides the @function parameter automatically.
0071  */
0072 void __ntfs_error(const char *function, const struct super_block *sb,
0073         const char *fmt, ...)
0074 {
0075     struct va_format vaf;
0076     va_list args;
0077     int flen = 0;
0078 
0079 #ifndef DEBUG
0080     if (!printk_ratelimit())
0081         return;
0082 #endif
0083     if (function)
0084         flen = strlen(function);
0085     va_start(args, fmt);
0086     vaf.fmt = fmt;
0087     vaf.va = &args;
0088     if (sb)
0089         pr_err("(device %s): %s(): %pV\n",
0090                sb->s_id, flen ? function : "", &vaf);
0091     else
0092         pr_err("%s(): %pV\n", flen ? function : "", &vaf);
0093     va_end(args);
0094 }
0095 
0096 #ifdef DEBUG
0097 
0098 /* If 1, output debug messages, and if 0, don't. */
0099 int debug_msgs = 0;
0100 
0101 void __ntfs_debug(const char *file, int line, const char *function,
0102         const char *fmt, ...)
0103 {
0104     struct va_format vaf;
0105     va_list args;
0106     int flen = 0;
0107 
0108     if (!debug_msgs)
0109         return;
0110     if (function)
0111         flen = strlen(function);
0112     va_start(args, fmt);
0113     vaf.fmt = fmt;
0114     vaf.va = &args;
0115     pr_debug("(%s, %d): %s(): %pV", file, line, flen ? function : "", &vaf);
0116     va_end(args);
0117 }
0118 
0119 /* Dump a runlist. Caller has to provide synchronisation for @rl. */
0120 void ntfs_debug_dump_runlist(const runlist_element *rl)
0121 {
0122     int i;
0123     const char *lcn_str[5] = { "LCN_HOLE         ", "LCN_RL_NOT_MAPPED",
0124                    "LCN_ENOENT       ", "LCN_unknown      " };
0125 
0126     if (!debug_msgs)
0127         return;
0128     pr_debug("Dumping runlist (values in hex):\n");
0129     if (!rl) {
0130         pr_debug("Run list not present.\n");
0131         return;
0132     }
0133     pr_debug("VCN              LCN               Run length\n");
0134     for (i = 0; ; i++) {
0135         LCN lcn = (rl + i)->lcn;
0136 
0137         if (lcn < (LCN)0) {
0138             int index = -lcn - 1;
0139 
0140             if (index > -LCN_ENOENT - 1)
0141                 index = 3;
0142             pr_debug("%-16Lx %s %-16Lx%s\n",
0143                     (long long)(rl + i)->vcn, lcn_str[index],
0144                     (long long)(rl + i)->length,
0145                     (rl + i)->length ? "" :
0146                         " (runlist end)");
0147         } else
0148             pr_debug("%-16Lx %-16Lx  %-16Lx%s\n",
0149                     (long long)(rl + i)->vcn,
0150                     (long long)(rl + i)->lcn,
0151                     (long long)(rl + i)->length,
0152                     (rl + i)->length ? "" :
0153                         " (runlist end)");
0154         if (!(rl + i)->length)
0155             break;
0156     }
0157 }
0158 
0159 #endif