Index: uspace/app/hdisk/Makefile
===================================================================
--- uspace/app/hdisk/Makefile	(revision ec50ac4a5f0f112c28f2a78b993c2c607f166d95)
+++ uspace/app/hdisk/Makefile	(revision 271e24a4aca586ebdc97458d9836e0a3a3e1038c)
@@ -32,5 +32,5 @@
 	$(LIBBLOCK_PREFIX)/libblock.a $(LIBCLUI_PREFIX)/libclui.a \
 	$(LIBC_PREFIX)/libc.a
-EXTRA_CFLAGS = -I$(LIBMBR_PREFIX) -I$(LIBBLOCK_PREFIX) -I$(LIBCLUI_PREFIX)
+EXTRA_CFLAGS = -I$(LIBMBR_PREFIX) -I$(LIBGPT_PREFIX) -I$(LIBBLOCK_PREFIX) -I$(LIBCLUI_PREFIX)
 BINARY = hdisk
 
@@ -38,5 +38,6 @@
 	hdisk.c \
 	func_mbr.c \
-	func_gpt.c 
+	func_gpt.c \
+	input.c
 
 include $(USPACE_PREFIX)/Makefile.common
Index: uspace/app/hdisk/func_gpt.c
===================================================================
--- uspace/app/hdisk/func_gpt.c	(revision ec50ac4a5f0f112c28f2a78b993c2c607f166d95)
+++ uspace/app/hdisk/func_gpt.c	(revision 271e24a4aca586ebdc97458d9836e0a3a3e1038c)
@@ -33,3 +33,36 @@
  */
 
+#include <stdio.h>
+#include <errno.h>
+#include <sys/types.h>
+
 #include "func_gpt.h"
+
+int add_gpt_part(tinput_t * in, union table_data * data)
+{
+	int rc = EOK;
+	
+	return rc;
+}
+
+int delete_gpt_part(tinput_t * in, union table_data * data)
+{
+	int rc = EOK;
+	
+	return rc;
+}
+
+int print_gpt_parts(union table_data * data)
+{
+	int rc = EOK;
+	
+	return rc;
+}
+
+int write_gpt_parts(service_id_t dev_handle, union table_data * data)
+{
+	int rc = EOK;
+	
+	return rc;
+}
+
Index: uspace/app/hdisk/func_gpt.h
===================================================================
--- uspace/app/hdisk/func_gpt.h	(revision ec50ac4a5f0f112c28f2a78b993c2c607f166d95)
+++ uspace/app/hdisk/func_gpt.h	(revision 271e24a4aca586ebdc97458d9836e0a3a3e1038c)
@@ -34,10 +34,16 @@
 
 #ifndef __FUNC_GPT_H__
-#def	__FUNC_GPT_H__
+#define	__FUNC_GPT_H__
 
-int add_gpt_part(tinput_t * in, gpt_parts_t * parts);
-int delete_gpt_part(tinput_t * in, gpt_parts_t * parts);
-extern void print_gpt_partitions(gpt_parts_t * parts);
-extern void write_gpt_parts(gpt_parts_t * parts, gpt_t * mbr, service_id_t dev_handle);
+#include <loc.h>
+#include <tinput.h>
+#include <libgpt.h>
+
+#include "common.h"
+
+extern int add_gpt_part(tinput_t * in, union table_data * data);
+extern int delete_gpt_part(tinput_t * in, union table_data * data);
+extern int print_gpt_parts(union table_data * data);
+extern int write_gpt_parts(service_id_t dev_handle, union table_data * data);
 
 #endif
Index: uspace/app/hdisk/func_mbr.c
===================================================================
--- uspace/app/hdisk/func_mbr.c	(revision ec50ac4a5f0f112c28f2a78b993c2c607f166d95)
+++ uspace/app/hdisk/func_mbr.c	(revision 271e24a4aca586ebdc97458d9836e0a3a3e1038c)
@@ -33,51 +33,40 @@
  */
 
+#include <stdio.h>
+#include <errno.h>
+#include <sys/types.h>
+
 #include "func_mbr.h"
+#include "input.h"
 
-int add_mbr_part(tinput_t * in, mbr_parts_t * parts)
+static int set_mbr_partition(tinput_t * in, mbr_part_t * p);
+
+
+int add_mbr_part(tinput_t * in, union table_data * data)
 {
-	part_t * part = mbr_alloc_partition();
-
-	printf("Primary (p) or logical (l): ");
-	int input = getchar();
-
-	switch(input) {
-		case 'p':
-			mbr_set_flag(parts, ST_LOGIC, false);
-		case 'l':
-			mbr_set_flag(parts, ST_LOGIC, false);
-		default:
-			printf("Invalid type. Cancelled.");
-			return EINVAL;
-	}
+	int rc;
+	
+	mbr_part_t * part = mbr_alloc_partition();
 
 	set_mbr_partition(in, part);
 
-	mbr_add_partition(parts, part);
+	rc = mbr_add_partition(data->mbr.parts, part);
+	if (rc != EOK) {
+		printf("Error adding partition.\n");
+	}
+	
+	
+	return rc;
 }
 
-int delete_mbr_part(tinput_t * in, part_t * parts)
+int delete_mbr_part(tinput_t * in, union table_data * data)
 {
-	char * str;
 	int rc;
-	part_t * temp = NULL;
-	part_t * p = parts;
-	uint32_t i, input = 0;
-	char * endptr;
+	size_t idx;
 
 	printf("Number of the partition to delete (counted from 0): ");
+	idx = get_input_size_t(in);
 
-	if((rc = get_input(in, &str)) != EOK)
-		return rc;
-
-	//convert from string to base 10 number
-	if(str_uint32_t(str, &endptr, 10, true, &input) != EOK) {
-		printf("Invalid value. Canceled.\n");
-		return EINVAL;
-	}
-
-	free(str);
-
-	rc = mbr_remove_partition(parts, input);
+	rc = mbr_remove_partition(data->mbr.parts, idx);
 	if(rc != EOK) {
 		printf("Error: something.\n");
@@ -88,5 +77,5 @@
 
 /** Print current partition scheme */
-void print_mbr_partitions(mbr_parts_t * parts)
+int print_mbr_parts(union table_data * data)
 {
 	int num = 0;
@@ -95,27 +84,91 @@
 	printf("\t\tBootable:\tStart:\tEnd:\tLength:\tType:\n");
 
-	mbr_part_foreach(parts, it) {
+	mbr_part_foreach(data->mbr.parts, it) {
 		if (it->type == PT_UNUSED)
 			continue;
 
-		printf("\t P%d:\t", i);
-		if (p->bootable)
+		printf("\t P%d:\t", num);
+		if (mbr_get_flag(it, ST_BOOT))
 			printf("*");
 		else
 			printf(" ");
 
-		printf("\t\t%llu\t%llu\t%llu\t%d\n", p->start_addr, p->start_addr + p->length, p->length, p->type);
+		printf("\t\t%u\t%u\t%u\t%d\n", it->start_addr, it->start_addr + it->length, it->length, it->type);
 
 		++num;
-	}*/
+	}
 
 	printf("%d partitions found.\n", num);
+	
+	return EOK;
 }
 
-void write_mbr_parts(mbr_parts_t * parts, mbr_t * mbr, service_id_t dev_handle)
+int write_mbr_parts(service_id_t dev_handle, union table_data * data)
 {
-	int rc = mbr_write_partitions(parts, mbr, dev_handle);
+	int rc = mbr_write_partitions(data->mbr.parts, data->mbr.mbr, dev_handle);
 	if (rc != EOK) {
 		printf("Error occured during writing. (ERR: %d)\n", rc);
 	}
+	
+	return rc;
 }
+
+
+
+static int set_mbr_partition(tinput_t * in, mbr_part_t * p)
+{
+	int c;
+	uint8_t type;
+	
+	printf("Primary (p) or logical (l): ");
+	c = getchar();
+
+	switch(c) {
+		case 'p':
+			mbr_set_flag(p, ST_LOGIC, false);
+		case 'l':
+			mbr_set_flag(p, ST_LOGIC, true);
+		default:
+			printf("Invalid type. Cancelled.");
+			return EINVAL;
+	}
+	
+	printf("Set type (0-255): ");
+	type = get_input_uint8(in);
+
+	///TODO: there can only be one bootable partition; let's do it just like fdisk
+	printf("Bootable? (y/n): ");
+	c = getchar();
+	if (c != 'y' && c != 'Y' && c != 'n' && c != 'N') {
+		printf("Invalid value. Cancelled.");
+		return EINVAL;
+	}
+	
+	mbr_set_flag(p, ST_BOOT, (c == 'y' || c == 'Y') ? true : false);
+
+
+	uint32_t sa, ea;
+
+	printf("Set starting address (number): ");
+	sa = get_input_uint32(in);
+
+	printf("Set end addres (number): ");
+	ea = get_input_uint32(in);
+	
+	if(ea < sa) {
+		printf("Invalid value. Canceled.\n");
+		return EINVAL;
+	}
+
+	p->type = type;
+	p->start_addr = sa;
+	p->length = ea - sa;
+
+	return EOK;
+}
+
+
+
+
+
+
Index: uspace/app/hdisk/func_mbr.h
===================================================================
--- uspace/app/hdisk/func_mbr.h	(revision ec50ac4a5f0f112c28f2a78b993c2c607f166d95)
+++ uspace/app/hdisk/func_mbr.h	(revision 271e24a4aca586ebdc97458d9836e0a3a3e1038c)
@@ -34,10 +34,16 @@
 
 #ifndef __FUNC_MBR_H__
-#def	__FUNC_MBR_H__
+#define	__FUNC_MBR_H__
 
-int add_mbr_part(tinput_t * in, mbr_parts_t * parts);
-int delete_mbr_part(tinput_t * in, mbr_parts_t * parts);
-extern void print_mbr_partitions(mbr_parts_t * parts);
-extern void write_mbr_parts(mbr_parts_t * parts, mbr_t * mbr, service_id_t dev_handle);
+#include <loc.h>
+#include <tinput.h>
+#include <libmbr.h>
+
+#include "common.h"
+
+extern int add_mbr_part(tinput_t * in, union table_data * data);
+extern int delete_mbr_part(tinput_t * in, union table_data * data);
+extern int print_mbr_parts(union table_data * data);
+extern int write_mbr_parts(service_id_t dev_handle, union table_data * data);
 
 #endif
Index: uspace/app/hdisk/hdisk.c
===================================================================
--- uspace/app/hdisk/hdisk.c	(revision ec50ac4a5f0f112c28f2a78b993c2c607f166d95)
+++ uspace/app/hdisk/hdisk.c	(revision 271e24a4aca586ebdc97458d9836e0a3a3e1038c)
@@ -38,5 +38,5 @@
 #include <stdio.h>
 #include <ipc/services.h>
-#include <libblock.h>
+#include <block.h>
 #include <errno.h>
 #include <stdlib.h>
@@ -44,24 +44,17 @@
 #include <str.h>
 #include <libmbr.h>
+#include <libgpt.h>
 #include <tinput.h>
 
+#include "hdisk.h"
 #include "func_mbr.h"
 #include "func_gpt.h"
 
-enum TABLES {
-	TBL_MBR,
-	TBL_GPT;
-};
-
-static TABLES table;
-
-int get_input(tinput_t * in, char ** str);
-void interact(mbr_parts_t * partitions, mbr_t * mbr, service_id_t dev_handle);
+int interact(service_id_t dev_handle);
 void print_help(void);
-
-
-int set_primary(tinput_t * in, mbr_parts_t * parts);
-int add_logical(tinput_t * in, mbr_parts_t * parts);
-int set_mbr_partition(tinput_t * in, mbr_parts_t * p);
+void fill_table_funcs(void);
+void free_table(void);
+
+static table_t table;
 
 int main(int argc, char ** argv)
@@ -80,43 +73,52 @@
 		return -1;
 	}
-
-	mbr_parts_t * parts = NULL;
-	gpt_header_t * g_hdr = NULL;
-	gpt_parts_t * g_parts = NULL;
-
+	
+	init_table();
+	
 	mbr_t * mbr = mbr_read_mbr(dev_handle);
 	if(mbr == NULL) {
 		printf("Failed to read the Master Boot Record.\n"	\
-			   "Either memory allocation or disk access failed.\n");
+			   "Either memory allocation or disk access failed. Exiting.\n");
 		return -1;
 	}
 
 	if(mbr_is_mbr(mbr)) {
-		table = TBL_MBR;
-		parts = mbr_read_partitions(mbr);
+		table.layout = LYT_MBR;
+		set_table_mbr(mbr);
+		mbr_partitions_t * parts = mbr_read_partitions(mbr);
 		if(parts == NULL) {
 			printf("Failed to read and parse partitions.\n"	\
-				   "Creating new partition table.")
-		}
+				   "Creating new partition table.");
+			parts = mbr_alloc_partitions();
+		}
+		set_table_mbr_parts(parts);
+		fill_table_funcs();
 	} else {
-		table = TBL_GPT;
-		//g_hdr = gpt_read_header();
-		//g_parts = gpt_read_partitions();
-	}
-
-
-	rc = interact(partitions, mbr, dev_handle);
-
-	if(gpt) {
-		gpt_free_partitions();
-		gpt_free_header();
-	} else {
-		mbr_free_partitions(partitions);
+		table.layout = LYT_GPT;
 		mbr_free_mbr(mbr);
-	}
+		gpt_t * gpt = gpt_read_gpt_header(dev_handle);
+		if(gpt == NULL) {
+			printf("Failed to read and parse GPT header. Exiting.\n");
+			return -1;
+		}
+		set_table_gpt(gpt);
+		gpt_partitions_t * parts = gpt_read_partitions(gpt);
+		if(parts == NULL) {
+			printf("Failed to read and parse partitions.\n"	\
+				   "Creating new partition table.");
+			//parts = gpt_alloc_partitions();
+		}
+		set_table_gpt_parts(parts);
+		fill_table_funcs();
+	}
+
+	rc = interact(dev_handle);
+
+	free_table();
 
 	return rc;
 }
 
+/*
 int get_input(tinput_t * in, char ** str)
 {
@@ -158,38 +160,12 @@
 	return EOK;
 }
-
-//int get_input(tinput_t * in, char ** str)
-//{
-//	int rc;
-//	printf("help1\n");
-//	rc = tinput_read(in, str);
-//	if (rc == ENOENT) {
-//		/* User requested exit */
-//		return EINTR;
-//	}
-//	printf("help2\n");
-//	fflush(stdout);
-//	if (rc != EOK) {
-//		printf("Failed reading input. Cancelling...\n");
-//		return rc;
-//	}
-//	printf("help3\n");
-//	fflush(stdout);
-//	/* Check for empty input. */
-//	if (str_cmp(*str, "") == 0) {
-//		printf("Canceled.\n");
-//		return EINVAL;
-//	}
-//	printf("help4\n");
-//	fflush(stdout);
-//
-//	return EOK;
-//}
+*/
+
 
 /** Interact with user */
-int interact_mbr(mbr_parts_t * partitions, mbr_t * mbr, service_id_t dev_handle)
-{
-	char * str;
+int interact(service_id_t dev_handle)
+{
 	//int rc;
+	int input;
 	tinput_t * in;
 
@@ -197,42 +173,40 @@
 	if (in == NULL) {
 		printf("Failed initing input. Free some memory.\n");
-		return;
-	}
-
-	tinput_set_prompt(in, " ");
+		return ENOMEM;
+	}
 
 	printf("Welcome to hdisk.\nType 'h' for help.\n");
 
 	//printf("# ");
-	//int input = getchar();
+	//input = getchar();
 	//printf("%c\n", input);
 
 	while (1) {
 
-		/*printf("# ");
-		int input = getchar();
-		printf("%c\n", input);
-		*/
-
-		rc = tinput_read(in, &str);
-		if (rc == ENOENT) {
-			// User requested exit
-			putchar('\n');
-			return rc;
-		}
-		if (rc != EOK) {
-			printf("Failed reading input. Exiting...\n");
-			return rc;
-		}
-		// Check for empty input.
-		if (str_cmp(str, "") == 0)
-			continue;
-
-		switch(*str) {
+		//printf("# ");
+		input = getchar();
+		//printf("%c\n", input);
+		
+
+		//rc = tinput_read(in, &str);
+		//if (rc == ENOENT) {
+			//// User requested exit
+			//putchar('\n');
+			//return rc;
+		//}
+		//if (rc != EOK) {
+			//printf("Failed reading input. Exiting...\n");
+			//return rc;
+		//}
+		//// Check for empty input.
+		//if (str_cmp(str, "") == 0)
+			//continue;
+
+		switch(input) {
 			case 'a':
-				add_part(in, partitions);
+				table.add_part(in, &table.data);
 				break;
 			case 'd':
-				delete_part(in, partitions);
+				table.delete_part(in, &table.data);
 				break;
 			case 'h':
@@ -240,11 +214,11 @@
 				break;
 			case 'p':
-				print_MBR(partitions);
+				table.print_parts(&table.data);
 				break;
 			case 'q':
 				putchar('\n');
-				return;
+				goto end;
 			case 'w':
-				write_parts(partitions, mbr, dev_handle);
+				table.write_parts(dev_handle, &table.data);
 				break;
 			default:
@@ -258,7 +232,8 @@
 	}
 
+end:
 	tinput_destroy(in);
 
-	return;
+	return EOK;
 }
 
@@ -269,5 +244,6 @@
 		"\t 'd' \t\t Delete partition.\n"
 		"\t 'h' \t\t Prints help. See help for more.\n" \
-		"\t 'p' \t\t Prints the MBR contents.\n" \
+		"\t 'p' \t\t Prints the table contents.\n" \
+		"\t 'w' \t\t Write table to disk.\n" \
 		"\t 'q' \t\t Quit.\n" \
 		);
@@ -275,147 +251,38 @@
 }
 
-//other functions
-//FIXME: need error checking after input
-int set_primary(tinput_t * in, part_t * parts)
-{
-	char * str;
-	int rc;
-	uint32_t input = 5;
-	part_t * p = parts;
-	//char c_input[2];
-	char * endptr;
-
-//	while (input > 3) {
-//		printf("Number of the primary partition to set (0-3): ");
-//		str_uint64(fgets(c_input, 1, stdin), &endptr, 10, true, &input);
-//		printf("%llu\n", input);
-//	}
-
-	if ((rc = get_input(in, &str)) != EOK)
-		return rc;
-
-	if (str_uint32_t(str, &endptr, 10, true, &input) != EOK || input > 3) {
-		printf("Invalid value. Canceled.\n");
-		return EINVAL;
-	}
-
-	free(str);
-
-	for (; input > 0; --input) {
-		p = p->next;
-	}
-
-	set_partition(in, p);
-
-	return EOK;
-}
-
-int add_logical(tinput_t * in, part_t * parts)
-{
-	int i;
-	part_t * p = parts;
-	part_t * ext = NULL;
-
-	//checking primary partitions for extended partition
-	for (i = 0; i < N_PRIMARY; ++i) {
-		if (p->type == PT_EXTENDED) {
-			ext = p;
-			break;
-		}
-		p = p->next;
-	}
-
-	if (ext == NULL) {
-		printf("Error: no extended partition.\n");
-		return EINVAL;
-	}
-
-	while (p->next != NULL) {
-		p = p->next;
-	}
-
-	p->next = malloc(sizeof(part_t));
-	if (p->next == NULL) {
-		printf("Error: not enough memory.\n");
-		return ENOMEM;
-	}
-
-	p->next->ebr = malloc(sizeof(br_block_t));
-	if (p->next->ebr == NULL) {
-		printf("Error: not enough memory.\n");
-		return ENOMEM;
-	}
-
-	set_partition(in, p->next);
-
-	return EOK;
-}
-
-int set_mbr_partition(tinput_t * in, part_t * p)
-{
-	char * str;
-	int rc;
-	uint8_t type;
-	char * endptr;
-
-//	while (type > 255) {
-//		printf("Set type (0-255): ");
-//		str_uint64(fgets(c_type, 3, stdin), &endptr, 10, true, &type);
-//	}
-
-	if ((rc = get_input(in, &str)) != EOK)
-		return rc;
-
-	if (str_uint8_t(str, &endptr, 10, true, &type) != EOK) {
-		printf("Invalid value. Canceled.\n");
-		return EINVAL;
-	}
-
-	free(str);
-
-	///TODO: there can only be one bootable partition; let's do it just like fdisk
-	printf("Bootable? (y/n): ");
-	int c = getchar();
-	printf("%c\n", c);
-	if (c != 'y' && c != 'Y' && c != 'n' && c != 'N') {
-		printf("Invalid value. Cancelled.");
-		return EINVAL;
-	}
-
-	uint32_t sa, ea;
-
-	printf("Set starting address (number): ");
-	//str_uint64(fgets(c_sa, 21, stdin), &endptr, 10, true, &sa);
-
-	if ((rc = get_input(in, &str)) != EOK)
-		return rc;
-
-	if(str_uint32_t(str, &endptr, 10, true, &sa) != EOK) {
-		printf("Invalid value. Canceled.\n");
-		return EINVAL;
-	}
-
-	free(str);
-
-	printf("Set end addres (number): ");
-	//str_uint64(fgets(c_len, 21, stdin), &endptr, 10, true, &len);
-
-	if ((rc = get_input(in, &str)) != EOK)
-		return rc;
-
-	if(str_uint32_t(str, &endptr, 10, true, &ea) != EOK || ea < sa) {
-		printf("Invalid value. Canceled.\n");
-		return EINVAL;
-	}
-
-	free(str);
-
-	p->type = type;
-	p->bootable = (c == 'y' || c == 'Y') ? true : false;
-	p->start_addr = sa;
-	p->length = ea - sa;
-
-	return EOK;
-}
-
-
+void fill_table_funcs(void)
+{
+	switch(table.layout) {
+		case LYT_MBR:
+			table.add_part = add_mbr_part;
+			table.delete_part = delete_mbr_part;
+			table.print_parts = print_mbr_parts;
+			table.write_parts = write_mbr_parts;
+			break;
+		case LYT_GPT:
+			table.add_part = add_gpt_part;
+			table.delete_part = delete_gpt_part;
+			table.print_parts = print_gpt_parts;
+			table.write_parts = write_gpt_parts;
+			break;
+		default:
+			break;
+	}
+}
+
+void free_table(void)
+{
+	switch(table.layout) {
+		case LYT_MBR:
+			mbr_free_partitions(table.data.mbr.parts);
+			mbr_free_mbr(table.data.mbr.mbr);
+			break;
+		case LYT_GPT:
+			gpt_free_partitions(table.data.gpt.parts);
+			gpt_free_gpt(table.data.gpt.gpt);
+			break;
+		default:
+			break;
+	}
+}
+
Index: uspace/lib/gpt/Makefile
===================================================================
--- uspace/lib/gpt/Makefile	(revision ec50ac4a5f0f112c28f2a78b993c2c607f166d95)
+++ uspace/lib/gpt/Makefile	(revision 271e24a4aca586ebdc97458d9836e0a3a3e1038c)
@@ -32,5 +32,6 @@
 
 SOURCES = \
-	libgpt.c
+	libgpt.c \
+	global.c
 
 include $(USPACE_PREFIX)/Makefile.common
Index: uspace/lib/gpt/libgpt.c
===================================================================
--- uspace/lib/gpt/libgpt.c	(revision ec50ac4a5f0f112c28f2a78b993c2c607f166d95)
+++ uspace/lib/gpt/libgpt.c	(revision 271e24a4aca586ebdc97458d9836e0a3a3e1038c)
@@ -52,7 +52,7 @@
 
 static int load_and_check_header(service_id_t handle, aoff64_t addr, size_t b_size, gpt_header_t * header);
-static gpt_parts_t * alloc_part_array(uint32_t num);
-static int extend_part_array(gpt_parts_t * p);
-static int reduce_part_array(gpt_parts_t * p);
+static gpt_partitions_t * alloc_part_array(uint32_t num);
+static int extend_part_array(gpt_partitions_t * p);
+static int reduce_part_array(gpt_partitions_t * p);
 static long long nearest_larger_int(double a);
 
@@ -162,9 +162,9 @@
  * 				error code is stored in errno
  */
-gpt_parts_t * gpt_read_partitions(gpt_t * gpt)
+gpt_partitions_t * gpt_read_partitions(gpt_t * gpt)
 {
 	int rc;
 	unsigned int i;
-	gpt_parts_t * res;
+	gpt_partitions_t * res;
 	uint32_t num_ent = uint32_t_le2host(gpt->raw_data->num_entries);
 	uint32_t ent_size = uint32_t_le2host(gpt->raw_data->entry_size);
@@ -242,5 +242,5 @@
  * @return				returns EOK on succes, specific error code otherwise
  */
-int gpt_write_partitions(gpt_parts_t * parts, gpt_t * gpt, service_id_t dev_handle)
+int gpt_write_partitions(gpt_partitions_t * parts, gpt_t * gpt, service_id_t dev_handle)
 {
 	int rc;
@@ -283,12 +283,15 @@
 }
 
-gpt_parts_t * gpt_add_partition(gpt_parts_t * parts, g_part_t * partition)
-{
-	
-}
-
-gpt_parts_t * gpt_remove_partition(gpt_parts_t * parts, int idx)
-{
-	
+gpt_partitions_t * gpt_add_partition(gpt_partitions_t * parts, gpt_part_t * partition)
+{
+	
+	extend_part_array(parts);
+	return parts;
+}
+
+gpt_partitions_t * gpt_remove_partition(gpt_partitions_t * parts, size_t idx)
+{
+	reduce_part_array(parts);
+	return parts;
 }
 
@@ -304,5 +307,5 @@
  * @param parts		partition list to be freed
  */
-void gpt_free_partitions(gpt_parts_t * parts)
+void gpt_free_partitions(gpt_partitions_t * parts)
 {
 	free(parts->part_array);
@@ -316,5 +319,5 @@
  * 
  */
-void gpt_set_part_type(g_part_t * p, int type)
+void gpt_set_part_type(gpt_part_t * p, int type)
 {
 	/* Beware: first 3 blocks are byteswapped! */
@@ -386,7 +389,7 @@
 }
 
-static gpt_parts_t * alloc_part_array(uint32_t num)
-{
-	gpt_parts_t * res = malloc(sizeof(gpt_parts_t));
+static gpt_partitions_t * alloc_part_array(uint32_t num)
+{
+	gpt_partitions_t * res = malloc(sizeof(gpt_partitions_t));
 	if (res == NULL) {
 		errno = ENOMEM;
@@ -408,5 +411,5 @@
 }
 
-static int extend_part_array(gpt_parts_t * p)
+static int extend_part_array(gpt_partitions_t * p)
 {
 	unsigned int nsize = p->arr_size * 2;
@@ -425,5 +428,5 @@
 }
 
-static int reduce_part_array(gpt_parts_t * p)
+static int reduce_part_array(gpt_partitions_t * p)
 {
 	if(p->arr_size > GPT_MIN_PART_NUM) {
Index: uspace/lib/gpt/libgpt.h
===================================================================
--- uspace/lib/gpt/libgpt.h	(revision ec50ac4a5f0f112c28f2a78b993c2c607f166d95)
+++ uspace/lib/gpt/libgpt.h	(revision 271e24a4aca586ebdc97458d9836e0a3a3e1038c)
@@ -36,6 +36,7 @@
 #define __GPT_H__
 
-#define NAME	"libgpt"
+#define LIBGPT_NAME	"libgpt"
 
+#include <loc.h>
 #include <sys/types.h>
 
@@ -50,7 +51,5 @@
 
 /** GPT header signature ("EFI PART" in ASCII) */
-const uint8_t efi_signature[8] = {
-	0x45, 0x46, 0x49, 0x20, 0x50, 0x41, 0x52, 0x54
-};
+extern const uint8_t efi_signature[8];
 
 /** GPT header
@@ -102,5 +101,5 @@
 	/** Raw data access */
 	gpt_entry_t raw_data;	//TODO: a pointer or just a member?
-}g_part_t;
+}gpt_part_t;
 
 typedef struct gpt_parts {
@@ -111,5 +110,11 @@
 	/** Resizable partition array */
 	gpt_entry_t * part_array;
-} gpt_parts_t;
+} gpt_partitions_t;
+
+
+typedef struct gpt_table {
+	gpt_t * gpt;
+	gpt_partitions_t * parts;
+} gpt_table_t;
 
 struct partition_type {
@@ -118,68 +123,6 @@
 };
 
-struct partition_type gpt_ptypes[] = {
-	{ "Unused entry",					"00000000-0000-0000-0000-000000000000" },
-	{ "MBR partition scheme",			"024DEE41-33E7-11D3-9D69-0008C781F39F" },
-	{ "EFI System",						"C12A7328-F81F-11D2-BA4B-00A0C93EC93B" },
-	{ "BIOS Boot",						"21686148-6449-6E6F-744E-656564454649" },
-	{ "Windows Reserved",				"E3C9E316-0B5C-4DB8-817D-F92DF00215AE" },
-	{ "Windows Basic data",				"EBD0A0A2-B9E5-4433-87C0-68B6B72699C7" },
-	{ "Windows LDM metadata", 			"5808C8AA-7E8F-42E0-85D2-E1E90434CFB3" },
-	{ "Windows LDM data", 				"AF9B60A0-1431-4F62-BC68-3311714A69AD" },
-	{ "Windows Recovery Environment",	"DE94BBA4-06D1-4D40-A16A-BFD50179D6AC" },
-	{ "Windows IBM GPFS",				"37AFFC90-EF7D-4E96-91C3-2D7AE055B174" },
-	{ "Windows Cluster metadata",		"DB97DBA9-0840-4BAE-97F0-FFB9A327C7E1" },
-	{ "HP-UX Data",						"75894C1E-3AEB-11D3-B7C1-7B03A0000000" },
-	{ "HP-UX Service",					"E2A1E728-32E3-11D6-A682-7B03A0000000" },
-	{ "Linux filesystem data",			"EBD0A0A2-B9E5-4433-87C0-68B6B72699C7" },
-	{ "Linux filesystem data",			"0FC63DAF-8483-4772-8E79-3D69D8477DE4" },
-	{ "Linux RAID",						"A19D880F-05FC-4D3B-A006-743F0F84911E" },
-	{ "Linux Swap",						"0657FD6D-A4AB-43C4-84E5-0933C84B4F4F" },
-	{ "Linux LVM",						"E6D6D379-F507-44C2-A23C-238F2A3DF928" },
-	{ "Linux Reserved",					"8DA63339-0007-60C0-C436-083AC8230908" },
-	{ "FreeBSD Boot",					"83BD6B9D-7F41-11DC-BE0B-001560B84F0F" },
-	{ "FreeBSD Data",					"516E7CB4-6ECF-11D6-8FF8-00022D09712B" },
-	{ "FreeBSD Swap",					"516E7CB5-6ECF-11D6-8FF8-00022D09712B" },
-	{ "FreeBSD UFS", 					"516E7CB6-6ECF-11D6-8FF8-00022D09712B" },
-	{ "FreeBSD Vinum VM",				"516E7CB8-6ECF-11D6-8FF8-00022D09712B" },
-	{ "FreeBSD ZFS",					"516E7CBA-6ECF-11D6-8FF8-00022D09712B" },
-	{ "Mac OS X HFS+",					"48465300-0000-11AA-AA11-00306543ECAC" },
-	{ "Mac OS X UFS",					"55465300-0000-11AA-AA11-00306543ECAC" },
-	{ "Mac OS X ZFS",					"6A898CC3-1DD2-11B2-99A6-080020736631" },
-	{ "Mac OS X RAID",					"52414944-0000-11AA-AA11-00306543ECAC" },
-	{ "Mac OS X RAID, offline",			"52414944-5F4F-11AA-AA11-00306543ECAC" },
-	{ "Mac OS X Boot",					"426F6F74-0000-11AA-AA11-00306543ECAC" },
-	{ "Mac OS X Label",					"4C616265-6C00-11AA-AA11-00306543ECAC" },
-	{ "Mac OS X TV Recovery",			"5265636F-7665-11AA-AA11-00306543ECAC" },
-	{ "Mac OS X Core Storage",			"53746F72-6167-11AA-AA11-00306543ECAC" },
-	{ "Solaris Boot",					"6A82CB45-1DD2-11B2-99A6-080020736631" },
-	{ "Solaris Root",					"6A85CF4D-1DD2-11B2-99A6-080020736631" },
-	{ "Solaris Swap",					"6A87C46F-1DD2-11B2-99A6-080020736631" },
-	{ "Solaris Backup",					"6A8B642B-1DD2-11B2-99A6-080020736631" },
-	{ "Solaris /usr",					"6A898CC3-1DD2-11B2-99A6-080020736631" },
-	{ "Solaris /var",					"6A8EF2E9-1DD2-11B2-99A6-080020736631" },
-	{ "Solaris /home",					"6A90BA39-1DD2-11B2-99A6-080020736631" },
-	{ "Solaris Alternate sector",		"6A9283A5-1DD2-11B2-99A6-080020736631" },
-	{ "Solaris Reserved",				"6A945A3B-1DD2-11B2-99A6-080020736631" },
-	{ "Solaris Reserved",				"6A9630D1-1DD2-11B2-99A6-080020736631" },
-	{ "Solaris Reserved",				"6A980767-1DD2-11B2-99A6-080020736631" },
-	{ "Solaris Reserved",				"6A96237F-1DD2-11B2-99A6-080020736631" },
-	{ "Solaris Reserved",				"6A8D2AC7-1DD2-11B2-99A6-080020736631" },
-	{ "NetBSD Swap",					"49F48D32-B10E-11DC-B99B-0019D1879648" },
-	{ "NetBSD FFS",						"49F48D5A-B10E-11DC-B99B-0019D1879648" },
-	{ "NetBSD LFS",						"49F48D82-B10E-11DC-B99B-0019D1879648" },
-	{ "NetBSD RAID",					"49F48DAA-B10E-11DC-B99B-0019D1879648" },
-	{ "NetBSD Concatenated",			"2DB519C4-B10F-11DC-B99B-0019D1879648" },
-	{ "NetBSD Encrypted",				"2DB519EC-B10F-11DC-B99B-0019D1879648" },
-	{ "ChromeOS ChromeOS kernel",		"FE3A2A5D-4F32-41A7-B725-ACCC3285A309" },
-	{ "ChromeOS rootfs",				"3CB8E202-3B7E-47DD-8A3C-7FF2A13CFCEC" },
-	{ "ChromeOS future use",			"2E0A753D-9E48-43B0-8337-B15192CB1B5E" },
-	{ "MidnightBSD Boot",				"85D5E45E-237C-11E1-B4B3-E89A8F7FC3A7" },
-	{ "MidnightBSD Data",				"85D5E45A-237C-11E1-B4B3-E89A8F7FC3A7" },
-	{ "MidnightBSD Swap",				"85D5E45B-237C-11E1-B4B3-E89A8F7FC3A7" },
-	{ "MidnightBSD UFS",				"0394Ef8B-237E-11E1-B4B3-E89A8F7FC3A7" },
-	{ "MidnightBSD Vinum VM",			"85D5E45C-237C-11E1-B4B3-E89A8F7FC3A7" },
-	{ "MidnightBSD ZFS",				"85D5E45D-237C-11E1-B4B3-E89A8F7FC3A7" }
-};
+extern const struct partition_type gpt_ptypes[];
+
 
 
@@ -187,13 +130,14 @@
 extern int gpt_write_gpt_header(gpt_t * header, service_id_t dev_handle);
 
-extern gpt_parts_t * gpt_read_partitions(gpt_t * gpt);
-extern int 			 gpt_write_partitions(gpt_parts_t * parts, gpt_t * header, service_id_t dev_handle);
-extern int			 gpt_add_partition(gpt_parts_t * parts, g_part_t * partition);
-extern void			 gpt_remove_partition(gpt_parts_t * parts, int idx);
-extern void 		 gpt_set_part_type(g_part_t * p, int type);
-extern void 		 gpt_set_part_name(gpt_entry_t * p, char * name[], size_t length);
+extern gpt_partitions_t * gpt_read_partitions(gpt_t * gpt);
+extern int 				  gpt_write_partitions(gpt_partitions_t * parts, gpt_t * header, service_id_t dev_handle);
+extern gpt_partitions_t * gpt_add_partition(gpt_partitions_t * parts, gpt_part_t * partition);
+extern gpt_partitions_t * gpt_remove_partition(gpt_partitions_t * parts, size_t idx);
+extern void 			  gpt_set_part_type(gpt_part_t * p, int type);
+extern void 			  gpt_set_part_name(gpt_entry_t * p, char * name[], size_t length);
 
 extern void gpt_free_gpt(gpt_t * gpt);
-extern void gpt_free_partitions(gpt_parts_t * parts);
+extern void gpt_free_partitions(gpt_partitions_t * parts);
 
 #endif
+
Index: uspace/lib/mbr/libmbr.c
===================================================================
--- uspace/lib/mbr/libmbr.c	(revision ec50ac4a5f0f112c28f2a78b993c2c607f166d95)
+++ uspace/lib/mbr/libmbr.c	(revision 271e24a4aca586ebdc97458d9836e0a3a3e1038c)
@@ -12,5 +12,5 @@
  *   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
+ * - The LIBMBR_NAME of the author may not be used to endorse or promote products
  *   derived from this software without specific prior written permission.
  *
@@ -45,7 +45,7 @@
 
 static br_block_t * alloc_br(void);
-static int decode_part(pt_entry_t * src, part_t * trgt, uint32_t base);
-static int decode_logical(mbr_t * mbr, mbr_parts_t * p, part_t * ext);
-static void encode_part(part_t * src, pt_entry_t * trgt, uint32_t base);
+static int decode_part(pt_entry_t * src, mbr_part_t * trgt, uint32_t base);
+static int decode_logical(mbr_t * mbr, mbr_partitions_t * p, mbr_part_t * ext);
+static void encode_part(mbr_part_t * src, pt_entry_t * trgt, uint32_t base);
 
 /** Read MBR from specific device
@@ -123,10 +123,10 @@
  * @return 		linked list of partitions or NULL on error
  */
-mbr_parts_t * mbr_read_partitions(mbr_t * mbr)
+mbr_partitions_t * mbr_read_partitions(mbr_t * mbr)
 {
 	int rc, i;
-	part_t * p;
-	part_t * ext = NULL;
-	mbr_parts_t * parts;
+	mbr_part_t * p;
+	mbr_part_t * ext = NULL;
+	mbr_partitions_t * parts;
 
 	if (mbr == NULL)
@@ -143,7 +143,7 @@
 			continue;
 		
-		p = malloc(sizeof(part_t));
+		p = malloc(sizeof(mbr_part_t));
 		if (p == NULL) {
-			printf(NAME ": Error on memory allocation.\n");
+			printf(LIBMBR_NAME ": Error on memory allocation.\n");
 			free(p);
 			mbr_free_partitions(parts);
@@ -159,6 +159,6 @@
 	rc = decode_logical(mbr, parts, ext);
 	if (rc != EOK) {
-		printf(NAME ": Error occured during decoding the MBR.\n" \
-			   NAME ": Partition list may be incomplete.\n");
+		printf(LIBMBR_NAME ": Error occured during decoding the MBR.\n" \
+			   LIBMBR_NAME ": Partition list may be incomplete.\n");
 	}
 
@@ -173,12 +173,12 @@
  * @return				returns EOK on succes, specific error code otherwise
  */
-int mbr_write_partitions(mbr_parts_t * parts, mbr_t * mbr, service_id_t dev_handle)
+int mbr_write_partitions(mbr_partitions_t * parts, mbr_t * mbr, service_id_t dev_handle)
 {
 	bool logical = false;
 	int i = 0;
 	int rc;
-	part_t * p;
-	part_t * ext = (parts->l_extended == NULL) ? NULL
-					: list_get_instance(parts->l_extended, part_t, link);
+	mbr_part_t * p;
+	mbr_part_t * ext = (parts->l_extended == NULL) ? NULL
+					: list_get_instance(parts->l_extended, mbr_part_t, link);
 	
 	br_block_t * last_ebr = NULL;
@@ -194,8 +194,8 @@
 
 	aoff64_t addr = ext->start_addr;
-	part_t * prev_part = NULL;
+	mbr_part_t * prev_part = NULL;
 
 	list_foreach(parts->list, it) {
-		p = list_get_instance(it, part_t, link);
+		p = list_get_instance(it, mbr_part_t, link);
 		if (mbr_get_flag(p, ST_LOGIC)) {
 			// writing logical partition
@@ -269,5 +269,5 @@
 
 	list_foreach(parts->list, it) {
-		p = list_get_instance(it, part_t, link);
+		p = list_get_instance(it, mbr_part_t, link);
 		if (mbr_get_flag(p, ST_LOGIC)) {
 			// extended does not exist, fail
@@ -295,5 +295,5 @@
 			ext = p;
 
-		//p = list_get_instance(p->link.next, mbr_parts_t, link);
+		//p = list_get_instance(p->link.next, mbr_partitions_t, link);
 		p = p->next;
 	}
@@ -357,8 +357,8 @@
 }
 
-/** part_t constructor */
-part_t * mbr_alloc_partition(void)
-{
-	part_t * p = malloc(sizeof(part_t));
+/** mbr_part_t constructor */
+mbr_part_t * mbr_alloc_partition(void)
+{
+	mbr_part_t * p = malloc(sizeof(mbr_part_t));
 	if (p == NULL) {
 		return NULL;
@@ -374,7 +374,7 @@
 }
 
-mbr_parts_t * mbr_alloc_partitions(void)
-{
-	mbr_parts_t * parts = malloc(sizeof(mbr_parts_t));
+mbr_partitions_t * mbr_alloc_partitions(void)
+{
+	mbr_partitions_t * parts = malloc(sizeof(mbr_partitions_t));
 	if (parts == NULL) {
 		return NULL;
@@ -387,20 +387,23 @@
 
 /** Add partition */
-void mbr_add_partition(mbr_parts_t * parts, part_t * partition)
+int mbr_add_partition(mbr_partitions_t * parts, mbr_part_t * partition)
 {
 	list_append(&(partition->link), &(parts->list));
+	return EOK;
 }
 
 /** Remove partition */
-void mbr_remove_partition(mbr_parts_t * parts, int idx)
+int mbr_remove_partition(mbr_partitions_t * parts, size_t idx)
 {
 	link_t * l = list_nth(&(parts->list), idx);
 	list_remove(l);
-	part_t * p = list_get_instance(l, part_t, link);
+	mbr_part_t * p = list_get_instance(l, mbr_part_t, link);
 	mbr_free_partition(p);
-}
-
-/** part_t destructor */
-void mbr_free_partition(part_t * p)
+	
+	return EOK;
+}
+
+/** mbr_part_t destructor */
+void mbr_free_partition(mbr_part_t * p)
 {
 	if (p->ebr != NULL)
@@ -410,5 +413,5 @@
 
 /** Get flag bool value */
-int mbr_get_flag(part_t * p, MBR_FLAGS flag)
+int mbr_get_flag(mbr_part_t * p, MBR_FLAGS flag)
 {
 	return (p->status & (1 << flag)) ? 1 : 0;
@@ -416,5 +419,5 @@
 
 /** Set a specifig status flag to a value */
-void mbr_set_flag(part_t * p, MBR_FLAGS flag, bool value)
+void mbr_set_flag(mbr_part_t * p, MBR_FLAGS flag, bool value)
 {
 	uint8_t status = p->status;
@@ -438,8 +441,8 @@
  * @param parts		partition list to be freed
  */
-void mbr_free_partitions(mbr_parts_t * parts)
+void mbr_free_partitions(mbr_partitions_t * parts)
 {
 	list_foreach_safe(parts->list, cur_link, next) {
-		part_t * p = list_get_instance(cur_link, part_t, link);
+		mbr_part_t * p = list_get_instance(cur_link, mbr_part_t, link);
 		list_remove(cur_link);
 		mbr_free_partition(p);
@@ -462,6 +465,6 @@
 }
 
-/** Parse partition entry to part_t */
-static int decode_part(pt_entry_t * src, part_t * trgt, uint32_t base)
+/** Parse partition entry to mbr_part_t */
+static int decode_part(pt_entry_t * src, mbr_part_t * trgt, uint32_t base)
 {
 	trgt->type = src->ptype;
@@ -477,11 +480,11 @@
 }
 
-/** Parse MBR contents to part_t list
+/** Parse MBR contents to mbr_part_t list
  * parameter 'p' is allocated for only used primary partitions
  */
-static int decode_logical(mbr_t * mbr, mbr_parts_t * parts, part_t * ext)
+static int decode_logical(mbr_t * mbr, mbr_partitions_t * parts, mbr_part_t * ext)
 {
 	int rc;
-	part_t * p;
+	mbr_part_t * p;
 
 	if (mbr == NULL || parts == NULL)
@@ -534,6 +537,6 @@
 }
 
-/** Convert part_t to pt_entry_t */
-static void encode_part(part_t * src, pt_entry_t * trgt, uint32_t base)
+/** Convert mbr_part_t to pt_entry_t */
+static void encode_part(mbr_part_t * src, pt_entry_t * trgt, uint32_t base)
 {
 	if (src != NULL) {
Index: uspace/lib/mbr/libmbr.h
===================================================================
--- uspace/lib/mbr/libmbr.h	(revision ec50ac4a5f0f112c28f2a78b993c2c607f166d95)
+++ uspace/lib/mbr/libmbr.h	(revision 271e24a4aca586ebdc97458d9836e0a3a3e1038c)
@@ -36,5 +36,7 @@
 #define LIBMBR_LIBMBR_H_
 
-#define NAME	"libmbr"
+#include <sys/types.h>
+
+#define LIBMBR_NAME	"libmbr"
 
 /** Number of primary partition records */
@@ -108,7 +110,7 @@
 
 
-//FIXME: make mbr_parts_t as the linked list for keeping the same interface as with GPT
+//FIXME: make mbr_partitions_t as the linked list for keeping the same interface as with GPT
 /** Partition */
-typedef struct part {
+typedef struct mbr_part {
 	/** The link in the doubly-linked list */
 	link_t link;
@@ -118,10 +120,10 @@
 	uint8_t status;
 	/** Address of first block */
-	aoff64_t start_addr;
+	uint32_t start_addr;
 	/** Number of blocks */
-	aoff64_t length;
+	uint32_t length;
 	/** Points to Extended Boot Record of logical partition */
 	br_block_t * ebr;
-} part_t;
+} mbr_part_t;
 
 typedef struct mbr_parts {
@@ -134,6 +136,10 @@
 	/** Partition linked list */
 	list_t list;
-} mbr_parts_t;
+} mbr_partitions_t;
 
+typedef struct mbr_table {
+	mbr_t * mbr;
+	mbr_partitions_t * parts;
+} mbr_table_t;
 
 /** Read/Write MBR header.
@@ -146,20 +152,23 @@
 
 /** Read/Write/Set MBR partitions. */
-extern mbr_parts_t * mbr_read_partitions(mbr_t * mbr);
-extern int 			 mbr_write_partitions(mbr_parts_t * parts, mbr_t * mbr, service_id_t dev_handle);
-extern part_t *		 mbr_alloc_partition(void);
-extern mbr_parts_t * mbr_alloc_partitions(void);
-extern void			 mbr_add_partition(mbr_parts_t * parts, part_t * partition);
-extern void			 mbr_remove_partition(mbr_parts_t * parts, int idx);
-extern int			 mbr_get_flag(part_t * p, MBR_FLAGS flag);
-extern void			 mbr_set_flag(part_t * p, MBR_FLAGS flag, bool value);
+extern mbr_partitions_t * mbr_read_partitions(mbr_t * mbr);
+extern int 			mbr_write_partitions(mbr_partitions_t * parts, mbr_t * mbr, service_id_t dev_handle);
+extern mbr_part_t *	mbr_alloc_partition(void);
+extern mbr_partitions_t * mbr_alloc_partitions(void);
+extern int			mbr_add_partition(mbr_partitions_t * parts, mbr_part_t * partition);
+extern int			mbr_remove_partition(mbr_partitions_t * parts, size_t idx);
+extern int			mbr_get_flag(mbr_part_t * p, MBR_FLAGS flag);
+extern void			mbr_set_flag(mbr_part_t * p, MBR_FLAGS flag, bool value);
 
 #define mbr_part_foreach(parts, iterator)	\
-			list_foreach(parts->list, iterator)
+			for (mbr_part_t * iterator = list_get_instance((parts)->list.head.next, mbr_part_t, link); \
+				iterator != list_get_instance(&(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_mbr(mbr_t * mbr);
-extern void mbr_free_partition(part_t * p);
-extern void mbr_free_partitions(mbr_parts_t * parts);
+extern void mbr_free_partition(mbr_part_t * p);
+extern void mbr_free_partitions(mbr_partitions_t * parts);
 
 #endif
