You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The exit code returned by fsck is the sum of the following conditions:
0 - No errors
1 - File system errors corrected
2 - System should be rebooted
4 - File system errors left uncorrected
8 - Operational error
16 - Usage or syntax error
32 - Fsck canceled by user request
128 - Shared library error
The exit code returned when multiple file systems are checked is the bit-wise OR of the exit codes for each file system that is checked.
Current code:
funcfsck(devstring) error {
if_, err:=os.Stat("/usr/bin/fsck"); !os.IsNotExist(err) {
cmd:=exec.Command("/usr/bin/fsck", "-y", dev)
ifverbosityLevel>=levelDebug {
cmd.Stdout=os.Stdout
}
iferr:=cmd.Run(); err!=nil {
iferr, ok:=err.(*exec.ExitError); ok {
iferr.ExitCode()&^0x1!=0 {
// bit 1 means errors were corrected successfully which is goodreturnunwrapExitError(err)
}
returnnil
}
returnfmt.Errorf("fsck for %s: unknown error %v", dev, err)
}
}
returnnil
}
My personal improved code
Use fsck.ext4, because otherwise the incompatible busybox fsck will be used.
Bitwise checking should not be required, because we do not check multiple devices at once.
Ensure to check for exit code 2 and reboot
Hint: I enforce a fsck operation and removed the file exists check.
// TODO: check which filesystem type it is and select the correct fsck utility.funcfsck(devstring) (errerror) {
output, err:=exec.Command("/usr/bin/fsck.ext4", "-y", dev).CombinedOutput()
iferr==nil {
debug("fsck output: %s", string(output))
return
}
iferr, ok:=err.(*exec.ExitError); ok {
switcherr.ExitCode() {
case0:
returnnilcase1: // File system errors correctedsevere("fsck corrected filesystem errors: %s", string(output))
returnnilcase2: // File system errors corrected, system should be rebootedsevere("fsck corrected filesystem errors: %s", string(output))
syscall.Sync()
fmt.Println("Reboot required")
time.Sleep(3*time.Second)
returnsyscall.Reboot(syscall.LINUX_REBOOT_CMD_RESTART)
}
}
returnfmt.Errorf("fsck for %s: unknown error %v\n%s", dev, err, string(output))
}
The text was updated successfully, but these errors were encountered:
Quote from fsck man:
Current code:
My personal improved code
The text was updated successfully, but these errors were encountered: