]>
Commit | Line | Data |
---|---|---|
21f63869 NS |
1 | #!/bin/sh -f |
2 | # | |
3 | # Copyright (c) 2006 Silicon Graphics, Inc. All Rights Reserved. | |
4 | # | |
5 | ||
04a2d5dc JT |
6 | NAME=$0 |
7 | ||
8 | # get the right return code for fsck | |
7a58ab01 | 9 | repair2fsck_code() { |
04a2d5dc JT |
10 | case $1 in |
11 | 0) return 0 # everything is ok | |
12 | ;; | |
13 | 1) echo "$NAME error: xfs_repair could not fix the filesystem." 1>&2 | |
14 | return 4 # errors left uncorrected | |
15 | ;; | |
16 | 2) echo "$NAME error: The filesystem log is dirty, mount it to recover" \ | |
17 | "the log. If that fails, refer to the section DIRTY LOGS in the" \ | |
18 | "xfs_repair manual page." 1>&2 | |
19 | return 4 # dirty log, don't do anything and let the user solve it | |
20 | ;; | |
21 | 4) return 1 # The fs has been fixed | |
22 | ;; | |
e3f20e60 DW |
23 | 127) |
24 | echo "$NAME error: xfs_repair was not found!" 1>&2 | |
25 | return 4 | |
26 | ;; | |
04a2d5dc JT |
27 | *) echo "$NAME error: An unknown return code from xfs_repair '$1'" 1>&2 |
28 | return 4 # something went wrong with xfs_repair | |
29 | esac | |
30 | } | |
31 | ||
21f63869 | 32 | AUTO=false |
04a2d5dc JT |
33 | FORCE=false |
34 | while getopts ":aApyf" c | |
21f63869 NS |
35 | do |
36 | case $c in | |
1993314d | 37 | a|A|p|y) AUTO=true;; |
04a2d5dc | 38 | f) FORCE=true;; |
21f63869 NS |
39 | esac |
40 | done | |
ec16267e BN |
41 | eval DEV=\${$#} |
42 | if [ ! -e $DEV ]; then | |
43 | echo "$0: $DEV does not exist" | |
44 | exit 8 | |
45 | fi | |
04a2d5dc JT |
46 | |
47 | # The flag -f is added by systemd/init scripts when /forcefsck file is present | |
48 | # or fsck.mode=force is used during boot; an unclean shutdown won't trigger | |
49 | # this check, user has to explicitly require a forced fsck. | |
50 | # But first of all, test if it is a non-interactive session. | |
51 | # Invoking xfs_repair via fsck.xfs is only intended to happen via initscripts. | |
52 | # Normal administrative filesystem repairs should always invoke xfs_repair | |
53 | # directly. | |
54 | # | |
55 | # Use multiple methods to capture most of the cases: | |
56 | # The case for *i* and -n "$PS1" are commonly suggested in bash manual | |
57 | # and the -t 0 test checks stdin | |
58 | case $- in | |
59 | *i*) FORCE=false ;; | |
60 | esac | |
61 | if [ -n "$PS1" -o -t 0 ]; then | |
62 | FORCE=false | |
63 | fi | |
64 | ||
65 | if $FORCE; then | |
e3f20e60 | 66 | xfs_repair -e $DEV |
04a2d5dc JT |
67 | repair2fsck_code $? |
68 | exit $? | |
69 | fi | |
70 | ||
21f63869 NS |
71 | if $AUTO; then |
72 | echo "$0: XFS file system." | |
73 | else | |
74 | echo "If you wish to check the consistency of an XFS filesystem or" | |
12a48f5d | 75 | echo "repair a damaged filesystem, see xfs_repair(8)." |
21f63869 NS |
76 | fi |
77 | exit 0 |