Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3BC94C433F5 for ; Fri, 12 Nov 2021 19:29:46 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B772161039 for ; Fri, 12 Nov 2021 19:29:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org B772161039 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 75FB18303F; Fri, 12 Nov 2021 20:29:22 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="WS5TPGcT"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DF62483023; Fri, 12 Nov 2021 20:28:59 +0100 (CET) Received: from mail-oi1-x22c.google.com (mail-oi1-x22c.google.com [IPv6:2607:f8b0:4864:20::22c]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id EACFB8302B for ; Fri, 12 Nov 2021 20:28:52 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-oi1-x22c.google.com with SMTP id r26so19770050oiw.5 for ; Fri, 12 Nov 2021 11:28:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QdtAIGbtjtG8j5k1ppokYR5vYwYwDyoEdB33xmkC/UA=; b=WS5TPGcTYj91lg8HtnlNRNOITaLjbsXRudLcxWQWK09UGy8rAFDXA5r0E01aJ2iFSQ e3Hx178ZM5tyGUWrblx+gaMyN4Tyuep92sqkH59ZGrjhk7GXnGdiC3EDTVCRcFjOaM2i rYLnkNENi1jVeg6tcwYnonSmgMcF+PqjxfXnI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QdtAIGbtjtG8j5k1ppokYR5vYwYwDyoEdB33xmkC/UA=; b=eAQR0dxmpBQl/8mBmNMEcJi+amXwafYuap016YLKAESb4Pt7DcZQ/GvAIy8d7UZADO az2xmwX5y9LzAHBPbQXSsoL2LwpjojNsfbSI1ihiDfEBqFsORXZC0dx3rZKNwC2tX267 H7mhcM24CmtiDhdnTk6nHLdvWtuPOIN+EZLQ/F8y6cqctwmh8/Rsg1qLG86R8iOVoqBw g352kufNnyBri6byD0TxvFr8cHv3mrghTJFEaFySWTnAQ565WKCxRejrGHbHOa8WECrh YzRHEypTYrBTqsj+BhV5Spjp6NwuGSxtx4cZyVXsVcOwjtXJ7REeDtmJZhFIvbtzKQx2 Mfng== X-Gm-Message-State: AOAM530h+hMOqO76ICJEU+Q2O06lRrKHgwwOSfvowRNifapYJvvhkRFd x/8PRcSCraqC2QGN5QoDRDAK/xIdp00PjA== X-Google-Smtp-Source: ABdhPJywsBXjrhYQl0pnHnUjMsQMsZzR+FXTAV+KSlwHpJCEoxVqftEfCULArzL4gHrYbKLGEF/z2Q== X-Received: by 2002:a05:6808:1294:: with SMTP id a20mr15561440oiw.138.1636745331421; Fri, 12 Nov 2021 11:28:51 -0800 (PST) Received: from kiwi.bld.corp.google.com (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id n20sm1283527ooe.7.2021.11.12.11.28.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Nov 2021 11:28:51 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Rob Herring , Tom Rini , Bill Mills , Simon Glass Subject: [PATCH 04/16] tools: Avoid leaving extra data at the end of copied files Date: Fri, 12 Nov 2021 12:28:05 -0700 Message-Id: <20211112192817.199075-5-sjg@chromium.org> X-Mailer: git-send-email 2.34.0.rc1.387.gb447b232ab-goog In-Reply-To: <20211112192817.199075-1-sjg@chromium.org> References: <20211112192817.199075-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.35 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean The copyfile() implementation has strange behaviour if the destination file already exists. Update it to ensure that any existing data in the destination file is dropped. Signed-off-by: Simon Glass --- tools/fit_common.c | 2 +- tools/fit_common.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/fit_common.c b/tools/fit_common.c index c161f23b0f7..d13e5ebf1ae 100644 --- a/tools/fit_common.c +++ b/tools/fit_common.c @@ -126,7 +126,7 @@ int copyfile(const char *src, const char *dst) goto out; } - fd_dst = open(dst, O_WRONLY | O_CREAT, 0666); + fd_dst = open(dst, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (fd_dst < 0) { printf("Can't open file %s (%s)\n", dst, strerror(errno)); goto out; diff --git a/tools/fit_common.h b/tools/fit_common.h index a76c4001c59..55f3f6acd4e 100644 --- a/tools/fit_common.h +++ b/tools/fit_common.h @@ -44,6 +44,8 @@ int mmap_fdt(const char *cmdname, const char *fname, size_t size_inc, * * This uses read()/write() to copy file @src to file @dst * + * If @dst exists, it is overwritten and truncated to the correct size. + * * @src: Filename to read from * @dst: Filename to write to * @return 0 if OK, -1 on error -- 2.34.0.rc1.387.gb447b232ab-goog