Thomas Gleixner | a1d312d | 2019-05-22 09:51:42 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 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 Engelhardt | 96de0e2 | 2007-10-19 23:21:04 +0200 | [diff] [blame] | 5 | * Copyright (C) 1997 Martin von Löwis, Régis Duchesne |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * |
Anton Altaparmakov | c002f42 | 2005-02-03 12:02:56 +0000 | [diff] [blame] | 7 | * Copyright (c) 2002-2005 Anton Altaparmakov |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | */ |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | /* Definition of the ntfs sysctl. */ |
Joe Perches | 5eccdf3 | 2014-06-06 14:38:04 -0700 | [diff] [blame] | 23 | static struct ctl_table ntfs_sysctls[] = { |
Eric W. Biederman | 4ed075e | 2007-02-14 00:33:56 -0800 | [diff] [blame] | 24 | { |
Eric W. Biederman | 4ed075e | 2007-02-14 00:33:56 -0800 | [diff] [blame] | 25 | .procname = "ntfs-debug", |
| 26 | .data = &debug_msgs, /* Data pointer and size. */ |
| 27 | .maxlen = sizeof(debug_msgs), |
| 28 | .mode = 0644, /* Mode, proc handler. */ |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 29 | .proc_handler = proc_dointvec |
Eric W. Biederman | 4ed075e | 2007-02-14 00:33:56 -0800 | [diff] [blame] | 30 | }, |
| 31 | {} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | }; |
| 33 | |
| 34 | /* Define the parent directory /proc/sys/fs. */ |
Joe Perches | 5eccdf3 | 2014-06-06 14:38:04 -0700 | [diff] [blame] | 35 | static struct ctl_table sysctls_root[] = { |
Eric W. Biederman | 4ed075e | 2007-02-14 00:33:56 -0800 | [diff] [blame] | 36 | { |
Eric W. Biederman | 4ed075e | 2007-02-14 00:33:56 -0800 | [diff] [blame] | 37 | .procname = "fs", |
| 38 | .mode = 0555, |
| 39 | .child = ntfs_sysctls |
| 40 | }, |
| 41 | {} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | }; |
| 43 | |
| 44 | /* Storage for the sysctls header. */ |
Fabian Frederick | 504e0e2 | 2014-06-04 16:05:50 -0700 | [diff] [blame] | 45 | static struct ctl_table_header *sysctls_root_table; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
| 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 | */ |
| 53 | int ntfs_sysctl(int add) |
| 54 | { |
| 55 | if (add) { |
| 56 | BUG_ON(sysctls_root_table); |
Eric W. Biederman | 0b4d414 | 2007-02-14 00:34:09 -0800 | [diff] [blame] | 57 | sysctls_root_table = register_sysctl_table(sysctls_root); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | if (!sysctls_root_table) |
| 59 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | } 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 */ |