/rc6.d/K21mountdebugfs

http://github.com/brinkman83/bashrc · Shell · 140 lines · 110 code · 9 blank · 21 comment · 11 complexity · f3dac797b3c079f6d12faa3989ba8f9b MD5 · raw file

  1. #! /bin/sh
  2. # blktrace Mount debugfs on boot
  3. # Copyright (c) 2008 by Bas Zoetekouw.
  4. # Redistribution and use in source and binary forms, with or without
  5. # modification, are permitted onder terms of the GPL, version 2.
  6. ### BEGIN INIT INFO
  7. # Provides: mountdebugfs
  8. # Required-Start: $local_fs mountkernfs
  9. # Required-Stop: $local_fs
  10. # Should-Start:
  11. # Should-Stop:
  12. # Default-Start: S 1 2 3 4 5
  13. # Default-Stop: 0 6
  14. # Short-Description: Mount debugfs on /sys/kernel/debug
  15. ### END INIT INFO
  16. # load LSB functions (log_success_msg etc)
  17. . /lib/lsb/init-functions
  18. # main mount point
  19. mount_dir=/sys/kernel/debug
  20. # check if /proc/mounts exists
  21. if ! [ -r /proc/mounts ]
  22. then
  23. log_failure_msg "Failed! Couldn't read /proc/mounts."
  24. exit 1
  25. fi
  26. # no need to do anything if blktrace isn't installed
  27. if ! [ -x /usr/sbin/blktrace ]
  28. then
  29. exit 0
  30. fi
  31. # find where (if anywhere) debugfs is mounted
  32. mountpoints=$(
  33. awk '$3 == "debugfs" { print $2 }' < /proc/mounts
  34. )
  35. mount_debugfs ()
  36. {
  37. # check if any of the current mountpoints is /sys/kernel/debug
  38. found_syskerneldebug=0
  39. for d in $mountpoints
  40. do
  41. if [ $d = $mount_dir ]
  42. then
  43. found_syskerneldebug=1
  44. fi
  45. done
  46. if [ $found_syskerneldebug -eq 1 ]
  47. then
  48. log_success_msg "Debugfs is already mounted on $mount_dir; nothing to do";
  49. exit 0
  50. fi
  51. # check that debugfs is supported by the kernel
  52. if ! [ $( awk -F\\t '$2 == "debugfs" { print $2 }' < /proc/filesystems ) ]
  53. then
  54. log_failure_msg "Can't mount debugfs: not supported by your kernel"
  55. exit 0
  56. fi
  57. # check that /sys/kernel exists
  58. the_dir=$( dirname $mount_dir )
  59. if ! [ -d $the_dir ]
  60. then
  61. log_failure_msg "Can't mount debugfs on $mountdir: $the_dir doesn't exist."
  62. exit 1
  63. fi
  64. # do the actual mounting
  65. if mount -t debugfs debugfs $mount_dir
  66. then
  67. log_success_msg "Mounted debugfs on $mount_dir"
  68. else
  69. log_failure_msg "Couldn't mount debugfs on $mount_dir"
  70. exit 1
  71. fi
  72. }
  73. umount_debugfs ()
  74. {
  75. if [ $mountpoints ]
  76. then
  77. for d in $mountpoints
  78. do
  79. if [ $d = $mount_dir ]
  80. then
  81. if umount $d
  82. then
  83. log_success_msg "Unmounted debugfs from $d"
  84. else
  85. log_failure_msg "Couln't unmount debugfs from $d"
  86. fi
  87. fi
  88. done
  89. else
  90. log_success_msg "Debugfs is not mounted; nothing to do."
  91. fi
  92. }
  93. show_status ()
  94. {
  95. if [ $mountpoints ]
  96. then
  97. for d in $mountpoints
  98. do
  99. log_success_msg "Debugfs is mounted on $d"
  100. done
  101. else
  102. log_success_msg "Debugfs is not mounted"
  103. fi
  104. }
  105. case "$1" in
  106. start)
  107. mount_debugfs
  108. ;;
  109. stop)
  110. umount_debugfs
  111. ;;
  112. restart|reload|force-reload)
  113. umount_debugfs
  114. exec $0 start
  115. ;;
  116. status)
  117. show_status
  118. ;;
  119. *)
  120. echo "Usage: $0 {start|stop|restart|reload|force-reload|status}"
  121. exit 1
  122. ;;
  123. esac
  124. exit 0