From 7ab41812ea213e5283d9089a6a6c413679ddddcd Mon Sep 17 00:00:00 2001 From: Pali Rohár Date: Tue, 7 Aug 2012 17:31:53 +0200 Subject: fiasco: Implemented unpacking to directory --- src/fiasco2.c | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) (limited to 'src') 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; } -- cgit v1.2.3