Index: uspace/app/hdisk/common.h
===================================================================
--- uspace/app/hdisk/common.h	(revision d51beba3dc7e6298f4b9692cbba4886d50303d39)
+++ uspace/app/hdisk/common.h	(revision 6453e30691421828634cd3f671e5840773c9ff46)
@@ -1,4 +1,4 @@
 /*
- * Copyright (c) 2012, 2013 Dominik Taborsky
+ * Copyright (c) 2012-2013 Dominik Taborsky
  * All rights reserved.
  *
@@ -27,5 +27,5 @@
  */
 
- /** @addtogroup hdisk
+/** @addtogroup hdisk
  * @{
  */
@@ -45,27 +45,24 @@
 } layouts_t;
 
-union label_data {
-	mbr_label_t	*mbr;
-	gpt_label_t	*gpt;
-};
+typedef union {
+	mbr_label_t *mbr;
+	gpt_label_t *gpt;
+} label_data_t;
 
-typedef struct label label_t;
-
-struct label {
+typedef struct label {
 	layouts_t layout;
-	aoff64_t nblocks;
+	aoff64_t blocks;
 	service_id_t device;
-	union label_data data;
+	label_data_t data;
 	unsigned int alignment;
-	int (* destroy_label)(label_t *);
-	int (* add_part)     (label_t *, tinput_t *);
-	int (* delete_part)  (label_t *, tinput_t *);
-	int (* new_label)    (label_t *);
-	int (* print_parts)  (label_t *);
-	int (* read_parts)   (label_t *);
-	int (* write_parts)  (label_t *);
-	int (* extra_funcs)  (label_t *, tinput_t *);
-};
+	int (* destroy_label)(struct label *);
+	int (* add_part)(struct label *, tinput_t *);
+	int (* delete_part)(struct label *, tinput_t *);
+	int (* new_label)(struct label *);
+	int (* print_parts)(struct label *);
+	int (* read_parts)(struct label *);
+	int (* write_parts)(struct label *);
+	int (* extra_funcs)(struct label *, tinput_t *);
+} label_t;
 
 #endif
-
Index: uspace/app/hdisk/func_gpt.c
===================================================================
--- uspace/app/hdisk/func_gpt.c	(revision d51beba3dc7e6298f4b9692cbba4886d50303d39)
+++ uspace/app/hdisk/func_gpt.c	(revision 6453e30691421828634cd3f671e5840773c9ff46)
@@ -1,4 +1,4 @@
 /*
- * Copyright (c) 2012, 2013 Dominik Taborsky
+ * Copyright (c) 2012-2013 Dominik Taborsky
  * All rights reserved.
  *
@@ -27,5 +27,5 @@
  */
 
- /** @addtogroup hdisk
+/** @addtogroup hdisk
  * @{
  */
@@ -39,5 +39,4 @@
 #include <sys/types.h>
 #include <sys/typefmt.h>
-
 #include "func_gpt.h"
 #include "input.h"
@@ -51,12 +50,12 @@
 	this->alignment = 1;
 	
-	this->add_part      = add_gpt_part;
-	this->delete_part   = delete_gpt_part;
+	this->add_part = add_gpt_part;
+	this->delete_part = delete_gpt_part;
 	this->destroy_label = destroy_gpt_label;
-	this->new_label     = new_gpt_label;
-	this->print_parts   = print_gpt_parts;
-	this->read_parts    = read_gpt_parts;
-	this->write_parts   = write_gpt_parts;
-	this->extra_funcs   = extra_gpt_funcs;
+	this->new_label = new_gpt_label;
+	this->print_parts = print_gpt_parts;
+	this->read_parts = read_gpt_parts;
+	this->write_parts = write_gpt_parts;
+	this->extra_funcs = extra_gpt_funcs;
 	
 	return this->new_label(this);
@@ -65,23 +64,19 @@
 int add_gpt_part(label_t *this, tinput_t *in)
 {
-	gpt_part_t * p = gpt_get_partition(this->data.gpt);
-	if (p == NULL) {
+	gpt_part_t *partition = gpt_get_partition(this->data.gpt);
+	if (partition == NULL)
 		return ENOMEM;
-	}
-	
-	return set_gpt_partition(in, p, this);
+	
+	return set_gpt_partition(in, partition, this);
 }
 
 int delete_gpt_part(label_t *this, tinput_t *in)
 {
-	int rc;
-	size_t idx;
-	
-	printf("Number of the partition to delete (counted from 0): ");
-	idx = get_input_size_t(in);
-	
-	rc = gpt_remove_partition(this->data.gpt, idx);
+	printf("Index of the partition to delete (counted from 0): ");
+	size_t idx = get_input_size_t(in);
+	
+	int rc = gpt_remove_partition(this->data.gpt, idx);
 	if (rc == ENOMEM) {
-		printf("Warning: running low on memory, not resizing...\n");
+		printf("Warning: Running out on memory, not resizing.\n");
 		return rc;
 	} else if (rc == EINVAL) {
@@ -107,24 +102,22 @@
 int print_gpt_parts(label_t *this)
 {
-	printf("Current partition scheme (GPT)(number of blocks: %" PRIu64 "):\n", this->nblocks);
-	printf("%15s %10s %10s Type: Name:\n", "Start:", "End:", "Length:");
+	printf("Current partition scheme: GPT\n");
+	printf("Number of blocks: %" PRIu64 "\n", this->blocks);
 	
 	size_t i = 0;
-	
 	gpt_part_foreach (this->data.gpt, iter) {
-		i++;
-		
 		if (gpt_get_part_type(iter) == GPT_PTE_UNUSED)
 			continue;
 		
 		if (i % 20 == 0)
-			printf("%15s %10s %10s Type: Name:\n", "Start:", "End:", "Length:");
-		
+			printf("%15s %10s %10s Type: Name:\n",
+			    "Start:", "End:", "Length:");
 		
 		printf("%3zu  %10" PRIu64 " %10" PRIu64 " %10" PRIu64 "    %3zu %s\n",
-		   i-1, gpt_get_start_lba(iter), gpt_get_end_lba(iter),
-		        gpt_get_end_lba(iter) - gpt_get_start_lba(iter), 
-		        gpt_get_part_type(iter), gpt_get_part_name(iter));
-		
+		   i, gpt_get_start_lba(iter), gpt_get_end_lba(iter),
+		   gpt_get_end_lba(iter) - gpt_get_start_lba(iter), 
+		   gpt_get_part_type(iter), gpt_get_part_name(iter));
+		
+		i++;
 	}
 	
@@ -134,9 +127,8 @@
 int read_gpt_parts(label_t *this)
 {
-	int rc;
-	
-	rc = gpt_read_header(this->data.gpt, this->device);
-	if (rc != EOK) {
-		printf("Error: Reading header failed: %d (%s)\n", rc, str_error(rc));
+	int rc = gpt_read_header(this->data.gpt, this->device);
+	if (rc != EOK) {
+		printf("Error: Reading header failed: %d (%s)\n", rc,
+		    str_error(rc));
 		return rc;
 	}
@@ -144,5 +136,6 @@
 	rc = gpt_read_partitions(this->data.gpt);
 	if (rc != EOK) {
-		printf("Error: Reading partitions failed: %d (%s)\n", rc, str_error(rc));
+		printf("Error: Reading partitions failed: %d (%s)\n", rc,
+		    str_error(rc));
 		return rc;
 	}
@@ -153,12 +146,11 @@
 int write_gpt_parts(label_t *this)
 {
-	int rc;
-	printf("test1\n");
-	rc = gpt_write_partitions(this->data.gpt, this->device);
-	if (rc != EOK) {
-		printf("Error: Writing partitions failed: %d (%s)\n", rc, str_error(rc));
-		return rc;
-	}
-	printf("test2\n");
+	int rc = gpt_write_partitions(this->data.gpt, this->device);
+	if (rc != EOK) {
+		printf("Error: Writing partitions failed: %d (%s)\n", rc,
+		    str_error(rc));
+		return rc;
+	}
+	
 	return EOK;
 }
@@ -170,17 +162,14 @@
 }
 
-static int set_gpt_partition(tinput_t *in, gpt_part_t *p, label_t * this)
-{
-	int rc;
-	
-	uint64_t sa, ea;
-	
+static int set_gpt_partition(tinput_t *in, gpt_part_t *partition, label_t *this)
+{
 	printf("Set starting address: ");
-	sa = get_input_uint64(in);
-	if (this->alignment != 0 && this->alignment != 1 && sa % this->alignment != 0)
+	uint64_t sa = get_input_uint64(in);
+	if ((this->alignment != 0) && (this->alignment != 1) &&
+	    (sa % this->alignment != 0))
 		sa = gpt_get_next_aligned(sa, this->alignment);
 	
-	printf("Set end address (max: %" PRIu64 "): ", this->nblocks);
-	ea = get_input_uint64(in);
+	printf("Set end address (max: %" PRIu64 "): ", this->blocks);
+	uint64_t ea = get_input_uint64(in);
 	
 	if (ea <= sa) {
@@ -189,19 +178,18 @@
 	}
 	
-	gpt_set_start_lba(p, sa);
-	gpt_set_end_lba(p, ea);
-	
-	/* See global.c from libgpt for all partition types. */
+	gpt_set_start_lba(partition, sa);
+	gpt_set_end_lba(partition, ea);
+	
 	printf("Choose type: ");
 	print_part_types();
 	printf("Set type (1 for HelenOS System): ");
 	size_t idx = get_input_size_t(in);
-	gpt_set_part_type(p, idx);
-	
-	gpt_set_random_uuid(p->part_id);
-	
+	gpt_set_part_type(partition, idx);
+	
+	gpt_set_random_uuid(partition->part_id);
+	
+	printf("Name the partition: ");
 	char *name;
-	printf("Name the partition: ");
-	rc = get_input_line(in, &name);
+	int rc = get_input_line(in, &name);
 	if (rc != EOK) {
 		printf("Error reading name: %d (%s)\n", rc, str_error(rc));
@@ -209,5 +197,5 @@
 	}
 	
-	gpt_set_part_name(p, name, str_size(name));
+	gpt_set_part_name(partition, name, str_size(name));
 	
 	return EOK;
@@ -216,20 +204,18 @@
 static void print_part_types(void)
 {
-	int c;
-	int count = 0;
-	const struct partition_type * ptype = gpt_ptypes;
+	unsigned int count = 0;
+	const partition_type_t *ptype = gpt_ptypes;
 	
 	do {
+		printf("%u: %s\n", count, ptype->desc);
+		count++;
+		ptype++;
+		
 		if (count % 10 == 0) {
 			printf("Print (more) partition types? (y/n)\n");
-			c = getchar();
+			int c = getchar();
 			if (c == 'n')
 				return;
 		}
-		
-		printf("%d: %s\n", count, ptype->desc);
-		++count;
-		++ptype;
 	} while (ptype->guid != NULL);
 }
-
Index: uspace/app/hdisk/func_gpt.h
===================================================================
--- uspace/app/hdisk/func_gpt.h	(revision d51beba3dc7e6298f4b9692cbba4886d50303d39)
+++ uspace/app/hdisk/func_gpt.h	(revision 6453e30691421828634cd3f671e5840773c9ff46)
@@ -1,4 +1,4 @@
 /*
- * Copyright (c) 2012, 2013 Dominik Taborsky
+ * Copyright (c) 2012-2013 Dominik Taborsky
  * All rights reserved.
  *
@@ -27,5 +27,5 @@
  */
 
- /** @addtogroup hdisk
+/** @addtogroup hdisk
  * @{
  */
@@ -34,21 +34,20 @@
 
 #ifndef __FUNC_GPT_H__
-#define	__FUNC_GPT_H__
+#define __FUNC_GPT_H__
 
 #include <loc.h>
 #include <tinput.h>
 #include <libgpt.h>
-
 #include "common.h"
 
 extern int construct_gpt_label(label_t *);
-extern int add_gpt_part     (label_t *, tinput_t *);
-extern int delete_gpt_part  (label_t *, tinput_t *);
+extern int add_gpt_part(label_t *, tinput_t *);
+extern int delete_gpt_part(label_t *, tinput_t *);
 extern int destroy_gpt_label(label_t *);
-extern int new_gpt_label    (label_t *);
-extern int print_gpt_parts  (label_t *);
-extern int read_gpt_parts   (label_t *);
-extern int write_gpt_parts  (label_t *);
-extern int extra_gpt_funcs  (label_t *, tinput_t *);
+extern int new_gpt_label(label_t *);
+extern int print_gpt_parts(label_t *);
+extern int read_gpt_parts(label_t *);
+extern int write_gpt_parts(label_t *);
+extern int extra_gpt_funcs(label_t *, tinput_t *);
 
 #endif
Index: uspace/app/hdisk/func_mbr.c
===================================================================
--- uspace/app/hdisk/func_mbr.c	(revision d51beba3dc7e6298f4b9692cbba4886d50303d39)
+++ uspace/app/hdisk/func_mbr.c	(revision 6453e30691421828634cd3f671e5840773c9ff46)
@@ -1,4 +1,4 @@
 /*
- * Copyright (c) 2012, 2013 Dominik Taborsky
+ * Copyright (c) 2012-2013 Dominik Taborsky
  * All rights reserved.
  *
@@ -27,5 +27,5 @@
  */
 
- /** @addtogroup hdisk
+/** @addtogroup hdisk
  * @{
  */
@@ -37,5 +37,4 @@
 #include <str_error.h>
 #include <sys/types.h>
-
 #include "func_mbr.h"
 #include "input.h"
@@ -62,16 +61,15 @@
 int add_mbr_part(label_t *this, tinput_t *in)
 {
-	int rc;
-	
-	mbr_part_t *part = mbr_alloc_partition();
-	
-	rc = set_mbr_partition(in, part, this);
+	mbr_part_t *partition = mbr_alloc_partition();
+	if (partition == NULL)
+		return ENOMEM;
+	
+	int rc = set_mbr_partition(in, partition, this);
 	if (rc != EOK)
 		return rc;
 	
-	rc = mbr_add_partition(this->data.mbr, part);
-	if (rc != ERR_OK) {
+	rc = mbr_add_partition(this->data.mbr, partition);
+	if (rc != ERR_OK)
 		printf("Error adding partition: %d\n", rc);
-	}
 	
 	return EOK;
@@ -80,17 +78,13 @@
 int delete_mbr_part(label_t *this, tinput_t *in)
 {
-	int rc;
-	size_t idx;
-	
-	printf("Number of the partition to delete (counted from 0): ");
-	idx = get_input_size_t(in);
-	
-	if (idx == 0 && errno != EOK)
-		return errno;
-	
-	rc = mbr_remove_partition(this->data.mbr, idx);
-	if (rc != EOK) {
+	printf("Index of the partition to delete (counted from 0): ");
+	size_t idx = get_input_size_t(in);
+	
+	if ((idx == 0) && (errno != EOK))
+		return errno;
+	
+	int rc = mbr_remove_partition(this->data.mbr, idx);
+	if (rc != EOK)
 		printf("Error: partition does not exist?\n");
-	}
 	
 	return EOK;
@@ -113,14 +107,13 @@
 }
 
-/** Print current partition scheme */
 int print_mbr_parts(label_t *this)
 {
-	int num = 0;
-	
-	printf("Current partition scheme (MBR)(number of blocks: %" PRIu64 "):\n", this->nblocks);
-	printf("\t\t%10s  %10s %10s %10s %7s\n", "Bootable:", "Start:", "End:", "Length:", "Type:");
-	
+	printf("Current partition scheme: MBR\n");
+	printf("Number of blocks: %" PRIu64 "\n", this->blocks);
+	printf("\t\t%10s  %10s %10s %10s %7s\n",
+	    "Bootable:", "Start:", "End:", "Length:", "Type:");
+	
+	unsigned int num = 0;
 	mbr_part_t *it;
-	
 	for (it = mbr_get_first_partition(this->data.mbr); it != NULL;
 	     it = mbr_get_next_partition(this->data.mbr, it)) {
@@ -128,5 +121,5 @@
 			continue;
 		
-		printf("\tP%d:\t", num);
+		printf("\tP%u:\t", num);
 		if (mbr_get_flag(it, ST_BOOT))
 			printf("*");
@@ -134,10 +127,11 @@
 			printf(" ");
 		
-		printf("\t%10u %10u %10u %7u\n", it->start_addr, it->start_addr + it->length, it->length, it->type);
+		printf("\t%10u %10u %10u %7u\n", it->start_addr,
+		    it->start_addr + it->length, it->length, it->type);
 		
 		num++;
 	}
 	
-	printf("%d partitions found.\n", num);
+	printf("%u partitions found.\n", num);
 	
 	return EOK;
@@ -146,6 +140,5 @@
 int read_mbr_parts(label_t *this)
 {
-	int rc;
-	rc = mbr_read_mbr(this->data.mbr, this->device);
+	int rc = mbr_read_mbr(this->data.mbr, this->device);
 	if (rc != EOK)
 		return rc;
@@ -164,7 +157,7 @@
 {
 	int rc = mbr_write_partitions(this->data.mbr, this->device);
-	if (rc != EOK) {
-		printf("Error occured during writing: ERR: %d: %s\n", rc, str_error(rc));
-	}
+	if (rc != EOK)
+		printf("Error occured during writing: ERR: %d: %s\n", rc,
+		    str_error(rc));
 	
 	return rc;
@@ -177,19 +170,16 @@
 }
 
-static int set_mbr_partition(tinput_t *in, mbr_part_t *p, label_t * this)
-{
-	int c;
-	uint8_t type;
-	
+static int set_mbr_partition(tinput_t *in, mbr_part_t *partition, label_t *this)
+{
 	printf("Primary (p) or logical (l): ");
-	c = getchar();
+	int c = getchar();
 	printf("%c\n", c);
 
 	switch (c) {
 	case 'p':
-		mbr_set_flag(p, ST_LOGIC, false);
+		mbr_set_flag(partition, ST_LOGIC, false);
 		break;
 	case 'l':
-		mbr_set_flag(p, ST_LOGIC, true);
+		mbr_set_flag(partition, ST_LOGIC, true);
 		break;
 	default:
@@ -198,35 +188,34 @@
 	}
 	
-	printf("Set type (0-255): ");
-	type = get_input_uint8(in);
-	if (type == 0 && errno != EOK)
-		return errno;
-
-	///TODO: there can only be one boolabel partition; let's do it just like fdisk
+	printf("Set type (0 - 255): ");
+	uint8_t type = get_input_uint8(in);
+	if ((type == 0) && (errno != EOK))
+		return errno;
+	
+	// FIXME: Make sure there is at most one bootable partition
 	printf("Bootable? (y/n): ");
 	c = getchar();
-	if (c != 'y' && c != 'Y' && c != 'n' && c != 'N') {
+	if ((c != 'y') && (c != 'Y') && (c != 'n') && (c != 'N')) {
 		printf("Invalid value. Cancelled.");
 		return EINVAL;
 	}
+	
 	printf("%c\n", c);
-	mbr_set_flag(p, ST_BOOT, (c == 'y' || c == 'Y') ? true : false);
-
-
-	uint32_t sa, ea;
-
+	mbr_set_flag(partition, ST_BOOT, (c == 'y' || c == 'Y') ? true : false);
+	
 	printf("Set starting address: ");
-	sa = get_input_uint32(in);
-	if (sa == 0 && errno != EOK)
-		return errno;
-	
-	if (this->alignment != 0 && this->alignment != 1 && sa % this->alignment != 0) {
+	uint32_t sa = get_input_uint32(in);
+	if ((sa == 0) && (errno != EOK))
+		return errno;
+	
+	if ((this->alignment != 0) && (this->alignment != 1) &&
+	    (sa % this->alignment != 0)) {
 		sa = mbr_get_next_aligned(sa, this->alignment);
-		printf("Starting address was aligned to %u.\n", sa);
-	}
-	
-	printf("Set end addres (max: %" PRIu64 "): ", this->nblocks);
-	ea = get_input_uint32(in);
-	if (ea == 0 && errno != EOK)
+		printf("Starting address was aligned to %" PRIu32 ".\n", sa);
+	}
+	
+	printf("Set end addres (max: %" PRIu64 "): ", this->blocks);
+	uint32_t ea = get_input_uint32(in);
+	if ((ea == 0) && (errno != EOK))
 		return errno;
 	
@@ -236,14 +225,8 @@
 	}
 	
-	p->type = type;
-	p->start_addr = sa;
-	p->length = ea - sa;
-
-	return EOK;
-}
-
-
-
-
-
-
+	partition->type = type;
+	partition->start_addr = sa;
+	partition->length = ea - sa;
+	
+	return EOK;
+}
Index: uspace/app/hdisk/func_mbr.h
===================================================================
--- uspace/app/hdisk/func_mbr.h	(revision d51beba3dc7e6298f4b9692cbba4886d50303d39)
+++ uspace/app/hdisk/func_mbr.h	(revision 6453e30691421828634cd3f671e5840773c9ff46)
@@ -1,4 +1,4 @@
 /*
- * Copyright (c) 2012, 2013 Dominik Taborsky
+ * Copyright (c) 2012-2013 Dominik Taborsky
  * All rights reserved.
  *
@@ -27,5 +27,5 @@
  */
 
- /** @addtogroup hdisk
+/** @addtogroup hdisk
  * @{
  */
@@ -34,21 +34,20 @@
 
 #ifndef __FUNC_MBR_H__
-#define	__FUNC_MBR_H__
+#define __FUNC_MBR_H__
 
 #include <loc.h>
 #include <tinput.h>
 #include <libmbr.h>
-
 #include "common.h"
 
 extern int construct_mbr_label(label_t *);
-extern int add_mbr_part     (label_t *, tinput_t *);
-extern int delete_mbr_part  (label_t *, tinput_t *);
+extern int add_mbr_part(label_t *, tinput_t *);
+extern int delete_mbr_part(label_t *, tinput_t *);
 extern int destroy_mbr_label(label_t *);
-extern int new_mbr_label    (label_t *);
-extern int print_mbr_parts  (label_t *);
-extern int read_mbr_parts   (label_t *);
-extern int write_mbr_parts  (label_t *);
-extern int extra_mbr_funcs  (label_t *, tinput_t *);
+extern int new_mbr_label(label_t *);
+extern int print_mbr_parts(label_t *);
+extern int read_mbr_parts(label_t *);
+extern int write_mbr_parts(label_t *);
+extern int extra_mbr_funcs(label_t *, tinput_t *);
 
 #endif
Index: uspace/app/hdisk/func_none.c
===================================================================
--- uspace/app/hdisk/func_none.c	(revision d51beba3dc7e6298f4b9692cbba4886d50303d39)
+++ uspace/app/hdisk/func_none.c	(revision 6453e30691421828634cd3f671e5840773c9ff46)
@@ -1,4 +1,4 @@
 /*
- * Copyright (c) 2012, 2013 Dominik Taborsky
+ * Copyright (c) 2012-2013 Dominik Taborsky
  * All rights reserved.
  *
@@ -27,5 +27,5 @@
  */
 
- /** @addtogroup hdisk
+/** @addtogroup hdisk
  * @{
  */
@@ -33,11 +33,8 @@
  */
 
-
 #include <errno.h>
-
 #include "func_none.h"
 
 static void not_implemented(void);
-
 
 int construct_none_label(label_t *this)
@@ -45,17 +42,17 @@
 	this->layout = LYT_NONE;
 	
-	this->add_part      = add_none_part;
-	this->delete_part   = delete_none_part;
+	this->add_part = add_none_part;
+	this->delete_part = delete_none_part;
 	this->destroy_label = destroy_none_label;
-	this->new_label     = new_none_label;
-	this->print_parts   = print_none_parts;
-	this->read_parts    = read_none_parts;
-	this->write_parts   = write_none_parts;
-	this->extra_funcs   = extra_none_funcs;
+	this->new_label = new_none_label;
+	this->print_parts = print_none_parts;
+	this->read_parts = read_none_parts;
+	this->write_parts = write_none_parts;
+	this->extra_funcs = extra_none_funcs;
 	
 	return EOK;
 }
 
-int add_none_part(label_t *this, tinput_t * in)
+int add_none_part(label_t *this, tinput_t *in)
 {
 	not_implemented();
@@ -63,5 +60,5 @@
 }
 
-int delete_none_part(label_t *this, tinput_t * in)
+int delete_none_part(label_t *this, tinput_t *in)
 {
 	not_implemented();
@@ -104,5 +101,5 @@
 }
 
-static void not_implemented()
+static void not_implemented(void)
 {
 	printf("No format selected.\n");
Index: uspace/app/hdisk/func_none.h
===================================================================
--- uspace/app/hdisk/func_none.h	(revision d51beba3dc7e6298f4b9692cbba4886d50303d39)
+++ uspace/app/hdisk/func_none.h	(revision 6453e30691421828634cd3f671e5840773c9ff46)
@@ -1,4 +1,4 @@
 /*
- * Copyright (c) 2012, 2013 Dominik Taborsky
+ * Copyright (c) 2012-2013 Dominik Taborsky
  * All rights reserved.
  *
@@ -27,5 +27,5 @@
  */
 
- /** @addtogroup hdisk
+/** @addtogroup hdisk
  * @{
  */
@@ -34,20 +34,19 @@
 
 #ifndef __FUNC_NONE_H__
-#define	__FUNC_NONE_H__
+#define __FUNC_NONE_H__
 
 #include <loc.h>
 #include <tinput.h>
-
 #include "common.h"
 
 extern int construct_none_label(label_t *);
-extern int add_none_part     (label_t *, tinput_t *);
-extern int delete_none_part  (label_t *, tinput_t *);
+extern int add_none_part(label_t *, tinput_t *);
+extern int delete_none_part(label_t *, tinput_t *);
 extern int destroy_none_label(label_t *);
-extern int new_none_label    (label_t *);
-extern int print_none_parts  (label_t *);
-extern int read_none_parts   (label_t *);
-extern int write_none_parts  (label_t *);
-extern int extra_none_funcs  (label_t *, tinput_t *);
+extern int new_none_label(label_t *);
+extern int print_none_parts(label_t *);
+extern int read_none_parts(label_t *);
+extern int write_none_parts(label_t *);
+extern int extra_none_funcs(label_t *, tinput_t *);
 
 #endif
Index: uspace/app/hdisk/hdisk.c
===================================================================
--- uspace/app/hdisk/hdisk.c	(revision d51beba3dc7e6298f4b9692cbba4886d50303d39)
+++ uspace/app/hdisk/hdisk.c	(revision 6453e30691421828634cd3f671e5840773c9ff46)
@@ -1,4 +1,4 @@
 /*
- * Copyright (c) 2012, 2013 Dominik Taborsky
+ * Copyright (c) 2012-2013 Dominik Taborsky
  * All rights reserved.
  *
@@ -27,5 +27,5 @@
  */
 
- /** @addtogroup hdisk
+/** @addtogroup hdisk
  * @{
  */
@@ -47,5 +47,4 @@
 #include <tinput.h>
 #include <str_error.h>
-
 #include "hdisk.h"
 #include "input.h"
@@ -54,31 +53,28 @@
 #include "func_none.h"
 
-int interact(void);
-void print_help(void);
-void select_label_format(tinput_t *);
-void construct_label(layouts_t);
-void free_label(void);
-int try_read(void);
-int try_read_mbr(void);
-int try_read_gpt(void);
-void set_alignment(tinput_t *);
-
+static int interact(void);
+static void print_help(void);
+static void select_label_format(tinput_t *);
+static void construct_label(layouts_t);
+static void free_label(void);
+static int try_read(void);
+static int try_read_mbr(void);
+static int try_read_gpt(void);
+static void set_alignment(tinput_t *);
 
 static label_t label;
 
-int main(int argc, char ** argv)
+int main(int argc, char *argv[])
 {
 	if (argc == 1) {
 		printf("Missing argument. Please specify a device to operate on.\n");
-		return -1;
-	}
-	
-	int rc;
+		return 1;
+	}
+	
 	service_id_t dev_handle;
-	
-	rc = loc_service_get_id(argv[1], &dev_handle, IPC_FLAG_BLOCKING);
+	int rc = loc_service_get_id(argv[1], &dev_handle, IPC_FLAG_BLOCKING);
 	if (rc != EOK) {
 		printf("Unknown device. Exiting.\n");
-		return -1;
+		return 2;
 	}
 	
@@ -89,16 +85,17 @@
 	if (rc != EOK) {
 		printf("Error during libblock init: %d - %s.\n", rc, str_error(rc));
-		return -1;
-	}
-	
-	aoff64_t nblocks;
-	rc = block_get_nblocks(dev_handle, &nblocks);
+		return 3;
+	}
+	
+	aoff64_t blocks;
+	rc = block_get_nblocks(dev_handle, &blocks);
 	block_fini(dev_handle);
 	if (rc != EOK) {
-		printf(LIBMBR_NAME ": Error while getting number of blocks: %d - %s.\n", rc, str_error(rc));
-		return -1;
-	}
-	
-	label.nblocks = nblocks;
+		printf("Error while getting number of blocks: %d - %s.\n",
+		    rc, str_error(rc));
+		return 4;
+	}
+	
+	label.blocks = blocks;
 	
 	rc = try_read_mbr();
@@ -116,17 +113,11 @@
 	
 interact:
-	
-	rc = interact();
-	
-	return rc;
+	return interact();
 }
 
 /** Interact with user */
-int interact()
-{
-	int input;
-	tinput_t *in;
-	
-	in = tinput_new();
+int interact(void)
+{
+	tinput_t *in = tinput_new();
 	if (in == NULL) {
 		printf("Failed initing input. Free some memory.\n");
@@ -137,7 +128,7 @@
 	printf("Welcome to hdisk.\nType 'h' for help.\n");
 	
-	while (1) {
+	while (true) {
 		printf("# ");
-		input = getchar();
+		int input = getchar();
 		printf("%c\n", input);
 		
@@ -187,5 +178,4 @@
 end:
 	tinput_destroy(in);
-	
 	return EOK;
 }
@@ -194,25 +184,22 @@
 {
 	printf(
-		"\t 'a' \t\t Add partition.\n"
-		"\t 'd' \t\t Delete partition.\n"
-		"\t 'e' \t\t Extra functions (per label format).\n"
-		"\t 'f' \t\t Switch the format of the partition label.\n"
-		"\t 'h' \t\t Prints help. See help for more.\n"
-		"\t 'l' \t\t Set alignment.\n"
-		"\t 'n' \t\t Create new label (discarding the old one).\n"
-		"\t 'p' \t\t Prints label contents.\n"
-		"\t 'q' \t\t Quit.\n"
-		"\t 'r' \t\t Read label from disk.\n"
-		"\t 'w' \t\t Write label to disk.\n"
-		);
-
-}
-
-void select_label_format(tinput_t * in)
+	    "\t 'a' \t\t Add partition.\n"
+	    "\t 'd' \t\t Delete partition.\n"
+	    "\t 'e' \t\t Extra functions (per label format).\n"
+	    "\t 'f' \t\t Switch the format of the partition label.\n"
+	    "\t 'h' \t\t Prints help. See help for more.\n"
+	    "\t 'l' \t\t Set alignment.\n"
+	    "\t 'n' \t\t Create new label (discarding the old one).\n"
+	    "\t 'p' \t\t Prints label contents.\n"
+	    "\t 'q' \t\t Quit.\n"
+	    "\t 'r' \t\t Read label from disk.\n"
+	    "\t 'w' \t\t Write label to disk.\n");
+}
+
+void select_label_format(tinput_t *in)
 {
 	printf("Available formats are: \n"
-			"1) MBR\n"
-			"2) GPT\n"
-	      );
+	    "1) MBR\n"
+	    "2) GPT\n");
 	
 	uint8_t val = get_input_uint8(in);
@@ -253,11 +240,10 @@
 }
 
-int try_read()
-{
-	
+int try_read(void)
+{
 	return label.read_parts(&label);
 }
 
-int try_read_mbr()
+int try_read_mbr(void)
 {
 	construct_label(LYT_MBR);
@@ -265,5 +251,5 @@
 }
 
-int try_read_gpt()
+int try_read_gpt(void)
 {
 	construct_label(LYT_GPT);
@@ -277,5 +263,2 @@
 	printf("Alignment set to %u sectors.\n", label.alignment);
 }
-
-
-
Index: uspace/app/hdisk/hdisk.h
===================================================================
--- uspace/app/hdisk/hdisk.h	(revision d51beba3dc7e6298f4b9692cbba4886d50303d39)
+++ uspace/app/hdisk/hdisk.h	(revision 6453e30691421828634cd3f671e5840773c9ff46)
@@ -1,4 +1,4 @@
 /*
- * Copyright (c) 2012, 2013 Dominik Taborsky
+ * Copyright (c) 2012-2013 Dominik Taborsky
  * All rights reserved.
  *
@@ -27,9 +27,12 @@
  */
 
- /** @addtogroup hdisk
+/** @addtogroup hdisk
  * @{
  */
 /** @file
  */
+
+#ifndef __HDISK_H__
+#define __HDISK_H__
 
 #include "common.h"
@@ -38,2 +41,3 @@
 	label.layout = LYT_NONE
 
+#endif
Index: uspace/app/hdisk/input.c
===================================================================
--- uspace/app/hdisk/input.c	(revision d51beba3dc7e6298f4b9692cbba4886d50303d39)
+++ uspace/app/hdisk/input.c	(revision 6453e30691421828634cd3f671e5840773c9ff46)
@@ -1,4 +1,4 @@
 /*
- * Copyright (c) 2012, 2013 Dominik Taborsky
+ * Copyright (c) 2012-2013 Dominik Taborsky
  * All rights reserved.
  *
@@ -27,5 +27,5 @@
  */
 
- /** @addtogroup hdisk
+/** @addtogroup hdisk
  * @{
  */
@@ -36,22 +36,19 @@
 #include <errno.h>
 #include <stdlib.h>
-
 #include "input.h"
 
 typedef int (*conv_f)(const char *, char **, unsigned int, bool, void *);
-static int convert(tinput_t * in, conv_f str_f, void * val);
 
-int get_input_line(tinput_t * in, char ** str)
+static int convert(tinput_t *, conv_f, void *);
+
+int get_input_line(tinput_t *in, char **str)
 {
-	int rc;
-	rc = tinput_read(in, str);
-	if (rc == ENOENT) {
-		/* User requested exit */
+	int rc = tinput_read(in, str);
+	if (rc == ENOENT)
 		return EINTR;
-	}
-	if (rc != EOK) {
-		/* Error in communication with console */
+	
+	if (rc != EOK)
 		return rc;
-	}
+	
 	/* Check for empty input. */
 	if (str_cmp(*str, "") == 0) {
@@ -60,56 +57,12 @@
 		return EINVAL;
 	}
-
+	
 	return EOK;
 }
 
-uint8_t get_input_uint8(tinput_t * in)
+uint8_t get_input_uint8(tinput_t *in)
 {
-	int rc;
 	uint32_t val;
-	
-	rc = convert(in, (conv_f) str_uint8_t, &val);
-	if (rc != EOK) {
-		errno = rc;
-		return 0;
-	}
-	
-	return val;
-}
-
-uint32_t get_input_uint32(tinput_t * in)
-{
-	int rc;
-	uint32_t val;
-	
-	rc = convert(in, (conv_f) str_uint32_t, &val);
-	if (rc != EOK) {
-		errno = rc;
-		return 0;
-	}
-	
-	return val;
-}
-
-uint64_t get_input_uint64(tinput_t * in)
-{
-	int rc;
-	uint64_t val;
-	
-	rc = convert(in, (conv_f) str_uint64_t, &val);
-	if (rc != EOK) {
-		errno = rc;
-		return 0;
-	}
-	
-	return val;
-}
-
-size_t get_input_size_t(tinput_t * in)
-{
-	int rc;
-	size_t val;
-	
-	rc = convert(in, (conv_f) str_size_t, &val);
+	int rc = convert(in, (conv_f) str_uint8_t, &val);
 	if (rc != EOK) {
 		errno = rc;
@@ -121,10 +74,47 @@
 }
 
-static int convert(tinput_t * in, conv_f str_f, void * val)
+uint32_t get_input_uint32(tinput_t *in)
 {
-	int rc;
-	char * str;
+	uint32_t val;
+	int rc = convert(in, (conv_f) str_uint32_t, &val);
+	if (rc != EOK) {
+		errno = rc;
+		return 0;
+	}
 	
-	rc = get_input_line(in, &str);
+	errno = EOK;
+	return val;
+}
+
+uint64_t get_input_uint64(tinput_t *in)
+{
+	uint64_t val;
+	int rc = convert(in, (conv_f) str_uint64_t, &val);
+	if (rc != EOK) {
+		errno = rc;
+		return 0;
+	}
+	
+	errno = EOK;
+	return val;
+}
+
+size_t get_input_size_t(tinput_t *in)
+{
+	size_t val;
+	int rc = convert(in, (conv_f) str_size_t, &val);
+	if (rc != EOK) {
+		errno = rc;
+		return 0;
+	}
+	
+	errno = EOK;
+	return val;
+}
+
+static int convert(tinput_t *in, conv_f str_f, void *val)
+{
+	char *str;
+	int rc = get_input_line(in, &str);
 	if (rc != EOK) {
 		printf("Error reading input.\n");
@@ -133,10 +123,8 @@
 	
 	rc = str_f(str, NULL, 10, true, val);
-	if (rc != EOK) {
+	if (rc != EOK)
 		printf("Invalid value.\n");
-	}
 	
 	free(str);
 	return rc;
 }
-
Index: uspace/app/hdisk/input.h
===================================================================
--- uspace/app/hdisk/input.h	(revision d51beba3dc7e6298f4b9692cbba4886d50303d39)
+++ uspace/app/hdisk/input.h	(revision 6453e30691421828634cd3f671e5840773c9ff46)
@@ -1,4 +1,4 @@
 /*
- * Copyright (c) 2012, 2013 Dominik Taborsky
+ * Copyright (c) 2012-2013 Dominik Taborsky
  * All rights reserved.
  *
@@ -27,5 +27,5 @@
  */
 
- /** @addtogroup hdisk
+/** @addtogroup hdisk
  * @{
  */
@@ -34,13 +34,13 @@
 
 #ifndef __INPUT_H__
-#define	__INPUT_H__
+#define __INPUT_H__
 
 #include <tinput.h>
 
-extern int		get_input_line(tinput_t * in, char ** str);
-extern uint8_t	get_input_uint8(tinput_t * in);
-extern uint32_t	get_input_uint32(tinput_t * in);
-extern uint64_t	get_input_uint64(tinput_t * in);
-extern size_t	get_input_size_t(tinput_t * in);
+extern int get_input_line(tinput_t *, char **);
+extern uint8_t get_input_uint8(tinput_t *);
+extern uint32_t get_input_uint32(tinput_t *);
+extern uint64_t get_input_uint64(tinput_t *);
+extern size_t get_input_size_t(tinput_t *);
 
 #endif
Index: uspace/lib/gpt/global.c
===================================================================
--- uspace/lib/gpt/global.c	(revision d51beba3dc7e6298f4b9692cbba4886d50303d39)
+++ uspace/lib/gpt/global.c	(revision 6453e30691421828634cd3f671e5840773c9ff46)
@@ -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 d51beba3dc7e6298f4b9692cbba4886d50303d39)
+++ uspace/lib/gpt/gpt.h	(revision 6453e30691421828634cd3f671e5840773c9ff46)
@@ -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 d51beba3dc7e6298f4b9692cbba4886d50303d39)
+++ uspace/lib/gpt/libgpt.c	(revision 6453e30691421828634cd3f671e5840773c9ff46)
@@ -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 d51beba3dc7e6298f4b9692cbba4886d50303d39)
+++ uspace/lib/gpt/libgpt.h	(revision 6453e30691421828634cd3f671e5840773c9ff46)
@@ -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
-
Index: uspace/lib/mbr/Makefile
===================================================================
--- uspace/lib/mbr/Makefile	(revision d51beba3dc7e6298f4b9692cbba4886d50303d39)
+++ uspace/lib/mbr/Makefile	(revision 6453e30691421828634cd3f671e5840773c9ff46)
@@ -28,5 +28,5 @@
 
 USPACE_PREFIX = ../..
-EXTRA_CFLAGS = -I$(LIBBLOCK_PREFIX) -DDEBUG_CONFIG
+EXTRA_CFLAGS = -I$(LIBBLOCK_PREFIX)
 LIBRARY = libmbr
 
Index: uspace/lib/mbr/libmbr.c
===================================================================
--- uspace/lib/mbr/libmbr.c	(revision d51beba3dc7e6298f4b9692cbba4886d50303d39)
+++ uspace/lib/mbr/libmbr.c	(revision 6453e30691421828634cd3f671e5840773c9ff46)
@@ -1,4 +1,4 @@
 /*
- * Copyright (c) 2011, 2012, 2013 Dominik Taborsky
+ * Copyright (c) 2011-2013 Dominik Taborsky
  * All rights reserved.
  *
@@ -27,5 +27,5 @@
  */
 
- /** @addtogroup libmbr
+/** @addtogroup libmbr
  * @{
  */
@@ -43,8 +43,8 @@
 #include <stdlib.h>
 #include <str_error.h>
-
+#include <align.h>
 #include "libmbr.h"
 
-static br_block_t * alloc_br(void);
+static br_block_t *alloc_br(void);
 static int decode_part(pt_entry_t *, mbr_part_t *, uint32_t);
 static int decode_logical(mbr_label_t *, mbr_part_t *);
@@ -57,5 +57,5 @@
 
 /** Allocate and initialize mbr_label_t structure */
-mbr_label_t * mbr_alloc_label(void)
+mbr_label_t *mbr_alloc_label(void)
 {
 	mbr_label_t *label = malloc(sizeof(mbr_label_t));
@@ -88,5 +88,5 @@
 
 /** Allocate memory for mbr_t */
-mbr_t * mbr_alloc_mbr(void)
+mbr_t *mbr_alloc_mbr(void)
 {
 	return malloc(sizeof(mbr_t));
@@ -94,85 +94,79 @@
 
 /** Read MBR from specific device
- * @param   label       label to write data to
- * @param   dev_handle  device to read MBR from
- *
- * @return				EOK on success, error code on error
+ *
+ * @param label      Label to be read.
+ * @param dev_handle Device to read MBR from.
+ *
+ * @return EOK on success, error code on error.
+ *
  */
 int mbr_read_mbr(mbr_label_t *label, service_id_t dev_handle)
 {	
-	int rc;
-	
 	if (label->mbr == NULL) {
 		label->mbr = mbr_alloc_mbr();
-		if (label->mbr == NULL) {
+		if (label->mbr == NULL)
 			return ENOMEM;
-		}
-	}
-
-	rc = block_init(EXCHANGE_ATOMIC, dev_handle, 512);
+	}
+	
+	int rc = block_init(EXCHANGE_ATOMIC, dev_handle, 512);
 	if (rc != EOK)
 		return rc;
-
-	rc = block_read_direct(dev_handle, 0, 1, &(label->mbr->raw_data));
+	
+	rc = block_read_direct(dev_handle, 0, 1, &label->mbr->raw_data);
 	block_fini(dev_handle);
 	if (rc != EOK)
 		return rc;
-
+	
 	label->device = dev_handle;
-
+	
 	return EOK;
 }
 
-/** Write mbr to disk
- * @param label			MBR to be written
- * @param dev_handle	device handle to write MBR to (may be different
- * 							from the device in 'mbr')
- *
- * @return				0 on success, otherwise libblock error code
+/** Write MBR to specific device
+ *
+ * @param label      Label to be written.
+ * @param dev_handle Device to write MBR to.
+ *
+ * @return EOK on success, error code on error.
+ *
  */
 int mbr_write_mbr(mbr_label_t *label, service_id_t dev_handle)
 {
-	int rc;
-
-	rc = block_init(EXCHANGE_ATOMIC, dev_handle, 512);
-	if (rc != EOK) {
+	int rc = block_init(EXCHANGE_ATOMIC, dev_handle, 512);
+	if (rc != EOK)
 		return rc;
-	}
-
-	rc = block_write_direct(dev_handle, 0, 1, &(label->mbr->raw_data));
+	
+	rc = block_write_direct(dev_handle, 0, 1, &label->mbr->raw_data);
 	block_fini(dev_handle);
-	if (rc != EOK) {
-		return rc;
-	}
-
-	return EOK;
-}
-
-/** Decide whether this is an actual MBR or a Protective MBR from GPT
- *
- * @param mbr		the actual MBR to decide upon
- *
- * @return			1 if MBR, 0 if GPT
+	
+	return rc;
+}
+
+/** Decide whether this is an actual MBR or a Protective MBR for GPT
+ *
+ * @param label Label to decide upon.
+ *
+ * @return True if MBR.
+ * @return False if Protective MBR for GPT.
+ *
  */
 int mbr_is_mbr(mbr_label_t *label)
 {
-	return (label->mbr->raw_data.pte[0].ptype != PT_GPT) ? 1 : 0;
-}
-
-/** Parse partitions from MBR, freeing previous partitions if any
- * NOTE: it is assumed mbr_read_mbr(label) was called before.
- * @param label  MBR to be parsed
- *
- * @return       linked list of partitions or NULL on error
+	return (label->mbr->raw_data.pte[0].ptype != PT_GPT);
+}
+
+/** Parse partitions from MBR (freeing previous partitions if any)
+ *
+ * It is assumed that mbr_read_mbr() was called before.
+ *
+ * @param label Label to be parsed.
+ *
+ * @return EOK on success, error code on error.
+ *
  */
 int mbr_read_partitions(mbr_label_t *label)
 {
-	if (label == NULL || label->mbr == NULL)
+	if ((label == NULL) || (label->mbr == NULL))
 		return EINVAL;
-	
-	int rc, rc_ext;
-	unsigned int i;
-	mbr_part_t *p;
-	mbr_part_t *ext = NULL;
 	
 	if (label->parts != NULL)
@@ -180,52 +174,48 @@
 	
 	label->parts = mbr_alloc_partitions();
-	if (label->parts == NULL) {
+	if (label->parts == NULL)
 		return ENOMEM;
-	}
+	
+	mbr_part_t *extended = NULL;
 	
 	/* Generate the primary partitions */
-	for (i = 0; i < N_PRIMARY; ++i) {
+	for (unsigned int i = 0; i < N_PRIMARY; i++) {
 		if (label->mbr->raw_data.pte[i].ptype == PT_UNUSED)
 			continue;
 		
-		p = mbr_alloc_partition();
-		if (p == NULL) {
-			printf(LIBMBR_NAME ": Error on memory allocation.\n");
+		mbr_part_t *partition = mbr_alloc_partition();
+		if (partition == NULL) {
 			mbr_free_partitions(label->parts);
 			return ENOMEM;
 		}
 		
-		rc_ext = decode_part(&(label->mbr->raw_data.pte[i]), p, 0);
-		mbr_set_flag(p, ST_LOGIC, false);
-		rc = mbr_add_partition(label, p);
+		int is_extended =
+		    decode_part(&label->mbr->raw_data.pte[i], partition, 0);
+		
+		mbr_set_flag(partition, ST_LOGIC, false);
+		
+		int rc = mbr_add_partition(label, partition);
 		if (rc != ERR_OK) {
-			printf(LIBMBR_NAME ": Error occured during decoding the MBR. (%d)\n" \
-			       LIBMBR_NAME ": MBR is invalid.\n", rc);
 			mbr_free_partitions(label->parts);
 			return EINVAL;
 		}
 		
-		if (rc_ext) {
-			ext = p;
-			label->parts->l_extended = &p->link;
-		}
-	}
-	
-	/* Fill in the primary partitions and generate logical ones, if any */
-	rc = decode_logical(label, ext);
-	if (rc != EOK) {
-		printf(LIBMBR_NAME ": Error during decoding logical partitions: %d - %s.\n" \
-			   LIBMBR_NAME ": Partition list may be incomplete.\n", rc, str_error(rc));
-		return rc;
-	}
-	
-	return EOK;
+		if (is_extended) {
+			extended = partition;
+			label->parts->l_extended = &partition->link;
+		}
+	}
+	
+	/* Fill in the primary partitions and generate logical ones (if any) */
+	return decode_logical(label, extended);
 }
 
 /** Write MBR and partitions to device
- * @param label        label to write
- * @param dev_handle   device to write the data to
- *
- * @return             returns EOK on succes, specific error code otherwise
+ *
+ * @param label      Label to write.
+ * @param dev_handle Device to write the data to.
+ *
+ * @return EOK on success, specific error code otherwise.
+ *
  */
 int mbr_write_partitions(mbr_label_t *label, service_id_t dev_handle)
@@ -237,217 +227,204 @@
 		label->mbr = mbr_alloc_mbr();
 	
-	int i = 0;
-	int rc;
-	mbr_part_t *p;
-	mbr_part_t *ext = (label->parts->l_extended == NULL) ? NULL
-					: list_get_instance(label->parts->l_extended, mbr_part_t, link);
-	
-	rc = block_init(EXCHANGE_ATOMIC, dev_handle, 512);
-	if (rc != EOK) {
-		printf(LIBMBR_NAME ": Error while initializing libblock: %d - %s.\n", rc, str_error(rc));
+	int rc = block_init(EXCHANGE_ATOMIC, dev_handle, 512);
+	if (rc != EOK)
 		return rc;
-	}
-	
-	link_t *l = label->parts->list.head.next;
-	
-	/* Encoding primary partitions */
-	for (i = 0; i < N_PRIMARY; i++) {
-		p = list_get_instance(l, mbr_part_t, link);	
-		encode_part(p, &(label->mbr->raw_data.pte[i]), 0, false);
-		l = l->next;
-	}
-	
-	label->mbr->raw_data.signature = host2uint16_t_le(BR_SIGNATURE);
-	
-	/* Writing MBR */
-	rc = block_write_direct(dev_handle, 0, 1, &(label->mbr->raw_data));
-	if (rc != EOK) {
-		printf(LIBMBR_NAME ": Error while writing MBR : %d - %s.\n", rc, str_error(rc));
+	
+	mbr_part_t *partition = NULL;
+	mbr_part_t *extended = NULL;
+	
+	if (label->parts->l_extended != NULL)
+		extended = list_get_instance(label->parts->l_extended,
+		    mbr_part_t, link);
+	
+	link_t *link = label->parts->list.head.next;
+	
+	/* Encode primary partitions */
+	for (unsigned int i = 0; i < N_PRIMARY; i++) {
+		partition = list_get_instance(link, mbr_part_t, link);
+		
+		encode_part(partition, &label->mbr->raw_data.pte[i], 0, false);
+		link = link->next;
+	}
+	
+	/* Write MBR */
+	rc = block_write_direct(dev_handle, 0, 1, &label->mbr->raw_data);
+	if ((rc != EOK) || (extended == NULL))
 		goto end;
-	}
-	
-	if (ext == NULL) {
-		rc = EOK;
+	
+	uint32_t base = extended->start_addr;
+	mbr_part_t *prev_partition;
+	
+	/* Encode and write first logical partition */
+	if (link != &label->parts->list.head) {
+		partition = list_get_instance(link, mbr_part_t, link);
+		
+		partition->ebr_addr = base;
+		encode_part(partition, &partition->ebr->pte[0], base, false);
+		link = link->next;
+	} else {
+		/*
+		 * If there was an extended partition but no logical partitions,
+		 * we should overwrite the space where the first logical
+		 * partitions's EBR would have been. There might be some
+		 * garbage from the past.
+		 */
+		
+		br_block_t *br = alloc_br();
+		rc = block_write_direct(dev_handle, base, 1, br);
+		if (rc != EOK)
+			goto end;
+		
+		free(br);
 		goto end;
 	}
 	
-	uint32_t base = ext->start_addr;
-	mbr_part_t *prev_p;
-	
-	/* Note for future changes: Some thought has been put into design
-	 * and implementation. If you don't have to change it, don't. Other
-	 * designs have been tried, this came out as the least horror with
-	 * as much power over it as you can get. */
-	
-	/* Encoding and writing first logical partition */
-	if (l != &(label->parts->list.head)) {
-		p = list_get_instance(l, mbr_part_t, link);
-		p->ebr_addr = base;
-		encode_part(p, &(p->ebr->pte[0]), base, false);
-		l = l->next;
-	} else {
-		/* If there was an extended but no logical, we should overwrite
-		 * the space where the first logical's EBR would have been. There
-		 * might be some garbage from the past. */
-		br_block_t * tmp = alloc_br();
-		rc = block_write_direct(dev_handle, base, 1, tmp);
-		if (rc != EOK) {
-			printf(LIBMBR_NAME ": Error while writing EBR: %d - %s.\n", rc, str_error(rc));
-			goto end;
-		}
-		free(tmp);
-		rc = EOK;
-		goto end;
-	}
-	
-	prev_p = p;
-	
-	/* Check EBR addresses
-	 * This piece of code saves previous EBR placements from other
-	 * software. But if our user modifies the logical partition chain,
-	 * we have to fix those placements if needed.*/
-	link_t *l_ebr = l;
-	link_t *l_iter;
-	mbr_part_t *tmp = mbr_alloc_partition();
-	tmp->length = 1;
-	while (l_ebr != &(label->parts->list.head)) {
-		p = list_get_instance(l_ebr, mbr_part_t, link);
-		tmp->start_addr = p->ebr_addr;
-		
-		l_iter = l;
-		while (l_iter != &(label->parts->list.head)) {
-			/* Checking whether EBR address makes sense. If not, we take a guess.
-			 * So far this is simple, we just take the first preceeding sector.
-			 * Fdisk always reserves at least 2048 sectors (1MiB), so it can have 
-			 * the EBR aligned as well as the partition itself. Parted reserves
-			 * minimum one sector, like we do.
-			 * 
-			 * Note that we know there is at least one sector free from previous checks.
-			 * Also note that the user can set ebr_addr to their liking (if it's valid). */		 
-			if (p->ebr_addr < base || p->ebr_addr >= base + ext->length ||
-			  check_overlap(tmp, list_get_instance(l_iter, mbr_part_t, link))) {
-				p->ebr_addr = p->start_addr - 1;
+	prev_partition = partition;
+	
+	/*
+	 * Check EBR addresses: The code saves previous EBR
+	 * placements from other software. But if our user
+	 * modifies the logical partition chain, we have to
+	 * fix those placements if needed.
+	 */
+	
+	link_t *link_ebr = link;
+	link_t *link_iter;
+	
+	mbr_part_t tmp_partition;
+	tmp_partition.length = 1;
+	
+	while (link_ebr != &label->parts->list.head) {
+		partition = list_get_instance(link_ebr, mbr_part_t, link);
+		
+		tmp_partition.start_addr = partition->ebr_addr;
+		
+		link_iter = link;
+		while (link_iter != &label->parts->list.head) {
+			/*
+			 * Check whether EBR address makes sense. If not, we take
+			 * a guess.  So far this is simple, we just take the first
+			 * preceeding sector. FDisk always reserves at least 2048
+			 * sectors (1 MiB), so it can have the EBR aligned as well
+			 * as the partition itself. Parted reserves minimum one
+			 * sector, like we do.
+			 *
+			 * Note that we know there is at least one sector free from
+			 * previous checks. Also note that the user can set ebr_addr
+			 * to their liking (if it is valid).
+			 */
+			
+			if ((partition->ebr_addr < base) ||
+			    (partition->ebr_addr >= base + extended->length) ||
+			    (check_overlap(&tmp_partition,
+			    list_get_instance(link_iter, mbr_part_t, link)))) {
+				partition->ebr_addr = partition->start_addr - 1;
 				break;
 			}
 			
-			l_iter = l_iter->next;
-		}
-		
-		l_ebr = l_ebr->next;
-	}
-	mbr_free_partition(tmp);
-	
-	/* Encoding and writing logical partitions */
-	while (l != &(label->parts->list.head)) {
-		p = list_get_instance(l, mbr_part_t, link);
-		
-		
-		encode_part(p, &(p->ebr->pte[0]), p->ebr_addr, false);
-		encode_part(p, &(prev_p->ebr->pte[1]), base, true);
-		
-		rc = block_write_direct(dev_handle, prev_p->ebr_addr, 1, prev_p->ebr);
-		if (rc != EOK) {
-			printf(LIBMBR_NAME ": Error while writing EBR: %d - %s.\n", rc, str_error(rc));
+			link_iter = link_iter->next;
+		}
+		
+		link_ebr = link_ebr->next;
+	}
+	
+	/* Encode and write logical partitions */
+	while (link != &label->parts->list.head) {
+		partition = list_get_instance(link, mbr_part_t, link);
+		
+		encode_part(partition, &partition->ebr->pte[0],
+		    partition->ebr_addr, false);
+		encode_part(partition, &prev_partition->ebr->pte[1],
+		    base, true);
+		
+		rc = block_write_direct(dev_handle, prev_partition->ebr_addr, 1,
+		    prev_partition->ebr);
+		if (rc != EOK)
 			goto end;
-		}
-		
-		prev_p = p;
-		l = l->next;
-	}
-	
-	/* write the last EBR */
-	encode_part(NULL, &(prev_p->ebr->pte[1]), 0, false);
-	rc = block_write_direct(dev_handle, prev_p->ebr_addr, 1, prev_p->ebr);
-	if (rc != EOK) {
-		printf(LIBMBR_NAME ": Error while writing EBR: %d - %s.\n", rc, str_error(rc));
-		goto end;
-	}
-	
-	rc = EOK;
+		
+		prev_partition = partition;
+		link = link->next;
+	}
+	
+	/* Write the last EBR */
+	encode_part(NULL, &prev_partition->ebr->pte[1], 0, false);
+	rc = block_write_direct(dev_handle, prev_partition->ebr_addr,
+	    1, prev_partition->ebr);
 	
 end:
 	block_fini(dev_handle);
-	
 	return rc;
 }
 
-/** mbr_part_t constructor */
-mbr_part_t * mbr_alloc_partition(void)
-{
-	mbr_part_t *p = malloc(sizeof(mbr_part_t));
-	if (p == NULL) {
+/** Partition constructor */
+mbr_part_t *mbr_alloc_partition(void)
+{
+	mbr_part_t *partition = malloc(sizeof(mbr_part_t));
+	if (partition == NULL)
 		return NULL;
-	}
-	
-	link_initialize(&(p->link));
-	p->ebr = NULL;
-	p->type = PT_UNUSED;
-	p->status = 0;
-	p->start_addr = 0;
-	p->length = 0;
-	p->ebr_addr = 0;
-	
-	return p;
-}
-
-/** mbr_partitions_t constructor */
-mbr_partitions_t * mbr_alloc_partitions(void)
+	
+	link_initialize(&partition->link);
+	partition->ebr = NULL;
+	partition->type = PT_UNUSED;
+	partition->status = 0;
+	partition->start_addr = 0;
+	partition->length = 0;
+	partition->ebr_addr = 0;
+	
+	return partition;
+}
+
+/** Partitions constructor */
+mbr_partitions_t *mbr_alloc_partitions(void)
 {
 	mbr_partitions_t *parts = malloc(sizeof(mbr_partitions_t));
-	if (parts == NULL) {
+	if (parts == NULL)
 		return NULL;
-	}
-	
-	list_initialize(&(parts->list));
+	
+	list_initialize(&parts->list);
 	parts->n_primary = 0;
 	parts->n_logical = 0;
 	parts->l_extended = NULL;
 	
-	/* add blank primary partitions */
-	int i;
-	mbr_part_t *p;
-	for (i = 0; i < N_PRIMARY; ++i) {
-		p = mbr_alloc_partition();
-		if (p == NULL) {
+	/* Add blank primary partitions */
+	for (unsigned int i = 0; i < N_PRIMARY; ++i) {
+		mbr_part_t *part = mbr_alloc_partition();
+		if (part == NULL) {
 			mbr_free_partitions(parts);
 			return NULL;
 		}
-		list_append(&(p->link), &(parts->list));
-	}
-	
-
+		
+		list_append(&part->link, &parts->list);
+	}
+	
 	return parts;
 }
 
 /** Add partition
- * 	Performs checks, sorts the list.
- * 
- * @param label			label to add to
- * @param p				partition to add
- * 
- * @return				ERR_OK (0) on success, other MBR_ERR_VAL otherwise
- */
-mbr_err_val mbr_add_partition(mbr_label_t *label, mbr_part_t *p)
-{
-	int rc1, rc2;
+ *
+ * Perform checks, sort the list.
+ *
+ * @param label Label to add to.
+ * @param part  Partition to add.
+ *
+ * @return ERR_OK on success, other MBR_ERR_VAL otherwise
+ *
+ */
+mbr_err_val mbr_add_partition(mbr_label_t *label, mbr_part_t *part)
+{
+	int rc = block_init(EXCHANGE_ATOMIC, label->device, 512);
+	if ((rc != EOK) && (rc != EEXIST))
+		return ERR_LIBBLOCK;
+	
 	aoff64_t nblocks;
-	
-	rc1 = block_init(EXCHANGE_ATOMIC, label->device, 512);
-	if (rc1 != EOK && rc1 != EEXIST) {
-		printf(LIBMBR_NAME ": Error during libblock init: %d - %s.\n", rc1, str_error(rc1));
+	int ret = block_get_nblocks(label->device, &nblocks);
+	
+	if (rc != EEXIST)
+		block_fini(label->device);
+	
+	if (ret != EOK)
 		return ERR_LIBBLOCK;
-	}
-	
-	rc2 = block_get_nblocks(label->device, &nblocks);
-	
-	if (rc1 != EEXIST)
-		block_fini(label->device);
-	
-	if (rc2 != EOK) {
-		printf(LIBMBR_NAME ": Error while getting number of blocks: %d - %s.\n", rc2, str_error(rc2));
-		return ERR_LIBBLOCK;
-	}
-	
-	if ((aoff64_t) p->start_addr + p->length > nblocks)
+	
+	if ((aoff64_t) part->start_addr + part->length > nblocks)
 		return ERR_OUT_BOUNDS;
 	
@@ -455,67 +432,76 @@
 		label->parts = mbr_alloc_partitions();
 		if (label->parts == NULL)
-			return ENOMEM; //FIXME! merge mbr_err_val into errno.h
-	}
-	
-	if (mbr_get_flag(p, ST_LOGIC))
-		/* adding logical partition */
-		return mbr_add_logical(label, p);
+			// FIXME! merge mbr_err_val into errno.h
+			return ENOMEM;
+	}
+	
+	if (mbr_get_flag(part, ST_LOGIC))
+		return mbr_add_logical(label, part);
 	else
-		/* adding primary */
-		return mbr_add_primary(label, p);
+		return mbr_add_primary(label, part);
 }
 
 /** Remove partition
- * 	Removes partition by index, indexed from zero. When removing extended
- *  partition, all logical partitions get removed as well.
- * 
- * @param label			label to remove from
- * @param idx			index of the partition to remove
- * 
- * @return				EOK on success, EINVAL if idx invalid
+ *
+ * Remove partition (indexed from zero). When removing the extended
+ * partition, all logical partitions get removed as well.
+ *
+ * @param label Label to remove from.
+ * @param idx   Index of the partition to remove.
+ *
+ * @return EOK on success.
+ * @return EINVAL if the index is invalid.
+ *
  */
 int mbr_remove_partition(mbr_label_t *label, size_t idx)
 {
-	link_t *l = list_nth(&(label->parts->list), idx);
-	if (l == NULL)
+	link_t *link = list_nth(&label->parts->list, idx);
+	if (link == NULL)
 		return EINVAL;
 	
-	mbr_part_t *p;
-	
-	/* If we're removing an extended partition, remove all logical as well */
-	if (l == label->parts->l_extended) {
+	/*
+	 * If removing the extended partition, remove all
+	 * logical partitions as well.
+	 */
+	if (link == label->parts->l_extended) {
 		label->parts->l_extended = NULL;
 		
-		link_t *it = l->next;
-		link_t *next_it;
-		while (it != &(label->parts->list.head)) {
-			next_it = it->next;
+		link_t *iterator = link->next;
+		link_t *next;
+		
+		while (iterator != &label->parts->list.head) {
+			next = iterator->next;
+			mbr_part_t *partition =
+			    list_get_instance(iterator, mbr_part_t, link);
 			
-			p = list_get_instance(it, mbr_part_t, link);
-			if (mbr_get_flag(p, ST_LOGIC)) {
-				list_remove(it);
-				label->parts->n_logical -= 1;
-				mbr_free_partition(p);
+			if (mbr_get_flag(partition, ST_LOGIC)) {
+				list_remove(iterator);
+				label->parts->n_logical--;
+				mbr_free_partition(partition);
 			}
 			
-			it = next_it;
-		}
-		
+			iterator = next;
+		}
 	}
 	
 	/* Remove the partition itself */
-	p = list_get_instance(l, mbr_part_t, link);
-	if (mbr_get_flag(p, ST_LOGIC)) {
-		label->parts->n_logical -= 1;
-		list_remove(l);
-		mbr_free_partition(p);
+	mbr_part_t *partition =
+	    list_get_instance(link, mbr_part_t, link);
+	
+	if (mbr_get_flag(partition, ST_LOGIC)) {
+		label->parts->n_logical--;
+		list_remove(link);
+		mbr_free_partition(partition);
 	} else {
-		/* Cannot remove primary - it would break ordering, just zero it */
-		label->parts->n_primary -= 1;
-		p->type = 0;
-		p->status = 0;
-		p->start_addr = 0;
-		p->length = 0;
-		p->ebr_addr = 0;
+		/*
+		 * Cannot remove a primary partition without
+		 * breaking the ordering. Just zero it.
+		 */
+		label->parts->n_primary--;
+		partition->type = 0;
+		partition->status = 0;
+		partition->start_addr = 0;
+		partition->length = 0;
+		partition->ebr_addr = 0;
 	}
 	
@@ -523,29 +509,26 @@
 }
 
-/** mbr_part_t destructor */
-void mbr_free_partition(mbr_part_t *p)
-{
-	if (p->ebr != NULL)
-		free(p->ebr);
-	free(p);
-}
-
-/** Get flag bool value */
-int mbr_get_flag(mbr_part_t *p, MBR_FLAGS flag)
-{
-	return (p->status & (1 << flag)) ? 1 : 0;
-}
-
-/** Set a specifig status flag to a value */
-void mbr_set_flag(mbr_part_t *p, MBR_FLAGS flag, bool value)
-{
-	uint16_t status = p->status;
-
-	if (value)
-		status = status | (1 << flag);
+/** Partition destructor */
+void mbr_free_partition(mbr_part_t *partition)
+{
+	if (partition->ebr != NULL)
+		free(partition->ebr);
+	
+	free(partition);
+}
+
+/** Check for flag */
+int mbr_get_flag(mbr_part_t *partition, mbr_flags_t flag)
+{
+	return (partition->status & (1 << flag));
+}
+
+/** Set a specific status flag */
+void mbr_set_flag(mbr_part_t *partition, mbr_flags_t flag, bool set)
+{
+	if (set)
+		partition->status |= 1 << flag;
 	else
-		status = status ^ (status & (1 << flag));
-
-	p->status = status;
+		partition->status &= ~((uint16_t) (1 << flag));
 }
 
@@ -553,20 +536,19 @@
 uint32_t mbr_get_next_aligned(uint32_t addr, unsigned int alignment)
 {
-	uint32_t div = addr / alignment;
-	return (div + 1) * alignment;
-}
-
-list_t * mbr_get_list(mbr_label_t *label)
+	return ALIGN_UP(addr + 1, alignment);
+}
+
+list_t *mbr_get_list(mbr_label_t *label)
 {
 	if (label->parts != NULL)
-		return &(label->parts->list);
+		return &label->parts->list;
 	else
 		return NULL;
 }
 
-mbr_part_t * mbr_get_first_partition(mbr_label_t *label)
+mbr_part_t *mbr_get_first_partition(mbr_label_t *label)
 {
 	list_t *list = mbr_get_list(label);
-	if (list != NULL && !list_empty(list))
+	if ((list != NULL) && (!list_empty(list)))
 		return list_get_instance(list->head.next, mbr_part_t, link);
 	else
@@ -574,14 +556,13 @@
 }
 
-mbr_part_t * mbr_get_next_partition(mbr_label_t *label, mbr_part_t *p)
+mbr_part_t *mbr_get_next_partition(mbr_label_t *label, mbr_part_t *partition)
 {
 	list_t *list = mbr_get_list(label);
-	if (list != NULL && &(p->link) != list_last(list))
-		return list_get_instance(p->link.next, mbr_part_t, link);
+	if ((list != NULL) && (&partition->link != list_last(list)))
+		return list_get_instance(partition->link.next, mbr_part_t, link);
 	else
 		return NULL;
 }
 
-/** Just a wrapper for free() */
 void mbr_free_mbr(mbr_t *mbr)
 {
@@ -591,20 +572,19 @@
 /** Free partition list
  *
- * @param parts		partition list to be freed
+ * @param parts Partition list to be freed
+ *
  */
 void mbr_free_partitions(mbr_partitions_t *parts)
 {
 	list_foreach_safe(parts->list, cur_link, next) {
-		mbr_part_t *p = list_get_instance(cur_link, mbr_part_t, link);
+		mbr_part_t *partition = list_get_instance(cur_link, mbr_part_t, link);
 		list_remove(cur_link);
-		mbr_free_partition(p);
-	}
-
+		mbr_free_partition(partition);
+	}
+	
 	free(parts);
 }
 
-/* Internal functions follow */
-
-static br_block_t *alloc_br()
+static br_block_t *alloc_br(void)
 {
 	br_block_t *br = malloc(sizeof(br_block_t));
@@ -618,104 +598,87 @@
 }
 
-/** Parse partition entry to mbr_part_t
- * @return		returns 1, if extended partition, 0 otherwise
- * */
-static int decode_part(pt_entry_t *src, mbr_part_t *trgt, uint32_t base)
-{
-	trgt->type = src->ptype;
-
-	trgt->status = (trgt->status & 0xFF00) | (uint16_t) src->status;
-
-	trgt->start_addr = uint32_t_le2host(src->first_lba) + base;
-	trgt->length = uint32_t_le2host(src->length);
-
-	return (src->ptype == PT_EXTENDED) ? 1 : 0;
-}
-
-/** Parse MBR contents to mbr_part_t list */
-static int decode_logical(mbr_label_t *label, mbr_part_t * ext)
-{
-	int rc;
-	mbr_part_t *p;
-
-	if (ext == NULL)
+/** Decode partition entry */
+static int decode_part(pt_entry_t *src, mbr_part_t *partition, uint32_t base)
+{
+	partition->type = src->ptype;
+	partition->status = (partition->status & 0xff00) | (uint16_t) src->status;
+	partition->start_addr = uint32_t_le2host(src->first_lba) + base;
+	partition->length = uint32_t_le2host(src->length);
+	
+	return (src->ptype == PT_EXTENDED);
+}
+
+/** Parse logical partitions */
+static int decode_logical(mbr_label_t *label, mbr_part_t *extended)
+{
+	if (extended == NULL)
 		return EOK;
-
-	uint32_t base = ext->start_addr;
+	
+	br_block_t *ebr = alloc_br();
+	if (ebr == NULL)
+		return ENOMEM;
+	
+	uint32_t base = extended->start_addr;
 	uint32_t addr = base;
-	br_block_t *ebr;
-	
-	rc = block_init(EXCHANGE_ATOMIC, label->device, 512);
+	
+	int rc = block_init(EXCHANGE_ATOMIC, label->device, 512);
 	if (rc != EOK)
-		return rc;
-	
-	ebr = alloc_br();
-	if (ebr == NULL) {
+		goto end;
+	
+	rc = block_read_direct(label->device, addr, 1, ebr);
+	if (rc != EOK)
+		goto end;
+	
+	if (uint16_t_le2host(ebr->signature) != BR_SIGNATURE) {
+		rc = EINVAL;
+		goto end;
+	}
+	
+	if (ebr->pte[0].ptype == PT_UNUSED) {
+		rc = EOK;
+		goto end;
+	}
+	
+	mbr_part_t *partition = mbr_alloc_partition();
+	if (partition == NULL) {
 		rc = ENOMEM;
 		goto end;
 	}
 	
-	rc = block_read_direct(label->device, addr, 1, ebr);
-	if (rc != EOK) {
-		goto free_ebr_end;
-	}
-	
-	if (uint16_t_le2host(ebr->signature) != BR_SIGNATURE) {
-		rc = EINVAL;
-		goto free_ebr_end;
-	}
-	
-	if (ebr->pte[0].ptype == PT_UNUSED) {
-		rc = EOK;
-		goto free_ebr_end;
-	}
-	
-	p = mbr_alloc_partition();
-	if (p == NULL) {
-		rc = ENOMEM;
-		goto free_ebr_end;
-	}
-	
-	decode_part(&(ebr->pte[0]), p, base);
-	mbr_set_flag(p, ST_LOGIC, true);
-	p->ebr = ebr;
-	p->ebr_addr = addr;
-	rc = mbr_add_partition(label, p);
-	if (rc != ERR_OK) 
-		return EINVAL;
+	decode_part(&ebr->pte[0], partition, base);
+	mbr_set_flag(partition, ST_LOGIC, true);
+	partition->ebr = ebr;
+	partition->ebr_addr = addr;
+	
+	rc = mbr_add_partition(label, partition);
+	if (rc != ERR_OK)
+		goto end;
 	
 	addr = uint32_t_le2host(ebr->pte[1].first_lba) + base;
 	
 	while (ebr->pte[1].ptype != PT_UNUSED) {
-		
-		ebr = alloc_br();
-		if (ebr == NULL) {
+		rc = block_read_direct(label->device, addr, 1, ebr);
+		if (rc != EOK)
+			goto end;
+		
+		if (uint16_t_le2host(ebr->signature) != BR_SIGNATURE) {
+			rc = EINVAL;
+			goto end;
+		}
+		
+		mbr_part_t *partition = mbr_alloc_partition();
+		if (partition == NULL) {
 			rc = ENOMEM;
 			goto end;
 		}
 		
-		rc = block_read_direct(label->device, addr, 1, ebr);
-		if (rc != EOK) {
-			goto free_ebr_end;
-		}
-		
-		if (uint16_t_le2host(ebr->signature) != BR_SIGNATURE) {
-			rc = EINVAL;
-			goto free_ebr_end;
-		}
-		
-		p = mbr_alloc_partition();
-		if (p == NULL) {
-			rc = ENOMEM;
-			goto free_ebr_end;
-		}
-		
-		decode_part(&(ebr->pte[0]), p, addr);
-		mbr_set_flag(p, ST_LOGIC, true);
-		p->ebr = ebr;
-		p->ebr_addr = addr;
-		rc = mbr_add_partition(label, p);
+		decode_part(&ebr->pte[0], partition, addr);
+		mbr_set_flag(partition, ST_LOGIC, true);
+		partition->ebr = ebr;
+		partition->ebr_addr = addr;
+		
+		rc = mbr_add_partition(label, partition);
 		if (rc != ERR_OK)
-			return EINVAL;
+			goto end;
 		
 		addr = uint32_t_le2host(ebr->pte[1].first_lba) + base;
@@ -723,10 +686,7 @@
 	
 	rc = EOK;
-	goto end;
-	
-free_ebr_end:
-	free(ebr);
 	
 end:
+	// FIXME possible memory leaks
 	block_fini(label->device);
 	
@@ -734,89 +694,86 @@
 }
 
-/** Convert mbr_part_t to pt_entry_t */
-static void encode_part(mbr_part_t * src, pt_entry_t * trgt, uint32_t base, bool ebr)
+/** Encode partition entry */
+static void encode_part(mbr_part_t *src, pt_entry_t *entry, uint32_t base,
+    bool ebr)
 {
 	if (src != NULL) {
-		trgt->status = (uint8_t) (src->status & 0xFF);
-		/* ingoring CHS */
-		trgt->first_chs[0] = 0xFE;
-		trgt->first_chs[1] = 0xFF;
-		trgt->first_chs[2] = 0xFF;
-		trgt->last_chs[0] = 0xFE;
-		trgt->last_chs[1] = 0xFF;
-		trgt->last_chs[2] = 0xFF;
-		if (ebr) {	/* encoding reference to EBR */
-			trgt->ptype = PT_EXTENDED_LBA;
-			trgt->first_lba = host2uint32_t_le(src->ebr_addr - base);
-			trgt->length = host2uint32_t_le(src->length + src->start_addr - src->ebr_addr);
-		} else {	/* encoding reference to partition */
-			trgt->ptype = src->type;
-			trgt->first_lba = host2uint32_t_le(src->start_addr - base);
-			trgt->length = host2uint32_t_le(src->length);
-		}
-		
-		if (trgt->ptype == PT_UNUSED)
-			memset(trgt, 0, sizeof(pt_entry_t));
-	} else {
-		memset(trgt, 0, sizeof(pt_entry_t));
-	}
-}
-
-/** Check whether two partitions overlap
- * 
- * @return		true/false
- */
-static bool check_overlap(mbr_part_t * p1, mbr_part_t * p2)
-{
-	if (p1->start_addr < p2->start_addr && p1->start_addr + p1->length <= p2->start_addr) {
+		entry->status = (uint8_t) src->status & 0xff;
+		
+		/* Ignore CHS */
+		entry->first_chs[0] = 0xfe;
+		entry->first_chs[1] = 0xff;
+		entry->first_chs[2] = 0xff;
+		entry->last_chs[0] = 0xfe;
+		entry->last_chs[1] = 0xff;
+		entry->last_chs[2] = 0xff;
+		
+		if (ebr) {
+			/* Encode reference to EBR */
+			entry->ptype = PT_EXTENDED_LBA;
+			entry->first_lba = host2uint32_t_le(src->ebr_addr - base);
+			entry->length = host2uint32_t_le(src->length + src->start_addr -
+			    src->ebr_addr);
+		} else {
+			/* Encode reference to partition */
+			entry->ptype = src->type;
+			entry->first_lba = host2uint32_t_le(src->start_addr - base);
+			entry->length = host2uint32_t_le(src->length);
+		}
+		
+		if (entry->ptype == PT_UNUSED)
+			memset(entry, 0, sizeof(pt_entry_t));
+	} else
+		memset(entry, 0, sizeof(pt_entry_t));
+}
+
+/** Check whether two partitions overlap */
+static bool check_overlap(mbr_part_t *part1, mbr_part_t *part2)
+{
+	if ((part1->start_addr < part2->start_addr) &&
+	    (part1->start_addr + part1->length <= part2->start_addr))
 		return false;
-	} else if (p1->start_addr > p2->start_addr && p2->start_addr + p2->length <= p1->start_addr) {
+	
+	if ((part1->start_addr > part2->start_addr) &&
+	    (part2->start_addr + part2->length <= part1->start_addr))
 		return false;
-	}
-
+	
 	return true;
 }
 
-/** Check whether one partition encapsulates the other
- * 
- * @return		true/false
- */
-static bool check_encaps(mbr_part_t * inner, mbr_part_t * outer)
-{
-	if (inner->start_addr <= outer->start_addr || outer->start_addr + outer->length <= inner->start_addr) {
+/** Check whether one partition encapsulates the other */
+static bool check_encaps(mbr_part_t *inner, mbr_part_t *outer)
+{
+	if ((inner->start_addr <= outer->start_addr) ||
+	    (outer->start_addr + outer->length <= inner->start_addr))
 		return false;
-	} else if (outer->start_addr + outer->length < inner->start_addr + inner->length) {
+	
+	if (outer->start_addr + outer->length < inner->start_addr + inner->length)
 		return false;
-	}
-
+	
 	return true;
 }
 
-/** Check whether one partition preceeds the other
- * 
- * @return		true/false
- */
-static bool check_preceeds(mbr_part_t * preceeder, mbr_part_t * precedee)
+/** Check whether one partition preceeds the other */
+static bool check_preceeds(mbr_part_t *preceeder, mbr_part_t *precedee)
 {
 	return preceeder->start_addr < precedee->start_addr;
 }
 
-mbr_err_val mbr_add_primary(mbr_label_t *label, mbr_part_t *p)
-{
-	if (label->parts->n_primary == 4) {
+mbr_err_val mbr_add_primary(mbr_label_t *label, mbr_part_t *part)
+{
+	if (label->parts->n_primary == 4)
 		return ERR_PRIMARY_FULL;
-	}
-	
-	/* Check if partition makes space for MBR itself. */
-	if (p->start_addr == 0) {
+	
+	/* Check if partition makes space for MBR itself */
+	if (part->start_addr == 0)
 		return ERR_OUT_BOUNDS;
-	}
-	
-	/* if it's extended, is there any other one? */
-	if ((p->type == PT_EXTENDED || p->type == PT_EXTENDED_LBA) && label->parts->l_extended != NULL) {
+	
+	/* If it is an extended partition, is there any other one? */
+	if (((part->type == PT_EXTENDED) || (part->type == PT_EXTENDED_LBA)) &&
+	    (label->parts->l_extended != NULL))
 		return ERR_EXTENDED_PRESENT;
-	}
-	
-	/* find a place and add it */
+	
+	/* Find a place and add it */
 	mbr_part_t *iter;
 	mbr_part_t *empty = NULL;
@@ -825,50 +782,56 @@
 			if (empty == NULL)
 				empty = iter;
-		} else if (check_overlap(p, iter))
+		} else if (check_overlap(part, iter))
 			return ERR_OVERLAP;
 	}
 	
-	list_insert_after(&(p->link), &(empty->link));
-	list_remove(&(empty->link));
+	list_insert_after(&part->link, &empty->link);
+	list_remove(&empty->link);
 	free(empty);
 	
-	label->parts->n_primary += 1;
-	
-	if (p->type == PT_EXTENDED || p->type == PT_EXTENDED_LBA)
-		label->parts->l_extended = &(p->link);
+	label->parts->n_primary++;
+	
+	if ((part->type == PT_EXTENDED) || (part->type == PT_EXTENDED_LBA))
+		label->parts->l_extended = &part->link;
 	
 	return EOK;
 }
 
-mbr_err_val mbr_add_logical(mbr_label_t *label, mbr_part_t *p)
-{
-	/* is there any extended partition? */
+mbr_err_val mbr_add_logical(mbr_label_t *label, mbr_part_t *part)
+{
+	/* Is there any extended partition? */
 	if (label->parts->l_extended == NULL)
 		return ERR_NO_EXTENDED;
 	
-	/* is the logical partition inside the extended one? */
-	mbr_part_t *ext = list_get_instance(label->parts->l_extended, mbr_part_t, link);
-	if (!check_encaps(p, ext))
+	/* Is the logical partition inside the extended partition? */
+	mbr_part_t *extended = list_get_instance(label->parts->l_extended, mbr_part_t, link);
+	if (!check_encaps(part, extended))
 		return ERR_OUT_BOUNDS;
 	
-	/* find a place for the new partition in a sorted linked list */
+	/* Find a place for the new partition in a sorted linked list */
 	bool first_logical = true;
 	mbr_part_t *iter;
 	mbr_part_foreach (label, iter) {
 		if (mbr_get_flag(iter, ST_LOGIC)) {
-			if (check_overlap(p, iter)) 
+			if (check_overlap(part, iter))
 				return ERR_OVERLAP;
-			if (check_preceeds(iter, p)) {
-				/* checking if there's at least one sector of space preceeding */
-				if ((iter->start_addr + iter->length) >= p->start_addr - 1)
+			
+			if (check_preceeds(iter, part)) {
+				/* Check if there is at least one sector of space preceeding */
+				if ((iter->start_addr + iter->length) >= part->start_addr - 1)
 					return ERR_NO_EBR;
-			} else if (first_logical){
-				/* First logical partition's EBR is before every other
-				 * logical partition. Thus we don't check if this partition
-				 * leaves enough space for it. */
+			} else if (first_logical) {
+				/*
+				 * First logical partition's EBR is before every other
+				 * logical partition. Thus we do not check if this partition
+				 * leaves enough space for it.
+				 */
 				first_logical = false;
 			} else {
-				/* checking if there's at least one sector of space following (for following partitions's EBR) */
-				if ((p->start_addr + p->length) >= iter->start_addr - 1)
+				/*
+				 * Check if there is at least one sector of space following
+				 * (for following partitions's EBR).
+				 */
+				if ((part->start_addr + part->length) >= iter->start_addr - 1)
 					return ERR_NO_EBR;
 			}
@@ -876,19 +839,14 @@
 	}
 	
-	/* alloc EBR if it's not already there */
-	if (p->ebr == NULL) {
-		p->ebr = alloc_br();
-		if (p->ebr == NULL) {
+	/* Allocate EBR if it is not already there */
+	if (part->ebr == NULL) {
+		part->ebr = alloc_br();
+		if (part->ebr == NULL)
 			return ERR_NOMEM;
-		}
-	}
-	
-	/* add it */
-	list_append(&(p->link), &(label->parts->list));
-	label->parts->n_logical += 1;
+	}
+	
+	list_append(&part->link, &label->parts->list);
+	label->parts->n_logical++;
 	
 	return EOK;
 }
-
-
-
Index: uspace/lib/mbr/libmbr.h
===================================================================
--- uspace/lib/mbr/libmbr.h	(revision d51beba3dc7e6298f4b9692cbba4886d50303d39)
+++ uspace/lib/mbr/libmbr.h	(revision 6453e30691421828634cd3f671e5840773c9ff46)
@@ -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.
  *
@@ -28,5 +28,5 @@
  */
 
- /** @addtogroup libmbr
+/** @addtogroup libmbr
  * @{
  */
@@ -40,5 +40,11 @@
 #include "mbr.h"
 
-#define LIBMBR_NAME	"libmbr"
+/*
+ * WARNING: When changing both header and partitions, write first header,
+ * then partitions. The MBR headers' raw_data is not updated to follow
+ * partition changes.
+ *
+ * NOTE: Writing partitions writes the complete header as well.
+ */
 
 typedef enum {
@@ -48,5 +54,5 @@
 	/** Logical partition, 0 = primary, 1 = logical*/
 	ST_LOGIC = 8
-} MBR_FLAGS;
+} mbr_flags_t;
 
 typedef enum {
@@ -77,5 +83,4 @@
 } mbr_t;
 
-
 /** Partition */
 typedef struct mbr_part {
@@ -91,5 +96,5 @@
 	uint32_t length;
 	/** Points to Extended Boot Record of logical partition */
-	br_block_t * ebr;
+	br_block_t *ebr;
 	/** EBR address */
 	uint32_t ebr_addr;
@@ -101,5 +106,5 @@
 	unsigned char n_primary;
 	/** Index to the extended partition in the array */
-	link_t * l_extended;
+	link_t *l_extended;
 	/** Number of logical partitions */
 	unsigned int n_logical;
@@ -111,5 +116,5 @@
 typedef struct mbr_label {
 	/** MBR header */
-	mbr_t * mbr;
+	mbr_t *mbr;
 	/** Partition list */
 	mbr_partitions_t * parts;
@@ -118,39 +123,30 @@
 } mbr_label_t;
 
-/* Alloc complete label structure */
-extern mbr_label_t * mbr_alloc_label(void);
+#define mbr_part_foreach(label, iterator) \
+	for (iterator = list_get_instance((label)->parts->list.head.next, mbr_part_t, link); \
+	    iterator != list_get_instance(&((label)->parts->list.head), mbr_part_t, link); \
+	    iterator = list_get_instance(iterator->link.next, mbr_part_t, link))
+
+extern mbr_label_t *mbr_alloc_label(void);
+
 extern void mbr_set_device(mbr_label_t *, service_id_t);
-
-/* Read/Write MBR header.
- * WARNING: when changing both header and partitions, write first header,
- * then partitions. The MBR headers' raw_data is NOT updated to follow
- * partition changes. */
-extern mbr_t * mbr_alloc_mbr(void);
+extern mbr_t *mbr_alloc_mbr(void);
 extern int mbr_read_mbr(mbr_label_t *, service_id_t);
 extern int mbr_write_mbr(mbr_label_t *, service_id_t);
 extern int mbr_is_mbr(mbr_label_t *);
 
-/* Read/Write/Set MBR partitions.
- * NOTE: Writing partitions writes the complete header as well. */
-extern int          mbr_read_partitions(mbr_label_t *);
-extern int          mbr_write_partitions(mbr_label_t *, service_id_t);
-extern mbr_part_t * mbr_alloc_partition(void);
-extern mbr_partitions_t * mbr_alloc_partitions(void);
-extern mbr_err_val  mbr_add_partition(mbr_label_t *, mbr_part_t *);
-extern int          mbr_remove_partition(mbr_label_t *, size_t);
-extern int          mbr_get_flag(mbr_part_t *, MBR_FLAGS);
-extern void         mbr_set_flag(mbr_part_t *, MBR_FLAGS, bool);
-extern uint32_t     mbr_get_next_aligned(uint32_t, unsigned int);
-extern list_t *     mbr_get_list(mbr_label_t *);
-extern mbr_part_t * mbr_get_first_partition(mbr_label_t *);
-extern mbr_part_t * mbr_get_next_partition(mbr_label_t *, mbr_part_t *);
+extern int mbr_read_partitions(mbr_label_t *);
+extern int mbr_write_partitions(mbr_label_t *, service_id_t);
+extern mbr_part_t *mbr_alloc_partition(void);
+extern mbr_partitions_t *mbr_alloc_partitions(void);
+extern mbr_err_val mbr_add_partition(mbr_label_t *, mbr_part_t *);
+extern int mbr_remove_partition(mbr_label_t *, size_t);
+extern int mbr_get_flag(mbr_part_t *, mbr_flags_t);
+extern void mbr_set_flag(mbr_part_t *, mbr_flags_t, bool);
+extern uint32_t mbr_get_next_aligned(uint32_t, unsigned int);
+extern list_t *mbr_get_list(mbr_label_t *);
+extern mbr_part_t *mbr_get_first_partition(mbr_label_t *);
+extern mbr_part_t *mbr_get_next_partition(mbr_label_t *, mbr_part_t *);
 
-#define mbr_part_foreach(label, iterator) \
-        for (iterator  = list_get_instance((label)->parts->list.head.next, mbr_part_t, link); \
-             iterator != list_get_instance(&((label)->parts->list.head), mbr_part_t, link); \
-             iterator  = list_get_instance(iterator->link.next, mbr_part_t, link))
-
-
-/* free() wrapper functions. */
 extern void mbr_free_label(mbr_label_t *);
 extern void mbr_free_mbr(mbr_t *);
@@ -159,3 +155,2 @@
 
 #endif
-
Index: uspace/lib/mbr/mbr.h
===================================================================
--- uspace/lib/mbr/mbr.h	(revision d51beba3dc7e6298f4b9692cbba4886d50303d39)
+++ uspace/lib/mbr/mbr.h	(revision 6453e30691421828634cd3f671e5840773c9ff46)
@@ -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.
  *
@@ -39,9 +39,11 @@
 #include <sys/types.h>
 
-/** Number of primary partition records */
-#define N_PRIMARY		4
-
-/** Boot record signature */
-#define BR_SIGNATURE	0xAA55
+enum {
+	/** Number of primary partition records */
+	N_PRIMARY = 4,
+	
+	/** Boot record signature */
+	BR_SIGNATURE = 0xAA55
+};
 
 enum {
@@ -55,11 +57,11 @@
 enum {
 	/** Unused partition entry */
-	PT_UNUSED	= 0x00,
+	PT_UNUSED = 0x00,
 	/** Extended partition */
-	PT_EXTENDED	= 0x05,
+	PT_EXTENDED = 0x05,
 	/** Extended partition with LBA */
-	PT_EXTENDED_LBA	= 0x0F,
+	PT_EXTENDED_LBA = 0x0F,
 	/** GPT Protective partition */
-	PT_GPT	= 0xEE,
+	PT_GPT = 0xEE,
 };
 
