hdparm-init-8 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/sbin/openrc-run
  2. # Copyright 1999-2012 Gentoo Foundation
  3. # Distributed under the terms of the GNU General Public License v2
  4. depend() {
  5. before bootmisc
  6. }
  7. do_hdparm() {
  8. local e=
  9. eval e=\$${extra_args}
  10. [ -z "${args}${all_args}${e}" ] && return 0
  11. if [ -n "${args:=${all_args} ${e}}" ] ; then
  12. local orgdevice=$(readlink -f "${device}")
  13. if [ -b "${orgdevice}" ] ; then
  14. ebegin "Running hdparm on ${device}"
  15. hdparm ${args} "${device}" > /dev/null
  16. eend $?
  17. fi
  18. fi
  19. }
  20. scan_nondevfs() {
  21. # non-devfs compatible system
  22. local device
  23. for device in /dev/hd* /dev/sd* /dev/cdrom* ; do
  24. [ -e "${device}" ] || continue
  25. case "${device}" in
  26. *[0-9]) continue ;;
  27. /dev/hd*) extra_args="pata_all_args" ;;
  28. /dev/sd*) extra_args="sata_all_args" ;;
  29. *) extra_args="_no_xtra_args" ;;
  30. esac
  31. # check that the block device really exists by
  32. # opening it for reading
  33. local errmsg= status= nomed=1
  34. errmsg=$(export LC_ALL=C ; : 2>&1 <"${device}")
  35. status=$?
  36. case ${errmsg} in
  37. *": No medium found") nomed=0;;
  38. esac
  39. if [ -b "${device}" ] && [ "${status}" = "0" -o "${nomed}" = "0" ] ; then
  40. local conf_var="${device##*/}_args"
  41. eval args=\$${conf_var}
  42. do_hdparm
  43. fi
  44. done
  45. }
  46. start() {
  47. if get_bootparam "nohdparm" ; then
  48. ewarn "Skipping hdparm init as requested in kernel cmdline"
  49. return 0
  50. fi
  51. scan_nondevfs
  52. }