blockdev: Add missing partition functions

Signed-off-by: Thomas Heijligen <src@posteo.de>
diff --git a/src/blockdev.c b/src/blockdev.c
index 43c990c..d3c2a48 100644
--- a/src/blockdev.c
+++ b/src/blockdev.c
@@ -5,8 +5,13 @@
 
 #include "blockdev.h"
 
-FILE* block_device = NULL;
-size_t device_size = 0;
+// private
+static FILE* block_device = NULL;
+static size_t device_size = 0;
+
+// from filo
+unsigned long part_start = 0;
+unsigned long part_length = 0;
 
 
 int devopen(const char* name, int* reopen)
@@ -26,6 +31,9 @@
 		return 0;
 	}
 
+	part_start = 0;
+	part_length = device_size;
+
 	return 1;
 }
 
@@ -37,6 +45,8 @@
 	}
 	block_device = NULL;
 	device_size = 0;
+	part_start = 0;
+	part_length = 0;
 }
 
 int devread(unsigned long sector, unsigned long byte_offset, unsigned long byte_len, void *buf)
@@ -65,12 +75,17 @@
 
 
 
-//void dev_set_partition(unsigned long start, unsigned long size);
-//void dev_get_partition(unsigned long *start, unsigned long *size);
+void dev_set_partition(unsigned long start, unsigned long size)
+{
+	if (start + size <= device_size) {
+		part_start = start;
+		part_length = size;
+	}
+}
 
-//int file_open(const char *filename);
-//int file_read(void *buf, unsigned long len);
-//unsigned long file_seek(unsigned long offset);
-//unsigned long file_size(void);
-//void file_set_size(unsigned long size);
-//void file_close(void);
+void dev_get_partition(unsigned long *start, unsigned long *size)
+{
+	*start = part_start;
+	*size = part_length;
+}
+
diff --git a/src/blockdev.h b/src/blockdev.h
index 77256aa..0def901 100644
--- a/src/blockdev.h
+++ b/src/blockdev.h
@@ -22,15 +22,17 @@
 int devread(unsigned long sector, unsigned long byte_offset,
 	unsigned long byte_len, void *buf);
 
+/** dev_set_partition
+ * Set partition offset and size. if start + size > blockdevice, do nothing
+ * @param start
+ * @param size
+ */
+void dev_set_partition(unsigned long start, unsigned long size);
 
-//void dev_set_partition(unsigned long start, unsigned long size);
-//void dev_get_partition(unsigned long *start, unsigned long *size);
-
-//int file_open(const char *filename);
-//int file_read(void *buf, unsigned long len);
-//unsigned long file_seek(unsigned long offset);
-//unsigned long file_size(void);
-//void file_set_size(unsigned long size);
-//void file_close(void);
+/** dev_get_partition
+ * @param *start  will be filled with the partition offset
+ * @param *size   will be filled with the partition length
+ */
+void dev_get_partition(unsigned long *start, unsigned long *size);
 
 #endif /* BLOCKDEV_H */