Index: uspace/app/hdisk/common.h
===================================================================
--- uspace/app/hdisk/common.h	(revision 802898f596cd8135db8d9d44c39a11981b5b7ecc)
+++ uspace/app/hdisk/common.h	(revision 8c95dff74a31d0b98e3e8fb115185a07e64c2ac2)
@@ -54,4 +54,6 @@
 struct label {
 	layouts_t layout;
+	aoff64_t nblocks;
+	service_id_t device;
 	union label_data data;
 	unsigned int alignment;
@@ -61,7 +63,7 @@
 	int (* new_label)    (label_t *);
 	int (* print_parts)  (label_t *);
-	int (* read_parts)   (label_t *, service_id_t);
-	int (* write_parts)  (label_t *, service_id_t);
-	int (* extra_funcs)  (label_t *, tinput_t *, service_id_t);
+	int (* read_parts)   (label_t *);
+	int (* write_parts)  (label_t *);
+	int (* extra_funcs)  (label_t *, tinput_t *);
 };
 
Index: uspace/app/hdisk/func_gpt.c
===================================================================
--- uspace/app/hdisk/func_gpt.c	(revision 802898f596cd8135db8d9d44c39a11981b5b7ecc)
+++ uspace/app/hdisk/func_gpt.c	(revision 8c95dff74a31d0b98e3e8fb115185a07e64c2ac2)
@@ -43,5 +43,6 @@
 #include "input.h"
 
-static int set_gpt_partition(tinput_t *, gpt_part_t *, unsigned int);
+static void print_part_types(void);
+static int set_gpt_partition(tinput_t *, gpt_part_t *, label_t *);
 
 int construct_gpt_label(label_t *this)
@@ -69,5 +70,5 @@
 	}
 	
-	return set_gpt_partition(in, p, this->alignment);
+	return set_gpt_partition(in, p, this);
 }
 
@@ -106,5 +107,5 @@
 int print_gpt_parts(label_t *this)
 {
-	printf("Current partition scheme (GPT):\n");
+	printf("Current partition scheme (GPT)(number of blocks: %" PRIu64 "):\n", this->nblocks);
 	printf("%15s %10s %10s Type: Name:\n", "Start:", "End:", "Length:");
 	
@@ -131,9 +132,9 @@
 }
 
-int read_gpt_parts(label_t *this, service_id_t dev_handle)
-{
-	int rc;
-	
-	rc = gpt_read_header(this->data.gpt, dev_handle);
+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));
@@ -150,24 +151,18 @@
 }
 
-int write_gpt_parts(label_t *this, service_id_t dev_handle)
-{
-	int rc;
-	
-	rc = gpt_write_partitions(this->data.gpt, dev_handle);
+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;
 	}
-	
-	rc = gpt_write_header(this->data.gpt, dev_handle);
-	if (rc != EOK) {
-		printf("Error: Writing header failed: %d (%s)\n", rc, str_error(rc));
-		return rc;
-	}
-	
-	return EOK;
-}
-
-int extra_gpt_funcs(label_t *this, tinput_t *in, service_id_t dev_handle)
+	printf("test2\n");
+	return EOK;
+}
+
+int extra_gpt_funcs(label_t *this, tinput_t *in)
 {
 	printf("Not implemented.\n");
@@ -175,5 +170,5 @@
 }
 
-static int set_gpt_partition(tinput_t *in, gpt_part_t *p, unsigned int alignment)
+static int set_gpt_partition(tinput_t *in, gpt_part_t *p, label_t * this)
 {
 	int rc;
@@ -181,10 +176,10 @@
 	uint64_t sa, ea;
 	
-	printf("Set starting address (number): ");
+	printf("Set starting address: ");
 	sa = get_input_uint64(in);
-	if (sa % alignment != 0)
-		sa = gpt_get_next_aligned(sa, alignment);
-	
-	printf("Set end address (number): ");
+	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);
 	
@@ -198,9 +193,10 @@
 	
 	/* See global.c from libgpt for all partition types. */
+	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_type);
 	gpt_set_random_uuid(p->part_id);
 	
@@ -218,2 +214,22 @@
 }
 
+static void print_part_types(void)
+{
+	int c;
+	int count = 0;
+	const struct partition_type * ptype = gpt_ptypes;
+	
+	do {
+		if (count % 10 == 0) {
+			printf("Print (more) partition types? (y/n)\n");
+			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 802898f596cd8135db8d9d44c39a11981b5b7ecc)
+++ uspace/app/hdisk/func_gpt.h	(revision 8c95dff74a31d0b98e3e8fb115185a07e64c2ac2)
@@ -48,7 +48,7 @@
 extern int new_gpt_label    (label_t *);
 extern int print_gpt_parts  (label_t *);
-extern int read_gpt_parts   (label_t *, service_id_t);
-extern int write_gpt_parts  (label_t *, service_id_t);
-extern int extra_gpt_funcs  (label_t *, tinput_t *, service_id_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 802898f596cd8135db8d9d44c39a11981b5b7ecc)
+++ uspace/app/hdisk/func_mbr.c	(revision 8c95dff74a31d0b98e3e8fb115185a07e64c2ac2)
@@ -41,5 +41,5 @@
 #include "input.h"
 
-static int set_mbr_partition(tinput_t *in, mbr_part_t *p, unsigned int alignment);
+static int set_mbr_partition(tinput_t *, mbr_part_t *, label_t *);
 
 int construct_mbr_label(label_t *this)
@@ -66,5 +66,7 @@
 	mbr_part_t *part = mbr_alloc_partition();
 	
-	set_mbr_partition(in, part, this->alignment);
+	rc = set_mbr_partition(in, part, this);
+	if (rc != EOK)
+		return rc;
 	
 	rc = mbr_add_partition(this->data.mbr, part);
@@ -89,5 +91,5 @@
 	rc = mbr_remove_partition(this->data.mbr, idx);
 	if (rc != EOK) {
-		printf("Error: something.\n");
+		printf("Error: partition does not exist?\n");
 	}
 	
@@ -106,6 +108,7 @@
 	if (this->data.mbr == NULL)
 		return ENOMEM;
-	else
-		return EOK;
+	
+	mbr_set_device(this->data.mbr, this->device);
+	return EOK;
 }
 
@@ -115,5 +118,5 @@
 	int num = 0;
 	
-	printf("Current partition scheme (MBR):\n");
+	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:");
 	
@@ -121,5 +124,5 @@
 	
 	for (it = mbr_get_first_partition(this->data.mbr); it != NULL;
-	     it = mbr_get_next_partition(this->data.mbr, it), ++num) {
+	     it = mbr_get_next_partition(this->data.mbr, it)) {
 		if (it->type == PT_UNUSED)
 			continue;
@@ -133,4 +136,5 @@
 		printf("\t%10u %10u %10u %7u\n", it->start_addr, it->start_addr + it->length, it->length, it->type);
 		
+		num++;
 	}
 	
@@ -140,8 +144,8 @@
 }
 
-int read_mbr_parts(label_t *this, service_id_t dev_handle)
+int read_mbr_parts(label_t *this)
 {
 	int rc;
-	rc = mbr_read_mbr(this->data.mbr, dev_handle);
+	rc = mbr_read_mbr(this->data.mbr, this->device);
 	if (rc != EOK)
 		return rc;
@@ -157,7 +161,7 @@
 }
 
-int write_mbr_parts(label_t *this, service_id_t dev_handle)
-{
-	int rc = mbr_write_partitions(this->data.mbr, dev_handle);
+int write_mbr_parts(label_t *this)
+{
+	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));
@@ -167,5 +171,5 @@
 }
 
-int extra_mbr_funcs(label_t *this, tinput_t *in, service_id_t dev_handle)
+int extra_mbr_funcs(label_t *this, tinput_t *in)
 {
 	printf("Not implemented.\n");
@@ -173,5 +177,5 @@
 }
 
-static int set_mbr_partition(tinput_t *in, mbr_part_t *p, unsigned int alignment)
+static int set_mbr_partition(tinput_t *in, mbr_part_t *p, label_t * this)
 {
 	int c;
@@ -214,15 +218,15 @@
 	uint32_t sa, ea;
 
-	printf("Set starting address (number): ");
+	printf("Set starting address: ");
 	sa = get_input_uint32(in);
 	if (sa == 0 && errno != EOK)
 		return errno;
 	
-	if (alignment != 0 && alignment != 1) {
-		sa = mbr_get_next_aligned(sa, alignment);
+	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 (number): ");
+	
+	printf("Set end addres (max: %" PRIu64 "): ", this->nblocks);
 	ea = get_input_uint32(in);
 	if (ea == 0 && errno != EOK)
@@ -233,5 +237,5 @@
 		return EINVAL;
 	}
-
+	
 	p->type = type;
 	p->start_addr = sa;
Index: uspace/app/hdisk/func_mbr.h
===================================================================
--- uspace/app/hdisk/func_mbr.h	(revision 802898f596cd8135db8d9d44c39a11981b5b7ecc)
+++ uspace/app/hdisk/func_mbr.h	(revision 8c95dff74a31d0b98e3e8fb115185a07e64c2ac2)
@@ -48,7 +48,7 @@
 extern int new_mbr_label    (label_t *);
 extern int print_mbr_parts  (label_t *);
-extern int read_mbr_parts   (label_t *, service_id_t);
-extern int write_mbr_parts  (label_t *, service_id_t);
-extern int extra_mbr_funcs  (label_t *, tinput_t *, service_id_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 802898f596cd8135db8d9d44c39a11981b5b7ecc)
+++ uspace/app/hdisk/func_none.c	(revision 8c95dff74a31d0b98e3e8fb115185a07e64c2ac2)
@@ -86,5 +86,5 @@
 }
 
-int read_none_parts(label_t *this, service_id_t dev_handle)
+int read_none_parts(label_t *this)
 {
 	not_implemented();
@@ -92,5 +92,5 @@
 }
 
-int write_none_parts(label_t *this, service_id_t dev_handle)
+int write_none_parts(label_t *this)
 {
 	not_implemented();
@@ -98,5 +98,5 @@
 }
 
-int extra_none_funcs(label_t *this, tinput_t * in, service_id_t dev_handle)
+int extra_none_funcs(label_t *this, tinput_t * in)
 {
 	not_implemented();
Index: uspace/app/hdisk/func_none.h
===================================================================
--- uspace/app/hdisk/func_none.h	(revision 802898f596cd8135db8d9d44c39a11981b5b7ecc)
+++ uspace/app/hdisk/func_none.h	(revision 8c95dff74a31d0b98e3e8fb115185a07e64c2ac2)
@@ -47,7 +47,7 @@
 extern int new_none_label    (label_t *);
 extern int print_none_parts  (label_t *);
-extern int read_none_parts   (label_t *, service_id_t);
-extern int write_none_parts  (label_t *, service_id_t);
-extern int extra_none_funcs  (label_t *, tinput_t *, service_id_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 802898f596cd8135db8d9d44c39a11981b5b7ecc)
+++ uspace/app/hdisk/hdisk.c	(revision 8c95dff74a31d0b98e3e8fb115185a07e64c2ac2)
@@ -46,4 +46,5 @@
 #include <libgpt.h>
 #include <tinput.h>
+#include <str_error.h>
 
 #include "hdisk.h"
@@ -53,12 +54,12 @@
 #include "func_none.h"
 
-int interact(service_id_t);
+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(service_id_t);
-int try_read_mbr(service_id_t);
-int try_read_gpt(service_id_t);
+int try_read(void);
+int try_read_mbr(void);
+int try_read_gpt(void);
 void set_alignment(tinput_t *);
 
@@ -83,19 +84,38 @@
 	
 	init_label();
-	
-	rc = try_read_mbr(dev_handle);
+	label.device = dev_handle;
+	
+	rc = block_init(EXCHANGE_ATOMIC, dev_handle, 512);
+	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);
+	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;
+	
+	rc = try_read_mbr();
 	if (rc == EOK)
 		goto interact;
 	
-	rc = try_read_gpt(dev_handle);
+	free_label();
+	
+	rc = try_read_gpt();
 	if (rc == EOK)
 		goto interact;
 	
 	printf("No label recognized. Create a new one.\n");
-	label.layout = LYT_NONE;
+	construct_label(LYT_NONE);
 	
 interact:
 	
-	rc = interact(dev_handle);
+	rc = interact();
 	
 	return rc;
@@ -103,5 +123,5 @@
 
 /** Interact with user */
-int interact(service_id_t dev_handle)
+int interact()
 {
 	int input;
@@ -130,7 +150,8 @@
 			break;
 		case 'e':
-			label.extra_funcs(&label, in, dev_handle);
+			label.extra_funcs(&label, in);
 			break;
 		case 'f':
+			free_label();
 			select_label_format(in);
 			break;
@@ -154,7 +175,7 @@
 			goto end;
 		case 'r':
-			label.read_parts(&label, dev_handle);
+			label.read_parts(&label);
 		case 'w':
-			label.write_parts(&label, dev_handle);
+			label.write_parts(&label);
 			break;
 		default:
@@ -197,15 +218,12 @@
 	uint8_t val = get_input_uint8(in);
 	switch (val) {
-	case 0:
-		free_label();
+	case 1:
+		construct_label(LYT_MBR);
+		break;
+	case 2:
+		construct_label(LYT_GPT);
+		break;
+	default:
 		construct_label(LYT_NONE);
-		break;
-	case 1:
-		free_label();
-		construct_label(LYT_MBR);
-		break;
-	case 2:
-		free_label();
-		construct_label(LYT_GPT);
 		break;
 	}
@@ -235,19 +253,20 @@
 }
 
-int try_read(service_id_t dev_handle)
-{
-	return label.read_parts(&label, dev_handle);
-}
-
-int try_read_mbr(service_id_t dev_handle)
+int try_read()
+{
+	
+	return label.read_parts(&label);
+}
+
+int try_read_mbr()
 {
 	construct_label(LYT_MBR);
-	return try_read(dev_handle);
-}
-
-int try_read_gpt(service_id_t dev_handle)
+	return try_read();
+}
+
+int try_read_gpt()
 {
 	construct_label(LYT_GPT);
-	return try_read(dev_handle);
+	return try_read();
 }
 
Index: uspace/lib/gpt/Makefile
===================================================================
--- uspace/lib/gpt/Makefile	(revision 802898f596cd8135db8d9d44c39a11981b5b7ecc)
+++ uspace/lib/gpt/Makefile	(revision 8c95dff74a31d0b98e3e8fb115185a07e64c2ac2)
@@ -28,5 +28,5 @@
 
 USPACE_PREFIX = ../..
-EXTRA_CFLAGS = -I$(LIBBLOCK_PREFIX)
+EXTRA_CFLAGS = -I$(LIBBLOCK_PREFIX) -I$(LIBMBR_PREFIX)
 LIBRARY = libgpt
 
Index: uspace/lib/gpt/global.c
===================================================================
--- uspace/lib/gpt/global.c	(revision 802898f596cd8135db8d9d44c39a11981b5b7ecc)
+++ uspace/lib/gpt/global.c	(revision 8c95dff74a31d0b98e3e8fb115185a07e64c2ac2)
@@ -40,4 +40,8 @@
 };
 
+const uint8_t revision[4] = {
+	00, 00, 01, 00
+};
+
 const struct partition_type gpt_ptypes[] = {
 	{ "Unused entry",					"00000000" "0000" "0000" "0000000000000000" }, /* 0 */
@@ -55,9 +59,9 @@
 	{ "HP-UX Data",						"75894C1E" "3AEB" "11D3" "B7C17B03A0000000" },
 	{ "HP-UX Service",					"E2A1E728" "32E3" "11D6" "A6827B03A0000000" },
-	{ "Linux filesystem data",			"EBD0A0A2" "B9E5" "4433" "87C068B6B72699C7" },
 	{ "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 */
Index: uspace/lib/gpt/gpt.h
===================================================================
--- uspace/lib/gpt/gpt.h	(revision 802898f596cd8135db8d9d44c39a11981b5b7ecc)
+++ uspace/lib/gpt/gpt.h	(revision 8c95dff74a31d0b98e3e8fb115185a07e64c2ac2)
@@ -50,5 +50,5 @@
 typedef struct {
 	uint8_t  efi_signature[8];
-	uint32_t revision;
+	uint8_t  revision[4];
 	uint32_t header_size;
 	uint32_t header_crc32;
Index: uspace/lib/gpt/libgpt.c
===================================================================
--- uspace/lib/gpt/libgpt.c	(revision 802898f596cd8135db8d9d44c39a11981b5b7ecc)
+++ uspace/lib/gpt/libgpt.c	(revision 8c95dff74a31d0b98e3e8fb115185a07e64c2ac2)
@@ -49,4 +49,5 @@
 #include <mem.h>
 #include <sys/typefmt.h>
+#include <mbr.h>
 
 
@@ -112,5 +113,12 @@
 	}
 	
+	/* Enter some sane defaults. */
 	memset(gpt->header, 0, final_size);
+	memcpy(gpt->header->efi_signature, efi_signature, 8);
+	memcpy(gpt->header->revision, revision, 4);
+	gpt->header->header_size = host2uint32_t_le(final_size);
+	gpt->header->entry_lba = host2uint64_t_le((uint64_t) 2);
+	gpt->header->entry_size = host2uint32_t_le(sizeof(gpt_entry_t));
+	
 	
 	return gpt;
@@ -207,4 +215,6 @@
 	uint64_t tmp;
 	
+	gpt_set_random_uuid(label->gpt->header->disk_guid);
+	
 	/* Prepare the backup header */
 	label->gpt->header->alternate_lba = label->gpt->header->my_lba;
@@ -243,8 +253,21 @@
 	/* 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;
+	
+	/* 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);
+	mbr.pte[0].first_lba = host2uint32_t_le(1);
+	mbr.pte[0].length = 0xFFFFFFFF;
+	mbr.signature = host2uint16_t_le(BR_SIGNATURE);
+	
+	rc = block_write_direct(dev_handle, 0, 1, &mbr);
 	block_fini(dev_handle);
 	if (rc != EOK)
 		return rc;
-	
 	
 	return 0;
@@ -343,9 +366,4 @@
 	int rc;
 	size_t 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))
-		return ENOTSUP;
 	
 	/* comm_size of 4096 is ignored */
@@ -363,4 +381,18 @@
 		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);
+	}
+	
+	printf("test1.0\n");
+	uint32_t e_size = uint32_t_le2host(label->gpt->header->entry_size);
+	printf("test1.025\n");
+	size_t fillries = label->parts->fill > GPT_MIN_PART_NUM ? label->parts->fill : GPT_MIN_PART_NUM;
+	printf("test1.05\n");
+	if (e_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;
@@ -368,5 +400,5 @@
 	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);
-	
+	printf("test1.5\n");
 	/* Perform checks */
 	gpt_part_foreach (label, p) {
@@ -395,10 +427,10 @@
 		}
 	}
-	
+	printf("test1.6\n");
 	label->gpt->header->pe_array_crc32 = host2uint32_t_le(compute_crc32(
 	                               (uint8_t *) label->parts->part_array,
 	                               fillries * e_size));
 	
-	
+	printf("test1.7\n");
 	/* Write to backup GPT partition array location */
 	rc = block_write_direct(dev_handle, n_blocks - arr_blocks - 1, 
@@ -406,5 +438,5 @@
 	if (rc != EOK)
 		goto fail;
-	
+	printf("test1.8\n");
 	/* Write to main GPT partition array location */
 	rc = block_write_direct(dev_handle, uint64_t_le2host(label->gpt->header->entry_lba),
@@ -412,5 +444,5 @@
 	if (rc != EOK)
 		goto fail;
-	
+	printf("test1.9\n");
 	return gpt_write_header(label, dev_handle);
 	
@@ -594,4 +626,9 @@
 	
 	for (i = 0; gpt_ptypes[i].guid != NULL; i++) {
+		//printf("%x =?= %x\n", p->part_type[3], get_byte(gpt_ptypes[i].guid +0));
+		//printf("%x =?= %x\n", p->part_type[2], get_byte(gpt_ptypes[i].guid +2));
+		//printf("%x =?= %x\n", p->part_type[1], get_byte(gpt_ptypes[i].guid +4));
+		//printf("%x =?= %x\n", p->part_type[0], get_byte(gpt_ptypes[i].guid +6));
+		//getchar();
 		if (p->part_type[3] == get_byte(gpt_ptypes[i].guid +0) &&
 			p->part_type[2] == get_byte(gpt_ptypes[i].guid +2) &&
@@ -627,23 +664,23 @@
 {
 	/* Beware: first 3 blocks are byteswapped! */
-	p->part_type[3] = gpt_ptypes[type].guid[0];
-	p->part_type[2] = gpt_ptypes[type].guid[1];
-	p->part_type[1] = gpt_ptypes[type].guid[2];
-	p->part_type[0] = gpt_ptypes[type].guid[3];
-
-	p->part_type[5] = gpt_ptypes[type].guid[4];
-	p->part_type[4] = gpt_ptypes[type].guid[5];
-
-	p->part_type[7] = gpt_ptypes[type].guid[6];
-	p->part_type[6] = gpt_ptypes[type].guid[7];
-
-	p->part_type[8] = gpt_ptypes[type].guid[8];
-	p->part_type[9] = gpt_ptypes[type].guid[9];
-	p->part_type[10] = gpt_ptypes[type].guid[10];
-	p->part_type[11] = gpt_ptypes[type].guid[11];
-	p->part_type[12] = gpt_ptypes[type].guid[12];
-	p->part_type[13] = gpt_ptypes[type].guid[13];
-	p->part_type[14] = gpt_ptypes[type].guid[14];
-	p->part_type[15] = gpt_ptypes[type].guid[15];
+	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);
 }
 
Index: uspace/lib/gpt/libgpt.h
===================================================================
--- uspace/lib/gpt/libgpt.h	(revision 802898f596cd8135db8d9d44c39a11981b5b7ecc)
+++ uspace/lib/gpt/libgpt.h	(revision 8c95dff74a31d0b98e3e8fb115185a07e64c2ac2)
@@ -60,4 +60,5 @@
 /** GPT header signature ("EFI PART" in ASCII) */
 extern const uint8_t efi_signature[8];
+extern const uint8_t revision[4];
 
 typedef struct {
Index: uspace/lib/mbr/libmbr.c
===================================================================
--- uspace/lib/mbr/libmbr.c	(revision 802898f596cd8135db8d9d44c39a11981b5b7ecc)
+++ uspace/lib/mbr/libmbr.c	(revision 8c95dff74a31d0b98e3e8fb115185a07e64c2ac2)
@@ -70,4 +70,9 @@
 }
 
+void mbr_set_device(mbr_label_t *label, service_id_t dev_handle)
+{
+	label->device = dev_handle;
+}
+
 /** Free mbr_label_t structure */
 void mbr_free_label(mbr_label_t *label)
@@ -253,4 +258,6 @@
 	}
 	
+	label->mbr->raw_data.signature = host2uint16_t_le(BR_SIGNATURE);
+	
 	/* Writing MBR */
 	rc = block_write_direct(dev_handle, 0, 1, &(label->mbr->raw_data));
@@ -271,5 +278,5 @@
 	 * 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. Thanks. */
+	 * as much power over it as you can get. */
 	
 	/* Encoding and writing first logical partition */
Index: uspace/lib/mbr/libmbr.h
===================================================================
--- uspace/lib/mbr/libmbr.h	(revision 802898f596cd8135db8d9d44c39a11981b5b7ecc)
+++ uspace/lib/mbr/libmbr.h	(revision 8c95dff74a31d0b98e3e8fb115185a07e64c2ac2)
@@ -120,4 +120,5 @@
 /* Alloc complete label structure */
 extern mbr_label_t * mbr_alloc_label(void);
+extern void mbr_set_device(mbr_label_t *, service_id_t);
 
 /* Read/Write MBR header.
