c59e5abd727fbeeff85d862fcdb4c7afe315ad4c
[openwrt.git] / package / block-mount / files / 20-fsck
1 #!/bin/sh
2 # Copyright (C) 2009-2010 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
8 . /lib/functions/block.sh
9 . /lib/functions/fsck.sh
10
11 blkdev=`dirname $DEVPATH`
12
13 if [ `basename $blkdev` != "block" ]; then
14
15     device=`basename $DEVPATH`
16
17     case "$ACTION" in
18         add)
19                 local from_fstab
20                 local anon_mount
21                 local anon_swap
22                 local anon_fsck         
23                 local mds_mount_target
24                 local mds_mount_device
25                 local mds_mount_fstype
26                 local mds_mount_enabled_fsck
27                 local sds_swap_device
28                 local use_device
29                 local do_fsck=0
30                 local fsck_type
31                 
32                 local autoswap_from_fstab
33                 local automount_from_fstab
34                 local hotplug_blkid_fstype_match
35
36             mount_dev_section_cb() {
37                         mds_mount_device="$3"
38                         mds_mount_fstype="$4"
39                         mds_mount_enabled_fsck="$7"
40             }
41
42             swap_dev_section_cb() { 
43                         sds_swap_device="$2"
44                         return 0
45             }
46
47                 config_get_automount
48                 automount_from_fstab="$from_fstab"
49                 
50                 [ "$automount_from_fstab" -eq 1 ] && {
51                         config_get_mount_section_by_device "/dev/$device"
52                         use_device="$mds_mount_device"
53                         [ "$mds_mount_enabled_fsck" -eq 1 ] && { 
54                                 do_fsck=1
55                                 fsck_type="$mds_mount_fstype"
56                         }
57                 }
58                 
59                 [ -z "$use_device" ] && {
60                         config_get_autoswap
61                         autoswap_from_fstab="$from_fstab"
62                 
63                         [ "$autoswap_from_fstab" -eq 1 ] && {
64                                 config_get_swap_section_by_device "/dev/$device"
65                                 use_device="$sds_swap_device" && do_fsck=0
66                         }
67                 }
68                 
69                 grep -q "/dev/$device" /proc/swaps || grep -q "/dev/$device" /proc/mounts || {
70                         [ "$anon_fsck" -eq 1 ] && [ -z "$use_device" ] && {
71                                 use_device="/dev/$device" && do_fsck=1 && mds_mount_fstype="" && hotplug_blkid_fstype_match=0
72                         }
73                 }
74                 
75                 [ "$do_fsck" -eq 1 ] && {               
76                         libmount_fsck "$use_device" "$fsck_type" "$do_fsck"
77                 }
78                 
79                 reset_dev_section_cb
80                 ;;
81     esac        
82 fi
83