mirror of
git://projects.qi-hardware.com/openwrt-xburst.git
synced 2024-11-27 17:55:55 +02:00
add the block-mount package by Daniel Dickinson (cshore), replacing existing automount functionality
git-svn-id: svn://svn.openwrt.org/openwrt/trunk@19877 3c298f89-4303-0410-b956-a3cf2f4a3e73
This commit is contained in:
parent
a35f8c9470
commit
faf7173b4d
@ -1,20 +0,0 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) 2009-2010 OpenWrt.org
|
||||
|
||||
blkdev=`dirname $DEVPATH`
|
||||
if [ `basename $blkdev` != "block" ]; then
|
||||
|
||||
device=`basename $DEVPATH`
|
||||
case "$ACTION" in
|
||||
add)
|
||||
swapon /dev/$device >/dev/null 2>/dev/null || (
|
||||
mkdir -p /mnt/$device
|
||||
mount /dev/$device /mnt/$device
|
||||
)
|
||||
;;
|
||||
remove)
|
||||
umount /dev/$device
|
||||
;;
|
||||
esac
|
||||
|
||||
fi
|
86
package/block-mount/Makefile
Normal file
86
package/block-mount/Makefile
Normal file
@ -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))
|
||||
|
78
package/block-mount/files/10-swap
Normal file
78
package/block-mount/files/10-swap
Normal file
@ -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
|
||||
|
83
package/block-mount/files/20-fsck
Normal file
83
package/block-mount/files/20-fsck
Normal file
@ -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
|
||||
|
84
package/block-mount/files/40-mount
Normal file
84
package/block-mount/files/40-mount
Normal file
@ -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
|
||||
|
262
package/block-mount/files/block.sh
Normal file
262
package/block-mount/files/block.sh
Normal file
@ -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
|
||||
}
|
||||
|
||||
|
36
package/block-mount/files/fsck.sh
Normal file
36
package/block-mount/files/fsck.sh
Normal file
@ -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
|
||||
|
@ -1,10 +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
|
||||
|
34
package/base-files/files/etc/init.d/fstab → package/block-mount/files/fstab.init
Executable file → Normal file
34
package/base-files/files/etc/init.d/fstab → package/block-mount/files/fstab.init
Executable file → Normal file
@ -1,30 +1,23 @@
|
||||
#!/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_get device "$cfg" device
|
||||
config_get target "$cfg" target
|
||||
[ -n "$device" -a -n "$target" ] || return 0
|
||||
|
||||
mkdir -p $target
|
||||
config_get fstype "$cfg" fstype 'auto'
|
||||
config_get options "$cfg" options '-rw'
|
||||
config_get_bool enabled "$cfg" "enabled" '1'
|
||||
[ "$enabled" -eq 0 ] && options="noauto,$options"
|
||||
echo "$device $target $fstype $options 0 0" >> /tmp/fstab
|
||||
config_mount_by_section "$cfg"
|
||||
}
|
||||
|
||||
do_swapon() {
|
||||
local cfg="$1"
|
||||
|
||||
config_get device "$cfg" device
|
||||
config_get_bool enabled "$cfg" "enabled" '1'
|
||||
[ -n "$device" -a "$enabled" -gt 0 ] || return 0
|
||||
echo "$device none swap sw 0 0" >> /tmp/fstab
|
||||
config_swapon_by_section "$cfg"
|
||||
}
|
||||
|
||||
do_unmount() {
|
||||
@ -47,17 +40,18 @@ do_swapoff() {
|
||||
|
||||
start() {
|
||||
config_load fstab
|
||||
echo '# WARNING: this is an auto generated file, please use uci to set static filesystems' > /tmp/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
|
||||
mount -a
|
||||
[ -x /sbin/swapon ] && swapon -a
|
||||
}
|
||||
|
||||
stop() {
|
||||
config_load fstab
|
||||
config_foreach do_unmount mount
|
||||
config_foreach do_swapoff swap
|
||||
[ -x /sbin/swapoff ] && swapoff -a
|
||||
swapoff -a
|
||||
}
|
||||
|
89
package/block-mount/files/mount.sh
Normal file
89
package/block-mount/files/mount.sh
Normal file
@ -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
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
#
|
||||
# Copyright (C) 2006-2008 OpenWrt.org
|
||||
#
|
||||
# Copyright 2010 Vertical Communications
|
||||
# This is free software, licensed under the GNU General Public License v2.
|
||||
# See /LICENSE for more information.
|
||||
#
|
||||
@ -156,8 +156,8 @@ define Package/e2fsprogs/install
|
||||
$(INSTALL_DIR) $(1)/usr/lib
|
||||
$(CP) $(foreach lib,com_err e2p,$(PKG_INSTALL_DIR)/usr/lib/lib$(lib).so.*) $(1)/usr/lib/
|
||||
$(INSTALL_DIR) $(1)/etc/init.d
|
||||
$(INSTALL_BIN) ./files/e2fsck.init $(1)/etc/init.d/e2fsck
|
||||
|
||||
$(INSTALL_DIR) $(1)/lib/functions/fsck
|
||||
$(INSTALL_DATA) ./files/e2fsck.sh $(1)/lib/functions/fsck/
|
||||
endef
|
||||
|
||||
define Package/libuuid/install
|
||||
|
@ -1,35 +0,0 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
# Copyright (C) 2008 OpenWrt.org
|
||||
# Vasilis Tsiligiannis <acinonyxs@yahoo.gr>
|
||||
|
||||
START=15
|
||||
|
||||
e2fsck() {
|
||||
local args
|
||||
local cfg="$1"
|
||||
|
||||
config_get device "$cfg" device
|
||||
[ -b "$device" ] || return 0
|
||||
|
||||
config_get fstype "$cfg" fstype
|
||||
case "$fstype" in
|
||||
ext2|ext3|ext4)
|
||||
/usr/sbin/e2fsck -p "$device"
|
||||
local status="$?"
|
||||
case "$status" in
|
||||
0|1) continue;;
|
||||
2) reboot;;
|
||||
4) echo "e2fsck ($device): Warning! Uncorrected errors.";;
|
||||
*) echo "e2fsck ($device): Error $status. Check not complete.";;
|
||||
esac
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
start() {
|
||||
config_load fstab
|
||||
config_foreach e2fsck mount
|
||||
}
|
||||
|
35
package/e2fsprogs/files/e2fsck.sh
Normal file
35
package/e2fsprogs/files/e2fsck.sh
Normal file
@ -0,0 +1,35 @@
|
||||
#!/bin/sh
|
||||
# Copyright 2010 Vertical Communications
|
||||
# This is free software, licensed under the GNU General Public License v2.
|
||||
# See /LICENSE for more information.
|
||||
#
|
||||
|
||||
fsck_e2fsck() {
|
||||
e2fsck -p "$device" 2>&1 | logger -t "fstab: e2fsck ($device)"
|
||||
local status="$?"
|
||||
case "$status" in
|
||||
0|1) ;; #success
|
||||
2) reboot;;
|
||||
4) echo "e2fsck ($device): Warning! Uncorrected errors."| logger -t fstab
|
||||
return 1
|
||||
;;
|
||||
*) echo "e2fsck ($device): Error $status. Check not complete."| logger -t fstab;;
|
||||
esac
|
||||
return 0
|
||||
}
|
||||
|
||||
fsck_ext2() {
|
||||
fsck_e2fsck "$@"
|
||||
}
|
||||
|
||||
fsck_ext3() {
|
||||
fsck_e2fsck "$@"
|
||||
}
|
||||
|
||||
fsck_ext4() {
|
||||
fsck_e2fsck "$@"
|
||||
}
|
||||
|
||||
append libmount_known_fsck "ext2"
|
||||
append libmount_known_fsck "ext3"
|
||||
append libmount_known_fsck "ext4"
|
Loading…
Reference in New Issue
Block a user