I modified this slightly to add something I forgot I needed for extroot. Namely the returning of the rootfs mount target, when we are searching for a rootfs in mount_by_section.
-- And that's my crabbing done for the day. Got it out of the way early, now I have the rest of the afternoon to sniff fragrant tea-roses or strangle cute bunnies or something. -- Michael Devore GnuPG Key Fingerprint 86 F5 81 A5 D4 2E 1F 1C http://gnupg.org The C Shore (Daniel Dickinson's Website) http://cshore.is-a-geek.com
Index: package/block-mount/files/fsck.sh =================================================================== --- package/block-mount/files/fsck.sh (revision 0) +++ package/block-mount/files/fsck.sh (revision 0) @@ -0,0 +1,74 @@ +#!/bin/sh +# Copyright 2010 Vertical Communications +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# + +# There is some commented out code that can be added back once busybox blkid has +# fstype detection added to it. util-linux blkid already does support this, if +# a user wants to use it and uncomment this code. + +libmount_fsck() { + local device="$1" + local fstype="$2" + local fsck_enabled="$3" +# local blkid_fstype_match="$4" + local known_type + local found_fsck=0 + + +# fsck_type="`libmount_fsck_fs_type "$device" "$fstype" "$blkid_fstype_match"`" + fsck_type="$fstype" + + [ -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" = "$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_fsck_fs_type() { +# local device="$1" +# local fstype="$2" +# local blkid_fstype_match="$3" +# local TYPE +# local echo_type="" +# +# eval "$(blkid -s TYPE $device | cut -f2 -d:)" +# +# if [ "$fstype" = "" ] && [ "$blkid_fstype_match" -eq 0 ]; then +# echo_type="$TYPE" +# elif [ "$blkid_fstype_match" -eq 0 ]; then +# echo_type="$fstype" +# elif [ "$fstype" = "$TYPE" ]; then +# echo_type="$TYPE" +# if [ -n "$fstype" ]; then +# # extX detection may detect a lower level than is actually on the device +# # additionally we may be forcing a higher level to be mounted as a lower level +# if [ "$fstype" = "ext4" ] || [ "$fstype" = "ext3" ] || [ "$fstype" = "ext2" ]; then +# if [ "$TYPE" = "ext2" ] || [ "$TYPE" = "ext3" ] || [ "$TYPE" = "ext4" ]; then +# echo_type="$fstype" +# fi +# fi +# else +# logger -t 'fstab' "fsck: Specified filesystem type $fstype does not match detected filesystem type $TYPE" +# fi +# echo "$echo_type" +# return 0 +#} + +libmount_known_fsck="" + +include /lib/functions/fsck + Index: package/block-mount/files/fstab.init =================================================================== --- package/block-mount/files/fstab.init (revision 0) +++ package/block-mount/files/fstab.init (revision 0) @@ -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 +} + Index: package/block-mount/files/block.sh =================================================================== --- package/block-mount/files/block.sh (revision 0) +++ package/block-mount/files/block.sh (revision 0) @@ -0,0 +1,281 @@ +#!/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" + shift + dmc_blkid_fstype_match="$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" + shift + dmds_mount_blkid_fstype_match="$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 + local gm_blkid_fstype_match + 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 + config_get_bool gm_blkid_fstype_match "$1" blkid_fstype_match 1 + 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" "$gm_blkid_fstype_match" +} + +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')" + + # We write to /etc/fstab, but it *should* be a symlink to /tmp/fstab + mkdir -p /var/lock + lock /var/lock/fstab.lck + cat /etc/fstab | grep -E -v "^$device[[:blank:]]" >>"$fstabnew" + [ "$enabled" -eq 1 ] && echo "$device none swap sw 0 0" >> "$fstabnew" + cat "$fstabnew" >/etc/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')" + + # We write to /etc/fstab, but it *should* be a symlink to /tmp/fstab + mkdir -p /var/lock + lock /var/lock/fstab.lck + cat /etc/fstab | grep -E -v "^$device[[:blank:]]" | grep -v "$target" >>"$fstabnew" + echo "$device $target $fstype $options 0 0" >>"$fstabnew" + cat "$fstabnew" >/etc/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" + shift + local mc_blkid_fstype_match="$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="$3" + msbd_enabled="$4" + msbd_enabled_fsck="$5" + msbd_uuid="$6" + msbd_label="$7" + msbd_is_rootfs="$8" + msbd_blkid_fstype_match="$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" "$msbd_blkid_fstype_match" + 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 +} + +#libmount_is_swap_device() { +# local device="$1" +# local TYPE +# eval "$(blkid -s TYPE $device | cut -f2 -d:)" +# [ "$TYPE" = "swap" ] && return 0 +# return 1 +#} + + Index: package/block-mount/files/40-mount =================================================================== --- package/block-mount/files/40-mount (revision 0) +++ package/block-mount/files/40-mount (revision 0) @@ -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 + Index: package/block-mount/files/fstab.config =================================================================== --- package/block-mount/files/fstab.config (revision 0) +++ package/block-mount/files/fstab.config (revision 0) @@ -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 + Index: package/block-mount/files/20-fsck =================================================================== --- package/block-mount/files/20-fsck (revision 0) +++ package/block-mount/files/20-fsck (revision 0) @@ -0,0 +1,87 @@ +#!/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" + shift + shift + mds_blkid_fstype_match="$9" + } + + 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 ] && { + hotplug_blkid_fstype_match="$mds_blkid_fstype_match" + 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" "$hotplug_blkid_fstype_match" + } + + reset_dev_section_cb + ;; + esac +fi + Index: package/block-mount/files/10-swap =================================================================== --- package/block-mount/files/10-swap (revision 0) +++ package/block-mount/files/10-swap (revision 0) @@ -0,0 +1,80 @@ +#!/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 ] && { +# libmount_is_swap_device $use_device && { + 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 + Index: package/block-mount/files/mount.sh =================================================================== --- package/block-mount/files/mount.sh (revision 0) +++ package/block-mount/files/mount.sh (revision 0) @@ -0,0 +1,92 @@ +#!/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 blkid_fstype_match="$9" + local blkid_fstype_match + 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" "$blkid_fstype_match" + } + } + + + 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_mount_point="$target" + } + 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 +} + + + Index: package/block-mount/Makefile =================================================================== --- package/block-mount/Makefile (revision 0) +++ package/block-mount/Makefile (revision 0) @@ -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)) + Index: package/base-files/files/etc/init.d/fstab =================================================================== --- package/base-files/files/etc/init.d/fstab (revision 19822) +++ package/base-files/files/etc/init.d/fstab (working copy) @@ -1,63 +0,0 @@ -#!/bin/sh /etc/rc.common -# Copyright (C) 2007 OpenWrt.org - -START=20 - -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 -} - -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 -} - -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 - echo '# WARNING: this is an auto generated file, please use uci to set static filesystems' > /tmp/fstab - 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 -} - Index: package/base-files/files/etc/hotplug.d/block/10-mount =================================================================== --- package/base-files/files/etc/hotplug.d/block/10-mount (revision 19822) +++ package/base-files/files/etc/hotplug.d/block/10-mount (working copy) @@ -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 Index: package/base-files/files/etc/config/fstab =================================================================== --- package/base-files/files/etc/config/fstab (revision 19822) +++ package/base-files/files/etc/config/fstab (working copy) @@ -1,10 +0,0 @@ -config mount - option target /home - option device /dev/sda1 - option fstype ext3 - option options rw,sync - option enabled 0 - -config swap - option device /dev/sda2 - option enabled 0 Index: package/e2fsprogs/files/e2fsck.init =================================================================== --- package/e2fsprogs/files/e2fsck.init (revision 19822) +++ package/e2fsprogs/files/e2fsck.init (working copy) @@ -1,35 +0,0 @@ -#!/bin/sh /etc/rc.common -# Copyright (C) 2008 OpenWrt.org -# Vasilis Tsiligiannis <acinon...@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 -} - Index: package/e2fsprogs/files/e2fsck.sh =================================================================== --- package/e2fsprogs/files/e2fsck.sh (revision 0) +++ package/e2fsprogs/files/e2fsck.sh (revision 0) @@ -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" Index: package/e2fsprogs/Makefile =================================================================== --- package/e2fsprogs/Makefile (revision 19822) +++ package/e2fsprogs/Makefile (working copy) @@ -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 @@ $(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 @@ -200,6 +200,11 @@ $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/blkid $(1)/usr/sbin/ endef +define Package/block-e2fsck/install + $(INSTALL_DIR) $(1)/etc/uci-defaults + $(INSTALL_BIN) ./files/e2fsck.uci-defaults $(1)/etc/uci-defaults/block-e2fsck +endef + $(eval $(call BuildPackage,e2fsprogs)) $(eval $(call BuildPackage,libuuid)) $(eval $(call BuildPackage,uuidgen)) @@ -209,3 +214,4 @@ $(eval $(call BuildPackage,resize2fs)) $(eval $(call BuildPackage,badblocks)) $(eval $(call BuildPackage,blkid)) +
signature.asc
Description: This is a digitally signed message part
_______________________________________________ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/mailman/listinfo/openwrt-devel