| 254 | } |
| 255 | |
| 256 | func e2fsck(d string, force bool) error { |
| 257 | // preen |
| 258 | args := []string{"-p"} |
| 259 | if force { |
| 260 | args = append(args, "-f") |
| 261 | } |
| 262 | args = append(args, d) |
| 263 | if err := exec.Command("e2fsck", args...).Run(); err != nil { |
| 264 | if exiterr, ok := err.(*exec.ExitError); ok { |
| 265 | status, ok := exiterr.Sys().(syscall.WaitStatus) |
| 266 | if !ok { |
| 267 | return fmt.Errorf("Unable to get status code from e2fsck") |
| 268 | } |
| 269 | switch status.ExitStatus() { |
| 270 | case 1: |
| 271 | return nil |
| 272 | case 2, 3: |
| 273 | return fmt.Errorf("e2fsck fixed errors but requires a reboot") |
| 274 | } |
| 275 | } else { |
| 276 | return fmt.Errorf("Unable to cast err to ExitError") |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | // exit code was > 4. try harder |
| 281 | args[0] = "-y" |
| 282 | if err := exec.Command("/sbin/e2fsck", args...).Run(); err != nil { |
| 283 | if exiterr, ok := err.(*exec.ExitError); ok { |
| 284 | status, ok := exiterr.Sys().(syscall.WaitStatus) |
| 285 | if !ok { |
| 286 | return fmt.Errorf("Unable to get status code from e2fsck") |
| 287 | } |
| 288 | switch status.ExitStatus() { |
| 289 | case 1: |
| 290 | return nil |
| 291 | case 2, 3: |
| 292 | return fmt.Errorf("e2fsck fixed errors but requires a reboot") |
| 293 | default: |
| 294 | return fmt.Errorf("e2fsck exited with fatal error: %v", err) |
| 295 | } |
| 296 | } else { |
| 297 | return fmt.Errorf("Unable to cast err to ExitError") |
| 298 | } |
| 299 | } |
| 300 | return nil |
| 301 | } |
| 302 | |
| 303 | // return a list of all available drives |
| 304 | func findDrives() { |