Eliminate 512 hardcoded sector size

* use SECTOR_SIZE
* use PLOOP1_SECTOR_LOG

Reference: PSBM-21987 "ploop library must support sector size 4096 bytes"
Reference: ploop@975660
Read 4K for files opened with O_DIRECT

To support sector size <= 4K

Reference: PSBM-21987 "ploop library must support sector size 4096 bytes"
Reference: ploop@975663
Fix partition creation on 4K sector devices

Fix partition creation for devices with non 512 sector size.
Pass data in bytes to parted to avoid sector size dependency.
Skip blocksize form the the start and the end of device

Reference: PSBM-21987 "ploop library must support sector size 4096 bytes"
Reference: ploop@975669
Correct GPT in case device sector size change

As far as GPT structure is sector size depended
it needed to do GPT correction in case ploop image
is migrated/copied on fs with different from original sector size.

The GPT correction performend on mount stage.
If GPT signature is not found we perform search signature
at 512,1024,204,4096 offset. If signature found the GPT
reorgnized according to target sector size.

TODO:
it needed to implement safe GPT corecton to not leave GPT
semiconfigured on write failure.
* backup/restore original GPT
 or
* recreaet GPT

Reference: PSBM-21987 "ploop library must support sector size 4096 bytes"
Reference: ploop@975730
detect_image_sector_size(): compilation fix

This is a fix to recent commit r975730, to which compiler says:

	gpt.c: In function ‘detect_image_sector_size’:
	gpt.c:375:6: error: variable ‘xxx_sector_size’ set but not used
	[-Werror=unused-but-set-variable]
	cc1: all warnings being treated as errors

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
lib/gpt.c: compile fix

This is a compilation fix to commit r975730, which adds

	#include <linux/fs.h>

statement. Apparently, already included <sys/mount.h> have all the same
defines, therefore it gives a multitude of errors, like these:

	In file included from gpt.c:30:0:
	../include/linux/fs.h:27:0: error: "BLOCK_SIZE" redefined [-Werror]
	In file included from gpt.c:28:0:
	/usr/include/sys/mount.h:27:0: note: this is the location of the
	previous definition
	In file included from gpt.c:30:0:
	../include/linux/fs.h:208:0: error: "MS_RDONLY" redefined [-Werror]
	In file included from gpt.c:28:0:
	/usr/include/sys/mount.h:36:0: note: this is the location of the
	previous definition

NOTE: this is on Fedora 18 system. I will recheck on CentOS 5 and 6
later and fix if necessary.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
[style] removed duplicate DISKDESCRIPTOR_XML

It is already defined in libploop.h

Reference: ploop@975737
ploop mount: remove -u base feature

The feature of having a special value of 'base' for
'ploop mount -u UUID' was added for debugging, and there is
no use case for it. In addition, it is no longer working
since we switched to new ploop_{open,close}_dd() locking
scheme. So, let's just remove it.

Reference: ploop@976676
Acked-by: Igor Sukhuh <igor@parallels.com>
Signed-off-by: Kir Kolyshkin <kir@openvz.org>
gensym.sh: better usage and error diag

1. Improve usage
2. Print error if input file can't be read.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
gensym.sh: add run mode

Add ability to run any shell function in this file.
Usable for debug, e.g.:

	./gensym.sh include/libploop.h run extract_functions

	./gensym.sh include/libploop.h run gen_h

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
ploop_get_base_delta_uuid(): deprecate

There is no known user of this function outside of the library,
and it is not working properly after the switch to new
ploop_{open,close}_dd() locking scheme since DiskDescriptor.xml
can not be read yet by the time this function is called.

Nevertheless, rather than removing it, let's
1 provide a version that prints an error
2 mark the function as deprecated, so linker will
  emit a warning (or an error, depending on flags)

Similar should be done to the rest of the functions
that are to be deprecated.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
check_and_repair_sparse: handle EOF

The repair sparse logic do process all extent and could broke image
by repair after EOF. This patch adds logic to terminate processing
extent after the end of file.

2014-02-27T12:43:30+0400 : 1154 696320 118747707 118718834 256 eof
2014-02-27T12:43:30+0400 : 1155 696576 118747963 589 unwritten,eof
2014-02-27T12:43:30+0400 : 1156 697165 118728724 118748552 828 unwritten,eof
2014-02-27T12:43:30+0400 : 1157 697993 118718834 118729552 375 unwritten,eof
2014-02-27T12:43:30+0400 : 1158 698368 118729737 118719209 788 unwritten,eof
2014-02-27T12:43:30+0400 : 1159 699156 118735950 118730525 770 unwritten,eof
2014-02-27T12:43:30+0400 : 1160 699926 118722562 118736720 490 unwritten,eof

2014-02-27T12:43:30+0400 : Error in check_and_repair_sparse (check.c:543): Delta file /vz/private/112233/root.hdd/root.hdd contains uninitialized blocks (offset=2855587840 len=3391488) which are not aligned to cluster size

https://bugzilla.openvz.org/2897

Reference: PSBM-24671
Reference: ploop@981123