From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755362AbZDFTVy (ORCPT ); Mon, 6 Apr 2009 15:21:54 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752270AbZDFTVq (ORCPT ); Mon, 6 Apr 2009 15:21:46 -0400 Received: from smtp-outbound-2.vmware.com ([65.115.85.73]:58782 "EHLO smtp-outbound-2.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752075AbZDFTVp (ORCPT ); Mon, 6 Apr 2009 15:21:45 -0400 Date: Mon, 6 Apr 2009 12:22:38 -0700 From: Randy Robertson To: linux-kernel@vger.kernel.org Cc: David Howells Subject: [PATCH] initramfs: Fix initramfs to work with hardlinked init Message-ID: <20090406192238.GA6621@vmware.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.18 (2008-05-17) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Change cb6ff208076b5f434db1b8c983429269d719cef5 seems to have broken booting from initramfs with /sbin/init being a hardlink. It seems like the logic required for XIP on nommu, i.e. ftruncate to reported cpio header file size (body_len) is broken for hardlinks, which have a reported size of 0, and the truncate thus nukes the contents of the file (in my case busybox), making boot impossible and ending with runaway loop modprobe binfmt-0000 - and of course 0000 is not a valid binary format. My fix is to only call ftruncate if size is non-zero which fixes things for me, but I'm not certain whether this will break XIP for those files on nommu systems, although I would guess not. This update adds David's ack and fixes whitespace. Signed-off-by: Randy Robertson Acked-by: David Howells --- init/initramfs.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/init/initramfs.c b/init/initramfs.c index 80cd713..ddf30d1 100644 --- a/init/initramfs.c +++ b/init/initramfs.c @@ -310,7 +310,8 @@ static int __init do_name(void) if (wfd >= 0) { sys_fchown(wfd, uid, gid); sys_fchmod(wfd, mode); - sys_ftruncate(wfd, body_len); + if (body_len) + sys_ftruncate(wfd, body_len); vcollected = kstrdup(collected, GFP_KERNEL); state = CopyFile; }