From patchwork Tue Sep 11 06:59:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 146406 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3314950ljw; Tue, 11 Sep 2018 00:04:39 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdb23pWBBWvIgbU55DZbVphwL6Ut1p8XskWUKDv2OdiT5goXAxefZpcc0P+mbm+RKRtF7Jjm X-Received: by 2002:aa7:c384:: with SMTP id k4-v6mr27299212edq.270.1536649479869; Tue, 11 Sep 2018 00:04:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536649479; cv=none; d=google.com; s=arc-20160816; b=e1eViRq/pD0Q4sfyh3qRNQHblhioIwK8Ndkbat/LgKyWon7vKOffPf4DzPnHxIMDH6 dUmpLwkCY61uFnI7LZl/E/iN9EkbBZzF1oj15KqfkrU9T9QD1KpVynBCdL662p1QY7GU FkNJZKrmdex4TRyTtppFF7p9CdkGHILHD1zaqQ3Um5Qf0EdSodsfDjnZIfakNM7c5R1y fsa2rXK4gLKD6FatjU7rXr6pQXayX/+beKbQZ6lo+U7sJHR/oEQOKe4JEYRaltaSCmPX HYS8Z8X/8IVZYjqbSra8bN6E4bO5x3dB/CfDV4P5m4+ZwpeBjhUxveYcjXGABxhltBQK aBOg== 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; bh=5vrqTDP9RF/l8RySU8gJUG8s4nM24YQu3HMrtHG7hdo=; b=Fih6WvPV+uD2hmrMRq/HGMRwaDRYb9yaXTb1GMlhEF5QK3CkTjF10PJWWkDOCfPttD A+mj7CpemxLhC5yB1cz1vW4d5od1SEPJuQZupUCdGJHyRbzrvb737g2ww7rhHeG5J16D krx6S9OuagjooHs45K4+XeIolnZyTKYQ0IQP10rz9prOUgZULgj243f8zx68rs6RrsIK 8Q08Bm4Q/WyxYsQAyx8R/jRHF8gk+Dt29wFKDWfAI0ybY5mUQTvOAbZyjjFfaPGfp/z1 kTdLK0/3VTmcQtiCphSdAWKEADab6p4GUa5DLoCtXGPzeL8AX1O6bJ1oHRGpbfSjjW1Z /DGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=R3sisVBf; 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 z6-v6si1105492edk.357.2018.09.11.00.04.39; Tue, 11 Sep 2018 00:04:39 -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=R3sisVBf; 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 64689C21E88; Tue, 11 Sep 2018 07:01:43 +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 3FE71C21EC2; Tue, 11 Sep 2018 06:59:48 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 19ABCC21E1A; Tue, 11 Sep 2018 06:59:34 +0000 (UTC) Received: from mail-pl1-f195.google.com (mail-pl1-f195.google.com [209.85.214.195]) by lists.denx.de (Postfix) with ESMTPS id E4C53C21E62 for ; Tue, 11 Sep 2018 06:59:29 +0000 (UTC) Received: by mail-pl1-f195.google.com with SMTP id b30-v6so8605542pla.0 for ; Mon, 10 Sep 2018 23:59: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=VF1OF+imD0YkNl5yzbdJ/3kiHzp3tab8EUp2uCwBcdo=; b=R3sisVBf+zRoaFSjccEjf0kaORqXEVLcrrwRwOr0LtMzsGVsf7ADe5b7rBQ5yPlwVA PzEyHoli7ljaI4YhWpAZtzyyQOm5BikUwdhrLKxyqzpLy7tYDXOVjBnmbOuVnouTdBhd wODK11k6iffSztntX9EHhAA7KBIHRoEBsWYWE= 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=VF1OF+imD0YkNl5yzbdJ/3kiHzp3tab8EUp2uCwBcdo=; b=tTEeiu0iUHKeXPqR4+8j3WULmmY2QwMHFPPYP3aCB+/CNQwzuFpfPw1fU4ZRGbFgdx /W84rgjT1HjnsZDK8vUsrltHakYVu/OqgSR6cEsyEXV4kgx0g6c3E/3kC2PFTVOFxXwQ HxwjdSUvpoHdrNBptn431vjugoU60lW07bAiNorkapk/3OdmlW4VX4jI7rqj18tKdekF HbtRzb2ADCj4ASjxYWRuGTCz81NOxAhyjP6v8UeWSnxahZ8/GQhEjLoJg+FEcO/t4aiU kgEJd4Yv2PIuOhqAseLoIFzMGXqVZb2fw9oIKgsSfDBZwtt2lldh5xwKoyEInDUcQZaO BAdA== X-Gm-Message-State: APzg51BYbAg1WQROaY2Mv5OREMrTCHaCJn0jJ2XCjNBlbAwZRyFZvlem nmwTxtbPqhQYUhkHEG7m7Cwulg== X-Received: by 2002:a17:902:6907:: with SMTP id j7-v6mr25680645plk.323.1536649168514; Mon, 10 Sep 2018 23:59:28 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id s27-v6sm37145285pfk.133.2018.09.10.23.59.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Sep 2018 23:59:27 -0700 (PDT) From: "Akashi, Takahiro" To: trini@konsulko.com Date: Tue, 11 Sep 2018 15:59:03 +0900 Message-Id: <20180911065922.19141-8-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180911065922.19141-1-takahiro.akashi@linaro.org> References: <20180911065922.19141-1-takahiro.akashi@linaro.org> Cc: u-boot@lists.denx.de, xypron.glpk@gmx.de, agraf@suse.de Subject: [U-Boot] [PATCH v3 07/26] 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" From: AKASHI Takahiro 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);