From patchwork Tue Sep 11 06:58:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 146399 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3310414ljw; Mon, 10 Sep 2018 23:59:43 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZyX6K8lBcrTeUqaIJLGAQp5BUBxHbY2loscpVeR7/bJpmkGsRbQGseXOtg4a6zxi9neR3b X-Received: by 2002:a50:a38a:: with SMTP id s10-v6mr25474918edb.99.1536649183071; Mon, 10 Sep 2018 23:59:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536649183; cv=none; d=google.com; s=arc-20160816; b=NN5/b5qUbQW3nwUtNatP+RpRFwuYBcV+Ih/GoEhgqo2WOieRjDxoa0c09sgDxkc/3j 8ioJ6fuDmlrjzu1wrNlMElBd6BZIdmHFk2jfEc6bo74zzp2f34Gf4U7xAYmz/PbxS5jc adiDzc84kJgxtk2yvJlJETlcWDIabNDx5COz1XNAolE+cUyvsdjZQILj3UaU0vV9TQI4 LUxZBsM14Qk5z6Huw9DeUc3J5xQ3F89tV8Y32o2J3p22JoXysjHLdqt3StmfX4iQm/e9 g2LWF1ZR2LdBehCgwoxludDjyAJuHApVDoT7cVuE7nxbN2ZeceD7lXzH3sRFekvKpKbh xCvA== 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=QvKs9DC48WSYoL5Dj2fJYskPfiaH358LuHW8P79mJF8=; b=P6QNb/CoNK5zGqarv0D+Dz8oOr16Wy3f3eW79O+H5xn1xmwh0i+tkbmF9GkkoHGUR0 l8l9jiXv25sHz+WVsgUEefQ9B6H3GN8YmPXeEO50ex8RdkauY1mYpcu2xS1dlePCO902 IYQ02wlEM/yZMoscD4qOSQAEbYXqpTIx7qlPy2H4ji68LzKeL6RNtUe2qQpvugdCv/pa 5GzF/SdvZ6iWdAmFUjb7x6h0Qq92irxFl0K4QQt832L0ap4CtcEN+uR5y3Vt+UhtMkI6 fKPgt07xXpuiawADLAXKfQ57NmhRdEpDVXi5laX88evuokYGXgQWsEHCZDoKpa4K1RVu GWbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b="PHnW6/8Y"; 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 o33-v6si3805565eda.43.2018.09.10.23.59.42; Mon, 10 Sep 2018 23:59:43 -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="PHnW6/8Y"; 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 9A9BFC21EBE; Tue, 11 Sep 2018 06:59:33 +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 352CBC21EC9; Tue, 11 Sep 2018 06:59:18 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 5B003C21EFD; Tue, 11 Sep 2018 06:59:10 +0000 (UTC) Received: from mail-pg1-f193.google.com (mail-pg1-f193.google.com [209.85.215.193]) by lists.denx.de (Postfix) with ESMTPS id 671E3C21E4E for ; Tue, 11 Sep 2018 06:59:05 +0000 (UTC) Received: by mail-pg1-f193.google.com with SMTP id t84-v6so9904052pgb.5 for ; Mon, 10 Sep 2018 23:59:05 -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=wv9JVKXeoEx9dUaoFqDtcAk8/G9k+/c2CohtUU6Bgxw=; b=PHnW6/8YU6+a+KhRKj1u1fJkijArwAHCFdbkKbPey+sQ2/bjORRMTfMyuNZNYh1qGG 3xqZZAcBIbO/NsFyFLMJOvfrkenQuUO5qVwTJaEfRO+yMe1wFl3Lw0wjKvq3cORA9OHt 2E5d2/QE5pkKvzq7p7QjTuHdPPfjKmoQeDH+8= 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=wv9JVKXeoEx9dUaoFqDtcAk8/G9k+/c2CohtUU6Bgxw=; b=Jz0aLs+BZMGlFbCZJDoCaaxOlpLaUFdODGEy/jNKjN1tj8B86Zhfpuov7E9btm12sk 4Fa8f2lOG/T7ZZzw3T0YZesQ6W6fqaVfniMcCw/1EeDACj5tq4+2UrFtIW74xUdz5up9 qEwl8lGNuKL6X9KRk/nol6JEiNmuh4H4a30HJ7j5oNjpedLQZW9Ff4Sx9DAj0gQxZp4b DmBKKrvq4myeR6A6IS+QWpxBRWHGQEMd7MO0il1fkyq43vsgXhQOhZjUk4hYrYGFdO8S UxfOKw2nFWCahwP+xxS5CaGAg+BgJECjKTMuGjBKdoVWjwES7M4kx/q/pHZGToI7WhCp wMWA== X-Gm-Message-State: APzg51BW72wdDdru+sRuzwXZNZaL1kqKI4D8oxiVsoBFwzq/Rqm3Y8sc Vh/zbiZaAtz36OTNQDu6JXwtQg== X-Received: by 2002:a63:7d48:: with SMTP id m8-v6mr27077926pgn.0.1536649144052; Mon, 10 Sep 2018 23:59:04 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id y124-v6sm25166009pfg.63.2018.09.10.23.59.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Sep 2018 23:59:03 -0700 (PDT) From: "Akashi, Takahiro" To: trini@konsulko.com Date: Tue, 11 Sep 2018 15:58:57 +0900 Message-Id: <20180911065922.19141-2-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 01/26] fs: fat: guard the content of include/fat.h 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 The whole content of include/fat.h is private to FAT implementation and then should be guarded with CONFIG_FS_FAT. Signed-off-by: AKASHI Takahiro --- include/fat.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/fat.h b/include/fat.h index 09e142368585..c02839dcb040 100644 --- a/include/fat.h +++ b/include/fat.h @@ -9,6 +9,8 @@ #ifndef _FAT_H_ #define _FAT_H_ +#ifdef CONFIG_FS_FAT + #include #include @@ -202,4 +204,5 @@ int fat_opendir(const char *filename, struct fs_dir_stream **dirsp); int fat_readdir(struct fs_dir_stream *dirs, struct fs_dirent **dentp); void fat_closedir(struct fs_dir_stream *dirs); void fat_close(void); +#endif /* CONFIG_FS_FAT */ #endif /* _FAT_H_ */ From patchwork Tue Sep 11 06:58:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 146401 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3312074ljw; Tue, 11 Sep 2018 00:01:32 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaHK5lZcxbK06BCHHrSvs2ynsTNOcPxmxn8t5gXbAoTTNrtttANlnCUZ6i+WkMax85hoBuh X-Received: by 2002:a50:8c45:: with SMTP id p63-v6mr27582974edp.84.1536649292689; Tue, 11 Sep 2018 00:01:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536649292; cv=none; d=google.com; s=arc-20160816; b=naLqbKfo3nbHT8hVFMtIMhoUl+bDibWKR0Y10MKc2DhhNeXuz92coK5tQNVgSdNNoE tFC15b1YroOAC2VTsusmDxLhpAFBkEk/JWZnvHLBY5mtihqw+09lLzokUnInhybslzZ4 d4a6ghI1fp9c9d3hXe5kWT+cc99Rr8/zUWUGrYIjy/Iu9t30f4j77zESebsK7ODb+Z5l qlNICtt4dNu0g/PwarIy1eS96MZVNWb8TFBw98kJ0BIK9jUfCkAD4MIFapDr4XASEDe3 8INidNNOHHScl/AGvWYYuPoADmL+9LBDYcR6iB9zaO6ikbpvoxFH+TvxNrFAphflskGI xY1w== 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=tzB2IUfkFv0dI2X8ODgcB5F+fxFpj4Kr00n3DZhDEAc=; b=pdZBLDr5xmZBkmjWLLr0eED6AAdlS+ChDnMCCDZqcC2bVNXhiL78ODUi81oMa6jwSs tbPEjqeBW+yQ/xfyE9WlOVCWXqSgPeHgXVzt5UsUtOEHx1FmdU1fxxU0lnGJ/535q3mJ J2BS2Ed1ZXFen0EoZL6IP0+njTwbJroqUdncFd3lxcSj5NjLlYRdYD2nhIGqIy25Qpm3 uE9fWfwunqNQQzmngY5ei0sws/qgcPyIcpro+tkUME6vhnHl25XygVnQFafWbSuu4VwC dHklctsP+pzqNbLW4SaL07fxgkUnyLRspLFVtGEw3P747JWW/1iDLmk5pJK3lrHdgsl8 78GA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Bbawzelu; 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 b23si1533297edx.434.2018.09.11.00.01.32; Tue, 11 Sep 2018 00:01:32 -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=Bbawzelu; 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 C8A7DC21E62; Tue, 11 Sep 2018 06:59:58 +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 D36EEC21E7D; Tue, 11 Sep 2018 06:59:22 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 47183C21ED6; Tue, 11 Sep 2018 06:59:19 +0000 (UTC) Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) by lists.denx.de (Postfix) with ESMTPS id 4CF1BC21E79 for ; Tue, 11 Sep 2018 06:59:10 +0000 (UTC) Received: by mail-pg1-f176.google.com with SMTP id i190-v6so11753982pgc.6 for ; Mon, 10 Sep 2018 23:59:10 -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=z4gXz1vdK4z2DA9GIQPVd2IabDXK127OgHrbIcURAZw=; b=BbawzeluXs7PLUFIXQAZZhbPdrIiZjPa5Lp2lIkLj9CT/hejq5WIM1aXLnfZyoXSGg Ta/ihfbLoWsg8674Sp5dVK6kp+TtfwoMrZJscyIDYGrfWhd8TgVm2SQxXHj/2l3z9iL2 vnvD/gv7JbIrgLs7K0BGy+89A5Rcir3FVTZmw= 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=z4gXz1vdK4z2DA9GIQPVd2IabDXK127OgHrbIcURAZw=; b=Gnjk51OfktvsLHdnyb2S56ugCwQdXaGwiplhDRFnv8I2qQTdNR0juDHfFmEFmePxrG eCF6KRbb8vOuVNxpGhb1F/Am27hDsxnPBtcMSDcc4HfR7F55I8mYYe9kw8pKlvytzRk8 Co4WBiZlCFq3wku4tuza+bMfBB/i7EFAZlZdnt7x0jcJ3/2b4lvty1fuNGCSvZHeaXop RtZ/AMTU7wfioAg8DOvOB1kbgZe/wEObRQm9sgXLHeohLa/nK/nrgzKOvNIvc7cfOnn5 +wjYZgVOhQev1ya1pTB+uHcVYrPHaw9fYfCQ5aqLvqD8h/bQQfmnUmBWpkFTb83dY30k zkTw== X-Gm-Message-State: APzg51AtNqQpkjzzdCihCQEeKzDqH6dZakTZ+gInb3ItJyB9WH3ICHe1 1yrcggBjKRiCBPWO4lZtyPWBRQ== X-Received: by 2002:a63:141c:: with SMTP id u28-v6mr26707831pgl.247.1536649148927; Mon, 10 Sep 2018 23:59:08 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id o34-v6sm22697430pgm.44.2018.09.10.23.59.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Sep 2018 23:59:08 -0700 (PDT) From: "Akashi, Takahiro" To: trini@konsulko.com Date: Tue, 11 Sep 2018 15:58:58 +0900 Message-Id: <20180911065922.19141-3-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 02/26] fs: fat: extend get_fs_info() for write use 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 get_fs_info() was introduced in major re-work of read operation by Rob. We want to reuse this function in write operation by extending it with additional members in fsdata structure. Signed-off-by: AKASHI Takahiro --- fs/fat/fat.c | 7 +++++++ include/fat.h | 2 ++ 2 files changed, 9 insertions(+) diff --git a/fs/fat/fat.c b/fs/fat/fat.c index 4efe8a3edaf1..0576658dde09 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -558,10 +558,17 @@ static int get_fs_info(fsdata *mydata) if (mydata->fatsize == 32) { mydata->fatlength = bs.fat32_length; + mydata->total_sect = bs.total_sect; } else { mydata->fatlength = bs.fat_length; + mydata->total_sect = (bs.sectors[1] << 8) + bs.sectors[0]; + if (!mydata->total_sect) + mydata->total_sect = bs.total_sect; } + if (!mydata->total_sect) /* unlikely */ + mydata->total_sect = (u32)cur_part_info.size; + mydata->fats = bs.fats; mydata->fat_sect = bs.reserved; mydata->rootdir_sect = mydata->fat_sect + mydata->fatlength * bs.fats; diff --git a/include/fat.h b/include/fat.h index c02839dcb040..127e6622a9b0 100644 --- a/include/fat.h +++ b/include/fat.h @@ -175,6 +175,8 @@ typedef struct { int fatbufnum; /* Used by get_fatent, init to -1 */ int rootdir_size; /* Size of root dir for non-FAT32 */ __u32 root_cluster; /* First cluster of root dir for FAT32 */ + u32 total_sect; /* Number of sectors */ + int fats; /* Number of FATs */ } fsdata; static inline u32 clust_to_sect(fsdata *fsdata, u32 clust) From patchwork Tue Sep 11 06:58:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 146403 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3313619ljw; Tue, 11 Sep 2018 00:03:06 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdb8pwil3/hamRTFUaE9bDJ67PSJmQP2jawSFzle6fVUCDfv+z4GGiIdg/U9o7sUML3lwpzq X-Received: by 2002:a50:d1c7:: with SMTP id i7-v6mr27542094edg.169.1536649386688; Tue, 11 Sep 2018 00:03:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536649386; cv=none; d=google.com; s=arc-20160816; b=xCNMyzEH9sAABb0nOFu/ZJILh3iOZotTetB7BXjb4hJWMqZ3daGCXepP3JpKDZzb6L tH16BVEYWYZgbpokhYRuKV3AMJBy7V1fLtOTlwaOgkiVcNP71eafoWx6PfmvJowASBEw k3Esrs6cexyCzMKzZN0XPD3qvpwPd34QNUL70UK6nQIEMElnOIf5PJ5hzWwhlHlyhmPv 8axFvhPmwsJHwpp7ZFK/obBNq8ulNpm2flDNOpjg9rUZOugJ4w4Cl5LvJA8QJhbVkO7F MUZsrTzVH3fkoeNiphxeNJRj9EMVV0VDJKFSdPSx465HTYGogjpBDNyuUIqaoi5dh5zC IczQ== 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=y2jCVFB3wvNtehATQrN16ytmxpVCsNxdgLEjJm+DsDk=; b=NgZw8XhrWEmj/NR1rgFcu69DDTFtGM/4IW4rzLNkHYJIXmXUKGLEoZOJ4zNOmf9/gu 2ezpUgoLukOAtA/Slj+ruIhSBab3XyTsKjjEhb7kZVSS+BXcJS0xM2yE5kZRJW/SBp8V fqVQp2DT255o23xH8fHu+wLFObbTjorkWIhkL+jIZy0DqycV1pP8YJcVWNNLxzqZfECu 6dRLBELe95g6T/i8PeeXY8ymhLYcq/Hg+Bb/N3L6YvZiHs3RmZ/t/u1ran9r317BO6kG Az+Ds79R6nUpqLqE+cqSJyFJTJhiaLQTswrJuBptU+kO+I3HpJspdDOO0k53+ucD5yf/ dCLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=VAjWGsTb; 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 y13-v6si379342edv.448.2018.09.11.00.03.06; Tue, 11 Sep 2018 00:03:06 -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=VAjWGsTb; 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 35A82C21E7F; Tue, 11 Sep 2018 07:00:51 +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 B90DEC21EA6; Tue, 11 Sep 2018 06:59:33 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 21CA7C21E1E; Tue, 11 Sep 2018 06:59:22 +0000 (UTC) Received: from mail-pg1-f193.google.com (mail-pg1-f193.google.com [209.85.215.193]) by lists.denx.de (Postfix) with ESMTPS id 7DDFCC21EE3 for ; Tue, 11 Sep 2018 06:59:14 +0000 (UTC) Received: by mail-pg1-f193.google.com with SMTP id x26-v6so11743729pge.12 for ; Mon, 10 Sep 2018 23:59:14 -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=WgJhfpNw2FLc9WovSCz84LpLX5oEQMsN6Dnki2RwYPY=; b=VAjWGsTbp50KBssW45lZMBJj2z0OiA+qfrzaiBSxngvR2B4nqEM96cacPw+taxz+ZI 4v0+g779sUt+1QvHKoosQACsxMdNOjLYQP4P6ct9R4TeXpXEenjaFkksQCq9feEMW4C9 1YVj184kzXjzvA0+64qCxi60At6sEQ0/QplDQ= 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=WgJhfpNw2FLc9WovSCz84LpLX5oEQMsN6Dnki2RwYPY=; b=l4s3Tn+TvF1JFiVOVusTTz3V2YV03H9oGmCVS44H+wZmv3rDFgrsqcTmNHhSPF6Evt Ax+s4DXfhLk0u1iRhbn89EEO0jLubDQ90YqIDU/KXl1TjAZO4QnFCMcAZXOhVLRzkA2x TRxndoc715uZ5HFyHNi38H5w3b5zGrmd/bRpdxATB/R32dJFg4KhwGMIcY2zDKZbXhmi n1RL5RK9KfFoOuvvQBhrbF4J8jQ+DJfm78l0qeJh47ahdK5SLdRwwC94PFQCApPP0L1O 4iAvaGj5a7dcDz98KfJJxKIY5giIYwx4K45wDt5LiDEKQBRQwjbcdq9JWA81JpTv7pAY lGQQ== X-Gm-Message-State: APzg51DaWjk8Q3JkHmr3wJ5hNvur2nD/3cJLN0Ud724SRefi4lfldcbm Z17fzZaUkOPX2YHFvNOt10Itbg== X-Received: by 2002:a62:a65a:: with SMTP id t87-v6mr27509309pfe.225.1536649152983; Mon, 10 Sep 2018 23:59:12 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id b3-v6sm37210623pgm.74.2018.09.10.23.59.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Sep 2018 23:59:12 -0700 (PDT) From: "Akashi, Takahiro" To: trini@konsulko.com Date: Tue, 11 Sep 2018 15:58:59 +0900 Message-Id: <20180911065922.19141-4-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 03/26] fs: fat: handle "." and ".." of root dir correctly with fat_itr_resolve() 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 FAT's root directory does not have "." nor ".." So care must be taken when scanning root directory with fat_itr_resolve(). Without this patch, any file path starting with "." or ".." will not be resolved at all. Signed-off-by: AKASHI Takahiro --- fs/fat/fat.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/fs/fat/fat.c b/fs/fat/fat.c index 0576658dde09..eaea9300fd7f 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -931,6 +931,27 @@ static int fat_itr_resolve(fat_itr *itr, const char *path, unsigned type) while (next[0] && !ISDIRDELIM(next[0])) next++; + if (itr->is_root) { + /* root dir doesn't have "." nor ".." */ + if ((((next - path) == 1) && !strncmp(path, ".", 1)) || + (((next - path) == 2) && !strncmp(path, "..", 2))) { + /* point back to itself */ + itr->clust = itr->fsdata->root_cluster; + itr->dent = NULL; + itr->remaining = 0; + itr->last_cluster = 0; + + if (next[0] == 0) { + if (type & TYPE_DIR) + return 0; + else + return -ENOENT; + } + + return fat_itr_resolve(itr, next, type); + } + } + while (fat_itr_next(itr)) { int match = 0; unsigned n = max(strlen(itr->name), (size_t)(next - path)); From patchwork Tue Sep 11 06:59:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 146400 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3311756ljw; Tue, 11 Sep 2018 00:01:12 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbaDXGRezfWF8N8mciayCRR/TpOi7bm2wQBtKxVjWPDzKPUfJQNLv6WzHe8+7IH+eMWnMYZ X-Received: by 2002:a50:9943:: with SMTP id l3-v6mr26406821edb.198.1536649272260; Tue, 11 Sep 2018 00:01:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536649272; cv=none; d=google.com; s=arc-20160816; b=vne9Cnef6IeumF1Cr5XsaDLMpz/KZuVU7bgmeJ0NCWQ8BDzvhKlyej1QJyX54dLz6k 45oCo3o9/YNWHc3z2AJi/5o06aw3BZFCzUZwKT7r011kbfnYZe4zya8Ysnwt1Vz82SbO t9UMTNLoej3V8ANcCYoCPOlGTGsylNbndVF+N+iITwKmw0DZ9mnPh+b7SBTr9dqk9oUA p0VoXHDwY9sW4OEvDKKYs62Vh9dB5z5C6FPXrqaDT2iC95tfkuEJi3B6WzDP3hiLoo5k 5wzS6sdiUxQSk4oyuOS0bHJ/gcr3StkXXyZqz9WZnJvBx6/7m6iMjrKnv064JjrOxhy2 43og== 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=VXxDYRf2UDJuSUK4m4S9fEEL+ihrtraWxS+O6Onn/JY=; b=GEiNPMquLnPDYoYFL6eh5sy2Zar6C3C70bUZ0Y9Xmb2xelmLTkg0sYxX9hlA6tZiwX ebCvyxGZNIvToOpvVx9Kk9snNOTbPnQgKcL933vt93GKXjEckTrdHrQmRrUukoZgdguw gqSArYm5Wmp5tdALm6/EXe4g7SpeBxpPWGWJwnNUOsrRE07QCHwYAT6VqNC4AwIDMlDM sqYFM7YT5NQkbPS3ftYdM+JKrlW++8ktwA7iOZYVRNv7Wv5m7kYXMpTMJvgMuIzFDbTe C3YtTUP1O8RimrhWq4CfNZrUu4Ve607xq7fH9jaCjfkaH1XMRnc4+ekFi6iLt6rK082S xeYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=ROv4dzdY; 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 m12-v6si2864168edl.377.2018.09.11.00.01.11; Tue, 11 Sep 2018 00:01:12 -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=ROv4dzdY; 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 746A5C21F0B; Tue, 11 Sep 2018 07:00:27 +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 92EEDC21E1E; Tue, 11 Sep 2018 06:59:31 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 1DFECC21E79; Tue, 11 Sep 2018 06:59:24 +0000 (UTC) Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by lists.denx.de (Postfix) with ESMTPS id 0166DC21EB4 for ; Tue, 11 Sep 2018 06:59:18 +0000 (UTC) Received: by mail-pl1-f174.google.com with SMTP id p5-v6so3420530plk.3 for ; Mon, 10 Sep 2018 23:59: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=keiPZSLItt2usdSO0Pcw2aKM3colcSf8l+MbC4bYk7s=; b=ROv4dzdYlBTJlg4qK4jaTHz8kKWwyJHReIGF7uJV9x1F1ozXyxo+xE60SlPDczSBtd M2tR39nDfNQ/JgH8fkDL/iFHNOxIl5Rh8TYcnAzESF3doxjrl1yFikMD25gPFvE+xmgk ReJwBbhbNw0oaECSzn9yDrWGedNSRuXfgpFlQ= 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=keiPZSLItt2usdSO0Pcw2aKM3colcSf8l+MbC4bYk7s=; b=jMLMhrWuXSAVyfuU1K+BLlupsN3X7lW0hIcOtD895VsQQz5ZXirTbxFDwIGgl9jsXm xi1Q5H/j/1c/oIS+ZfZI6kuO+CIyZYVM4eyyMiyVPp9CZinALYG079m+0CONgGMbaL0S qZedh0Wnv7gq5qy0/Yy0BB5sNJBRZGHBYZRHDgwgm0r0uio2Ir6uIBtqxfjRyhWoRDMa g0C1sxh/FyJc6C8eF3JlmtX14veOBZlU92W+E+IV+e8nJUs1/eyVuIs1JrKmcBiYpF2/ ZF5x04VT9WWQbamSYVo/gyfHXXJ9oRE5YBxCiZDepwgsXVXLVDHx4Jn652TAgMq/G0m9 df4A== X-Gm-Message-State: APzg51BI3rvXo+7kHKeFOgeSlJwcOo9hwHdlJDQlXDe/l88wNSqp1FlK 9xJPLAlM3Cf+3uHolDUsVB2JDA== X-Received: by 2002:a17:902:722:: with SMTP id 31-v6mr25417554pli.207.1536649157445; Mon, 10 Sep 2018 23:59:17 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id w12-v6sm27310589pfd.110.2018.09.10.23.59.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Sep 2018 23:59:16 -0700 (PDT) From: "Akashi, Takahiro" To: trini@konsulko.com Date: Tue, 11 Sep 2018 15:59:00 +0900 Message-Id: <20180911065922.19141-5-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 04/26] fs: fat: assure iterator's ->dent belongs to ->clust 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 In my attempt to re-work write operation, it was revealed that iterator's "clust" does not always point to a cluster to which a current directory entry ("dent") belongs. This patch assures that it is always true by adding "next_clust" which is used solely for dereferencing a cluster chain. Signed-off-by: AKASHI Takahiro --- fs/fat/fat.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/fs/fat/fat.c b/fs/fat/fat.c index eaea9300fd7f..afb8b3f9ef1a 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -641,6 +641,7 @@ static int get_fs_info(fsdata *mydata) typedef struct { fsdata *fsdata; /* filesystem parameters */ unsigned clust; /* current cluster */ + unsigned next_clust; /* next cluster if remaining == 0 */ int last_cluster; /* set once we've read last cluster */ int is_root; /* is iterator at root directory */ int remaining; /* remaining dent's in current cluster */ @@ -672,6 +673,7 @@ static int fat_itr_root(fat_itr *itr, fsdata *fsdata) itr->fsdata = fsdata; itr->clust = fsdata->root_cluster; + itr->next_clust = fsdata->root_cluster; itr->dent = NULL; itr->remaining = 0; itr->last_cluster = 0; @@ -707,9 +709,11 @@ static void fat_itr_child(fat_itr *itr, fat_itr *parent) itr->fsdata = parent->fsdata; if (clustnum > 0) { itr->clust = clustnum; + itr->next_clust = clustnum; itr->is_root = 0; } else { itr->clust = parent->fsdata->root_cluster; + itr->next_clust = parent->fsdata->root_cluster; itr->is_root = 1; } itr->dent = NULL; @@ -727,7 +731,7 @@ static void *next_cluster(fat_itr *itr) if (itr->last_cluster) return NULL; - sect = clust_to_sect(itr->fsdata, itr->clust); + sect = clust_to_sect(itr->fsdata, itr->next_clust); debug("FAT read(sect=%d), clust_size=%d, DIRENTSPERBLOCK=%zd\n", sect, itr->fsdata->clust_size, DIRENTSPERBLOCK); @@ -748,18 +752,19 @@ static void *next_cluster(fat_itr *itr) return NULL; } + itr->clust = itr->next_clust; if (itr->is_root && itr->fsdata->fatsize != 32) { - itr->clust++; - sect = clust_to_sect(itr->fsdata, itr->clust); + itr->next_clust++; + sect = clust_to_sect(itr->fsdata, itr->next_clust); if (sect - itr->fsdata->rootdir_sect >= itr->fsdata->rootdir_size) { - debug("cursect: 0x%x\n", itr->clust); + debug("nextclust: 0x%x\n", itr->next_clust); itr->last_cluster = 1; } } else { - itr->clust = get_fatent(itr->fsdata, itr->clust); - if (CHECK_CLUST(itr->clust, itr->fsdata->fatsize)) { - debug("cursect: 0x%x\n", itr->clust); + itr->next_clust = get_fatent(itr->fsdata, itr->next_clust); + if (CHECK_CLUST(itr->next_clust, itr->fsdata->fatsize)) { + debug("nextclust: 0x%x\n", itr->next_clust); itr->last_cluster = 1; } } @@ -775,8 +780,11 @@ static dir_entry *next_dent(fat_itr *itr) itr->fsdata->clust_size; /* have we reached the last cluster? */ - if (!dent) + if (!dent) { + /* a sign for no more entries left */ + itr->dent = NULL; return NULL; + } itr->remaining = nbytes / sizeof(dir_entry) - 1; itr->dent = dent; @@ -937,6 +945,7 @@ static int fat_itr_resolve(fat_itr *itr, const char *path, unsigned type) (((next - path) == 2) && !strncmp(path, "..", 2))) { /* point back to itself */ itr->clust = itr->fsdata->root_cluster; + itr->next_clust = itr->fsdata->root_cluster; itr->dent = NULL; itr->remaining = 0; itr->last_cluster = 0; From patchwork Tue Sep 11 06:59:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 146402 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3312285ljw; Tue, 11 Sep 2018 00:01:46 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZAB78ebILuaXRUkQqMWfQxbrJneSiElK3ST3ff+UPx9gh5jLMGA9n74V61XLox1V2X33es X-Received: by 2002:a50:98c1:: with SMTP id j59-v6mr27200095edb.212.1536649306221; Tue, 11 Sep 2018 00:01:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536649306; cv=none; d=google.com; s=arc-20160816; b=lpzmH4xgaagH09mllePdSFHQSQ1+/71OkxRZ+KtohfCTPEtTZYq0clI+klbRnZLsfA /GVNDHSKDte5CcF82Y1xGmxXcDA6/p5O5mFkU1smvy131gf6gpD1JdCzLbvgY8zEViSE Ty11e9vlr/OiXNICupeZQo/3WLc1LZ1jtCoEixP5Hij3q3ep5NccO7vs3kpSQhW2r/XO G4zJkT1ReHEzxwj8t2zhMzHF0uw7JbAf1aw2WOrGZAb0Cyn5Yz2T0ONByWDvlCCpZ8SO 8jEhYNVjOamBce3quuyKjqko/cwIzmJPFl2T1INa7WGHWaaq/v5ATqAin2K+F5nm8SWK EzQg== 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=KJ0W4AgnmDNh21ps7wgONtwIDhWSnZl4NK/NNPLb2oo=; b=NFwx4962dB5f0VMouUj/vUJ3UDj97ajw3UBK7wqDhyz0CBv2C3LFH4tkT2ICq6SYt6 Dydxa2Zm2ON2RLMdbe6vZzFpQnxzcYOtCqkdTPhlLfQku2MEbVO0eCkqnIkHI/kc9Zac g5VpHMoZhCL4wTX70KyajiGMWAOZsa1jCT63CYmXL6J1QuQT+9nc2rxuayn++HjO6xiD MtC/Fn+vtTgmzAr4fQfq67B7LMs6H7FG42ehIX/dfhtVYG4K1o1p9bTt8EztPT3HdoFV StEuEl4z4c2brwhWzt83/XeWmg/8Nbr3cGFR0TVhCCpWk8ukWlrsWuIeU7f9ihD1Mr87 9GTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=LD0lhz0e; 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 g14-v6si1545001edv.426.2018.09.11.00.01.45; Tue, 11 Sep 2018 00:01:46 -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=LD0lhz0e; 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 C2894C21EE0; Tue, 11 Sep 2018 07:01:19 +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 9BC07C21E62; Tue, 11 Sep 2018 06:59:45 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 16FE7C21E44; Tue, 11 Sep 2018 06:59:28 +0000 (UTC) Received: from mail-pf1-f194.google.com (mail-pf1-f194.google.com [209.85.210.194]) by lists.denx.de (Postfix) with ESMTPS id 8050CC21EAE for ; Tue, 11 Sep 2018 06:59:23 +0000 (UTC) Received: by mail-pf1-f194.google.com with SMTP id j8-v6so11740156pff.6 for ; Mon, 10 Sep 2018 23:59:23 -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=ctFj8Pr+H4tXDOL9qPjkWMRjj/pmNWHvYPWLNrAU8iM=; b=LD0lhz0eRv+YzL0f8VgszSea1SyKZnoj5JXslYEz18HQBksFhPPlzerrxi/h1iS8Dz jCg7qtXoxh25DyYDLBjOhhWJK2XoJS2/ZXP+aDATruOzyhlI1tjgEiAf6POhipakqtQC A8Pz9NOVJBq4nyc6YPjAIr/EUFsDe8APxtY78= 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=ctFj8Pr+H4tXDOL9qPjkWMRjj/pmNWHvYPWLNrAU8iM=; b=Jwoqfo2Bstg5qnKiYrGFVbPoY/wDHCKXNAJTUo7McTjJPh6Z4XhHm4voQ/LId8KROr aRo+cDKQTrz7cJR0rYOuAAX07b3q2aBI1/NqaPWOFV55IyR1yBxagOiiICwSg7xLw4Xf AmVTUzdcZQsZOR00YZlAUODS4k7+SxEYpHs3RcPmKbwQ9UrCMh1DoXAWjTPtv/JjiObA bMgXagtlVBsMqpvBUl6H4dJIHqNvlrgHbS1RTvL4AmP4jRPaBA0hhh1qbNvEZEHC197c Xe+ixNtSlttrSY16TQg92eLZd6SAqhjJWAEuA756ZJmrTsVe6cEaO6yjuGKpasOknDc/ Jt8Q== X-Gm-Message-State: APzg51ALyBGA3/+m0EVA0e3yRbaEsn+yWDqptSvJSrVKAZwyZWU6GvVp BJZTf+MBYwD7pojwZaS98K+C3w== X-Received: by 2002:a62:1a8f:: with SMTP id a137-v6mr27740295pfa.190.1536649162010; Mon, 10 Sep 2018 23:59:22 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id g5-v6sm29820367pfc.77.2018.09.10.23.59.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Sep 2018 23:59:21 -0700 (PDT) From: "Akashi, Takahiro" To: trini@konsulko.com Date: Tue, 11 Sep 2018 15:59:01 +0900 Message-Id: <20180911065922.19141-6-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 05/26] Revert "fs: fat: cannot write to subdirectories" 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 This reverts commit 0dc1bfb7302d220a48364263d5632d6d572b069b. The succeeding patch series will supersede it. Signed-off-by: AKASHI Takahiro --- fs/fat/fat_write.c | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c index 27e0ff66966c..3b77557b3ede 100644 --- a/fs/fat/fat_write.c +++ b/fs/fat/fat_write.c @@ -909,11 +909,9 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, volume_info volinfo; fsdata datablock; fsdata *mydata = &datablock; - int cursect, i; + int cursect; int ret = -1, name_len; char l_filename[VFAT_MAXLEN_BYTES]; - char bad[2] = " "; - const char illegal[] = "<>:\"/\\|?*"; *actwrite = size; dir_curclust = 0; @@ -973,18 +971,6 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, } dentptr = (dir_entry *) do_fat_read_at_block; - /* Strip leading (back-)slashes */ - while ISDIRDELIM(*filename) - ++filename; - /* Check that the filename is valid */ - for (i = 0; i < strlen(illegal); ++i) { - *bad = illegal[i]; - if (strstr(filename, bad)) { - printf("FAT: illegal filename (%s)\n", filename); - return -1; - } - } - name_len = strlen(filename); if (name_len >= VFAT_MAXLEN_BYTES) name_len = VFAT_MAXLEN_BYTES - 1; From patchwork Tue Sep 11 06:59:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 146407 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3315465ljw; Tue, 11 Sep 2018 00:05:17 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbchYD3w09QLqrtiiipqOTCDmpvk+nUdxK83uQXmbVQ9Sg2acWXbQ6BC6XXk09Qy3iXP7kL X-Received: by 2002:a50:a9e2:: with SMTP id n89-v6mr26694566edc.158.1536649517735; Tue, 11 Sep 2018 00:05:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536649517; cv=none; d=google.com; s=arc-20160816; b=DQPcHP299dO4ql/IquTJJn9cFvWZMaZ9awaiptfQOq8R947OlfUaW16W6MIR3Vmyec bopriqYHbRZQYLjSj9YDHHJeinjUBQqXFpJJeudgSQNhdeqMP63AaQyov1ONgZYqNPM9 5aDnR4cEbLanxdEFjWqyguS2c29s97zq5IJsMK4cpqctFRohDgI8eY/twUugm23H6Pnv YuUM9Q1G4DNWCJHDiusi5tzAwDQmI/Q0Jw78NlN65RIDtzRHRBTYwVLyYwBUeBNq3MC+ Cg89IeR/eH2eb3Y0sNZi3VsX+LlG9vqQX3budLdTG3x2PGbFKMKkrkrHrVOsmdR8eL8e VCYA== 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=gdXYslx8p5W/KMPvE1C04bKY7LPpHiqTmFibqJwhMZ8=; b=xQUaB9HHR5qdqT/nVOXkSPesGixKRIPivkZgKoBrVvXRIxZvre564Xr1ZOL6WoIRg8 BjVY0r/lplX+F5jUdMX72JHQTsa9EmzgiEeoaKeVkQloynR2oD9aBNbFjR1hc/tIUTyg BI5R5m8blHgt14mCcwNtkmxtrY8cM/lYkVjRxX6nudXXkCAs5uCXL57PM8TuOVMyfhTc YohszpFvdkU/Fxi+Qzog1TD1nz71ShMf2SFw6jf5CpAiewG9TJzFa3su86NEM5CkUp5b A3DrDOGFBQCaRTlMu3BvdFcfXFtJafQ+XySvubCXgUYR4wEpc70t36Ek9xn5rv5A579u 8nhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=XmsJmWQx; 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 t24-v6si2613920edq.93.2018.09.11.00.05.17; Tue, 11 Sep 2018 00:05:17 -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=XmsJmWQx; 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 0A37EC21EC8; Tue, 11 Sep 2018 07:02:00 +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 1ADA9C21EAE; Tue, 11 Sep 2018 06:59:52 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id AC18FC21EE4; Tue, 11 Sep 2018 06:59:31 +0000 (UTC) Received: from mail-pg1-f193.google.com (mail-pg1-f193.google.com [209.85.215.193]) by lists.denx.de (Postfix) with ESMTPS id 98691C21E8A for ; Tue, 11 Sep 2018 06:59:26 +0000 (UTC) Received: by mail-pg1-f193.google.com with SMTP id d19-v6so11766532pgv.1 for ; Mon, 10 Sep 2018 23:59:26 -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=MVxMfgjxhQvMYNO4yw3uXrCa1n21Pbn66r3R2pzJQMs=; b=XmsJmWQx+qCbvt+Z7egcWg9tVQRxKo9iRmUxrHGxD7WM2f+T79BkoU7ZIJ+ZHtlJx3 3kcei+a5E/76ZuOT/zEXzMxx1K8rfTNJaxZxpM1C95Mr65IUqzDBMcr1f8D5fzg8wS9x dADfxcGsGfZMFlzPYg3DDi2Q0mABzV0wUeGzo= 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=MVxMfgjxhQvMYNO4yw3uXrCa1n21Pbn66r3R2pzJQMs=; b=WRBB6QDoisy7PiW5He/btHU6s/sbpx2ZK263M35hY+DsDFxv39E56WpsihsS5PcAyw jT3NQL5UZh8Fh7zSmgDHgxGJO7Dkno5+3lIHSXmD0PoTFrjsDaoxiviRR5By/+jPSEpQ 2iSv8nugS/2enuVJ8o7yWqifjxaDHehnb1L3U3lw9Ulzw+DqKnb5t3qmrObUkwG8VUeV TQW2CTe0AtGFQqrO+TNEgt83EYoQhPudruKzsEmRkMx/vyLKYcVyMJXhJ421Tg2fxoz6 Ep4WPaH9BNHJ8XB+9FEpVsFZcPK2JEE9Z1X4b2H7KXb4eIzKBnylsLOsW4tYqZKsTuEk D/GA== X-Gm-Message-State: APzg51B3kzUY+zUrMkyvxU0Ytzs2A9Yfu1elmuymgLjixp7qAjn8266C +2MUNVVPLK8I4syEIFoj5HhyaA== X-Received: by 2002:aa7:860b:: with SMTP id p11-v6mr24898263pfn.247.1536649165234; Mon, 10 Sep 2018 23:59:25 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id e14-v6sm22776940pff.128.2018.09.10.23.59.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Sep 2018 23:59:24 -0700 (PDT) From: "Akashi, Takahiro" To: trini@konsulko.com Date: Tue, 11 Sep 2018 15:59:02 +0900 Message-Id: <20180911065922.19141-7-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 06/26] fs: fat: check and normalize file name 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 FAT file system's long file name support is a bit complicated and has some restrictions on its naming. We should be careful about it especially for write as it may easily end up with wrong file system. normalize_longname() check for the rules and normalize a file name if necessary. Please note, however, that this function is yet to be extended to fully comply with the standard. Signed-off-by: AKASHI Takahiro --- fs/fat/fat_write.c | 52 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 8 deletions(-) diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c index 3b77557b3ede..6c715a70f447 100644 --- a/fs/fat/fat_write.c +++ b/fs/fat/fat_write.c @@ -899,6 +899,44 @@ static dir_entry *find_directory_entry(fsdata *mydata, int startsect, return NULL; } +static int normalize_longname(char *l_filename, const char *filename) +{ + const char *p, legal[] = "!#$%&\'()-.@^`_{}~"; + char c; + int name_len; + + /* Check that the filename is valid */ + for (p = filename; p < filename + strlen(filename); p++) { + c = *p; + + if (('0' <= c) && (c <= '9')) + continue; + if (('A' <= c) && (c <= 'Z')) + continue; + if (('a' <= c) && (c <= 'z')) + continue; + if (strchr(legal, c)) + continue; + /* extended code */ + if ((0x80 <= c) && (c <= 0xff)) + continue; + + return -1; + } + + /* Normalize it */ + name_len = strlen(filename); + if (name_len >= VFAT_MAXLEN_BYTES) + /* should return an error? */ + name_len = VFAT_MAXLEN_BYTES - 1; + + memcpy(l_filename, filename, name_len); + l_filename[name_len] = 0; /* terminate the string */ + downcase(l_filename, INT_MAX); + + return 0; +} + static int do_fat_write(const char *filename, void *buffer, loff_t size, loff_t *actwrite) { @@ -910,7 +948,7 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, fsdata datablock; fsdata *mydata = &datablock; int cursect; - int ret = -1, name_len; + int ret = -1; char l_filename[VFAT_MAXLEN_BYTES]; *actwrite = size; @@ -971,13 +1009,11 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, } dentptr = (dir_entry *) do_fat_read_at_block; - name_len = strlen(filename); - if (name_len >= VFAT_MAXLEN_BYTES) - name_len = VFAT_MAXLEN_BYTES - 1; - - memcpy(l_filename, filename, name_len); - l_filename[name_len] = 0; /* terminate the string */ - downcase(l_filename, INT_MAX); + if (normalize_longname(l_filename, filename)) { + printf("FAT: illegal filename (%s)\n", filename); + ret = -EINVAL; + goto exit; + } startsect = mydata->rootdir_sect; retdent = find_directory_entry(mydata, startsect, 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); From patchwork Tue Sep 11 06:59:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 146408 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3315694ljw; Tue, 11 Sep 2018 00:05:33 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbByShD6YWjRmQABW6Zv590kTtyWURiCdjBrK+MpAtfG/CP63TrxFvZGA2B7aQZ4mdbvKXf X-Received: by 2002:a50:b7db:: with SMTP id i27-v6mr27311984ede.284.1536649533405; Tue, 11 Sep 2018 00:05:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536649533; cv=none; d=google.com; s=arc-20160816; b=yGiA4IWunYbwIHFYMDQWApDn/hTtQdCPzMTGZsf1lbqP1R6kGW9mBVmB4WRO1dxpjg d4ua0hch0Xx7YunwRQxTvTb2zLee46wuGHirCLgew0r8hZikesIy4gKv8+odmE6jRupN /8upKqaqDFC0yeqC0j+Sg6pA4l1FFxhxs1ytYe9rj/wSaF+WSCkgqCYIuUxIiqpeZ1cA V/UZJVR+CwVyBbn1RrzhVMOQ4hUBQNCimt+uNwuy6dZHYJhGESVYjWQdH9GhZnNF7R66 IP8WDeoGpnqQoIixpW0fygO7x6b39xJoxI8cfhdp6WJRL4U0LG0m3JMqIx04vzCvVAX5 rZDw== 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=KR3ol98ispkUpcCN5jE+NgBwqP8r9KSwJMjTj6yWW4I=; b=NOeIpcB3oy1ooKzPhRQW1CtJYTDvGAUDUKdrbzMAbRvU/4xMmIz9m9eCFQoRruYo4W 5Sdy164kFBNezO0jqBEBHixA8grc6oh8pRul7NZpnzBWFhI1zi2Ck8bL22xK/bOpjXnV 0JXlGNrMyoU275p/q20VqQnWuMwdMZ5Bvc9vQ6XKT3zKmr7sXKTqBNglZWC9NJ7BHfRI BZxRgRKnWK85nZ+rDFY//16for9uWFEoJAEceYbnIeiTrmw6KcKphQoEJim5BS3Y1GM5 +KEYaaHETbcV/4QNkb7AMP0wt1JvG567KEVVYPOV9bA7mxVfMPdKTyTUodaflgyh7H6C gAnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=A6cYHgfk; 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 m8-v6si557823edj.236.2018.09.11.00.05.33; Tue, 11 Sep 2018 00:05:33 -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=A6cYHgfk; 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 D368CC21E13; Tue, 11 Sep 2018 07:03:22 +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 DAD50C21EDE; Tue, 11 Sep 2018 07:00:11 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 92E75C21EFD; Tue, 11 Sep 2018 06:59:38 +0000 (UTC) Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com [209.85.210.195]) by lists.denx.de (Postfix) with ESMTPS id BFF94C21E4E for ; Tue, 11 Sep 2018 06:59:33 +0000 (UTC) Received: by mail-pf1-f195.google.com with SMTP id u24-v6so11726897pfn.13 for ; Mon, 10 Sep 2018 23:59:33 -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=4PONucRGR9V0Hud3joGkF+3QgBqMV6Pco8o94a2cJDo=; b=A6cYHgfkSOeqeS1AEcxKKNUGJFpNkLzXjOq4uOmwrAAsGXBv12hUWXLY+3G+P+HcNq cFexAY4jpb+qHg3isxHTEr2Br3xNG8PuOkqT6SMHW9DpGPiLQCFnOt6T//njZV/C0yOU QRJb/eOQdKvI78Vr6Pwr23mCfd6RCVUFfDmjs= 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=4PONucRGR9V0Hud3joGkF+3QgBqMV6Pco8o94a2cJDo=; b=YZOr8+ywTfIkWFusJmDTWsn/iAHddTZTMtUeN7DPyBv3Ma+Jfletk3S+RvXnBuEHRA oxkbQqm5pHQ6R/RvauJtJJfGXAhdI4wApovapa9VG22J3t7tpKpTJNFuAiAC1bDyHgFa yrU73hzG+9wOSryeMubBVACn0l1FPCyAgG63oYWCpMP3vzC1IAcJAq7yCyCG9qOt9PyI sSUKRzyOa6o1ymNGn2O66QRoAS0UtwL9xptoMOlTMzpy+JuBtz7ss0ovKUmpp5wVBN8M FGFzRgLr8/qyyKEXz1bNP2RIXSwK4CXa7y5Gqg11n5+Geula7Zaqq2Y9g/2DL7IId9D3 aq6A== X-Gm-Message-State: APzg51CmoOWDZFjMWCxE+DLvde5/6XiWDTKt5jln0BQOz7n1XZDXpULC OnVKPRzBp55h9jWZr7Ioqy/ifA== X-Received: by 2002:a63:77ce:: with SMTP id s197-v6mr27032666pgc.172.1536649172151; Mon, 10 Sep 2018 23:59:32 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id j27-v6sm31485315pfj.91.2018.09.10.23.59.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Sep 2018 23:59:31 -0700 (PDT) From: "Akashi, Takahiro" To: trini@konsulko.com Date: Tue, 11 Sep 2018 15:59:04 +0900 Message-Id: <20180911065922.19141-9-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 08/26] fs: fat: support write with sub-directory path 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 In this patch, write implementation is overhauled and rewritten by making full use of directory iterator. The obvious bonus is that we are now able to write to a file with a directory path, like /A/B/C/FILE. Please note that, as there is no notion of "current directory" on u-boot, a file name specified must contain an absolute directory path. Otherwise, "/" (root directory) is assumed. Signed-off-by: AKASHI Takahiro --- fs/fat/fat.c | 9 - fs/fat/fat_write.c | 469 +++++++++++++++------------------------------ 2 files changed, 156 insertions(+), 322 deletions(-) diff --git a/fs/fat/fat.c b/fs/fat/fat.c index afb8b3f9ef1a..5aa28656c7d5 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -464,15 +464,6 @@ static __u8 mkcksum(const char name[8], const char ext[3]) return ret; } -/* - * TODO these should go away once fat_write is reworked to use the - * directory iterator - */ -__u8 get_dentfromdir_block[MAX_CLUSTSIZE] - __aligned(ARCH_DMA_MINALIGN); -__u8 do_fat_read_at_block[MAX_CLUSTSIZE] - __aligned(ARCH_DMA_MINALIGN); - /* * Read boot sector and volume info from a FAT filesystem */ diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c index 1e4f5af9106d..37ef0564eb5e 100644 --- a/fs/fat/fat_write.c +++ b/fs/fat/fat_write.c @@ -99,7 +99,6 @@ static void set_name(dir_entry *dirent, const char *filename) debug("ext : %s\n", dirent->ext); } -static __u8 num_of_fats; /* * Write fat buffer into block device */ @@ -128,7 +127,7 @@ static int flush_dirty_fat_buffer(fsdata *mydata) return -1; } - if (num_of_fats == 2) { + if (mydata->fats == 2) { /* Update corresponding second FAT blocks */ startblock += mydata->fatlength; if (disk_write(startblock, getsize, bufptr) < 0) { @@ -210,15 +209,14 @@ name11_12: return 1; } -static int is_next_clust(fsdata *mydata, dir_entry *dentptr); -static void flush_dir_table(fsdata *mydata, dir_entry **dentptr); +static int flush_dir_table(fat_itr *itr); /* * Fill dir_slot entries with appropriate name, id, and attr - * The real directory entry is returned by 'dentptr' + * 'itr' will point to a next entry */ -static void -fill_dir_slot(fsdata *mydata, dir_entry **dentptr, const char *l_name) +static int +fill_dir_slot(fat_itr *itr, const char *l_name) { __u8 temp_dir_slot_buffer[MAX_LFN_SLOT * sizeof(dir_slot)]; dir_slot *slotptr = (dir_slot *)temp_dir_slot_buffer; @@ -226,7 +224,7 @@ fill_dir_slot(fsdata *mydata, dir_entry **dentptr, const char *l_name) int idx = 0, ret; /* Get short file name checksum value */ - checksum = mkcksum((*dentptr)->name, (*dentptr)->ext); + checksum = mkcksum(itr->dent->name, itr->dent->ext); do { memset(slotptr, 0x00, sizeof(dir_slot)); @@ -241,120 +239,21 @@ fill_dir_slot(fsdata *mydata, dir_entry **dentptr, const char *l_name) slotptr->id |= LAST_LONG_ENTRY_MASK; while (counter >= 1) { - if (is_next_clust(mydata, *dentptr)) { - /* A new cluster is allocated for directory table */ - flush_dir_table(mydata, dentptr); - } - memcpy(*dentptr, slotptr, sizeof(dir_slot)); - (*dentptr)++; + memcpy(itr->dent, slotptr, sizeof(dir_slot)); slotptr--; counter--; - } - - if (is_next_clust(mydata, *dentptr)) { - /* A new cluster is allocated for directory table */ - flush_dir_table(mydata, dentptr); - } -} - -static __u32 dir_curclust; - -/* - * Extract the full long filename starting at 'retdent' (which is really - * a slot) into 'l_name'. If successful also copy the real directory entry - * into 'retdent' - * If additional adjacent cluster for directory entries is read into memory, - * then 'get_contents_vfatname_block' is copied into 'get_dentfromdir_block' and - * the location of the real directory entry is returned by 'retdent' - * Return 0 on success, -1 otherwise. - */ -static int -get_long_file_name(fsdata *mydata, int curclust, __u8 *cluster, - dir_entry **retdent, char *l_name) -{ - dir_entry *realdent; - dir_slot *slotptr = (dir_slot *)(*retdent); - dir_slot *slotptr2 = NULL; - __u8 *buflimit = cluster + mydata->sect_size * ((curclust == 0) ? - PREFETCH_BLOCKS : - mydata->clust_size); - __u8 counter = (slotptr->id & ~LAST_LONG_ENTRY_MASK) & 0xff; - int idx = 0, cur_position = 0; - - if (counter > VFAT_MAXSEQ) { - debug("Error: VFAT name is too long\n"); - return -1; - } - - while ((__u8 *)slotptr < buflimit) { - if (counter == 0) - break; - if (((slotptr->id & ~LAST_LONG_ENTRY_MASK) & 0xff) != counter) - return -1; - slotptr++; - counter--; - } - - if ((__u8 *)slotptr >= buflimit) { - if (curclust == 0) - return -1; - curclust = get_fatent(mydata, dir_curclust); - if (CHECK_CLUST(curclust, mydata->fatsize)) { - debug("curclust: 0x%x\n", curclust); - printf("Invalid FAT entry\n"); - return -1; - } - - dir_curclust = curclust; - - if (get_cluster(mydata, curclust, get_contents_vfatname_block, - mydata->clust_size * mydata->sect_size) != 0) { - debug("Error: reading directory block\n"); - return -1; - } - - slotptr2 = (dir_slot *)get_contents_vfatname_block; - while (counter > 0) { - if (((slotptr2->id & ~LAST_LONG_ENTRY_MASK) - & 0xff) != counter) + if (!fat_itr_next(itr)) + if (!itr->dent && !itr->is_root && flush_dir_table(itr)) return -1; - slotptr2++; - counter--; - } - - /* Save the real directory entry */ - realdent = (dir_entry *)slotptr2; - while ((__u8 *)slotptr2 > get_contents_vfatname_block) { - slotptr2--; - slot2str(slotptr2, l_name, &idx); - } - } else { - /* Save the real directory entry */ - realdent = (dir_entry *)slotptr; } - do { - slotptr--; - if (slot2str(slotptr, l_name, &idx)) - break; - } while (!(slotptr->id & LAST_LONG_ENTRY_MASK)); - - l_name[idx] = '\0'; - if (*l_name == DELETED_FLAG) - *l_name = '\0'; - else if (*l_name == aRING) - *l_name = DELETED_FLAG; - downcase(l_name, INT_MAX); - - /* Return the real directory entry */ - *retdent = realdent; - - if (slotptr2) { - memcpy(get_dentfromdir_block, get_contents_vfatname_block, - mydata->clust_size * mydata->sect_size); - cur_position = (__u8 *)realdent - get_contents_vfatname_block; - *retdent = (dir_entry *) &get_dentfromdir_block[cur_position]; - } + if (!itr->dent && !itr->is_root) + /* + * don't care return value here because we have already + * finished completing an entry with name, only ending up + * no more entry left + */ + flush_dir_table(itr); return 0; } @@ -569,20 +468,20 @@ static int find_empty_cluster(fsdata *mydata) } /* - * Write directory entries in 'get_dentfromdir_block' to block device + * Write directory entries in itr's buffer to block device */ -static void flush_dir_table(fsdata *mydata, dir_entry **dentptr) +static int flush_dir_table(fat_itr *itr) { + fsdata *mydata = itr->fsdata; int dir_newclust = 0; + unsigned int bytesperclust = mydata->clust_size * mydata->sect_size; - if (set_cluster(mydata, dir_curclust, - get_dentfromdir_block, - mydata->clust_size * mydata->sect_size) != 0) { - printf("error: wrinting directory entry\n"); - return; + if (set_cluster(mydata, itr->clust, itr->block, bytesperclust) != 0) { + printf("error: writing directory entry\n"); + return -1; } dir_newclust = find_empty_cluster(mydata); - set_fatent_value(mydata, dir_curclust, dir_newclust); + set_fatent_value(mydata, itr->clust, dir_newclust); if (mydata->fatsize == 32) set_fatent_value(mydata, dir_newclust, 0xffffff8); else if (mydata->fatsize == 16) @@ -590,15 +489,19 @@ static void flush_dir_table(fsdata *mydata, dir_entry **dentptr) else if (mydata->fatsize == 12) set_fatent_value(mydata, dir_newclust, 0xff8); - dir_curclust = dir_newclust; + itr->clust = dir_newclust; + itr->next_clust = dir_newclust; if (flush_dirty_fat_buffer(mydata) < 0) - return; + return -1; + + memset(itr->block, 0x00, bytesperclust); - memset(get_dentfromdir_block, 0x00, - mydata->clust_size * mydata->sect_size); + itr->dent = (dir_entry *)itr->block; + itr->last_cluster = 1; + itr->remaining = bytesperclust / sizeof(dir_entry) - 1; - *dentptr = (dir_entry *) get_dentfromdir_block; + return 0; } /* @@ -764,139 +667,83 @@ static int check_overflow(fsdata *mydata, __u32 clustnum, loff_t size) return 0; } -/* - * Check if adding several entries exceed one cluster boundary - */ -static int is_next_clust(fsdata *mydata, dir_entry *dentptr) -{ - int cur_position; - - cur_position = (__u8 *)dentptr - get_dentfromdir_block; - - if (cur_position >= mydata->clust_size * mydata->sect_size) - return 1; - else - return 0; -} - -static dir_entry *empty_dentptr; /* * Find a directory entry based on filename or start cluster number * If the directory entry is not found, * the new position for writing a directory entry will be returned */ -static dir_entry *find_directory_entry(fsdata *mydata, int startsect, - char *filename, dir_entry *retdent, __u32 start) +static dir_entry *find_directory_entry(fat_itr *itr, char *filename) { - __u32 curclust = sect_to_clust(mydata, startsect); - - debug("get_dentfromdir: %s\n", filename); + int match = 0; - while (1) { - dir_entry *dentptr; + while (fat_itr_next(itr)) { + /* check both long and short name: */ + if (!strcasecmp(filename, itr->name)) + match = 1; + else if (itr->name != itr->s_name && + !strcasecmp(filename, itr->s_name)) + match = 1; - int i; + if (!match) + continue; - if (get_cluster(mydata, curclust, get_dentfromdir_block, - mydata->clust_size * mydata->sect_size) != 0) { - printf("Error: reading directory block\n"); + if (itr->dent->name[0] == '\0') return NULL; - } - - dentptr = (dir_entry *)get_dentfromdir_block; - - dir_curclust = curclust; - - for (i = 0; i < DIRENTSPERCLUST; i++) { - char s_name[14], l_name[VFAT_MAXLEN_BYTES]; - - l_name[0] = '\0'; - if (dentptr->name[0] == DELETED_FLAG) { - dentptr++; - if (is_next_clust(mydata, dentptr)) - break; - continue; - } - if ((dentptr->attr & ATTR_VOLUME)) { - if ((dentptr->attr & ATTR_VFAT) && - (dentptr->name[0] & LAST_LONG_ENTRY_MASK)) { - get_long_file_name(mydata, curclust, - get_dentfromdir_block, - &dentptr, l_name); - debug("vfatname: |%s|\n", l_name); - } else { - /* Volume label or VFAT entry */ - dentptr++; - if (is_next_clust(mydata, dentptr)) - break; - continue; - } - } - if (dentptr->name[0] == 0) { - debug("Dentname == NULL - %d\n", i); - empty_dentptr = dentptr; - return NULL; - } - - get_name(dentptr, s_name); - - if (strncasecmp(filename, s_name, sizeof(s_name)) && - strncasecmp(filename, l_name, sizeof(l_name))) { - debug("Mismatch: |%s|%s|\n", - s_name, l_name); - dentptr++; - if (is_next_clust(mydata, dentptr)) - break; - continue; - } + else + return itr->dent; + } - memcpy(retdent, dentptr, sizeof(dir_entry)); + if (!itr->dent && !itr->is_root && flush_dir_table(itr)) + /* indicate that allocating dent failed */ + itr->dent = NULL; - debug("DentName: %s", s_name); - debug(", start: 0x%x", START(dentptr)); - debug(", size: 0x%x %s\n", - FAT2CPU32(dentptr->size), - (dentptr->attr & ATTR_DIR) ? - "(DIR)" : ""); + return NULL; +} - return dentptr; +static int split_filename(char *filename, char **dirname, char **basename) +{ + char *p, *last_slash, *last_slash_cont; + +again: + p = filename; + last_slash = NULL; + last_slash_cont = NULL; + while (*p) { + if (ISDIRDELIM(*p)) { + last_slash = p; + last_slash_cont = p; + /* continuous slashes */ + while (ISDIRDELIM(*p)) + last_slash_cont = p++; + if (!*p) + break; } + p++; + } - /* - * In FAT16/12, the root dir is locate before data area, shows - * in following: - * ------------------------------------------------------------- - * | Boot | FAT1 & 2 | Root dir | Data (start from cluster #2) | - * ------------------------------------------------------------- - * - * As a result if curclust is in Root dir, it is a negative - * number or 0, 1. - * - */ - if (mydata->fatsize != 32 && (int)curclust <= 1) { - /* Current clust is in root dir, set to next clust */ - curclust++; - if ((int)curclust <= 1) - continue; /* continue to find */ - - /* Reach the end of root dir */ - empty_dentptr = dentptr; - return NULL; + if (last_slash) { + if (last_slash_cont == (filename + strlen(filename) - 1)) { + /* remove trailing slashes */ + *last_slash = '\0'; + goto again; } - curclust = get_fatent(mydata, dir_curclust); - if (IS_LAST_CLUST(curclust, mydata->fatsize)) { - empty_dentptr = dentptr; - return NULL; - } - if (CHECK_CLUST(curclust, mydata->fatsize)) { - debug("curclust: 0x%x\n", curclust); - debug("Invalid FAT entry\n"); - return NULL; + if (last_slash == filename) { + /* avoid ""(null) directory */ + *dirname = "/"; + } else { + *last_slash = '\0'; + *dirname = filename; } + + *last_slash_cont = '\0'; + *basename = last_slash_cont + 1; + } else { + *dirname = "/"; /* root by default */ + *basename = filename; } - return NULL; + return 0; } static int normalize_longname(char *l_filename, const char *filename) @@ -940,86 +787,58 @@ static int normalize_longname(char *l_filename, const char *filename) static int do_fat_write(const char *filename, void *buffer, loff_t size, loff_t *actwrite) { - dir_entry *dentptr, *retdent; - __u32 startsect; + dir_entry *retdent; __u32 start_cluster; - boot_sector bs; - volume_info volinfo; - fsdata datablock; + fsdata datablock = { .fatbuf = NULL, }; fsdata *mydata = &datablock; - int cursect; + fat_itr *itr = NULL; int ret = -1; + char *filename_copy, *parent, *basename; char l_filename[VFAT_MAXLEN_BYTES]; - *actwrite = size; - dir_curclust = 0; + filename_copy = strdup(filename); + if (!filename_copy) + return -ENOMEM; - if (read_bootsectandvi(&bs, &volinfo, &mydata->fatsize)) { - debug("error: reading boot sector\n"); - return -EIO; + split_filename(filename_copy, &parent, &basename); + if (!strlen(basename)) { + ret = -EINVAL; + goto exit; } - total_sector = bs.total_sect; - if (total_sector == 0) - total_sector = (int)cur_part_info.size; /* cast of lbaint_t */ - - if (mydata->fatsize == 32) - mydata->fatlength = bs.fat32_length; - else - mydata->fatlength = bs.fat_length; - - mydata->fat_sect = bs.reserved; - - cursect = mydata->rootdir_sect - = mydata->fat_sect + mydata->fatlength * bs.fats; - num_of_fats = bs.fats; - - mydata->sect_size = (bs.sector_size[1] << 8) + bs.sector_size[0]; - mydata->clust_size = bs.cluster_size; - - if (mydata->fatsize == 32) { - mydata->data_begin = mydata->rootdir_sect - - (mydata->clust_size * 2); - } else { - int rootdir_size; - - rootdir_size = ((bs.dir_entries[1] * (int)256 + - bs.dir_entries[0]) * - sizeof(dir_entry)) / - mydata->sect_size; - mydata->data_begin = mydata->rootdir_sect + - rootdir_size - - (mydata->clust_size * 2); + filename = basename; + if (normalize_longname(l_filename, filename)) { + printf("FAT: illegal filename (%s)\n", filename); + ret = -EINVAL; + goto exit; } - mydata->fatbufnum = -1; - mydata->fat_dirty = 0; - mydata->fatbuf = memalign(ARCH_DMA_MINALIGN, FATBUFSIZE); - if (mydata->fatbuf == NULL) { - debug("Error: allocating memory\n"); - return -ENOMEM; + itr = malloc_cache_aligned(sizeof(fat_itr)); + if (!itr) { + ret = -ENOMEM; + goto exit; } - if (disk_read(cursect, - (mydata->fatsize == 32) ? - (mydata->clust_size) : - PREFETCH_BLOCKS, do_fat_read_at_block) < 0) { - debug("Error: reading rootdir block\n"); - ret = -EIO; + ret = fat_itr_root(itr, &datablock); + if (ret) goto exit; - } - dentptr = (dir_entry *) do_fat_read_at_block; - if (normalize_longname(l_filename, filename)) { - printf("FAT: illegal filename (%s)\n", filename); - ret = -EINVAL; + total_sector = datablock.total_sect; + + ret = fat_itr_resolve(itr, parent, TYPE_DIR); + if (ret) { + printf("%s: doesn't exist (%d)\n", parent, ret); goto exit; } - startsect = mydata->rootdir_sect; - retdent = find_directory_entry(mydata, startsect, - l_filename, dentptr, 0); + retdent = find_directory_entry(itr, l_filename); + if (retdent) { + if (fat_itr_isdir(itr)) { + ret = -EISDIR; + goto exit; + } + /* Update file size and start_cluster in a directory entry */ retdent->size = cpu_to_le32(size); start_cluster = START(retdent); @@ -1062,9 +881,31 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, set_start_cluster(mydata, retdent, start_cluster); } } else { + /* Create a new file */ + + if (itr->is_root) { + /* root dir cannot have "." or ".." */ + if (!strcmp(l_filename, ".") || + !strcmp(l_filename, "..")) { + ret = -EINVAL; + goto exit; + } + } + + if (!itr->dent) { + printf("Error: allocating new dir entry\n"); + ret = -EIO; + goto exit; + } + + memset(itr->dent, 0, sizeof(*itr->dent)); + /* Set short name to set alias checksum field in dir_slot */ - set_name(empty_dentptr, filename); - fill_dir_slot(mydata, &empty_dentptr, filename); + set_name(itr->dent, filename); + if (fill_dir_slot(itr, filename)) { + ret = -EIO; + goto exit; + } if (size) { ret = start_cluster = find_empty_cluster(mydata); @@ -1084,11 +925,11 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, start_cluster = 0; } - /* Set attribute as archieve for regular file */ - fill_dentry(mydata, empty_dentptr, filename, - start_cluster, size, 0x20); + /* Set attribute as archive for regular file */ + fill_dentry(itr->fsdata, itr->dent, filename, + start_cluster, size, 0x20); - retdent = empty_dentptr; + retdent = itr->dent; } ret = set_contents(mydata, retdent, buffer, size, actwrite); @@ -1108,15 +949,17 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, } /* Write directory table to device */ - ret = set_cluster(mydata, dir_curclust, get_dentfromdir_block, - mydata->clust_size * mydata->sect_size); + ret = set_cluster(mydata, itr->clust, itr->block, + mydata->clust_size * mydata->sect_size); if (ret) { printf("Error: writing directory entry\n"); ret = -EIO; } exit: + free(filename_copy); free(mydata->fatbuf); + free(itr); return ret; } From patchwork Tue Sep 11 06:59:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 146405 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3314886ljw; Tue, 11 Sep 2018 00:04:35 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYZ3ThacBykbqV5wk3GPJY9yQT5yZrR91U4FdaGCssIT4QSyx+xxTq0RPdbbG/MNc1antS8 X-Received: by 2002:a50:9069:: with SMTP id z38-v6mr26979321edz.24.1536649475341; Tue, 11 Sep 2018 00:04:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536649475; cv=none; d=google.com; s=arc-20160816; b=qV5/7ikGtm/+ooiSm7pz5xumYTjuZKMIzUM+QD9qiihLNhyC+jsVagUuQNud/cAV4i w7jOpSTD23PiZolU0UCljrXQh5+nRghsVWpLbI0cQejjW0oK8q+1aWadwVCX7SWeuH1B 3Gvu39ORG3pV8mYNNAiadAcQ0W0SXU9vOgowBgVq1B4aCfrQBLG86t8OxL3ze3YQAd5E KlGBd2rOvuzQ+Xfh9Xuqh8hoZOy6VVvlUlpjsKnrY/HoneMW42lqEuD/Y6QpiLzPKYXU d8sCPntI3Cq2zM1M1GBwen9rirEggBwhFoUhgr60Rvu9b3vWhXj7lsOU+r4/e3wm2k37 gdPw== 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=XWfPpWQAWgw11aQvxkx9AWt3+I9k+tbz91lUR+z3OQ8=; b=pcu5ny0uCZ7Bqo22XkiyoLBXDP72lgMr+xqoN3FHQscJk0UXbmvm3VeOR/9cpfZpFV vKvA6UlJ297/UJLBombGV5NPTR4c8YAf8uNRb9b63/9apm7vKwlvVoQ63mcmK5ZQEc5x qDgqORmVDQZStf90iGLHgdkgpVc2+cAOywR23QhP3t27chDhKOb/gmKjyHnZo8F+pXy9 6VHxw1xU0T7UaDen+398kgF6VAJWA6LtOdosqRjJx2h6BwUn0vaVWEqOvggbOgc2QXMd ZgZattMOak/zSEEFX1OVMR+he3vUh+gBaWs+LcNW/juZv4yPCgVIER7wr+MGZL2DnYT/ kmSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=fxSTYgkL; 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 u14-v6si3661315edm.414.2018.09.11.00.04.33; Tue, 11 Sep 2018 00:04:35 -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=fxSTYgkL; 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 7FF28C21EB9; Tue, 11 Sep 2018 07:02:48 +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 3C080C21EE4; Tue, 11 Sep 2018 07:00:07 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 82CFDC21EC5; Tue, 11 Sep 2018 06:59:43 +0000 (UTC) Received: from mail-pl1-f196.google.com (mail-pl1-f196.google.com [209.85.214.196]) by lists.denx.de (Postfix) with ESMTPS id 0EB62C21E44 for ; Tue, 11 Sep 2018 06:59:38 +0000 (UTC) Received: by mail-pl1-f196.google.com with SMTP id f6-v6so10903518plo.1 for ; Mon, 10 Sep 2018 23:59:37 -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=X2HxNzRQ7CApE52WpExRcYF5fqD7dR2rw4yTsfaB5vM=; b=fxSTYgkLFfX8GxwioKo6dHz3+Nb/mUieQiKYJLfZaONyuBzTSRvdHBvF6VRSBUdjDe 9H+63g9UEcpuN1QjcomzAq9zyt1zecBL9H/qufDPj0K0jkUKyObGfgBcKYi/jNK271LW SEjOMstjK6bTYHPOIELlqLVNDXw3hSoaWLdl4= 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=X2HxNzRQ7CApE52WpExRcYF5fqD7dR2rw4yTsfaB5vM=; b=aIuNq8yu2gklP+kj68PoTNBfS9k5f2B/SOoqTiGL5rk5gRnyqydDy/I067V7BTfC97 MqMkpKQSIZuA9Q1X1///JpvUletf8wndxuh2vwfItMiJyP5GzTUTR2BxKcCMefd2hhBX 3+SS2Hg5QGQKxomkVUDZsDBIAg6R7D/9UF1PkmoPgE+aBeoC1VLhT1fDYlUgCGk+dBmr cl6sPfcsIyVZpyyufpaANweS9fP6G5vPlAA5PwhoVvdoOLc+x/2cQrx6U++bIE6h3vur dIbLXiEZTdGp0DNMqdD2Wh2n6wEPkYLr5nsiInGHIGSoAso0gpJf75PjO3ZSqbfBBhth JTEg== X-Gm-Message-State: APzg51AJTZravQ6shQl5Eh9Z4sPzDwVvOjoMo9r6LXqlsWJv+NWsLOc2 7NAQXDvzj+PuVnhNhml8j+veRw== X-Received: by 2002:a17:902:b282:: with SMTP id u2-v6mr24985090plr.123.1536649176589; Mon, 10 Sep 2018 23:59:36 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id t21-v6sm29704354pfi.73.2018.09.10.23.59.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Sep 2018 23:59:35 -0700 (PDT) From: "Akashi, Takahiro" To: trini@konsulko.com Date: Tue, 11 Sep 2018 15:59:05 +0900 Message-Id: <20180911065922.19141-10-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 09/26] fs: fat: refactor write interface for a file offset 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 The current write implementation is quite simple: remove existing clusters and then allocating new ones and filling them with data. This, inevitably, enforces always writing from the beginning of a file. As the first step to lift this restriction, fat_file_write() and set_contents() are modified to accept an additional parameter, file offset and further re-factored so that, in the next patch, all the necessary code will be put into set_contents(). Signed-off-by: AKASHI Takahiro --- fs/fat/fat_write.c | 179 ++++++++++++++++----------------------------- 1 file changed, 65 insertions(+), 114 deletions(-) diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c index 37ef0564eb5e..c22d8c7a46a1 100644 --- a/fs/fat/fat_write.c +++ b/fs/fat/fat_write.c @@ -528,6 +528,42 @@ static int clear_fatent(fsdata *mydata, __u32 entry) return 0; } +/* + * Set start cluster in directory entry + */ +static void set_start_cluster(const fsdata *mydata, dir_entry *dentptr, + __u32 start_cluster) +{ + if (mydata->fatsize == 32) + dentptr->starthi = + cpu_to_le16((start_cluster & 0xffff0000) >> 16); + dentptr->start = cpu_to_le16(start_cluster & 0xffff); +} + +/* + * Check whether adding a file makes the file system to + * exceed the size of the block device + * Return -1 when overflow occurs, otherwise return 0 + */ +static int check_overflow(fsdata *mydata, __u32 clustnum, loff_t size) +{ + __u32 startsect, sect_num, offset; + + if (clustnum > 0) + startsect = clust_to_sect(mydata, clustnum); + else + startsect = mydata->rootdir_sect; + + sect_num = div_u64_rem(size, mydata->sect_size, &offset); + + if (offset != 0) + sect_num++; + + if (startsect + sect_num > total_sector) + return -1; + return 0; +} + /* * Write at most 'maxsize' bytes from 'buffer' into * the file associated with 'dentptr' @@ -535,29 +571,36 @@ static int clear_fatent(fsdata *mydata, __u32 entry) * or return -1 on fatal errors. */ static int -set_contents(fsdata *mydata, dir_entry *dentptr, __u8 *buffer, - loff_t maxsize, loff_t *gotsize) +set_contents(fsdata *mydata, dir_entry *dentptr, loff_t pos, __u8 *buffer, + loff_t maxsize, loff_t *gotsize) { - loff_t filesize = FAT2CPU32(dentptr->size); + loff_t filesize; unsigned int bytesperclust = mydata->clust_size * mydata->sect_size; __u32 curclust = START(dentptr); __u32 endclust = 0, newclust = 0; loff_t actsize; *gotsize = 0; - debug("Filesize: %llu bytes\n", filesize); - - if (maxsize > 0 && filesize > maxsize) - filesize = maxsize; + filesize = maxsize; debug("%llu bytes\n", filesize); - if (!curclust) { - if (filesize) { - debug("error: nonempty clusterless file!\n"); + if (curclust) { + /* + * release already-allocated clusters anyway + */ + if (clear_fatent(mydata, curclust)) { + printf("Error: clearing FAT entries\n"); return -1; } - return 0; + } + + curclust = find_empty_cluster(mydata); + set_start_cluster(mydata, dentptr, curclust); + + if (check_overflow(mydata, curclust, filesize)) { + printf("Error: no space left: %llu\n", filesize); + return -1; } actsize = bytesperclust; @@ -568,6 +611,7 @@ set_contents(fsdata *mydata, dir_entry *dentptr, __u8 *buffer, newclust = determine_fatent(mydata, endclust); if ((newclust - 1) != endclust) + /* write to */ goto getit; if (CHECK_CLUST(newclust, mydata->fatsize)) { @@ -614,18 +658,8 @@ getit: actsize = bytesperclust; curclust = endclust = newclust; } while (1); -} -/* - * Set start cluster in directory entry - */ -static void set_start_cluster(const fsdata *mydata, dir_entry *dentptr, - __u32 start_cluster) -{ - if (mydata->fatsize == 32) - dentptr->starthi = - cpu_to_le16((start_cluster & 0xffff0000) >> 16); - dentptr->start = cpu_to_le16(start_cluster & 0xffff); + return 0; } /* @@ -642,31 +676,6 @@ static void fill_dentry(fsdata *mydata, dir_entry *dentptr, set_name(dentptr, filename); } -/* - * Check whether adding a file makes the file system to - * exceed the size of the block device - * Return -1 when overflow occurs, otherwise return 0 - */ -static int check_overflow(fsdata *mydata, __u32 clustnum, loff_t size) -{ - __u32 startsect, sect_num, offset; - - if (clustnum > 0) { - startsect = clust_to_sect(mydata, clustnum); - } else { - startsect = mydata->rootdir_sect; - } - - sect_num = div_u64_rem(size, mydata->sect_size, &offset); - - if (offset != 0) - sect_num++; - - if (startsect + sect_num > total_sector) - return -1; - return 0; -} - /* * Find a directory entry based on filename or start cluster number * If the directory entry is not found, @@ -784,11 +793,10 @@ static int normalize_longname(char *l_filename, const char *filename) return 0; } -static int do_fat_write(const char *filename, void *buffer, loff_t size, - loff_t *actwrite) +int file_fat_write_at(const char *filename, loff_t pos, void *buffer, + loff_t size, loff_t *actwrite) { dir_entry *retdent; - __u32 start_cluster; fsdata datablock = { .fatbuf = NULL, }; fsdata *mydata = &datablock; fat_itr *itr = NULL; @@ -796,6 +804,8 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, char *filename_copy, *parent, *basename; char l_filename[VFAT_MAXLEN_BYTES]; + debug("writing %s\n", filename); + filename_copy = strdup(filename); if (!filename_copy) return -ENOMEM; @@ -839,47 +849,8 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, goto exit; } - /* Update file size and start_cluster in a directory entry */ - retdent->size = cpu_to_le32(size); - start_cluster = START(retdent); - - if (start_cluster) { - if (size) { - ret = check_overflow(mydata, start_cluster, - size); - if (ret) { - printf("Error: %llu overflow\n", size); - ret = -ENOSPC; - goto exit; - } - } - - ret = clear_fatent(mydata, start_cluster); - if (ret) { - printf("Error: clearing FAT entries\n"); - ret = -EIO; - goto exit; - } - - if (!size) - set_start_cluster(mydata, retdent, 0); - } else if (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; - } - - set_start_cluster(mydata, retdent, start_cluster); - } + /* Update file size in a directory entry */ + retdent->size = cpu_to_le32(pos + size); } else { /* Create a new file */ @@ -907,32 +878,13 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, goto exit; } - if (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 { - start_cluster = 0; - } - /* Set attribute as archive for regular file */ - fill_dentry(itr->fsdata, itr->dent, filename, - start_cluster, size, 0x20); + fill_dentry(itr->fsdata, itr->dent, filename, 0, size, 0x20); retdent = itr->dent; } - ret = set_contents(mydata, retdent, buffer, size, actwrite); + ret = set_contents(mydata, retdent, pos, buffer, size, actwrite); if (ret < 0) { printf("Error: writing contents\n"); ret = -EIO; @@ -971,6 +923,5 @@ int file_fat_write(const char *filename, void *buffer, loff_t offset, return -EINVAL; } - printf("writing %s\n", filename); - return do_fat_write(filename, buffer, maxsize, actwrite); + return file_fat_write_at(filename, offset, buffer, maxsize, actwrite); } From patchwork Tue Sep 11 06:59:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 146409 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3316435ljw; Tue, 11 Sep 2018 00:06:32 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdb/Uuw0LNdjExO94qMeyWb0L9luuZANNunnSJ5ys1gbZOvGpm8SmY3cC8i9091ODnz8IxLq X-Received: by 2002:aa7:c441:: with SMTP id n1-v6mr26005828edr.55.1536649591951; Tue, 11 Sep 2018 00:06:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536649591; cv=none; d=google.com; s=arc-20160816; b=rVmop6aEzbhmNQCF26i0RjM84400K/cFJmFTGsvSttgOicsMS+eiCZZoQ95SB1Ad/+ SbKva5LrgMY9Us2O+koju8DnxCNoPmdOTuMwS133g3pLuHC6WD5t+4Q87BoIePa57p4K tUya9bdAC46g3pXCXmCb2Zwv1XBjXBi6sE1dCDHPhNdsRQ2o3gPnzmcoj3vLsAs+pd3f BjiQEsvYuzFgtGv2aukC36oFsPFHg4AAn1eJV8f2G0CSSGsFmofdC/W05X3VePNcuMHG /Xm3KuWL+7d+9qRhLzjiax2wlyjWgB+QEHvCHnrIjVEiX3ExOvEc7kv82aLcbSIIcWkm NZSw== 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=Ct99BLiCJieLrybxk3KjGFheYtGbcOoDzGlGG+dfDb8=; b=B0Q1in53GOWLHBxwRdF4TG6U4KXSzvXmMmH7F2UEChe8V1W+rVGulMyuEnSy0hD9LO mTlgZnioM7iqGVe/PW/2Hfg32eKzwh+rSxiiIUQC8QSXELXPlB2ltOh/Hc3DmdhchxR4 hUFed+lnpwGo2e8agif4w7GklinSGqyillaC/eD8BZAKbWOpH5vYr76HRGqem0RJ8TJu PwYbBOJ0UF3iSvNV0zyQ0E5OUdOZalM9pwRJTFdAGLqTdZ5eEUTKz6BubI8A47TuQA/n 80WFeZFgBmDRpsjuVulY7j+1Bp/Z15IHqFCGjb4dZuNeAbuqyWWzXIwkJ/1ez/GnbQcQ t5ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Xdt2mCKS; 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 k1-v6si7223669edf.127.2018.09.11.00.06.31; Tue, 11 Sep 2018 00:06:31 -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=Xdt2mCKS; 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 5A4C4C21E76; Tue, 11 Sep 2018 07:04:40 +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 670E5C21ECF; Tue, 11 Sep 2018 07:00:15 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 86A2BC21F13; Tue, 11 Sep 2018 06:59:48 +0000 (UTC) Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) by lists.denx.de (Postfix) with ESMTPS id 45249C21E77 for ; Tue, 11 Sep 2018 06:59:41 +0000 (UTC) Received: by mail-pg1-f194.google.com with SMTP id r1-v6so11735574pgp.11 for ; Mon, 10 Sep 2018 23:59:41 -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=zNRV+sAGYlpd4MCnwOpkz+vhTS1NAfDl0YaTIOD1cug=; b=Xdt2mCKS367V4uALrFoFpgPmAZpwS/LIKZn2qd5eQDlZ1nEHAEaStx9WxS9+23g/dq H8VR8EZ7+2qS5rsbRT6GeT8XjNtgu86qHJKqr7gUHc89+MZRC3g0qzM3wKpo2DUgKB3x KL3XUF+8DhPqeQuNyuggcYgra20PTN/NBOvAQ= 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=zNRV+sAGYlpd4MCnwOpkz+vhTS1NAfDl0YaTIOD1cug=; b=VxdbMqPM3yS20U7SnmjFPs+zd4jE2LpY+lY6HKpBZDCkZUvwF3FigZ4oHpBYEqzhmx r5LCRFmC8i7GP39r00kRPOyc5NHjZ4ZwTvdFBq0QJ+nILlhjiRIUATtpYSSfnqv7FSee YUbzELckXHfYfnEQwT1lXVcNuIP+CU6CP2ioDXMUB5ZWV8d4wjd+MKPIRm9NOxFmFF0y lXqg40DdhNGt7hCsKSgOcvpg42Me04gDT8LXa7BN03vpVwqHnPEfK70KeQ99MvnPsWtV S+L3CBgsafJboDmndInPSGAkQG+/c0cAchRu3S1lUBqK5r3Rafrv7AAU0A5qr67G3EuV 5yNQ== X-Gm-Message-State: APzg51BYlbRqpb1yMbuFtZt9uD4C5mSQuNkVVPPzbeuZbZL7+aCSd6yO ZzBeF3NQOpbYW/UVtCMACmsD/w== X-Received: by 2002:a62:6b49:: with SMTP id g70-v6mr27763488pfc.91.1536649179813; Mon, 10 Sep 2018 23:59:39 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id f186-v6sm18793426pgc.4.2018.09.10.23.59.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Sep 2018 23:59:39 -0700 (PDT) From: "Akashi, Takahiro" To: trini@konsulko.com Date: Tue, 11 Sep 2018 15:59:06 +0900 Message-Id: <20180911065922.19141-11-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 10/26] fs: fat: support write with non-zero offset 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 In this patch, all the necessary code for allowing for a file offset at write is implemented. What plays a major roll here is get_set_cluster(), which, in contrast to its counterpart, set_cluster(), only operates on already-allocated clusters, overwriting with data. So, with a file offset specified, set_contents() seeks and writes data with set_get_cluster() until the end of a file, and, once it reaches there, continues writing with set_cluster() for the rest. Please note that a file will be trimmed as a result of write operation if write ends before reaching file's end. This is an intended behavior in order to maintain compatibility with the current interface. Signed-off-by: AKASHI Takahiro --- fs/fat/fat_write.c | 288 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 273 insertions(+), 15 deletions(-) diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c index c22d8c7a46a1..651c7866debc 100644 --- a/fs/fat/fat_write.c +++ b/fs/fat/fat_write.c @@ -450,6 +450,121 @@ set_cluster(fsdata *mydata, __u32 clustnum, __u8 *buffer, return 0; } +static __u8 tmpbuf_cluster[MAX_CLUSTSIZE] __aligned(ARCH_DMA_MINALIGN); + +/* + * Read and modify data on existing and consecutive cluster blocks + */ +static int +get_set_cluster(fsdata *mydata, __u32 clustnum, loff_t pos, __u8 *buffer, + loff_t size, loff_t *gotsize) +{ + unsigned int bytesperclust = mydata->clust_size * mydata->sect_size; + __u32 startsect; + loff_t wsize; + int clustcount, i, ret; + + *gotsize = 0; + if (!size) + return 0; + + assert(pos < bytesperclust); + startsect = clust_to_sect(mydata, clustnum); + + debug("clustnum: %d, startsect: %d, pos: %lld\n", + clustnum, startsect, pos); + + /* partial write at beginning */ + if (pos) { + wsize = min(bytesperclust - pos, size); + ret = disk_read(startsect, mydata->clust_size, tmpbuf_cluster); + if (ret != mydata->clust_size) { + debug("Error reading data (got %d)\n", ret); + return -1; + } + + memcpy(tmpbuf_cluster + pos, buffer, wsize); + ret = disk_write(startsect, mydata->clust_size, tmpbuf_cluster); + if (ret != mydata->clust_size) { + debug("Error writing data (got %d)\n", ret); + return -1; + } + + size -= wsize; + buffer += wsize; + *gotsize += wsize; + + startsect += mydata->clust_size; + + if (!size) + return 0; + } + + /* full-cluster write */ + if (size >= bytesperclust) { + clustcount = lldiv(size, bytesperclust); + + if (!((unsigned long)buffer & (ARCH_DMA_MINALIGN - 1))) { + wsize = clustcount * bytesperclust; + ret = disk_write(startsect, + clustcount * mydata->clust_size, + buffer); + if (ret != clustcount * mydata->clust_size) { + debug("Error writing data (got %d)\n", ret); + return -1; + } + + size -= wsize; + buffer += wsize; + *gotsize += wsize; + + startsect += clustcount * mydata->clust_size; + } else { + for (i = 0; i < clustcount; i++) { + memcpy(tmpbuf_cluster, buffer, bytesperclust); + ret = disk_write(startsect, + mydata->clust_size, + tmpbuf_cluster); + if (ret != mydata->clust_size) { + debug("Error writing data (got %d)\n", + ret); + return -1; + } + + size -= bytesperclust; + buffer += bytesperclust; + *gotsize += bytesperclust; + + startsect += mydata->clust_size; + } + } + } + + /* partial write at end */ + if (size) { + wsize = size; + ret = disk_read(startsect, mydata->clust_size, tmpbuf_cluster); + if (ret != mydata->clust_size) { + debug("Error reading data (got %d)\n", ret); + return -1; + } + memcpy(tmpbuf_cluster, buffer, wsize); + ret = disk_write(startsect, mydata->clust_size, tmpbuf_cluster); + if (ret != mydata->clust_size) { + debug("Error writing data (got %d)\n", ret); + return -1; + } + + size -= wsize; + buffer += wsize; + *gotsize += wsize; + } + + assert(!size); + + return 0; +} + /* * Find the first empty cluster */ @@ -578,26 +693,158 @@ set_contents(fsdata *mydata, dir_entry *dentptr, loff_t pos, __u8 *buffer, unsigned int bytesperclust = mydata->clust_size * mydata->sect_size; __u32 curclust = START(dentptr); __u32 endclust = 0, newclust = 0; - loff_t actsize; + loff_t cur_pos, offset, actsize, wsize; *gotsize = 0; - filesize = maxsize; + filesize = pos + maxsize; debug("%llu bytes\n", filesize); - if (curclust) { - /* - * release already-allocated clusters anyway - */ - if (clear_fatent(mydata, curclust)) { - printf("Error: clearing FAT entries\n"); + if (!filesize) { + if (!curclust) + return 0; + if (!CHECK_CLUST(curclust, mydata->fatsize) || + IS_LAST_CLUST(curclust, mydata->fatsize)) { + clear_fatent(mydata, curclust); + set_start_cluster(mydata, dentptr, 0); + return 0; + } + debug("curclust: 0x%x\n", curclust); + debug("Invalid FAT entry\n"); + return -1; + } + + if (!curclust) { + assert(pos == 0); + goto set_clusters; + } + + /* go to cluster at pos */ + cur_pos = bytesperclust; + while (1) { + if (pos <= cur_pos) + break; + if (IS_LAST_CLUST(curclust, mydata->fatsize)) + break; + + newclust = get_fatent(mydata, curclust); + if (!IS_LAST_CLUST(newclust, mydata->fatsize) && + CHECK_CLUST(newclust, mydata->fatsize)) { + debug("curclust: 0x%x\n", curclust); + debug("Invalid FAT entry\n"); return -1; } + + cur_pos += bytesperclust; + curclust = newclust; + } + if (IS_LAST_CLUST(curclust, mydata->fatsize)) { + assert(pos == cur_pos); + goto set_clusters; } - curclust = find_empty_cluster(mydata); - set_start_cluster(mydata, dentptr, curclust); + assert(pos < cur_pos); + cur_pos -= bytesperclust; + /* overwrite */ + assert(IS_LAST_CLUST(curclust, mydata->fatsize) || + !CHECK_CLUST(curclust, mydata->fatsize)); + + while (1) { + /* search for allocated consecutive clusters */ + actsize = bytesperclust; + endclust = curclust; + while (1) { + if (filesize <= (cur_pos + actsize)) + break; + + newclust = get_fatent(mydata, endclust); + + if (IS_LAST_CLUST(newclust, mydata->fatsize)) + break; + if (CHECK_CLUST(newclust, mydata->fatsize)) { + debug("curclust: 0x%x\n", curclust); + debug("Invalid FAT entry\n"); + return -1; + } + + actsize += bytesperclust; + endclust = newclust; + } + + /* overwrite to */ + if (pos < cur_pos) + offset = 0; + else + offset = pos - cur_pos; + wsize = min(cur_pos + actsize, filesize) - pos; + if (get_set_cluster(mydata, curclust, offset, + buffer, wsize, &actsize)) { + printf("Error get-and-setting cluster\n"); + return -1; + } + buffer += wsize; + *gotsize += wsize; + cur_pos += offset + wsize; + + if (filesize <= cur_pos) + break; + + /* CHECK: newclust = get_fatent(mydata, endclust); */ + + if (IS_LAST_CLUST(newclust, mydata->fatsize)) + /* no more clusters */ + break; + + curclust = newclust; + } + + if (filesize <= cur_pos) { + /* no more write */ + newclust = get_fatent(mydata, endclust); + if (!IS_LAST_CLUST(newclust, mydata->fatsize)) { + /* truncate the rest */ + clear_fatent(mydata, newclust); + + /* Mark end of file in FAT */ + if (mydata->fatsize == 12) + newclust = 0xfff; + else if (mydata->fatsize == 16) + newclust = 0xffff; + else if (mydata->fatsize == 32) + newclust = 0xfffffff; + set_fatent_value(mydata, endclust, newclust); + } + + return 0; + } + + curclust = endclust; + filesize -= cur_pos; + assert(!(cur_pos % bytesperclust)); + +set_clusters: + /* allocate and write */ + assert(!pos); + + /* Assure that curclust is valid */ + if (!curclust) { + curclust = find_empty_cluster(mydata); + set_start_cluster(mydata, dentptr, curclust); + } else { + newclust = get_fatent(mydata, curclust); + + if (IS_LAST_CLUST(newclust, mydata->fatsize)) { + newclust = determine_fatent(mydata, curclust); + set_fatent_value(mydata, curclust, newclust); + curclust = newclust; + } else { + debug("error: something wrong\n"); + return -1; + } + } + + /* TODO: already partially written */ if (check_overflow(mydata, curclust, filesize)) { printf("Error: no space left: %llu\n", filesize); return -1; @@ -849,6 +1096,16 @@ int file_fat_write_at(const char *filename, loff_t pos, void *buffer, goto exit; } + /* A file exists */ + if (pos == -1) + /* Append to the end */ + pos = FAT2CPU32(retdent->size); + if (pos > retdent->size) { + /* No hole allowed */ + ret = -EINVAL; + goto exit; + } + /* Update file size in a directory entry */ retdent->size = cpu_to_le32(pos + size); } else { @@ -869,6 +1126,12 @@ int file_fat_write_at(const char *filename, loff_t pos, void *buffer, goto exit; } + if (pos) { + /* No hole allowed */ + ret = -EINVAL; + goto exit; + } + memset(itr->dent, 0, sizeof(*itr->dent)); /* Set short name to set alias checksum field in dir_slot */ @@ -918,10 +1181,5 @@ exit: int file_fat_write(const char *filename, void *buffer, loff_t offset, loff_t maxsize, loff_t *actwrite) { - if (offset != 0) { - printf("Error: non zero offset is currently not supported.\n"); - return -EINVAL; - } - return file_fat_write_at(filename, offset, buffer, maxsize, actwrite); } From patchwork Tue Sep 11 06:59:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 146410 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3318262ljw; Tue, 11 Sep 2018 00:08:42 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYpJOu39R7K3KHzJxt9u9xWo+dQaXMZ4n1NqeHHY1Ayhi4MwuUJAfRYh4jFniJVyZ3e7Muo X-Received: by 2002:a50:8b65:: with SMTP id l92-v6mr27115921edl.44.1536649722395; Tue, 11 Sep 2018 00:08:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536649722; cv=none; d=google.com; s=arc-20160816; b=RCc5cTOwwQ6lFMyS5EvtvAzVZ6y/OdjqvmX5vkroCHBnUOqS67JjYxya6dKnam4N+T e6QR8kN3u5cXhZfzVb6Zzmg4fU8hSFkbhJiHIHBCGFQbbB0e4cBkHB3lKWprjdOLnIEo fHNMkU0XYQjqoVnhRgkesycR2YJN+1CYF93DgO2VxJPCA05n47uQs0lkS2e9dE7Ud3f8 0YDZyDrLs5huQSirKGGUt3TWGxixvndzuMRTf9XCCoK/cXC/wEl+X37EfVPzLIeVNRyT 99cEK0k5brxUMYwAqJscBnbv9hBb31wNFLWFB1C9Rj/oSRJjL/sNr+Vd7fRvamVtIRHI RvCQ== 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=yriI+vRxf9WXzirczYqLujZ6Fc7F7vfUaZ4WCW0yY4E=; b=VcU/NUWJpbPM3ZmpkaSkMkeY29+VzsczFmvKRYK3mjxVlf8vP6cUhd23aPXG3e6cRh UQFN4uUc3nx2WZU5/2zfr/U93CWJ8QH20iNPI+R0J1tU4hEu9QCRREjFUT+ukTuxMI1o fFJiOdo/aKLoXsnIZ+ESh5P1rcytl3sS3l53DFQ4GSFsHGEA+M6vxRTLmGYwOpPEXKF5 2LcXTgjsytGQEnvLL8LQ1G/p1D07Vo9kOEAvK8wBSWHwVYZoWvoyUKdhQh39YGByU4yr Jh5AEfX00/wbSvz4ZOfJJ5uuAWmwCVh1NUqpEzT7p/LoTbLG5i6DVqeS9dWV5OfuHjBG N0Xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=SpOOoJdE; 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 j3-v6si6472738edh.183.2018.09.11.00.08.42; Tue, 11 Sep 2018 00:08:42 -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=SpOOoJdE; 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 CDCF9C21E75; Tue, 11 Sep 2018 07:04:13 +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 9402AC21EBB; Tue, 11 Sep 2018 07:00:14 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 4328BC21F13; Tue, 11 Sep 2018 06:59:55 +0000 (UTC) Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) by lists.denx.de (Postfix) with ESMTPS id A61C6C21E52 for ; Tue, 11 Sep 2018 06:59:47 +0000 (UTC) Received: by mail-pg1-f196.google.com with SMTP id d19-v6so11766917pgv.1 for ; Mon, 10 Sep 2018 23:59:47 -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=MZY5qHI+Lk5hLrjvrMRhBcO625AKCyNEKJYLQg7vrps=; b=SpOOoJdEjx1R/QIadMF2w/jAh/6vgAm1VgihMtCgOoqMUsMk873Wsmx/E/HoY15HWh 8bOIM1ZjmAKL7estyTGkWPZGWzeKuuWLXYwl3Heyj4s8OyHca6e9bybxOOUsbbrtknOx PIs3J5H+ZLFnY/fDz4nAxwLrMq4WRcFnWlZ2U= 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=MZY5qHI+Lk5hLrjvrMRhBcO625AKCyNEKJYLQg7vrps=; b=nt0JxAWEnGOrhcm1LkIBgApx+OJUBZwb1EYmtFTeIOWiMI29JvpHPUuAZcC26qevE1 sp/OsPw/VXOJKdqIjaNew9g+QTBHmhD/Ufq5d0rkwKPANGMj7oQRaSZc0JySrwcvPav3 HgU4CiNKL5Usc1nEXSnfIeYZWN6dXurLs28iGaKq2qkKe09NdTw+oCaHLl1XnWp+bgvO mT2lQ5Rie9guq1jfLc5JMWRj1FSdvhLMhkDi6ljQzI5FN9Tdil4nIpNLC2RUz1rTQQrg 8JB4Yg35okh11n9AvH+imDcDg1n0vHlj8iDv27OfglKsASMSM53k7NJgEUO03Vg/A5Iv n0Ww== X-Gm-Message-State: APzg51Cr0qhREWojd1qwV6uw+jPPpX9sNEk9ZmfTVmcFk+IvfwhVZQAW 6nEVxJ8TJ0uBqjnORlVFrHBEuw== X-Received: by 2002:a62:9894:: with SMTP id d20-v6mr27790560pfk.186.1536649183602; Mon, 10 Sep 2018 23:59:43 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id 22-v6sm27180185pfl.126.2018.09.10.23.59.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Sep 2018 23:59:42 -0700 (PDT) From: "Akashi, Takahiro" To: trini@konsulko.com Date: Tue, 11 Sep 2018 15:59:07 +0900 Message-Id: <20180911065922.19141-12-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 11/26] cmd: fat: add offset parameter to fatwrite 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 In this patch, fatwrite command is extended so as to accept an additional parameter of file offset. Signed-off-by: AKASHI Takahiro --- cmd/fat.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cmd/fat.c b/cmd/fat.c index 03de5d11afb4..2a5f7bfc2690 100644 --- a/cmd/fat.c +++ b/cmd/fat.c @@ -104,6 +104,7 @@ static int do_fat_fswrite(cmd_tbl_t *cmdtp, int flag, int ret; unsigned long addr; unsigned long count; + long offset; struct blk_desc *dev_desc = NULL; disk_partition_t info; int dev = 0; @@ -126,9 +127,11 @@ static int do_fat_fswrite(cmd_tbl_t *cmdtp, int flag, } addr = simple_strtoul(argv[3], NULL, 16); count = (argc <= 5) ? 0 : simple_strtoul(argv[5], NULL, 16); + /* offset should be a hex, but "-1" is allowed */ + offset = (argc <= 6) ? 0 : simple_strtol(argv[6], NULL, 16); buf = map_sysmem(addr, count); - ret = file_fat_write(argv[4], buf, 0, count, &size); + ret = file_fat_write(argv[4], buf, offset, count, &size); unmap_sysmem(buf); if (ret < 0) { printf("\n** Unable to write \"%s\" from %s %d:%d **\n", @@ -142,9 +145,9 @@ static int do_fat_fswrite(cmd_tbl_t *cmdtp, int flag, } U_BOOT_CMD( - fatwrite, 6, 0, do_fat_fswrite, + fatwrite, 7, 0, do_fat_fswrite, "write file into a dos filesystem", - " []\n" + " [ []]\n" " - write file 'filename' from the address 'addr' in RAM\n" " to 'dev' on 'interface'" ); From patchwork Tue Sep 11 06:59:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 146404 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3314449ljw; Tue, 11 Sep 2018 00:04:04 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYNYms4n7SIdSn1rWirO6VNrReS28WekudICtlExCwtOaV4yK2vnJU0Ab16c+piGhmrInuu X-Received: by 2002:a50:af03:: with SMTP id g3-v6mr27893923edd.220.1536649444621; Tue, 11 Sep 2018 00:04:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536649444; cv=none; d=google.com; s=arc-20160816; b=iGUcSo8IGMIUB4r2vDLW8dOUx6pB9DFe4YogZ6wJvUfs85wmCm0Fl+UKyi5HEEmarQ KF78nqxU6Lm/kBxS2sEVZyXNUrFVvQIohV9jTgm/irjL0Dv9Ne07TeFos1uDFWIFEXoT uyCoz/81djpimKELoWFTp2HqjE92gpumwYwZKUZf5JX+V7tRfa3lTEksBC+mofgrBpv9 JQZNOW2nk9S9gjEBeVyJw97T0E3V3SHDgdmgYjTpY0E9eNBe01kx6pPgR/M08ZTmQlAm mAG4S0ua0imLbh0Yh1AOBZlLUCUN+oIJ2tEvRxuqSaa0kXxdJhsGF3VE9E8ZROFw7r3u agSg== 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=/81ZOFY9U7yFQ3Cdf0+/xzBa0GR8zUwPHibd0ViQhpw=; b=MtjDTFgqQEPfttW3VyeJ/Ht419VOmHSTAecNLjS9bndLsTpepC5O+cmm0QP5MFiZKs uDJe3cxW18z589HtvDZebqcdZH9swZg/mFipBdB23/jCzmNOiPgZqw4Oa9b/JwkPSeoU UfX0wm+OF3oRQAlxULsLaEZXce3RVGjRJ4l46A6y5O128WpRs0rqQ+c4Y5LxOn/bv53z +SsUG8QQhuRBas5qbAXcPU83XqnCxX49lieG6X6aPUFw5ULT/J+O5ofv02A6JaL48lG8 E3OEWSRH5KF/uwCJ1zaCnp8m42p2FlLWZThy3jtlcQkyOZVE2h0p72r+Ht28xk+EblNV NeHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=h81WQ6fQ; 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 l8-v6si1726864edb.116.2018.09.11.00.04.04; Tue, 11 Sep 2018 00:04:04 -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=h81WQ6fQ; 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 CE54CC21E62; Tue, 11 Sep 2018 07:02:22 +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 35454C21E7F; Tue, 11 Sep 2018 06:59:59 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id D45CCC21E1A; Tue, 11 Sep 2018 06:59:55 +0000 (UTC) Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) by lists.denx.de (Postfix) with ESMTPS id 84467C21E89 for ; Tue, 11 Sep 2018 06:59:49 +0000 (UTC) Received: by mail-pf1-f196.google.com with SMTP id j8-v6so11740745pff.6 for ; Mon, 10 Sep 2018 23:59:49 -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=AqztbRLDhZ6l8EEhvFlCJvPn1sueBHj4bIuWqsVulIU=; b=h81WQ6fQZKVJtr29NpvuqmDNqzSgJt09h0AAJRkS2A070SLHuUDYedK9TE1C+UrqQh hEl7zSVYsxWm85RkYHMsrH8X0t/WHIIWWFSnmkFMqvldseeIGtN/Uy6altpo/vHWww3W EYBMoj7awwBZ5oYa87ne5s28aaDnSne/ceQic= 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=AqztbRLDhZ6l8EEhvFlCJvPn1sueBHj4bIuWqsVulIU=; b=qHxv6PQ8IUOiysWa2hOMd2oQzauZsc/+WesNvls+H8dpHWiLs+WozJ1bNXJX3Zykxt FvPsM/W2+nUqirV1oeAYGLl1Nmvx0N/DpYEKHYHq49/OpoGXddIRamtmM06gsOq/2/+m k6CuxyY+i4bZIVWzDUfrLMuVX/LyB4cnh3s6BP+/m4072T27CvxfSwqwrXf7LuULG7/d lVqnPmuwqinMjdCm2U+m4/De2gkdZslznIiK3cmy8PHYzUq/i1GA+Dgj1d/CjwL5lgp7 mquJXbVLQU8W5u0mpPi76qf/zT2s26U2qtUxg1TVsCBHvZ2bLGPTIvJaDQ7+63F5p1KH DMFA== X-Gm-Message-State: APzg51BNhwSYdof1i6Zk+HG16j7/lt7he+sV8bGCbUnb1ytumzwrk23K GDqOU9APtAUeVmZ0jnJsc/r+ig== X-Received: by 2002:a63:f111:: with SMTP id f17-v6mr25935109pgi.87.1536649188076; Mon, 10 Sep 2018 23:59:48 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id 9-v6sm30006855pfc.20.2018.09.10.23.59.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Sep 2018 23:59:46 -0700 (PDT) From: "Akashi, Takahiro" To: trini@konsulko.com Date: Tue, 11 Sep 2018 15:59:08 +0900 Message-Id: <20180911065922.19141-13-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 12/26] fs: add mkdir interface 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 "mkdir" interface is added to file operations. This is a preparatory change as mkdir support for FAT file system will be added in next patch. Signed-off-by: AKASHI Takahiro --- fs/fs.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ include/fs.h | 10 ++++++++++ 2 files changed, 55 insertions(+) diff --git a/fs/fs.c b/fs/fs.c index cb68e81cd309..62165d5c5701 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -105,6 +105,11 @@ static inline int fs_opendir_unsupported(const char *filename, return -EACCES; } +static inline int fs_mkdir_unsupported(const char *dirname) +{ + return -1; +} + struct fstype_info { int fstype; char *name; @@ -142,6 +147,7 @@ struct fstype_info { int (*readdir)(struct fs_dir_stream *dirs, struct fs_dirent **dentp); /* see fs_closedir() */ void (*closedir)(struct fs_dir_stream *dirs); + int (*mkdir)(const char *dirname); }; static struct fstype_info fstypes[] = { @@ -165,6 +171,7 @@ static struct fstype_info fstypes[] = { .opendir = fat_opendir, .readdir = fat_readdir, .closedir = fat_closedir, + .mkdir = fs_mkdir_unsupported, }, #endif #ifdef CONFIG_FS_EXT4 @@ -185,6 +192,7 @@ static struct fstype_info fstypes[] = { #endif .uuid = ext4fs_uuid, .opendir = fs_opendir_unsupported, + .mkdir = fs_mkdir_unsupported, }, #endif #ifdef CONFIG_SANDBOX @@ -201,6 +209,7 @@ static struct fstype_info fstypes[] = { .write = fs_write_sandbox, .uuid = fs_uuid_unsupported, .opendir = fs_opendir_unsupported, + .mkdir = fs_mkdir_unsupported, }, #endif #ifdef CONFIG_CMD_UBIFS @@ -217,6 +226,7 @@ static struct fstype_info fstypes[] = { .write = fs_write_unsupported, .uuid = fs_uuid_unsupported, .opendir = fs_opendir_unsupported, + .mkdir = fs_mkdir_unsupported, }, #endif #ifdef CONFIG_FS_BTRFS @@ -233,6 +243,7 @@ static struct fstype_info fstypes[] = { .write = fs_write_unsupported, .uuid = btrfs_uuid, .opendir = fs_opendir_unsupported, + .mkdir = fs_mkdir_unsupported, }, #endif { @@ -248,6 +259,7 @@ static struct fstype_info fstypes[] = { .write = fs_write_unsupported, .uuid = fs_uuid_unsupported, .opendir = fs_opendir_unsupported, + .mkdir = fs_mkdir_unsupported, }, }; @@ -498,6 +510,20 @@ void fs_closedir(struct fs_dir_stream *dirs) } +int fs_mkdir(const char *dirname) +{ + int ret; + + struct fstype_info *info = fs_get_info(fs_type); + + ret = info->mkdir(dirname); + + fs_type = FS_TYPE_ANY; + fs_close(); + + return ret; +} + int do_size(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], int fstype) { @@ -700,3 +726,22 @@ int do_fs_type(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) return CMD_RET_SUCCESS; } +int do_mkdir(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], + int fstype) +{ + int ret; + + if (argc != 4) + return CMD_RET_USAGE; + + if (fs_set_blk_dev(argv[1], argv[2], fstype)) + return 1; + + ret = fs_mkdir(argv[3]); + if (ret) { + printf("** Unable to create a directory \"%s\" **\n", argv[3]); + return 1; + } + + return 0; +} diff --git a/include/fs.h b/include/fs.h index 163da103b472..fbaee154dd0d 100644 --- a/include/fs.h +++ b/include/fs.h @@ -155,6 +155,14 @@ struct fs_dirent *fs_readdir(struct fs_dir_stream *dirs); */ void fs_closedir(struct fs_dir_stream *dirs); +/* + * fs_mkdir - Create a directory + * + * @filename: Name of directory to create + * @return 0 on success, -1 on error conditions + */ +int fs_mkdir(const char *filename); + /* * Common implementation for various filesystem commands, optionally limited * to a specific filesystem type via the fstype parameter. @@ -169,6 +177,8 @@ int file_exists(const char *dev_type, const char *dev_part, const char *file, int fstype); int do_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], int fstype); +int do_mkdir(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], + int fstype); /* * Determine the UUID of the specified filesystem and print it. Optionally it is From patchwork Tue Sep 11 06:59:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 146411 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3318568ljw; Tue, 11 Sep 2018 00:08:59 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdbf4NzWeprTqbZyRSCkqrRcbip/2kt39wTTseGA3O6LUFbJN03vinw/J9M86idkh6PhvDBJ X-Received: by 2002:a50:8dcb:: with SMTP id s11-v6mr26961716edh.86.1536649739347; Tue, 11 Sep 2018 00:08:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536649739; cv=none; d=google.com; s=arc-20160816; b=hbYzhLXH7czhLzSouW/Ed1P0/omTzY4/HTJI+LtKi2TtqknqKU9UVjY3/rUSB5Ye60 szPBqETcFR/NwNVwv3dYysrPPKZwxNC3/I6AdQV5AvgDayCxBt1FZLT4eRse5CfqgyxV Jk9KjrhsJrsV1DnO6CParTxYZed5VNxP85P+uDQDOeL3l5H/inpIrTsFdq+X2JOC/6Qy wxk4T4dnm1DbUokYb3ErVdsZMzCC5YHk0bDJZAmjNmYICK7cBCl53p8xwVa+FzH9tsHu 3Q2ilep2CBL2F/U2SHB8QNjNKv41B4AROGw4VOtMqdo8tKvCIK0ztxiVLlJX1lwffSrk u6Cg== 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=NvFsatuTR0x63lNbHP5kBahBfki6Gl8FJtk+AR1kmyg=; b=I+Ry6YynashLNRtBai4+HqjS42wlHSK9g9ZkMwOeCjBah5etXRUyqOKRYY/bhioJXu YCtG3OPzut9glOglAckaNN+bvHzBNDtI6lnG+YCkSw+ohxcuWxICblHWA3S5DssDb4U3 CY/hINZwxqGBWBZPEyl7z7IQtKcORsUdi9PiCJWV0ydIWeEoOlpRrm15gc5b77Tq6aLk gULU43ymI3AydD7DYYhnvltUt18gD5zJ7q6zIw0vHXuRHIHIsSxUTuWvmvQQZD0+EScJ Zc6f2wln72CcK5pHjh1nsLU6Fh5OP7uY1Nn0E8LDZ3ElePf2AEk36gHLw72Hc7wQH1XF 9AMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=bXWNhjtE; 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 l21-v6si7767038edr.310.2018.09.11.00.08.59; Tue, 11 Sep 2018 00:08:59 -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=bXWNhjtE; 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 DB377C21E89; Tue, 11 Sep 2018 07:05:11 +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 4CD63C21E75; Tue, 11 Sep 2018 07:00:38 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 4B035C21E90; Tue, 11 Sep 2018 06:59:58 +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 23972C21EEB for ; Tue, 11 Sep 2018 06:59:53 +0000 (UTC) Received: by mail-pg1-f195.google.com with SMTP id b129-v6so11732895pga.13 for ; Mon, 10 Sep 2018 23:59:53 -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=wXq93k54/Qh9tf236I4soQCnb40ier46I9ZQ615Gzlk=; b=bXWNhjtEhayaKzm+xg4eHH5J3/5coX5MVX9QgY1PblHMOItqBTc0dYT4LIRDiejtaY Mpo+wzrpllNf88K08TJhf/z3KtRe3bhwy5Zmaulx48Tkfnp/LrM4QkbTWTsv0B5eVkI/ GXFdO/4smEVhUb9yfdoPukiHZH5jOT6L+Y+FI= 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=wXq93k54/Qh9tf236I4soQCnb40ier46I9ZQ615Gzlk=; b=U9hSMMFSoUKjMc2UISZ8F6BKtSRDEwHm0mGaubnazykgBQSj8AB/fsyjKboCm/vmlM cMUIU+XEGG0vuhSymSemvb3xQNaoFLojVHUMGTU+EAq/k5MvMlmo5ibh24A7+UzCKyxF GaqNjMMp/oILo+PWPQGHJGhev5UTd3ZPlxnkIm9hcpuCofNzYSFHDCvst8Iw98Ou4V/B tuuwD3LY5sMX+U6+7E1iOjM/Xwjw2bcz+Auyptvr3NpHfq4Rio7yTOagz6nx0/POofm0 8+KxCJZSm55+XJcDfBA5MrsckFB+nDTErg8H1T48u8vgvRqXpWBhm0l1qKuqDXBnoUiT m9WA== X-Gm-Message-State: APzg51DRlW1rwsLCQROg3FlJnxU6hygLaGxko82504D1t7xadsyijLe3 mxytKnlTHMwuf7MI3hXOxcBrOw== X-Received: by 2002:a62:c218:: with SMTP id l24-v6mr27707583pfg.185.1536649191733; Mon, 10 Sep 2018 23:59:51 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id e64-v6sm25589237pfk.87.2018.09.10.23.59.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Sep 2018 23:59:51 -0700 (PDT) From: "Akashi, Takahiro" To: trini@konsulko.com Date: Tue, 11 Sep 2018 15:59:09 +0900 Message-Id: <20180911065922.19141-14-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 13/26] fs: fat: remember the starting cluster number of directory 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 The starting cluster number of directory is needed to initialize ".." (parent directory) entry when creating a new directory. Signed-off-by: AKASHI Takahiro --- fs/fat/fat.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/fat/fat.c b/fs/fat/fat.c index 5aa28656c7d5..10741925bdd4 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -631,6 +631,7 @@ static int get_fs_info(fsdata *mydata) typedef struct { fsdata *fsdata; /* filesystem parameters */ + unsigned start_clust; /* first cluster */ unsigned clust; /* current cluster */ unsigned next_clust; /* next cluster if remaining == 0 */ int last_cluster; /* set once we've read last cluster */ @@ -663,6 +664,7 @@ static int fat_itr_root(fat_itr *itr, fsdata *fsdata) return -ENXIO; itr->fsdata = fsdata; + itr->start_clust = 0; itr->clust = fsdata->root_cluster; itr->next_clust = fsdata->root_cluster; itr->dent = NULL; @@ -698,6 +700,7 @@ static void fat_itr_child(fat_itr *itr, fat_itr *parent) assert(fat_itr_isdir(parent)); itr->fsdata = parent->fsdata; + itr->start_clust = clustnum; if (clustnum > 0) { itr->clust = clustnum; itr->next_clust = clustnum; From patchwork Tue Sep 11 06:59:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 146418 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3321757ljw; Tue, 11 Sep 2018 00:12:46 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbOmoBhopPp2TE/DIkA1T+96rmUzh5yPDwUd7cCsYXf4I5aS4acGToDPjX3QfJ+L6TXQf3p X-Received: by 2002:a50:ae03:: with SMTP id c3-v6mr27118340edd.114.1536649966349; Tue, 11 Sep 2018 00:12:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536649966; cv=none; d=google.com; s=arc-20160816; b=xjPcOx6WMZYNId5cCA1Bm5p8xFpf5h08q+Lxmn3qkq96uCjcOtm2LqMCBeLusAUhe/ srfa5Mu7a3MhHmE73XOSjtd0uF2uBEjdzfUsUjXhsjpbLgmw0oA/Sar/JFEsY9z43QxI oiplMB5gIr5jPbO4qYQGlW5mUen96fg+Fgsmjn3y1YbQRFaH3kvdMtIPCFffA8RKentp AAz7t2lEqqD97UVl4KkmQuUt2D7bK4KuNzsf31LJYD3l2Xsu+GBGUCigkpixck3EB5TZ Sl1Pjq1+qCL+qhmjNw+BeW5zOyXR7QzVpUqGuu6EyVC8AeFp3Aqyn/C6MfaH1NwVwm8E 4C1Q== 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=LacOXEnvvUjh2NI/UhmWCXdGxOsgDU8FjqMkSAlnsQM=; b=gePTYV1UAnT6cwVBMg9qEqjNBMlO/79iQbVqxE/VKON24vp3Iw/fdDRwkZ6NYjzHdB 2U+U4S+Ood9fdyyChiC/jNMlCzsb8mpte1yc/6ePUgEIh85amIQl37Vebiw7RGYy58Qa lLaIpsa4fCRCMPso6Mrpd5SOO36BXBPYnigI7tyiAmotoYxmW3wjutIgnGnAXzbWwovF Rg50fSAJhcGWpLaOzgIrygM08SE59AfJ9q6M+ev/ovnz6Asq4r+IlCST3Ma+3LqJGlDm G6TVxz9VodT/AixkbLz70EWE7Z4iBy1v0Iboagv4InqwdpRG5wBL0qaonznZbaoFQXaQ 1uKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=f5cgcMvv; 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 n4-v6si990195eda.62.2018.09.11.00.12.46; Tue, 11 Sep 2018 00:12:46 -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=f5cgcMvv; 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 C7039C21EF7; Tue, 11 Sep 2018 07:07:18 +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 D383AC21F27; Tue, 11 Sep 2018 07:01:09 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 3EA3EC21E38; Tue, 11 Sep 2018 07:00:01 +0000 (UTC) Received: from mail-pf1-f193.google.com (mail-pf1-f193.google.com [209.85.210.193]) by lists.denx.de (Postfix) with ESMTPS id D3F30C21ECA for ; Tue, 11 Sep 2018 06:59:56 +0000 (UTC) Received: by mail-pf1-f193.google.com with SMTP id j26-v6so11734571pfi.10 for ; Mon, 10 Sep 2018 23:59:56 -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=YhoD+noqvIgNmZenXk13qZKT62iVkeAGtESN5aQgv+Y=; b=f5cgcMvv+Fyl6Yhsh6vMZqRUm1wn8ze0AB/xNXK9WnXa7zlddu6irDAhB0Kd1LtfoB /7OHZCSBsyARDCYAw0bisUjIqJ9hM28sK8h9q4Msmo5X1XETWy7O5qD02M6gUMuaJWPH AfRoNs9FmOcORdSzqxEqewMrp5+EN15vt4g8E= 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=YhoD+noqvIgNmZenXk13qZKT62iVkeAGtESN5aQgv+Y=; b=mU1NJ2x7DjWVE5/n7TZp6Tff999XjkSlAXXUkU4QpklMnTerdx1RvIGrfX4SkthzP0 9rP+enJaYSOzSudT/Yh0g2qC8YM3fGPK3ck2YXdrs69mudwISrgAll8hHqUNs5PJKOZR PNB/X2DeOC3534lQfIC+9ivsOjhG2Pv7dRqRDi4BV+pBuWBMiAGNGbDOld/nJfk1stcz imNuH2yOYMP7NXbAYAdAnI/jtT2Ku6NOrKe62lx9JAQbHms4bzzYVPeXmGLlaw73JsK3 3Pu9A19nhtl6FuW8yxMTwdC/8oYuspZH8iEWUvsb86W+560ydvy0CiB/jtLDBXga48FT a5Ow== X-Gm-Message-State: APzg51CY5Uaoex6OLJWO66tzB0tVHmEDub1u5qn1UnKGFDnrGhLVQlbv FbdffISvojpX2RnDbXLZsTVD1Q== X-Received: by 2002:aa7:800f:: with SMTP id j15-v6mr27840020pfi.174.1536649195471; Mon, 10 Sep 2018 23:59:55 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id 143-v6sm27074993pfy.156.2018.09.10.23.59.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Sep 2018 23:59:54 -0700 (PDT) From: "Akashi, Takahiro" To: trini@konsulko.com Date: Tue, 11 Sep 2018 15:59:10 +0900 Message-Id: <20180911065922.19141-15-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 14/26] fs: fat: support mkdir 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 In this patch, mkdir support is added to FAT file system. A newly created directory contains only "." and ".." entries. Signed-off-by: AKASHI Takahiro --- fs/fat/fat_write.c | 136 +++++++++++++++++++++++++++++++++++++++++++++ fs/fs.c | 3 +- include/fat.h | 1 + 3 files changed, 139 insertions(+), 1 deletion(-) diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c index 651c7866debc..035469f31c8d 100644 --- a/fs/fat/fat_write.c +++ b/fs/fat/fat_write.c @@ -1183,3 +1183,139 @@ int file_fat_write(const char *filename, void *buffer, loff_t offset, { return file_fat_write_at(filename, offset, buffer, maxsize, actwrite); } + +int fat_mkdir(const char *new_dirname) +{ + dir_entry *retdent; + fsdata datablock = { .fatbuf = NULL, }; + fsdata *mydata = &datablock; + fat_itr *itr = NULL; + char *dirname_copy, *parent, *dirname; + char l_dirname[VFAT_MAXLEN_BYTES]; + int ret = -1; + loff_t actwrite; + unsigned int bytesperclust; + dir_entry *dotdent = NULL; + + dirname_copy = strdup(new_dirname); + if (!dirname_copy) + goto exit; + + split_filename(dirname_copy, &parent, &dirname); + if (!strlen(dirname)) { + ret = -EINVAL; + goto exit; + } + + if (normalize_longname(l_dirname, dirname)) { + printf("FAT: illegal filename (%s)\n", dirname); + ret = -EINVAL; + goto exit; + } + + itr = malloc_cache_aligned(sizeof(fat_itr)); + if (!itr) { + ret = -ENOMEM; + goto exit; + } + + ret = fat_itr_root(itr, &datablock); + if (ret) + goto exit; + + total_sector = datablock.total_sect; + + ret = fat_itr_resolve(itr, parent, TYPE_DIR); + if (ret) { + printf("%s: doesn't exist (%d)\n", parent, ret); + goto exit; + } + + retdent = find_directory_entry(itr, l_dirname); + + if (retdent) { + printf("%s: already exists\n", l_dirname); + ret = -EEXIST; + goto exit; + } else { + if (itr->is_root) { + /* root dir cannot have "." or ".." */ + if (!strcmp(l_dirname, ".") || + !strcmp(l_dirname, "..")) { + ret = -EINVAL; + goto exit; + } + } + + if (!itr->dent) { + printf("Error: allocating new dir entry\n"); + ret = -EIO; + goto exit; + } + + memset(itr->dent, 0, sizeof(*itr->dent)); + + /* Set short name to set alias checksum field in dir_slot */ + set_name(itr->dent, dirname); + fill_dir_slot(itr, dirname); + + /* Set attribute as archive for regular file */ + fill_dentry(itr->fsdata, itr->dent, dirname, 0, 0, + ATTR_DIR | ATTR_ARCH); + + retdent = itr->dent; + } + + /* Default entries */ + bytesperclust = mydata->clust_size * mydata->sect_size; + dotdent = malloc_cache_aligned(bytesperclust); + if (!dotdent) { + ret = -ENOMEM; + goto exit; + } + memset(dotdent, 0, bytesperclust); + + memcpy(dotdent[0].name, ". ", 8); + memcpy(dotdent[0].ext, " ", 3); + dotdent[0].attr = ATTR_DIR | ATTR_ARCH; + + memcpy(dotdent[1].name, ".. ", 8); + memcpy(dotdent[1].ext, " ", 3); + dotdent[1].attr = ATTR_DIR | ATTR_ARCH; + set_start_cluster(mydata, &dotdent[1], itr->start_clust); + + ret = set_contents(mydata, retdent, 0, (__u8 *)dotdent, + bytesperclust, &actwrite); + if (ret < 0) { + printf("Error: writing contents\n"); + goto exit; + } + /* Write twice for "." */ + set_start_cluster(mydata, &dotdent[0], START(retdent)); + ret = set_contents(mydata, retdent, 0, (__u8 *)dotdent, + bytesperclust, &actwrite); + if (ret < 0) { + printf("Error: writing contents\n"); + goto exit; + } + + /* Flush fat buffer */ + ret = flush_dirty_fat_buffer(mydata); + if (ret) { + printf("Error: flush fat buffer\n"); + goto exit; + } + + /* Write directory table to device */ + ret = set_cluster(mydata, itr->clust, itr->block, + mydata->clust_size * mydata->sect_size); + if (ret) + printf("Error: writing directory entry\n"); + +exit: + free(dirname_copy); + free(mydata->fatbuf); + free(itr); + free(dotdent); + return ret; +} diff --git a/fs/fs.c b/fs/fs.c index 62165d5c5701..099540f38a10 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -164,14 +164,15 @@ static struct fstype_info fstypes[] = { .read = fat_read_file, #ifdef CONFIG_FAT_WRITE .write = file_fat_write, + .mkdir = fat_mkdir, #else .write = fs_write_unsupported, + .mkdir = fs_mkdir_unsupported, #endif .uuid = fs_uuid_unsupported, .opendir = fat_opendir, .readdir = fat_readdir, .closedir = fat_closedir, - .mkdir = fs_mkdir_unsupported, }, #endif #ifdef CONFIG_FS_EXT4 diff --git a/include/fat.h b/include/fat.h index 127e6622a9b0..97460a3cdff1 100644 --- a/include/fat.h +++ b/include/fat.h @@ -205,6 +205,7 @@ int fat_read_file(const char *filename, void *buf, loff_t offset, loff_t len, int fat_opendir(const char *filename, struct fs_dir_stream **dirsp); int fat_readdir(struct fs_dir_stream *dirs, struct fs_dirent **dentp); void fat_closedir(struct fs_dir_stream *dirs); +int fat_mkdir(const char *dirname); void fat_close(void); #endif /* CONFIG_FS_FAT */ #endif /* _FAT_H_ */ From patchwork Tue Sep 11 06:59:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 146413 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3319627ljw; Tue, 11 Sep 2018 00:10:15 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbO96pSK4fLPtL8+83XlBAaITsWOTCcbZvl29kja7zbLnlDt6d/ydwC1bqsDbB+RHTLle8M X-Received: by 2002:a50:cf42:: with SMTP id d2-v6mr27537945edk.242.1536649815775; Tue, 11 Sep 2018 00:10:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536649815; cv=none; d=google.com; s=arc-20160816; b=SSzWP2+n4mBx/8WVhkla/pxRFquecxG2UCF9G0nA/wQMbP1ScWWgD1gmXoQo6S9rP3 lBTxQW1d13nJflUOeraNuSyoMrYg0D8JAOIdCdVCcfN1rHZVCjlgJ+2l6XqYaPLnTB1g txAV3JqYY/OxDp6s6dbv0kKYVqcZQHHtlfDIhDMIDGTQ7raMHWAc+P6zp/pkxnONVo9g Y81r8RP1wiR6C2r2j8brpLnqmu88ooObVWpWCBABYDqOVBNWqk/o1qyxumRDxMFNfkho cwHlzwXs6bamYgmllaqL7CnjaTL3UZk0I/Rr4En3PrNK+VtTtBsGf7aJJcpPimxEAxFj r1wA== 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=SCAz4Do97pMJ4kNLSCKJ7edKRwp4NgRvdMb8Br2XmIc=; b=CNR0voWSSmMAkidLL1KaDbKfdKtF3CyY+sMVzP+88K5xZBNcVetq9DdWgBWPA9yieC L4WwXCkVHV6d9UvyXptQmWT4OP9PasrCIWc4qpN6qMlE/6TgFfGmUasxsAd+aM6g+eja KKH3EJH+xu2x1vuEgGgY5IzN3gJP462u+eGfZZkRcNv9BfLOm3bPS9gsNaDtE6fapYn8 LJ2rHJykkKGCurzBvl+X+YOU+KlkKBzaNv965T51ixLom1T5Vs0O9gEq5Sb6Wmd0j/FJ 3uT3iyXNrpqeyWZJiDUP5jnRt9iAd9Qs8/tfVF5JeeTPK1BJTkyDxHBwKEi5LN+VYS/H SD6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Vlv7LspI; 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 h25-v6si864124edb.423.2018.09.11.00.10.15; Tue, 11 Sep 2018 00:10:15 -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=Vlv7LspI; 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 D83C2C21EBE; Tue, 11 Sep 2018 07:08:10 +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 06605C21E1E; Tue, 11 Sep 2018 07:01:25 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 2E5F6C21E1E; Tue, 11 Sep 2018 07:00:07 +0000 (UTC) Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) by lists.denx.de (Postfix) with ESMTPS id 1BCC7C21EF0 for ; Tue, 11 Sep 2018 07:00:00 +0000 (UTC) Received: by mail-pf1-f196.google.com with SMTP id h69-v6so11746568pfd.4 for ; Tue, 11 Sep 2018 00:00:00 -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=4J/varR4JkH+LdOL6OeUi0ZfxUIxDMF7scG9lf1e4QE=; b=Vlv7LspI2SuT5Tkw7tdQxGVMtk/wtQLjYiHIO/YNdVZVMItLo9s09hTRtKMiGLCnT/ aLQ4+5LWzGQ0sSEooU+usWvccv9rK1OpxAhqMi37O25/3cIPFUNtFO/VPeD2Ov4LJ7av AGnLAml6PfpXi4ZVhABQT/9cPgu39dWW9QiTk= 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=4J/varR4JkH+LdOL6OeUi0ZfxUIxDMF7scG9lf1e4QE=; b=mStQ/glzMSdE7MkAZP8wBUmkDhK/la9o0e0VXU67plwpRI2FC8av3UyHf1AM5N7vtB +HtlQDS8GRDf9An3WIGqG+HtK5WOnp+BoiI+vKZ3oykT80YxseETy71OHM4qVXq2vkYW q/KytOgVs2RoWYprIEAOXJVrWaWMA2geCHWJF2jYw0AvqLyB0/PCtc7kdFHwq/9j0bbO n+vKAXWJUgUzniEyAL8kmmgq0a6lxZvcrMpHMnk/WWebWAhTuuSRJO889pcO/W2tL55l 28XhdAQIm9DVN4kIkayew17UrH7OXXqPDhCw/yRfeGyRYTS084fUd3kTdQuBvZnKJ1YP lzQQ== X-Gm-Message-State: APzg51A4HLzf8E06vEV6N3s8t2/LuZTUOLJyENoUhTxR2d7kqbbCFu6x Ljq/W+MqM7eAzmGjTNjGN+b8Zw== X-Received: by 2002:a62:591a:: with SMTP id n26-v6mr27854899pfb.94.1536649198793; Mon, 10 Sep 2018 23:59:58 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id x24-v6sm23315619pfh.67.2018.09.10.23.59.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Sep 2018 23:59:58 -0700 (PDT) From: "Akashi, Takahiro" To: trini@konsulko.com Date: Tue, 11 Sep 2018 15:59:11 +0900 Message-Id: <20180911065922.19141-16-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 15/26] cmd: fat: add fatmkdir command 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 In this patch, a new command, fatmkdir, is added. Please note that, as there is no notion of "current directory" on u-boot, a directory name specified must contains an absolute directory path as a parent directory. Otherwise, "/" (root directory) is assumed. Signed-off-by: AKASHI Takahiro --- cmd/fat.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/cmd/fat.c b/cmd/fat.c index 2a5f7bfc2690..b685bf70a2b3 100644 --- a/cmd/fat.c +++ b/cmd/fat.c @@ -151,4 +151,17 @@ U_BOOT_CMD( " - write file 'filename' from the address 'addr' in RAM\n" " to 'dev' on 'interface'" ); + +static int do_fat_mkdir(cmd_tbl_t *cmdtp, int flag, int argc, + char * const argv[]) +{ + return do_mkdir(cmdtp, flag, argc, argv, FS_TYPE_FAT); +} + +U_BOOT_CMD( + fatmkdir, 4, 1, do_fat_mkdir, + "create a directory", + " [] \n" + " - create a directory in 'dev' on 'interface'" +); #endif From patchwork Tue Sep 11 06:59: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: 146414 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3320901ljw; Tue, 11 Sep 2018 00:11:47 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZ9NDtCrOOJiZ+iNQY8ZgOKEXdrwTDM7baaAgiLRFh8p548t7Uvjcfs3DJWKAv1rUA1eKev X-Received: by 2002:a50:b5e6:: with SMTP id a93-v6mr4404141ede.94.1536649907303; Tue, 11 Sep 2018 00:11:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536649907; cv=none; d=google.com; s=arc-20160816; b=tuLohbmL8v24iGiYP4SXodIpw4a+8BrOLhzCUksixzxQ3vLwK/1+JBEcdEVphxL82B iV98cj55T8qVosckiTRj+WbPzHTquqcdeWSFELuMfIlTK4j9XuiTqnfeAeeEhwaKqlOJ OwE8vQcGeGB3KTPpCygMwQilFKMCIvlTTOHjicDG4F6F0qrPNBl6YoIdAh86iFbvNI3S PEWkrhgyfYCOSESUSTbEa75B2lnee1B86UipvImQYFEvGQV60Z+vdrHy1ykHd/d3nMQR 7NwgZfiJfsYsBksvkXz/sAs+QrNTQkL5onTcaOnYWAmwmBfpPjI4oTNWVUKtpDKg6pey jqTw== 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=JjG+XLCDrDY2TPS8NwWoK0Bw7QrWsnCPFraKsHoivvE=; b=X5EeGXmEanRPgBms1DxUOOQdqXBo/999kJCxfCU3i4R8g0yr3laPopjdPDx5v01oV3 gLoryqwJirUy+NlWm/1iOE+fxYrQbbZCWxT2YlkSFtMZPe4Ygn5LBKeQBY+go3uQi3Zx MixGMQGPFu1wFwYE1e3DbNVEZlI0R8SwznWUh0CbYy7ufU3RtIOXW9+d1Lj91ju2UyXK cgxF+p4qnEzBNtsIfb60iCyNVsf2+uVvSSI6BQs0zz/Kzy9uICY/DVzLARgm2VUnXI99 S/js3a3LDYfp2ktdIzJ+dCcM3QvEpWd/pb5cLAWiEkt73VSLsfRhQ955X8i94kD6yw1u m7mQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=ZBTeEpf2; 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 l60-v6si2213030ede.26.2018.09.11.00.11.47; Tue, 11 Sep 2018 00:11:47 -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=ZBTeEpf2; 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 CE53BC21E6C; Tue, 11 Sep 2018 07:05:37 +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 C4958C21EF7; Tue, 11 Sep 2018 07:00:43 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 3C5D4C21F18; Tue, 11 Sep 2018 07:00:09 +0000 (UTC) Received: from mail-pl1-f196.google.com (mail-pl1-f196.google.com [209.85.214.196]) by lists.denx.de (Postfix) with ESMTPS id 3DC6DC21EFD for ; Tue, 11 Sep 2018 07:00:04 +0000 (UTC) Received: by mail-pl1-f196.google.com with SMTP id w14-v6so10881055plp.6 for ; Tue, 11 Sep 2018 00:00:04 -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=sIUjgMi15niwdxNpCMu99DQmDjkdIUo6+OFO+w+4tvY=; b=ZBTeEpf2taB2uO8ooMWPzAUP0XZNyb26T2f4eiRfABD8yEjm6bLMHte716NZGzOOly X7YhRSdcyZgQb8adoNpfUcCWUndGxEzrX1R2XSmdlGsGp8YdvI2eX7mgzbk6hEDcr8ZZ xWn/m7PJ7gZDWu50XcMfjfhHG5LDLxF/5zgR0= 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=sIUjgMi15niwdxNpCMu99DQmDjkdIUo6+OFO+w+4tvY=; b=c7KPlb/KaQv8uC/2r/9KZ3NZP6baFrS8rCFdGioQvROSw1vgFjXqj6etlamGXHPG0H 9NUvo1dnaGoN6pTE6eE634O+TKkd/iHesxVcxdVnjAQDl0ZGSS9DDC4Y5+TyF721GOq/ 9+JQq8pgbryVRkSpdkGMIo72JsYwLql5NINb/aBxPcosYNZCN1zEoqLWU/uMnuW8OJ3k aOYkeDSDsEZFAuLPDJ0naCUbfHiaXzRgjCyp5HHeSIJsSZ7oCF/t7bSRyQywNn7gDlmi +Wb8TnkWk8RKaPSss1ar7KZ4we3Xd19BeHLlH7UOYgsi9xKqJNgXwXlO0Soj59RMlTRM M/rw== X-Gm-Message-State: APzg51BgiU2N+937ONVxHk8yDI0BVj6DBEBt9o2wlbT6qw9jBL/j7OeN 21Oz+2ECT2jIVaJWThhc8cvH8Q== X-Received: by 2002:a17:902:1001:: with SMTP id b1-v6mr25730527pla.155.1536649202933; Tue, 11 Sep 2018 00:00:02 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id j184-v6sm19672412pge.77.2018.09.11.00.00.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Sep 2018 00:00:02 -0700 (PDT) From: "Akashi, Takahiro" To: trini@konsulko.com Date: Tue, 11 Sep 2018 15:59:12 +0900 Message-Id: <20180911065922.19141-17-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 16/26] efi_loader: file: support creating a directory 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 In efi world, there is no obvious "mkdir" interface, instead, Open() with EFI_FILE_MODE_CREATE in mode parameter and EFI_FILE_DIRECTORY in attributes parameter creates a directory. In this patch, efi_file_open() is extended so as to accept such a combination of parameters and call u-boot's mkdir interface for expected action. Signed-off-by: AKASHI Takahiro --- lib/efi_loader/efi_file.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/efi_loader/efi_file.c b/lib/efi_loader/efi_file.c index e6a15bcb523e..6ec98c80227e 100644 --- a/lib/efi_loader/efi_file.c +++ b/lib/efi_loader/efi_file.c @@ -130,7 +130,8 @@ static int sanitize_path(char *path) * With windoze style backlashes, ofc. */ static struct efi_file_handle *file_open(struct file_system *fs, - struct file_handle *parent, s16 *file_name, u64 mode) + struct file_handle *parent, s16 *file_name, u64 mode, + u64 attributes) { struct file_handle *fh; char f0[MAX_UTF8_PER_UTF16] = {0}; @@ -173,7 +174,12 @@ static struct efi_file_handle *file_open(struct file_system *fs, if (set_blk_dev(fh)) goto error; - if (!((mode & EFI_FILE_MODE_CREATE) || fs_exists(fh->path))) + if ((mode & EFI_FILE_MODE_CREATE) && + (attributes & EFI_FILE_DIRECTORY)) { + if (fs_mkdir(fh->path)) + goto error; + } else if (!((mode & EFI_FILE_MODE_CREATE) || + fs_exists(fh->path))) goto error; /* figure out if file is a directory: */ @@ -199,7 +205,7 @@ static efi_status_t EFIAPI efi_file_open(struct efi_file_handle *file, EFI_ENTRY("%p, %p, \"%ls\", %llx, %llu", file, new_handle, file_name, open_mode, attributes); - *new_handle = file_open(fh->fs, fh, file_name, open_mode); + *new_handle = file_open(fh->fs, fh, file_name, open_mode, attributes); if (!*new_handle) return EFI_EXIT(EFI_NOT_FOUND); @@ -598,7 +604,7 @@ efi_open_volume(struct efi_simple_file_system_protocol *this, EFI_ENTRY("%p, %p", this, root); - *root = file_open(fs, NULL, NULL, 0); + *root = file_open(fs, NULL, NULL, 0, 0); return EFI_EXIT(EFI_SUCCESS); } From patchwork Tue Sep 11 06:59:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 146416 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3321481ljw; Tue, 11 Sep 2018 00:12:26 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZkjOxac0EpU2VN2+eCwxFhXHC+wkKlYZi0J+ko94nLmUo/60XoV42pOTVrEdYRg18gnLt6 X-Received: by 2002:a50:9b5c:: with SMTP id a28-v6mr26774953edj.167.1536649946046; Tue, 11 Sep 2018 00:12:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536649946; cv=none; d=google.com; s=arc-20160816; b=DqQPpB3ZCKwPTVKeXD/8GiMw5BPromE5+pTIQ1yL+qLzswBQJrGnI/O9MCxW4Ehfx6 3EDNXm1FSYY4pkrejwZbOMal/TnQpxSv9G+1A9QQxjQBiws54g7gbNt+Fn2xPG5rU1RH RyEmTStmVfnCr8tVMfueHQWZDF2//RQjFmFpbzJlZAFyX88U2P6mbgjhhKc3C0zHWQ/2 4QEMtVtZUpKw3gCxUTnSLbMkNbU6JCBD3hgofYak71+fDVo6Z5skSOzBxj8FuRFGlsWY 0BauHRBprFiIZImjkqGHhsKH/YbTSZbyQ33ewt1LnFlzM9yjKyyEkgeEFis82tCpGNS2 P79Q== 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=js2Sg93crJS4pFuBlLMiX7ciQ5A9G2FaiUcP+8DcQlY=; b=XiOhFo93PQUQAOGybrc+rCQINDX4OtJ0SkERJN+Y9zZhRvU/2DTTbwSglp+wOCZ+ae xlHGYdUscUygXW/2h06GmBYkiBOH1mH4A+CibJLL8CIBhbH6N6l7cRh9QwhDBVbo5Jgj tB/h54c5bSUCVuCfTLNOo4fA9lof4drDruK1TqtmQW9NUC+VZUWQG0zEA7js0KCAuuvM nWTSvon3QSNgrubjaapsChituEr3hko8cVwP6xHTcehmV2Mwu63BWjkjXlL82Ap44onD fN1n/K4aPqHrKo7h6TKBBjTdSP+k1jzFdu84pokPzImSFeErPDUGJXhFwaIZeKFVaAch hl5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Wedq6znK; 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 t15si197606edw.353.2018.09.11.00.12.25; Tue, 11 Sep 2018 00:12:26 -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=Wedq6znK; 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 8E6A3C21ECC; Tue, 11 Sep 2018 07:06:28 +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 EAD8BC21E85; Tue, 11 Sep 2018 07:00:53 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id EF09CC21E44; Tue, 11 Sep 2018 07:00:17 +0000 (UTC) Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) by lists.denx.de (Postfix) with ESMTPS id 346FFC21DD9 for ; Tue, 11 Sep 2018 07:00:08 +0000 (UTC) Received: by mail-pg1-f194.google.com with SMTP id x26-v6so11744938pge.12 for ; Tue, 11 Sep 2018 00:00:08 -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=X+AcmSTaCYGaZ32A/XhLqf/ypKyPsh9GyVKF6+XU8d8=; b=Wedq6znKQOLL5UcKLpp6LwYOjoZZEg4SROSAIEPloVo+CorrQvajM88w6cqIaiPOwf h917e8hlA2uzC55JIe3E1+qIgIspPFsbX2HnBYtTsaFAjYOpgZ53e2TDEh9/vbimhqJD d0Muc73JUYBYfcrSsFcKfFJY9Q/aC2E5MhCFQ= 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=X+AcmSTaCYGaZ32A/XhLqf/ypKyPsh9GyVKF6+XU8d8=; b=h2ueSVrgkbyFKYiDgUszF29pmwqVpEASBJvxR887JjaOi7cr9thv/DMv7n1WlDNyAE pXYPCL2h+sl1Xjrog6OIVajmoRBYy6NbiYd4dsfu2FtL3mgFtBheNr6dCgPCfS0rPU/o ZMDVB4kG+rzy7n3W/DUywQdt52LzpFnbUvTN4HGgtPJne+JGRniiJqRAURmp+dxVAsWF Z6QjHyyeTlTAgD3Idu+/vsAMx3rZlHNJfzTI5AwpHQthA3fvhjIlvl0tMXqeaC9sC8Ws BREfJA6mBXUcNwi366t5hiB9cag4AQHl3XN2KaKXHMiBeEqHHodBb/pDn+3eXc1a3RFd mybQ== X-Gm-Message-State: APzg51D3rbAOGoWYPtbqk2iin23LeU3UgzVaH0BUFr9qAHE8NIwD2HSQ Jz4adsBgTA98ZMk9XjVtNRLEnQ== X-Received: by 2002:a63:f244:: with SMTP id d4-v6mr26181155pgk.2.1536649206768; Tue, 11 Sep 2018 00:00:06 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id d66-v6sm26467541pfd.121.2018.09.11.00.00.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Sep 2018 00:00:06 -0700 (PDT) From: "Akashi, Takahiro" To: trini@konsulko.com Date: Tue, 11 Sep 2018 15:59:13 +0900 Message-Id: <20180911065922.19141-18-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 17/26] fs: add unlink interface 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 "unlink" interface is added to file operations. This is a preparatory change as unlink support for FAT file system will be added in next patch. Signed-off-by: AKASHI Takahiro --- fs/fs.c | 40 ++++++++++++++++++++++++++++++++++++++++ include/fs.h | 12 ++++++++++++ 2 files changed, 52 insertions(+) diff --git a/fs/fs.c b/fs/fs.c index 099540f38a10..ba9a65166c70 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -105,6 +105,11 @@ static inline int fs_opendir_unsupported(const char *filename, return -EACCES; } +static inline int fs_unlink_unsupported(const char *filename) +{ + return -1; +} + static inline int fs_mkdir_unsupported(const char *dirname) { return -1; @@ -147,6 +152,7 @@ struct fstype_info { int (*readdir)(struct fs_dir_stream *dirs, struct fs_dirent **dentp); /* see fs_closedir() */ void (*closedir)(struct fs_dir_stream *dirs); + int (*unlink)(const char *filename); int (*mkdir)(const char *dirname); }; @@ -173,6 +179,7 @@ static struct fstype_info fstypes[] = { .opendir = fat_opendir, .readdir = fat_readdir, .closedir = fat_closedir, + .unlink = fs_unlink_unsupported, }, #endif #ifdef CONFIG_FS_EXT4 @@ -193,6 +200,7 @@ static struct fstype_info fstypes[] = { #endif .uuid = ext4fs_uuid, .opendir = fs_opendir_unsupported, + .unlink = fs_unlink_unsupported, .mkdir = fs_mkdir_unsupported, }, #endif @@ -210,6 +218,7 @@ static struct fstype_info fstypes[] = { .write = fs_write_sandbox, .uuid = fs_uuid_unsupported, .opendir = fs_opendir_unsupported, + .unlink = fs_unlink_unsupported, .mkdir = fs_mkdir_unsupported, }, #endif @@ -227,6 +236,7 @@ static struct fstype_info fstypes[] = { .write = fs_write_unsupported, .uuid = fs_uuid_unsupported, .opendir = fs_opendir_unsupported, + .unlink = fs_unlink_unsupported, .mkdir = fs_mkdir_unsupported, }, #endif @@ -244,6 +254,7 @@ static struct fstype_info fstypes[] = { .write = fs_write_unsupported, .uuid = btrfs_uuid, .opendir = fs_opendir_unsupported, + .unlink = fs_unlink_unsupported, .mkdir = fs_mkdir_unsupported, }, #endif @@ -260,6 +271,7 @@ static struct fstype_info fstypes[] = { .write = fs_write_unsupported, .uuid = fs_uuid_unsupported, .opendir = fs_opendir_unsupported, + .unlink = fs_unlink_unsupported, .mkdir = fs_mkdir_unsupported, }, }; @@ -510,6 +522,19 @@ void fs_closedir(struct fs_dir_stream *dirs) fs_close(); } +int fs_unlink(const char *filename) +{ + int ret; + + struct fstype_info *info = fs_get_info(fs_type); + + ret = info->unlink(filename); + + fs_type = FS_TYPE_ANY; + fs_close(); + + return ret; +} int fs_mkdir(const char *dirname) { @@ -727,6 +752,21 @@ int do_fs_type(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) return CMD_RET_SUCCESS; } +int do_rm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], + int fstype) +{ + if (argc != 4) + return CMD_RET_USAGE; + + if (fs_set_blk_dev(argv[1], argv[2], fstype)) + return 1; + + if (fs_unlink(argv[3])) + return 1; + + return 0; +} + int do_mkdir(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], int fstype) { diff --git a/include/fs.h b/include/fs.h index fbaee154dd0d..aa3604db8dc4 100644 --- a/include/fs.h +++ b/include/fs.h @@ -155,6 +155,16 @@ struct fs_dirent *fs_readdir(struct fs_dir_stream *dirs); */ void fs_closedir(struct fs_dir_stream *dirs); +/* + * fs_unlink - delete a file or directory + * + * If a given name is a directory, it will be deleted only if it's empty + * + * @filename: Name of file or directory to delete + * @return 0 on success, -1 on error conditions + */ +int fs_unlink(const char *filename); + /* * fs_mkdir - Create a directory * @@ -177,6 +187,8 @@ int file_exists(const char *dev_type, const char *dev_part, const char *file, int fstype); int do_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], int fstype); +int do_rm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], + int fstype); int do_mkdir(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], int fstype); From patchwork Tue Sep 11 06:59:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 146412 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3319575ljw; Tue, 11 Sep 2018 00:10:12 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZGBPwwjf6mChgddzM3Wks7GYcJAj7oeEY5PHB73CcYrPbLOz7168jyDsK48tqtnikDrgnx X-Received: by 2002:a05:6402:1348:: with SMTP id y8mr26494979edw.222.1536649812483; Tue, 11 Sep 2018 00:10:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536649812; cv=none; d=google.com; s=arc-20160816; b=0sYb94KDXKat+35R9MBO3IORoydgWt0fpA6Jgs9rJqj7lo1nXdt3ea3F+iTHbfEyUn Xnyb2q4UCK7tgZWSK9rUYA+0ns/6+/xlpbcWmwQULuKS/XGjy6/4M14LaIFL8shFg93X BMeVtK5zJAwTKYdFafMx7mhVbbNwuy3mbZcZAAhzmUEr7ZF6vApN34SdBC24gnbgPUTB +wBEnjJ+yegITEEic+i2+2PMzWiaoasmQizHUm7SuQQ5aU9o7sr1am/xZshCxrSW3eQk 87/d2MfX/yfSo/JIZdeLzTdTcSoPKy+YMecwAP8HlMM8FkbIKP2dEGF8DuYlfa0Lf36V sYKQ== 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=6xyOXqM+2tiS+2VQCDWEqEq0V9sB2bS2faqKqCG64h8=; b=zgOFMgdnbdw6U1wbghOLmOVL94pJ8D6qgZ9vlUS39ViduLywqxl+WixVPkU2KBGH0e fueJR4FWWxcP3MCbG1vQyfzmxWPWo6OeOgHLWIPhlvKtEbDVEe6Ku9zRu2YxZwadEJpy QXPtR3ukUVf5YE/EA5MFjfqxD02Nd32j9ZBhoauvd87yK5IHyg9fwb/mYAKGEHtMOebp OyPA35esSRKdO8D8gmw1eyrsLZ9dPeGkuoagWMX1Cp6DprTAFwoYIos/J34O0Zva0eJA UjO8RppjKLlGzKYv5Vhuup7v80TmPdt+rVSZ+4ehffGtR1mdJNnJvIB4WfD10YtbOj5K 41fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=QtfZ98lw; 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 s13-v6si2010097edh.327.2018.09.11.00.10.12; Tue, 11 Sep 2018 00:10:12 -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=QtfZ98lw; 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 D753BC21E70; Tue, 11 Sep 2018 07:06:05 +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 DA38EC21EFC; Tue, 11 Sep 2018 07:00:52 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 74ACFC21EC9; Tue, 11 Sep 2018 07:00: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 E2782C21EFC for ; Tue, 11 Sep 2018 07:00:17 +0000 (UTC) Received: by mail-pg1-f195.google.com with SMTP id d19-v6so11767638pgv.1 for ; Tue, 11 Sep 2018 00:00:17 -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=4kbxUPVWkedb8CcqEPt5F1V4tG0kf9B6Ax7XOaTDTyU=; b=QtfZ98lw0FM47AX6q9sHjaojV47aV2BTGd65T9VuWbBnQEQbToUsqsSCHRRc5OuCZ1 2hN2UwpoBCIVZimBTErhjoggie06vOAlR1vRTg9NTqr1sTh8XP2jHdmqZbTIAqQ2GBAZ pOKfc2k7S8a+kQ4JZYp4o72t5uRfgpYYGrkp0= 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=4kbxUPVWkedb8CcqEPt5F1V4tG0kf9B6Ax7XOaTDTyU=; b=jqJRz04pMnpWBt1QRS2+50FqLysoKv8ruuvgcZ38hS3L+ej8YPslZgwH7pXa3Pzh5J WHcEbYhsZCxeIIktxB5Nym/BEeOtdC7fI905TgPf4t0AIDG7gjQNegttc43V1xeGXLSa yX1lOs5UCTjo3syLS/njH91H9xvNxEVCuHANL7oBB1ldKQjaoJApg4TAP4BRiBvs/aLW QROVu2fYdBDwXWycN61oxb670FTsA6re1nvuL6LVKKg2dd+zsCsfKdPKZ2YNJzJ/0MRv 0/ruQTLL1rzko5QWpaLrEQxTDAFWOVLISg0AK6+Ln9k6kOVD63bejkKBoSI2hKaSuDfQ f+Dg== X-Gm-Message-State: APzg51COliiN49I9u6z8q0TthWK6/oZsqLkrz24f6pgJhgQTu0xgG7Jw can3Wt/Fq+svaE3PHtV8cA9ZyA== X-Received: by 2002:a63:4826:: with SMTP id v38-v6mr26767573pga.379.1536649211327; Tue, 11 Sep 2018 00:00:11 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id o21-v6sm26008596pfi.165.2018.09.11.00.00.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Sep 2018 00:00:10 -0700 (PDT) From: "Akashi, Takahiro" To: trini@konsulko.com Date: Tue, 11 Sep 2018 15:59:14 +0900 Message-Id: <20180911065922.19141-19-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 18/26] fs: fat: support unlink 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 In this patch, unlink support is added to FAT file system. A directory can be deleted only if it is empty. In this implementation, only a directory entry for a short file name will be removed. So entries for a long file name can and should be reclaimed with fsck. Signed-off-by: AKASHI Takahiro --- fs/fat/fat_write.c | 132 +++++++++++++++++++++++++++++++++++++++++++++ fs/fs.c | 3 +- include/fat.h | 1 + 3 files changed, 135 insertions(+), 1 deletion(-) diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c index 035469f31c8d..6d3d2d1abb04 100644 --- a/fs/fat/fat_write.c +++ b/fs/fat/fat_write.c @@ -1184,6 +1184,138 @@ int file_fat_write(const char *filename, void *buffer, loff_t offset, return file_fat_write_at(filename, offset, buffer, maxsize, actwrite); } +static int fat_dir_entries(fat_itr *itr) +{ + fat_itr *dirs; + fsdata fsdata = { .fatbuf = NULL, }, *mydata = &fsdata; + /* for FATBUFSIZE */ + int count; + + dirs = malloc_cache_aligned(sizeof(fat_itr)); + if (!dirs) { + debug("Error: allocating memory\n"); + count = -ENOMEM; + goto exit; + } + + /* duplicate fsdata */ + fat_itr_child(dirs, itr); + fsdata = *dirs->fsdata; + + /* allocate local fat buffer */ + fsdata.fatbuf = malloc_cache_aligned(FATBUFSIZE); + if (!fsdata.fatbuf) { + debug("Error: allocating memory\n"); + count = -ENOMEM; + goto exit; + } + fsdata.fatbufnum = -1; + dirs->fsdata = &fsdata; + + for (count = 0; fat_itr_next(dirs); count++) + ; + +exit: + free(fsdata.fatbuf); + free(dirs); + return count; +} + +static int delete_dentry(fat_itr *itr) +{ + fsdata *mydata = itr->fsdata; + dir_entry *dentptr = itr->dent; + + /* free cluster blocks */ + clear_fatent(mydata, START(dentptr)); + if (flush_dirty_fat_buffer(mydata) < 0) { + printf("Error: flush fat buffer\n"); + return -EIO; + } + + /* + * update a directory entry + * TODO: + * - long file name support + * - find and mark the "new" first invalid entry as name[0]=0x00 + */ + memset(dentptr, 0, sizeof(*dentptr)); + dentptr->name[0] = 0xe5; + + if (set_cluster(mydata, itr->clust, itr->block, + mydata->clust_size * mydata->sect_size) != 0) { + printf("error: writing directory entry\n"); + return -EIO; + } + + return 0; +} + +int fat_unlink(const char *filename) +{ + fsdata fsdata = { .fatbuf = NULL, }; + fat_itr *itr = NULL; + int n_entries, ret; + char *filename_copy, *dirname, *basename; + + filename_copy = strdup(filename); + split_filename(filename_copy, &dirname, &basename); + + if (!strcmp(dirname, "/") && !strcmp(basename, "")) { + printf("Error: cannot remove root\n"); + ret = -EINVAL; + goto exit; + } + + itr = malloc_cache_aligned(sizeof(fat_itr)); + if (!itr) { + printf("Error: allocating memory\n"); + return -ENOMEM; + } + + ret = fat_itr_root(itr, &fsdata); + if (ret) + goto exit; + + total_sector = fsdata.total_sect; + + ret = fat_itr_resolve(itr, dirname, TYPE_DIR); + if (ret) { + printf("%s: doesn't exist (%d)\n", dirname, ret); + ret = -ENOENT; + goto exit; + } + + if (!find_directory_entry(itr, basename)) { + printf("%s: doesn't exist\n", basename); + ret = -ENOENT; + goto exit; + } + + if (fat_itr_isdir(itr)) { + n_entries = fat_dir_entries(itr); + if (n_entries < 0) { + ret = n_entries; + goto exit; + } + if (n_entries > 2) { + printf("Error: directory is not empty: %d\n", + n_entries); + ret = -EINVAL; + goto exit; + } + } + + ret = delete_dentry(itr); + +exit: + free(fsdata.fatbuf); + free(itr); + free(filename_copy); + + return ret; +} + int fat_mkdir(const char *new_dirname) { dir_entry *retdent; diff --git a/fs/fs.c b/fs/fs.c index ba9a65166c70..adae98d021ee 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -170,16 +170,17 @@ static struct fstype_info fstypes[] = { .read = fat_read_file, #ifdef CONFIG_FAT_WRITE .write = file_fat_write, + .unlink = fat_unlink, .mkdir = fat_mkdir, #else .write = fs_write_unsupported, + .unlink = fs_unlink_unsupported, .mkdir = fs_mkdir_unsupported, #endif .uuid = fs_uuid_unsupported, .opendir = fat_opendir, .readdir = fat_readdir, .closedir = fat_closedir, - .unlink = fs_unlink_unsupported, }, #endif #ifdef CONFIG_FS_EXT4 diff --git a/include/fat.h b/include/fat.h index 97460a3cdff1..ca92a735b4fd 100644 --- a/include/fat.h +++ b/include/fat.h @@ -205,6 +205,7 @@ int fat_read_file(const char *filename, void *buf, loff_t offset, loff_t len, int fat_opendir(const char *filename, struct fs_dir_stream **dirsp); int fat_readdir(struct fs_dir_stream *dirs, struct fs_dirent **dentp); void fat_closedir(struct fs_dir_stream *dirs); +int fat_unlink(const char *filename); int fat_mkdir(const char *dirname); void fat_close(void); #endif /* CONFIG_FS_FAT */ From patchwork Tue Sep 11 06:59:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 146420 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3322258ljw; Tue, 11 Sep 2018 00:13:16 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdb0N9nP34a0cdY+WtiowXkok5cS6COxsgIVzDU/r+3HLEAcdMxX13LUkGDgXX3rr/+WSnT/ X-Received: by 2002:a50:c8c3:: with SMTP id k3-v6mr26682347edh.193.1536649996489; Tue, 11 Sep 2018 00:13:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536649996; cv=none; d=google.com; s=arc-20160816; b=Nnn8LlgHEdurvjAHVECDYKR3gAICO4Yj7x/Kw76+xXxoyB1A3ia/epywKudxwr1zEd aHWVQyeGDxe9E3aD/OBJ8eeaqJ61Ugzfmp1kxDGsZSn9K54tEBnFFiiQZkob1V69jQJw gISBaGd2QWmQCAD4FiW4NuuM+swwJ7zLnu7KMaF7crUUb1c9RsjRGx9ffqE0Stz3phGT Kx48N5qEErnWhZto+5g3FQ5fMjm1TVLTGw14ZfPfsJcvGXfITYddzTHThYlqNGGM9ElN moxJABNcqbcrYShfxbEgvIQ8/CBhsokUb/Mu9k1Wq2TkNurwQpJNuhndmZDGKK0SDtA0 /1QA== 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=foKekA0O3THAciU4L42jgVpzWyxS/OtiJDh5ZCnQDTs=; b=0BJleIK6L42OuWvRf8rHMS8vVB43Bcda1fBBJ86pQxhYbRXP+JaIC94lA7yOsK5Uv7 uw66NFzYwtojLdA6l/R1TKUeAg0by3JABG/o0EAgjPlhcnXALAhzbIyPIZ/R1+bG6ojm der6vQ8zkt1P/2Llu+VIk63HafiZWThZ4UMIk4PhmLEyXOOKY6bkZiuHOXWMeKcnhDYH mWwWSFNtS2+33CKgcKr44hUaqtENe1QBFpHXOFD3NlS14BpRwyeF/PKoxJfF3ptZgrYi pFfeO7u/WPM+XNQWHucr/Pg1dMvIskGtpmAU+qPGYX4U8tJRbV9CELn2DE0ZvC0dCo3S EeAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=WEIYMuZE; 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 z36-v6si736004edd.71.2018.09.11.00.13.16; Tue, 11 Sep 2018 00:13:16 -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=WEIYMuZE; 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 0C154C21E4E; Tue, 11 Sep 2018 07:06:47 +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 0C241C21F06; Tue, 11 Sep 2018 07:01:07 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 5FCAEC21E18; Tue, 11 Sep 2018 07:00:23 +0000 (UTC) Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) by lists.denx.de (Postfix) with ESMTPS id BACFDC21EFF for ; Tue, 11 Sep 2018 07:00:16 +0000 (UTC) Received: by mail-pf1-f180.google.com with SMTP id x17-v6so11751884pfh.5 for ; Tue, 11 Sep 2018 00:00:16 -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=+Nm0L2LvUSrM9BJZKd7IaUsRyE5BVM1LGYlzIHTxAR8=; b=WEIYMuZEW+9gX5A0tANGxcrqltfdCDHQAEaIZ0vAingLi2dd/63acziOcIGj2FgN6+ k8Kw5lUZH9mPMNwHVH2SG5AUJiOoJW7rLhS3pw7ly3NY083e2c7YpVF23YFo4HwZsQWI oq2a0lVYfw4BmMEbmAysFqvhbTcz38wWAG/7Y= 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=+Nm0L2LvUSrM9BJZKd7IaUsRyE5BVM1LGYlzIHTxAR8=; b=G9pu+Rtr5ESX0R1NvX3YD2TpF3lr+xkY/SvKgi/IshRKC9xfna4wKveAwUoioMXHqB 0FTQ9wPxAISs2i/7Ms3ajQiwPrNrnA+U5ZZaQOsqlvb/y+ATLgo1F0hpN8H2ueDYjTLU Ve8tK3GE/jX/AJrrA1am15mf/ecOV/+YwVphF/LRxUV8PJ7HIDq8eEPiCFO5Ueg5p2bQ hAB1YKpTqngXIznJUEGnxDmN//O8K9PNpNfZk7ctDq+bjf09BDwjzlAG7itje2abErWF HhkdQKuUkZ+D5I5mqwzG105kGi0KrZ/Z+B+m4+hiky++T2xgcy9Zx3GlvlfATBTrqh6E zl5Q== X-Gm-Message-State: APzg51Awn6f+mzpGTRD4Dbzc6EmojgtOIjo4iA3fwPs5spadU0ZT2aw1 w4M9bWRG2iBFxdZFJDwHsoiyIg== X-Received: by 2002:a63:1064:: with SMTP id 36-v6mr26536107pgq.254.1536649215496; Tue, 11 Sep 2018 00:00:15 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id l9-v6sm22119733pgg.79.2018.09.11.00.00.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Sep 2018 00:00:14 -0700 (PDT) From: "Akashi, Takahiro" To: trini@konsulko.com Date: Tue, 11 Sep 2018 15:59:15 +0900 Message-Id: <20180911065922.19141-20-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 19/26] cmd: fat: add fatrm command 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 In this patch, a new command, fatrm, is added so as to delete a file or directory. Signed-off-by: AKASHI Takahiro --- cmd/fat.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cmd/fat.c b/cmd/fat.c index b685bf70a2b3..4b9a7eaab054 100644 --- a/cmd/fat.c +++ b/cmd/fat.c @@ -152,6 +152,18 @@ U_BOOT_CMD( " to 'dev' on 'interface'" ); +static int do_fat_rm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + return do_rm(cmdtp, flag, argc, argv, FS_TYPE_FAT); +} + +U_BOOT_CMD( + fatrm, 4, 1, do_fat_rm, + "delete a file", + " [] \n" + " - delete a file from 'dev' on 'interface'" +); + static int do_fat_mkdir(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { From patchwork Tue Sep 11 06:59:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 146423 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3324210ljw; Tue, 11 Sep 2018 00:15:50 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZn2t8bihqaNc3mrYbrz5whEJ9600C+IaTnelupJLucjv+GxLTk5rIEynMtHK6JUft86xfC X-Received: by 2002:a50:81c6:: with SMTP id 64-v6mr26422476ede.93.1536650150861; Tue, 11 Sep 2018 00:15:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536650150; cv=none; d=google.com; s=arc-20160816; b=bEwZAqNd18kWICD6MYcbf+8oOFwF28Saj6zxo2iSKBymfL6yyXrL4ZKzOrI8OT0HYV kNAzm+m6/uY8x5Z7bt6tNCzIo1pYCQoGSUsRkdbOKjgNKvJci06MvJ31nIEs+MqrATZC C/6W4A7BSAO/9xeMb4srHgM+coRPLy7t/QKF6fx7TbrS893aj3xOX/1VSgCjN3if3YIw fMEmN2o3daWrbsdjUslpROfkQZMuOFXHu4hafffbiM/IfVjC10niCYp+l5xeklfr+jaC jR648DrSz4ageGXGQogTbnce9g1Nb4LJXEhGJmzxA1W/jXpstPRBGC11DChuHSw/9gSX 6IgQ== 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=0WGfkTsSmm8pnQHQaeUntKB7/SyeIS9S0I1TecBhVS4=; b=YXCy2IQy67uuVdLGYYjoKiuIUfTL+IwlZ69E0UEPFErp8m5Bb1nAa+pjscscQRcacG 3Svr/+flxXNAaAFXM+LSLj7hvtNUNA/jjQDsoozZ4vBcNpOBYgwGqJo72kiD6y7ajNPK mDi4Py2yr6VM5Xon3IVHX7++Zcwig+1OBG8gMomaNO6jwJAfreag4f2Y87m+9RtjcRQR 9k+VhtQ4nSp3tLRm/t78x7EINXVH/temZf+McH0M3WncNQO88cQhD/L5UpXvo4el+7Za QMjvMhj/iVoZOqGFME7q/MS8mEXMtKYRP3t1FXY/JibMWTJdwJUu9vWgY8FzO3UweLMd 1IKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=VGziMP1c; 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 92-v6si1191509edj.173.2018.09.11.00.15.50; Tue, 11 Sep 2018 00:15:50 -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=VGziMP1c; 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 67823C21EE3; Tue, 11 Sep 2018 07:09:08 +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 0D2ACC21F07; Tue, 11 Sep 2018 07:01:34 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 3535FC21F29; Tue, 11 Sep 2018 07:00:24 +0000 (UTC) Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) by lists.denx.de (Postfix) with ESMTPS id BBEA2C21F04 for ; Tue, 11 Sep 2018 07:00:19 +0000 (UTC) Received: by mail-pf1-f196.google.com with SMTP id i26-v6so11729451pfo.12 for ; Tue, 11 Sep 2018 00:00:19 -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=nkHlKBHNcO4mG7XfvMpL+bqf1m84GCvR1iwc8zgfMcs=; b=VGziMP1cnVGcOlvzgUYqVHPV0hI+Hmbc1G4VkbrxTIuCWXm7tpSt+woSVq25CxqpEG l1u9S/5pFBRvCvXywlK0VFmkQpcLMsDb6CzgVsr4uxlm8e+Jsmjgc7ebYoVDNZu5flnt h4pE/rAyJqoHKJzf6dMW0ug2Zl2MILhMHY4fM= 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=nkHlKBHNcO4mG7XfvMpL+bqf1m84GCvR1iwc8zgfMcs=; b=Zpxn4UNzR1bwp2qgeQ+QwR1/zuA+cGkpVsGJA2sdMqlRbbRx1ltlO4P4AQlQ5+0wcz BmbII8xAEET7Q3LpGub6nEaF3nzeJUUfZgY93TXhPces0p9ivOdpOepdxJI3hZTRzLYv qaQK8acbg8QDVGZspcAfk0OyQk0EcGgiFu+bFdKS2Ciu25AKKEcoy3yToVY7hrFI3SNe XSo524XBWwtq2i3Pw2ZVwvGFU3qGDrA36hXwDf0/DP6vrE4l/H8/tcS9me4+TIdtwLtn XA2SoPz0587JydmsaV0f2btgzArVjF4OwyOWL+QEii9qx+m8DAlQpdCC+fQDCB89YQWi mqdg== X-Gm-Message-State: APzg51AQJ5XhnVdtAfveOb+VQ12RFUrEIXkUx3uefBLCUICfY3gKxUyi RirJ4YHnSj2EwWvefSn1Aq2lnw== X-Received: by 2002:a63:4425:: with SMTP id r37-v6mr26535263pga.391.1536649218429; Tue, 11 Sep 2018 00:00:18 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id m27-v6sm24363668pff.152.2018.09.11.00.00.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Sep 2018 00:00:17 -0700 (PDT) From: "Akashi, Takahiro" To: trini@konsulko.com Date: Tue, 11 Sep 2018 15:59:16 +0900 Message-Id: <20180911065922.19141-21-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 20/26] efi_loader: implement a file delete 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 'Delete' will be implemented here by calling fs_unlink() which relies on underlying file system's implementation. Signed-off-by: AKASHI Takahiro --- lib/efi_loader/efi_file.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/efi_loader/efi_file.c b/lib/efi_loader/efi_file.c index 6ec98c80227e..e726bb0eb2d2 100644 --- a/lib/efi_loader/efi_file.c +++ b/lib/efi_loader/efi_file.c @@ -229,9 +229,21 @@ static efi_status_t EFIAPI efi_file_close(struct efi_file_handle *file) static efi_status_t EFIAPI efi_file_delete(struct efi_file_handle *file) { struct file_handle *fh = to_fh(file); + efi_status_t ret = EFI_SUCCESS; + EFI_ENTRY("%p", file); + + if (set_blk_dev(fh)) { + ret = EFI_DEVICE_ERROR; + goto error; + } + + if (fs_unlink(fh->path)) + ret = EFI_DEVICE_ERROR; file_close(fh); - return EFI_EXIT(EFI_WARN_DELETE_FAILURE); + +error: + return EFI_EXIT(ret); } static efi_status_t file_read(struct file_handle *fh, u64 *buffer_size, From patchwork Tue Sep 11 06:59:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 146417 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3321707ljw; Tue, 11 Sep 2018 00:12:43 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZ5Ju2/BZTuz8n36B3lZAs/SkmGDL5qM6XJKVQW8NbkEq8v88h5rhIe6vxvpW3WAZTheGn0 X-Received: by 2002:a50:aed8:: with SMTP id f24-v6mr26647383edd.271.1536649963111; Tue, 11 Sep 2018 00:12:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536649963; cv=none; d=google.com; s=arc-20160816; b=AElj8ss4JkFPdkbGDGfkOXieDSKLbHC+gKNTX9se+4jdW5igR7ePUwGWXWlxReJJVY ch93SENV1EMaUrS+4hKkRh8dladV3nQ80bGiPr2AXFs2q3lccfByesKhApvDPO+ecSWU eKQU1V7JPgsnfX3qBrV56AKCfI9GlJeAMh7aM4gAQMkqLDPCizVoLSvERfI0DFU7C0Ru Ezjk4bDR9pnEqfnCKRmR2C/4G18jkEmvdhTvVU24U4e060E/4IZmJGLzwrY8wT+3s4yM TnYXBqqYzwnuDXF2sinBk7EOkv1yD2KL4uMlfDzHstcq8Gr17hlpqYkqw66o6/eOEG12 uSgw== 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=+JRX5sX+y4pLXZgm8sBpz5zSkgv8XFDwKA7PwnSOirs=; b=B0v5UJJxDP3nnAw6/6iB7GF2M4vRzJfa+jfbqiuybERQt1p8sfvx3m3JNezRUxzdvu 3lC3WyPhiIWWJAMwG2XzXVLnEG9NRPfW4m53hBxAUsfFuOyXim/wvHdmOxpSZ3PQpuGT 6fn++It6TCKez0caNRe9g4sT3+GZtjzV6b29IsdxxqtLx6Y5xSV0SycCtaEKivo0Z60F hhagNyEFL8QKYnIWWCmbPmpkUV4tts7E77IuaUScoOQeeVnVzyALX/NgoMGiwz1wYHzD M1P2gvKzkTLe8kHF4TDlEVBex2ip4F68OJ87nuveMJ92MUs791iW4+h6WStO/jtWiPP5 eJeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=g4i7vGRM; 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 a18-v6si523415edj.406.2018.09.11.00.12.42; Tue, 11 Sep 2018 00:12:43 -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=g4i7vGRM; 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 A39D0C21E70; Tue, 11 Sep 2018 07:07:45 +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 C1CCFC21F20; Tue, 11 Sep 2018 07:01:17 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id B1727C21F3C; Tue, 11 Sep 2018 07:00:28 +0000 (UTC) Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) by lists.denx.de (Postfix) with ESMTPS id D1497C21F16 for ; Tue, 11 Sep 2018 07:00:22 +0000 (UTC) Received: by mail-pg1-f196.google.com with SMTP id b129-v6so11733760pga.13 for ; Tue, 11 Sep 2018 00:00:22 -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=o3JMV0lnoneaj1DtKoRe4jrJRlJ+hoKxH0/BvxcDny4=; b=g4i7vGRMQdqeegHDNbuQpL61vKuJOc2UoupPpd69AN9k1IdajnR6kA5XtjK0tLdVwl /i5t6Av8pjnOGytzAAalSKaP9zcIe3vzZ1P+5zOfIBskWim9+Yhbe+gY+3isxgV18X2P uEUxVW/k9ywecQju1BoGO8Wfn3yVy+zBNF1G8= 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=o3JMV0lnoneaj1DtKoRe4jrJRlJ+hoKxH0/BvxcDny4=; b=HON6DdJRx8dwZ9t90mB3X1gWvFH8ZLJQ+ZYny+Q1pY+NOvoDjh5fcEHvPoRi4lvMtx btH0Iub3q0l2yQFdDm7J/WsId3cW/7ZVPYOX0Mw1PemSk2DNXEW7Tv5vg3sdgyuvjTOE 4NZOncmm3a+ro7EHKBqOY/SPpZMO6hlPVJmSbiLBkUNLZ57yfiDw/GBSWKGphNAXRyQL N8SY2vj/cRGHA1BXI7gyrJsrtzEDhXbYJYZAr4eyXlB4Zwvk0HQAO23ofPO/MlB5ho0a OHwpCbDXfM9O61DpsUPV11hbRZuJsreuNe8Z8fziUqtQj1JcOlu9eXzPfjFZrqjAt5jg 4DvA== X-Gm-Message-State: APzg51BRAWOtc2NfBo596eQ/Pa2HGUeHmK9apyYLPe8CtaEt/f9ML9L4 FY9I2bC+M5ryiLfVXMp0W5s3UjG0tOI= X-Received: by 2002:a62:25c5:: with SMTP id l188-v6mr27428188pfl.179.1536649221469; Tue, 11 Sep 2018 00:00:21 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id d9-v6sm29998687pfb.86.2018.09.11.00.00.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Sep 2018 00:00:20 -0700 (PDT) From: "Akashi, Takahiro" To: trini@konsulko.com Date: Tue, 11 Sep 2018 15:59:17 +0900 Message-Id: <20180911065922.19141-22-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 21/26] fs-test: fix false positive error at Test Case 12 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 The error message to be matched is wrong. Fix it. Signed-off-by: AKASHI Takahiro --- test/fs/fs-test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/fs/fs-test.sh b/test/fs/fs-test.sh index 9482239562ea..e002b9105131 100755 --- a/test/fs/fs-test.sh +++ b/test/fs/fs-test.sh @@ -522,7 +522,7 @@ function check_results() { "TC11: 1MB write to $3.w - content verified" # Check lookup of 'dot' directory - grep -A4 "Test Case 12 " "$1" | grep -q 'Unable to write file' + grep -A4 "Test Case 12 " "$1" | grep -q 'Unable to write' pass_fail "TC12: 1MB write to . - write denied" # Check directory traversal From patchwork Tue Sep 11 06:59:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 146419 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3322209ljw; Tue, 11 Sep 2018 00:13:12 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYWoxsRT7hgyXHgFa6cANpUf/4ZM2ViFUpC2f4buKndxks1ueX3GWsdf7WpmSccMsdQWKvY X-Received: by 2002:a50:b544:: with SMTP id z4-v6mr27680251edd.219.1536649992073; Tue, 11 Sep 2018 00:13:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536649992; cv=none; d=google.com; s=arc-20160816; b=pprJMpNKwCJFpZTFpZZwEi6FEhRLJv2FXI5fCyF5AX6orZ19OcxZinBQM1Ji/Z6stq RERh6k5dObmpKzkBs+UeFTzMNLkW1Xs0EltKGRl51HgtoV1nYZGqjRlwcyVUcJlbRXMB Ye1QYH7o6xG7fyh6VCzgFLuAOZfq7YHx8+Sygh6q+upJEK5nGDev/kJuOLHRxkzQofxA IQxONJd3JyLPmIHd70uLIpGnfojyiht7BaAyorq7oyyJ9UGlQfNoNz+65MMnvkV2bpv7 nVvqdLZSzNXJrkxhlsQajV25qgrBa21tkjqzBw633dEgYeJNF9MwAFPq3Rb/RAEMAhbM mR+A== 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=wwzNAUT1voelaZ27r2rE7VykdjmptaCH7sVhsiripFc=; b=EPAvzuuYaeGYfucRSJsZrssSr6v7gIe8FpchpvZcLx5Il62vi0rSmdqS18Iri/BjwQ NQvmLxulVKmNBOL3HadcV3u1ar1ItxHaLT6owULathtnj2k4vxcePfZI/ia3ncAtjjoi iVQdoy/yHM+seJpwFDHRdG8IITLoKhpUgRak5SM0NcaVKTTiFvEF8wwPc6bdEwmK3O0b 3KbpE6U9kNy2k9h9V6y2OaLb/GueTCEDA46iHWYjdcw5NGiUZlVX8tksgsuF20x52gUE vx1vfPgPcS409qxK57FLtDOwP9wDcBFJY+5FHJB4iHbppa0uO1owo3wp5dpA3JLMPWp/ uLVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=CmPN7rfk; 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 u35-v6si565715edc.308.2018.09.11.00.13.11; Tue, 11 Sep 2018 00:13:12 -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=CmPN7rfk; 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 E6D40C21F0C; Tue, 11 Sep 2018 07:08:38 +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 E4F8EC21F3E; Tue, 11 Sep 2018 07:01:29 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id F1AC8C21F18; Tue, 11 Sep 2018 07:00:32 +0000 (UTC) Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com [209.85.210.195]) by lists.denx.de (Postfix) with ESMTPS id 92FB1C21EFF for ; Tue, 11 Sep 2018 07:00:27 +0000 (UTC) Received: by mail-pf1-f195.google.com with SMTP id j26-v6so11735400pfi.10 for ; Tue, 11 Sep 2018 00:00:27 -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=V+DEty+ZWzwXBpRGpzTru8AZis5u3RuK2RuSqQQmMcg=; b=CmPN7rfkw7/jb4iu0sUTlMn7PN4Fk/wJk4FC799ETeuPBqM99RQAr/X5bMDqBLRPFR 3voQUqjrVoV8MWnL8fne9qXl09/skUj9oAewzug37ayd/jBcXgyg2us9HTRxs26rGPku jckckDKHWeMuKaNSRVa1qkX8ZDTj2/xG9NOPw= 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=V+DEty+ZWzwXBpRGpzTru8AZis5u3RuK2RuSqQQmMcg=; b=hT3Qs1Ki7NXBqNiD91rLQwPybGHHQBW+OmjBE//FZbvy9KD32xk5BC83WMaVcFlcJC /JJghgZA8G2JWZ3HKy4so7UEMVBxRREHeqavRcA4KzZcHHS51Oo8AK4ruQgdXIlgoEvY 8uO/9z5MxxRNo4bbtaGnjIgNovnG8MRQNRu8Cxd/XXEjy6kt7J4V2SLgwCWdv3U60Sv5 XaFdk2c/6pYpu/RhL5eRWXJWu8xHjLMSFbjtMAbD3ERaOZIClQv3PWqBtbMe3sg3YsJv VQ/8H251rSJMtx5MavhL54kximIdccFVh47h/KLrHRyccFnRa0J12VwcDVysJoLKFdWA VzuA== X-Gm-Message-State: APzg51APVkLTrdFOJQYdsb3K+LSijzpqKMPnWvS/YOJJ2RQjmLb0XWRQ 2aOKhB7RJbmBVpMLBOjEV13BdQ== X-Received: by 2002:a63:eb53:: with SMTP id b19-v6mr26559917pgk.371.1536649226170; Tue, 11 Sep 2018 00:00:26 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id x23-v6sm39267767pff.9.2018.09.11.00.00.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Sep 2018 00:00:25 -0700 (PDT) From: "Akashi, Takahiro" To: trini@konsulko.com Date: Tue, 11 Sep 2018 15:59:18 +0900 Message-Id: <20180911065922.19141-23-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 22/26] fs-test: update the test result as of v2018.09 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 As far as this patch series has been applied, all the tests should pass. So update the test result summary. Signed-off-by: AKASHI Takahiro --- test/fs/fs-test.sh | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/test/fs/fs-test.sh b/test/fs/fs-test.sh index e002b9105131..86308cfe2dbd 100755 --- a/test/fs/fs-test.sh +++ b/test/fs/fs-test.sh @@ -7,18 +7,20 @@ # It currently tests the fs/sb and native commands for ext4 and fat partitions # Expected results are as follows: # EXT4 tests: -# fs-test.sb.ext4.out: Summary: PASS: 24 FAIL: 0 -# fs-test.ext4.out: Summary: PASS: 24 FAIL: 0 -# fs-test.fs.ext4.out: Summary: PASS: 24 FAIL: 0 +# fs-test.sb.ext4 Summary: PASS: 24 FAIL: 0 +# fs-test.nonfs.ext4 Summary: PASS: 24 FAIL: 0 +# fs-test.fs.ext4 Summary: PASS: 24 FAIL: 0 # FAT16 tests: -# fs-test.sb.fat16.out: Summary: PASS: 24 FAIL: 0 -# fs-test.fat16.out: Summary: PASS: 20 FAIL: 4 -# fs-test.fs.fat16.out: Summary: PASS: 20 FAIL: 4 +# fs-test.sb.fat16 Summary: PASS: 24 FAIL: 0 +# fs-test.nonfs.fat16 Summary: PASS: 24 FAIL: 0 +# fs-test.fs.fat16 Summary: PASS: 24 FAIL: 0 # FAT32 tests: -# fs-test.sb.fat32.out: Summary: PASS: 24 FAIL: 0 -# fs-test.fat32.out: Summary: PASS: 20 FAIL: 4 -# fs-test.fs.fat32.out: Summary: PASS: 20 FAIL: 4 -# Total Summary: TOTAL PASS: 200 TOTAL FAIL: 16 +# fs-test.sb.fat32 Summary: PASS: 24 FAIL: 0 +# fs-test.nonfs.fat32 Summary: PASS: 24 FAIL: 0 +# fs-test.fs.fat32 Summary: PASS: 24 FAIL: 0 +# -------------------------------------------- +# Total Summary: TOTAL PASS: 216 TOTAL FAIL: 0 +# -------------------------------------------- # pre-requisite binaries list. PREREQ_BINS="md5sum mkfs mount umount dd fallocate mkdir" From patchwork Tue Sep 11 06:59:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 146422 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3324156ljw; Tue, 11 Sep 2018 00:15:47 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaqqDvf6jlns479m+ythyvI6LUOgE5DsC/BLx/bXor3T3NSpqTXk8wIpEc42lPaUNbIMzHX X-Received: by 2002:a50:8843:: with SMTP id c3-v6mr26441881edc.146.1536650147111; Tue, 11 Sep 2018 00:15:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536650147; cv=none; d=google.com; s=arc-20160816; b=r8pHXGOQyZPGQXQBOGeNB5PVnDghY7voeIV48nEdeTcpgDz3rUOVXsoaNm84GxsGTZ 2dwJQi+AZnxC9TYh5FBIMuiNMvnZzNChh3O46P4TADcG/ayXKEavPF9+vNKnO3baEJme vDmefeeI3pXA/hwGhvXAC9Xl+N+mYlOdSNswH+oATvgirXZhwbKLzE8B1nparmcPZtAP AgGRbAZXwHiybibWjf+nCWhnukEJILHTDDzXTC8UHk46gNtXkmsAYu1FcqTapFgxOAkz zsg0ukWDwNButqV/+Ain5n6GByi3WaOruHTgYgM991qwPDPucioAGi61yeuuldACaZgh mBPg== 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=2CoFrq2caE65sBRWphB087wfJIv+61NpJkdpJaFHmvI=; b=euAjy6VG48J876AbKG9d1mboh7xy/jhcbJmn/MY6m32Cl2fbfmJO0KBv+ZRRfWp2Ee 8Pm7DkSl5W0jA9gMAtXrm+lt6F5+NPFVic9aI93bnoNxxY4kUZxFFA5LDkdJU+xPEXOP Qy0VCMILEFJNVQNzYKltNiKSOlaTBbC1JFuQzMdoXvlDMfSOQk619378CT0OZpZa8+8J +urBTJDJP/8AI8+GHCRP7hlFtURJHCu59hdMunlQpPeRcmLstRRWWnWVwQZkRqzLE3Um 8qUKcEF7bKPDPwYL2qJk/itjG3MOXJYIBTmmhwt5Eo+RqEMZQmvdoReOZHYEFMPnJJbt n92Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=fDICnzRz; 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 x33-v6si1057358ede.8.2018.09.11.00.15.46; Tue, 11 Sep 2018 00:15:47 -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=fDICnzRz; 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 B5272C21F00; Tue, 11 Sep 2018 07:10:35 +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 3C41CC21EB4; Tue, 11 Sep 2018 07:02:54 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id A561FC21E7D; Tue, 11 Sep 2018 07:00:37 +0000 (UTC) Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com [209.85.210.195]) by lists.denx.de (Postfix) with ESMTPS id 32DE6C21E75 for ; Tue, 11 Sep 2018 07:00:32 +0000 (UTC) Received: by mail-pf1-f195.google.com with SMTP id k21-v6so11726343pff.11 for ; Tue, 11 Sep 2018 00:00:32 -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=ijyZT1WN4WUl32wlTiOMXgY6KrqWJsJl4kPK/dIc6/U=; b=fDICnzRzyTVD2CDtH5usbQysB9p1PUFQ8KkqOB31XtKc9l5FfbFhoz6OGlU2QxCHXy Ysdm4pc7HZRRBWIt6OM52gVK6wtOtnBzr/B/o4F7K4wqR4rB4YV/tBgXUEC0iWdvfqgK hhU30/KQeDjtid64s9ghMt9FrZlAquySCDKxI= 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=ijyZT1WN4WUl32wlTiOMXgY6KrqWJsJl4kPK/dIc6/U=; b=SUg2dhXvww4fFDLNsQ8X6iQu4U3xNUseusyuDJkE8uhl7NsZWLmiSKFNuoAIaY2tsF 3xFF/HnNOP2AYstoEPcwRd1TfbAXT6TtA3D6resIp77/fkbcjowywtUm2jRNmNu5fRvK u6zwHtRFlpfaO3QbDC6w+GdCuQA51MIEz0pFsQA9enaLYrVueYnT0QmmjNQ439k+r5fs EU5SU67HQ4O2hMsmEs378uJEW+kayRIpLG2S9jJxZTek9mCQqitrU8NTsG1AnaY6Ibkm nVdxUPn+o3CxJUha+w8Pva/BrAmMOPP2iCy8LTYwggjwiXPLGbgKOlh2Mpayh1/5IM9t O3NA== X-Gm-Message-State: APzg51BRDj4G6a9LluhKZIEpU/UUb+BJCFPWSNUuXrepXs/QN3GoRpkU e4UmUSMstRN/SfFafXNqSSiB5w== X-Received: by 2002:a63:d806:: with SMTP id b6-v6mr26230010pgh.347.1536649230510; Tue, 11 Sep 2018 00:00:30 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id l3-v6sm21561001pff.8.2018.09.11.00.00.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Sep 2018 00:00:29 -0700 (PDT) From: "Akashi, Takahiro" To: trini@konsulko.com Date: Tue, 11 Sep 2018 15:59:19 +0900 Message-Id: <20180911065922.19141-24-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 23/26] test/py: convert fs-test.sh to pytest 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 In this commit, the same set of test cases as in test/fs/fs-test.sh is provided using pytest framework. Actually, fs-test.sh provides three variants:"sb" (sb command), "nonfs" (fatxx and etc.) and "fs" (hostfs), and this patch currently supports only "nonfs" variant; So it is not a replacement of fs-test.sh for now. Simple usage: $ py.test test/py/tests/test_fs [] You may also specify filesystem types to be tested: $ py.test test/py/tests/test_fs --fs-type fat32 [] Signed-off-by: AKASHI Takahiro --- test/py/tests/test_fs/conftest.py | 218 ++++++++++++++++++++ test/py/tests/test_fs/fstest_defs.py | 10 + test/py/tests/test_fs/test_basic.py | 287 +++++++++++++++++++++++++++ 3 files changed, 515 insertions(+) create mode 100644 test/py/tests/test_fs/conftest.py create mode 100644 test/py/tests/test_fs/fstest_defs.py create mode 100644 test/py/tests/test_fs/test_basic.py diff --git a/test/py/tests/test_fs/conftest.py b/test/py/tests/test_fs/conftest.py new file mode 100644 index 000000000000..3437accc971f --- /dev/null +++ b/test/py/tests/test_fs/conftest.py @@ -0,0 +1,218 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright (c) 2018, Linaro Limited +# Author: Takahiro Akashi + +import os +import os.path +import pytest +import re +from subprocess import call, check_call, check_output, CalledProcessError +from fstest_defs import * + +supported_fs_basic = ['fat16', 'fat32', 'ext4'] + +# +# Filesystem test specific setup +# +def pytest_addoption(parser): + parser.addoption('--fs-type', action='append', default=None, + help='Targeting Filesystem Types') + +def pytest_configure(config): + global supported_fs_basic + + def intersect(listA, listB): + return [x for x in listA if x in listB] + + supported_fs = config.getoption('fs_type') + if supported_fs: + print("*** FS TYPE modified: %s" % supported_fs) + supported_fs_basic = intersect(supported_fs, supported_fs_basic) + +def pytest_generate_tests(metafunc): + if 'fs_obj_basic' in metafunc.fixturenames: + metafunc.parametrize('fs_obj_basic', supported_fs_basic, + indirect=True, scope='module') + +# +# Helper functions +# +def fstype_to_ubname(fs_type): + if re.match('fat', fs_type): + return 'fat' + else: + return fs_type + +def check_ubconfig(config, fs_type): + if not config.buildconfig.get('config_cmd_%s' % fs_type, None): + pytest.skip('.config feature "CMD_%s" not enabled' % fs_type.upper()) + if not config.buildconfig.get('config_%s_write' % fs_type, None): + pytest.skip('.config feature "%s_WRITE" not enabled' + % fs_type.upper()) + +def mk_fs(config, fs_type, size, id): + fs_img = '%s.%s.img' % (id, fs_type) + fs_img = config.persistent_data_dir + '/' + fs_img + + if fs_type == 'fat16': + mkfs_opt = '-F 16' + elif fs_type == 'fat32': + mkfs_opt = '-F 32' + else: + mkfs_opt = '' + + if re.match('fat', fs_type): + fs_lnxtype = 'vfat' + else: + fs_lnxtype = fs_type + + count = (size + 1048576 - 1) / 1048576 + + try: + check_call('rm -f %s' % fs_img, shell=True) + check_call('dd if=/dev/zero of=%s bs=1M count=%d' + % (fs_img, count), shell=True) + check_call('mkfs.%s %s %s' + % (fs_lnxtype, mkfs_opt, fs_img), shell=True) + return fs_img + except CalledProcessError: + call('rm -f %s' % fs_img, shell=True) + raise + +# from test/py/conftest.py +def tool_is_in_path(tool): + for path in os.environ["PATH"].split(os.pathsep): + fn = os.path.join(path, tool) + if os.path.isfile(fn) and os.access(fn, os.X_OK): + return True + return False + +fuse_mounted = False + +def mount_fs(fs_type, device, mount_point): + global fuse_mounted + + fuse_mounted = False + try: + if tool_is_in_path('guestmount'): + fuse_mounted = True + check_call('guestmount -a %s -m /dev/sda %s' + % (device, mount_point), shell=True) + else: + mount_opt = "loop,rw" + if re.match('fat', fs_type): + mount_opt += ",umask=0000" + + check_call('sudo mount -o %s %s %s' + % (mount_opt, device, mount_point), shell=True) + + # may not be effective for some file systems + check_call('sudo chmod a+rw %s' % mount_point, shell=True) + except CalledProcessError: + raise + +def umount_fs(fs_type, mount_point): + if fuse_mounted: + call('sync') + call('guestunmount %s' % mount_point, shell=True) + else: + call('sudo umount %s' % mount_point, shell=True) + +# +# Fixture for basic fs test +# derived from test/fs/fs-test.sh +# +# NOTE: yield_fixture was deprecated since pytest-3.0 +@pytest.yield_fixture() +def fs_obj_basic(request, u_boot_config): + fs_type = request.param + fs_img = '' + + fs_ubtype = fstype_to_ubname(fs_type) + check_ubconfig(u_boot_config, fs_ubtype) + + mount_dir = u_boot_config.persistent_data_dir + '/mnt' + + small_file = mount_dir + '/' + SMALL_FILE + big_file = mount_dir + '/' + BIG_FILE + + try: + + # 3GiB volume + fs_img = mk_fs(u_boot_config, fs_type, 0xc0000000, '3GB') + + # Mount the image so we can populate it. + check_call('mkdir -p %s' % mount_dir, shell=True) + mount_fs(fs_type, fs_img, mount_dir) + + # Create a subdirectory. + check_call('mkdir %s/SUBDIR' % mount_dir, shell=True) + + # Create big file in this image. + # Note that we work only on the start 1MB, couple MBs in the 2GB range + # and the last 1 MB of the huge 2.5GB file. + # So, just put random values only in those areas. + check_call('dd if=/dev/urandom of=%s bs=1M count=1' + % big_file, shell=True) + check_call('dd if=/dev/urandom of=%s bs=1M count=2 seek=2047' + % big_file, shell=True) + check_call('dd if=/dev/urandom of=%s bs=1M count=1 seek=2499' + % big_file, shell=True) + + # Create a small file in this image. + check_call('dd if=/dev/urandom of=%s bs=1M count=1' + % small_file, shell=True) + + # Delete the small file copies which possibly are written as part of a + # previous test. + # check_call('rm -f "%s.w"' % MB1, shell=True) + # check_call('rm -f "%s.w2"' % MB1, shell=True) + + # Generate the md5sums of reads that we will test against small file + out = check_output( + 'dd if=%s bs=1M skip=0 count=1 2> /dev/null | md5sum' + % small_file, shell=True) + md5val = [ out.split()[0] ] + + # Generate the md5sums of reads that we will test against big file + # One from beginning of file. + out = check_output( + 'dd if=%s bs=1M skip=0 count=1 2> /dev/null | md5sum' + % big_file, shell=True) + md5val.append(out.split()[0]) + + # One from end of file. + out = check_output( + 'dd if=%s bs=1M skip=2499 count=1 2> /dev/null | md5sum' + % big_file, shell=True) + md5val.append(out.split()[0]) + + # One from the last 1MB chunk of 2GB + out = check_output( + 'dd if=%s bs=1M skip=2047 count=1 2> /dev/null | md5sum' + % big_file, shell=True) + md5val.append(out.split()[0]) + + # One from the start 1MB chunk from 2GB + out = check_output( + 'dd if=%s bs=1M skip=2048 count=1 2> /dev/null | md5sum' + % big_file, shell=True) + md5val.append(out.split()[0]) + + # One 1MB chunk crossing the 2GB boundary + out = check_output( + 'dd if=%s bs=512K skip=4095 count=2 2> /dev/null | md5sum' + % big_file, shell=True) + md5val.append(out.split()[0]) + + umount_fs(fs_type, mount_dir) + except CalledProcessError: + pytest.skip('Setup failed for filesystem: ' + fs_type) + return + else: + yield [fs_ubtype, fs_img, md5val] + finally: + umount_fs(fs_type, mount_dir) + call('rmdir %s' % mount_dir, shell=True) + if fs_img: + call('rm -f %s' % fs_img, shell=True) diff --git a/test/py/tests/test_fs/fstest_defs.py b/test/py/tests/test_fs/fstest_defs.py new file mode 100644 index 000000000000..f26dd06cacf2 --- /dev/null +++ b/test/py/tests/test_fs/fstest_defs.py @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0+ + +# $SMALL_FILE is the name of the 1MB file in the file system image +SMALL_FILE='1MB.file' + +# $BIG_FILE is the name of the 2.5GB file in the file system image +BIG_FILE='2.5GB.file' + +ADDR=0x01000008 +LENGTH=0x00100000 diff --git a/test/py/tests/test_fs/test_basic.py b/test/py/tests/test_fs/test_basic.py new file mode 100644 index 000000000000..c067cc9ba3f6 --- /dev/null +++ b/test/py/tests/test_fs/test_basic.py @@ -0,0 +1,287 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright (c) 2018, Linaro Limited +# Author: Takahiro Akashi +# +# U-Boot File System:Basic Test + +""" +This test verifies basic read/write operation on file system. +""" + +import pytest +import re +from fstest_defs import * + +@pytest.mark.boardspec('sandbox') +class TestFsBasic(object): + def test_fs1(self, u_boot_console, fs_obj_basic): + """ + Test Case 1 - ls command, listing a root directory and invalid directory + """ + fs_type,fs_img,md5val = fs_obj_basic + with u_boot_console.log.section('Test Case 1a - ls'): + # Test Case 1 - ls + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % fs_img, + '%sls host 0:0' % fs_type]) + assert(re.search('2621440000 *%s' % BIG_FILE, ''.join(output))) + assert(re.search('1048576 *%s' % SMALL_FILE, ''.join(output))) + + with u_boot_console.log.section('Test Case 1b - ls (invalid dir)'): + # In addition, test with a nonexistent directory to see if we crash. + output = u_boot_console.run_command( + '%sls host 0:0 invalid_d' % fs_type) + if fs_type == 'ext4': + assert('Can not find directory' in output) + else: + assert('' == output) + + def test_fs2(self, u_boot_console, fs_obj_basic): + """ + Test Case 2 - size command for a small file + """ + fs_type,fs_img,md5val = fs_obj_basic + with u_boot_console.log.section('Test Case 2a - size (small)'): + # 1MB is 0x0010 0000 + # Test Case 2a - size of small file + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % fs_img, + '%ssize host 0:0 /%s' % (fs_type, SMALL_FILE), + 'printenv filesize', + 'setenv filesize']) + assert('filesize=100000' in ''.join(output)) + + with u_boot_console.log.section('Test Case 2b - size (/../)'): + # Test Case 2b - size of small file via a path using '..' + output = u_boot_console.run_command_list([ + '%ssize host 0:0 /SUBDIR/../%s' % (fs_type, SMALL_FILE), + 'printenv filesize', + 'setenv filesize']) + assert('filesize=100000' in ''.join(output)) + + def test_fs3(self, u_boot_console, fs_obj_basic): + """ + Test Case 3 - size command for a large file + """ + fs_type,fs_img,md5val = fs_obj_basic + with u_boot_console.log.section('Test Case 3 - size (large)'): + # 2.5GB (1024*1024*2500) is 0x9C40 0000 + # Test Case 3 - size of big file + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % fs_img, + '%ssize host 0:0 /%s' % (fs_type, BIG_FILE), + 'printenv filesize', + 'setenv filesize']) + assert('filesize=9c400000' in ''.join(output)) + + def test_fs4(self, u_boot_console, fs_obj_basic): + """ + Test Case 4 - load a small file, 1MB + """ + fs_type,fs_img,md5val = fs_obj_basic + with u_boot_console.log.section('Test Case 4 - load (small)'): + # Test Case 4a - Read full 1MB of small file + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % fs_img, + '%sload host 0:0 %x /%s' % (fs_type, ADDR, SMALL_FILE), + 'printenv filesize']) + assert('filesize=100000' in ''.join(output)) + + # Test Case 4b - Read full 1MB of small file + output = u_boot_console.run_command_list([ + 'md5sum %x $filesize' % ADDR, + 'setenv filesize']) + assert(md5val[0] in ''.join(output)) + + def test_fs5(self, u_boot_console, fs_obj_basic): + """ + Test Case 5 - load, reading first 1MB of 3GB file + """ + fs_type,fs_img,md5val = fs_obj_basic + with u_boot_console.log.section('Test Case 5 - load (first 1MB)'): + # Test Case 5a - First 1MB of big file + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % fs_img, + '%sload host 0:0 %x /%s %x 0x0' % (fs_type, ADDR, BIG_FILE, LENGTH), + 'printenv filesize']) + assert('filesize=100000' in ''.join(output)) + + # Test Case 5b - First 1MB of big file + output = u_boot_console.run_command_list([ + 'md5sum %x $filesize' % ADDR, + 'setenv filesize']) + assert(md5val[1] in ''.join(output)) + + def test_fs6(self, u_boot_console, fs_obj_basic): + """ + Test Case 6 - load, reading last 1MB of 3GB file + """ + fs_type,fs_img,md5val = fs_obj_basic + with u_boot_console.log.section('Test Case 6 - load (last 1MB)'): + # fails for ext as no offset support + # Test Case 6a - Last 1MB of big file + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % fs_img, + '%sload host 0:0 %x /%s %x 0x9c300000' + % (fs_type, ADDR, BIG_FILE, LENGTH), + 'printenv filesize']) + assert('filesize=100000' in ''.join(output)) + + # Test Case 6b - Last 1MB of big file + output = u_boot_console.run_command_list([ + 'md5sum %x $filesize' % ADDR, + 'setenv filesize']) + assert(md5val[2] in ''.join(output)) + + def test_fs7(self, u_boot_console, fs_obj_basic): + """ + Test Case 7 - load, 1MB from the last 1MB in 2GB + """ + fs_type,fs_img,md5val = fs_obj_basic + with u_boot_console.log.section('Test Case 7 - load (last 1MB in 2GB)'): + # fails for ext as no offset support + # Test Case 7a - One from the last 1MB chunk of 2GB + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % fs_img, + '%sload host 0:0 %x /%s %x 0x7ff00000' + % (fs_type, ADDR, BIG_FILE, LENGTH), + 'printenv filesize']) + assert('filesize=100000' in ''.join(output)) + + # Test Case 7b - One from the last 1MB chunk of 2GB + output = u_boot_console.run_command_list([ + 'md5sum %x $filesize' % ADDR, + 'setenv filesize']) + assert(md5val[3] in ''.join(output)) + + def test_fs8(self, u_boot_console, fs_obj_basic): + """ + Test Case 8 - load, reading first 1MB in 2GB + """ + fs_type,fs_img,md5val = fs_obj_basic + with u_boot_console.log.section('Test Case 8 - load (first 1MB in 2GB)'): + # fails for ext as no offset support + # Test Case 8a - One from the start 1MB chunk from 2GB + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % fs_img, + '%sload host 0:0 %x /%s %x 0x80000000' + % (fs_type, ADDR, BIG_FILE, LENGTH), + 'printenv filesize']) + assert('filesize=100000' in ''.join(output)) + + # Test Case 8b - One from the start 1MB chunk from 2GB + output = u_boot_console.run_command_list([ + 'md5sum %x $filesize' % ADDR, + 'setenv filesize']) + assert(md5val[4] in ''.join(output)) + + def test_fs9(self, u_boot_console, fs_obj_basic): + """ + Test Case 9 - load, 1MB crossing 2GB boundary + """ + fs_type,fs_img,md5val = fs_obj_basic + with u_boot_console.log.section('Test Case 9 - load (crossing 2GB boundary)'): + # fails for ext as no offset support + # Test Case 9a - One 1MB chunk crossing the 2GB boundary + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % fs_img, + '%sload host 0:0 %x /%s %x 0x7ff80000' + % (fs_type, ADDR, BIG_FILE, LENGTH), + 'printenv filesize']) + assert('filesize=100000' in ''.join(output)) + + # Test Case 9b - One 1MB chunk crossing the 2GB boundary + output = u_boot_console.run_command_list([ + 'md5sum %x $filesize' % ADDR, + 'setenv filesize']) + assert(md5val[5] in ''.join(output)) + + def test_fs10(self, u_boot_console, fs_obj_basic): + """ + Test Case 10 - load, reading beyond file end'): + """ + fs_type,fs_img,md5val = fs_obj_basic + with u_boot_console.log.section('Test Case 10 - load (beyond file end)'): + # Generic failure case + # Test Case 10 - 2MB chunk from the last 1MB of big file + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % fs_img, + '%sload host 0:0 %x /%s 0x00200000 0x9c300000' + % (fs_type, ADDR, BIG_FILE), + 'printenv filesize', + 'md5sum %x $filesize' % ADDR, + 'setenv filesize']) + assert('filesize=100000' in ''.join(output)) + + def test_fs11(self, u_boot_console, fs_obj_basic): + """ + Test Case 11 - write' + """ + fs_type,fs_img,md5val = fs_obj_basic + with u_boot_console.log.section('Test Case 11 - write'): + # Read 1MB from small file + # Write it back to test the writes + # Test Case 11a - Check that the write succeeded + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % fs_img, + '%sload host 0:0 %x /%s' % (fs_type, ADDR, SMALL_FILE), + '%swrite host 0:0 %x /%s.w $filesize' + % (fs_type, ADDR, SMALL_FILE)]) + assert('1048576 bytes written' in ''.join(output)) + + # Test Case 11b - Check md5 of written to is same + # as the one read from + output = u_boot_console.run_command_list([ + '%sload host 0:0 %x /%s.w' % (fs_type, ADDR, SMALL_FILE), + 'md5sum %x $filesize' % ADDR, + 'setenv filesize']) + assert(md5val[0] in ''.join(output)) + + def test_fs12(self, u_boot_console, fs_obj_basic): + """ + Test Case 12 - write to "." directory + """ + fs_type,fs_img,md5val = fs_obj_basic + with u_boot_console.log.section('Test Case 12 - write (".")'): + # Next test case checks writing a file whose dirent + # is the first in the block, which is always true for "." + # The write should fail, but the lookup should work + # Test Case 12 - Check directory traversal + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % fs_img, + '%swrite host 0:0 %x /. 0x10' % (fs_type, ADDR)]) + assert('Unable to write' in ''.join(output)) + + def test_fs13(self, u_boot_console, fs_obj_basic): + """ + Test Case 13 - write to a file with "/./" + """ + fs_type,fs_img,md5val = fs_obj_basic + with u_boot_console.log.section('Test Case 13 - write ("./")'): + # Read 1MB from small file + # Write it via "same directory", i.e. "." dirent + # Test Case 13a - Check directory traversal + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % fs_img, + '%sload host 0:0 %x /%s' % (fs_type, ADDR, SMALL_FILE), + '%swrite host 0:0 %x /./%s2 $filesize' + % (fs_type, ADDR, SMALL_FILE)]) + assert('1048576 bytes written' in ''.join(output)) + + # Test Case 13b - Check md5 of written to is same + # as the one read from + output = u_boot_console.run_command_list([ + 'mw.b %x 00 100' % ADDR, + '%sload host 0:0 %x /./%s2' % (fs_type, ADDR, SMALL_FILE), + 'md5sum %x $filesize' % ADDR, + 'setenv filesize']) + assert(md5val[0] in ''.join(output)) + + # Test Case 13c - Check md5 of written to is same + # as the one read from + output = u_boot_console.run_command_list([ + 'mw.b %x 00 100' % ADDR, + '%sload host 0:0 %x /%s2' % (fs_type, ADDR, SMALL_FILE), + 'md5sum %x $filesize' % ADDR, + 'setenv filesize']) + assert(md5val[0] in ''.join(output)) From patchwork Tue Sep 11 06:59:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 146421 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3324130ljw; Tue, 11 Sep 2018 00:15:45 -0700 (PDT) X-Google-Smtp-Source: ANB0VdamnRRXqVf93559VlMLbWKY9A9mZ+WFMIDmrUt9bdWA29UrU0N+z6AJaRw+0FV54fdFmidV X-Received: by 2002:a50:9935:: with SMTP id k50-v6mr27399234edb.175.1536650145256; Tue, 11 Sep 2018 00:15:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536650145; cv=none; d=google.com; s=arc-20160816; b=jNJ+vQCtZRo/kGeN3HjmeKNAZFKBpICYB5x/zSwb7szgjuoHKAh+ZyDVjHIV43b6sp tFvnhhhu3qbzi/Ql8n7LzRnQz+BT/Ag3bGeTZSH1oFCKNC8d7EUC5GIy22EateyjEStM ILJGTtgcQJeSuojwrPXzCzLL7R/sj5d42B+qNQSmXRdwLv1z238m5U6Mxzd5ybLPDEsU hNJ7+zPqaIq9B/SnTnzeQIyU7BalllvBB63DI70wJyHKKS8m63OSX9ZaX008CcI6yyn1 UvTGYUoMOokitAdUD7vPQpqSo5SJf06b65O0k5dqzVbeJszwE1+uD5BNGl2NXYWM3q0h m4RQ== 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=nMcp4kVVDTSK83JK5jl7VSgukqVebUGxBUAoISDWGtc=; b=agwuUsJ2RBLzdb+3fQS21YR9/ivz/xipvE0C+maHEaUQc4RuVrBCNahRzbCFMBTD7R Kh6JvFTP4+GDuBfHu+H2Vt6Q6A/tmzvMvq0wAlIVCfQxX7jrNjc5WHTO5cKrXTNT5nRz Nb8Glpowl9fj5e4+mJptpJujokFItSXGtJKkwTtYmxo8xdGldT87PBLb8ThYbGLWldXx oUtU3IkFydjSa8ca7Q86/BQ2ra8K0z/4CO3izCwYIpFpayF9j5LnMSLJvyLks9NMkQMy v5uX5WTXwvbf3imUFHIoxOrR2WScRPxv/utuoY88kc4TuO7sfegnEm+MqeXIwL6L49Xw jZdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=bCmEaeO0; 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-v6si5433615edd.224.2018.09.11.00.15.44; Tue, 11 Sep 2018 00:15:45 -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=bCmEaeO0; 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 6750FC21F07; Tue, 11 Sep 2018 07:09:58 +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 7D706C21EC2; Tue, 11 Sep 2018 07:02:15 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 83ADEC21E68; Tue, 11 Sep 2018 07:00:46 +0000 (UTC) Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) by lists.denx.de (Postfix) with ESMTPS id 138DBC21E44 for ; Tue, 11 Sep 2018 07:00:36 +0000 (UTC) Received: by mail-pg1-f180.google.com with SMTP id 7-v6so11768393pgf.2 for ; Tue, 11 Sep 2018 00:00:36 -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=Dp75uk4iU3CL26gUSfT2sXhsiJneQggyEfxWzbsdbhE=; b=bCmEaeO0w2VVtkpyifWc89viQZ9SB+xQ16FAbxnOv4C1tn5iBATHbU7rhlE4vsnNyi sObAaIhri8s+02QAA1FOcHbRl73ZAv44CPRsLU7bUxbA3YzyO1cDQjLj0VHVT9+kXNhs 4LnqGcNIVvbe07YuPcPdApV0myFVkkWzABcJA= 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=Dp75uk4iU3CL26gUSfT2sXhsiJneQggyEfxWzbsdbhE=; b=oXsbJ1Te2haoBA1bFayO0qzjd0mIdENKS+RTUVtqSVKwqGCUzhJYvVqhwk4Bh17nlV OxjHgxfCX/Jom9fDAry5YvF15jMgd7iY7AFU23HaobTo6VpzdgeQt3vFdhM8LYxU7EfU JsT2ksTK5HzZwd7JNh9w8bUmgZj4cNQOqDEW8mrhz+9j2tmA8U0KxPZxKxw+he3XOojf 6kENdVeL3dDYHsGU1+f7AQUrZN8XcOTv6r3K4j2aomaqLzG/aoq0ZqsYU2c/BuOI1wmi uaRbWy1CU70Z60DBq5jGPqJe58RjWDNjSg91/EvKRZ40OtocBqiFBOjXhUrKQVi5nFT3 sN7w== X-Gm-Message-State: APzg51AI0F1YZeK5HEyeWpd3rU+uFSj0xtQKWr4iW5qygOFY28rZGh8Q BaK4rTU5kPFdGOz9CXK7H7QG8g== X-Received: by 2002:a63:9244:: with SMTP id s4-v6mr26139074pgn.141.1536649234526; Tue, 11 Sep 2018 00:00:34 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id a15-v6sm31107686pfe.32.2018.09.11.00.00.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Sep 2018 00:00:33 -0700 (PDT) From: "Akashi, Takahiro" To: trini@konsulko.com Date: Tue, 11 Sep 2018 15:59:20 +0900 Message-Id: <20180911065922.19141-25-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 24/26] test/py: fs: add extended write operation test 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 In this commit and the following, test scripts for new filesystem functionalities introduced by my patch set, "fs: fat: extend FAT write operations," are provided. In particular, this patch adds test cases for sub-directory write and write with non-zero offset. Signed-off-by: AKASHI Takahiro --- test/py/tests/test_fs/conftest.py | 83 ++++++++++ test/py/tests/test_fs/fstest_defs.py | 3 + test/py/tests/test_fs/test_ext.py | 224 +++++++++++++++++++++++++++ 3 files changed, 310 insertions(+) create mode 100644 test/py/tests/test_fs/test_ext.py diff --git a/test/py/tests/test_fs/conftest.py b/test/py/tests/test_fs/conftest.py index 3437accc971f..d2908590be16 100644 --- a/test/py/tests/test_fs/conftest.py +++ b/test/py/tests/test_fs/conftest.py @@ -10,6 +10,7 @@ from subprocess import call, check_call, check_output, CalledProcessError from fstest_defs import * supported_fs_basic = ['fat16', 'fat32', 'ext4'] +supported_fs_ext = ['fat16', 'fat32'] # # Filesystem test specific setup @@ -20,6 +21,7 @@ def pytest_addoption(parser): def pytest_configure(config): global supported_fs_basic + global supported_fs_ext def intersect(listA, listB): return [x for x in listA if x in listB] @@ -28,11 +30,15 @@ def pytest_configure(config): if supported_fs: print("*** FS TYPE modified: %s" % supported_fs) supported_fs_basic = intersect(supported_fs, supported_fs_basic) + supported_fs_ext = intersect(supported_fs, supported_fs_ext) def pytest_generate_tests(metafunc): if 'fs_obj_basic' in metafunc.fixturenames: metafunc.parametrize('fs_obj_basic', supported_fs_basic, indirect=True, scope='module') + if 'fs_obj_ext' in metafunc.fixturenames: + metafunc.parametrize('fs_obj_ext', supported_fs_ext, + indirect=True, scope='module') # # Helper functions @@ -216,3 +222,80 @@ def fs_obj_basic(request, u_boot_config): call('rmdir %s' % mount_dir, shell=True) if fs_img: call('rm -f %s' % fs_img, shell=True) + +# +# Fixture for extended fs test +# +# NOTE: yield_fixture was deprecated since pytest-3.0 +@pytest.yield_fixture() +def fs_obj_ext(request, u_boot_config): + fs_type = request.param + fs_img = '' + + fs_ubtype = fstype_to_ubname(fs_type) + check_ubconfig(u_boot_config, fs_ubtype) + + mount_dir = u_boot_config.persistent_data_dir + '/mnt' + + min_file = mount_dir + '/' + MIN_FILE + tmp_file = mount_dir + '/tmpfile' + + try: + + # 128MiB volume + fs_img = mk_fs(u_boot_config, fs_type, 0x8000000, '128MB') + + # Mount the image so we can populate it. + check_call('mkdir -p %s' % mount_dir, shell=True) + mount_fs(fs_type, fs_img, mount_dir) + + # Create a test directory + check_call('mkdir %s/dir1' % mount_dir, shell=True) + + # Create a small file and calculate md5 + check_call('dd if=/dev/urandom of=%s bs=1K count=20' + % min_file, shell=True) + out = check_output( + 'dd if=%s bs=1K 2> /dev/null | md5sum' + % min_file, shell=True) + md5val = [ out.split()[0] ] + + # Calculate md5sum of Test Case 4 + check_call('dd if=%s of=%s bs=1K count=20' + % (min_file, tmp_file), shell=True) + check_call('dd if=%s of=%s bs=1K seek=5 count=20' + % (min_file, tmp_file), shell=True) + out = check_output('dd if=%s bs=1K 2> /dev/null | md5sum' + % tmp_file, shell=True) + md5val.append(out.split()[0]) + + # Calculate md5sum of Test Case 5 + check_call('dd if=%s of=%s bs=1K count=20' + % (min_file, tmp_file), shell=True) + check_call('dd if=%s of=%s bs=1K seek=5 count=5' + % (min_file, tmp_file), shell=True) + out = check_output('dd if=%s bs=1K 2> /dev/null | md5sum' + % tmp_file, shell=True) + md5val.append(out.split()[0]) + + # Calculate md5sum of Test Case 7 + check_call('dd if=%s of=%s bs=1K count=20' + % (min_file, tmp_file), shell=True) + check_call('dd if=%s of=%s bs=1K seek=20 count=20' + % (min_file, tmp_file), shell=True) + out = check_output('dd if=%s bs=1K 2> /dev/null | md5sum' + % tmp_file, shell=True) + md5val.append(out.split()[0]) + + check_call('rm %s' % tmp_file, shell=True) + umount_fs(fs_type, mount_dir) + except CalledProcessError: + pytest.skip('Setup failed for filesystem: ' + fs_type) + return + else: + yield [fs_ubtype, fs_img, md5val] + finally: + umount_fs(fs_type, mount_dir) + call('rmdir %s' % mount_dir, shell=True) + if fs_img: + call('rm -f %s' % fs_img, shell=True) diff --git a/test/py/tests/test_fs/fstest_defs.py b/test/py/tests/test_fs/fstest_defs.py index f26dd06cacf2..5f107562d952 100644 --- a/test/py/tests/test_fs/fstest_defs.py +++ b/test/py/tests/test_fs/fstest_defs.py @@ -1,5 +1,8 @@ # SPDX-License-Identifier: GPL-2.0+ +# $MIN_FILE is the name of the 20KB file in the file system image +MIN_FILE='testfile' + # $SMALL_FILE is the name of the 1MB file in the file system image SMALL_FILE='1MB.file' diff --git a/test/py/tests/test_fs/test_ext.py b/test/py/tests/test_fs/test_ext.py new file mode 100644 index 000000000000..38217d08bf64 --- /dev/null +++ b/test/py/tests/test_fs/test_ext.py @@ -0,0 +1,224 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright (c) 2018, Linaro Limited +# Author: Takahiro Akashi +# +# U-Boot File System:Exntented Test + +""" +This test verifies extended write operation on file system. +""" + +import pytest +import re +from fstest_defs import * + +@pytest.mark.boardspec('sandbox') +class TestFsExt(object): + def test_fs_ext1(self, u_boot_console, fs_obj_ext): + """ + Test Case 1 - write a file with absolute path + """ + fs_type,fs_img,md5val = fs_obj_ext + with u_boot_console.log.section('Test Case 1 - write with abs path'): + # Test Case 1a - Check if command successfully returned + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % fs_img, + '%sload host 0:0 %x /%s' % (fs_type, ADDR, MIN_FILE), + '%swrite host 0:0 %x /dir1/%s.w1 $filesize' + % (fs_type, ADDR, MIN_FILE)]) + assert('20480 bytes written' in ''.join(output)) + + # Test Case 1b - Check md5 of file content + output = u_boot_console.run_command_list([ + 'mw.b %x 00 100' % ADDR, + '%sload host 0:0 %x /dir1/%s.w1' % (fs_type, ADDR, MIN_FILE), + 'md5sum %x $filesize' % ADDR, + 'setenv filesize']) + assert(md5val[0] in ''.join(output)) + + def test_fs_ext2(self, u_boot_console, fs_obj_ext): + """ + Test Case 2 - write to a file with relative path + """ + fs_type,fs_img,md5val = fs_obj_ext + with u_boot_console.log.section('Test Case 2 - write with rel path'): + # Test Case 2a - Check if command successfully returned + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % fs_img, + '%sload host 0:0 %x /%s' % (fs_type, ADDR, MIN_FILE), + '%swrite host 0:0 %x dir1/%s.w2 $filesize' + % (fs_type, ADDR, MIN_FILE)]) + assert('20480 bytes written' in ''.join(output)) + + # Test Case 2b - Check md5 of file content + output = u_boot_console.run_command_list([ + 'mw.b %x 00 100' % ADDR, + '%sload host 0:0 %x dir1/%s.w2' % (fs_type, ADDR, MIN_FILE), + 'md5sum %x $filesize' % ADDR, + 'setenv filesize']) + assert(md5val[0] in ''.join(output)) + + def test_fs_ext3(self, u_boot_console, fs_obj_ext): + """ + Test Case 3 - write to a file with invalid path + """ + fs_type,fs_img,md5val = fs_obj_ext + with u_boot_console.log.section('Test Case 3 - write with invalid path'): + # Test Case 3 - Check if command expectedly failed + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % fs_img, + '%sload host 0:0 %x /%s' % (fs_type, ADDR, MIN_FILE), + '%swrite host 0:0 %x /dir1/none/%s.w3 $filesize' + % (fs_type, ADDR, MIN_FILE)]) + assert('Unable to write "/dir1/none/' in ''.join(output)) + + def test_fs_ext4(self, u_boot_console, fs_obj_ext): + """ + Test Case 4 - write at non-zero offset, enlarging file size + """ + fs_type,fs_img,md5val = fs_obj_ext + with u_boot_console.log.section('Test Case 4 - write at non-zero offset, enlarging file size'): + # Test Case 4a - Check if command successfully returned + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % fs_img, + '%sload host 0:0 %x /%s' % (fs_type, ADDR, MIN_FILE), + '%swrite host 0:0 %x /dir1/%s.w4 $filesize' + % (fs_type, ADDR, MIN_FILE)]) + output = u_boot_console.run_command( + '%swrite host 0:0 %x /dir1/%s.w4 $filesize 0x1400' + % (fs_type, ADDR, MIN_FILE)) + assert('20480 bytes written' in output) + + # Test Case 4b - Check size of written file + output = u_boot_console.run_command_list([ + '%ssize host 0:0 /dir1/%s.w4' % (fs_type, MIN_FILE), + 'printenv filesize', + 'setenv filesize']) + assert('filesize=6400' in ''.join(output)) + + # Test Case 4c - Check md5 of file content + output = u_boot_console.run_command_list([ + 'mw.b %x 00 100' % ADDR, + '%sload host 0:0 %x /dir1/%s.w4' % (fs_type, ADDR, MIN_FILE), + 'md5sum %x $filesize' % ADDR, + 'setenv filesize']) + assert(md5val[1] in ''.join(output)) + + def test_fs_ext5(self, u_boot_console, fs_obj_ext): + """ + Test Case 5 - write at non-zero offset, shrinking file size + """ + fs_type,fs_img,md5val = fs_obj_ext + with u_boot_console.log.section('Test Case 5 - write at non-zero offset, shrinking file size'): + # Test Case 5a - Check if command successfully returned + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % fs_img, + '%sload host 0:0 %x /%s' % (fs_type, ADDR, MIN_FILE), + '%swrite host 0:0 %x /dir1/%s.w5 $filesize' + % (fs_type, ADDR, MIN_FILE)]) + output = u_boot_console.run_command( + '%swrite host 0:0 %x /dir1/%s.w5 0x1400 0x1400' + % (fs_type, ADDR, MIN_FILE)) + assert('5120 bytes written' in output) + + # Test Case 5b - Check size of written file + output = u_boot_console.run_command_list([ + '%ssize host 0:0 /dir1/%s.w5' % (fs_type, MIN_FILE), + 'printenv filesize', + 'setenv filesize']) + assert('filesize=2800' in ''.join(output)) + + # Test Case 5c - Check md5 of file content + output = u_boot_console.run_command_list([ + 'mw.b %x 00 100' % ADDR, + '%sload host 0:0 %x /dir1/%s.w5' % (fs_type, ADDR, MIN_FILE), + 'md5sum %x $filesize' % ADDR, + 'setenv filesize']) + assert(md5val[2] in ''.join(output)) + + def test_fs_ext6(self, u_boot_console, fs_obj_ext): + """ + Test Case 6 - write nothing at the start, truncating to zero + """ + fs_type,fs_img,md5val = fs_obj_ext + with u_boot_console.log.section('Test Case 6 - write nothing at the start, truncating to zero'): + # Test Case 6a - Check if command successfully returned + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % fs_img, + '%sload host 0:0 %x /%s' % (fs_type, ADDR, MIN_FILE), + '%swrite host 0:0 %x /dir1/%s.w6 $filesize' + % (fs_type, ADDR, MIN_FILE)]) + output = u_boot_console.run_command( + '%swrite host 0:0 %x /dir1/%s.w6 0 0' + % (fs_type, ADDR, MIN_FILE)) + assert('0 bytes written' in output) + + # Test Case 6b - Check size of written file + output = u_boot_console.run_command_list([ + '%ssize host 0:0 /dir1/%s.w6' % (fs_type, MIN_FILE), + 'printenv filesize', + 'setenv filesize']) + assert('filesize=0' in ''.join(output)) + + def test_fs_ext7(self, u_boot_console, fs_obj_ext): + """ + Test Case 7 - write at the end (append) + """ + fs_type,fs_img,md5val = fs_obj_ext + with u_boot_console.log.section('Test Case 7 - write at the end (append)'): + # Test Case 7a - Check if command successfully returned + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % fs_img, + '%sload host 0:0 %x /%s' % (fs_type, ADDR, MIN_FILE), + '%swrite host 0:0 %x /dir1/%s.w7 $filesize' + % (fs_type, ADDR, MIN_FILE)]) + output = u_boot_console.run_command( + '%swrite host 0:0 %x /dir1/%s.w7 $filesize $filesize' + % (fs_type, ADDR, MIN_FILE)) + assert('20480 bytes written' in output) + + # Test Case 7b - Check size of written file + output = u_boot_console.run_command_list([ + '%ssize host 0:0 /dir1/%s.w7' % (fs_type, MIN_FILE), + 'printenv filesize', + 'setenv filesize']) + assert('filesize=a000' in ''.join(output)) + + # Test Case 7c - Check md5 of file content + output = u_boot_console.run_command_list([ + 'mw.b %x 00 100' % ADDR, + '%sload host 0:0 %x /dir1/%s.w7' % (fs_type, ADDR, MIN_FILE), + 'md5sum %x $filesize' % ADDR, + 'setenv filesize']) + assert(md5val[3] in ''.join(output)) + + def test_fs_ext8(self, u_boot_console, fs_obj_ext): + """ + Test Case 8 - write at offset beyond the end of file + """ + fs_type,fs_img,md5val = fs_obj_ext + with u_boot_console.log.section('Test Case 8 - write beyond the end'): + # Test Case 8a - Check if command expectedly failed + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % fs_img, + '%sload host 0:0 %x /%s' % (fs_type, ADDR, MIN_FILE), + '%swrite host 0:0 %x /dir1/%s.w8 $filesize' + % (fs_type, ADDR, MIN_FILE)]) + output = u_boot_console.run_command( + '%swrite host 0:0 %x /dir1/%s.w8 0x1400 %x' + % (fs_type, ADDR, MIN_FILE, 0x100000 + 0x1400)) + assert('Unable to write "/dir1' in output) + + def test_fs_ext9(self, u_boot_console, fs_obj_ext): + """ + Test Case 9 - write to a non-existing file at non-zero offset + """ + fs_type,fs_img,md5val = fs_obj_ext + with u_boot_console.log.section('Test Case 9 - write to non-existing file with non-zero offset'): + # Test Case 9a - Check if command expectedly failed + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % fs_img, + '%sload host 0:0 %x /%s' % (fs_type, ADDR, MIN_FILE), + '%swrite host 0:0 %x /dir1/%s.w9 0x1400 0x1400' + % (fs_type, ADDR, MIN_FILE)]) + assert('Unable to write "/dir1' in ''.join(output)) From patchwork Tue Sep 11 06:59:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 146424 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3324746ljw; Tue, 11 Sep 2018 00:16:37 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZskw9iTMxnexnLW6N9AaYp3VEBKG6g69CSEOo/nT2hNbg9K0r3+ytRaa2vpv4c2VBGQin9 X-Received: by 2002:aa7:da19:: with SMTP id r25-v6mr27395323eds.54.1536650197467; Tue, 11 Sep 2018 00:16:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536650197; cv=none; d=google.com; s=arc-20160816; b=WN5s29Ne5hMyFRehAgMYuqWHnh5ctVeqVmAbvWUvEP9/5O7ng1vzsgDXRwY5mZ6qpk kk2bU6TkPjN2SnQhox5Ix4NStM8/LcJ/OZbwtFStZX9mRebJ/b+87FhlTcoFfrW7HzoA 7/WuZ2zS4szoO2RH455h74KIwPGxu56IFeQhvBakTZfNTnb94OswfeXGBX3CPSD19US1 PbDKzZXhcEtcI5QQ2F1PtkKxmlqg34NHEG2ZffAAPxYc9l9GiwxaC3iiVU3TocJXIK6N vsBH5f+5Fb/4IQ+k670vghQc7p+bdhwxf9kVIVqj+lJIovujHPpozje8mCdiPEqbg95z R5hw== 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=+8Cx8d6weufEkRT4WK5/G/iVIM4i28kCmZnay2JT2Ns=; b=u4bCXSXDRSczpeCCGKWWGQKMVEcLR4ekuPCyh+cKA/BGrv/aBIKNAn/yBDU6FL+FZT axB2zdoL3Hd9Znw74ikpikkOGqusoaxT/XabMJEBLIOWfX8FJk86MGJ/tXYrj5jUvFVY 8v7qWs2YLn7zocmc8TRxmGEY93xrbf09brd4UX2rixwjfCOfPw7kMoF4LKHkIbm9p21y YcTeChrIAr49k3w1QwX+fpBQa80KD42yi0QQMF+aZRq2SYm9h/5oWrsfcJV1tmWwtdYD 3ARIL/t0MByGUIHSWawPZGOgmUJF+0bFOfcnWWnnZwc1K690t6zk6nqFaJtJhnJGjk6v G2Fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=e68yMH34; 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 f32-v6si8366613edb.230.2018.09.11.00.16.37; Tue, 11 Sep 2018 00:16:37 -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=e68yMH34; 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 1A88AC21E1A; Tue, 11 Sep 2018 07:09:33 +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 34F2DC21EE3; Tue, 11 Sep 2018 07:01:57 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 8B212C21E3B; Tue, 11 Sep 2018 07:00:47 +0000 (UTC) Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) by lists.denx.de (Postfix) with ESMTPS id BCDADC21E38 for ; Tue, 11 Sep 2018 07:00:40 +0000 (UTC) Received: by mail-pl1-f170.google.com with SMTP id t19-v6so10888092ply.13 for ; Tue, 11 Sep 2018 00:00:40 -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=VEtfDqQ5Vcsg6Xb/VtHu5sYaXNDDu1AZt8pqzhwgvLo=; b=e68yMH347UwF2cjUrsKTRmV4k5T19akgGKYq8GiVrwXdtA67wkQPcvFazbM7u3On5O 1rJ3ZD6YW4adAxexvTAJtnM82G6K+2MEmTBwRwUg031mP63xw0XpWx78Oepj665WFHBG sEo4bDPYnKOi/BCoB0d2JX79pxCtBgdTLUo0U= 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=VEtfDqQ5Vcsg6Xb/VtHu5sYaXNDDu1AZt8pqzhwgvLo=; b=fEt4+N03s24sZIVpuD+DXtZZAFFVnDxuJ4RkxMoEZLm+etuqtBzVJmSjJvLuXSddoy PkwbK5a90ne91+9F62Uf6kxgHUJu5+7iy5JHBeusF9X+k8FHnoXahrhySfRtlD4lkrOi znlhskKYtE4ugLPQzthMsoukOGzCEDa4n7FF1koDN4VA83o6Fx6T6v6/xiWCpUiPZnIx wq63VnZ8PJ+Gqn87RiQlgXdtiKDCutM7ypUWWlbAAzvprhppCQUQsQ5SmKEmgI+/1AkI zI2EBxQnhfQqs57TyaOsP6OfGA+OqRmr2qYrXceB3p5EvyKQwBDb7y2pl861fcOKmHDO +2DQ== X-Gm-Message-State: APzg51DP8MkDRhnwkMXQCMy6PPVUOhbTLSbd/Ouzh7CKxbV4zJnc50ny Pb+MP2uh9ZLcwD+Lz49nAf4h/Q== X-Received: by 2002:a17:902:3081:: with SMTP id v1-v6mr25898099plb.58.1536649238750; Tue, 11 Sep 2018 00:00:38 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id j15-v6sm21897381pfn.52.2018.09.11.00.00.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Sep 2018 00:00:37 -0700 (PDT) From: "Akashi, Takahiro" To: trini@konsulko.com Date: Tue, 11 Sep 2018 15:59:21 +0900 Message-Id: <20180911065922.19141-26-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 25/26] test/py: fs: add fstest/mkdir test 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 In this commit, test cases for mkdir interfaces are added as part of "test_fs" test suite. Signed-off-by: AKASHI Takahiro --- test/py/tests/test_fs/conftest.py | 29 +++++++ test/py/tests/test_fs/test_mkdir.py | 112 ++++++++++++++++++++++++++++ 2 files changed, 141 insertions(+) create mode 100644 test/py/tests/test_fs/test_mkdir.py diff --git a/test/py/tests/test_fs/conftest.py b/test/py/tests/test_fs/conftest.py index d2908590be16..71abf8fa4222 100644 --- a/test/py/tests/test_fs/conftest.py +++ b/test/py/tests/test_fs/conftest.py @@ -11,6 +11,7 @@ from fstest_defs import * supported_fs_basic = ['fat16', 'fat32', 'ext4'] supported_fs_ext = ['fat16', 'fat32'] +supported_fs_mkdir = ['fat16', 'fat32'] # # Filesystem test specific setup @@ -22,6 +23,7 @@ def pytest_addoption(parser): def pytest_configure(config): global supported_fs_basic global supported_fs_ext + global supported_fs_mkdir def intersect(listA, listB): return [x for x in listA if x in listB] @@ -31,6 +33,7 @@ def pytest_configure(config): print("*** FS TYPE modified: %s" % supported_fs) supported_fs_basic = intersect(supported_fs, supported_fs_basic) supported_fs_ext = intersect(supported_fs, supported_fs_ext) + supported_fs_mkdir = intersect(supported_fs, supported_fs_mkdir) def pytest_generate_tests(metafunc): if 'fs_obj_basic' in metafunc.fixturenames: @@ -39,6 +42,9 @@ def pytest_generate_tests(metafunc): if 'fs_obj_ext' in metafunc.fixturenames: metafunc.parametrize('fs_obj_ext', supported_fs_ext, indirect=True, scope='module') + if 'fs_obj_mkdir' in metafunc.fixturenames: + metafunc.parametrize('fs_obj_mkdir', supported_fs_mkdir, + indirect=True, scope='module') # # Helper functions @@ -299,3 +305,26 @@ def fs_obj_ext(request, u_boot_config): call('rmdir %s' % mount_dir, shell=True) if fs_img: call('rm -f %s' % fs_img, shell=True) + +# +# Fixture for mkdir test +# +# NOTE: yield_fixture was deprecated since pytest-3.0 +@pytest.yield_fixture() +def fs_obj_mkdir(request, u_boot_config): + fs_type = request.param + fs_img = '' + + fs_ubtype = fstype_to_ubname(fs_type) + check_ubconfig(u_boot_config, fs_ubtype) + + try: + # 128MiB volume + fs_img = mk_fs(u_boot_config, fs_type, 0x8000000, '128MB') + except: + pytest.skip('Setup failed for filesystem: ' + fs_type) + else: + yield [fs_ubtype, fs_img] + finally: + if fs_img: + call('rm -f %s' % fs_img, shell=True) diff --git a/test/py/tests/test_fs/test_mkdir.py b/test/py/tests/test_fs/test_mkdir.py new file mode 100644 index 000000000000..d9da97b56b5e --- /dev/null +++ b/test/py/tests/test_fs/test_mkdir.py @@ -0,0 +1,112 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright (c) 2018, Linaro Limited +# Author: Takahiro Akashi +# +# U-Boot File System:mkdir Test + +""" +This test verifies mkdir operation on file system. +""" + +import pytest + +@pytest.mark.boardspec('sandbox') +class TestMkdir(object): + def test_mkdir1(self, u_boot_console, fs_obj_mkdir): + """ + Test Case 1 - create a directory under a root + """ + fs_type,fs_img = fs_obj_mkdir + with u_boot_console.log.section('Test Case 1 - mkdir'): + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % fs_img, + '%smkdir host 0:0 dir1' % fs_type, + '%sls host 0:0 /' % fs_type]) + assert('dir1/' in ''.join(output)) + + output = u_boot_console.run_command( + '%sls host 0:0 dir1' % fs_type) + assert('./' in output) + assert('../' in output) + + def test_mkdir2(self, u_boot_console, fs_obj_mkdir): + """ + Test Case 2 - create a directory under a sub-directory + """ + fs_type,fs_img = fs_obj_mkdir + with u_boot_console.log.section('Test Case 2 - mkdir (sub-sub directory)'): + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % fs_img, + '%smkdir host 0:0 dir1/dir2' % fs_type, + '%sls host 0:0 dir1' % fs_type]) + assert('dir2/' in ''.join(output)) + + output = u_boot_console.run_command( + '%sls host 0:0 dir1/dir2' % fs_type) + assert('./' in output) + assert('../' in output) + + def test_mkdir3(self, u_boot_console, fs_obj_mkdir): + """ + Test Case 3 - trying to create a directory with a non-existing + path should fail + """ + fs_type,fs_img = fs_obj_mkdir + with u_boot_console.log.section('Test Case 3 - mkdir (non-existing path)'): + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % fs_img, + '%smkdir host 0:0 none/dir3' % fs_type]) + assert('Unable to create a directory' in ''.join(output)) + + def test_mkdir4(self, u_boot_console, fs_obj_mkdir): + """ + Test Case 4 - trying to create "." should fail + """ + fs_type,fs_img = fs_obj_mkdir + with u_boot_console.log.section('Test Case 4 - mkdir (".")'): + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % fs_img, + '%smkdir host 0:0 .' % fs_type]) + assert('Unable to create a directory' in ''.join(output)) + + def test_mkdir5(self, u_boot_console, fs_obj_mkdir): + """ + Test Case 5 - trying to create ".." should fail + """ + fs_type,fs_img = fs_obj_mkdir + with u_boot_console.log.section('Test Case 5 - mkdir ("..")'): + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % fs_img, + '%smkdir host 0:0 ..' % fs_type]) + assert('Unable to create a directory' in ''.join(output)) + + def test_mkdir6(self, u_boot_console, fs_obj_mkdir): + """ + 'Test Case 6 - create as many directories as amount of directory + entries goes beyond a cluster size)' + """ + fs_type,fs_img = fs_obj_mkdir + with u_boot_console.log.section('Test Case 6 - mkdir (create many)'): + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % fs_img, + '%smkdir host 0:0 dir6' % fs_type, + '%sls host 0:0 /' % fs_type]) + assert('dir6/' in ''.join(output)) + + for i in range(0, 20): + output = u_boot_console.run_command( + '%smkdir host 0:0 dir6/0123456789abcdef%02x' + % (fs_type, i)) + output = u_boot_console.run_command('%sls host 0:0 dir6' % fs_type) + assert('0123456789abcdef00/' in output) + assert('0123456789abcdef13/' in output) + + output = u_boot_console.run_command( + '%sls host 0:0 dir6/0123456789abcdef13/.' % fs_type) + assert('./' in output) + assert('../' in output) + + output = u_boot_console.run_command( + '%sls host 0:0 dir6/0123456789abcdef13/..' % fs_type) + assert('0123456789abcdef00/' in output) + assert('0123456789abcdef13/' in output) From patchwork Tue Sep 11 07:06: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: 146415 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3321383ljw; Tue, 11 Sep 2018 00:12:19 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYHe8KbtHIiRL1ni+LnjcZT5s8oxAdXhLRRe1UGcYrq1nEtOjTHUBEasUynJoESV84BP6rM X-Received: by 2002:a50:9943:: with SMTP id l3-v6mr26451383edb.198.1536649939224; Tue, 11 Sep 2018 00:12:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536649939; cv=none; d=google.com; s=arc-20160816; b=VDaGj2UmQc0l4T+lb4u1tBpoAsKAm/veSJ31s059+mITFUbOh8fXN5dRoCwhjzwLpL AqgXb1Km4KGesIpdnbqpS94oEknl8a9x+Eag4JPjJ7NGKLOaNtENXyJchldymIGoeHDN xud76cszi1Mj7iFaEsL0tQ4jn7rQPHe2JfRhkVhp7g6LwVxsnckjk72LFUCJNsIs78fB EvXloYhL9UYWqpdC+BHsSxCqRhM3KQXmkR+1xLN9i3nj+GOH56p1WTEFoqPsEKUjsfN9 DAqn/1CBfFsl7NFyUSSeltDQ0sSNhPuH7UrqKdi0QnhtcfH42smcpZp9XD2welmpI7TR aEdA== 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:message-id:date:to:from :dkim-signature; bh=FmI3GIbeEhRmRj7huseHyw17B60qHGP0urOmiV7MDms=; b=fQQDQyWUkzxpFkIlXMtReJQvTZjRInnZ0A1uNlJ2CbsK8ebRB0oIBrXMbi4Ct7//V0 CBR9aVsUIq6MaWvz6wEwJejlG6Tm4ZZpcAypvS4ACnqSov/UrH6MNx/JHHM5EXeAlywV 7rB/Ukp9laX03hXQnITl8vb+ACe21jHIhAdXckXpwqK+TVXqBECHczQ9oxQb4AyxCEom ou9e9P7UMxD9FqqewuBs7X/2pNqnGON0oTmBS2fHR4LRubSLI7Ke4OR6xAWSpB0iSGJx yPNKKXSqMgpNxJ6qIzQJwb5RYJA0/4CkdsIbhfuAkNhuo6Ag0dw1jLd71WwA/+JIkgT1 h1NA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=CHtdvC5n; 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 k4-v6si2477799edr.290.2018.09.11.00.12.18; Tue, 11 Sep 2018 00:12:19 -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=CHtdvC5n; 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 BD910C21E18; Tue, 11 Sep 2018 07:11:22 +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 31FD8C21E18; Tue, 11 Sep 2018 07:08:06 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 1AEE1C21DD9; Tue, 11 Sep 2018 07:05:25 +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 A4B1AC21E76 for ; Tue, 11 Sep 2018 07:05:18 +0000 (UTC) Received: by mail-pg1-f195.google.com with SMTP id b129-v6so11740921pga.13 for ; Tue, 11 Sep 2018 00:05: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; bh=htsTI3uKmEw1mLxTS4jetYUPfQSPLrIfgujWvm4VK3I=; b=CHtdvC5nVFvVQ1xTBZ+VlG41cuZbuHR3ESl9rTNKlgRdx+3ke/CwNzEU4UodKr5NP9 Jw6G67J4BMOU5dznC5c+SozbC2cVfyTPrQgdI95Cgeyhcxdw0vWmp17KhZLMlAQXfKZt LEXeYUSuFMMz+P0HvovOCr/pun1J9jqvFPK2Y= 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; bh=htsTI3uKmEw1mLxTS4jetYUPfQSPLrIfgujWvm4VK3I=; b=FpM4nJvSJ7+dQ6uHz372dEwMkJ6b3JexEkIG2LqJ52h0Ba8MAFQSxOCoJHbeaaMTBG Mr3HPOtK2PZ/gOlL1Q9dzY9NhduiMGluYkZKTOR+ygOL0tMFIIPBwoJBt46TjRlOh/Ee sViz31kcpY6TVtVtKI/W384mBm0Eo9JlMv3rFWvwe/QI7KP5xMvaVmYJpG+CwyrgEs6a +0Z20mF7/DSqLDfnaw161Mrcb31NOc1mncsEJrLPjGj5/Yx88tTzFHeTE9k8rWzNfsLl 60Wr3YH4Sq5DKVfCue+uScnHAM4f2dUtM7ads01q0SIee+HZ8FMcPs5rB9IPkJyRtWo2 kO8w== X-Gm-Message-State: APzg51AzjIFpvvEcyrFwqesjaN0SdBg25SjuXdDjZuvWIZY02Fz/sPfs n4UFMTZBTxQaKXuyTW7rlNNakQ== X-Received: by 2002:a63:d806:: with SMTP id b6-v6mr26250311pgh.347.1536649517204; Tue, 11 Sep 2018 00:05:17 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id u9-v6sm32877743pfi.104.2018.09.11.00.05.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Sep 2018 00:05:16 -0700 (PDT) From: "Akashi, Takahiro" To: trini@konsulko.com Date: Tue, 11 Sep 2018 16:06:03 +0900 Message-Id: <20180911070603.19495-1-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 Cc: u-boot@lists.denx.de, xypron.glpk@gmx.de, agraf@suse.de Subject: [U-Boot] [PATCH v3 26/26] test/py: fs: add fstest/unlink test 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" In this commit, test cases for unlink interfaces are added as part of "test_fs" test suite. Signed-off-by: AKASHI Takahiro --- test/py/tests/test_fs/conftest.py | 62 +++++++++++++++ test/py/tests/test_fs/test_unlink.py | 109 +++++++++++++++++++++++++++ 2 files changed, 171 insertions(+) create mode 100644 test/py/tests/test_fs/test_unlink.py diff --git a/test/py/tests/test_fs/conftest.py b/test/py/tests/test_fs/conftest.py index 71abf8fa4222..6404b311bc30 100644 --- a/test/py/tests/test_fs/conftest.py +++ b/test/py/tests/test_fs/conftest.py @@ -12,6 +12,7 @@ from fstest_defs import * supported_fs_basic = ['fat16', 'fat32', 'ext4'] supported_fs_ext = ['fat16', 'fat32'] supported_fs_mkdir = ['fat16', 'fat32'] +supported_fs_unlink = ['fat16', 'fat32'] # # Filesystem test specific setup @@ -24,6 +25,7 @@ def pytest_configure(config): global supported_fs_basic global supported_fs_ext global supported_fs_mkdir + global supported_fs_unlink def intersect(listA, listB): return [x for x in listA if x in listB] @@ -34,6 +36,7 @@ def pytest_configure(config): supported_fs_basic = intersect(supported_fs, supported_fs_basic) supported_fs_ext = intersect(supported_fs, supported_fs_ext) supported_fs_mkdir = intersect(supported_fs, supported_fs_mkdir) + supported_fs_unlink = intersect(supported_fs, supported_fs_unlink) def pytest_generate_tests(metafunc): if 'fs_obj_basic' in metafunc.fixturenames: @@ -45,6 +48,9 @@ def pytest_generate_tests(metafunc): if 'fs_obj_mkdir' in metafunc.fixturenames: metafunc.parametrize('fs_obj_mkdir', supported_fs_mkdir, indirect=True, scope='module') + if 'fs_obj_unlink' in metafunc.fixturenames: + metafunc.parametrize('fs_obj_unlink', supported_fs_unlink, + indirect=True, scope='module') # # Helper functions @@ -328,3 +334,59 @@ def fs_obj_mkdir(request, u_boot_config): finally: if fs_img: call('rm -f %s' % fs_img, shell=True) + +# +# Fixture for unlink test +# +# NOTE: yield_fixture was deprecated since pytest-3.0 +@pytest.yield_fixture() +def fs_obj_unlink(request, u_boot_config): + fs_type = request.param + fs_img = '' + + fs_ubtype = fstype_to_ubname(fs_type) + check_ubconfig(u_boot_config, fs_ubtype) + + mount_dir = u_boot_config.persistent_data_dir + '/mnt' + + try: + + # 128MiB volume + fs_img = mk_fs(u_boot_config, fs_type, 0x8000000, '128MB') + + # Mount the image so we can populate it. + check_call('mkdir -p %s' % mount_dir, shell=True) + mount_fs(fs_type, fs_img, mount_dir) + + # Test Case 1 & 3 + check_call('mkdir %s/dir1' % mount_dir, shell=True) + check_call('dd if=/dev/urandom of=%s/dir1/file1 bs=1K count=1' + % mount_dir, shell=True) + check_call('dd if=/dev/urandom of=%s/dir1/file2 bs=1K count=1' + % mount_dir, shell=True) + + # Test Case 2 + check_call('mkdir %s/dir2' % mount_dir, shell=True) + for i in range(0, 20): + check_call('mkdir %s/dir2/0123456789abcdef%02x' + % (mount_dir, i), shell=True) + + # Test Case 4 + check_call('mkdir %s/dir4' % mount_dir, shell=True) + + # Test Case 5, 6 & 7 + check_call('mkdir %s/dir5' % mount_dir, shell=True) + check_call('dd if=/dev/urandom of=%s/dir5/file1 bs=1K count=1' + % mount_dir, shell=True) + + umount_fs(fs_type, mount_dir) + except CalledProcessError: + pytest.skip('Setup failed for filesystem: ' + fs_type) + return + else: + yield [fs_ubtype, fs_img] + finally: + umount_fs(fs_type, mount_dir) + call('rmdir %s' % mount_dir, shell=True) + if fs_img: + call('rm -f %s' % fs_img, shell=True) diff --git a/test/py/tests/test_fs/test_unlink.py b/test/py/tests/test_fs/test_unlink.py new file mode 100644 index 000000000000..69c1a6e078c3 --- /dev/null +++ b/test/py/tests/test_fs/test_unlink.py @@ -0,0 +1,109 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright (c) 2018, Linaro Limited +# Author: Takahiro Akashi +# +# U-Boot File System:unlink Test + +""" +This test verifies unlink operation (deleting a file or a directory) +on file system. +""" + +import pytest + +@pytest.mark.boardspec('sandbox') +class TestUnlink(object): + def test_unlink1(self, u_boot_console, fs_obj_unlink): + """ + Test Case 1 - delete a file + """ + fs_type,fs_img = fs_obj_unlink + with u_boot_console.log.section('Test Case 1 - unlink (file)'): + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % fs_img, + '%srm host 0:0 dir1/file1' % fs_type, + '%sls host 0:0 dir1/file1' % fs_type]) + assert('' == ''.join(output)) + + output = u_boot_console.run_command( + '%sls host 0:0 dir1/' % fs_type) + assert(not 'file1' in output) + assert('file2' in output) + + def test_unlink2(self, u_boot_console, fs_obj_unlink): + """ + Test Case 2 - delete many files + """ + fs_type,fs_img = fs_obj_unlink + with u_boot_console.log.section('Test Case 2 - unlink (many)'): + output = u_boot_console.run_command('host bind 0 %s' % fs_img) + + for i in range(0, 20): + output = u_boot_console.run_command_list([ + '%srm host 0:0 dir2/0123456789abcdef%02x' % (fs_type, i), + '%sls host 0:0 dir2/0123456789abcdef%02x' % (fs_type, i)]) + assert('' == ''.join(output)) + + output = u_boot_console.run_command( + '%sls host 0:0 dir2' % fs_type) + assert('0 file(s), 2 dir(s)' in output) + + def test_unlink3(self, u_boot_console, fs_obj_unlink): + """ + Test Case 3 - trying to delete a non-existing file should fail + """ + fs_type,fs_img = fs_obj_unlink + with u_boot_console.log.section('Test Case 3 - unlink (non-existing)'): + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % fs_img, + '%srm host 0:0 dir1/nofile' % fs_type]) + assert('nofile: doesn\'t exist' in ''.join(output)) + + def test_unlink4(self, u_boot_console, fs_obj_unlink): + """ + Test Case 4 - delete an empty directory + """ + fs_type,fs_img = fs_obj_unlink + with u_boot_console.log.section('Test Case 4 - unlink (directory)'): + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % fs_img, + '%srm host 0:0 dir4' % fs_type]) + assert('' == ''.join(output)) + + output = u_boot_console.run_command( + '%sls host 0:0 /' % fs_type) + assert(not 'dir4' in output) + + def test_unlink5(self, u_boot_console, fs_obj_unlink): + """ + Test Case 5 - trying to deleting a non-empty directory ".." + should fail + """ + fs_type,fs_img = fs_obj_unlink + with u_boot_console.log.section('Test Case 5 - unlink ("non-empty directory")'): + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % fs_img, + '%srm host 0:0 dir5' % fs_type]) + assert('directory is not empty' in ''.join(output)) + + def test_unlink6(self, u_boot_console, fs_obj_unlink): + """ + Test Case 6 - trying to deleting a "." should fail + """ + fs_type,fs_img = fs_obj_unlink + with u_boot_console.log.section('Test Case 6 - unlink (".")'): + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % fs_img, + '%srm host 0:0 dir5/.' % fs_type]) + assert('directory is not empty' in ''.join(output)) + + def test_unlink7(self, u_boot_console, fs_obj_unlink): + """ + Test Case 7 - trying to deleting a ".." should fail + """ + fs_type,fs_img = fs_obj_unlink + with u_boot_console.log.section('Test Case 7 - unlink ("..")'): + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % fs_img, + '%srm host 0:0 dir5/..' % fs_type]) + assert('directory is not empty' in ''.join(output))