blob: a030d00af90c4a25fd9b9e85fde321f36c708f2f [file] [log] [blame]
Thomas Gleixnera1d312d2019-05-22 09:51:42 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * sysctl.c - Code for sysctl handling in NTFS Linux kernel driver. Part of
4 * the Linux-NTFS project. Adapted from the old NTFS driver,
Jan Engelhardt96de0e22007-10-19 23:21:04 +02005 * Copyright (C) 1997 Martin von Löwis, Régis Duchesne
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 *
Anton Altaparmakovc002f422005-02-03 12:02:56 +00007 * Copyright (c) 2002-2005 Anton Altaparmakov
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 */
9
10#ifdef DEBUG
11
12#include <linux/module.h>
13
14#ifdef CONFIG_SYSCTL
15
16#include <linux/proc_fs.h>
17#include <linux/sysctl.h>
18
19#include "sysctl.h"
20#include "debug.h"
21
Linus Torvalds1da177e2005-04-16 15:20:36 -070022/* Definition of the ntfs sysctl. */
Joe Perches5eccdf32014-06-06 14:38:04 -070023static struct ctl_table ntfs_sysctls[] = {
Eric W. Biederman4ed075e2007-02-14 00:33:56 -080024 {
Eric W. Biederman4ed075e2007-02-14 00:33:56 -080025 .procname = "ntfs-debug",
26 .data = &debug_msgs, /* Data pointer and size. */
27 .maxlen = sizeof(debug_msgs),
28 .mode = 0644, /* Mode, proc handler. */
Eric W. Biederman6d456112009-11-16 03:11:48 -080029 .proc_handler = proc_dointvec
Eric W. Biederman4ed075e2007-02-14 00:33:56 -080030 },
31 {}
Linus Torvalds1da177e2005-04-16 15:20:36 -070032};
33
34/* Define the parent directory /proc/sys/fs. */
Joe Perches5eccdf32014-06-06 14:38:04 -070035static struct ctl_table sysctls_root[] = {
Eric W. Biederman4ed075e2007-02-14 00:33:56 -080036 {
Eric W. Biederman4ed075e2007-02-14 00:33:56 -080037 .procname = "fs",
38 .mode = 0555,
39 .child = ntfs_sysctls
40 },
41 {}
Linus Torvalds1da177e2005-04-16 15:20:36 -070042};
43
44/* Storage for the sysctls header. */
Fabian Frederick504e0e22014-06-04 16:05:50 -070045static struct ctl_table_header *sysctls_root_table;
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
47/**
48 * ntfs_sysctl - add or remove the debug sysctl
49 * @add: add (1) or remove (0) the sysctl
50 *
51 * Add or remove the debug sysctl. Return 0 on success or -errno on error.
52 */
53int ntfs_sysctl(int add)
54{
55 if (add) {
56 BUG_ON(sysctls_root_table);
Eric W. Biederman0b4d4142007-02-14 00:34:09 -080057 sysctls_root_table = register_sysctl_table(sysctls_root);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 if (!sysctls_root_table)
59 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 } else {
61 BUG_ON(!sysctls_root_table);
62 unregister_sysctl_table(sysctls_root_table);
63 sysctls_root_table = NULL;
64 }
65 return 0;
66}
67
68#endif /* CONFIG_SYSCTL */
69#endif /* DEBUG */