fstab 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2007 OpenWrt.org
  3. START=20
  4. do_mount() {
  5. local cfg="$1"
  6. config_get fstype "$cfg" fstype
  7. fstype="${fstype:-auto}"
  8. config_get options "$cfg" options
  9. options="${options:-rw}"
  10. config_get device "$cfg" device
  11. [ -n "device" ] || return 0
  12. config_get target "$cfg" target
  13. [ -n "target" ] || return 0
  14. mkdir -p $target
  15. config_get_bool enabled "$cfg" "enabled" '1'
  16. [ "$enabled" -eq 0 ] && options="noauto,$options"
  17. echo "$device $target $fstype $options 0 0" >> /tmp/fstab
  18. }
  19. do_swapon() {
  20. local cfg="$1"
  21. config_get device "$cfg" device
  22. [ -n "device" ] || return 0
  23. config_get_bool enabled "$cfg" "enabled" '1'
  24. [ "$enabled" -gt 0 ] && {
  25. echo "$device none swap ${noauto}sw 0 0" >> /tmp/fstab
  26. }
  27. }
  28. do_unmount() {
  29. local cfg="$1"
  30. config_get target "$cfg" target
  31. [ -n "target" ] || return 0
  32. config_get_bool enabled "$cfg" "enabled" '1'
  33. [ "$enabled" -gt 0 ] && {
  34. umount $target
  35. }
  36. }
  37. do_swapoff() {
  38. local cfg="$1"
  39. config_get device "$cfg" device
  40. [ -n "device" ] || return 0
  41. config_get_bool enabled "$cfg" "enabled" '1'
  42. [ "$enabled" -gt 0 ] && type swapoff >/dev/null && {
  43. swapoff $device
  44. }
  45. }
  46. start() {
  47. config_load fstab
  48. echo '# WARNING: this is an auto generated file, please use uci to set static filesystems' > /tmp/fstab
  49. config_foreach do_mount mount
  50. config_foreach do_swapon swap
  51. mount -a
  52. swapon -a
  53. }
  54. stop() {
  55. config_load fstab
  56. config_foreach do_unmount mount
  57. config_foreach do_swapoff swap
  58. }