auchk 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #!/bin/sh -
  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. set -eu
  18. #set -x
  19. EEcho() # str
  20. {
  21. echo $0: $@ 1>&2
  22. }
  23. f=/etc/default/aufs
  24. . $f
  25. Usage()
  26. {
  27. echo $0 writable_branch '[...]'
  28. }
  29. Pass() # title
  30. {
  31. pass=$(($pass + 1))
  32. EEcho \[Pass $pass\] $@
  33. }
  34. Remove() # file
  35. {
  36. if [ -d "$1" ]
  37. then
  38. rm -ir "$1" || :
  39. else
  40. rm -v "$1" || :
  41. fi
  42. }
  43. for i
  44. do
  45. EEcho Checking "$i" for aufs
  46. cd "$i"
  47. case $(stat -f -c %T .) in
  48. aufs|UNKNOWN*${AUFS_SUPER_MAGIC_HEX}*)
  49. EEcho $i must not be aufs
  50. cd $OLDPWD
  51. continue
  52. ;;
  53. esac
  54. ########################################
  55. pass=0
  56. Pass Illegal whiteout
  57. find . -name '.wh.*' ! -name '.wh..wh.*' -printf '%h\0%f\0' |
  58. xargs -r0n2 |
  59. while read dir wh
  60. do
  61. #echo \""$dir"\" \""$wh"\"
  62. base=$(echo "$wh" | cut -c5-)
  63. test ! -e "$dir/$base" && continue
  64. ls -ld "$dir/$wh" "$dir/$base"
  65. read -p 'Which to remove [whiteout/real/skip]? ' ans \
  66. < /dev/tty > /dev/tty 2>&1
  67. case "$ans" in
  68. [wW]*) Remove "$dir/$wh" || :;;
  69. [rR]*) Remove "$dir/$base" || :;;
  70. *) echo skipped;;
  71. esac
  72. done
  73. ########################################
  74. Pass Remained pseudo-links
  75. did=0
  76. for plink in ${AUFS_WH_PLINKDIR}/*
  77. do
  78. test ! -e "$plink" && break
  79. if [ -d "$plink" ]
  80. then
  81. EEcho illegal "$plink"
  82. continue
  83. fi
  84. did=1
  85. #ls -l "$plink" || :
  86. find . -inum $(basename "$plink" | cut -f2 -d .) -ls || :
  87. done
  88. if [ $did -ne 0 ]
  89. then
  90. cat <<- EOF
  91. They will be maintained at remount or umount time,
  92. if you installed aufs helper scripts (See README
  93. in detail).
  94. If "$i" is not a writeble branch of CURRENTLY mounted
  95. aufs, you need to maintain them by yourself.
  96. EOF
  97. fi
  98. ########################################
  99. Pass Remained temp files
  100. for tmp in ${AUFS_WH_TMPDIR}/*
  101. do
  102. test ! -e "$tmp" && break
  103. if [ -d "$tmp" ]
  104. then
  105. EEcho illegal "$tmp"
  106. continue
  107. fi
  108. ls -l "$tmp" || :
  109. rm -i "$tmp" || :
  110. done
  111. # nothing to do for xinodir
  112. cd $OLDPWD
  113. done