aufs.shlib 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #
  2. # Copyright (C) 2005-2009 Junjiro Okajima
  3. #
  4. # This program, aufs is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  17. # library functions for aufs shell scripts
  18. # path in canonical representation
  19. SetDir() # var dir
  20. {
  21. cd "$2"
  22. eval "$1=\"$PWD\""
  23. cd "$OLDPWD"
  24. }
  25. # escape the unprintable characters, mainly for grep-ping /proc/mounts
  26. Esc() # [-e]
  27. {
  28. sed -r -e '
  29. s/\\/\\134/g
  30. s/$/\\012/
  31. ' |
  32. tr -d '\n' |
  33. sed -r -e '
  34. s/ /\\040/g
  35. s/\t/\\011/g
  36. s/\r/\\015/g
  37. s/\\012$//
  38. ' |
  39. { test $# -eq 1 &&
  40. test "$1" = "-e" &&
  41. sed -r -e 's/\\/\\\\/g' ||
  42. cat; }
  43. echo
  44. }
  45. # find a mount-entry by its mount-point
  46. FindMntEnt() # mntpnt
  47. {
  48. proc_mounts=/proc/self/mounts
  49. test ! -e $proc_mounts && proc_mounts=/proc/$$/mounts
  50. test ! -e $proc_mounts && proc_mounts=/proc/mounts
  51. fgrep \ $(echo "$1" | Esc)\ aufs\ $proc_mounts |
  52. tail -n 1
  53. }
  54. # current mount options
  55. MntOpts() # mntpnt
  56. {
  57. FindMntEnt "$1" |
  58. cut -f4 -d' '
  59. }
  60. ########################################
  61. AuDebug() # 1 | 0 [sec]
  62. {
  63. test $1 -eq 0 && set +x
  64. aufs_debug=/sys/module/aufs/parameters/debug
  65. if [ -f $aufs_debug ]
  66. then
  67. echo $1 | sudo dd of=$aufs_debug 2> /dev/null
  68. test $# -eq 2 && sleep $2
  69. fi
  70. test $1 -eq 1 && set -x
  71. true
  72. }
  73. # Local variables: ;
  74. # mode: text;
  75. # End: ;