[PATCH] Fix bug in saa7146 analog tv i2c-handling
[linux-2.6/history.git] / fs / ntfs / debug.c
blobb78932c15f076557b90987fb72173ec111c7f911
1 /*
2 * debug.c - NTFS kernel debug support. Part of the Linux-NTFS project.
4 * Copyright (c) 2001,2002 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
22 #include "debug.h"
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 spinlock_t err_buf_lock = SPIN_LOCK_UNLOCKED;
31 /**
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
39 * by @sb.
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
45 * called.
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,
51 const char *fmt, ...)
53 va_list args;
54 int flen = 0;
56 if (function)
57 flen = strlen(function);
58 spin_lock(&err_buf_lock);
59 va_start(args, fmt);
60 vsnprintf(err_buf, sizeof(err_buf), fmt, args);
61 va_end(args);
62 if (sb)
63 printk(KERN_ERR "NTFS-fs warning (device %s): %s(): %s\n",
64 sb->s_id, flen ? function : "", err_buf);
65 else
66 printk(KERN_ERR "NTFS-fs warning: %s(): %s\n",
67 flen ? function : "", err_buf);
68 spin_unlock(&err_buf_lock);
71 /**
72 * __ntfs_error - output an error to the syslog
73 * @function: name of function outputting the error
74 * @sb: super block of mounted ntfs filesystem
75 * @fmt: error string containing format specifications
76 * @...: a variable number of arguments specified in @fmt
78 * Outputs an error to the syslog for the mounted ntfs filesystem described
79 * by @sb.
81 * @fmt and the corresponding @... is printf style format string containing
82 * the error string and the corresponding format arguments, respectively.
84 * @function is the name of the function from which __ntfs_error is being
85 * called.
87 * Note, you should be using debug.h::ntfs_error(@sb, @fmt, @...) instead
88 * as this provides the @function parameter automatically.
90 void __ntfs_error(const char *function, const struct super_block *sb,
91 const char *fmt, ...)
93 va_list args;
94 int flen = 0;
96 if (function)
97 flen = strlen(function);
98 spin_lock(&err_buf_lock);
99 va_start(args, fmt);
100 vsnprintf(err_buf, sizeof(err_buf), fmt, args);
101 va_end(args);
102 if (sb)
103 printk(KERN_ERR "NTFS-fs error (device %s): %s(): %s\n",
104 sb->s_id, flen ? function : "", err_buf);
105 else
106 printk(KERN_ERR "NTFS-fs error: %s(): %s\n",
107 flen ? function : "", err_buf);
108 spin_unlock(&err_buf_lock);
111 #ifdef DEBUG
113 /* If 1, output debug messages, and if 0, don't. */
114 int debug_msgs = 0;
116 void __ntfs_debug (const char *file, int line, const char *function,
117 const char *fmt, ...)
119 va_list args;
120 int flen = 0;
122 if (!debug_msgs)
123 return;
124 if (function)
125 flen = strlen(function);
126 spin_lock(&err_buf_lock);
127 va_start(args, fmt);
128 vsnprintf(err_buf, sizeof(err_buf), fmt, args);
129 va_end(args);
130 printk(KERN_DEBUG "NTFS-fs DEBUG (%s, %d): %s: %s\n",
131 file, line, flen ? function : "", err_buf);
132 spin_unlock(&err_buf_lock);
135 /* Dump a run list. Caller has to provide synchronisation for @rl. */
136 void ntfs_debug_dump_runlist(const run_list_element *rl)
138 int i;
139 const char *lcn_str[5] = { "LCN_HOLE ", "LCN_RL_NOT_MAPPED",
140 "LCN_ENOENT ", "LCN_EINVAL ",
141 "LCN_unknown " };
143 if (!debug_msgs)
144 return;
145 printk(KERN_DEBUG "NTFS-fs DEBUG: Dumping run list (values "
146 "in hex):\n");
147 if (!rl) {
148 printk(KERN_DEBUG "Run list not present.\n");
149 return;
151 printk(KERN_DEBUG "VCN LCN Run length\n");
152 for (i = 0; ; i++) {
153 LCN lcn = (rl + i)->lcn;
155 if (lcn < (LCN)0) {
156 int index = -lcn - 1;
158 if (index > -LCN_EINVAL - 1)
159 index = 4;
160 printk(KERN_DEBUG "%-16Lx %s %-16Lx%s\n",
161 (rl + i)->vcn, lcn_str[index],
162 (rl + i)->length, (rl + i)->length ?
163 "" : " (run list end)");
164 } else
165 printk(KERN_DEBUG "%-16Lx %-16Lx %-16Lx%s\n",
166 (rl + i)->vcn, (rl + i)->lcn,
167 (rl + i)->length, (rl + i)->length ?
168 "" : " (run list end)");
169 if (!(rl + i)->length)
170 break;
174 #endif