From patchwork Sun Feb 17 23:10:27 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yann E. MORIN" X-Patchwork-Id: 221114 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from silver.osuosl.org (silver.osuosl.org [140.211.166.136]) by ozlabs.org (Postfix) with ESMTP id 1F6BF2C007A for ; Mon, 18 Feb 2013 10:10:55 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id E36FE300D8; Sun, 17 Feb 2013 23:10:53 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id tNJJh-jc0xcQ; Sun, 17 Feb 2013 23:10:48 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by silver.osuosl.org (Postfix) with ESMTP id D886C2FE9B; Sun, 17 Feb 2013 23:10:47 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from whitealder.osuosl.org (whitealder.osuosl.org [140.211.166.138]) by ash.osuosl.org (Postfix) with ESMTP id 8B1CA8F753 for ; Sun, 17 Feb 2013 23:10:49 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 5B93F87C3F for ; Sun, 17 Feb 2013 23:10:42 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id zsQAE7cBv3mc for ; Sun, 17 Feb 2013 23:10:39 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-wi0-f182.google.com (mail-wi0-f182.google.com [209.85.212.182]) by whitealder.osuosl.org (Postfix) with ESMTPS id 417408BE92 for ; Sun, 17 Feb 2013 23:10:39 +0000 (UTC) Received: by mail-wi0-f182.google.com with SMTP id hi18so2884268wib.15 for ; Sun, 17 Feb 2013 15:10:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:in-reply-to:references; bh=F7RiTL9S8ZbgSDTJMtpqAqnK3fponsFbEZjEEPit8nw=; b=fQahgo5kipCq4bChfU8tXkp75SL/buPkVHNAJhW4WrSqKkhvaXSm3MgqivpfkO3hF6 wluP6Hwqu3ZOcXVQ8byHSJUgSrv2tu5TXQ76wViq94aENMIfPs+ZOFGuvWfVAdgK6FRL Cfp857j4HeWRt23lK7hnEE7lTF/xPXl1NcZ/xEGKbCGKFyhCBdoDHa6AEzwf/NAhZOAh B4wrqnqQn8XHPxdg8LUzr2dKz4QyKxsSd9BB4xU5noy35XYaOD/z2iC2oaKiDq5ECed5 PQvucL17Si5CXu0/GYNS4hPCLQ7zLoaMwpkKbfJcYjWUibkaHjHmhoPdokR8jFCXIix1 Ey4w== X-Received: by 10.181.12.103 with SMTP id ep7mr16811168wid.12.1361142637261; Sun, 17 Feb 2013 15:10:37 -0800 (PST) Received: from localhost.localdomain (ARennes-256-1-67-109.w90-32.abo.wanadoo.fr. [90.32.146.109]) by mx.google.com with ESMTPS id cf8sm6061269wib.1.2013.02.17.15.10.35 (version=TLSv1 cipher=RC4-SHA bits=128/128); Sun, 17 Feb 2013 15:10:36 -0800 (PST) From: "Yann E. MORIN" To: buildroot@busybox.net Date: Mon, 18 Feb 2013 00:10:27 +0100 Message-Id: <1a995bdbc65141cf4e8a540c41cb56f4a43fba5f.1361142401.git.yann.morin.1998@free.fr> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: References: In-Reply-To: References: Cc: "Yann E. MORIN" Subject: [Buildroot] [PATCH 2/4] fs/ext2: add ability to build ext3/4 too X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.14 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: buildroot-bounces@busybox.net Sender: buildroot-bounces@busybox.net Signed-off-by: "Yann E. MORIN" --- fs/ext2/Config.in | 37 ++++++++++++++++++++++++++++++------- fs/ext2/ext2.mk | 4 ++-- fs/ext2/genext2fs.sh | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 78 insertions(+), 11 deletions(-) diff --git a/fs/ext2/Config.in b/fs/ext2/Config.in index cb4beed..00f11a2 100644 --- a/fs/ext2/Config.in +++ b/fs/ext2/Config.in @@ -1,10 +1,33 @@ config BR2_TARGET_ROOTFS_EXT2 - bool "ext2 root filesystem" + bool "ext2/3/4 root filesystem" help - Build an ext2 root filesystem + Build an ext2/3/4 root filesystem if BR2_TARGET_ROOTFS_EXT2 +choice + bool "ext generation" + default BR2_TARGET_ROOTFS_EXT2_2 + +config BR2_TARGET_ROOTFS_EXT2_2 + bool "ext2" + +config BR2_TARGET_ROOTFS_EXT2_3 + bool "ext3" + select BR2_PACKAGE_HOST_E2FSPROGS + +config BR2_TARGET_ROOTFS_EXT2_4 + bool "ext4" + select BR2_PACKAGE_HOST_E2FSPROGS + +endchoice + +config BR2_TARGET_ROOTFS_EXT2_GEN + int + default 2 if BR2_TARGET_ROOTFS_EXT2_2 + default 3 if BR2_TARGET_ROOTFS_EXT2_3 + default 4 if BR2_TARGET_ROOTFS_EXT2_4 + config BR2_TARGET_ROOTFS_EXT2_BLOCKS int "size in blocks (leave at 0 for auto calculation)" default 0 @@ -21,27 +44,27 @@ choice prompt "Compression method" default BR2_TARGET_ROOTFS_EXT2_NONE help - Select compressor for ext2 filesystem of the root filesystem + Select compressor for ext2/3/4 filesystem of the root filesystem config BR2_TARGET_ROOTFS_EXT2_NONE bool "no compression" help - Do not compress the ext2 filesystem. + Do not compress the ext2/3/4 filesystem. config BR2_TARGET_ROOTFS_EXT2_GZIP bool "gzip" help - Do compress the ext2 filesystem with gzip. + Do compress the ext2/3/4 filesystem with gzip. config BR2_TARGET_ROOTFS_EXT2_BZIP2 bool "bzip2" help - Do compress the ext2 filesystem with bzip2. + Do compress the ext2/3/4 filesystem with bzip2. config BR2_TARGET_ROOTFS_EXT2_LZMA bool "lzma" help - Do compress the ext2 filesystem with lzma. + Do compress the ext2/3/4 filesystem with lzma. endchoice diff --git a/fs/ext2/ext2.mk b/fs/ext2/ext2.mk index 7b71592..80ad93f 100644 --- a/fs/ext2/ext2.mk +++ b/fs/ext2/ext2.mk @@ -18,10 +18,10 @@ ifneq ($(strip $(BR2_TARGET_ROOTFS_EXT2_RESBLKS)),0) EXT2_OPTS += -m $(BR2_TARGET_ROOTFS_EXT2_RESBLKS) endif -ROOTFS_EXT2_DEPENDENCIES = host-genext2fs +ROOTFS_EXT2_DEPENDENCIES = host-genext2fs $(if $(BR2_PACKAGE_HOST_E2FSPROGS),host-e2fsprogs) define ROOTFS_EXT2_CMD - PATH=$(TARGET_PATH) fs/ext2/genext2fs.sh -d $(TARGET_DIR) $(EXT2_OPTS) $@ + PATH=$(TARGET_PATH) fs/ext2/genext2fs.sh -d $(TARGET_DIR) $(EXT2_OPTS) -$(BR2_TARGET_ROOTFS_EXT2_GEN) $@ endef $(eval $(call ROOTFS_TARGET,ext2)) diff --git a/fs/ext2/genext2fs.sh b/fs/ext2/genext2fs.sh index 7a518ae..fcbd43c 100755 --- a/fs/ext2/genext2fs.sh +++ b/fs/ext2/genext2fs.sh @@ -1,19 +1,22 @@ #!/bin/sh # genext2fs wrapper calculating needed blocks/inodes values if not specified +set -e export LC_ALL=C CALC_BLOCKS=1 CALC_INODES=1 -while getopts x:d:D:b:i:N:m:g:e:zfqUPhVv f +while getopts x:d:D:b:i:N:m:g:e:zfqUPhVv234 f do case $f in + 2|3|4) GEN=$f ;; b) CALC_BLOCKS=0 ;; N) CALC_INODES=0; INODES=$OPTARG ;; d) TARGET_DIR=$OPTARG ;; esac done +eval IMG="\"\${${OPTIND}}\"" # calculate needed inodes if [ $CALC_INODES -eq 1 ]; @@ -30,7 +33,48 @@ then # we scale inodes / blocks with 10% to compensate for bitmaps size + slack BLOCKS=$(du -s -c -k $TARGET_DIR | grep total | sed -e "s/total//") BLOCKS=$(expr 500 + \( $BLOCKS + $INODES / 8 \) \* 11 / 10) + # we add 1081 blocks (a bit more than 1 MiB, assuming 1KiB blocks) for + # the journal if ext3/4 + if [ ${GEN} -ge 3 ]; then + BLOCKS=$(expr 1081 + $BLOCKS ) + fi set -- $@ -b $BLOCKS fi -exec genext2fs $@ +# Remove -{2,3,4} from the arguments, they are not recognised +# by genext2fs and we handle them manually later +first=1 +for o; do + case "${o}" in + -2|-3|-4) ;; + *) if [ ${first} -eq 1 ]; then + set -- + first=0 + fi + set -- "$@" "${o}" + ;; + esac +done + +# Generate the base ext2 file system +genext2fs "$@" + +# Upgrade to ext3 if needed +if [ ${GEN} -ge 3 ]; then + tune2fs -j -J size=1 "${IMG}" >/dev/null +fi + +# Upgrade to ext4 if needed +if [ ${GEN} -ge 4 ]; then + tune2fs -O extents,uninit_bg,dir_index "${IMG}" >/dev/null + ret=0 + fsck.ext4 -pDf "${IMG}" >/dev/null || ret=$? + # Exit codes 1 & 2 are OK, it means fs errors + # were successfully corrected + case ${ret} in + 0|1|2) ;; + *) exit 1;; + esac + # fsck.ext4 will force a UUID, which we do not want + tune2fs -U clear "${IMG}" >/dev/null +fi