-
Notifications
You must be signed in to change notification settings - Fork 17
/
mount_ext4.sh
68 lines (62 loc) · 2.25 KB
/
mount_ext4.sh
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
60
61
62
63
64
65
66
67
68
#!/system/bin/sh
export PATH=/system/bin:/system/xbin:$PATH
BLOCK_DEVICE=$1
MOUNT_POINT=$2
LOG_FILE="/dev/null"
LOG_LOCATION="/data/.fsck_log/"
TMP_LOG_LOCATION="/dev/.fsck_log/"
if [ "${MOUNT_POINT}" == "/data" ]; then
mkdir -p ${TMP_LOG_LOCATION}
chmod 600 ${TMP_LOG_LOCATION}
TIMESTAMP=`date +%F_%H-%M-%S`
LOG_FILE=${TMP_LOG_LOCATION}/data_${TIMESTAMP}.log
elif [ "${MOUNT_POINT}" == "/cache" ]; then
mkdir -p ${LOG_LOCATION}
chmod 600 ${LOG_LOCATION}
TIMESTAMP=`date +%F_%H-%M-%S`
LOG_FILE=${LOG_LOCATION}/cache_${TIMESTAMP}.log
elif [ "${MOUNT_POINT}" == "/persist" ]; then
busybox find ${LOG_LOCATION} -type f -mtime +14 -exec rm {} \;
busybox mv ${TMP_LOG_LOCATION}/* ${LOG_LOCATION}/
TIMESTAMP=`date +%F_%H-%M-%S`
LOG_FILE=${LOG_LOCATION}/persist_${TIMESTAMP}.log
fi
if [ -e ${BLOCK_DEVICE} ]; then
/system/bin/dumpe2fs -h ${BLOCK_DEVICE} 2>&1 >${LOG_FILE}
ret1=$?
if [ $ret1 -ne 0 ];then
mke2fs -T ext4 -j -L ${MOUNT_POINT} ${BLOCK_DEVICE}
ret2=$?
echo "${PART_ALIAS} partition format ret = $ret2"
if [ $ret2 -ne 0 ];then
exit 1
fi
fi
e2fsck -y ${BLOCK_DEVICE} 2>&1 >>${LOG_FILE}
ret3=$?
echo "e2fsck on ${BLOCK_DEVICE} ret = $ret3" 2>&1 >>${LOG_FILE}
mount -t ext4 -o nosuid,nodev,barrier=1,noauto_da_alloc,discard ${BLOCK_DEVICE} ${MOUNT_POINT}
if [ -e ${MOUNT_POINT}/extend_size.userdata ]; then
umount ${MOUNT_POINT}
e2fsck -f -y ${BLOCK_DEVICE}
ret4=$?
echo "Forced e2fsck on ${BLOCK_DEVICE} ret = $ret4"
if [ $ret4 -eq 4 ]; then
e2fsck -y ${BLOCK_DEVICE}
fi
resize2fs ${BLOCK_DEVICE}
ret5=$?
echo "resize ${BLOCK_DEVICE} ret = $ret5"
e2fsck -y ${BLOCK_DEVICE}
ret6=$?
echo "e2fsck on ${BLOCK_DEVICE} ret = $ret6"
mount -t ext4 -o nosuid,nodev,barrier=1,noauto_da_alloc,discard ${BLOCK_DEVICE} ${MOUNT_POINT}
if [ $ret5 -eq 0 -o $ret5 -eq 2 ]; then
rm ${MOUNT_POINT}/extend_size*
fi
fi
fi
# hide recovery partition
RECOVERY_NODE="$(busybox readlink -f /dev/block/platform/msm_sdcc.1/by-name/recovery)"
busybox mv "${RECOVERY_NODE}" /dev/recovery_moved
busybox mknod -m 0600 "${RECOVERY_NODE}" b 1 3