blob: a7090760602538ebd1ec3649e8eea410b872398f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Dave Kleikamp63f83c92006-10-02 09:55:27 -05007 * the Free Software Foundation; either version 2 of the License, or
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 * (at your option) any later version.
Dave Kleikamp63f83c92006-10-02 09:55:27 -05009 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 * 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
Dave Kleikamp63f83c92006-10-02 09:55:27 -050016 * along with this program; if not, write to the Free Software
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 * 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>
Alexey Dobriyanb2e03ca2008-05-13 08:22:10 -050024#include <linux/seq_file.h>
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080025#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include "jfs_incore.h"
27#include "jfs_filsys.h"
28#include "jfs_debug.h"
29
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#ifdef PROC_FS_JFS /* see jfs_debug.h */
31
32static struct proc_dir_entry *base;
33#ifdef CONFIG_JFS_DEBUG
Alexey Dobriyanb2e03ca2008-05-13 08:22:10 -050034static int jfs_loglevel_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -070035{
Alexey Dobriyanb2e03ca2008-05-13 08:22:10 -050036 seq_printf(m, "%d\n", jfsloglevel);
37 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070038}
39
Alexey Dobriyanb2e03ca2008-05-13 08:22:10 -050040static int jfs_loglevel_proc_open(struct inode *inode, struct file *file)
41{
42 return single_open(file, jfs_loglevel_proc_show, NULL);
43}
44
45static ssize_t jfs_loglevel_proc_write(struct file *file,
46 const char __user *buffer, size_t count, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -070047{
48 char c;
49
50 if (get_user(c, buffer))
51 return -EFAULT;
52
53 /* yes, I know this is an ASCIIism. --hch */
54 if (c < '0' || c > '9')
55 return -EINVAL;
56 jfsloglevel = c - '0';
57 return count;
58}
Alexey Dobriyanb2e03ca2008-05-13 08:22:10 -050059
60static const struct file_operations jfs_loglevel_proc_fops = {
Alexey Dobriyanb2e03ca2008-05-13 08:22:10 -050061 .open = jfs_loglevel_proc_open,
62 .read = seq_read,
63 .llseek = seq_lseek,
64 .release = single_release,
65 .write = jfs_loglevel_proc_write,
66};
Linus Torvalds1da177e2005-04-16 15:20:36 -070067#endif
68
Linus Torvalds1da177e2005-04-16 15:20:36 -070069static struct {
70 const char *name;
Alexey Dobriyanb2e03ca2008-05-13 08:22:10 -050071 const struct file_operations *proc_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072} Entries[] = {
73#ifdef CONFIG_JFS_STATISTICS
Alexey Dobriyanb2e03ca2008-05-13 08:22:10 -050074 { "lmstats", &jfs_lmstats_proc_fops, },
75 { "txstats", &jfs_txstats_proc_fops, },
76 { "xtstat", &jfs_xtstat_proc_fops, },
77 { "mpstat", &jfs_mpstat_proc_fops, },
Linus Torvalds1da177e2005-04-16 15:20:36 -070078#endif
79#ifdef CONFIG_JFS_DEBUG
Alexey Dobriyanb2e03ca2008-05-13 08:22:10 -050080 { "TxAnchor", &jfs_txanchor_proc_fops, },
81 { "loglevel", &jfs_loglevel_proc_fops }
Linus Torvalds1da177e2005-04-16 15:20:36 -070082#endif
83};
Tobias Klausere8c96f82006-03-24 03:15:34 -080084#define NPROCENT ARRAY_SIZE(Entries)
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
86void jfs_proc_init(void)
87{
88 int i;
89
Alexey Dobriyan36a5aeb2008-04-29 01:01:42 -070090 if (!(base = proc_mkdir("fs/jfs", NULL)))
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
Alexey Dobriyanb2e03ca2008-05-13 08:22:10 -050093 for (i = 0; i < NPROCENT; i++)
94 proc_create(Entries[i].name, 0, base, Entries[i].proc_fops);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095}
96
97void jfs_proc_clean(void)
98{
99 int i;
100
101 if (base) {
102 for (i = 0; i < NPROCENT; i++)
103 remove_proc_entry(Entries[i].name, base);
Alexey Dobriyan36a5aeb2008-04-29 01:01:42 -0700104 remove_proc_entry("fs/jfs", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 }
106}
107
108#endif /* PROC_FS_JFS */