2 * debug.c - NTFS kernel debug support. Part of the Linux-NTFS project.
4 * Copyright (c) 2001-2004 Anton Altaparmakov
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.
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.
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
25 * A static buffer to hold the error string being displayed and a spinlock
26 * to protect concurrent accesses to it.
28 static char err_buf[1024];
29 static DEFINE_SPINLOCK(err_buf_lock);
32 * __ntfs_warning - output a warning to the syslog
33 * @function: name of function outputting the warning
34 * @sb: super block of mounted ntfs filesystem
35 * @fmt: warning string containing format specifications
36 * @...: a variable number of arguments specified in @fmt
38 * Outputs a warning to the syslog for the mounted ntfs filesystem described
41 * @fmt and the corresponding @... is printf style format string containing
42 * the warning string and the corresponding format arguments, respectively.
44 * @function is the name of the function from which __ntfs_warning is being
47 * Note, you should be using debug.h::ntfs_warning(@sb, @fmt, @...) instead
48 * as this provides the @function parameter automatically.
50 void __ntfs_warning(const char *function, const struct super_block *sb,
57 if (!printk_ratelimit())
61 flen = strlen(function);
62 spin_lock(&err_buf_lock);
64 vsnprintf(err_buf, sizeof(err_buf), fmt, args);
67 printk(KERN_ERR "NTFS-fs warning (device %s): %s(): %s\n",
68 sb->s_id, flen ? function : "", err_buf);
70 printk(KERN_ERR "NTFS-fs warning: %s(): %s\n",
71 flen ? function : "", err_buf);
72 spin_unlock(&err_buf_lock);
76 * __ntfs_error - output an error to the syslog
77 * @function: name of function outputting the error
78 * @sb: super block of mounted ntfs filesystem
79 * @fmt: error string containing format specifications
80 * @...: a variable number of arguments specified in @fmt
82 * Outputs an error to the syslog for the mounted ntfs filesystem described
85 * @fmt and the corresponding @... is printf style format string containing
86 * the error string and the corresponding format arguments, respectively.
88 * @function is the name of the function from which __ntfs_error is being
91 * Note, you should be using debug.h::ntfs_error(@sb, @fmt, @...) instead
92 * as this provides the @function parameter automatically.
94 void __ntfs_error(const char *function, const struct super_block *sb,
101 if (!printk_ratelimit())
105 flen = strlen(function);
106 spin_lock(&err_buf_lock);
108 vsnprintf(err_buf, sizeof(err_buf), fmt, args);
111 printk(KERN_ERR "NTFS-fs error (device %s): %s(): %s\n",
112 sb->s_id, flen ? function : "", err_buf);
114 printk(KERN_ERR "NTFS-fs error: %s(): %s\n",
115 flen ? function : "", err_buf);
116 spin_unlock(&err_buf_lock);
121 /* If 1, output debug messages, and if 0, don't. */
124 void __ntfs_debug (const char *file, int line, const char *function,
125 const char *fmt, ...)
133 flen = strlen(function);
134 spin_lock(&err_buf_lock);
136 vsnprintf(err_buf, sizeof(err_buf), fmt, args);
138 printk(KERN_DEBUG "NTFS-fs DEBUG (%s, %d): %s(): %s\n", file, line,
139 flen ? function : "", err_buf);
140 spin_unlock(&err_buf_lock);
143 /* Dump a runlist. Caller has to provide synchronisation for @rl. */
144 void ntfs_debug_dump_runlist(const runlist_element *rl)
147 const char *lcn_str[5] = { "LCN_HOLE ", "LCN_RL_NOT_MAPPED",
148 "LCN_ENOENT ", "LCN_unknown " };
152 printk(KERN_DEBUG "NTFS-fs DEBUG: Dumping runlist (values in hex):\n");
154 printk(KERN_DEBUG "Run list not present.\n");
157 printk(KERN_DEBUG "VCN LCN Run length\n");
159 LCN lcn = (rl + i)->lcn;
162 int index = -lcn - 1;
164 if (index > -LCN_ENOENT - 1)
166 printk(KERN_DEBUG "%-16Lx %s %-16Lx%s\n",
167 (rl + i)->vcn, lcn_str[index],
168 (rl + i)->length, (rl + i)->length ?
169 "" : " (runlist end)");
171 printk(KERN_DEBUG "%-16Lx %-16Lx %-16Lx%s\n",
172 (rl + i)->vcn, (rl + i)->lcn,
173 (rl + i)->length, (rl + i)->length ?
174 "" : " (runlist end)");
175 if (!(rl + i)->length)