Index: uspace/lib/gpt/global.c
===================================================================
--- uspace/lib/gpt/global.c	(revision f4a47e52b9d2a3642a58eb1b953d1e52d56a160a)
+++ uspace/lib/gpt/global.c	(revision b51cf2cfbf7533cc494e6a1795d62f5fbd481c87)
@@ -1,4 +1,4 @@
 /*
- * Copyright (c) 2011, 2012, 2013 Dominik Taborsky
+ * Copyright (c) 2011-2013 Dominik Taborsky
  * All rights reserved.
  *
@@ -44,71 +44,68 @@
 };
 
-const struct partition_type gpt_ptypes[] = {
-	{ "Unused entry",					"00000000" "0000" "0000" "0000000000000000" }, /* 0 */
-	{ "HelenOS System",					"656C6548" "4F6E" "5320" "53797374656D0000" }, /* 1 It says "HelenOS System\0\0" */
-	{ "MBR partition scheme",			"024DEE41" "33E7" "11D3" "9D690008C781F39F" },
-	{ "EFI System",						"C12A7328" "F81F" "11D2" "BA4B00A0C93EC93B" },
-	{ "BIOS Boot",						"21686148" "6449" "6E6F" "744E656564454649" },
-	{ "Windows Reserved",				"E3C9E316" "0B5C" "4DB8" "817DF92DF00215AE" },
-	{ "Windows Basic data",				"EBD0A0A2" "B9E5" "4433" "87C068B6B72699C7" },
-	{ "Windows LDM metadata", 			"5808C8AA" "7E8F" "42E0" "85D2E1E90434CFB3" },
-	{ "Windows LDM data", 				"AF9B60A0" "1431" "4F62" "BC683311714A69AD" },
-	{ "Windows Recovery Environment",	"DE94BBA4" "06D1" "4D40" "A16ABFD50179D6AC" },
-	{ "Windows IBM GPFS",				"37AFFC90" "EF7D" "4E96" "91C32D7AE055B174" }, /* 10 */
-	{ "Windows Cluster metadata",		"DB97DBA9" "0840" "4BAE" "97F0FFB9A327C7E1" },
-	{ "HP-UX Data",						"75894C1E" "3AEB" "11D3" "B7C17B03A0000000" },
-	{ "HP-UX Service",					"E2A1E728" "32E3" "11D6" "A6827B03A0000000" },
-	{ "Linux filesystem data",			"0FC63DAF" "8483" "4772" "8E793D69D8477DE4" },
-	{ "Linux RAID",						"A19D880F" "05FC" "4D3B" "A006743F0F84911E" },
-	{ "Linux Swap",						"0657FD6D" "A4AB" "43C4" "84E50933C84B4F4F" },
-	{ "Linux LVM",						"E6D6D379" "F507" "44C2" "A23C238F2A3DF928" },
-	{ "Linux filesystem data",			"933AC7E1" "2EB4" "4F13" "B8440E14E2AEF915" },
-	{ "Linux Reserved",					"8DA63339" "0007" "60C0" "C436083AC8230908" },
-	{ "FreeBSD Boot",					"83BD6B9D" "7F41" "11DC" "BE0B001560B84F0F" }, /* 20 */
-	{ "FreeBSD Data",					"516E7CB4" "6ECF" "11D6" "8FF800022D09712B" },
-	{ "FreeBSD Swap",					"516E7CB5" "6ECF" "11D6" "8FF800022D09712B" },
-	{ "FreeBSD UFS", 					"516E7CB6" "6ECF" "11D6" "8FF800022D09712B" },
-	{ "FreeBSD Vinum VM",				"516E7CB8" "6ECF" "11D6" "8FF800022D09712B" },
-	{ "FreeBSD ZFS",					"516E7CBA" "6ECF" "11D6" "8FF800022D09712B" },
-	{ "Mac OS X HFS+",					"48465300" "0000" "11AA" "AA1100306543ECAC" },
-	{ "Mac OS X UFS",					"55465300" "0000" "11AA" "AA1100306543ECAC" },
-	{ "Mac OS X ZFS",					"6A898CC3" "1DD2" "11B2" "99A6080020736631" },
-	{ "Mac OS X RAID",					"52414944" "0000" "11AA" "AA1100306543ECAC" },
-	{ "Mac OS X RAID, offline",			"52414944" "5F4F" "11AA" "AA1100306543ECAC" }, /* 30 */
-	{ "Mac OS X Boot",					"426F6F74" "0000" "11AA" "AA1100306543ECAC" },
-	{ "Mac OS X Label",					"4C616265" "6C00" "11AA" "AA1100306543ECAC" },
-	{ "Mac OS X TV Recovery",			"5265636F" "7665" "11AA" "AA1100306543ECAC" },
-	{ "Mac OS X Core Storage",			"53746F72" "6167" "11AA" "AA1100306543ECAC" },
-	{ "Solaris Boot",					"6A82CB45" "1DD2" "11B2" "99A6080020736631" },
-	{ "Solaris Root",					"6A85CF4D" "1DD2" "11B2" "99A6080020736631" },
-	{ "Solaris Swap",					"6A87C46F" "1DD2" "11B2" "99A6080020736631" },
-	{ "Solaris Backup",					"6A8B642B" "1DD2" "11B2" "99A6080020736631" },
-	{ "Solaris /usr",					"6A898CC3" "1DD2" "11B2" "99A6080020736631" },
-	{ "Solaris /var",					"6A8EF2E9" "1DD2" "11B2" "99A6080020736631" }, /* 40 */
-	{ "Solaris /home",					"6A90BA39" "1DD2" "11B2" "99A6080020736631" },
-	{ "Solaris Alternate sector",		"6A9283A5" "1DD2" "11B2" "99A6080020736631" },
-	{ "Solaris Reserved",				"6A945A3B" "1DD2" "11B2" "99A6080020736631" },
-	{ "Solaris Reserved",				"6A9630D1" "1DD2" "11B2" "99A6080020736631" },
-	{ "Solaris Reserved",				"6A980767" "1DD2" "11B2" "99A6080020736631" },
-	{ "Solaris Reserved",				"6A96237F" "1DD2" "11B2" "99A6080020736631" },
-	{ "Solaris Reserved",				"6A8D2AC7" "1DD2" "11B2" "99A6080020736631" },
-	{ "NetBSD Swap",					"49F48D32" "B10E" "11DC" "B99B0019D1879648" },
-	{ "NetBSD FFS",						"49F48D5A" "B10E" "11DC" "B99B0019D1879648" },
-	{ "NetBSD LFS",						"49F48D82" "B10E" "11DC" "B99B0019D1879648" }, /* 50 */
-	{ "NetBSD RAID",					"49F48DAA" "B10E" "11DC" "B99B0019D1879648" },
-	{ "NetBSD Concatenated",			"2DB519C4" "B10F" "11DC" "B99B0019D1879648" },
-	{ "NetBSD Encrypted",				"2DB519EC" "B10F" "11DC" "B99B0019D1879648" },
-	{ "ChromeOS ChromeOS kernel",		"FE3A2A5D" "4F32" "41A7" "B725ACCC3285A309" },
-	{ "ChromeOS rootfs",				"3CB8E202" "3B7E" "47DD" "8A3C7FF2A13CFCEC" },
-	{ "ChromeOS future use",			"2E0A753D" "9E48" "43B0" "8337B15192CB1B5E" },
-	{ "MidnightBSD Boot",				"85D5E45E" "237C" "11E1" "B4B3E89A8F7FC3A7" },
-	{ "MidnightBSD Data",				"85D5E45A" "237C" "11E1" "B4B3E89A8F7FC3A7" },
-	{ "MidnightBSD Swap",				"85D5E45B" "237C" "11E1" "B4B3E89A8F7FC3A7" },
-	{ "MidnightBSD UFS",				"0394Ef8B" "237E" "11E1" "B4B3E89A8F7FC3A7" }, /* 60 */
-	{ "MidnightBSD Vinum VM",			"85D5E45C" "237C" "11E1" "B4B3E89A8F7FC3A7" },
-	{ "MidnightBSD ZFS",				"85D5E45D" "237C" "11E1" "B4B3E89A8F7FC3A7" },
-	{ "Uknown", NULL} /* keep this as the last one! gpt_get_part_type depends on it! */
+const partition_type_t gpt_ptypes[] = {
+	{ "unused entry",                 "00000000" "0000" "0000" "0000000000000000" }, /* 0 */
+	{ "HelenOS System",               "3dc61fa0" "cf7a" "3ad8" "ac57615029d81a6b" }, /* "HelenOS System" encoded as RFC 4122 UUID, version 3 (MD5 name-based) */
+	{ "MBR partition scheme",         "024dee41" "33e7" "11d3" "9d690008c781f39f" },
+	{ "EFI System",                   "c12a7328" "f81f" "11d2" "ba4b00a0c93ec93b" },
+	{ "BIOS Boot",                    "21686148" "6449" "6e6f" "744e656564454649" },
+	{ "Windows Reserved",             "e3c9e316" "0b5c" "4db8" "817df92df00215ae" },
+	{ "Windows Basic data",           "ebd0a0a2" "b9e5" "4433" "87c068b6b72699c7" },
+	{ "Windows LDM metadata",         "5808c8aa" "7e8f" "42e0" "85d2e1e90434cfb3" },
+	{ "Windows LDM data",             "af9b60a0" "1431" "4f62" "bc683311714a69ad" },
+	{ "Windows Recovery Environment", "de94bba4" "06d1" "4d40" "a16abfd50179d6ac" },
+	{ "Windows IBM GPFS",             "37affc90" "ef7d" "4e96" "91c32d7ae055b174" }, /* 10 */
+	{ "Windows Cluster metadata",     "db97dba9" "0840" "4bae" "97f0ffb9a327c7e1" },
+	{ "HP-UX Data",                   "75894c1e" "3aeb" "11d3" "b7c17b03a0000000" },
+	{ "HP-UX Service",                "e2a1e728" "32e3" "11d6" "a6827b03a0000000" },
+	{ "Linux filesystem data",        "0fc63daf" "8483" "4772" "8e793d69d8477de4" },
+	{ "Linux RAID",                   "a19d880f" "05fc" "4d3b" "a006743f0f84911e" },
+	{ "Linux Swap",                   "0657fd6d" "a4ab" "43c4" "84e50933c84b4f4f" },
+	{ "Linux LVM",                    "e6d6d379" "f507" "44c2" "a23c238f2a3df928" },
+	{ "Linux filesystem data",        "933ac7e1" "2eb4" "4f13" "b8440e14e2aef915" },
+	{ "Linux Reserved",               "8da63339" "0007" "60c0" "c436083ac8230908" },
+	{ "FreeBSD Boot",                 "83bd6b9d" "7f41" "11dc" "be0b001560b84f0f" }, /* 20 */
+	{ "FreeBSD Data",                 "516e7cb4" "6ecf" "11d6" "8ff800022d09712b" },
+	{ "FreeBSD Swap",                 "516e7cb5" "6ecf" "11d6" "8ff800022d09712b" },
+	{ "FreeBSD UFS",                  "516e7cb6" "6ecf" "11d6" "8ff800022d09712b" },
+	{ "FreeBSD Vinum VM",             "516e7cb8" "6ecf" "11d6" "8ff800022d09712b" },
+	{ "FreeBSD ZFS",                  "516e7cba" "6ecf" "11d6" "8ff800022d09712b" },
+	{ "Mac OS X HFS+",                "48465300" "0000" "11aa" "aa1100306543ecac" },
+	{ "Mac OS X UFS",                 "55465300" "0000" "11aa" "aa1100306543ecac" },
+	{ "Mac OS X ZFS",                 "6a898cc3" "1dd2" "11b2" "99a6080020736631" },
+	{ "Mac OS X RAID",                "52414944" "0000" "11aa" "aa1100306543ecac" },
+	{ "Mac OS X RAID, offline",       "52414944" "5f4f" "11aa" "aa1100306543ecac" }, /* 30 */
+	{ "Mac OS X Boot",                "426f6f74" "0000" "11aa" "aa1100306543ecac" },
+	{ "Mac OS X Label",               "4c616265" "6c00" "11aa" "aa1100306543ecac" },
+	{ "Mac OS X TV Recovery",         "5265636f" "7665" "11aa" "aa1100306543ecac" },
+	{ "Mac OS X Core Storage",        "53746f72" "6167" "11aa" "aa1100306543ecac" },
+	{ "Solaris Boot",                 "6a82cb45" "1dd2" "11b2" "99a6080020736631" },
+	{ "Solaris Root",                 "6a85cf4d" "1dd2" "11b2" "99a6080020736631" },
+	{ "Solaris Swap",                 "6a87c46f" "1dd2" "11b2" "99a6080020736631" },
+	{ "Solaris Backup",               "6a8b642b" "1dd2" "11b2" "99a6080020736631" },
+	{ "Solaris /usr",                 "6a898cc3" "1dd2" "11b2" "99a6080020736631" },
+	{ "Solaris /var",                 "6a8ef2e9" "1dd2" "11b2" "99a6080020736631" }, /* 40 */
+	{ "Solaris /home",                "6a90ba39" "1dd2" "11b2" "99a6080020736631" },
+	{ "Solaris Alternate sector",     "6a9283a5" "1dd2" "11b2" "99a6080020736631" },
+	{ "Solaris Reserved",             "6a945a3b" "1dd2" "11b2" "99a6080020736631" },
+	{ "Solaris Reserved",             "6a9630d1" "1dd2" "11b2" "99a6080020736631" },
+	{ "Solaris Reserved",             "6a980767" "1dd2" "11b2" "99a6080020736631" },
+	{ "Solaris Reserved",             "6a96237f" "1dd2" "11b2" "99a6080020736631" },
+	{ "Solaris Reserved",             "6a8d2ac7" "1dd2" "11b2" "99a6080020736631" },
+	{ "NetBSD Swap",                  "49f48d32" "b10e" "11dc" "b99b0019d1879648" },
+	{ "NetBSD FFS",                   "49f48d5a" "b10e" "11dc" "b99b0019d1879648" },
+	{ "NetBSD LFS",                   "49f48d82" "b10e" "11dc" "b99b0019d1879648" }, /* 50 */
+	{ "NetBSD RAID",                  "49f48daa" "b10e" "11dc" "b99b0019d1879648" },
+	{ "NetBSD Concatenated",          "2db519c4" "b10f" "11dc" "b99b0019d1879648" },
+	{ "NetBSD Encrypted",             "2db519ec" "b10f" "11dc" "b99b0019d1879648" },
+	{ "ChromeOS ChromeOS kernel",     "fe3a2a5d" "4f32" "41a7" "b725accc3285a309" },
+	{ "ChromeOS rootfs",              "3cb8e202" "3b7e" "47dd" "8a3c7ff2a13cfcec" },
+	{ "ChromeOS future use",          "2e0a753d" "9e48" "43b0" "8337b15192cb1b5e" },
+	{ "MidnightBSD Boot",             "85d5e45e" "237c" "11e1" "b4b3e89a8f7fc3a7" },
+	{ "MidnightBSD Data",             "85d5e45a" "237c" "11e1" "b4b3e89a8f7fc3a7" },
+	{ "MidnightBSD Swap",             "85d5e45b" "237c" "11e1" "b4b3e89a8f7fc3a7" },
+	{ "MidnightBSD UFS",              "0394ef8b" "237e" "11e1" "b4b3e89a8f7fc3a7" }, /* 60 */
+	{ "MidnightBSD Vinum VM",         "85d5e45c" "237c" "11e1" "b4b3e89a8f7fc3a7" },
+	{ "MidnightBSD ZFS",              "85d5e45d" "237c" "11e1" "b4b3e89a8f7fc3a7" },
+	{ "unknown entry",                NULL } /* Keep this as the last entry */
 };
-
-
-
Index: uspace/lib/gpt/gpt.h
===================================================================
--- uspace/lib/gpt/gpt.h	(revision f4a47e52b9d2a3642a58eb1b953d1e52d56a160a)
+++ uspace/lib/gpt/gpt.h	(revision b51cf2cfbf7533cc494e6a1795d62f5fbd481c87)
@@ -1,5 +1,5 @@
 /*
  * Copyright (c) 2009 Jiri Svoboda
- * Copyright (c) 2011, 2012, 2013 Dominik Taborsky
+ * Copyright (c) 2011-2013 Dominik Taborsky
  * All rights reserved.
  *
@@ -43,20 +43,18 @@
 	AT_UNDEFINED,
 	AT_SPECIFIC = 48
-} GPT_ATTR;
+} gpt_attr_t;
 
-/** GPT header
- * - all in little endian.
- */
+/** GPT header */
 typedef struct {
-	uint8_t  efi_signature[8];
-	uint8_t  revision[4];
+	uint8_t efi_signature[8];
+	uint8_t revision[4];
 	uint32_t header_size;
 	uint32_t header_crc32;
 	uint32_t reserved;
-	uint64_t my_lba;
+	uint64_t current_lba;
 	uint64_t alternate_lba;
 	uint64_t first_usable_lba;
 	uint64_t last_usable_lba;
-	uint8_t  disk_guid[16];
+	uint8_t disk_guid[16];
 	uint64_t entry_lba;
 	uint32_t fillries;
@@ -76,4 +74,2 @@
 
 #endif
-
-
Index: uspace/lib/gpt/libgpt.c
===================================================================
--- uspace/lib/gpt/libgpt.c	(revision f4a47e52b9d2a3642a58eb1b953d1e52d56a160a)
+++ uspace/lib/gpt/libgpt.c	(revision b51cf2cfbf7533cc494e6a1795d62f5fbd481c87)
@@ -1,4 +1,4 @@
 /*
- * Copyright (c) 2011, 2012, 2013 Dominik Taborsky
+ * Copyright (c) 2011-2013 Dominik Taborsky
  * All rights reserved.
  *
@@ -34,6 +34,6 @@
 
 /* TODO:
- * This implementation only supports fixed size partition entries. Specification
- * requires otherwise, though. Use void * array and casting to achieve that.
+ * The implementation currently supports fixed size partition entries only.
+ * The specification requires otherwise, though.
  */
 
@@ -46,14 +46,13 @@
 #include <assert.h>
 #include <byteorder.h>
-#include <checksum.h>
+#include <adt/checksum.h>
 #include <mem.h>
 #include <sys/typefmt.h>
 #include <mbr.h>
-
-
+#include <align.h>
 #include "libgpt.h"
 
 static int load_and_check_header(service_id_t, aoff64_t, size_t, gpt_header_t *);
-static gpt_partitions_t * alloc_part_array(uint32_t);
+static gpt_partitions_t *alloc_part_array(uint32_t);
 static int extend_part_array(gpt_partitions_t *);
 static int reduce_part_array(gpt_partitions_t *);
@@ -62,6 +61,6 @@
 static bool check_encaps(gpt_part_t *, uint64_t, uint64_t);
 
-/** Allocate memory for gpt label */
-gpt_label_t * gpt_alloc_label(void)
+/** Allocate a GPT label */
+gpt_label_t *gpt_alloc_label(void)
 {
 	gpt_label_t *label = malloc(sizeof(gpt_label_t));
@@ -69,7 +68,6 @@
 		return NULL;
 	
-	/* This is necessary so that gpt_part_foreach does not segfault */
 	label->parts = gpt_alloc_partitions();
-	if (label == NULL) {
+	if (label->parts == NULL) {
 		free(label);
 		return NULL;
@@ -77,5 +75,4 @@
 	
 	label->gpt = NULL;
-	
 	label->device = 0;
 	
@@ -83,5 +80,5 @@
 }
 
-/** Free gpt_label_t structure */
+/** Free a GPT label */
 void gpt_free_label(gpt_label_t *label)
 {
@@ -95,6 +92,6 @@
 }
 
-/** Allocate memory for gpt header */
-gpt_t * gpt_alloc_header(size_t size)
+/** Allocate a GPT header */
+gpt_t *gpt_alloc_header(size_t size)
 {
 	gpt_t *gpt = malloc(sizeof(gpt_t));
@@ -102,9 +99,9 @@
 		return NULL;
 	
-	/* 
-	 * We might need only sizeof(gpt_header_t), but we should follow 
+	/*
+	 * We might need only sizeof(gpt_header_t), but we should follow
 	 * specs and have zeroes through all the rest of the block
 	 */
-	size_t final_size = size > sizeof(gpt_header_t) ? size : sizeof(gpt_header_t);
+	size_t final_size = max(size, sizeof(gpt_header_t));
 	gpt->header = malloc(final_size);
 	if (gpt->header == NULL) {
@@ -113,5 +110,4 @@
 	}
 	
-	/* Enter some sane defaults. */
 	memset(gpt->header, 0, final_size);
 	memcpy(gpt->header->efi_signature, efi_signature, 8);
@@ -121,9 +117,8 @@
 	gpt->header->entry_size = host2uint32_t_le(sizeof(gpt_entry_t));
 	
-	
 	return gpt;
 }
 
-/** free() GPT header including gpt->header_lba */
+/** Free a GPT header */
 void gpt_free_gpt(gpt_t *gpt)
 {
@@ -132,148 +127,142 @@
 }
 
-/** Read GPT from specific device
- * @param label        label structure to fill
- * @param dev_handle   device to read GPT from
- *
- * @return             EOK on success, errorcode on error
+/** Read GPT from a device
+ *
+ * @param label      Label to read.
+ * @param dev_handle Device to read GPT from.
+ *
+ * @return EOK on success, error code on error.
+ *
  */
 int gpt_read_header(gpt_label_t *label, service_id_t dev_handle)
 {
-	int rc;
-	size_t b_size;
-	
-	rc = block_init(EXCHANGE_ATOMIC, dev_handle, 512);
-	if (rc != EOK)
-		goto fail;
-	
-	rc = block_get_bsize(dev_handle, &b_size);
-	if (rc != EOK)
-		goto fini_fail;
+	int rc = block_init(EXCHANGE_ATOMIC, dev_handle, 512);
+	if (rc != EOK)
+		return rc;
+	
+	size_t block_size;
+	rc = block_get_bsize(dev_handle, &block_size);
+	if (rc != EOK)
+		goto end;
 	
 	if (label->gpt == NULL) {
-		label->gpt = gpt_alloc_header(b_size);
+		label->gpt = gpt_alloc_header(block_size);
 		if (label->gpt == NULL) {
 			rc = ENOMEM;
-			goto fini_fail;
+			goto end;
 		}
 	}
 	
-	rc = load_and_check_header(dev_handle, GPT_HDR_BA, b_size, label->gpt->header);
-	if (rc == EBADCHECKSUM || rc == EINVAL) {
-		aoff64_t n_blocks;
-		rc = block_get_nblocks(dev_handle, &n_blocks);
-		if (rc != EOK)
-			goto free_fail;
-
-		rc = load_and_check_header(dev_handle, n_blocks - 1, b_size, label->gpt->header);
-		if (rc == EBADCHECKSUM || rc == EINVAL)
-			goto free_fail;
+	rc = load_and_check_header(dev_handle, GPT_HDR_BA, block_size,
+	    label->gpt->header);
+	if ((rc == EBADCHECKSUM) || (rc == EINVAL)) {
+		aoff64_t blocks;
+		rc = block_get_nblocks(dev_handle, &blocks);
+		if (rc != EOK) {
+			gpt_free_gpt(label->gpt);
+			goto end;
+		}
+		
+		rc = load_and_check_header(dev_handle, blocks - 1, block_size,
+		    label->gpt->header);
+		if ((rc == EBADCHECKSUM) || (rc == EINVAL)) {
+			gpt_free_gpt(label->gpt);
+			goto end;
+		}
 	}
 	
 	label->device = dev_handle;
+	rc = EOK;
+	
+end:
 	block_fini(dev_handle);
-	return EOK;
-	
-free_fail:
-	gpt_free_gpt(label->gpt);
-	label->gpt = NULL;
-fini_fail:
-	block_fini(dev_handle);
-fail:
 	return rc;
 }
 
 /** Write GPT header to device
- * @param label        GPT label header to be written
- * @param dev_handle   device handle to write the data to
- *
- * @return             EOK on success, libblock error code otherwise
- *
- * Note: Firstly write partitions (if modified), then gpt header.
+ *
+ * @param label        Label to be written.
+ * @param dev_handle   Device to write the GPT to.
+ *
+ * @return EOK on success, libblock error code otherwise.
+ *
  */
 int gpt_write_header(gpt_label_t *label, service_id_t dev_handle)
 {
-	int rc;
-	size_t b_size;
-	
 	/* The comm_size argument (the last one) is ignored */
-	rc = block_init(EXCHANGE_ATOMIC, dev_handle, 4096);
-	if (rc != EOK && rc != EEXIST)
+	int rc = block_init(EXCHANGE_ATOMIC, dev_handle, 4096);
+	if ((rc != EOK) && (rc != EEXIST))
 		return rc;
 	
-	rc = block_get_bsize(dev_handle, &b_size);
-	if (rc != EOK)
-		return rc;
-	
-	aoff64_t n_blocks;
-	rc = block_get_nblocks(dev_handle, &n_blocks);
-	if (rc != EOK) {
-		block_fini(dev_handle);
-		return rc;
-	}
-	
-	uint64_t tmp;
+	size_t block_size;
+	rc = block_get_bsize(dev_handle, &block_size);
+	if (rc != EOK)
+		goto end;
+	
+	aoff64_t blocks;
+	rc = block_get_nblocks(dev_handle, &blocks);
+	if (rc != EOK)
+		goto end;
 	
 	gpt_set_random_uuid(label->gpt->header->disk_guid);
 	
 	/* Prepare the backup header */
-	label->gpt->header->alternate_lba = label->gpt->header->my_lba;
-	label->gpt->header->my_lba = host2uint64_t_le(n_blocks - 1);
-	
-	tmp = label->gpt->header->entry_lba;
-	label->gpt->header->entry_lba = host2uint64_t_le(n_blocks - 
-	    (uint32_t_le2host(label->gpt->header->fillries) * sizeof(gpt_entry_t)) 
-	    / b_size - 1);
+	label->gpt->header->alternate_lba = label->gpt->header->current_lba;
+	label->gpt->header->current_lba = host2uint64_t_le(blocks - 1);
+	
+	uint64_t lba = label->gpt->header->entry_lba;
+	label->gpt->header->entry_lba = host2uint64_t_le(blocks -
+	    (uint32_t_le2host(label->gpt->header->fillries) *
+	    sizeof(gpt_entry_t)) / block_size - 1);
 	
 	label->gpt->header->header_crc32 = 0;
-	label->gpt->header->header_crc32 = host2uint32_t_le( 
-	    compute_crc32((uint8_t *) label->gpt->header,
-	        uint32_t_le2host(label->gpt->header->header_size)));
+	label->gpt->header->header_crc32 =
+	    host2uint32_t_le(compute_crc32((uint8_t *) label->gpt->header,
+	    uint32_t_le2host(label->gpt->header->header_size)));
 	
 	/* Write to backup GPT header location */
-	rc = block_write_direct(dev_handle, n_blocks - 1, GPT_HDR_BS, label->gpt->header);
-	if (rc != EOK) {
-		block_fini(dev_handle);
-		return rc;
-	}
-	
+	rc = block_write_direct(dev_handle, blocks - 1, GPT_HDR_BS,
+	    label->gpt->header);
+	if (rc != EOK)
+		goto end;
 	
 	/* Prepare the main header */
-	label->gpt->header->entry_lba = tmp;
-	
-	tmp = label->gpt->header->alternate_lba;
-	label->gpt->header->alternate_lba = label->gpt->header->my_lba;
-	label->gpt->header->my_lba = tmp;
+	label->gpt->header->entry_lba = lba;
+	
+	lba = label->gpt->header->alternate_lba;
+	label->gpt->header->alternate_lba = label->gpt->header->current_lba;
+	label->gpt->header->current_lba = lba;
 	
 	label->gpt->header->header_crc32 = 0;
-	label->gpt->header->header_crc32 = host2uint32_t_le( 
-	    compute_crc32((uint8_t *) label->gpt->header,
-	        uint32_t_le2host(label->gpt->header->header_size)));
+	label->gpt->header->header_crc32 =
+	    host2uint32_t_le(compute_crc32((uint8_t *) label->gpt->header,
+	    uint32_t_le2host(label->gpt->header->header_size)));
 	
 	/* Write to main GPT header location */
-	rc = block_write_direct(dev_handle, GPT_HDR_BA, GPT_HDR_BS, label->gpt->header);
-	if (rc != EOK)
-		return rc;
+	rc = block_write_direct(dev_handle, GPT_HDR_BA, GPT_HDR_BS,
+	    label->gpt->header);
+	if (rc != EOK)
+		goto end;
 	
 	/* Write Protective MBR */
 	br_block_t mbr;
 	memset(&mbr, 0, 512);
+	
 	memset(mbr.pte[0].first_chs, 1, 3);
 	mbr.pte[0].ptype = 0xEE;
-	memset(mbr.pte[0].last_chs, 0xFF, 3);
+	memset(mbr.pte[0].last_chs, 0xff, 3);
 	mbr.pte[0].first_lba = host2uint32_t_le(1);
-	mbr.pte[0].length = 0xFFFFFFFF;
+	mbr.pte[0].length = 0xffffffff;
 	mbr.signature = host2uint16_t_le(BR_SIGNATURE);
 	
 	rc = block_write_direct(dev_handle, 0, 1, &mbr);
+	
+end:
 	block_fini(dev_handle);
-	if (rc != EOK)
-		return rc;
-	
-	return 0;
+	return rc;
 }
 
 /** Alloc partition array */
-gpt_partitions_t * gpt_alloc_partitions()
+gpt_partitions_t *gpt_alloc_partitions(void)
 {
 	return alloc_part_array(GPT_MIN_PART_NUM);
@@ -281,12 +270,12 @@
 
 /** Parse partitions from GPT
- * @param label   GPT label to be parsed
- *
- * @return        EOK on success, errorcode otherwise
+ *
+ * @param label GPT label to be parsed.
+ *
+ * @return EOK on success, error code otherwise.
+ *
  */
 int gpt_read_partitions(gpt_label_t *label)
 {
-	int rc;
-	unsigned int i;
 	uint32_t fillries = uint32_t_le2host(label->gpt->header->fillries);
 	uint32_t ent_size = uint32_t_le2host(label->gpt->header->entry_size);
@@ -295,105 +284,103 @@
 	if (label->parts == NULL) {
 		label->parts = alloc_part_array(fillries);
-		if (label->parts == NULL) {
+		if (label->parts == NULL)
 			return ENOMEM;
-		}
-	}
-
-	/* comm_size is ignored */
-	rc = block_init(EXCHANGE_SERIALIZE, label->device, sizeof(gpt_entry_t));
-	if (rc != EOK)
-		goto fail;
-
+	}
+	
+	int rc = block_init(EXCHANGE_SERIALIZE, label->device,
+	    sizeof(gpt_entry_t));
+	if (rc != EOK) {
+		gpt_free_partitions(label->parts);
+		label->parts = NULL;
+		goto end;
+	}
+	
 	size_t block_size;
 	rc = block_get_bsize(label->device, &block_size);
-	if (rc != EOK)
-		goto fini_fail;
-
+	if (rc != EOK) {
+		gpt_free_partitions(label->parts);
+		label->parts = NULL;
+		goto end;
+	}
+	
 	aoff64_t pos = ent_lba * block_size;
-
-	/* 
-	 * Now we read just sizeof(gpt_entry_t) bytes for each entry from the device.
-	 * Hopefully, this does not bypass cache (no mention in libblock.c),
-	 * and also allows us to have variable partition entry size (but we
-	 * will always read just sizeof(gpt_entry_t) bytes - hopefully they
-	 * don't break backward compatibility) 
-	 */
-	for (i = 0; i < fillries; ++i) {
-		/*FIXME: this does bypass cache... */
-		rc = block_read_bytes_direct(label->device, pos, sizeof(gpt_entry_t), label->parts->part_array + i);
-		/* 
-		 * FIXME: but seqread() is just too complex...
-		 * rc = block_seqread(gpt->device, &bufpos, &buflen, &pos, res->part_array[i], sizeof(gpt_entry_t));
-		 */
+	
+	for (uint32_t i = 0; i < fillries; i++) {
+		rc = block_read_bytes_direct(label->device, pos, sizeof(gpt_entry_t),
+		    label->parts->part_array + i);
 		pos += ent_size;
-
-		if (rc != EOK)
-			goto fini_fail;
-	}
-	
-	uint32_t crc = compute_crc32((uint8_t *) label->parts->part_array, 
-	                   fillries * ent_size);
-
-	if (uint32_t_le2host(label->gpt->header->pe_array_crc32) != crc)
-	{
+		
+		if (rc != EOK) {
+			gpt_free_partitions(label->parts);
+			label->parts = NULL;
+			goto end;
+		}
+	}
+	
+	uint32_t crc = compute_crc32((uint8_t *) label->parts->part_array,
+	    fillries * ent_size);
+	
+	if (uint32_t_le2host(label->gpt->header->pe_array_crc32) != crc) {
 		rc = EBADCHECKSUM;
-		goto fini_fail;
-	}
-	
+		gpt_free_partitions(label->parts);
+		label->parts = NULL;
+		goto end;
+	}
+	
+	rc = EOK;
+	
+end:
 	block_fini(label->device);
-	return EOK;
-	
-fini_fail:
-	block_fini(label->device);
-	
-fail:
-	gpt_free_partitions(label->parts);
-	label->parts = NULL;
 	return rc;
 }
 
 /** Write GPT and partitions to device
- * Note: also writes the header.
- * @param label        label to write
- * @param dev_handle   device to write the data to
- *
- * @return             returns EOK on succes, errorcode otherwise
+ *
+ * Note: Also writes the header.
+ *
+ * @param label      Label to write.
+ * @param dev_handle Device to write the data to.
+ *
+ * @return EOK on succes, error code otherwise
+ *
  */
 int gpt_write_partitions(gpt_label_t *label, service_id_t dev_handle)
 {
-	int rc;
-	size_t b_size;
-	
 	/* comm_size of 4096 is ignored */
-	rc = block_init(EXCHANGE_ATOMIC, dev_handle, 4096);
-	if (rc != EOK && rc != EEXIST)
+	int rc = block_init(EXCHANGE_ATOMIC, dev_handle, 4096);
+	if ((rc != EOK) && (rc != EEXIST))
 		return rc;
 	
-	rc = block_get_bsize(dev_handle, &b_size);
+	size_t block_size;
+	rc = block_get_bsize(dev_handle, &block_size);
 	if (rc != EOK)
 		goto fail;
 	
-	aoff64_t n_blocks;
-	rc = block_get_nblocks(dev_handle, &n_blocks);
+	aoff64_t blocks;
+	rc = block_get_nblocks(dev_handle, &blocks);
 	if (rc != EOK)
 		goto fail;
 	
-	/* When we're creating a new label from scratch, we need to fill 
-	 * the header with sensible defaults. */
-	if (label->gpt == NULL) {
-		label->gpt = gpt_alloc_header(b_size);
-	}
-	
-	uint32_t e_size = uint32_t_le2host(label->gpt->header->entry_size);
-	size_t fillries = label->parts->fill > GPT_MIN_PART_NUM ? label->parts->fill : GPT_MIN_PART_NUM;
-	
-	if (e_size != sizeof(gpt_entry_t))
+	if (label->gpt == NULL)
+		label->gpt = gpt_alloc_header(block_size);
+	
+	uint32_t entry_size =
+	    uint32_t_le2host(label->gpt->header->entry_size);
+	size_t fillries = (label->parts->fill > GPT_MIN_PART_NUM) ?
+	    label->parts->fill : GPT_MIN_PART_NUM;
+	
+	if (entry_size != sizeof(gpt_entry_t))
 		return ENOTSUP;
-
+	
 	label->gpt->header->fillries = host2uint32_t_le(fillries);
-	uint64_t arr_blocks = (fillries * sizeof(gpt_entry_t)) / b_size;
-	uint64_t gpt_space = arr_blocks + GPT_HDR_BS + 1; /* +1 for Protective MBR */
+	
+	uint64_t arr_blocks = (fillries * sizeof(gpt_entry_t)) / block_size;
+	
+	/* Include Protective MBR */
+	uint64_t gpt_space = arr_blocks + GPT_HDR_BS + 1;
+	
 	label->gpt->header->first_usable_lba = host2uint64_t_le(gpt_space);
-	label->gpt->header->last_usable_lba = host2uint64_t_le(n_blocks - gpt_space - 1);
+	label->gpt->header->last_usable_lba =
+	    host2uint64_t_le(blocks - gpt_space - 1);
 	
 	/* Perform checks */
@@ -402,5 +389,5 @@
 			continue;
 		
-		if (!check_encaps(p, n_blocks, gpt_space)) {
+		if (!check_encaps(p, blocks, gpt_space)) {
 			rc = ERANGE;
 			goto fail;
@@ -420,18 +407,18 @@
 	}
 	
-	label->gpt->header->pe_array_crc32 = host2uint32_t_le(compute_crc32(
-	                               (uint8_t *) label->parts->part_array,
-	                               fillries * e_size));
-	
+	label->gpt->header->pe_array_crc32 =
+	    host2uint32_t_le(compute_crc32((uint8_t *) label->parts->part_array,
+	    fillries * entry_size));
 	
 	/* Write to backup GPT partition array location */
-	rc = block_write_direct(dev_handle, n_blocks - arr_blocks - 1, 
-	         arr_blocks, label->parts->part_array);
+	rc = block_write_direct(dev_handle, blocks - arr_blocks - 1,
+	    arr_blocks, label->parts->part_array);
 	if (rc != EOK)
 		goto fail;
 	
 	/* Write to main GPT partition array location */
-	rc = block_write_direct(dev_handle, uint64_t_le2host(label->gpt->header->entry_lba),
-	         arr_blocks, label->parts->part_array);
+	rc = block_write_direct(dev_handle,
+	    uint64_t_le2host(label->gpt->header->entry_lba),
+	    arr_blocks, label->parts->part_array);
 	if (rc != EOK)
 		goto fail;
@@ -444,39 +431,40 @@
 }
 
-/** Alloc new partition
- *
- * @return        returns pointer to the new partition or NULL
- *
- * Note: use either gpt_alloc_partition or gpt_get_partition.
+/** Allocate a new partition
+ *
+ * Note: Use either gpt_alloc_partition() or gpt_get_partition().
  * This returns a memory block (zero-filled) and needs gpt_add_partition()
  * to be called to insert it into a partition array.
  * Requires you to call gpt_free_partition afterwards.
- */
-gpt_part_t * gpt_alloc_partition(void)
-{
-	gpt_part_t *p = malloc(sizeof(gpt_part_t));
-	if (p == NULL)
+ *
+ * @return Pointer to the new partition or NULL.
+ *
+ */
+gpt_part_t *gpt_alloc_partition(void)
+{
+	gpt_part_t *partition = malloc(sizeof(gpt_part_t));
+	if (partition == NULL)
 		return NULL;
 	
-	memset(p, 0, sizeof(gpt_part_t));
-	
-	return p;
-}
-
-/** Alloc new partition already inside the label
- *
- * @param label   label to carry new partition
- *
- * @return        returns pointer to the new partition or NULL on ENOMEM
- *
- * Note: use either gpt_alloc_partition or gpt_get_partition.
+	memset(partition, 0, sizeof(gpt_part_t));
+	
+	return partition;
+}
+
+/** Allocate a new partition already inside the label
+ *
+ * Note: Use either gpt_alloc_partition() or gpt_get_partition().
  * This one returns a pointer to the first empty structure already
  * inside the array, so don't call gpt_add_partition() afterwards.
  * This is the one you will usually want.
- */
-gpt_part_t * gpt_get_partition(gpt_label_t *label)
-{
-	gpt_part_t *p;
-	
+ *
+ * @param label Label to carry new partition.
+ *
+ * @return Pointer to the new partition or NULL.
+ *
+ */
+gpt_part_t *gpt_get_partition(gpt_label_t *label)
+{
+	gpt_part_t *partition;
 	
 	/* Find the first empty entry */
@@ -487,21 +475,14 @@
 		}
 		
-		p = label->parts->part_array + label->parts->fill++;
-		
-	} while (gpt_get_part_type(p) != GPT_PTE_UNUSED);
-	
-	return p;
+		partition = label->parts->part_array + label->parts->fill++;
+	} while (gpt_get_part_type(partition) != GPT_PTE_UNUSED);
+	
+	return partition;
 }
 
 /** Get partition already inside the label
  *
- * @param label   label to carrying the partition
- * @param idx     index of the partition
- *
- * @return        returns pointer to the partition
- *                or NULL when out of range
- *
- * Note: For new partitions use either gpt_alloc_partition or
- * gpt_get_partition unless you want a partition at a specific place.
+ * Note: For new partitions use either gpt_alloc_partition() or
+ * gpt_get_partition() unless you want a partition at a specific place.
  * This returns a pointer to a structure already inside the array,
  * so don't call gpt_add_partition() afterwards.
@@ -510,10 +491,14 @@
  * for indexes smaller than either 128 or the actual number of filled
  * entries.
- */
-gpt_part_t * gpt_get_partition_at(gpt_label_t *label, size_t idx)
-{
-	return NULL;
-	
-	if (idx >= GPT_MIN_PART_NUM && idx >= label->parts->fill)
+ *
+ * @param label Label to carrying the partition.
+ * @param idx   Index of the partition.
+ *
+ * @return Pointer to the partition or NULL when out of range.
+ *
+ */
+gpt_part_t *gpt_get_partition_at(gpt_label_t *label, size_t idx)
+{
+	if ((idx >= GPT_MIN_PART_NUM) && (idx >= label->parts->fill))
 		return NULL;
 	
@@ -523,17 +508,20 @@
 /** Copy partition into partition array
  *
- * @param parts			target label
- * @param partition		source partition to copy
- *
- * @return 				-1 on error, 0 otherwise
- *
- * Note: for use with gpt_alloc_partition() only. You will get
+ * Note: For use with gpt_alloc_partition() only. You will get
  * duplicates with gpt_get_partition().
- * Note: does not call gpt_free_partition()!
+ * Note: Does not call gpt_free_partition()!
+ *
+ * @param parts     Target label
+ * @param partition Source partition to copy
+ *
+ * @return EOK on succes, error code otherwise
+ *
  */
 int gpt_add_partition(gpt_label_t *label, gpt_part_t *partition)
 {
-	gpt_part_t *p;
 	/* Find the first empty entry */
+	
+	gpt_part_t *part;
+	
 	do {
 		if (label->parts->fill == label->parts->arr_size) {
@@ -542,23 +530,21 @@
 		}
 		
-		p = label->parts->part_array + label->parts->fill++;
-		
-	} while (gpt_get_part_type(p) != GPT_PTE_UNUSED);
-	
-	
-	memcpy(p, partition, sizeof(gpt_entry_t));
-	
-	
+		part = label->parts->part_array + label->parts->fill++;
+	} while (gpt_get_part_type(part) != GPT_PTE_UNUSED);
+	
+	memcpy(part, partition, sizeof(gpt_entry_t));
 	return EOK;
 }
 
 /** Remove partition from array
- * @param label   label to remove from
- * @param idx     index of the partition to remove
- *
- * @return        EOK on success, ENOMEM on array reduction failure
- *
- * Note: even if it fails, the partition still gets removed. Only
+ *
+ * Note: Even if it fails, the partition still gets removed. Only
  * reducing the array failed.
+ *
+ * @param label Label to remove from
+ * @param idx   Index of the partition to remove
+ *
+ * @return EOK on success, ENOMEM on array reduction failure
+ *
  */
 int gpt_remove_partition(gpt_label_t *label, size_t idx)
@@ -567,10 +553,11 @@
 		return EINVAL;
 	
-	/* 
-	 * FIXME! 
+	/*
+	 * FIXME:
 	 * If we allow blank spots, we break the array. If we have more than
 	 * 128 partitions in the array and then remove something from
 	 * the first 128 partitions, we would forget to write the last one.
 	 */
+	
 	memset(label->parts->part_array + idx, 0, sizeof(gpt_entry_t));
 	
@@ -578,17 +565,14 @@
 		label->parts->fill = idx;
 	
-	/* 
-	 * FIXME! HOPEFULLY FIXED.
-	 * We cannot reduce the array so simply. We may have some partitions
-	 * there since we allow blank spots. 
-	 */
-	gpt_part_t * p;
-	
-	if (label->parts->fill > GPT_MIN_PART_NUM &&
-	    label->parts->fill < (label->parts->arr_size / 2) - GPT_IGNORE_FILL_NUM) {
-		for (p = gpt_get_partition_at(label, label->parts->arr_size / 2); 
-		     p < label->parts->part_array + label->parts->arr_size; ++p) {
-				if (gpt_get_part_type(p) != GPT_PTE_UNUSED)
-					return EOK;
+	gpt_part_t *partition;
+	
+	if ((label->parts->fill > GPT_MIN_PART_NUM) &&
+	    (label->parts->fill < (label->parts->arr_size / 2) -
+	    GPT_IGNORE_FILL_NUM)) {
+		for (partition = gpt_get_partition_at(label, label->parts->arr_size / 2);
+		     partition < label->parts->part_array + label->parts->arr_size;
+		     partition++) {
+			if (gpt_get_part_type(partition) != GPT_PTE_UNUSED)
+				return EOK;
 		}
 		
@@ -596,5 +580,5 @@
 			return ENOMEM;
 	}
-
+	
 	return EOK;
 }
@@ -602,7 +586,8 @@
 /** Free partition list
  *
- * @param parts		partition list to be freed
- */
-void gpt_free_partitions(gpt_partitions_t * parts)
+ * @param parts Partition list to be freed
+ *
+ */
+void gpt_free_partitions(gpt_partitions_t *parts)
 {
 	free(parts->part_array);
@@ -610,32 +595,27 @@
 }
 
-/** Get partition type by linear search
- * (hopefully this doesn't get slow)
- */
-size_t gpt_get_part_type(gpt_part_t * p)
+/** Get partition type */
+size_t gpt_get_part_type(gpt_part_t *partition)
 {
 	size_t i;
 	
 	for (i = 0; gpt_ptypes[i].guid != NULL; i++) {
-		if (p->part_type[3] == get_byte(gpt_ptypes[i].guid +0) &&
-			p->part_type[2] == get_byte(gpt_ptypes[i].guid +2) &&
-			p->part_type[1] == get_byte(gpt_ptypes[i].guid +4) &&
-			p->part_type[0] == get_byte(gpt_ptypes[i].guid +6) &&
-			
-			p->part_type[5] == get_byte(gpt_ptypes[i].guid +8) &&
-			p->part_type[4] == get_byte(gpt_ptypes[i].guid +10) &&
-			
-			p->part_type[7] == get_byte(gpt_ptypes[i].guid +12) &&
-			p->part_type[6] == get_byte(gpt_ptypes[i].guid +14) &&
-			
-			p->part_type[8] == get_byte(gpt_ptypes[i].guid +16) &&
-			p->part_type[9] == get_byte(gpt_ptypes[i].guid +18) &&
-			p->part_type[10] == get_byte(gpt_ptypes[i].guid +20) &&
-			p->part_type[11] == get_byte(gpt_ptypes[i].guid +22) &&
-			p->part_type[12] == get_byte(gpt_ptypes[i].guid +24) &&
-			p->part_type[13] == get_byte(gpt_ptypes[i].guid +26) &&
-			p->part_type[14] == get_byte(gpt_ptypes[i].guid +28) &&
-			p->part_type[15] == get_byte(gpt_ptypes[i].guid +30))
-				break;
+		if ((partition->part_type[3] == get_byte(gpt_ptypes[i].guid + 0)) &&
+		    (partition->part_type[2] == get_byte(gpt_ptypes[i].guid + 2)) &&
+		    (partition->part_type[1] == get_byte(gpt_ptypes[i].guid + 4)) &&
+		    (partition->part_type[0] == get_byte(gpt_ptypes[i].guid + 6)) &&
+		    (partition->part_type[5] == get_byte(gpt_ptypes[i].guid + 8)) &&
+		    (partition->part_type[4] == get_byte(gpt_ptypes[i].guid + 10)) &&
+		    (partition->part_type[7] == get_byte(gpt_ptypes[i].guid + 12)) &&
+		    (partition->part_type[6] == get_byte(gpt_ptypes[i].guid + 14)) &&
+		    (partition->part_type[8] == get_byte(gpt_ptypes[i].guid + 16)) &&
+		    (partition->part_type[9] == get_byte(gpt_ptypes[i].guid + 18)) &&
+		    (partition->part_type[10] == get_byte(gpt_ptypes[i].guid + 20)) &&
+		    (partition->part_type[11] == get_byte(gpt_ptypes[i].guid + 22)) &&
+		    (partition->part_type[12] == get_byte(gpt_ptypes[i].guid + 24)) &&
+		    (partition->part_type[13] == get_byte(gpt_ptypes[i].guid + 26)) &&
+		    (partition->part_type[14] == get_byte(gpt_ptypes[i].guid + 28)) &&
+		    (partition->part_type[15] == get_byte(gpt_ptypes[i].guid + 30)))
+			return i;
 	}
 	
@@ -643,103 +623,99 @@
 }
 
-/** Set partition type
- * @param p			partition to be set
- * @param type		partition type to set
- * 					- see our fine selection at gpt_ptypes to choose from
- */
-void gpt_set_part_type(gpt_part_t * p, size_t type)
+/** Set partition type */
+void gpt_set_part_type(gpt_part_t *partition, size_t type)
 {
 	/* Beware: first 3 blocks are byteswapped! */
-	p->part_type[3] = get_byte(gpt_ptypes[type].guid +0);
-	p->part_type[2] = get_byte(gpt_ptypes[type].guid +2);
-	p->part_type[1] = get_byte(gpt_ptypes[type].guid +4);
-	p->part_type[0] = get_byte(gpt_ptypes[type].guid +6);
-	                
-	p->part_type[5] = get_byte(gpt_ptypes[type].guid +8);
-	p->part_type[4] = get_byte(gpt_ptypes[type].guid +10);
-	                
-	p->part_type[7] = get_byte(gpt_ptypes[type].guid +12);
-	p->part_type[6] = get_byte(gpt_ptypes[type].guid +14);
-	                
-	p->part_type[8] = get_byte(gpt_ptypes[type].guid +16);
-	p->part_type[9] = get_byte(gpt_ptypes[type].guid +18);
-	p->part_type[10] = get_byte(gpt_ptypes[type].guid +20);
-	p->part_type[11] = get_byte(gpt_ptypes[type].guid +22);
-	p->part_type[12] = get_byte(gpt_ptypes[type].guid +24);
-	p->part_type[13] = get_byte(gpt_ptypes[type].guid +26);
-	p->part_type[14] = get_byte(gpt_ptypes[type].guid +28);
-	p->part_type[15] = get_byte(gpt_ptypes[type].guid +30);
+	partition->part_type[3] = get_byte(gpt_ptypes[type].guid + 0);
+	partition->part_type[2] = get_byte(gpt_ptypes[type].guid + 2);
+	partition->part_type[1] = get_byte(gpt_ptypes[type].guid + 4);
+	partition->part_type[0] = get_byte(gpt_ptypes[type].guid + 6);
+	
+	partition->part_type[5] = get_byte(gpt_ptypes[type].guid + 8);
+	partition->part_type[4] = get_byte(gpt_ptypes[type].guid + 10);
+	
+	partition->part_type[7] = get_byte(gpt_ptypes[type].guid + 12);
+	partition->part_type[6] = get_byte(gpt_ptypes[type].guid + 14);
+	
+	partition->part_type[8] = get_byte(gpt_ptypes[type].guid + 16);
+	partition->part_type[9] = get_byte(gpt_ptypes[type].guid + 18);
+	partition->part_type[10] = get_byte(gpt_ptypes[type].guid + 20);
+	partition->part_type[11] = get_byte(gpt_ptypes[type].guid + 22);
+	partition->part_type[12] = get_byte(gpt_ptypes[type].guid + 24);
+	partition->part_type[13] = get_byte(gpt_ptypes[type].guid + 26);
+	partition->part_type[14] = get_byte(gpt_ptypes[type].guid + 28);
+	partition->part_type[15] = get_byte(gpt_ptypes[type].guid + 30);
 }
 
 /** Get partition starting LBA */
-uint64_t gpt_get_start_lba(gpt_part_t * p)
-{
-	return uint64_t_le2host(p->start_lba);
+uint64_t gpt_get_start_lba(gpt_part_t *partition)
+{
+	return uint64_t_le2host(partition->start_lba);
 }
 
 /** Set partition starting LBA */
-void gpt_set_start_lba(gpt_part_t * p, uint64_t start)
-{
-	p->start_lba = host2uint64_t_le(start);
+void gpt_set_start_lba(gpt_part_t *partition, uint64_t start)
+{
+	partition->start_lba = host2uint64_t_le(start);
 }
 
 /** Get partition ending LBA */
-uint64_t gpt_get_end_lba(gpt_part_t * p)
-{
-	return uint64_t_le2host(p->end_lba);
+uint64_t gpt_get_end_lba(gpt_part_t *partition)
+{
+	return uint64_t_le2host(partition->end_lba);
 }
 
 /** Set partition ending LBA */
-void gpt_set_end_lba(gpt_part_t * p, uint64_t end)
-{
-	p->end_lba = host2uint64_t_le(end);
+void gpt_set_end_lba(gpt_part_t *partition, uint64_t end)
+{
+	partition->end_lba = host2uint64_t_le(end);
 }
 
 /** Get partition name */
-unsigned char * gpt_get_part_name(gpt_part_t * p)
-{
-	return p->part_name;
+unsigned char * gpt_get_part_name(gpt_part_t *partition)
+{
+	return partition->part_name;
 }
 
 /** Copy partition name */
-void gpt_set_part_name(gpt_part_t *p, char *name, size_t length)
+void gpt_set_part_name(gpt_part_t *partition, char *name, size_t length)
 {
 	if (length >= 72)
 		length = 71;
-
-	memcpy(p->part_name, name, length);
-	p->part_name[length] = '\0';
+	
+	memcpy(partition->part_name, name, length);
+	partition->part_name[length] = '\0';
 }
 
 /** Get partition attribute */
-bool gpt_get_flag(gpt_part_t * p, GPT_ATTR flag)
-{
-	return (p->attributes & (((uint64_t) 1) << flag)) ? 1 : 0;
+bool gpt_get_flag(gpt_part_t *partition, gpt_attr_t flag)
+{
+	return (partition->attributes & (((uint64_t) 1) << flag)) ? 1 : 0;
 }
 
 /** Set partition attribute */
-void gpt_set_flag(gpt_part_t * p, GPT_ATTR flag, bool value)
-{
-	uint64_t attr = p->attributes;
-
+void gpt_set_flag(gpt_part_t *partition, gpt_attr_t flag, bool value)
+{
+	uint64_t attr = partition->attributes;
+	
 	if (value)
 		attr = attr | (((uint64_t) 1) << flag);
 	else
 		attr = attr ^ (attr & (((uint64_t) 1) << flag));
-
-	p->attributes = attr;
+	
+	partition->attributes = attr;
 }
 
 /** Generate a new pseudo-random UUID
- * @param uuid Pointer to the UUID to overwrite.
- */
-void gpt_set_random_uuid(uint8_t * uuid)
+ *
+ * FIXME: This UUID generator is not compliant with RFC 4122.
+ *
+ */
+void gpt_set_random_uuid(uint8_t *uuid)
 {
 	srandom((unsigned int) (size_t) uuid);
 	
-	unsigned int i;
-	for (i = 0; i < 16/sizeof(long int); ++i)
-		((long int *)uuid)[i] = random();
-	
+	for (size_t i = 0; i < 16; i++)
+		uuid[i] = random();
 }
 
@@ -747,49 +723,43 @@
 uint64_t gpt_get_next_aligned(uint64_t addr, unsigned int alignment)
 {
-	uint64_t div = addr / alignment;
-	return (div + 1) * alignment;
-}
-
-/* Internal functions follow */
-
-static int load_and_check_header(service_id_t dev_handle, aoff64_t addr, size_t b_size, gpt_header_t * header)
-{
-	int rc;
-
-	rc = block_read_direct(dev_handle, addr, GPT_HDR_BS, header);
+	return ALIGN_UP(addr + 1, alignment);
+}
+
+static int load_and_check_header(service_id_t dev_handle, aoff64_t addr,
+    size_t block_size, gpt_header_t *header)
+{
+	int rc = block_read_direct(dev_handle, addr, GPT_HDR_BS, header);
 	if (rc != EOK)
 		return rc;
-
-	unsigned int i;
+	
 	/* Check the EFI signature */
-	for (i = 0; i < 8; ++i) {
+	for (unsigned int i = 0; i < 8; i++) {
 		if (header->efi_signature[i] != efi_signature[i])
 			return EINVAL;
 	}
-
+	
 	/* Check the CRC32 of the header */
 	uint32_t crc = header->header_crc32;
 	header->header_crc32 = 0;
+	
 	if (crc != compute_crc32((uint8_t *) header, header->header_size))
 		return EBADCHECKSUM;
 	else
 		header->header_crc32 = crc;
-
+	
 	/* Check for zeroes in the rest of the block */
-	for (i = sizeof(gpt_header_t); i < b_size; ++i) {
+	for (size_t i = sizeof(gpt_header_t); i < block_size; i++) {
 		if (((uint8_t *) header)[i] != 0)
 			return EINVAL;
 	}
-
+	
 	return EOK;
 }
 
-static gpt_partitions_t * alloc_part_array(uint32_t num)
-{
-	gpt_partitions_t * res = malloc(sizeof(gpt_partitions_t));
-	if (res == NULL) {
-		errno = ENOMEM;
+static gpt_partitions_t *alloc_part_array(uint32_t num)
+{
+	gpt_partitions_t *res = malloc(sizeof(gpt_partitions_t));
+	if (res == NULL)
 		return NULL;
-	}
 	
 	uint32_t size = num > GPT_BASE_PART_NUM ? num : GPT_BASE_PART_NUM;
@@ -797,5 +767,4 @@
 	if (res->part_array == NULL) {
 		free(res);
-		errno = ENOMEM;
 		return NULL;
 	}
@@ -805,73 +774,78 @@
 	res->fill = 0;
 	res->arr_size = num;
-
+	
 	return res;
 }
 
-static int extend_part_array(gpt_partitions_t * p)
-{
-	size_t nsize = p->arr_size * 2;
-	gpt_entry_t * tmp = malloc(nsize * sizeof(gpt_entry_t));
-	if (tmp == NULL) {
-		errno = ENOMEM;
-		return -1;
-	}
-	
-	memcpy(tmp, p->part_array, p->fill * sizeof(gpt_entry_t));
-	free(p->part_array);
-	p->part_array = tmp;
-	p->arr_size = nsize;
-
-	return 0;
-}
-
-static int reduce_part_array(gpt_partitions_t * p)
-{
-	if (p->arr_size > GPT_MIN_PART_NUM) {
-		unsigned int nsize = p->arr_size / 2;
+static int extend_part_array(gpt_partitions_t *partition)
+{
+	size_t nsize = partition->arr_size * 2;
+	gpt_entry_t *entry = malloc(nsize * sizeof(gpt_entry_t));
+	if (entry == NULL)
+		return ENOMEM;
+	
+	memcpy(entry, partition->part_array, partition->fill *
+	    sizeof(gpt_entry_t));
+	free(partition->part_array);
+	
+	partition->part_array = entry;
+	partition->arr_size = nsize;
+	
+	return EOK;
+}
+
+static int reduce_part_array(gpt_partitions_t *partition)
+{
+	if (partition->arr_size > GPT_MIN_PART_NUM) {
+		unsigned int nsize = partition->arr_size / 2;
 		nsize = nsize > GPT_MIN_PART_NUM ? nsize : GPT_MIN_PART_NUM;
-		gpt_entry_t * tmp = malloc(nsize * sizeof(gpt_entry_t));
-		if (tmp == NULL)
+		
+		gpt_entry_t *entry = malloc(nsize * sizeof(gpt_entry_t));
+		if (entry == NULL)
 			return ENOMEM;
-
-		memcpy(tmp, p->part_array, p->fill < nsize ? p->fill : nsize);
-		free(p->part_array);
-		p->part_array = tmp;
-		p->arr_size = nsize;
-	}
-
-	return 0;
-}
-
-/* Parse a byte from a string in hexadecimal 
- * i.e., "FF" => 255 
- */
-static uint8_t get_byte(const char * c)
+		
+		memcpy(entry, partition->part_array,
+		    partition->fill < nsize ? partition->fill : nsize);
+		free(partition->part_array);
+		
+		partition->part_array = entry;
+		partition->arr_size = nsize;
+	}
+	
+	return EOK;
+}
+
+/* Parse a byte from a string in hexadecimal */
+static uint8_t get_byte(const char *c)
 {
 	uint8_t val = 0;
-	char hex[3] = {*c, *(c+1), 0};
-	
-	errno = str_uint8_t(hex, NULL, 16, false, &val);
+	char hex[3] = {*c, *(c + 1), 0};
+	
+	str_uint8_t(hex, NULL, 16, false, &val);
 	return val;
 }
 
-static bool check_overlap(gpt_part_t * p1, gpt_part_t * p2)
-{
-	if (gpt_get_start_lba(p1) < gpt_get_start_lba(p2) && gpt_get_end_lba(p1) < gpt_get_start_lba(p2)) {
+static bool check_overlap(gpt_part_t *part1, gpt_part_t *part2)
+{
+	if ((gpt_get_start_lba(part1) < gpt_get_start_lba(part2)) &&
+	    (gpt_get_end_lba(part1) < gpt_get_start_lba(part2)))
 		return false;
-	} else if (gpt_get_start_lba(p1) > gpt_get_start_lba(p2) && gpt_get_end_lba(p2) < gpt_get_start_lba(p1)) {
+	
+	if ((gpt_get_start_lba(part1) > gpt_get_start_lba(part2)) &&
+	    (gpt_get_end_lba(part2) < gpt_get_start_lba(part1)))
 		return false;
-	}
-
+	
 	return true;
 }
 
-static bool check_encaps(gpt_part_t *p, uint64_t n_blocks, uint64_t first_lba)
-{
-	/* 
-	 * We allow "<=" in the second expression because it lacks MBR so 
-	 * it's by 1 block smaller.
+static bool check_encaps(gpt_part_t *part, uint64_t blocks,
+    uint64_t first_lba)
+{
+	/*
+	 * We allow "<=" in the second expression because it lacks
+	 * MBR so it is smaller by 1 block.
 	 */
-	if (gpt_get_start_lba(p) >= first_lba && gpt_get_end_lba(p) <= n_blocks - first_lba)
+	if ((gpt_get_start_lba(part) >= first_lba) &&
+	    (gpt_get_end_lba(part) <= blocks - first_lba))
 		return true;
 	
Index: uspace/lib/gpt/libgpt.h
===================================================================
--- uspace/lib/gpt/libgpt.h	(revision f4a47e52b9d2a3642a58eb1b953d1e52d56a160a)
+++ uspace/lib/gpt/libgpt.h	(revision b51cf2cfbf7533cc494e6a1795d62f5fbd481c87)
@@ -1,5 +1,5 @@
 /*
  * Copyright (c) 2009 Jiri Svoboda
- * Copyright (c) 2011, 2012, 2013 Dominik Taborsky
+ * Copyright (c) 2011-2013 Dominik Taborsky
  * All rights reserved.
  *
@@ -37,24 +37,57 @@
 #define LIBGPT_LIBGPT_H_
 
-#define LIBGPT_NAME	"libgpt"
-
 #include <loc.h>
 #include <sys/types.h>
-
 #include "gpt.h"
 
 /** Block address of GPT header. */
-#define GPT_HDR_BA	1
+#define GPT_HDR_BA  1
+
 /** Block size of GPT header. */
-#define GPT_HDR_BS	1
+#define GPT_HDR_BS  1
+
 /** Minimum number of GPT partition entries */
-#define GPT_MIN_PART_NUM 128
+#define GPT_MIN_PART_NUM  128
+
 /** Basic number of GPT partition entries */
-#define GPT_BASE_PART_NUM (GPT_MIN_PART_NUM)
+#define GPT_BASE_PART_NUM  (GPT_MIN_PART_NUM)
+
 /** How much fill we ignore before resizing partition array */
-#define GPT_IGNORE_FILL_NUM 10
+#define GPT_IGNORE_FILL_NUM  10
 
 /** Unused partition entry */
-#define GPT_PTE_UNUSED 0
+#define GPT_PTE_UNUSED  0
+
+/** Raw GPT header.
+ *
+ * Uses more bytes than sizeof(gpt_header_t).
+ */
+typedef struct {
+	gpt_header_t *header;
+} gpt_t;
+
+typedef gpt_entry_t gpt_part_t;
+
+typedef struct {
+	/** Number of entries */
+	size_t fill;
+	
+	/** Size of the array */
+	size_t arr_size;
+	
+	/** Resizable partition array */
+	gpt_part_t *part_array;
+} gpt_partitions_t;
+
+typedef struct {
+	gpt_t *gpt;
+	gpt_partitions_t *parts;
+	service_id_t device;
+} gpt_label_t;
+
+typedef struct {
+	const char *desc;
+	const char *guid;
+} partition_type_t;
 
 /** GPT header signature ("EFI PART" in ASCII) */
@@ -62,69 +95,41 @@
 extern const uint8_t revision[4];
 
-typedef struct {
-	/** Raw header. Has more bytes alloced than sizeof(gpt_header_t)!
-	 * See gpt_alloc_header() to know why. */
-	gpt_header_t *header;
-} gpt_t;
+extern const partition_type_t gpt_ptypes[];
 
-typedef gpt_entry_t gpt_part_t;
-
-typedef struct gpt_parts {
-	/** Number of entries */
-	size_t fill;
-	/** Size of the array */
-	size_t arr_size;
-	/** Resizable partition array */
-	gpt_entry_t *part_array;
-} gpt_partitions_t;
-
-
-typedef struct gpt_table {
-	gpt_t *gpt;
-	gpt_partitions_t *parts;
-	service_id_t device;
-} gpt_label_t;
-
-struct partition_type {
-	const char *desc;
-	const char *guid;
-};
-
-extern const struct partition_type gpt_ptypes[];
-
-extern gpt_label_t * gpt_alloc_label(void);
+extern gpt_label_t *gpt_alloc_label(void);
 extern void gpt_free_label(gpt_label_t *);
 
-extern gpt_t * gpt_alloc_header(size_t);
-extern int     gpt_read_header(gpt_label_t *, service_id_t);
-extern int     gpt_write_header(gpt_label_t *, service_id_t);
+extern gpt_t *gpt_alloc_header(size_t);
+extern int gpt_read_header(gpt_label_t *, service_id_t);
+extern int gpt_write_header(gpt_label_t *, service_id_t);
 
-extern gpt_partitions_t * gpt_alloc_partitions(void);
-extern int             gpt_read_partitions (gpt_label_t *);
-extern int             gpt_write_partitions(gpt_label_t *, service_id_t);
-extern gpt_part_t *    gpt_alloc_partition (void);
-extern gpt_part_t *    gpt_get_partition   (gpt_label_t *);
-extern gpt_part_t *    gpt_get_partition_at(gpt_label_t *, size_t);
-extern int             gpt_add_partition   (gpt_label_t *, gpt_part_t *);
-extern int             gpt_remove_partition(gpt_label_t *, size_t);
+extern gpt_partitions_t *gpt_alloc_partitions(void);
+extern int gpt_read_partitions(gpt_label_t *);
+extern int gpt_write_partitions(gpt_label_t *, service_id_t);
+extern gpt_part_t *gpt_alloc_partition(void);
+extern gpt_part_t *gpt_get_partition(gpt_label_t *);
+extern gpt_part_t *gpt_get_partition_at(gpt_label_t *, size_t);
+extern int gpt_add_partition(gpt_label_t *, gpt_part_t *);
+extern int gpt_remove_partition(gpt_label_t *, size_t);
 
-extern size_t          gpt_get_part_type(gpt_part_t *);
-extern void            gpt_set_part_type(gpt_part_t *, size_t);
-extern void            gpt_set_start_lba(gpt_part_t *, uint64_t);
-extern uint64_t        gpt_get_start_lba(gpt_part_t *);
-extern void            gpt_set_end_lba  (gpt_part_t *, uint64_t);
-extern uint64_t        gpt_get_end_lba  (gpt_part_t *);
-extern unsigned char * gpt_get_part_name(gpt_part_t *);
-extern void            gpt_set_part_name(gpt_part_t *, char *, size_t);
-extern bool            gpt_get_flag     (gpt_part_t *, GPT_ATTR);
-extern void            gpt_set_flag     (gpt_part_t *, GPT_ATTR, bool);
+extern size_t gpt_get_part_type(gpt_part_t *);
+extern void gpt_set_part_type(gpt_part_t *, size_t);
+extern void gpt_set_start_lba(gpt_part_t *, uint64_t);
+extern uint64_t gpt_get_start_lba(gpt_part_t *);
+extern void gpt_set_end_lba(gpt_part_t *, uint64_t);
+extern uint64_t gpt_get_end_lba(gpt_part_t *);
+extern unsigned char *gpt_get_part_name(gpt_part_t *);
+extern void gpt_set_part_name(gpt_part_t *, char *, size_t);
+extern bool gpt_get_flag(gpt_part_t *, gpt_attr_t);
+extern void gpt_set_flag(gpt_part_t *, gpt_attr_t, bool);
 
-extern void            gpt_set_random_uuid(uint8_t *);
-extern uint64_t        gpt_get_next_aligned(uint64_t, unsigned int);
+extern void gpt_set_random_uuid(uint8_t *);
+extern uint64_t gpt_get_next_aligned(uint64_t, unsigned int);
 
 
 #define gpt_part_foreach(label, iterator) \
-		for(gpt_part_t * iterator = (label)->parts->part_array; \
-		    iterator < (label)->parts->part_array + (label)->parts->arr_size; ++iterator)
+	for (gpt_part_t *iterator = (label)->parts->part_array; \
+	    iterator < (label)->parts->part_array + (label)->parts->arr_size; \
+	    iterator++)
 
 extern void gpt_free_gpt(gpt_t *);
@@ -132,3 +137,2 @@
 
 #endif
-
