From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matt Evans Subject: [PATCH V2 12/23] kvm tools: Allow initrd_check() to match a cpio Date: Fri, 09 Dec 2011 17:54:37 +1100 Message-ID: <4EE1B0AD.3070904@ozlabs.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: penberg@kernel.org, asias.hejun@gmail.com, levinsasha928@gmail.com, gorcunov@gmail.com To: kvm@vger.kernel.org, kvm-ppc@vger.kernel.org Return-path: In-Reply-To: Sender: kvm-ppc-owner@vger.kernel.org List-Id: kvm.vger.kernel.org cpios are valid as initrds too, so allow them through the check. Signed-off-by: Matt Evans --- tools/kvm/kvm.c | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-) diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c index 0bbe9ba..d26e3d7 100644 --- a/tools/kvm/kvm.c +++ b/tools/kvm/kvm.c @@ -351,10 +351,11 @@ struct kvm *kvm__init(const char *kvm_dev, u64 ram_size, const char *name) /* RFC 1952 */ #define GZIP_ID1 0x1f #define GZIP_ID2 0x8b - +#define CPIO_MAGIC "0707" +/* initrd may be gzipped, or a plain cpio */ static bool initrd_check(int fd) { - unsigned char id[2]; + unsigned char id[4]; if (read_in_full(fd, id, ARRAY_SIZE(id)) < 0) return false; @@ -362,7 +363,8 @@ static bool initrd_check(int fd) if (lseek(fd, 0, SEEK_SET) < 0) die_perror("lseek"); - return id[0] == GZIP_ID1 && id[1] == GZIP_ID2; + return (id[0] == GZIP_ID1 && id[1] == GZIP_ID2) || + !memcmp(id, CPIO_MAGIC, 4); } bool kvm__load_kernel(struct kvm *kvm, const char *kernel_filename,