chain/partiter: fix and improve gpt handling in buggy cases

Previous version had some issues in case of error situations, among
those:

- backup gpt header was not read if reading of primary failed
- alternating nature of lba_cur and lba_alt was ignored

This patch fixes this and extends the gpt handling.
The current behavior is:

- try primary header; if unreadable or checksum fails (or sanity checks
  fail unless relax flag is set) - try secondary header

- try main partition table referenced in the header that was read; if
  it's unreadable or if its crc check fails - try alternative (so if we
  managed to read primary header, table at the end would be considered
  as alternative - if we managed to read secondary header, table at the
  beginning would be treated as such)

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
chain/partiter: fix possible non-NULL value returned by pi_begin() on error

This patch fixes non-NULL value returned from pi_begin() in case of an
error (which resulted in further hang instead of proper exit). Probably
a leftover from pi_dealloc() times.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
chain/partiter: adjust error reporting

Use <0 for errors, 0 for normal state, and >0 for clean completion.

In future this would be necessary if it's decided to make partiter
a generic lib (similar to disklib) - though it has to be quieted first
and provide strerr()-like functionality in place of its verbosity.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
chain: add missing pi_del() in find*() functions

As partiter doesn't deallocate itself after finish (anymore), it should
be deleted after each loop iteration.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
chain: implement strict=<0|1|2>

This provides more fine grained control than single relax flag. to cover
case with wrong disk sizes.

relax and nostrict are equivalent to strict=0
norelax and strict are equivalent to strict=2

strict=1 does the same as strict=2, but ignores checks against disk size

The current default is strict=1. Options: 'fixchs', '[un]hide[all]' and
'save' will forcibly enable strict=2 (can be overridden by the user).

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
chain/partiter: correct gpt header checks

In gpt header, lba_cur and lba_alt alternate depending on whether we
read primary or backup copy.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>