-
Notifications
You must be signed in to change notification settings - Fork 4
/
usb
190 lines (162 loc) · 4.02 KB
/
usb
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#!/system/bin/sh
#
# W.I.P. script, by XDA@USBhost. made for the Nexus 9/aarch64 in mind.
# If your using f2fs i am assuming the kernel is using the latest f2fs.
#
#set -x
# This is to avoid running though everything just for an exit 1
if [ "$(whoami)" != "root" ]; then
echo "...ROOT is required...";
exit 1;
fi
#globle
BB="$(find /system -name busybox | head -n 1)"; # BusyBox
MF="USB"; #-------------------------------------- Mount Folder
MP="/mnt/${MF}"; #------------------------------- Mount point
function helpd() {
echo "
Usage: -m BLOCK FILE-SYSTEM // like -m sda f2fs
Note: if FILE-SYSTEM is not specified (like -m sda )
for mount, auto will be used insted.
-h -------------------- display this help
-u -------------------- umount drive
-m BLOCK FILE-SYSTEM -- mount drive
-r BLOCK FILE-SYSTEM -- repair drive
-f BLOCK FILE-SYSTEM -- format drive
IF YOUR MOUNTS DONT SHOW USE <su -mm> NOT <su>
Supported file systems (to mount):
$(< /proc/filesystems grep -v nodev | grep -v fuseblk)
Supported file systems (to format):
ext3
ext2
ext4
vfat
exfat
f2fs
Supported file systems (to repair):
ext3
ext2
ext4
vfat
exfat
f2fs"
}
# list mount points
function listd() {
for f in /dev/block/sd*;
do
echo "${f##*/}";
done
}
# mount
function mountd() {
function mountcheck()
{
mountcheck="$("${BB}" mount | "${BB}" grep -o "${MP}")";
if [ "${mountcheck}" != "${MP}" ]; then
echo "Mount failed";
exit 1;
elif [ "${mountcheck}" = "${MP}" ]; then
echo "Mount success";
fi
}
mkdir -p "${MP}";
chmod 777 "${MP}";
if [ "${3}" != "" ]; then
# vfat does not need umask=000 because it has no permission support.
if [ "${3}" = "ntfs" ]; then
"${BB}" mount -t "${3}" -o rw,umask=000 /dev/block/"${2}" "${MP}";
"${BB}" mount -o remount,nls=utf8,nofail "${MP}"; # if this fails no worrys
elif [ "${3}" = "exfat" ]; then
"${BB}" mount -t "${3}" -o rw,umask=000 /dev/block/"${2}" "${MP}";
else
"${BB}" mount -t "${3}" -o rw /dev/block/"${2}" "${MP}";
fi
else
"${BB}" mount -t auto -o rw /dev/block/"${2}" "${MP}";
fi
mountcheck;
echo "Access here: ${MP}";
}
# umount
function umountd() {
"${BB}" umount -l "${MP}";
echo "Unmounted: ${MP}";
}
# format
function formatd() {
f2fs="/system/etc/usblib/mkfs.f2fs";
ext="/system/etc/usblib/mke2fs";
vfat="/system/etc/usblib/mkfs.fat";
exfat="/system/etc/usblib/mkfs.exfat";
if [ "${3}" != "" ]; then
umountd;
if [ "${3}" = "f2fs" ]; then
"${f2fs}" /dev/block/"${2}";
mountd - "${2}" "${3}";
chmod -R 777 "${MP}";
elif [ "${3}" = "ext2" ] ||
[ "${3}" = "ext3" ] ||
[ "${3}" = "ext4" ]; then
"${ext}" -t "${3}" /dev/block/"${2}";
mountd - "${2}" "${3}";
chmod -R 777 "${MP}";
elif [ "${3}" = "ntfs" ]; then
echo "not supported";
elif [ "${3}" = "vfat" ]; then
"${vfat}" /dev/block/"${2}";
mountd - "${2}" "${3}";
elif [ "${3}" = "exfat" ]; then
"${exfat}" /dev/block/"${2}";
mountd - "${2}" "${3}";
fi
fi
}
# repair
function repaird() {
f2fs="/system/etc/usblib/fsck.f2fs";
ext="/system/etc/usblib/e2fsck";
vfat="/system/etc/usblib/fsck.fat";
exfat="/system/etc/usblib/fsck.exfat";
function extcheck() {
if [ "${3}" = "ext2" ] ||
[ "${3}" = "ext3" ] ||
[ "${3}" = "ext4" ]; then
echo "dont use ${3}, use ext instead";
exit 1;
fi
}
if [ "${3}" != "" ]; then
extcheck "${@}";
umountd;
if [ "${3}" = "f2fs" ]; then
"${f2fs}" "${4}" /dev/block/"${2}";
elif [ "${3}" = "ext" ]; then
"${ext}" "${4}" /dev/block/"${2}";
elif [ "${3}" = "ntfs" ]; then
echo "not supported yet";
elif [ "${3}" = "vfat" ]; then
"${vfat}" "${4}" /dev/block/"${2}";
elif [ "${3}" = "exfat" ]; then
"${exfat}" /dev/block/"${2}";
fi
fi
}
while getopts lum:f:r:h opt; do
case $opt in
l) listd;
;;
u) umountd;
;;
m) mountd "${@}";
;;
f) formatd "${@}";
;;
r) repaird "${@}";
;;
h) helpd;
;;
*) helpd;
;;
esac
done