summaryrefslogtreecommitdiffstats
path: root/prebuilt/common/etc/init.d/05mountsd
blob: c5b87e22007e4e1082f5df3f543e0b5008276c10 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/system/bin/sh
#
# mount ext[234] partition from sd card

BB="logwrapper busybox";

if [ "$SD_EXT_DIRECTORY" = "" ];
then
    SD_EXT_DIRECTORY=/sd-ext;
fi;

# find first linux partition on SD card
MMC=/dev/block/mmcblk0

# wait for the device to settle
COUNT=6;
until [ -b "$MMC" ] || [ $COUNT -lt 1 ];
do
    sleep 1;
    COUNT=$((COUNT-1));
done;

if [ -b "$MMC" ];
then
    FDISK="busybox fdisk"
    PARTITION=`$FDISK -l $MMC | awk '/^\// && $5 == 83 {print $1;exit;}'`

    if [ -b "$PARTITION" ];
    then
        log -p i -t mountsd "Checking filesystems..";
   
        # fsck the sdcard filesystem first
        if [ -x `which e2fsck` ];
        then
            e2fsck -y $PARTITION;e2fsk_exitcode=$?
        else
            echo "executable e2fsck not found, assuming no filesystem errors"
            e2fsk_exitcode=0
        fi
        # set property with exit code in case an error occurs
        setprop cm.e2fsck.errors $e2fsk_exitcode;
        if [ "$e2fsk_exitcode" -lt 2 ];
        then
   
            # mount and set perms
            $BB mount -o noatime,nodiratime -t auto $PARTITION $SD_EXT_DIRECTORY;
            if [ "$?" = 0 ];
            then
                $BB chown 1000:1000 $SD_EXT_DIRECTORY;
                $BB chmod 771 $SD_EXT_DIRECTORY;
                log -p i -t mountsd "$SD_EXT_DIRECTORY successfully mounted";
            else
                log -p e -t mountsd "Unable to mount filesystem for $SD_EXT_DIRECTORY!";
            fi
        else
            log -p e -t mountsd "Unable to repair filesystem, disabling apps2sd";
        fi
    fi
fi