sysctl.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  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,
  5. * Copyright (C) 1997 Martin von Löwis, Régis Duchesne
  6. *
  7. * Copyright (c) 2002-2005 Anton Altaparmakov
  8. */
  9. #ifdef DEBUG
  10. #include <linux/module.h>
  11. #ifdef CONFIG_SYSCTL
  12. #include <linux/proc_fs.h>
  13. #include <linux/sysctl.h>
  14. #include "sysctl.h"
  15. #include "debug.h"
  16. /* Definition of the ntfs sysctl. */
  17. static struct ctl_table ntfs_sysctls[] = {
  18. {
  19. .procname = "ntfs-debug",
  20. .data = &debug_msgs, /* Data pointer and size. */
  21. .maxlen = sizeof(debug_msgs),
  22. .mode = 0644, /* Mode, proc handler. */
  23. .proc_handler = proc_dointvec
  24. },
  25. {}
  26. };
  27. /* Define the parent directory /proc/sys/fs. */
  28. static struct ctl_table sysctls_root[] = {
  29. {
  30. .procname = "fs",
  31. .mode = 0555,
  32. .child = ntfs_sysctls
  33. },
  34. {}
  35. };
  36. /* Storage for the sysctls header. */
  37. static struct ctl_table_header *sysctls_root_table;
  38. /**
  39. * ntfs_sysctl - add or remove the debug sysctl
  40. * @add: add (1) or remove (0) the sysctl
  41. *
  42. * Add or remove the debug sysctl. Return 0 on success or -errno on error.
  43. */
  44. int ntfs_sysctl(int add)
  45. {
  46. if (add) {
  47. BUG_ON(sysctls_root_table);
  48. sysctls_root_table = register_sysctl_table(sysctls_root);
  49. if (!sysctls_root_table)
  50. return -ENOMEM;
  51. } else {
  52. BUG_ON(!sysctls_root_table);
  53. unregister_sysctl_table(sysctls_root_table);
  54. sysctls_root_table = NULL;
  55. }
  56. return 0;
  57. }
  58. #endif /* CONFIG_SYSCTL */
  59. #endif /* DEBUG */