Index: uspace/app/hdisk/func_gpt.c
===================================================================
--- uspace/app/hdisk/func_gpt.c	(revision c3cbbb2a143977e56be842336794a3a84e70279d)
+++ uspace/app/hdisk/func_gpt.c	(revision dc76f4a6d7e0da45038149275644c9fbe876bd84)
@@ -42,5 +42,5 @@
 #include "input.h"
 
-static int set_gpt_partition(tinput_t *, gpt_part_t *);
+static int set_gpt_partition(tinput_t *, gpt_part_t *, unsigned int);
 
 int construct_gpt_label(label_t *this)
@@ -68,5 +68,5 @@
 	}
 	
-	return set_gpt_partition(in, p);
+	return set_gpt_partition(in, p, this->alignment);
 }
 
@@ -80,7 +80,10 @@
 	
 	rc = gpt_remove_partition(this->data.gpt, idx);
-	if (rc != EOK) {
+	if (rc == ENOMEM) {
 		printf("Warning: running low on memory, not resizing...\n");
 		return rc;
+	} else if (rc == EINVAL) {
+		printf("Invalid index.\n");
+		return rc;
 	}
 	
@@ -102,7 +105,6 @@
 int print_gpt_parts(label_t *this)
 {
-	//int rc;
 	printf("Current partition scheme (GPT):\n");
-	printf("\t\tStart:\tEnd:\tLength:\tType:\tName:\n");
+	printf("%15s %10s %10s Type: Name:\n", "Start:", "End:", "Length:");
 	
 	size_t i = 0;
@@ -117,6 +119,5 @@
 			printf("%15s %10s %10s Type: Name:\n", "Start:", "End:", "Length:");
 		
-		//printf("\t%10u %10u %10u %3d\n", iter->start_addr, iter->start_addr + iter->length,
-		//		iter->length, gpt_get_part_type(iter), gpt_get_part_name(iter));
+		
 		printf("%3u  %10llu %10llu %10llu    %3d %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),
@@ -125,5 +126,4 @@
 	}
 	
-	//return rc;
 	return EOK;
 }
@@ -173,5 +173,5 @@
 }
 
-static int set_gpt_partition(tinput_t *in, gpt_part_t *p)
+static int set_gpt_partition(tinput_t *in, gpt_part_t *p, unsigned int alignment)
 {
 	int rc;
@@ -181,4 +181,6 @@
 	printf("Set starting address (number): ");
 	sa = get_input_uint64(in);
+	if (sa % alignment != 0)
+		sa = gpt_get_next_aligned(sa, alignment);
 	
 	printf("Set end addres (number): ");
Index: uspace/app/hdisk/hdisk.c
===================================================================
--- uspace/app/hdisk/hdisk.c	(revision c3cbbb2a143977e56be842336794a3a84e70279d)
+++ uspace/app/hdisk/hdisk.c	(revision dc76f4a6d7e0da45038149275644c9fbe876bd84)
@@ -178,5 +178,4 @@
 				break;
 			case 'f':
-				free_label();
 				select_label_format(in);
 				break;
Index: uspace/lib/gpt/gpt.h
===================================================================
--- uspace/lib/gpt/gpt.h	(revision dc76f4a6d7e0da45038149275644c9fbe876bd84)
+++ uspace/lib/gpt/gpt.h	(revision dc76f4a6d7e0da45038149275644c9fbe876bd84)
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2009 Jiri Svoboda
+ * Copyright (c) 2011, 2012, 2013 Dominik Taborsky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libgpt
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBGPT_GPT_H_
+#define LIBGPT_GPT_H_
+
+typedef enum {
+	AT_REQ_PART = 0,
+	AT_NO_BLOCK_IO,
+	AT_LEGACY_BOOT,
+	AT_UNDEFINED,
+	AT_SPECIFIC = 48
+} GPT_ATTR;
+
+/** GPT header
+ * - all in little endian.
+ */
+typedef struct {
+	uint8_t  efi_signature[8];
+	uint32_t revision;
+	uint32_t header_size;
+	uint32_t header_crc32;
+	uint32_t reserved;
+	uint64_t my_lba;
+	uint64_t alternate_lba;
+	uint64_t first_usable_lba;
+	uint64_t last_usable_lba;
+	uint8_t  disk_guid[16];
+	uint64_t entry_lba;
+	uint32_t fillries;
+	uint32_t entry_size;
+	uint32_t pe_array_crc32;
+} __attribute__((packed)) gpt_header_t;
+
+/** GPT partition entry */
+typedef struct {
+	uint8_t part_type[16];
+	uint8_t part_id[16];
+	uint64_t start_lba;
+	uint64_t end_lba;
+	uint64_t attributes;
+	uint8_t part_name[72];
+} __attribute__((packed)) gpt_entry_t;
+
+#endif
+
+
Index: uspace/lib/gpt/libgpt.c
===================================================================
--- uspace/lib/gpt/libgpt.c	(revision c3cbbb2a143977e56be842336794a3a84e70279d)
+++ uspace/lib/gpt/libgpt.c	(revision dc76f4a6d7e0da45038149275644c9fbe876bd84)
@@ -51,11 +51,11 @@
 #include "libgpt.h"
 
-static int load_and_check_header(service_id_t handle, aoff64_t addr, size_t b_size, gpt_header_t *header);
-static gpt_partitions_t * alloc_part_array(uint32_t num);
+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 int extend_part_array(gpt_partitions_t *);
 static int reduce_part_array(gpt_partitions_t *);
-static long long nearest_larger_int(double a);
+//static long long nearest_larger_int(double);
 static uint8_t get_byte(const char *);
-static int check_overlap(gpt_part_t * p1, gpt_part_t * p2);
+static bool check_overlap(gpt_part_t *, gpt_part_t *);
 
 /** Allocate memory for gpt label */
@@ -66,6 +66,13 @@
 		return NULL;
 	
+	/* This is necessary so that gpt_part_foreach does not segfault */
+	label->parts = gpt_alloc_partitions();
+	if (label == NULL) {
+		free(label);
+		return NULL;
+	}
+	
 	label->gpt = NULL;
-	label->parts = NULL;
+	
 	label->device = 0;
 	
@@ -92,7 +99,8 @@
 		return NULL;
 	
-	// We might need only sizeof(gpt_header_t),
-	// but we should follow specs and have
-	// zeroes through all the rest of the block
+	/* 
+	 * 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);
 	gpt->header = malloc(final_size);
@@ -178,24 +186,14 @@
 	int rc;
 	size_t b_size;
-
-	label->gpt->header->header_crc32 = 0;
-	label->gpt->header->header_crc32 = compute_crc32((uint8_t *) label->gpt->header,
-					uint32_t_le2host(label->gpt->header->header_size));
-
-	rc = block_init(EXCHANGE_ATOMIC, dev_handle, b_size);
+	
+	/* The comm_size argument (the last one) is ignored */
+	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;
-
-	/* Write to main GPT header location */
-	rc = block_write_direct(dev_handle, GPT_HDR_BA, GPT_HDR_BS, label->gpt->header);
-	if (rc != EOK) {
-		block_fini(dev_handle);
-		return rc;
-	}
-
+	
 	aoff64_t n_blocks;
 	rc = block_get_nblocks(dev_handle, &n_blocks);
@@ -204,12 +202,48 @@
 		return rc;
 	}
-
+	
+	uint64_t tmp;
+	
+	/* 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->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)));
+	
 	/* Write to backup GPT header location */
-	//FIXME: those idiots thought it would be cool to have these fields in reverse order...
 	rc = block_write_direct(dev_handle, n_blocks - 1, GPT_HDR_BS, label->gpt->header);
+	if (rc != EOK) {
+		block_fini(dev_handle);
+		return rc;
+	}
+	
+	
+	/* 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->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)));
+	
+	/* Write to main GPT header location */
+	rc = block_write_direct(dev_handle, GPT_HDR_BA, GPT_HDR_BS, label->gpt->header);
 	block_fini(dev_handle);
 	if (rc != EOK)
 		return rc;
-
+	
+	
 	return 0;
 }
@@ -218,5 +252,5 @@
 gpt_partitions_t * gpt_alloc_partitions()
 {
-	return alloc_part_array(128);
+	return alloc_part_array(GPT_MIN_PART_NUM);
 }
 
@@ -241,7 +275,4 @@
 	}
 
-	/* We can limit comm_size like this:
-	 *  - we don't need more bytes
-	 *  - the size of GPT partition entry can be different to 128 bytes */
 	/* comm_size is ignored */
 	rc = block_init(EXCHANGE_SERIALIZE, label->device, sizeof(gpt_entry_t));
@@ -258,14 +289,18 @@
 	aoff64_t pos = ent_lba * block_size;
 
-	/* Now we read just sizeof(gpt_entry_t) bytes for each entry from the device.
+	/* 
+	 * 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) */
+	 * don't break backward compatibility) 
+	 */
 	for (i = 0; i < fillries; ++i) {
-		//FIXME: this does bypass cache...
+		/*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));
+		/* 
+		 * FIXME: but seqread() is just too complex...
+		 * rc = block_seqread(gpt->device, &bufpos, &buflen, &pos, res->part_array[i], sizeof(gpt_entry_t));
+		 */
 		pos += ent_size;
 
@@ -274,5 +309,6 @@
 	}
 
-	/* FIXME: so far my boasting about variable partition entry size
+	/*
+	 * FIXME: so far my boasting about variable partition entry size
 	 * will not work. The CRC32 checksums will be different.
 	 * This can't be fixed easily - we'd have to run the checksum
@@ -333,6 +369,12 @@
 		goto fail;
 	
+	uint64_t arr_blocks = (fillries * sizeof(gpt_entry_t)) / b_size;
+	label->gpt->header->first_usable_lba = host2uint64_t_le(arr_blocks + 1);
+	label->gpt->header->last_usable_lba = host2uint64_t_le(n_blocks - arr_blocks - 2);
+	
+	
 	/* Write to backup GPT partition array location */
-	//rc = block_write_direct(dev_handle, n_blocks - 1, GPT_HDR_BS, header->raw_data);
+	rc = block_write_direct(dev_handle, n_blocks - arr_blocks - 1, 
+	         arr_blocks, label->parts->part_array);
 	if (rc != EOK)
 		goto fail;
@@ -340,6 +382,5 @@
 	/* Write to main GPT partition array location */
 	rc = block_write_direct(dev_handle, uint64_t_le2host(label->gpt->header->entry_lba),
-	         nearest_larger_int((uint64_t_le2host(label->gpt->header->entry_size) * fillries) / b_size),
-	         label->parts->part_array);
+	         arr_blocks, label->parts->part_array);
 	if (rc != EOK)
 		goto fail;
@@ -442,11 +483,5 @@
 int gpt_add_partition(gpt_label_t *label, gpt_part_t *partition)
 {
-	if (label->parts->fill == label->parts->arr_size) {
-		if (extend_part_array(label->parts) == -1)
-			return ENOMEM;
-	}
-	
-	/*FIXME:
-	 * Check dimensions and stuff! */
+	/* FIXME: Check dimensions! */
 	gpt_part_foreach(label, p) {
 		if (gpt_get_part_type(p) != GPT_PTE_UNUSED) {
@@ -456,7 +491,18 @@
 	}
 	
-	memcpy(label->parts->part_array + label->parts->fill++,
-	       partition, sizeof(gpt_part_t));
-	
+	gpt_part_t *p;
+	/* Find the first empty entry */
+	do {
+		if (label->parts->fill == label->parts->arr_size) {
+			if (extend_part_array(label->parts) == -1)
+				return ENOMEM;
+		}
+		
+		p = label->parts->part_array + label->parts->fill++;
+		
+	} while (gpt_get_part_type(p) != GPT_PTE_UNUSED);
+	
+	
+	memcpy(p, partition, sizeof(gpt_entry_t));
 	
 	
@@ -475,20 +521,27 @@
 int gpt_remove_partition(gpt_label_t *label, size_t idx)
 {
-	if (idx >= label->parts->fill)
+	if (idx >= label->parts->arr_size)
 		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.*/
+	 * the first 128 partitions, we would forget to write the last one.
+	 */
 	memset(label->parts->part_array + idx, 0, sizeof(gpt_entry_t));
 	
-	label->parts->fill = idx;
-	
-	/* FIXME! HOPEFULLY FIXED.
+	if (label->parts->fill > idx)
+		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. */
+	 * there since we allow blank spots. 
+	 */
 	gpt_part_t * p;
-	if (label->parts->fill < (label->parts->arr_size / 2) - GPT_IGNORE_FILL_NUM) {
+	
+	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) {
@@ -635,4 +688,7 @@
 }
 
+/** Generate a new pseudo-random UUID
+ * @param uuid Pointer to the UUID to overwrite.
+ */
 void gpt_set_random_uuid(uint8_t * uuid)
 {
@@ -645,5 +701,12 @@
 }
 
-// Internal functions follow //
+/** Get next aligned address */
+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)
@@ -686,5 +749,5 @@
 		return NULL;
 	}
-
+	
 	uint32_t size = num > GPT_BASE_PART_NUM ? num : GPT_BASE_PART_NUM;
 	res->part_array = malloc(size * sizeof(gpt_entry_t));
@@ -694,5 +757,7 @@
 		return NULL;
 	}
-
+	
+	memset(res->part_array, 0, size * sizeof(gpt_entry_t));
+	
 	res->fill = 0;
 	res->arr_size = num;
@@ -727,5 +792,5 @@
 			return ENOMEM;
 
-		memcpy(tmp, p->part_array, p->fill < nsize ? p->fill  : nsize);
+		memcpy(tmp, p->part_array, p->fill < nsize ? p->fill : nsize);
 		free(p->part_array);
 		p->part_array = tmp;
@@ -736,6 +801,5 @@
 }
 
-//FIXME: replace this with a library call, if it exists
-static long long nearest_larger_int(double a)
+/*static long long nearest_larger_int(double a)
 {
 	if ((long long) a == a) {
@@ -744,6 +808,9 @@
 
 	return ((long long) a) + 1;
-}
-
+}*/
+
+/* Parse a byte from a string in hexadecimal 
+ * i.e., "FF" => 255 
+ */
 static uint8_t get_byte(const char * c)
 {
@@ -755,14 +822,14 @@
 }
 
-static int check_overlap(gpt_part_t * p1, gpt_part_t * p2)
+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)) {
-		return 0;
+		return false;
 	} else if (gpt_get_start_lba(p1) > gpt_get_start_lba(p2) && gpt_get_end_lba(p2) <= gpt_get_start_lba(p1)) {
-		return 0;
-	}
-
-	return 1;
-}
-
-
+		return false;
+	}
+
+	return true;
+}
+
+
Index: uspace/lib/gpt/libgpt.h
===================================================================
--- uspace/lib/gpt/libgpt.h	(revision c3cbbb2a143977e56be842336794a3a84e70279d)
+++ uspace/lib/gpt/libgpt.h	(revision dc76f4a6d7e0da45038149275644c9fbe876bd84)
@@ -34,6 +34,6 @@
  */
 
-#ifndef __GPT_H__
-#define __GPT_H__
+#ifndef LIBGPT_LIBGPT_H_
+#define LIBGPT_LIBGPT_H_
 
 #define LIBGPT_NAME	"libgpt"
@@ -41,4 +41,6 @@
 #include <loc.h>
 #include <sys/types.h>
+
+#include "gpt.h"
 
 /** Block address of GPT header. */
@@ -59,32 +61,4 @@
 extern const uint8_t efi_signature[8];
 
-typedef enum {
-	AT_REQ_PART = 0,
-	AT_NO_BLOCK_IO,
-	AT_LEGACY_BOOT,
-	AT_UNDEFINED,
-	AT_SPECIFIC = 48
-} GPT_ATTR;
-
-/** GPT header
- * - all in little endian.
- */
-typedef struct {
-	uint8_t  efi_signature[8];
-	uint32_t revision;
-	uint32_t header_size;
-	uint32_t header_crc32;
-	uint32_t reserved;
-	uint64_t my_lba;
-	uint64_t alternate_lba;
-	uint64_t first_usable_lba;
-	uint64_t last_usable_lba;
-	uint8_t  disk_guid[16];
-	uint64_t entry_lba;
-	uint32_t fillries;
-	uint32_t entry_size;
-	uint32_t pe_array_crc32;
-} __attribute__((packed)) gpt_header_t;
-
 typedef struct {
 	/** Raw header. Has more bytes alloced than sizeof(gpt_header_t)!
@@ -93,27 +67,5 @@
 } gpt_t;
 
-/** GPT partition entry */
-typedef struct {
-	uint8_t part_type[16];
-	uint8_t part_id[16];
-	uint64_t start_lba;
-	uint64_t end_lba;
-	uint64_t attributes;
-	uint8_t part_name[72];
-} __attribute__((packed)) gpt_entry_t;
-
-
-//typedef struct g_part {
-	///** Partition entry is in use **/
-	//bool present;
-	///** Address of first block */
-	//aoff64_t start_addr;
-	///** Number of blocks */
-	//aoff64_t length;
-	///** Raw data access */
-	//gpt_entry_t raw_data;	//TODO: a pointer or just a member?
-//}gpt_part_t;
 typedef gpt_entry_t gpt_part_t;
-
 
 typedef struct gpt_parts {
@@ -168,4 +120,5 @@
 
 extern void            gpt_set_random_uuid(uint8_t *);
+extern uint64_t        gpt_get_next_aligned(uint64_t, unsigned int);
 
 
Index: uspace/lib/mbr/libmbr.c
===================================================================
--- uspace/lib/mbr/libmbr.c	(revision c3cbbb2a143977e56be842336794a3a84e70279d)
+++ uspace/lib/mbr/libmbr.c	(revision dc76f4a6d7e0da45038149275644c9fbe876bd84)
@@ -42,4 +42,5 @@
 #include <stdio.h>
 #include <stdlib.h>
+#include <str_error.h>
 
 #include "libmbr.h"
@@ -49,9 +50,9 @@
 static int decode_logical(mbr_label_t *, mbr_part_t *);
 static void encode_part(mbr_part_t *, pt_entry_t *, uint32_t, bool);
-static int check_overlap(mbr_part_t *, mbr_part_t *);
-static int check_encaps(mbr_part_t *, mbr_part_t *);
-static int check_preceeds(mbr_part_t *, mbr_part_t *);
-static mbr_err_val mbr_add_primary(mbr_label_t *label, mbr_part_t *p);
-static mbr_err_val mbr_add_logical(mbr_label_t *label, mbr_part_t *p);
+static bool check_overlap(mbr_part_t *, mbr_part_t *);
+static bool check_encaps(mbr_part_t *, mbr_part_t *);
+static bool check_preceeds(mbr_part_t *, mbr_part_t *);
+static mbr_err_val mbr_add_primary(mbr_label_t *, mbr_part_t *);
+static mbr_err_val mbr_add_logical(mbr_label_t *, mbr_part_t *);
 
 /** Allocate and initialize mbr_label_t structure */
@@ -759,37 +760,37 @@
 /** Check whether two partitions overlap
  * 
- * @return		1 for yes, 0 for no
- */
-static int check_overlap(mbr_part_t * p1, mbr_part_t * p2)
+ * @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) {
-		return 0;
+		return false;
 	} else if (p1->start_addr > p2->start_addr && p2->start_addr + p2->length <= p1->start_addr) {
-		return 0;
-	}
-
-	return 1;
+		return false;
+	}
+
+	return true;
 }
 
 /** Check whether one partition encapsulates the other
  * 
- * @return		1 for yes, 0 for no
- */
-static int check_encaps(mbr_part_t * inner, mbr_part_t * outer)
+ * @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) {
-		return 0;
+		return false;
 	} else if (outer->start_addr + outer->length < inner->start_addr + inner->length) {
-		return 0;
-	}
-
-	return 1;
+		return false;
+	}
+
+	return true;
 }
 
 /** Check whether one partition preceeds the other
  * 
- * @return		1 for yes, 0 for no
- */
-static int check_preceeds(mbr_part_t * preceeder, mbr_part_t * precedee)
+ * @return		true/false
+ */
+static bool check_preceeds(mbr_part_t * preceeder, mbr_part_t * precedee)
 {
 	return preceeder->start_addr < precedee->start_addr;
Index: uspace/lib/mbr/libmbr.h
===================================================================
--- uspace/lib/mbr/libmbr.h	(revision c3cbbb2a143977e56be842336794a3a84e70279d)
+++ uspace/lib/mbr/libmbr.h	(revision dc76f4a6d7e0da45038149275644c9fbe876bd84)
@@ -38,38 +38,7 @@
 
 #include <sys/types.h>
+#include "mbr.h"
 
 #define LIBMBR_NAME	"libmbr"
-
-#ifdef DEBUG_CONFIG
-#include <stdio.h>
-#include <str_error.h>
-#define DEBUG_PRINT_0(str) \
-	printf("%s:%d: " str, __FILE__, __LINE__)
-#define DEBUG_PRINT_1(str, arg1) \
-	printf("%s:%d: " str, __FILE__, __LINE__, arg1)
-#define DEBUG_PRINT_2(str, arg1, arg2) \
-	printf("%s:%d: " str, __FILE__, __LINE__, arg1, arg2)
-#define DEBUG_PRINT_3(str, arg1, arg2, arg3) \
-	printf("%s:%d: " str, __FILE__, __LINE__, arg1, arg2, arg3)
-#else
-#define DEBUG_PRINT_0(str)
-#define DEBUG_PRINT_1(str, arg1)
-#define DEBUG_PRINT_2(str, arg1, arg2)
-#define DEBUG_PRINT_3(str, arg1, arg2, arg3)
-#endif
-
-/** Number of primary partition records */
-#define N_PRIMARY		4
-
-/** Boot record signature */
-#define BR_SIGNATURE	0xAA55
-
-enum {
-	/** Non-bootable */
-	B_INACTIVE = 0x00,
-	/** Bootable */
-	B_ACTIVE = 0x80,
-	/** Anything else means invalid */
-};
 
 typedef enum {
@@ -80,15 +49,4 @@
 	ST_LOGIC = 8
 } MBR_FLAGS;
-
-enum {
-	/** Unused partition entry */
-	PT_UNUSED	= 0x00,
-	/** Extended partition */
-	PT_EXTENDED	= 0x05,
-	/** Extended partition with LBA */
-	PT_EXTENDED_LBA	= 0x0F,
-	/** GPT Protective partition */
-	PT_GPT	= 0xEE,
-};
 
 typedef enum {
@@ -112,34 +70,4 @@
 	ERR_LIBBLOCK,
 } mbr_err_val;
-
-
-/** Structure of a partition table entry */
-typedef struct {
-	uint8_t status;
-	/** CHS of fist block in partition */
-	uint8_t first_chs[3];
-	/** Partition type */
-	uint8_t ptype;
-	/** CHS of last block in partition */
-	uint8_t last_chs[3];
-	/** LBA of first block in partition */
-	uint32_t first_lba;
-	/** Number of blocks in partition */
-	uint32_t length;
-} __attribute__((packed)) pt_entry_t;
-
-/** Structure of a boot-record block */
-typedef struct {
-	/** Area for boot code */
-	uint8_t code_area[440];
-	/** Optional media ID */
-	uint32_t media_id;
-	/** Padding */
-	uint16_t pad0;
-	/** Partition table entries */
-	pt_entry_t pte[N_PRIMARY];
-	/** Boot record block signature (@c BR_SIGNATURE) */
-	uint16_t signature;
-} __attribute__((packed)) br_block_t;
 
 /** MBR header */
Index: uspace/lib/mbr/mbr.h
===================================================================
--- uspace/lib/mbr/mbr.h	(revision dc76f4a6d7e0da45038149275644c9fbe876bd84)
+++ uspace/lib/mbr/mbr.h	(revision dc76f4a6d7e0da45038149275644c9fbe876bd84)
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2009 Jiri Svoboda
+ * Copyright (c) 2011, 2012, 2013 Dominik Taborsky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+ /** @addtogroup libmbr
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBMBR_MBR_H_
+#define LIBMBR_MBR_H_
+
+#include <sys/types.h>
+
+/** Number of primary partition records */
+#define N_PRIMARY		4
+
+/** Boot record signature */
+#define BR_SIGNATURE	0xAA55
+
+enum {
+	/** Non-bootable */
+	B_INACTIVE = 0x00,
+	/** Bootable */
+	B_ACTIVE = 0x80,
+	/** Anything else means invalid */
+};
+
+enum {
+	/** Unused partition entry */
+	PT_UNUSED	= 0x00,
+	/** Extended partition */
+	PT_EXTENDED	= 0x05,
+	/** Extended partition with LBA */
+	PT_EXTENDED_LBA	= 0x0F,
+	/** GPT Protective partition */
+	PT_GPT	= 0xEE,
+};
+
+/** Structure of a partition table entry */
+typedef struct {
+	uint8_t status;
+	/** CHS of fist block in partition */
+	uint8_t first_chs[3];
+	/** Partition type */
+	uint8_t ptype;
+	/** CHS of last block in partition */
+	uint8_t last_chs[3];
+	/** LBA of first block in partition */
+	uint32_t first_lba;
+	/** Number of blocks in partition */
+	uint32_t length;
+} __attribute__((packed)) pt_entry_t;
+
+/** Structure of a boot-record block */
+typedef struct {
+	/** Area for boot code */
+	uint8_t code_area[440];
+	/** Optional media ID */
+	uint32_t media_id;
+	/** Padding */
+	uint16_t pad0;
+	/** Partition table entries */
+	pt_entry_t pte[N_PRIMARY];
+	/** Boot record block signature (@c BR_SIGNATURE) */
+	uint16_t signature;
+} __attribute__((packed)) br_block_t;
+
+#endif
+
