fiasco: Implemented unpacking to directory

This commit is contained in:
Pali Rohár committed 2012-08-07 17:31:53 +02:00
1 parent 2cab7a9c80
commit 7ab41812ea
1 file changed
+34 -3
+34 -3
View File
@@ -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;
}