File: mkf2fsuserimg.sh

package info (click to toggle)
android-platform-tools 29.0.6-28
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 365,224 kB
  • sloc: cpp: 1,049,638; java: 460,532; ansic: 375,452; asm: 301,257; xml: 134,509; python: 92,731; perl: 62,008; sh: 26,753; makefile: 3,210; javascript: 3,172; yacc: 1,403; lex: 455; awk: 368; ruby: 183; sql: 140
file content (118 lines) | stat: -rwxr-xr-x 1,998 bytes parent folder | download
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
#!/bin/bash
#
# To call this script, make sure make_f2fs is somewhere in PATH

function usage() {
cat<<EOT
Usage:
${0##*/} OUTPUT_FILE SIZE
         [-S] [-C FS_CONFIG] [-f SRC_DIR] [-D PRODUCT_OUT]
         [-s FILE_CONTEXTS] [-t MOUNT_POINT] [-T TIMESTAMP]
         [-L LABEL] [--prjquota] [--casefold]
EOT
}

echo "in mkf2fsuserimg.sh PATH=$PATH"

MKFS_OPTS=""
SLOAD_OPTS=""

if [ $# -lt 2 ]; then
  usage
  exit 1
fi

OUTPUT_FILE=$1
SIZE=$2
shift; shift

SPARSE_IMG="false"
if [[ "$1" == "-S" ]]; then
  MKFS_OPTS+=" -S $SIZE"
  SLOAD_OPTS+=" -S"
  SPARSE_IMG="true"
  shift
fi

if [[ "$1" == "-C" ]]; then
  SLOAD_OPTS+=" -C $2"
  shift; shift
fi
if [[ "$1" == "-f" ]]; then
  SLOAD_OPTS+=" -f $2"
  shift; shift
fi
if [[ "$1" == "-D" ]]; then
  SLOAD_OPTS+=" -p $2"
  shift; shift
fi
if [[ "$1" == "-s" ]]; then
  SLOAD_OPTS+=" -s $2"
  shift; shift
fi
if [[ "$1" == "-t" ]]; then
  MOUNT_POINT=$2
  shift; shift
fi

if [ -z $MOUNT_POINT ]; then
  echo "Mount point is required"
  exit 2
fi

if [[ ${MOUNT_POINT:0:1} != "/" ]]; then
  MOUNT_POINT="/"$MOUNT_POINT
fi

SLOAD_OPTS+=" -t $MOUNT_POINT"

if [[ "$1" == "-T" ]]; then
  SLOAD_OPTS+=" -T $2"
  shift; shift
fi

if [[ "$1" == "-L" ]]; then
  MKFS_OPTS+=" -l $2"
  shift; shift
fi

if [[ "$1" == "--prjquota" ]]; then
  MKFS_OPTS+=" -O project_quota,extra_attr"
  shift;
fi
if [[ "$1" == "--casefold" ]]; then
  MKFS_OPTS+=" -O casefold -C utf8"
  shift;
fi

if [ -z $SIZE ]; then
  echo "Need size of filesystem"
  exit 2
fi

if [ "$SPARSE_IMG" = "false" ]; then
  TRUNCATE_CMD="truncate -s $SIZE $OUTPUT_FILE"
  echo $TRUNCATE_CMD
  $TRUNCATE_CMD
  if [ $? -ne 0 ]; then
    exit 3
  fi
fi

MAKE_F2FS_CMD="make_f2fs -g android $MKFS_OPTS $OUTPUT_FILE"
echo $MAKE_F2FS_CMD
$MAKE_F2FS_CMD
if [ $? -ne 0 ]; then
  if [ "$SPARSE_IMG" = "false" ]; then
    rm -f $OUTPUT_FILE
  fi
  exit 4
fi

SLOAD_F2FS_CMD="sload_f2fs $SLOAD_OPTS $OUTPUT_FILE"
echo $SLOAD_F2FS_CMD
$SLOAD_F2FS_CMD
if [ $? -ne 0 ]; then
  rm -f $OUTPUT_FILE
  exit 4
fi