Linux Audio

Check our new training course

Loading...
  1/*
  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 */
 21
 22#include "debug.h"
 23
 24/*
 25 * A static buffer to hold the error string being displayed and a spinlock
 26 * to protect concurrent accesses to it.
 27 */
 28static char err_buf[1024];
 29static DEFINE_SPINLOCK(err_buf_lock);
 30
 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
 37 *
 38 * Outputs a warning to the syslog for the mounted ntfs filesystem described
 39 * by @sb.
 40 *
 41 * @fmt and the corresponding @... is printf style format string containing
 42 * the warning string and the corresponding format arguments, respectively.
 43 *
 44 * @function is the name of the function from which __ntfs_warning is being
 45 * called.
 46 *
 47 * Note, you should be using debug.h::ntfs_warning(@sb, @fmt, @...) instead
 48 * as this provides the @function parameter automatically.
 49 */
 50void __ntfs_warning(const char *function, const struct super_block *sb,
 51		const char *fmt, ...)
 52{
 53	va_list args;
 54	int flen = 0;
 55
 56#ifndef DEBUG
 57	if (!printk_ratelimit())
 58		return;
 59#endif
 60	if (function)
 61		flen = strlen(function);
 62	spin_lock(&err_buf_lock);
 63	va_start(args, fmt);
 64	vsnprintf(err_buf, sizeof(err_buf), fmt, args);
 65	va_end(args);
 66	if (sb)
 67		printk(KERN_ERR "NTFS-fs warning (device %s): %s(): %s\n",
 68				sb->s_id, flen ? function : "", err_buf);
 69	else
 70		printk(KERN_ERR "NTFS-fs warning: %s(): %s\n",
 71				flen ? function : "", err_buf);
 72	spin_unlock(&err_buf_lock);
 73}
 74
 75/**
 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
 81 *
 82 * Outputs an error to the syslog for the mounted ntfs filesystem described
 83 * by @sb.
 84 *
 85 * @fmt and the corresponding @... is printf style format string containing
 86 * the error string and the corresponding format arguments, respectively.
 87 *
 88 * @function is the name of the function from which __ntfs_error is being
 89 * called.
 90 *
 91 * Note, you should be using debug.h::ntfs_error(@sb, @fmt, @...) instead
 92 * as this provides the @function parameter automatically.
 93 */
 94void __ntfs_error(const char *function, const struct super_block *sb,
 95		const char *fmt, ...)
 96{
 97	va_list args;
 98	int flen = 0;
 99
100#ifndef DEBUG
101	if (!printk_ratelimit())
102		return;
103#endif
104	if (function)
105		flen = strlen(function);
106	spin_lock(&err_buf_lock);
107	va_start(args, fmt);
108	vsnprintf(err_buf, sizeof(err_buf), fmt, args);
109	va_end(args);
110	if (sb)
111		printk(KERN_ERR "NTFS-fs error (device %s): %s(): %s\n",
112				sb->s_id, flen ? function : "", err_buf);
113	else
114		printk(KERN_ERR "NTFS-fs error: %s(): %s\n",
115				flen ? function : "", err_buf);
116	spin_unlock(&err_buf_lock);
117}
118
119#ifdef DEBUG
120
121/* If 1, output debug messages, and if 0, don't. */
122int debug_msgs = 0;
123
124void __ntfs_debug (const char *file, int line, const char *function,
125		const char *fmt, ...)
126{
127	va_list args;
128	int flen = 0;
129
130	if (!debug_msgs)
131		return;
132	if (function)
133		flen = strlen(function);
134	spin_lock(&err_buf_lock);
135	va_start(args, fmt);
136	vsnprintf(err_buf, sizeof(err_buf), fmt, args);
137	va_end(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);
141}
142
143/* Dump a runlist. Caller has to provide synchronisation for @rl. */
144void ntfs_debug_dump_runlist(const runlist_element *rl)
145{
146	int i;
147	const char *lcn_str[5] = { "LCN_HOLE         ", "LCN_RL_NOT_MAPPED",
148				   "LCN_ENOENT       ", "LCN_unknown      " };
149
150	if (!debug_msgs)
151		return;
152	printk(KERN_DEBUG "NTFS-fs DEBUG: Dumping runlist (values in hex):\n");
153	if (!rl) {
154		printk(KERN_DEBUG "Run list not present.\n");
155		return;
156	}
157	printk(KERN_DEBUG "VCN              LCN               Run length\n");
158	for (i = 0; ; i++) {
159		LCN lcn = (rl + i)->lcn;
160
161		if (lcn < (LCN)0) {
162			int index = -lcn - 1;
163
164			if (index > -LCN_ENOENT - 1)
165				index = 3;
166			printk(KERN_DEBUG "%-16Lx %s %-16Lx%s\n",
167					(long long)(rl + i)->vcn, lcn_str[index],
168					(long long)(rl + i)->length,
169					(rl + i)->length ? "" :
170						" (runlist end)");
171		} else
172			printk(KERN_DEBUG "%-16Lx %-16Lx  %-16Lx%s\n",
173					(long long)(rl + i)->vcn,
174					(long long)(rl + i)->lcn,
175					(long long)(rl + i)->length,
176					(rl + i)->length ? "" :
177						" (runlist end)");
178		if (!(rl + i)->length)
179			break;
180	}
181}
182
183#endif
  1// SPDX-License-Identifier: GPL-2.0-or-later
  2/*
  3 * debug.c - NTFS kernel debug support. Part of the Linux-NTFS project.
  4 *
  5 * Copyright (c) 2001-2004 Anton Altaparmakov
  6 */
  7#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  8#include "debug.h"
  9
 10/**
 11 * __ntfs_warning - output a warning to the syslog
 12 * @function:	name of function outputting the warning
 13 * @sb:		super block of mounted ntfs filesystem
 14 * @fmt:	warning string containing format specifications
 15 * @...:	a variable number of arguments specified in @fmt
 16 *
 17 * Outputs a warning to the syslog for the mounted ntfs filesystem described
 18 * by @sb.
 19 *
 20 * @fmt and the corresponding @... is printf style format string containing
 21 * the warning string and the corresponding format arguments, respectively.
 22 *
 23 * @function is the name of the function from which __ntfs_warning is being
 24 * called.
 25 *
 26 * Note, you should be using debug.h::ntfs_warning(@sb, @fmt, @...) instead
 27 * as this provides the @function parameter automatically.
 28 */
 29void __ntfs_warning(const char *function, const struct super_block *sb,
 30		const char *fmt, ...)
 31{
 32	struct va_format vaf;
 33	va_list args;
 34	int flen = 0;
 35
 36#ifndef DEBUG
 37	if (!printk_ratelimit())
 38		return;
 39#endif
 40	if (function)
 41		flen = strlen(function);
 42	va_start(args, fmt);
 43	vaf.fmt = fmt;
 44	vaf.va = &args;
 45	if (sb)
 46		pr_warn("(device %s): %s(): %pV\n",
 47			sb->s_id, flen ? function : "", &vaf);
 48	else
 49		pr_warn("%s(): %pV\n", flen ? function : "", &vaf);
 50	va_end(args);
 51}
 52
 53/**
 54 * __ntfs_error - output an error to the syslog
 55 * @function:	name of function outputting the error
 56 * @sb:		super block of mounted ntfs filesystem
 57 * @fmt:	error string containing format specifications
 58 * @...:	a variable number of arguments specified in @fmt
 59 *
 60 * Outputs an error to the syslog for the mounted ntfs filesystem described
 61 * by @sb.
 62 *
 63 * @fmt and the corresponding @... is printf style format string containing
 64 * the error string and the corresponding format arguments, respectively.
 65 *
 66 * @function is the name of the function from which __ntfs_error is being
 67 * called.
 68 *
 69 * Note, you should be using debug.h::ntfs_error(@sb, @fmt, @...) instead
 70 * as this provides the @function parameter automatically.
 71 */
 72void __ntfs_error(const char *function, const struct super_block *sb,
 73		const char *fmt, ...)
 74{
 75	struct va_format vaf;
 76	va_list args;
 77	int flen = 0;
 78
 79#ifndef DEBUG
 80	if (!printk_ratelimit())
 81		return;
 82#endif
 83	if (function)
 84		flen = strlen(function);
 85	va_start(args, fmt);
 86	vaf.fmt = fmt;
 87	vaf.va = &args;
 88	if (sb)
 89		pr_err("(device %s): %s(): %pV\n",
 90		       sb->s_id, flen ? function : "", &vaf);
 91	else
 92		pr_err("%s(): %pV\n", flen ? function : "", &vaf);
 93	va_end(args);
 94}
 95
 96#ifdef DEBUG
 97
 98/* If 1, output debug messages, and if 0, don't. */
 99int debug_msgs = 0;
100
101void __ntfs_debug(const char *file, int line, const char *function,
102		const char *fmt, ...)
103{
104	struct va_format vaf;
105	va_list args;
106	int flen = 0;
107
108	if (!debug_msgs)
109		return;
110	if (function)
111		flen = strlen(function);
112	va_start(args, fmt);
113	vaf.fmt = fmt;
114	vaf.va = &args;
115	pr_debug("(%s, %d): %s(): %pV", file, line, flen ? function : "", &vaf);
116	va_end(args);
117}
118
119/* Dump a runlist. Caller has to provide synchronisation for @rl. */
120void ntfs_debug_dump_runlist(const runlist_element *rl)
121{
122	int i;
123	const char *lcn_str[5] = { "LCN_HOLE         ", "LCN_RL_NOT_MAPPED",
124				   "LCN_ENOENT       ", "LCN_unknown      " };
125
126	if (!debug_msgs)
127		return;
128	pr_debug("Dumping runlist (values in hex):\n");
129	if (!rl) {
130		pr_debug("Run list not present.\n");
131		return;
132	}
133	pr_debug("VCN              LCN               Run length\n");
134	for (i = 0; ; i++) {
135		LCN lcn = (rl + i)->lcn;
136
137		if (lcn < (LCN)0) {
138			int index = -lcn - 1;
139
140			if (index > -LCN_ENOENT - 1)
141				index = 3;
142			pr_debug("%-16Lx %s %-16Lx%s\n",
143					(long long)(rl + i)->vcn, lcn_str[index],
144					(long long)(rl + i)->length,
145					(rl + i)->length ? "" :
146						" (runlist end)");
147		} else
148			pr_debug("%-16Lx %-16Lx  %-16Lx%s\n",
149					(long long)(rl + i)->vcn,
150					(long long)(rl + i)->lcn,
151					(long long)(rl + i)->length,
152					(rl + i)->length ? "" :
153						" (runlist end)");
154		if (!(rl + i)->length)
155			break;
156	}
157}
158
159#endif