force_erase.sh 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/bin/bash
  2. #********************************************************************************#
  3. #* *#
  4. #* Copyright (c) 2005 Instituto Nokia de Tecnologia - INdT - Manaus Brazil *#
  5. #* *#
  6. #* This program is free software; you can redistribute it and#or modify *#
  7. #* it under the terms of the GNU General Public License as published by *#
  8. #* the Free Software Foundation; either version 2 of the License, or *#
  9. #* (at your option) any later version. *#
  10. #* *#
  11. #* This program is distributed in the hope that it will be useful, *#
  12. #* but WITHOUT ANY WARRANTY; without even the implied warranty of *#
  13. #* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See *#
  14. #* the GNU General Public License for more details. *#
  15. #* *#
  16. #* You should have received a copy of the GNU General Public License *#
  17. #* along with this program; if not, write to the Free Software *#
  18. #* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *#
  19. #* *#
  20. #********************************************************************************#
  21. #********************************************************************************#
  22. #* *#
  23. #* File: force_erase.sh *#
  24. #* *#
  25. #* Description: used to force-erase a card, usually when the user has forgot *#
  26. #* the password and wants to unlock the card. NOTE: all the card's contents are *#
  27. #* lost when using this option! It only works for _locked_ cards. *#
  28. #* *#
  29. #* Total Tests: 1 *#
  30. #* *#
  31. #* Author: Anderson Briglia <anderson.briglia@indt.org.br> *#
  32. #* Anderson Lizardo <anderson.lizardo@indt.org.br> *#
  33. #* Carlos Eduardo Aguiar <carlos.aguiar@indt.org.br> *#
  34. #* *#
  35. #* *#
  36. #* *#
  37. #********************************************************************************#
  38. force_erase()
  39. {
  40. export TST_TOTAL=1 # Total number of test cases in this file.
  41. # Set up LTPTMP (temporary directory used by the tests).
  42. LTPTMP=${TMP} # Temporary directory to create files, etc.
  43. export TCID="force_erase" # Test case identifier
  44. export TST_COUNT=0 # Set up is initialized as test 0
  45. RC=0 # Exit values of system commands used
  46. echo "=== Erase MMC Password (AND its contents!) ==="
  47. if grep -q "unlocked" /sys/bus/mmc/devices/mmc0\:*/lockable; then
  48. echo -n "*** No locked MMC card was found. You can only use the forced "
  49. echo "erase operation on locked cards."
  50. exit 1
  51. fi
  52. while [ -z "$yn" ]; do
  53. read -p "WARNING: all card contents will be lost! Continue? (y/n) " yn
  54. case "$yn" in
  55. y|Y) break ;;
  56. n|N) exit 0 ;;
  57. *) yn=""
  58. esac
  59. done
  60. echo "Erasing card. This may take some time, wait..."
  61. echo erase > /sys/bus/mmc/devices/mmc0\:*/lockable || \
  62. { echo "*** Error erasing card" >&2; exit 1 ;}
  63. # Clear session keyring
  64. # FIXME: It assumes we have only the MMC key there
  65. keyctl clear -3
  66. echo "Card unlocked and erased."
  67. }
  68. force_erase || exit $RC