blob: dd6103cc93c1b4cd50c14400372ecdfae33bfe91 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * debug.c - NTFS kernel debug support. Part of the Linux-NTFS project.
3 *
4 * Copyright (c) 2001-2004 Anton Altaparmakov
5 *
6 * This program/include file is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as published
8 * by the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program/include file is distributed in the hope that it will be
12 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program (in the main directory of the Linux-NTFS
18 * distribution in the file COPYING); if not, write to the Free Software
19 * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
Fabian Frederick87c1b492014-04-07 15:36:53 -070021#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include "debug.h"
23
Linus Torvalds1da177e2005-04-16 15:20:36 -070024/**
25 * __ntfs_warning - output a warning to the syslog
26 * @function: name of function outputting the warning
27 * @sb: super block of mounted ntfs filesystem
28 * @fmt: warning string containing format specifications
29 * @...: a variable number of arguments specified in @fmt
30 *
31 * Outputs a warning to the syslog for the mounted ntfs filesystem described
32 * by @sb.
33 *
34 * @fmt and the corresponding @... is printf style format string containing
35 * the warning string and the corresponding format arguments, respectively.
36 *
37 * @function is the name of the function from which __ntfs_warning is being
38 * called.
39 *
40 * Note, you should be using debug.h::ntfs_warning(@sb, @fmt, @...) instead
41 * as this provides the @function parameter automatically.
42 */
43void __ntfs_warning(const char *function, const struct super_block *sb,
44 const char *fmt, ...)
45{
Fabian Frederick87c1b492014-04-07 15:36:53 -070046 struct va_format vaf;
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 va_list args;
48 int flen = 0;
49
50#ifndef DEBUG
51 if (!printk_ratelimit())
52 return;
53#endif
54 if (function)
55 flen = strlen(function);
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 va_start(args, fmt);
Fabian Frederick87c1b492014-04-07 15:36:53 -070057 vaf.fmt = fmt;
58 vaf.va = &args;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 if (sb)
Fabian Frederick87c1b492014-04-07 15:36:53 -070060 pr_warn("(device %s): %s(): %pV\n",
61 sb->s_id, flen ? function : "", &vaf);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 else
Fabian Frederick87c1b492014-04-07 15:36:53 -070063 pr_warn("%s(): %pV\n", flen ? function : "", &vaf);
64 va_end(args);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065}
66
67/**
68 * __ntfs_error - output an error to the syslog
69 * @function: name of function outputting the error
70 * @sb: super block of mounted ntfs filesystem
71 * @fmt: error string containing format specifications
72 * @...: a variable number of arguments specified in @fmt
73 *
74 * Outputs an error to the syslog for the mounted ntfs filesystem described
75 * by @sb.
76 *
77 * @fmt and the corresponding @... is printf style format string containing
78 * the error string and the corresponding format arguments, respectively.
79 *
80 * @function is the name of the function from which __ntfs_error is being
81 * called.
82 *
83 * Note, you should be using debug.h::ntfs_error(@sb, @fmt, @...) instead
84 * as this provides the @function parameter automatically.
85 */
86void __ntfs_error(const char *function, const struct super_block *sb,
87 const char *fmt, ...)
88{
Fabian Frederick87c1b492014-04-07 15:36:53 -070089 struct va_format vaf;
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 va_list args;
91 int flen = 0;
92
93#ifndef DEBUG
94 if (!printk_ratelimit())
95 return;
96#endif
97 if (function)
98 flen = strlen(function);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 va_start(args, fmt);
Fabian Frederick87c1b492014-04-07 15:36:53 -0700100 vaf.fmt = fmt;
101 vaf.va = &args;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 if (sb)
Fabian Frederick87c1b492014-04-07 15:36:53 -0700103 pr_err("(device %s): %s(): %pV\n",
104 sb->s_id, flen ? function : "", &vaf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 else
Fabian Frederick87c1b492014-04-07 15:36:53 -0700106 pr_err("%s(): %pV\n", flen ? function : "", &vaf);
107 va_end(args);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108}
109
110#ifdef DEBUG
111
112/* If 1, output debug messages, and if 0, don't. */
113int debug_msgs = 0;
114
115void __ntfs_debug (const char *file, int line, const char *function,
116 const char *fmt, ...)
117{
Fabian Frederick87c1b492014-04-07 15:36:53 -0700118 struct va_format vaf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 va_list args;
120 int flen = 0;
121
122 if (!debug_msgs)
123 return;
124 if (function)
125 flen = strlen(function);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 va_start(args, fmt);
Fabian Frederick87c1b492014-04-07 15:36:53 -0700127 vaf.fmt = fmt;
128 vaf.va = &args;
129 pr_debug("(%s, %d): %s(): %pV", file, line, flen ? function : "", &vaf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 va_end(args);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131}
132
133/* Dump a runlist. Caller has to provide synchronisation for @rl. */
134void ntfs_debug_dump_runlist(const runlist_element *rl)
135{
136 int i;
137 const char *lcn_str[5] = { "LCN_HOLE ", "LCN_RL_NOT_MAPPED",
138 "LCN_ENOENT ", "LCN_unknown " };
139
140 if (!debug_msgs)
141 return;
Fabian Frederick87c1b492014-04-07 15:36:53 -0700142 pr_debug("Dumping runlist (values in hex):\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 if (!rl) {
Fabian Frederick87c1b492014-04-07 15:36:53 -0700144 pr_debug("Run list not present.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 return;
146 }
Fabian Frederick87c1b492014-04-07 15:36:53 -0700147 pr_debug("VCN LCN Run length\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 for (i = 0; ; i++) {
149 LCN lcn = (rl + i)->lcn;
150
151 if (lcn < (LCN)0) {
152 int index = -lcn - 1;
153
154 if (index > -LCN_ENOENT - 1)
155 index = 3;
Fabian Frederick87c1b492014-04-07 15:36:53 -0700156 pr_debug("%-16Lx %s %-16Lx%s\n",
Randy Dunlap89075472005-03-03 11:19:53 +0000157 (long long)(rl + i)->vcn, lcn_str[index],
158 (long long)(rl + i)->length,
159 (rl + i)->length ? "" :
160 " (runlist end)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 } else
Fabian Frederick87c1b492014-04-07 15:36:53 -0700162 pr_debug("%-16Lx %-16Lx %-16Lx%s\n",
Randy Dunlap89075472005-03-03 11:19:53 +0000163 (long long)(rl + i)->vcn,
164 (long long)(rl + i)->lcn,
165 (long long)(rl + i)->length,
166 (rl + i)->length ? "" :
167 " (runlist end)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 if (!(rl + i)->length)
169 break;
170 }
171}
172
173#endif