From patchwork Tue Sep 4 07:49:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 145858 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3367020ljw; Tue, 4 Sep 2018 00:56:21 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYz05vol232MpdbKG8XSH3u6ab6Js4G4Tg0zC1EvZbyAnosNOqRAdM6Lt7pRbaG1H9Hnl23 X-Received: by 2002:a50:8978:: with SMTP id f53-v6mr34937171edf.166.1536047781411; Tue, 04 Sep 2018 00:56:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536047781; cv=none; d=google.com; s=arc-20160816; b=Eho9lT3CtQCcLag2r0RGKH8bdSmQALGX/Un2ai33zqKqsskCkOoGpm3Mzshr4PPolq 1WrAKW4DqTkR4P1vqitbSVAnj20hFoFCHaRDTeG6kM9qZMsYRi8bpFIQcudVoi5yuyuA 6h1zBCeHmDtWyzprk0clF8lLOI5migwrjPIUZ0/KduFBx1OzKyFuQwi5ttdhVnTc8TQq aE1ALL8ZD9OWZfwapMverTIcVWr7LnRkaQ1QEc+24hjiS6P+eRfHpUg5mbZu5SEGVHOM J8jwYV8ZUYw2uA2qj/GSIf/28TSQCl7fK4zcgXxvSN0JOhQwetWG2jFRfO25eyzG103e SJoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature:arc-authentication-results; bh=6jNPSIQQTiCZl4IUpS0iCF7DQqtgnM/PvSMEvzVYqfY=; b=Bqz0xVEnVisrWuK2vRtfyq8O4qOadzUy7mwpa7BLegmVm+PeXYGf/mEe8BRTQUiqfV iQ9hhUb2bgf6Ca2CJdmkDtJY8vCzjHQJZEfnorXn4HTb1c/6s/CfS+/iAzckf0hN6ea9 9jiYiHgBItCdUwkSbohO5ZViBrh7PEXhBSoREQo6cU9aoyTPtBmd6D33xYwF44akVaVc zTeIJel12wVwqAY8MkuxDVCg41yvRgcWkjv9CXjd4kkArXT4FEl+CIh16VI3QzzMqxVP KKllD4GhIMInjQL5WTywVrhiCJQ6Z3qzn1uwpNnTeKPePX/I5vQsdxucetkAvFmr8r3k 6Ykg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=bF3zRYbN; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id a58-v6si6888983edd.224.2018.09.04.00.56.21; Tue, 04 Sep 2018 00:56:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=bF3zRYbN; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.denx.de (Postfix, from userid 105) id 0F48CC21F3C; Tue, 4 Sep 2018 07:53:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 41E50C21F1B; Tue, 4 Sep 2018 07:52:38 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 0DD35C21F3C; Tue, 4 Sep 2018 07:51:23 +0000 (UTC) Received: from mail-pg1-f195.google.com (mail-pg1-f195.google.com [209.85.215.195]) by lists.denx.de (Postfix) with ESMTPS id D9359C21EBB for ; Tue, 4 Sep 2018 07:51:18 +0000 (UTC) Received: by mail-pg1-f195.google.com with SMTP id d1-v6so1261733pgo.3 for ; Tue, 04 Sep 2018 00:51:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=X7ZI/U94WrKfUolj3xO8yEJWPxPTuHmEgeLQAGDyIrQ=; b=bF3zRYbNyGVQDVQnM1onJhO9gjRaYYErLjgGkiAHPG8C8sw6/N9P5iJxl+a8+TmTT/ 23k5PbQWxWYGk+tjTdGK6ZcEy7DsJwtriCEV4l1sR8J7AbEUHzLloJDpEZC8Buj6x42W Rp2th4/LKfgY0fqg0/0jRWmc04UaSFUPVBaFI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=X7ZI/U94WrKfUolj3xO8yEJWPxPTuHmEgeLQAGDyIrQ=; b=UTT0oHvHIIcDM72l2E907ZaZQHvgDyFZQHMixAikd5lp3c5A/4TF7lv3hzLsDhfWuD glxlcS9nLD0NZCWaQHQqOl5vGwtr6nVGTfEhSqNC9n5a8q7CE1S9kkDH23MlTTYTll4B qqRXyfXGPsh37xUhHR4RUGGXV+flqQXW8TVCqiyOT7CzzSl1P7EJ4AUtcTnAUM5N0eCs YcCVaILzU9qt3qbEMR0lF93CleZavraOFPPsipyk+yUAvlrEx+AIiWFuvETuSRt7IUR9 WScajj1malSKeynd8F9nuqNp/PqG48J3zZ7Zhm8LFQFECIoHJXehY0OY0p55HpP7Axn5 2bsQ== X-Gm-Message-State: APzg51D2QVpipjYXY0ersAY/N5H+h62kOseD6mOWqW7MtcAfezofyPfD wNvkhZOucj17/Fn+iToMTeB89g== X-Received: by 2002:a65:608b:: with SMTP id t11-v6mr15589930pgu.259.1536047477502; Tue, 04 Sep 2018 00:51:17 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id l10-v6sm31807841pfj.179.2018.09.04.00.51.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Sep 2018 00:51:16 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Tue, 4 Sep 2018 16:49:33 +0900 Message-Id: <20180904074948.18146-9-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180904074948.18146-1-takahiro.akashi@linaro.org> References: <20180904074948.18146-1-takahiro.akashi@linaro.org> Cc: xypron.glpk@gmx.de, agraf@suse.de, u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 08/23] fs: fat: write returns error code instead of -1 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" It would be good that FAT write function return error code instead of just returning -1 as fat_read_file() does. This patch attempts to address this issue although it is 'best effort (or estimate)' for now. Signed-off-by: AKASHI Takahiro --- fs/fat/fat_write.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c index 6c715a70f447..1e4f5af9106d 100644 --- a/fs/fat/fat_write.c +++ b/fs/fat/fat_write.c @@ -956,7 +956,7 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, if (read_bootsectandvi(&bs, &volinfo, &mydata->fatsize)) { debug("error: reading boot sector\n"); - return -1; + return -EIO; } total_sector = bs.total_sect; @@ -997,7 +997,7 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, mydata->fatbuf = memalign(ARCH_DMA_MINALIGN, FATBUFSIZE); if (mydata->fatbuf == NULL) { debug("Error: allocating memory\n"); - return -1; + return -ENOMEM; } if (disk_read(cursect, @@ -1005,6 +1005,7 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, (mydata->clust_size) : PREFETCH_BLOCKS, do_fat_read_at_block) < 0) { debug("Error: reading rootdir block\n"); + ret = -EIO; goto exit; } dentptr = (dir_entry *) do_fat_read_at_block; @@ -1029,6 +1030,7 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, size); if (ret) { printf("Error: %llu overflow\n", size); + ret = -ENOSPC; goto exit; } } @@ -1036,6 +1038,7 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, ret = clear_fatent(mydata, start_cluster); if (ret) { printf("Error: clearing FAT entries\n"); + ret = -EIO; goto exit; } @@ -1045,12 +1048,14 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, ret = start_cluster = find_empty_cluster(mydata); if (ret < 0) { printf("Error: finding empty cluster\n"); + ret = -ENOSPC; goto exit; } ret = check_overflow(mydata, start_cluster, size); if (ret) { printf("Error: %llu overflow\n", size); + ret = -ENOSPC; goto exit; } @@ -1065,12 +1070,14 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, ret = start_cluster = find_empty_cluster(mydata); if (ret < 0) { printf("Error: finding empty cluster\n"); + ret = -ENOSPC; goto exit; } ret = check_overflow(mydata, start_cluster, size); if (ret) { printf("Error: %llu overflow\n", size); + ret = -ENOSPC; goto exit; } } else { @@ -1087,6 +1094,7 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, ret = set_contents(mydata, retdent, buffer, size, actwrite); if (ret < 0) { printf("Error: writing contents\n"); + ret = -EIO; goto exit; } debug("attempt to write 0x%llx bytes\n", *actwrite); @@ -1095,14 +1103,17 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, ret = flush_dirty_fat_buffer(mydata); if (ret) { printf("Error: flush fat buffer\n"); + ret = -EIO; goto exit; } /* Write directory table to device */ ret = set_cluster(mydata, dir_curclust, get_dentfromdir_block, mydata->clust_size * mydata->sect_size); - if (ret) + if (ret) { printf("Error: writing directory entry\n"); + ret = -EIO; + } exit: free(mydata->fatbuf); @@ -1114,7 +1125,7 @@ int file_fat_write(const char *filename, void *buffer, loff_t offset, { if (offset != 0) { printf("Error: non zero offset is currently not supported.\n"); - return -1; + return -EINVAL; } printf("writing %s\n", filename);