2 # Functions for reporting fsck progress in usplash
4 # (C) 2008 Canonical Ltd.
5 # Author: Martin Pitt <martin.pitt@ubuntu.com>
8 # convert a "pass cur max" progress triple from fsck to a progress percentage
9 # based on calc_percent() from e2fsck
10 fsck_progress_to_percent() {
12 PERCENT=$(($2 * 70 / $3))
14 PERCENT=$(($2 * 20 / $3 + 70))
16 PERCENT=$(($2 * 2 / $3 + 90))
18 PERCENT=$(($2 * 3 / $3 + 92))
20 PERCENT=$(($2 * 5 / $3 + 95))
26 # read current fsck status ($PASS, $CUR, $MAX) from file descriptor 4
27 # this assumes that fsck was started in the background ($!)
33 # only consider the last line
39 if [ -n "$PASS" ] && [ -z "$a" ]; then
43 # if we did not read anything, check if the process is still
44 # actually running, or just waiting to be reaped
45 if [ -z "$PASS" ] && [ -z "$a" ]; then
46 S=`ps -o state --no-headers -p $!` || break
47 [ "$S" != "Z" ] || break
48 # do not spin while waiting for fsck to start up
54 # Set $NAME to a human readable description of which partitions are currently
55 # being checked. Set $CLEAN if this is only a routine check on clean
56 # partitions which can be skipped.
61 FSCKPROCS=$(ps --no-headers -C 'fsck.ext2 fsck.ext3 fsck.ext4 fsck.ext4dev' -o pid,args | grep /dev)
62 DEVS=$(echo "$FSCKPROCS" | sed 's_^.*\(/dev/[^[:space:]]*\).*$_\1_')
63 FSCKPIDS=$(echo "$FSCKPROCS" | sed 's_^[[:space:]]*\([[:digit:]]\+\).*$_\1_')
65 if [ -z "$DEVS" ]; then
73 DUMP=$(dumpe2fs -h $DEV)
74 if ! echo "$DUMP" | grep -q 'state:[[:space:]]*clean$'; then
78 LABEL=$(blkid $DEV | sed -rn '/LABEL="([^"]+)"/ { s/^.*LABEL="//; s/".*$//; p }')
79 [ -z "$NAME" ] || NAME="$NAME, "
80 if [ -n "$LABEL" ]; then
81 NAME="$NAME$LABEL ($DEV)"
88 # Return true if usplash is active
90 if pidof usplash ; then
97 # Read fsck progress from file $1 and display progress in usplash.
101 ESCAPE=`/bin/echo -ne "\x1B"`
108 [ -n "$PASS" ] || break
110 fsck_progress_to_percent "$PASS" "$CUR" "$MAX"
112 # check if fsck advanced to the next drive
113 if [ "$PREVPERCENT" -gt "$PERCENT" ]; then
114 if [ -n "$CANCEL" ]; then
115 usplash_write "STATUS skip "
117 usplash_write "STATUS "
123 # lazy initialization of output and progress report on the first
124 # progress line that we receive; this avoids starting the output
125 # for clean or non-ext[234] partitions
126 if [ -n "$FIRST" ]; then
127 usplash_write "TIMEOUT 0"
129 # show which device is being checked
131 [ -n "$NAME" ] || break
133 usplash_write "VERBOSE on"
134 if [ "$CLEAN" ]; then
135 usplash_write "TEXT Routine check of drives: $NAME..."
136 usplash_write "TEXT Press ESC to skip"
138 usplash_write "TEXT Unclean shutdown, checking drives:"
139 usplash_write "TEXT $NAME..."
145 usplash_write "STATUS $PERCENT% (stage $PASS/5, $CUR/$MAX) "
146 echo "Checking drive $NAME: $PERCENT% (stage $PASS/5, $CUR/$MAX)" >/dev/console
148 # ESC interrupts check for clean drives
149 if [ -n "$CLEAN" ]; then
150 if FAIL_NO_USPLASH=1 usplash_write "INPUTCHAR"; then
151 read ch < /dev/.initramfs/usplash_outfifo
152 if [ "$ch" = "$ESCAPE" ]; then
155 continue # there might be more drives, so do not break
161 if [ -n "$CANCEL" ]; then
162 usplash_write "STATUS skip "
164 usplash_write "STATUS "
166 usplash_write "VERBOSE default"
167 usplash_write "TEXT Drive checks finished."
168 usplash_write "TIMEOUT 15"
169 wait %1 # to collect fsck's exit code
171 [ -n "$CANCEL" ] && FSCKCODE=0 || FSCKCODE=$EXITCODE
172 if [ "$FSCKCODE" -gt 1 ]; then
173 # non-correctable failure which requires sulogin: quit usplash and
174 # restore stdin/out/err
176 exec </dev/console >/dev/console 2>/dev/console