blob: f8aef217c06aa230523d4d34b24349499b809c89 (
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
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
|
#!/bin/bash
#
# To call this script, make sure mke2fs is somewhere in PATH
function usage() {
cat<<EOT
Usage:
mkuserimg.sh [-s] SRC_DIR OUTPUT_FILE EXT_VARIANT MOUNT_POINT SIZE [-j <journal_size>]
[-T TIMESTAMP] [-C FS_CONFIG] [-D PRODUCT_OUT] [-B BLOCK_LIST_FILE]
[-d BASE_ALLOC_FILE_IN ] [-A BASE_ALLOC_FILE_OUT ] [-L LABEL]
[ -i INODES ] [FILE_CONTEXTS]
EOT
}
MKE2FS_OPTS=""
E2FSDROID_OPTS=""
if [ "$1" = "-s" ]; then
MKE2FS_OPTS+="-E android_sparse"
shift
else
E2FSDROID_OPTS+="-e"
fi
if [ $# -lt 5 ]; then
usage
exit 1
fi
SRC_DIR=$1
if [ ! -d $SRC_DIR ]; then
echo "Can not find directory $SRC_DIR!"
exit 2
fi
OUTPUT_FILE=$2
EXT_VARIANT=$3
MOUNT_POINT=$4
SIZE=$5
shift; shift; shift; shift; shift
if [ "$1" = "-j" ]; then
if [ "$2" = "0" ]; then
MKE2FS_OPTS+="-O ^has_journal"
else
MKE2FS_OPTS+="-J size=$2"
fi
shift; shift
fi
if [[ "$1" == "-T" ]]; then
E2FSDROID_OPTS+=" -T $2"
shift; shift
fi
if [[ "$1" == "-C" ]]; then
E2FSDROID_OPTS+=" -C $2"
shift; shift
fi
if [[ "$1" == "-D" ]]; then
E2FSDROID_OPTS+=" -p $2"
shift; shift
fi
if [[ "$1" == "-B" ]]; then
E2FSDROID_OPTS+=" -B $2"
shift; shift
fi
if [[ "$1" == "-d" ]]; then
E2FSDROID_OPTS+=" -d $2"
shift; shift
fi
if [[ "$1" == "-A" ]]; then
E2FSDROID_OPTS+=" -D $2"
shift; shift
fi
if [[ "$1" == "-L" ]]; then
MKE2FS_OPTS+=" -L $2"
shift; shift
fi
if [[ "$1" == "-i" ]]; then
MKE2FS_OPTS+=" -N $2"
shift; shift
fi
E2FSDROID_OPTS+=" -S $1"
case $EXT_VARIANT in
ext4) ;;
*) echo "Only ext4 is supported!"; exit 3 ;;
esac
if [ -z $MOUNT_POINT ]; then
echo "Mount point is required"
exit 2
fi
if [[ ${MOUNT_POINT:0:1} != "/" ]]; then
MOUNT_POINT="/"$MOUNT_POINT
fi
if [ -z $SIZE ]; then
echo "Need size of filesystem"
exit 2
fi
BLOCKSIZE=4096
# Round down the filesystem length to be a multiple of the block size
SIZE=$((SIZE / BLOCKSIZE))
# truncate output file since mke2fs will keep verity section in existing file
cat /dev/null >$OUTPUT_FILE
MAKE_EXT4FS_CMD="mke2fs $MKE2FS_OPTS -t $EXT_VARIANT -b $BLOCKSIZE $OUTPUT_FILE $SIZE"
echo $MAKE_EXT4FS_CMD
$MAKE_EXT4FS_CMD
if [ $? -ne 0 ]; then
exit 4
fi
E2FSDROID_CMD="e2fsdroid $E2FSDROID_OPTS -f $SRC_DIR -a $MOUNT_POINT $OUTPUT_FILE"
echo $E2FSDROID_CMD
$E2FSDROID_CMD
if [ $? -ne 0 ]; then
rm -f $OUTPUT_FILE
exit 4
fi
|