fstab.init 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2007 OpenWrt.org
  3. # Copyright (C) 2010 Vertical Communications
  4. # This is free software, licensed under the GNU General Public License v2.
  5. # See /LICENSE for more information.
  6. #
  7. START=20
  8. do_mount() {
  9. local cfg="$1"
  10. config_mount_by_section "$cfg"
  11. }
  12. do_swapon() {
  13. local cfg="$1"
  14. config_swapon_by_section "$cfg"
  15. }
  16. do_unmount() {
  17. local cfg="$1"
  18. config_get target "$cfg" target
  19. config_get_bool enabled "$cfg" "enabled" '1'
  20. [ -n "$target" -a "$enabled" -gt 0 ] || return 0
  21. umount $target
  22. }
  23. do_swapoff() {
  24. local cfg="$1"
  25. config_get device "$cfg" device
  26. config_get_bool enabled "$cfg" "enabled" '1'
  27. [ -n "$device" -a "$enabled" -gt 0 ] && type swapoff >/dev/null || return 0
  28. swapoff $device
  29. }
  30. start() {
  31. . /lib/functions/mount.sh
  32. config_load fstab
  33. mkdir -p /var/lock
  34. lock -w /var/lock/fstab.lck && {
  35. lock /var/lock/fstab.lck
  36. [ -e /tmp/fstab ] || {
  37. echo '# WARNING: this is an auto generated file, please use uci to set defined filesystems' > /tmp/fstab
  38. }
  39. lock -u /var/lock/fstab.lck
  40. }
  41. config_foreach do_swapon swap
  42. config_foreach do_mount mount
  43. config_foreach do_swapon swap # do swap a second time so that swap on filesystems is enabled
  44. }
  45. stop() {
  46. . /lib/functions/mount.sh
  47. config_load fstab
  48. config_foreach do_unmount mount
  49. config_foreach do_swapoff swap
  50. swapoff -a
  51. }