From f44e46cde522d5a20ce5c2703cf9bbf6a19484fa Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Sat, 10 May 2014 15:54:57 +0200 Subject: [PATCH] Flatten initrd symbolic links to hardlinks inside the same directory. --- kernel/initrd.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/kernel/initrd.cpp b/kernel/initrd.cpp index d1d456ab..18100398 100644 --- a/kernel/initrd.cpp +++ b/kernel/initrd.cpp @@ -261,6 +261,42 @@ static bool ExtractDir(struct initrd_context* ctx, initrd_inode_t* inode, Refmode) ) + { + size_t filesize; + uint8_t* data = initrd_inode_get_data(ctx, child, &filesize); + if ( !data ) + return false; + char* dest_path = new char[filesize + 1]; + if ( !dest_path ) + return false; + memcpy(dest_path, data, filesize); + dest_path[filesize] = '\0'; + // TODO: Currently only symbolic links to files inside the same + // directory are supported when converted to hardlinks. + if ( !strchr(dest_path, '/') ) + { + if ( Ref dest = dir->open(&ctx->ioctx, dest_path, O_READ, 0) ) + dir->link(&ctx->ioctx, name, dest); + } + delete[] dest_path; + ctx->amount_extracted += child->size; + initrd_progress(ctx); + } + } + ctx->amount_extracted += inode->size; initrd_progress(ctx); return true;