From patchwork Mon May 8 16:26:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 1778505 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4864:20::43e; helo=mail-wr1-x43e.google.com; envelope-from=swupdate+bncbcxploxj6ikrblwf4sramgqeh3gcxny@googlegroups.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20221208 header.b=dPMJ++QV; dkim-atps=neutral Received: from mail-wr1-x43e.google.com (mail-wr1-x43e.google.com [IPv6:2a00:1450:4864:20::43e]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QFRWB5KwWz214S for ; Tue, 9 May 2023 02:26:29 +1000 (AEST) Received: by mail-wr1-x43e.google.com with SMTP id ffacd0b85a97d-302cdf5d034sf2937850f8f.0 for ; Mon, 08 May 2023 09:26:28 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1683563183; cv=pass; d=google.com; s=arc-20160816; b=kWWjTrijQ1MPSnocV0bH+z/PI8OYaR2E+gWSwP5g1XXaV7jBR8PXHqrt1ayb124W0g ET8YeHry5OXsgpfrPK10KgDdSrZLi8ZpFo/wK+3RvqE4F7Nm6nYaXjiKt05wABVgY9O7 PwkFmqcH2ak6RwKMd47R0E2i+GKG1KoAZVl2rIbbtHZF2IjJe3xcPV6Qc7gQSGFP0Eg0 JRiqQf6rLBQmQrms/JvCpDgBMv9a0yG2P3XuwnCg/QBYvujY7/nKWEhzXbtAQQLQkHID jg9OV0yOJ2Npiy1voYipxXwZUy0H2rWihxaXJwYvIoS7iAadiazkG8y9+G0Ybc/UhZ4V QGqw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:mime-version:message-id:date :subject:cc:to:from:sender:dkim-signature; bh=Hq+h0KuMYC+m9L5YNOpFzce2N/vR8NibiQqX1EnWlWo=; b=KqhqsA1atPiVkQ4TXLris6jI+2tqcpC+bWAFvy4g6fJUFO+or/6i78rFCCiitLalFE dN3SJmQUtIlDaVuQ/z03NCogGc4M/2dyfjC1tcJftuYkf59Mz6/e+/qGER3JBfK2bGr2 EfW7Um5925+owYr91iTWezq//2lQGkfgvdIqGZ1TM2ysK2xgDUy/nro63w1O00nQaSl3 wUeKL1kZNhqJ587krE7Tiwy7UoBi2FT5kABMj83DXh7sBsQ5G7AecEwpya+C4qqu8xvw 1XiEwg+t1ijRLlg7s/6A889yyh84IPdkBj2fb8b86qSMORkQj3rZqqELE0IMqOfi5+or CY6A== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20221208; t=1683563183; x=1686155183; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:x-original-authentication-results :x-original-sender:mime-version:message-id:date:subject:cc:to:from :sender:from:to:cc:subject:date:message-id:reply-to; bh=Hq+h0KuMYC+m9L5YNOpFzce2N/vR8NibiQqX1EnWlWo=; b=dPMJ++QV7jXklIMQ8ojwuFfitb9H8PWh46Xj4DzNGGBPCRQiXUFEK8UsprUHpiCHoE vX0ABB02jIqwSY3z0u1FYOz24Un8J5CZIYmTpMuZgHE0qMLCE2KR2S5AfU0TnobBAn9j 7E4mYTeh726us3a3x+6yzl9K9nouE+cHK0Pape1G5iAh076FMvGxZOQvi/wx5vSQdhXW sikP502gJPE6YrS7iN47MMsYPn4lnNjivoJznKK2xlqLSVfL75ByMeFKYK5tRIMvzfYi H6M48AbN++r4Btva3A/dFST80l09AXSEzYPxzbaMhqnCObpQGxHjCDBhISdb4wWYBa9G HY2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683563183; x=1686155183; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence :x-original-authentication-results:x-original-sender:mime-version :message-id:date:subject:cc:to:from:x-beenthere:x-gm-message-state :sender:from:to:cc:subject:date:message-id:reply-to; bh=Hq+h0KuMYC+m9L5YNOpFzce2N/vR8NibiQqX1EnWlWo=; b=KQuArW+JdJZrsXuxZ64t7WC6m+Zy0PngzWiMMhVKjooLdckDggsrCeTDMn4FM7XSv6 ktsuMDcgDfOfEwPjesyJCpllz9tJGczK6277x8hBpyah105+A/RAj4E64wH1Dt41cWWb 0N/l0m3fSoxaV0Iu+tKyvsO3qD8dEM0CGgToatrqibRtKGTkz5U9zzwfirkEvj3lYNBg Iu8U39eUwVSvvbjqagJxggE5omX0Zz/KelH5toynFcHIlP7CUyxXaGBmLOffkqZVlw7L mq/pqKdlu5NOtheUVw/FBrP+MIBFzjxaQzQcsxWddjVpC5Tmi6cMk4MhbOMpvOSKe8wn I3Xg== Sender: swupdate@googlegroups.com X-Gm-Message-State: AC+VfDy7T6UhYGx+LZlsG2qxBJ6OkXNHfr0W2k+YSTXnwtvg8SinuHAc is+qnUXotj425/vDpAwf2O8= X-Google-Smtp-Source: ACHHUZ5kGqV0b+o/oNvtem5B64gftPsvMeHQyJY8s68GrsAgZntpyUWTuhgkb315vzMQp/aw6n7a6Q== X-Received: by 2002:a5d:6411:0:b0:306:2dea:3093 with SMTP id z17-20020a5d6411000000b003062dea3093mr1372749wru.9.1683563182638; Mon, 08 May 2023 09:26:22 -0700 (PDT) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a5d:64ea:0:b0:306:28af:9a26 with SMTP id g10-20020a5d64ea000000b0030628af9a26ls1551555wri.0.-pod-prod-gmail; Mon, 08 May 2023 09:26:21 -0700 (PDT) X-Received: by 2002:a5d:4a86:0:b0:306:2aea:3dff with SMTP id o6-20020a5d4a86000000b003062aea3dffmr7681035wrq.31.1683563181223; Mon, 08 May 2023 09:26:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683563181; cv=none; d=google.com; s=arc-20160816; b=Qv4pfla3Dx6LodUamjtFpIGPORTMZmZUu+96bGp5i6J7Dn4JspeAmpCIeJw01pS+Dx y5zVH2rVvG7Opbk/pj+irKaxNaFZ3qZAQTYNo5RndNukKm0/0vahpfSV4xEQbEyyK987 ypBTMUG1LV9bM+oHtl81SgukqV3cTq7FkQQQXcfhDEVvjuEiAbiIUXtXpioomc1t9PrE exvZApqY26QfSBHibJi1FbQCz7TbQSBU5rIQTgBD4DariVwOmiSvyx9ChEXcs70rrx7h h0AsbmiEAH3I2p0Fa1mHoQ9lBbu58j/P7xrWCMfPNCWy6mkVg7QWQHW0IY9l4t0s7Dy5 jRcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from; bh=WQY18bckZb0ScBUN/AfxIYs0p/r+UGyeIwolWzMoknU=; b=0krYg9M4JQEZrIhNCsuCIOz44Qc2Irer0HDFurr7R1VXe7IVRZuBjyzAMO4AX+g+kP +mgeazVLx9alUPgVkFukA83X8HhfuRr1QMmC8H75S+58mAaQCAnMRGhBI5APwWaC2NBa 1tVatGrglZzcwpltM2kMes52DiSND4LZcj1UzMSB9QktcPt5Z4no1KzwXqmZ/V8NCveP rHNDEvMVJhG8qGbQVZgIZhCKCP63bzuCE0tIhQ4znLM7mQ1zdQy+cmwWiEwieQ+333vl oCs3snZGiy6MJTkK8vpvT5Kz9VpuoKk/4TynpH2Q8s5Wwa0ZmRGLjlWrcpgA/mq4sUEP mdJA== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=denx.de Received: from mail-out.m-online.net (mail-out.m-online.net. [212.18.0.9]) by gmr-mx.google.com with ESMTPS id cc5-20020a5d5c05000000b002f419cfd872si521530wrb.3.2023.05.08.09.26.21 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 May 2023 09:26:21 -0700 (PDT) Received-SPF: neutral (google.com: 212.18.0.9 is neither permitted nor denied by domain of sbabic@denx.de) client-ip=212.18.0.9; Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 4QFRW069Tpz1r3Dw; Mon, 8 May 2023 18:26:20 +0200 (CEST) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 4QFRW05yMjz1qqlb; Mon, 8 May 2023 18:26:20 +0200 (CEST) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id 2-tkX3NpTp9g; Mon, 8 May 2023 18:26:19 +0200 (CEST) Received: from babic.homelinux.org (host-88-217-136-221.customer.m-online.net [88.217.136.221]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPS; Mon, 8 May 2023 18:26:19 +0200 (CEST) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id B68F34540A55; Mon, 8 May 2023 18:26:18 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at babic.homelinux.org Received: from babic.homelinux.org ([IPv6:::1]) by localhost (mail.babic.homelinux.org [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id a8oQkVg8aM3J; Mon, 8 May 2023 18:26:16 +0200 (CEST) Received: from paperino.fritz.box (paperino.fritz.box [192.168.178.48]) by babic.homelinux.org (Postfix) with ESMTP id EB4C245404AB; Mon, 8 May 2023 18:26:15 +0200 (CEST) From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH] copyhandler: allow zero sized files Date: Mon, 8 May 2023 18:26:12 +0200 Message-Id: <20230508162612.116091-1-sbabic@denx.de> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Original-Sender: sbabic@denx.de X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=denx.de Precedence: list Mailing-list: list swupdate@googlegroups.com; contact swupdate+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: swupdate@googlegroups.com X-Google-Group-Id: 605343134186 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , An empty file generates an error and SWUpdate stops the update. The reason is that the size is detected and 0 was not assumed as valid size, but it really is. Change logic and allows empty files to be copied. Signed-off-by: Stefano Babic --- handlers/copy_handler.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/handlers/copy_handler.c b/handlers/copy_handler.c index fa5f3c0..8ab4f01 100644 --- a/handlers/copy_handler.c +++ b/handlers/copy_handler.c @@ -73,26 +73,31 @@ static int copy_single_file(const char *path, ssize_t size, struct img_type *img /* * try to detect the size if was not set in sw-description */ + bool valid_size = true; if (!size) { - if (S_ISREG(statbuf.st_mode)) + if (S_ISREG(statbuf.st_mode)) { size = statbuf.st_size; + } else if (S_ISBLK(statbuf.st_mode) && (ioctl(fdin, BLKGETSIZE64, &size) < 0)) { ERROR("Cannot get size of Block Device %s", path); + valid_size = false; } else if (S_ISCHR(statbuf.st_mode)) { /* it is maybe a MTD device, just try */ ret = ioctl(fdin, MEMGETINFO, &mtdinfo); - if (!ret) + if (!ret) { size = mtdinfo.size; + } else { + valid_size = false; + } } } - if (!size) { + if (!valid_size) { ERROR("Size cannot be detected for %s", path); close(fdin); return -ENODEV; } - if (pipe(pipes) < 0) { ERROR("Could not create pipes for chained handler, existing..."); close(fdin);