xref: /linux/fs/jfs/jfs_debug.c (revision 9527cc77e25b3a3787569edcbb8e74080b8df54a)
1 /*
2  *   Copyright (C) International Business Machines Corp., 2000-2004
3  *   Portions Copyright (C) Christoph Hellwig, 2001-2002
4  *
5  *   This program is free software;  you can redistribute it and/or modify
6  *   it under the terms of the GNU General Public License as published by
7  *   the Free Software Foundation; either version 2 of the License, or
8  *   (at your option) any later version.
9  *
10  *   This program is distributed in the hope that it will be useful,
11  *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
13  *   the GNU General Public License for more details.
14  *
15  *   You should have received a copy of the GNU General Public License
16  *   along with this program;  if not, write to the Free Software
17  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */
19 
20 #include <linux/fs.h>
21 #include <linux/ctype.h>
22 #include <linux/module.h>
23 #include <linux/proc_fs.h>
24 #include <asm/uaccess.h>
25 #include "jfs_incore.h"
26 #include "jfs_filsys.h"
27 #include "jfs_debug.h"
28 
29 #ifdef CONFIG_JFS_DEBUG
30 void dump_mem(char *label, void *data, int length)
31 {
32 	int i, j;
33 	int *intptr = data;
34 	char *charptr = data;
35 	char buf[10], line[80];
36 
37 	printk("%s: dump of %d bytes of data at 0x%p\n\n", label, length,
38 	       data);
39 	for (i = 0; i < length; i += 16) {
40 		line[0] = 0;
41 		for (j = 0; (j < 4) && (i + j * 4 < length); j++) {
42 			sprintf(buf, " %08x", intptr[i / 4 + j]);
43 			strcat(line, buf);
44 		}
45 		buf[0] = ' ';
46 		buf[2] = 0;
47 		for (j = 0; (j < 16) && (i + j < length); j++) {
48 			buf[1] =
49 			    isprint(charptr[i + j]) ? charptr[i + j] : '.';
50 			strcat(line, buf);
51 		}
52 		printk("%s\n", line);
53 	}
54 }
55 #endif
56 
57 #ifdef PROC_FS_JFS /* see jfs_debug.h */
58 
59 static struct proc_dir_entry *base;
60 #ifdef CONFIG_JFS_DEBUG
61 static int loglevel_read(char *page, char **start, off_t off,
62 			 int count, int *eof, void *data)
63 {
64 	int len;
65 
66 	len = sprintf(page, "%d\n", jfsloglevel);
67 
68 	len -= off;
69 	*start = page + off;
70 
71 	if (len > count)
72 		len = count;
73 	else
74 		*eof = 1;
75 
76 	if (len < 0)
77 		len = 0;
78 
79 	return len;
80 }
81 
82 static int loglevel_write(struct file *file, const char __user *buffer,
83 			unsigned long count, void *data)
84 {
85 	char c;
86 
87 	if (get_user(c, buffer))
88 		return -EFAULT;
89 
90 	/* yes, I know this is an ASCIIism.  --hch */
91 	if (c < '0' || c > '9')
92 		return -EINVAL;
93 	jfsloglevel = c - '0';
94 	return count;
95 }
96 #endif
97 
98 static struct {
99 	const char	*name;
100 	read_proc_t	*read_fn;
101 	write_proc_t	*write_fn;
102 } Entries[] = {
103 #ifdef CONFIG_JFS_STATISTICS
104 	{ "lmstats",	jfs_lmstats_read, },
105 	{ "txstats",	jfs_txstats_read, },
106 	{ "xtstat",	jfs_xtstat_read, },
107 	{ "mpstat",	jfs_mpstat_read, },
108 #endif
109 #ifdef CONFIG_JFS_DEBUG
110 	{ "TxAnchor",	jfs_txanchor_read, },
111 	{ "loglevel",	loglevel_read, loglevel_write }
112 #endif
113 };
114 #define NPROCENT	(sizeof(Entries)/sizeof(Entries[0]))
115 
116 void jfs_proc_init(void)
117 {
118 	int i;
119 
120 	if (!(base = proc_mkdir("jfs", proc_root_fs)))
121 		return;
122 	base->owner = THIS_MODULE;
123 
124 	for (i = 0; i < NPROCENT; i++) {
125 		struct proc_dir_entry *p;
126 		if ((p = create_proc_entry(Entries[i].name, 0, base))) {
127 			p->read_proc = Entries[i].read_fn;
128 			p->write_proc = Entries[i].write_fn;
129 		}
130 	}
131 }
132 
133 void jfs_proc_clean(void)
134 {
135 	int i;
136 
137 	if (base) {
138 		for (i = 0; i < NPROCENT; i++)
139 			remove_proc_entry(Entries[i].name, base);
140 		remove_proc_entry("jfs", proc_root_fs);
141 	}
142 }
143 
144 #endif /* PROC_FS_JFS */
145