summaryrefslogtreecommitdiff
path: root/package/block-mount
diff options
context:
space:
mode:
Diffstat (limited to 'package/block-mount')
-rw-r--r--package/block-mount/Makefile86
-rw-r--r--package/block-mount/files/10-swap78
-rw-r--r--package/block-mount/files/20-fsck83
-rw-r--r--package/block-mount/files/40-mount84
-rw-r--r--package/block-mount/files/block.sh262
-rw-r--r--package/block-mount/files/fsck.sh36
-rw-r--r--package/block-mount/files/fstab.config20
-rw-r--r--package/block-mount/files/fstab.init57
-rw-r--r--package/block-mount/files/mount.sh89
9 files changed, 795 insertions, 0 deletions
diff --git a/package/block-mount/Makefile b/package/block-mount/Makefile
new file mode 100644
index 0000000000..a31096de3b
--- /dev/null
+++ b/package/block-mount/Makefile
@@ -0,0 +1,86 @@
+#
+# Copyright (C) 2006-2009 OpenWrt.org
+# Copyright 2010 Vertical Communications
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=block-mount
+PKG_VERSION:=0.1.0
+PKG_RELEASE:=1
+
+PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/block-mount/Default
+ SECTION:=base
+ CATEGORY:=Base system
+endef
+
+define Package/block-mount
+ $(call Package/block-mount/Default)
+ TITLE:=Block device mounting and checking
+endef
+
+define Package/block-mount/config
+ select BUSYBOX_CONFIG_MKSWAP
+ select BUSYBOX_CONFIG_FEATURE_MKSWAP_UUID
+ select BUSYBOX_CONFIG_SWAPONOFF
+ select BUSYBOX_CONFIG_BLKID
+ select BUSYBOX_CONFIG_FEATURE_VOLUMEID_EXT
+ select BUSYBOX_CONFIG_FEATURE_VOLUMEID_REISERFS
+ select BUSYBOX_CONFIG_FEATURE_VOLUMEID_FAT
+ select BUSYBOX_CONFIG_FEATURE_VOLUMEID_HFS
+ select BUSYBOX_CONFIG_FEATURE_VOLUMEID_JFS
+ select BUSYBOX_CONFIG_FEATURE_VOLUMEID_XFS
+ select BUSYBOX_CONFIG_FEATURE_VOLUMEID_NTFS
+ select BUSYBOX_CONFIG_FEATURE_VOLUMEID_SYSV
+ select BUSYBOX_CONFIG_FEATURE_VOLUMEID_OCFS2
+ select BUSYBOX_CONFIG_FEATURE_VOLUMEID_ISO9660
+ select BUSYBOX_CONFIG_FEATURE_VOLUMEID_UDF
+ select BUSYBOX_CONFIG_FEATURE_VOLUMEID_LINUXSWAP
+ select BUSYBOX_CONFIG_FEATURE_VOLUMEID_CRAMFS
+ select BUSYBOX_CONFIG_FEATURE_VOLUMEID_ROMFS
+endef
+
+define Package/block-mount/description
+ Scripts used to mount and check block devices (filesystems and swap)
+endef
+
+define Package/block-hotplug
+ $(call Package/block-mount/Default)
+ TITLE:=Automount and autocheck block devices
+ DEPENDS:=block-mount hotplug2
+endef
+
+define Package/block-hotplug/description
+ Scripts used to automatically check and mount filesystem and/or swap
+endef
+
+define Build/Compile
+endef
+
+define Package/block-mount/install
+ $(INSTALL_DIR) $(1)/etc/init.d
+ $(INSTALL_BIN) ./files/fstab.init $(1)/etc/init.d/fstab
+ $(INSTALL_DIR) $(1)/etc/config
+ $(INSTALL_DATA) ./files/fstab.config $(1)/etc/config/fstab
+ $(INSTALL_DIR) $(1)/lib/functions
+ $(INSTALL_DATA) ./files/mount.sh $(1)/lib/functions/
+ $(INSTALL_DATA) ./files/fsck.sh $(1)/lib/functions/
+ $(INSTALL_DATA) ./files/block.sh $(1)/lib/functions/
+endef
+
+define Package/block-hotplug/install
+ $(INSTALL_DIR) $(1)/etc/hotplug.d/block
+ $(INSTALL_DATA) ./files/10-swap $(1)/etc/hotplug.d/block/
+ $(INSTALL_DATA) ./files/20-fsck $(1)/etc/hotplug.d/block/
+ $(INSTALL_DATA) ./files/40-mount $(1)/etc/hotplug.d/block/
+endef
+
+$(eval $(call BuildPackage,block-mount))
+$(eval $(call BuildPackage,block-hotplug))
+
diff --git a/package/block-mount/files/10-swap b/package/block-mount/files/10-swap
new file mode 100644
index 0000000000..2837d2763e
--- /dev/null
+++ b/package/block-mount/files/10-swap
@@ -0,0 +1,78 @@
+#!/bin/sh
+# Copyright (C) 2009-2010 OpenWrt.org
+# Copyright (C) 2010 Vertical Communications
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+. /lib/functions/block.sh
+
+blkdev=`dirname $DEVPATH`
+
+if [ `basename $blkdev` != "block" ]; then
+
+ device=`basename $DEVPATH`
+
+
+ case "$ACTION" in
+ add)
+ local autoswap_from_fstab
+ local automount_from_fstab
+ local from_fstab
+ local anon_mount
+ local anon_swap
+ local anon_fsck
+ local mds_mount_device
+ local sds_swap_device
+ local sds_swap_enabled
+ local use_device
+ local do_swap=0
+
+ mount_dev_section_cb() {
+ mds_mount_device="$3"
+ }
+
+ swap_dev_section_cb() {
+ sds_swap_device="$2"
+ sds_swap_enabled="$3"
+ return 0
+ }
+
+ config_get_automount
+ automount_from_fstab="$from_fstab"
+
+ [ "$automount_from_fstab" -eq 1 ] && {
+ config_get_mount_section_by_device "/dev/$device"
+ }
+
+ # skip trying swap if this device is defined as a mount point
+ [ -z "$mds_mount_device" ] && {
+ config_get_autoswap
+ autoswap_from_fstab="$from_fstab"
+
+ [ "$autoswap_from_fstab" -eq 1 ] && {
+ config_get_swap_section_by_device "/dev/$device"
+ use_device="$sds_swap_device"
+ do_swap="$sds_swap_enabled"
+ }
+
+ [ -z "$use_device" ] && [ "$anon_swap" -eq 1 ] && {
+ use_device="/dev/$device" && do_swap=1
+ }
+ }
+
+ [ -n "$use_device" ] && [ "$do_swap" -eq 1 ] && {
+ grep -q "$use_device" /proc/swaps || grep -q "$use_device" /proc/mounts || {
+ swapon "$use_device"
+ }
+ }
+ reset_dev_section_cb
+ ;;
+ remove)
+ grep -q "/dev/$device" /proc/swaps && {
+ swapoff "/dev/$device"
+ }
+ ;;
+ esac
+fi
+
diff --git a/package/block-mount/files/20-fsck b/package/block-mount/files/20-fsck
new file mode 100644
index 0000000000..c59e5abd72
--- /dev/null
+++ b/package/block-mount/files/20-fsck
@@ -0,0 +1,83 @@
+#!/bin/sh
+# Copyright (C) 2009-2010 OpenWrt.org
+# Copyright (C) 2010 Vertical Communications
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+. /lib/functions/block.sh
+. /lib/functions/fsck.sh
+
+blkdev=`dirname $DEVPATH`
+
+if [ `basename $blkdev` != "block" ]; then
+
+ device=`basename $DEVPATH`
+
+ case "$ACTION" in
+ add)
+ local from_fstab
+ local anon_mount
+ local anon_swap
+ local anon_fsck
+ local mds_mount_target
+ local mds_mount_device
+ local mds_mount_fstype
+ local mds_mount_enabled_fsck
+ local sds_swap_device
+ local use_device
+ local do_fsck=0
+ local fsck_type
+
+ local autoswap_from_fstab
+ local automount_from_fstab
+ local hotplug_blkid_fstype_match
+
+ mount_dev_section_cb() {
+ mds_mount_device="$3"
+ mds_mount_fstype="$4"
+ mds_mount_enabled_fsck="$7"
+ }
+
+ swap_dev_section_cb() {
+ sds_swap_device="$2"
+ return 0
+ }
+
+ config_get_automount
+ automount_from_fstab="$from_fstab"
+
+ [ "$automount_from_fstab" -eq 1 ] && {
+ config_get_mount_section_by_device "/dev/$device"
+ use_device="$mds_mount_device"
+ [ "$mds_mount_enabled_fsck" -eq 1 ] && {
+ do_fsck=1
+ fsck_type="$mds_mount_fstype"
+ }
+ }
+
+ [ -z "$use_device" ] && {
+ config_get_autoswap
+ autoswap_from_fstab="$from_fstab"
+
+ [ "$autoswap_from_fstab" -eq 1 ] && {
+ config_get_swap_section_by_device "/dev/$device"
+ use_device="$sds_swap_device" && do_fsck=0
+ }
+ }
+
+ grep -q "/dev/$device" /proc/swaps || grep -q "/dev/$device" /proc/mounts || {
+ [ "$anon_fsck" -eq 1 ] && [ -z "$use_device" ] && {
+ use_device="/dev/$device" && do_fsck=1 && mds_mount_fstype="" && hotplug_blkid_fstype_match=0
+ }
+ }
+
+ [ "$do_fsck" -eq 1 ] && {
+ libmount_fsck "$use_device" "$fsck_type" "$do_fsck"
+ }
+
+ reset_dev_section_cb
+ ;;
+ esac
+fi
+
diff --git a/package/block-mount/files/40-mount b/package/block-mount/files/40-mount
new file mode 100644
index 0000000000..0d4f669404
--- /dev/null
+++ b/package/block-mount/files/40-mount
@@ -0,0 +1,84 @@
+#!/bin/sh
+# Copyright (C) 2009-2010 OpenWrt.org
+# Copyright (C) 2010 Vertical Communications
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+. /lib/functions/block.sh
+
+blkdev=`dirname $DEVPATH`
+if [ `basename $blkdev` != "block" ]; then
+
+ device=`basename $DEVPATH`
+
+ case "$ACTION" in
+ add)
+
+ local from_fstab
+ local anon_mount
+ local anon_swap
+ local anon_fsck
+ local mds_mount_target
+ local mds_mount_device
+ local mds_mount_fstype
+ local sds_swap_device
+ local use_device
+ local do_fsck=0
+ local fsck_type
+
+ local autoswap_from_fstab
+ local automount_from_fstab
+
+ mount_dev_section_cb() {
+ mds_mount_target="$2"
+ mds_mount_device="$3"
+ mds_mount_fstype="$4"
+ mds_mount_enabled="$6"
+ }
+
+ swap_dev_section_cb() {
+ sds_swap_device="$2"
+ return 0
+ }
+
+ config_get_automount
+ automount_from_fstab="$from_fstab"
+ [ "$automount_from_fstab" -eq 1 ] && {
+ config_get_mount_section_by_device "/dev/$device"
+ use_device="$mds_mount_device"
+ [ "$mds_mount_enabled" -eq 1 ] && {
+ if [ -n "$mds_mount_target" ]; then
+ grep -q "/dev/$device" /proc/swaps || grep -q "/dev/$device" /proc/mounts || {
+ ( mkdir -p "$mds_mount_target" && mount "$mds_mount_target" ) 2>&1 | tee /proc/self/fd/2 | logger -t 'fstab'
+ }
+ else
+ logger -t 'fstab' "Mount enabled for $mds_mount_device but it doesn't have a defined mountpoint (target)"
+ fi
+ }
+ }
+
+ [ -z "$use_device" ] && {
+ config_get_autoswap
+ autoswap_from_fstab="$from_fstab"
+
+ [ "$autoswap_from_fstab" -eq 1 ] && {
+ config_get_swap_section_by_device "/dev/$device"
+ use_device="$sds_swap_device"
+ }
+ }
+
+ grep -q "/dev/$device" /proc/swaps || grep -q "/dev/$device" /proc/mounts || {
+ [ "$anon_mount" -eq 1 ] && [ -z "$use_device" ] && {
+ ( mkdir -p /mnt/$device && mount /dev/$device /mnt/$device ) 2>&1 | tee /proc/self/fd/2 | logger -t 'fstab'
+ }
+ }
+ reset_dev_section_cb
+ ;;
+ remove)
+ umount /dev/$device
+ ;;
+ esac
+
+fi
+
diff --git a/package/block-mount/files/block.sh b/package/block-mount/files/block.sh
new file mode 100644
index 0000000000..b8a473a00f
--- /dev/null
+++ b/package/block-mount/files/block.sh
@@ -0,0 +1,262 @@
+#!/bin/sh
+# Copyright 2010 Vertical Communications
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+. /etc/functions.sh
+
+reset_block_cb() {
+ mount_cb() {
+ dmc_mount_cfg="$1"
+ shift # skip optional param
+ dmc_target="$2"
+ dmc_mount_device="$3"
+ dmc_fstype="$4"
+ dmc_options="$5"
+ dmc_enabled="$6"
+ dmc_enabled_fsck="$7"
+ dmc_uuid="$8"
+ dmc_label="$9"
+ shift
+ dmc_is_rootfs="$9"
+ return 0
+ }
+ swap_cb() {
+ dsc_swap_cfg="$1"
+ shift # skip optional param
+ dsc_swap_device="$2"
+ dsc_enabled="$3"
+ dsc_uuid="$4"
+ dsc_label="$5"
+ return 0
+ }
+}
+reset_block_cb
+
+reset_dev_section_cb() {
+ mount_dev_section_cb() {
+ dmds_mount_cfg="$1"
+ dmds_mount_target="$2"
+ dmds_mount_device="$3"
+ dmds_mount_fstype="$4"
+ dmds_mount_options="$5"
+ dmds_mount_enabled="$6"
+ dmds_mount_enabled_fsck="$7"
+ dmds_mount_uuid="$8"
+ dmds_mount_label="$9"
+ shift
+ dmds_is_rootfs="$9"
+ return 0
+ }
+ swap_dev_section_cb() {
+ dsds_swap_cfg="$1"
+ dsds_swap_device="$2"
+ dsds_swap_enabled="$3"
+ dsds_swap_uuid="$4"
+ dsds_swap_label="$5"
+ return 0
+ }
+}
+reset_dev_section_cb
+
+config_get_mount() {
+ local gm_cfg="$1"
+ local gm_param="$2"
+ local gm_target
+ local gm_device
+ local gm_fstype
+ local gm_options
+ local gm_enabled
+ local gm_enabled_fsck
+ local gm_uuid
+ local gm_label
+ local gm_is_rootfs
+ config_get gm_target "$1" target
+ config_get gm_device "$1" device
+ config_get gm_fstype "$1" fstype 'auto'
+ config_get gm_options "$1" options 'rw'
+ config_get_bool gm_enabled "$1" enabled 1
+ config_get_bool gm_enabled_fsck "$1" enabled_fsck 0
+ config_get gm_uuid "$1" uuid
+ config_get gm_label "$1" label
+ config_get_bool gm_is_rootfs "$1" is_rootfs 0
+ mount_cb "$gm_cfg" "$gm_param" "$gm_target" "$gm_device" "$gm_fstype" "$gm_options" "$gm_enabled" "$gm_enabled_fsck" "$gm_uuid" "$gm_label" "$gm_is_rootfs"
+}
+
+config_get_swap() {
+ local gs_cfg="$1"
+ local gs_param="$2"
+ local gs_device
+ local gs_enabled
+ local gs_uuid
+ local gs_label
+ config_get gs_device "$1" device
+ config_get_bool gs_enabled "$1" enabled 1
+ config_get gs_uuid "$1" uuid
+ config_get gs_label "$1" label
+
+ swap_cb "$gs_cfg" "$gs_param" "$gs_device" "$gs_enabled" "$gs_uuid" "$gs_label"
+}
+
+config_get_automount() {
+ config_load fstab
+ config_get_bool from_fstab "automount" from_fstab 1
+ config_get_bool anon_mount "automount" anon_mount 1
+ config_get_bool anon_fsck "automount" anon_fsck 0
+}
+
+config_get_autoswap() {
+ config_load fstab
+ config_get_bool from_fstab "autoswap" from_fstab 1
+ config_get_bool anon_swap "autoswap" anon_swap 0
+}
+
+config_create_swap_fstab_entry() {
+ local device="$1"
+ local enabled="$2"
+
+ [ -n "$device" ] || return 0
+
+ local fstabnew="$(mktemp -t '.fstab.XXXXXXXX')"
+
+ mkdir -p /var/lock
+ lock /var/lock/fstab.lck
+ cat /tmp/fstab | grep -E -v "^$device[[:blank:]]" >>"$fstabnew"
+ [ "$enabled" -eq 1 ] && echo "$device none swap sw 0 0" >> "$fstabnew"
+ cat "$fstabnew" >/tmp/fstab
+ lock -u /var/lock/fstab.lck
+ rm -f $fstabnew
+}
+
+config_create_mount_fstab_entry() {
+ local device="$1"
+ local target="$2"
+ local fstype="$3"
+ local options="$4"
+ local enabled="$5"
+ options="${options:-rw}"
+ [ "$enabled" -eq 0 ] && options="noauto,$options"
+ [ -n "$target" ] || return 0
+ [ -n "$device" ] || return 0
+
+ local fstabnew="$(mktemp -t '.fstab.XXXXXXXX')"
+
+ mkdir -p /var/lock
+ lock /var/lock/fstab.lck
+ cat /tmp/fstab | grep -E -v "^$device[[:blank:]]" | grep -v "$target" >>"$fstabnew"
+ echo "$device $target $fstype $options 0 0" >>"$fstabnew"
+ cat "$fstabnew" >/tmp/fstab
+ lock -u /var/lock/fstab.lck
+ rm -f $fstabnew
+}
+
+libmount_find_token() {
+ local token="$1"
+ local value="$2"
+ local device
+ device="$(blkid | grep "$token=\"$value\"" | cut -f1 -d:)"
+ echo "$device"
+}
+
+libmount_find_device_by_id() {
+ local uuid="$1"
+ local label="$2"
+ local device="$3"
+ local cfg_device="$4"
+ local found_device
+
+ if [ -n "$uuid" ]; then
+ found_device="$(libmount_find_token "UUID" "$uuid")"
+ elif [ -n "$label" ]; then
+ found_device="$(libmount_find_token "LABEL" "$label")"
+ elif [ "$device" = "$cfg_device" ]; then
+ found_device="$device"
+ elif [ -z "$device" ] && [ -e "$cfg_device" ]; then
+ found_device="$cfg_device"
+ fi
+ [ -n "$device" ] && [ "$device" != "$found_device" ] && {
+ found_device=""
+ }
+ echo "$found_device"
+}
+
+config_get_mount_section_by_device() {
+ local msbd_device="$1"
+ local msbd_mount_cfg=
+ local msbd_target=
+ local msbd_mount_device=
+ local msbd_fstype=
+ local msbd_options=
+ local msbd_enabled=
+ local msbd_enabled_fsck=
+ local msbd_uuid=
+ local msbd_label=
+ local msbd_is_rootfs
+ local msbd_blkid_fstype_match=
+ mount_cb() {
+ local mc_cfg="$1"
+ local mc_device="$2"
+ shift
+ local mc_target="$2"
+ local mc_cfgdevice="$3"
+ local mc_fstype="$4"
+ local mc_uuid="$8"
+ local mc_label="$9"
+ shift
+ local mc_is_rootfs="$9"
+ local mc_found_device=""
+
+ mc_found_device="$(libmount_find_device_by_id "$mc_uuid" "$mc_label" "$mc_device" "$mc_cfgdevice")"
+ if [ -n "$mc_found_device" ]; then
+ msbd_mount_cfg="$mc_cfg"
+ msbd_target="$mc_target"
+ msbd_mount_device="$mc_found_device"
+ msbd_fstype="$mc_fstype"
+ msbd_options="$4"
+ msbd_enabled="$5"
+ msbd_enabled_fsck="$6"
+ msbd_uuid="$7"
+ msbd_label="$8"
+ msbd_is_rootfs="$9"
+ fi
+ return 0
+ }
+ config_foreach config_get_mount mount "$msbd_device"
+ [ -n "$msbd_mount_device" ] && config_create_mount_fstab_entry "$msbd_mount_device" "$msbd_target" "$msbd_fstype" "$msbd_options" "$msbd_enabled"
+ mount_dev_section_cb "$msbd_mount_cfg" "$msbd_target" "$msbd_mount_device" "$msbd_fstype" "$msbd_options" "$msbd_enabled" "$msbd_enabled_fsck" "$msbd_uuid" "$msbd_label" "$msbd_is_rootfs"
+ reset_block_cb
+}
+
+config_get_swap_section_by_device() {
+ local ssbd_device="$1"
+ local ssbd_swap_cfg=
+ local ssbd_swap_device=
+ local ssbd_enabled=
+ local ssbd_uuid=
+ local ssbd_label=
+ swap_cb() {
+ local sc_cfg="$1"
+ local sc_device="$2"
+ local sc_uuid="$5"
+ local sc_label="$6"
+ local sc_cfgdevice="$3"
+ local sc_found_device
+
+ sc_found_device="$(libmount_find_device_by_id "$sc_uuid" "$sc_label" "$sc_device" "$sc_cfgdevice")"
+ if [ -n "$sc_found_device" ]; then
+ ssbd_swap_cfg="$sc_cfg"
+ ssbd_swap_device="$sc_found_device"
+ ssbd_enabled="$4"
+ ssbd_uuid="$5"
+ ssbd_label="$6"
+ fi
+ return 0
+ }
+ config_foreach config_get_swap swap "$ssbd_device"
+ [ -n "$ssbd_swap_device" ] && config_create_swap_fstab_entry "$ssbd_swap_device" "$ssbd_enabled"
+ swap_dev_section_cb "$ssbd_swap_cfg" "$ssbd_swap_device" "$ssbd_enabled" "$ssbd_uuid" "$ssbd_label"
+ reset_block_cb
+}
+
+
diff --git a/package/block-mount/files/fsck.sh b/package/block-mount/files/fsck.sh
new file mode 100644
index 0000000000..d80e71693e
--- /dev/null
+++ b/package/block-mount/files/fsck.sh
@@ -0,0 +1,36 @@
+#!/bin/sh
+# Copyright 2010 Vertical Communications
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+libmount_fsck() {
+ local device="$1"
+ local fsck_fstype="$2"
+ local fsck_enabled="$3"
+ local known_type
+ local found_fsck=0
+
+
+ [ -n "$fsck_type" ] && [ "$fsck_type" != "swap" ] && {
+ grep -q "$device" /proc/swaps || grep -q "$device" /proc/mounts || {
+ [ -e "$device" ] && [ "$fsck_enabled" -eq 1 ] && {
+ for known_type in $libmount_known_fsck; do
+ if [ "$known_type" = "$fsck_fstype" ]; then
+ fsck_${known_type} "$device"
+ found_fsck=1
+ break
+ fi
+ done
+ if [ "$found_fsck" -ne 1 ]; then
+ logger -t 'fstab' "Unable to check/repair $device; no known fsck for filesystem type $fstype"
+ fi
+ }
+ }
+ }
+}
+
+libmount_known_fsck=""
+
+include /lib/functions/fsck
+
diff --git a/package/block-mount/files/fstab.config b/package/block-mount/files/fstab.config
new file mode 100644
index 0000000000..f672ef4d56
--- /dev/null
+++ b/package/block-mount/files/fstab.config
@@ -0,0 +1,20 @@
+config global automount
+ option from_fstab 1
+ option anon_mount 1
+
+config global autoswap
+ option from_fstab 1
+ option anon_swap 0
+
+config mount
+ option target /home
+ option device /dev/sda1
+ option fstype ext3
+ option options rw,sync
+ option enabled 0
+ option enabled_fsck 0
+
+config swap
+ option device /dev/sda2
+ option enabled 0
+
diff --git a/package/block-mount/files/fstab.init b/package/block-mount/files/fstab.init
new file mode 100644
index 0000000000..bd2bf24cb0
--- /dev/null
+++ b/package/block-mount/files/fstab.init
@@ -0,0 +1,57 @@
+#!/bin/sh /etc/rc.common
+# Copyright (C) 2007 OpenWrt.org
+# Copyright (C) 2010 Vertical Communications
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+
+START=20
+
+. /lib/functions/mount.sh
+
+do_mount() {
+ local cfg="$1"
+ config_mount_by_section "$cfg"
+}
+
+do_swapon() {
+ local cfg="$1"
+ config_swapon_by_section "$cfg"
+}
+
+do_unmount() {
+ local cfg="$1"
+
+ config_get target "$cfg" target
+ config_get_bool enabled "$cfg" "enabled" '1'
+ [ -n "$target" -a "$enabled" -gt 0 ] || return 0
+ umount $target
+}
+
+do_swapoff() {
+ local cfg="$1"
+
+ config_get device "$cfg" device
+ config_get_bool enabled "$cfg" "enabled" '1'
+ [ -n "$device" -a "$enabled" -gt 0 ] && type swapoff >/dev/null || return 0
+ swapoff $device
+}
+
+start() {
+ config_load fstab
+ mkdir -p /var/lock
+ lock /var/lock/fstab.lck
+ echo '# WARNING: this is an auto generated file, please use uci to set defined filesystems' > /etc/fstab
+ lock -u /var/lock/fstab.lck
+ config_foreach do_mount mount
+ config_foreach do_swapon swap
+}
+
+stop() {
+ config_load fstab
+ config_foreach do_unmount mount
+ config_foreach do_swapoff swap
+ swapoff -a
+}
+
diff --git a/package/block-mount/files/mount.sh b/package/block-mount/files/mount.sh
new file mode 100644
index 0000000000..1616ca7a13
--- /dev/null
+++ b/package/block-mount/files/mount.sh
@@ -0,0 +1,89 @@
+#!/bin/sh
+# Copyright 2010 Vertical Communications
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+
+. /lib/functions/block.sh
+. /lib/functions/fsck.sh
+
+config_mount_by_section() {
+ local cfg="$1"
+ local find_rootfs="$2"
+
+ mount_cb() {
+ local cfg="$1"
+ local device="$2"
+ shift
+ local target="$2"
+ local cfgdevice="$3"
+ local fstype="$4"
+ local options="$5"
+ local enabled="$6"
+ local enabled_fsck="$7"
+ local uuid="$8"
+ local label="$9"
+ shift
+ local is_rootfs="$9"
+ shift
+ local found_device=""
+ local fsck_type=""
+
+ found_device="$(libmount_find_device_by_id "$uuid" "$label" "$device" "$cfgdevice")"
+ if [ -n "$found_device" ]; then
+ if [ -z "$find_rootfs" ] || [ "$find_rootfs" -eq 0 ] || [ "$is_rootfs" -eq 1 ]; then
+ [ "$enabled_fsck" -eq 1 ] && {
+ grep -q "$found_device" /proc/swaps || grep -q "$found_device" /proc/mounts || {
+ libmount_fsck "$found_device" "$fsck_type" "$enabled_fsck"
+ }
+ }
+
+ [ "$is_rootfs" -eq 1 ] && [ "$find_rootfs" -eq 1 ] && {
+ target=/overlay
+ }
+ config_create_mount_fstab_entry "$found_device" "$target" "$fstype" "$options" "$enabled"
+ grep -q "$found_device" /proc/swaps || grep -q "$found_device" /proc/mounts || {
+ [ "$enabled" -eq 1 ] && mkdir -p "$target" && mount "$target" 2>&1 | tee /proc/self/fd/2 | logger -t 'fstab'
+ }
+
+ fi
+ fi
+ [ "$is_rootfs" -eq 1 ] && [ "$find_rootfs" -eq 1 ] && {
+ rootfs_found=1
+ }
+ return 0
+ }
+ config_get_mount "$cfg"
+ reset_block_cb
+}
+
+config_swapon_by_section() {
+ local cfg="$1"
+
+ swap_cb() {
+ local cfg="$1"
+ local device="$2"
+ local cfgdevice="$3"
+ local enabled="$4"
+ local uuid="$5"
+ local label="$6"
+ local uuid
+ local label
+
+ local found_device=""
+ local fsck_type=""
+
+ found_device="$(libmount_find_device_by_id "$uuid" "$label" "$device" "$cfgdevice")"
+
+ if [ -n "$found_device" ]; then
+ config_create_swap_fstab_entry "$found_device" "$enabled"
+ grep -q "$found_device" /proc/swaps || grep -q "$found_device" /proc/mounts || {
+ [ "$enabled" -eq 1 ] && swapon "$found_device" | tee /proc/self/fd/2 | logger -t 'fstab'
+ }
+ fi
+ return 0
+ }
+ config_get_swap "$cfg"
+ reset_block_cb
+}