From patchwork Fri Jul 20 02:57:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 142414 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2437715ljj; Thu, 19 Jul 2018 20:00:29 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfIZbtS4gusKgrJeN/qQAzihcl1OPuAUbI80JzIHJJUADRvdhDASL2VZmoPlxDm69w8gtRN X-Received: by 2002:a50:a166:: with SMTP id 93-v6mr505489edj.184.1532055629323; Thu, 19 Jul 2018 20:00:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532055629; cv=none; d=google.com; s=arc-20160816; b=iaVMRjzXM0mLy0AKDEVlGmkqEFLAQ9acLQQQ8KemCuGaYhjzEzFfAnw9DLfGggszSG s+qTr2c9e02zuh87eFjg4Q4MoXParO7B9UXQwW1TFjjHsfafNIO2JYxJv6NTCKKIfH8b vQDwKltQKJdmJ7OCLZAcMpfmPIO2jSdnBECW3ZZherfbT+nk1X2WqaXJMWoKY9Oc9gAT 8/Md1ZX2AVPlhBmcJXoDZdztxcJ8G4mCcbNprOqfrDOkd91R3wVdiNtAf+6RUpqv0I88 6gO4JV6fRIuKw4POpH3UXSaHjeZ+rwQN2w0lVBkt08i+nj25abak/g2q4h1l2AkXgRt3 IoJA== 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=1CbOol4MFyVpBNHxgVl6bLVe5OldMpH4Tu6KXJL2VZ0=; b=D1wEBk4iY9FvO1+rTFUEFSbB5E1KMvpqFe7R7q38O+bDSF4oSet+pWt9VMbwQxbHO0 63MxeKflDUMhziWx6NWtZTjyqs2VKfFbEHvWiHAbMrPH3KqM1A3FcKLD0Rw1ZogIK8Ak FTKU9n8TG3QtQKvIOUf3XtKa3R8RgeRm3Lv0iyxjGSTJR/j/FzVtBjN+xmlf0+GiruBx 14Of0zTKkix9X5MMSp72GtF6pbPUgsKo86bq1IV0r8JSs3GLIgmHfs38URLwG2xvuiu7 bLdlgy2pwlKazPkzk6OgynXXquDVmkls3nkY/U0AnS9ZEDhMQYZ+WC6cAqeinNDnB5OG 1qDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=ZOrsr3XY; 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 i57-v6si279267eda.238.2018.07.19.20.00.28; Thu, 19 Jul 2018 20:00:29 -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=ZOrsr3XY; 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 C6F22C21DB3; Fri, 20 Jul 2018 02:58:14 +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=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 D3A45C21DC1; Fri, 20 Jul 2018 02:58:09 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 6A703C21D9A; Fri, 20 Jul 2018 02:57:33 +0000 (UTC) Received: from mail-pl0-f43.google.com (mail-pl0-f43.google.com [209.85.160.43]) by lists.denx.de (Postfix) with ESMTPS id BDFB7C21DF8 for ; Fri, 20 Jul 2018 02:57:29 +0000 (UTC) Received: by mail-pl0-f43.google.com with SMTP id 6-v6so4515478plb.0 for ; Thu, 19 Jul 2018 19:57:29 -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=BPzUpR5wLH8HCOOwmOCTlkYJK0x+jfG+XHxAqPa3gt0=; b=ZOrsr3XYIOlee8/B0uvub9qmxY9oFM3hX+Gi64TDE0zyD4qYiN5c2KtgId222+7NXb Vr1AuAVF6ijvOR2KU19BRnH71fH31GuPrZ8cDkcntt+SPA8W53GpU3bhUHl9j/tR1JDs 61j/k/lKfLPY8uLFAgYAIxvMgO+04X8LEDhR4= 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=BPzUpR5wLH8HCOOwmOCTlkYJK0x+jfG+XHxAqPa3gt0=; b=IbF8HZZe8CgbahoE/BYge3Bh2OvUyQqtwEC+60Z70Y5HJ5Lxqg4bNT/LBSfnQSs8pL KvEO1oP8bd8lCCFuXfCCiDGpEpsq+2G7ZA/McApvUamjwnHSYWS341CBvuq5lFySBNHU tiiHUft9DINsyO50j2S7PDrJtJv6j3HLmjDYGbgIxnnnp5Q2Xvu+Brfzlzx+p5kPHH36 r0igazlVYxfRXnNc3RcqgFH18rX3VUr94rJ1387HUQdqyie821ZuX1qPgbJ5sbSz00N7 Ku6Ixp2+GtNwuf7QlWQoB8XvYhKnie00dYo9hW64NPmOI2reBBm3sFY6Vfws6CXXJ4Vb R5nA== X-Gm-Message-State: AOUpUlFCuWrHQbsAMtq8u/jVy0eyn2934kg9mZPm6Av+1iWJQlIOl8iv 01MT4+NeaS732+nF7NvL3q+4oQ== X-Received: by 2002:a17:902:7c8b:: with SMTP id y11-v6mr290591pll.222.1532055448429; Thu, 19 Jul 2018 19:57:28 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id p3-v6sm614085pfo.130.2018.07.19.19.57.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Jul 2018 19:57:27 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Fri, 20 Jul 2018 11:57:12 +0900 Message-Id: <20180720025723.6736-7-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180720025723.6736-1-takahiro.akashi@linaro.org> References: <20180720025723.6736-1-takahiro.akashi@linaro.org> Cc: u-boot@lists.denx.de, xypron.glpk@gmx.de, agraf@suse.de Subject: [U-Boot] [PATCH 06/17] 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 6c715a70f4..1e4f5af910 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);