PageRenderTime 83ms CodeModel.GetById 40ms app.highlight 5ms RepoModel.GetById 35ms app.codeStats 0ms

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