summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPali Rohár <pali.rohar@gmail.com>2012-08-07 17:31:53 +0200
committerPali Rohár <pali.rohar@gmail.com>2012-08-07 17:31:53 +0200
commit7ab41812ea213e5283d9089a6a6c413679ddddcd (patch)
tree06c832b0dfbc14d01fe21b40fcadb8a2fafc5079 /src
parent2cab7a9c8091f61061092c7476f04bb5e21f34da (diff)
download0xFFFF-7ab41812ea213e5283d9089a6a6c413679ddddcd.tar.bz2
fiasco: Implemented unpacking to directory
Diffstat (limited to 'src')
-rw-r--r--src/fiasco2.c37
1 files changed, 34 insertions, 3 deletions
diff --git a/src/fiasco2.c b/src/fiasco2.c
index a8d78e5..5da202d 100644
--- a/src/fiasco2.c
+++ b/src/fiasco2.c
@@ -487,12 +487,13 @@ int fiasco_write_to_file(struct fiasco * fiasco, const char * file) {
int fiasco_unpack(struct fiasco * fiasco, const char * dir) {
+ int fd;
char * name;
char * layout_name;
- const char * type;
- const char * device;
struct image * image;
struct image_list * image_list;
+ uint32_t size;
+ unsigned char buf[4096];
if ( dir && chdir(dir) < 0 ) {
perror("Cannot chdir");
@@ -537,10 +538,40 @@ int fiasco_unpack(struct fiasco * fiasco, const char * dir) {
printf(" output file: %s\n", name);
- /* TODO: Unpack image */
+ fd = open(name, O_RDWR|O_CREAT|O_TRUNC, 0644);
+ if ( fd < 0 ) {
+ perror("Cannot create file");
+ return -1;
+ }
free(name);
+ image_seek(image, 0);
+ while ( 1 ) {
+ size = image_read(image, buf, sizeof(buf));
+ if ( size < 1 )
+ break;
+ WRITE_OR_FAIL(fd, buf, size);
+ }
+
+ close(fd);
+
+ if ( image->layout ) {
+
+ fd = open(layout_name, O_RDWR|O_CREAT|O_TRUNC, 0644);
+ if ( fd < 0 ) {
+ perror("Cannot create file");
+ return -1;
+ }
+
+ free(layout_name);
+
+ WRITE_OR_FAIL(fd, image->layout, (int)strlen(image->layout));
+
+ close(fd);
+
+ }
+
image_list = image_list->next;
}