From patchwork Tue Sep 4 07:49:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 145852 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3362664ljw; Tue, 4 Sep 2018 00:50:22 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdaw5qTo0sei3VrxW6t0dpJVdKvtLzhG+RgPQRcintrqnN4VIkbsHa79c3n3wCVlQpRNOAC0 X-Received: by 2002:aa7:d80e:: with SMTP id v14-v6mr35761638edq.255.1536047422890; Tue, 04 Sep 2018 00:50:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536047422; cv=none; d=google.com; s=arc-20160816; b=Tc5rtXAN1TQ5poP8UOqZSA2sB+fPNeVUsJl35SSovlilL0oLj5wElbN9jpib/r6SHY 371tKVoq/dBG6FTPJHgAcDBbBV5FS19AMZ5xkVT3Pi37MxaxulZqBqMRgPXF4KdgVW4U Sa8akLipIVVzLc58GzUykcm9P8GRSf9jHNrZ+T71bp540U1zjWhPlX0RHlxKRuTNGzYP EFxq7vMN9is4D0pDpZo+0mVBeapCZySrcn5zRzZ5aTyT4PVMk6Z4eAGqOB0oSyrQZO1n IRdL71YmcN9fxt+J/o3TOfsMQwvqPsVmOvKJZo3hLhS+GTDYUHAfiNhtojdvgOP5gO1r fEAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature:arc-authentication-results; bh=wFYq1b/f3J5R8GQpkk0IO4td4eSz3F7thuIadTBgj0w=; b=SV11BDPiyQzBXc1h6G9FTm8pzkWMOzvclOtXfYg8IL0f33G9NEe8MExA/QOs1tKd3U r3NDr3Lu7xZQ/Ti6iALYj+b5O3LaLRpjBMYPsR4ZH6DJrurdLtbnuXXyl0iITx6W3/6z r/Aume4s7KQLUrugO4oFxdbX0pSPO0z7azLjLStVHQCH01W+Qgtni1Nhkbglzi9HaS/e ni3oLHr+6bHbY3C/LUPumnlR1yfcPJmLk3cBo0JJtWCor0L9mDQBTo9lU3YvQrvnpcYS vyUbrKJ4zAtssonGRBOpwgFhQXz/l54TS3gxzSmzakF7Wx3Rjn399SgMTtcSz+K1Xycp pTUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=h7+w2UKh; 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 d30-v6si42578edn.311.2018.09.04.00.50.22; Tue, 04 Sep 2018 00:50:22 -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=h7+w2UKh; 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 68F4EC21F34; Tue, 4 Sep 2018 07:50: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 22ADAC21E4E; Tue, 4 Sep 2018 07:50:17 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 8C1B6C21EFB; Tue, 4 Sep 2018 07:50:00 +0000 (UTC) Received: from mail-pl1-f193.google.com (mail-pl1-f193.google.com [209.85.214.193]) by lists.denx.de (Postfix) with ESMTPS id 03274C21EE8 for ; Tue, 4 Sep 2018 07:49:56 +0000 (UTC) Received: by mail-pl1-f193.google.com with SMTP id b12-v6so1233278plr.8 for ; Tue, 04 Sep 2018 00:49:55 -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=DfRzWPWQ4lB7I4JLvE23YhmWMHI3MlCV+5OELHUfB3w=; b=h7+w2UKhBGPP6nPrKGuhzryHrtsZRKD9HjhsfQHWox2DWWcV/4Hyku0p8RxpGwCgJA +ZXLTjKEOg+dlmQZ1Ah2JNC/uqHD64K0tM5ZHSUJq1BZnxDzaG254BAmzTMyJg8qg+9U 4cCtLwNuFd2v661+zOHnc5M8sgcEK+YHj84Og= 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=DfRzWPWQ4lB7I4JLvE23YhmWMHI3MlCV+5OELHUfB3w=; b=oY11dJLtZHyoYJxt23/m+kqoCuf/E1P6T7p9Jtivj+sYbr6zCUXC62FDjJ0NxnFUwC 6D7bDhw5rV4SNsBvmAS13GReOwSV9eqZWPwRb3+crx9Usy5lIhzBfzLA/SxrezWL91+t cYNhi9lzgJRSgMuqyaZLlL6dDG0ZIoGTDx9jN3HZf4qFDswnu3lTlfTRP9cl9ifYLT05 dPjMDeAtYtTnvdg2QmGsq/xWuiTAmq0uySJ7bGDP5m6NNb103ji1uiKJ81RNj6oShRj3 dKGMUwnuJTEFdbdlRyRRwMVe7Zo+HcRvq3tyy1rD0sKrfo3FZT1dFymuYse5A/R/oohg 9EgA== X-Gm-Message-State: APzg51DGrlD8JlKZX82lRCEkIDv9M6ES48ekhqwUVym9toiiCIibaGR9 Px3f6r/WwPHP3b4W3+rNSvi9Ww== X-Received: by 2002:a17:902:158b:: with SMTP id m11-v6mr32400288pla.102.1536047394675; Tue, 04 Sep 2018 00:49:54 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id a90-v6sm37267701pfg.106.2018.09.04.00.49.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Sep 2018 00:49:54 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Tue, 4 Sep 2018 16:49:26 +0900 Message-Id: <20180904074948.18146-2-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180904074948.18146-1-takahiro.akashi@linaro.org> References: <20180904074948.18146-1-takahiro.akashi@linaro.org> Cc: xypron.glpk@gmx.de, agraf@suse.de, u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 01/23] 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" 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 4 07:49:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 145854 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3363932ljw; Tue, 4 Sep 2018 00:52:09 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYeb7nxrz2vRHvkQNBRlOGxTkx27Oq+j1UxEL9A+VviVt55VGx5MkBwxcDwoHeozQY4Y0R6 X-Received: by 2002:a50:9943:: with SMTP id l3-v6mr36342337edb.198.1536047529237; Tue, 04 Sep 2018 00:52:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536047529; cv=none; d=google.com; s=arc-20160816; b=glA/zLIEt3iC/QGWXvbXpvBGQHGbPDdwn1L5p0wyx3ez5CQPRewNZRG6JlwhhPDHWo 9uT68KYFP/OlQ2DgV9muN2AqelnM1QfWj5E38/9rA9SeOa4NfaREflWUXjTRJW2ywTWX BlbeVFWIdcVxtl6y247BOA4G5yz+mKBQ/HtHvZLoJlGQw1JDJyTczH+Bml3TPynKdDZU AM+s4aZe+ieFvKtqeb0mJCQWr/K9Cc8uxKT0ShCyly6TOVHNNJbEQz1QtPKdT3vK6aKh tSaW4ZKOTV6ODkkwkooBT99yTkriYr6d/CgnjCsmEQu76mlnoIz1+HpE9rxX022OlgY5 LqyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature:arc-authentication-results; bh=zzLvVeu9I30xNtYdIfH1X8vn7lxPReL5Oym6eFAN7TE=; b=n/ggM1VW4u5G4g0+OPuqYIvOr0sP1H1Kc2JaxgSEIDqbAiILBCBlGE+NChdPI7x416 5bV5xUxxvNFw2C3mRhMk6lmhYbG+B/nirfM7NIRla8L3DOEshJn7ctF+YI45Prdo41UB 980awGOEWYXAIpIG6UjjkwBY9ACnplI1cgXjJg6wYUIgZZZEnJi1nkjswo6RGGr2G5x8 8c0D5XaeCfBzRT4U4mLZnp43q6WYgzJv0MCBKKyok28v8T5uMkZmXC2TGslZkPdqqQrP Zy1hRRGp+M0zAT+onpxnVAnTYIB/7T+lfwRhZDjU7vLkDgr9BXMR614KkAIy+ZX3No+W uo3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=eJxWPKOz; 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 q23-v6si4055430eds.14.2018.09.04.00.52.09; Tue, 04 Sep 2018 00:52:09 -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=eJxWPKOz; 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 DAADEC21E49; Tue, 4 Sep 2018 07:50: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=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 D6573C21F00; Tue, 4 Sep 2018 07:50:17 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id D6455C21DA6; Tue, 4 Sep 2018 07:50:07 +0000 (UTC) Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) by lists.denx.de (Postfix) with ESMTPS id 10092C21F24 for ; Tue, 4 Sep 2018 07:50:07 +0000 (UTC) Received: by mail-pf1-f171.google.com with SMTP id l9-v6so1270728pff.9 for ; Tue, 04 Sep 2018 00:50:06 -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=3qrr9QH6inJDbghfQTPCEefOHDyZ8p0CbM4DD7Np98c=; b=eJxWPKOzKZGBivwX8oer+YhGAafi9W8uVblp71/ioprob9CKN83gDe+qQtdGp6Jupb D3/UPfmkerS3TtRFeDxEwQ2JqsjZT7d/eh/uJffQa4Ja153nZFqeTGzq4ZltE0gtrru9 lHAuBb7fq6LHeC3ckU0LfkkR/gvYmSHs6x5lI= 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=3qrr9QH6inJDbghfQTPCEefOHDyZ8p0CbM4DD7Np98c=; b=NUdRNqrtxpdEP2YO824wFDf6AidRh+y9/v4obmb99ao4rfyPfHJX8bYnEu1iMvdTKz dxeuY7fQzG2nmmFaG3tSfTUJ0PFB4gDy/4roFQkLHOngNod8+nkE2C/4qiUctb2UtSvS 3Q67OFHhzJF6mbNz2/4srFzkyPVzNKbnOiRO6qrUmWn2sDyTitVN0dcGa/0zh4KVgg9H wqsNJOyT8Q1VX34dyr8f+2FObeEIZYNyeR0ocKqE0oYpSDBQy0UgLFn/R2kolJ69JTCs PR3evfEzAD5Uwk/mnS1no3B7D4UY3tiyg/me2PlUnD7kGiUyHYgkiqbzU5PSpyDBgNzJ lMvA== X-Gm-Message-State: APzg51BItPwvqtoX0u3frxQ1s4JJlBr+N4ZoSKGJKDGi3ubByPRTeCJe tkCSX5Mqz3N8cQ/YhUwPPUYy3w== X-Received: by 2002:a63:4306:: with SMTP id q6-v6mr28902917pga.181.1536047405732; Tue, 04 Sep 2018 00:50:05 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id p19-v6sm24517679pgh.60.2018.09.04.00.50.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Sep 2018 00:50:05 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Tue, 4 Sep 2018 16:49:27 +0900 Message-Id: <20180904074948.18146-3-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180904074948.18146-1-takahiro.akashi@linaro.org> References: <20180904074948.18146-1-takahiro.akashi@linaro.org> Cc: xypron.glpk@gmx.de, agraf@suse.de, u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 02/23] 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" 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 4 07:49:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 145853 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3363464ljw; Tue, 4 Sep 2018 00:51:28 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZIs6C0PLUUqXTHqJMZ611nNbyPxKYjAIbek9p1ZhDw6Me75Cu12Vg4viYtwtAjKNEDn4Cd X-Received: by 2002:a50:bf0d:: with SMTP id f13-v6mr35818109edk.157.1536047488774; Tue, 04 Sep 2018 00:51:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536047488; cv=none; d=google.com; s=arc-20160816; b=pit6gsbkkUdf5u2icg3AbXDF37BGMvClRf2sIHTaScHKZpBwR/PYL3N4IBO9lAKA5P gpIaiEshGwyA26y1UlWAzsv132hHxHEPjVk8uZu+On3KCIMXHSMiZE0OHpqjcIEaMLaI QqDeakUR7pEDTtlriR1GKx3/eBzV+UfXJ9wMLghUqsZth+wqIQeXpAnOIjxB9VGqD3WI ShzgWazmEhS++Ldx7Co/TE0GNhubFNh9hgZNRR18CNSucFm623spjUdG+b5/4Qdin/37 oDmzH6K1xTZ6rw5j4cXV5AXrtlSENC8fzbW/0kLP8eY9WzQykPFT6qVe5BtuDLw0KS9G pv4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature:arc-authentication-results; bh=UjCjUbNIC7BvJhbxggVu4pNJuVle7DnrTmTsil27Gx4=; b=eYYTvbzn01I8Xv3cqlbdgDxBS1h6/uy6573sPdMT3ucgRqYii8A3Ygq1xD4skfJ5Fr nLiciCzFOtGey89dPBVgdM4Tcm8/C+BJb/hV+kwzWpeJMtaN2SzZ+4l2gc1RgK7Z7iEX P9CAMdnT6YFn7sNTBD63A0LvIT4i60RawLFv2jj969AeCZWb3eE5CEDmPgLxgCaNc42l etdM2YPkTGR2f+5QudX1XoBJT6wpUdGS/5chjU7HdOQ5VVGavtFueood6uhQI8RUZir9 y8Qv7yiLbJUvYwScgSfv/kaIxSYsK/IhocGhDdlmIdpG8sq2b5C/0i3LhJRh8DjcS56T x4cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Ddls1zua; 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 f17-v6si30824edq.89.2018.09.04.00.51.28; Tue, 04 Sep 2018 00:51:28 -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=Ddls1zua; 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 3D5F3C21F05; Tue, 4 Sep 2018 07:50:56 +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 54695C21EE8; Tue, 4 Sep 2018 07:50:40 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 90250C21EC8; Tue, 4 Sep 2018 07:50:22 +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 AF578C21F34 for ; Tue, 4 Sep 2018 07:50:17 +0000 (UTC) Received: by mail-pg1-f194.google.com with SMTP id x26-v6so1234961pge.12 for ; Tue, 04 Sep 2018 00:50: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=U+cSG0JMd3XVUOKmfaA+19W2ms/NtV5geclg5/GnRdc=; b=Ddls1zuamcWBOEVnz20WomZoKH13HxhvBnbQ03ArkssaQlglxGRPCBJwkK8g4oBlpM z9oLD5XNJ1UWiO9sCkXykd+GRldQZdwjxamVs5i4DoySS4QpHQvWTdXuzLs7RbaB3YX3 g5fkZrMPs4LX4fSNAGkRB5uUJnJBy60IoB+iE= 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=U+cSG0JMd3XVUOKmfaA+19W2ms/NtV5geclg5/GnRdc=; b=kNyyuQkgOlSjpCS4NNfFCevmisGknbJTUdDk9S32FdMqPOWZepHu3XtDOXy20JK6+k 034QDVjMpJHoG53J+kRzlodiOhwpykMs7ezT7xq2LMDAOrE5f0BhbFeK2MtuQqUKM4S4 jqo0/slDXBU9lvxV+KLZFew3lOUCkev795f/AyGZbSDdCRihdMA4h0PgFME/f+lQ7cJB Fw48M3qBQm0E8kTe7vMb/gBmaqMWsgUdr8gPc/EImrWNHrJnINIqgYB7nTNlPQdKLlUt bTgjCO7QF+mrUVOGy8JnEl879PHR6Fre54b9hqzC23IhLh9ZVCLZfw3CYmjK/M3//Ntf UvkQ== X-Gm-Message-State: APzg51Aqpj0I4cbgVS8aMVqJAU67z3GFqPCdth81mIirYLjPNV19ffKI sPLzDTkOd3s3GYB+tywODrMgSw== X-Received: by 2002:a63:d518:: with SMTP id c24-v6mr28787442pgg.357.1536047416381; Tue, 04 Sep 2018 00:50:16 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id e190-v6sm46295120pfc.81.2018.09.04.00.50.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Sep 2018 00:50:15 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Tue, 4 Sep 2018 16:49:28 +0900 Message-Id: <20180904074948.18146-4-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180904074948.18146-1-takahiro.akashi@linaro.org> References: <20180904074948.18146-1-takahiro.akashi@linaro.org> Cc: xypron.glpk@gmx.de, agraf@suse.de, u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 03/23] 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" 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 4 07:49:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 145856 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3364305ljw; Tue, 4 Sep 2018 00:52:39 -0700 (PDT) X-Google-Smtp-Source: ANB0VdasTTnHN0rKg9OwT6hBFp7zawjaOIQpbuIwlIItusJ/tZQ8s5ftOyAWGR2Xn2nucWr3ypcb X-Received: by 2002:a50:fa8b:: with SMTP id w11-v6mr12615855edr.59.1536047559692; Tue, 04 Sep 2018 00:52:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536047559; cv=none; d=google.com; s=arc-20160816; b=pqZ/jUI2xDHM1YMxZf1U7txJPST/tfF/2FKfDDHoSBwXjEaN2OTbT9JNneXuAPo1em 1BmbIOjpMLOVe5d7Z8D8zn8Y8cqMKSid6ZTrZGsO/kM7K54GX9VAjWm9vPZl2L51NLhY HQEV7iFwZKhjGtOIHFSjxP9qjfVcA4+eLmHND1SDAcoQs6gMnj6bfXgIVbKV+ezCGrPS WRQeTe8mFjiIC3HRq/on6s+kiz/YQGp70VxEXLjm1IdtI83FusNKNpZwktmBe7Hkd2dz yR0CJb7lFZmhc4E9knLjhkaE+zuf3Ktk77HNy8EPDKksT37nS+ybAXBRpcVyhqk39Yra jHPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature:arc-authentication-results; bh=aeUZj2qFpGLokdMQ7HoNP6FVhVHlXXIow2McIlMRznI=; b=FSq6kMCffmgXYGZpiZQUbL0K8Qu3y7CuYITh+yYX/K8Xp/YrE+S2wbdu1A5S5T/ZjS 567nxx1uvOzZwroiTf9xnBsOYhaJNrMoSqGv6jeX1Qetu7fuiBerE5nAPMJmhhVUYvaH HzIgWSwRt+bb58g1l6CZtWVlaQ1nOP5OPmohBfX80prVfnGs5LqFwDDuUntqfuut4pEi exZCuyPLDAi5wxLrmxDcSlcVESgtobbFg34/uDf9Iqf+eDChbIWXc0kg4SKwNN0Wr9V7 mPVP5hhvqlhIvCyuQ0MwY97bYhQ3ykLOlPCYYaaiXhWoNijfZ1naEKuUOesp00pJXX7x VCfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b="RCAV+lB/"; 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 b16-v6si2611151edh.182.2018.09.04.00.52.39; Tue, 04 Sep 2018 00:52: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="RCAV+lB/"; 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 44D33C21EFC; Tue, 4 Sep 2018 07:51:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=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 EAD63C21F2A; Tue, 4 Sep 2018 07:51:12 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id BD9D6C21EFB; Tue, 4 Sep 2018 07:50:44 +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 45C39C21F2A for ; Tue, 4 Sep 2018 07:50:41 +0000 (UTC) Received: by mail-pg1-f194.google.com with SMTP id 2-v6so1255178pgo.4 for ; Tue, 04 Sep 2018 00:50: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=GIeh8lLNlwEqZbN/Ylkl4kDPmqfsSWqu/sQpxn0xOso=; b=RCAV+lB/gxhlupUspNaF/ZZtytY+N7bFi6vrzlQkbKXp6eIwD/yk2O9gkucLJLY4co 6xZ+GGx6Fgx/KBGJh0sEVlqr/ayQDBllAXD8LsDPoDMyelkmhnJJnZqUS5QrT179GxmM JxT0/LKLyQ5OL4e6gAr3zGuU5SOTEco9eP/Hw= 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=GIeh8lLNlwEqZbN/Ylkl4kDPmqfsSWqu/sQpxn0xOso=; b=I1HO6RI1HkTFsW90n1UkkW3iPRXyhONobnheFDWzec+OMm3dMcVsNxEAyoU/kRByVR TYObLpqN/uKy19cByX1Wby1sP3RgXBexrv1XpH1CqjZND/A78Yj9hxzsiN4GFgMuzoS0 +28SzL8Lx/bKQL9CKWOgXn97TbwIvY5kk6Db/0f1v+YzZl/BE35IZN/S8mXyj9A9+e3V GxmhAqxWDgbxa65NVepd1XFSBAhhw1d2AtWFQq7fS+kXqKRoSYd7dt8Im5uN7o8hAo9O za+t9D24DCE5xOyFRyVdsqMAHfTaP+Hea9GK0N67xnk6DX9LJ3F1OUOCpmZ8p8IyMpHe FbMg== X-Gm-Message-State: APzg51C0QteixZw9J1cY3wGE6i9Q/BqNL7KrVgAYpFyyPzauEYIyT25L yxSlrYqzUq/Jv1DuPIOpWOUrfQ== X-Received: by 2002:a63:7557:: with SMTP id f23-v6mr15304301pgn.135.1536047439953; Tue, 04 Sep 2018 00:50:39 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id s75-v6sm37103921pfd.108.2018.09.04.00.50.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Sep 2018 00:50:39 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Tue, 4 Sep 2018 16:49:29 +0900 Message-Id: <20180904074948.18146-5-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180904074948.18146-1-takahiro.akashi@linaro.org> References: <20180904074948.18146-1-takahiro.akashi@linaro.org> Cc: xypron.glpk@gmx.de, agraf@suse.de, u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 04/23] fs: fat: make directory iterator global 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" Directory iterator was introduced in major re-work of read operation by Rob. We want to use it for write operation extensively as well. This patch makes relevant functions, as well as iterator definition, visible outside of fat.c. Signed-off-by: AKASHI Takahiro --- fs/fat/fat.c | 39 ++++++--------------------------------- include/fat.h | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 33 deletions(-) diff --git a/fs/fat/fat.c b/fs/fat/fat.c index eaea9300fd7f..0574af0c0011 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -638,25 +638,6 @@ static int get_fs_info(fsdata *mydata) * For more complete example, see fat_itr_resolve() */ -typedef struct { - fsdata *fsdata; /* filesystem parameters */ - unsigned clust; /* current cluster */ - 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 */ - - /* current iterator position values: */ - dir_entry *dent; /* current directory entry */ - char l_name[VFAT_MAXLEN_BYTES]; /* long (vfat) name */ - char s_name[14]; /* short 8.3 name */ - char *name; /* l_name if there is one, else s_name */ - - /* storage for current cluster in memory: */ - u8 block[MAX_CLUSTSIZE] __aligned(ARCH_DMA_MINALIGN); -} fat_itr; - -static int fat_itr_isdir(fat_itr *itr); - /** * fat_itr_root() - initialize an iterator to start at the root * directory @@ -665,7 +646,7 @@ static int fat_itr_isdir(fat_itr *itr); * @fsdata: filesystem data for the partition * @return 0 on success, else -errno */ -static int fat_itr_root(fat_itr *itr, fsdata *fsdata) +int fat_itr_root(fat_itr *itr, fsdata *fsdata) { if (get_fs_info(fsdata)) return -ENXIO; @@ -697,7 +678,7 @@ static int fat_itr_root(fat_itr *itr, fsdata *fsdata) * @parent: the iterator pointing at a directory entry in the * parent directory of the directory to iterate */ -static void fat_itr_child(fat_itr *itr, fat_itr *parent) +void fat_itr_child(fat_itr *itr, fat_itr *parent) { fsdata *mydata = parent->fsdata; /* for silly macros */ unsigned clustnum = START(parent->dent); @@ -717,7 +698,7 @@ static void fat_itr_child(fat_itr *itr, fat_itr *parent) itr->last_cluster = 0; } -static void *next_cluster(fat_itr *itr) +void *next_cluster(fat_itr *itr) { fsdata *mydata = itr->fsdata; /* for silly macros */ int ret; @@ -838,7 +819,7 @@ static dir_entry *extract_vfat_name(fat_itr *itr) * @return boolean, 1 if success or 0 if no more entries in the * current directory */ -static int fat_itr_next(fat_itr *itr) +int fat_itr_next(fat_itr *itr) { dir_entry *dent; @@ -883,19 +864,11 @@ static int fat_itr_next(fat_itr *itr) * @itr: the iterator * @return true if cursor is at a directory */ -static int fat_itr_isdir(fat_itr *itr) +int fat_itr_isdir(fat_itr *itr) { return !!(itr->dent->attr & ATTR_DIR); } -/* - * Helpers: - */ - -#define TYPE_FILE 0x1 -#define TYPE_DIR 0x2 -#define TYPE_ANY (TYPE_FILE | TYPE_DIR) - /** * fat_itr_resolve() - traverse directory structure to resolve the * requested path. @@ -911,7 +884,7 @@ static int fat_itr_isdir(fat_itr *itr) * @type: bitmask of allowable file types * @return 0 on success or -errno */ -static int fat_itr_resolve(fat_itr *itr, const char *path, unsigned type) +int fat_itr_resolve(fat_itr *itr, const char *path, unsigned type) { const char *next; diff --git a/include/fat.h b/include/fat.h index 127e6622a9b0..d86eb5a11576 100644 --- a/include/fat.h +++ b/include/fat.h @@ -189,6 +189,38 @@ static inline u32 sect_to_clust(fsdata *fsdata, int sect) return (sect - fsdata->data_begin) / fsdata->clust_size; } +/* + * Directory iterator + */ + +#define TYPE_FILE 0x1 +#define TYPE_DIR 0x2 +#define TYPE_ANY (TYPE_FILE | TYPE_DIR) + +typedef struct { + fsdata *fsdata; /* filesystem parameters */ + unsigned clust; /* current cluster */ + 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 */ + + /* current iterator position values: */ + dir_entry *dent; /* current directory entry */ + char l_name[VFAT_MAXLEN_BYTES]; /* long (vfat) name */ + char s_name[14]; /* short 8.3 name */ + char *name; /* l_name if there is one, else s_name */ + + /* storage for current cluster in memory: */ + u8 block[MAX_CLUSTSIZE] __aligned(ARCH_DMA_MINALIGN); +} fat_itr; + +int fat_itr_root(fat_itr *itr, fsdata *fsdata); +void fat_itr_child(fat_itr *itr, fat_itr *parent); +void *next_cluster(fat_itr *itr); +int fat_itr_next(fat_itr *itr); +int fat_itr_isdir(fat_itr *itr); +int fat_itr_resolve(fat_itr *itr, const char *path, unsigned type); + int file_fat_detectfs(void); int fat_exists(const char *filename); int fat_size(const char *filename, loff_t *size); From patchwork Tue Sep 4 07:49:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 145855 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3363967ljw; Tue, 4 Sep 2018 00:52:11 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbleeJxqfQ9pRkY8q188UhKrtfl2sZeFHnpK7USC7fZ3EiI65molkft2DGFNbuuB0F6Aegh X-Received: by 2002:a50:8ee4:: with SMTP id x33-v6mr35020546edx.252.1536047531694; Tue, 04 Sep 2018 00:52:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536047531; cv=none; d=google.com; s=arc-20160816; b=Ra73YXud9ZUPSKdVpKOYaSFa0VfR+EnBf2AgJOKhyEh1S8K9mkSiWXYEhzLLRuW1a2 UFlcd7qBdd3FXr3wxelvLLz1mq1OLciLe4Sb5meBEtjnLSUSQPRnwRWhy1Ht1oW+irww whZpmMrS4ppWRd5Dg/481cUs6NE7L74uTxZ+9DhSkRi4BS1m/oDxf4nq1RwwnVRKAwZn RPJdp1XRNeiYzRhRLRRDAHYcc3qHVNsTwgIARYtJwJT+Bptkp3pyfOrG1jzrw24dWK7q dsTNGD/O+UbOJoFB1dagSrx7H/1LCT2DGj4fbdGJBGqM57ImOLpzdFKZM+MZaetWXYTE sreA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature:arc-authentication-results; bh=4Ndd58saM4ybxdzbhBBjwH9xfcn/g9JkWoVmgORTFTE=; b=rSJb+/kB3lly9QuVN92NO4F8TdYo0c+mzfuX2U5aBuqyqcCFrqLusnFGRvXnxcw/tE MQ2KJkuDQOTjRINkGOuFPLEuj5WFgPWKDLjnFsc83PBlg66GBC5T87TJFpI0wpZBrsX6 GDH7PNbiBHTPKlir+MmLU44nRVMCzreVm66Fal9N9k2v0runyKIBdC1R3Jh06uEqYVz1 BArRVBATktbzIr2EiscjW2u1cjRe24D7oJIVp0y9UtxoaxyNANL5VdKiEeFyO9pPD3qy 5hMOa6u7L11VbhAAdG4uGkpYuc6pqBw+0w+78MOpnuFoA6Oxy22pbda+uPg90MKvvu9U dukQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=eB9wubb8; 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 g13-v6si994417edf.328.2018.09.04.00.52.11; Tue, 04 Sep 2018 00:52:11 -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=eB9wubb8; 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 3CC19C21EE8; Tue, 4 Sep 2018 07:52:04 +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 7CD96C21EBB; Tue, 4 Sep 2018 07:52:01 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 20BC5C21DEC; Tue, 4 Sep 2018 07:50:56 +0000 (UTC) Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) by lists.denx.de (Postfix) with ESMTPS id 37515C21D8E for ; Tue, 4 Sep 2018 07:50:51 +0000 (UTC) Received: by mail-pg1-f179.google.com with SMTP id d1-v6so1261064pgo.3 for ; Tue, 04 Sep 2018 00:50:51 -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=ys6XheIq6x/pFLbbYfjyJ6g4Zalor9R2KdEMPx6Or+I=; b=eB9wubb8q1K53TRBS8o2wJ5+DFyNiMMcXNtNnwX2u/hQ2arDrYTnzOUKleUmc5ErlC xv3kRQUxrhtex1VZEqYuX6FJtBAOVqgth+k56UBIS+Mk+eo3Sm6w9xA2wVXhq8I7Ah4B /N0bTp4JrN7ELl+pN/PxuM1/R4c46QTnqeKPM= 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=ys6XheIq6x/pFLbbYfjyJ6g4Zalor9R2KdEMPx6Or+I=; b=X768Wkic488Htl5zQVVik8nMhAr5T7h/rzMNyPZi8Ps5ZN9QwB53xyd+TI+s4Px4Lu 4JLLPJ4l/iZu8PSJDIiMUd4heT/8VWBMQoDOUuSuDD1ABQffUFJDkf5e+rBZVo9i40UB xH44wuGpH10dxwjM1kwtVjqxS6UnjGuyuEHD4gRIxa8p+CN6+Vp9QajEtaB9cEW5RmS6 gnHrazGcA+gmJE/UIkbDj02Uo/JzmY8wUdVvYBL5hvfOKTuJ0Y5SX0J1yXnkoukJsQo/ PNKn5LXN0VrURuqqEZ5U+zZTsQHH5Ahn8xhCU4R2UueSDpZYDX2bPKFLAC6W/j0JmwK8 63vg== X-Gm-Message-State: APzg51A5L9PPJHgnJlV74G1FdsMgn9z34VAEB7gTYcLombnJp9wlzyIH JbXp2FpZhQO8mQoS3cF+He/P/g== X-Received: by 2002:a63:e756:: with SMTP id j22-v6mr30225561pgk.185.1536047449903; Tue, 04 Sep 2018 00:50:49 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id v140-v6sm37403148pgb.45.2018.09.04.00.50.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Sep 2018 00:50:49 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Tue, 4 Sep 2018 16:49:30 +0900 Message-Id: <20180904074948.18146-6-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180904074948.18146-1-takahiro.akashi@linaro.org> References: <20180904074948.18146-1-takahiro.akashi@linaro.org> Cc: xypron.glpk@gmx.de, agraf@suse.de, u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 05/23] 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" 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 | 24 ++++++++++++++++-------- include/fat.h | 1 + 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/fs/fat/fat.c b/fs/fat/fat.c index 0574af0c0011..1e414380d527 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -653,6 +653,7 @@ 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; @@ -688,9 +689,11 @@ 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; @@ -708,7 +711,7 @@ 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); @@ -729,18 +732,19 @@ 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; } } @@ -756,8 +760,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; @@ -910,6 +917,7 @@ 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; diff --git a/include/fat.h b/include/fat.h index d86eb5a11576..9b114e3cbda4 100644 --- a/include/fat.h +++ b/include/fat.h @@ -200,6 +200,7 @@ static inline u32 sect_to_clust(fsdata *fsdata, int sect) 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 */ From patchwork Tue Sep 4 07:49:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 145862 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3368141ljw; Tue, 4 Sep 2018 00:57:51 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZBk5TVOMEMKuLEKcw231WpOEPkS4nz+j/mUCQX3NyE1T23eo45RFA1disUajA8vYJgfE85 X-Received: by 2002:aa7:c708:: with SMTP id i8-v6mr35854479edq.231.1536047871875; Tue, 04 Sep 2018 00:57:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536047871; cv=none; d=google.com; s=arc-20160816; b=ucTfsP6j9W14wbrEorhumuuDyQ/C3RMU2mKyIRPzQJubaLS0KmnfR+q7Lf/g+KBbWw bfAJgpfKRFHcdzledstJv7rMhv5Jx0cMlyLjVD1P8hoEUx/H9APtg1hjGZSjblmXDD8Z WqnBBqgxqd/VGIQ4YpqdnZzhbZntHudNzEF/03mXI2Mu5jWzpaHt+++lvEx//10LnEAz egmy0ryRe7DIjZkAsihtxn+6QOdwe6opU2kKhJJf2AJwa61dCa/U2rmG5kAW/vZyuTd+ KENdgw+3xTB271PQo9PuApZevOHsohLP8NNPuUUtIJHy2IW83CA7z0oYJNMsWVijJOpk 2KDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature:arc-authentication-results; bh=VgVazMn0ShOotXyqddOFg5J8E068Jwri8TQnsLAjKP0=; b=knAtaEsLg4GPD2kNU0DRAIU1MRHu4fMpoTuN5T2EyRikeVv2vz3WKOROS+6czecBQL +kagvoN8QgnzzA3p+K5BYwFgtVfmgm5CSkQNHYlmv9SprD3vcr/WjPFJ/33lsy15sJLb RwjTMO2EPJU4ZTTPeEMx0n7ArqvEKjLjgR8q//Vh7m+cBCtaW2WxQKV+jTsUjMXz4EkF MsaIdPjXBuPtVPfZLD4fT86EJTdJ4rkS+4yKqlJo7mBYf/FJGaN9kQEyLFMvCA4iwsMy QhqZ074krl9yLIPG97QlvVRA9i+AkmgHk2Cz7qQGitC+3wLYr0uHrIp0X9ncv9phjvn7 ovTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b="T0SKw/lM"; 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 v2-v6si569881edr.368.2018.09.04.00.57.51; Tue, 04 Sep 2018 00:57:51 -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="T0SKw/lM"; 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 7F54FC21EE8; Tue, 4 Sep 2018 07:52:21 +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 B6B73C21F29; Tue, 4 Sep 2018 07:52:11 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id BFDE3C21F3C; Tue, 4 Sep 2018 07:51:03 +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 3E2BAC21EFB for ; Tue, 4 Sep 2018 07:51:00 +0000 (UTC) Received: by mail-pl1-f195.google.com with SMTP id x6-v6so1232141plv.10 for ; Tue, 04 Sep 2018 00:51: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=SpBE0UKMVzI1Iv0u8PblzyD9AHUB5mxIHYIZanYQK7c=; b=T0SKw/lMRxygkhoRIEYLNaRKKanjOn9gHXyjXkE4HF3e1JP4uFkTsg3KKunJEF5Qp4 VjC9cRte+LbyhV5ZLzleszCsCNj76s3FEzK3y79oASwQRzdD6zLqb/nrsAv3nSLXnJPP Ghf+Y2DxPI/iEa/mJY41Gj2D2s8PD3WKfJiTU= 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=SpBE0UKMVzI1Iv0u8PblzyD9AHUB5mxIHYIZanYQK7c=; b=h9NUbaWtVaSl+KAFBFGfFt2DPFhdaAPNGf6SOqUrGPlhGJzFo/zFqZKFRzQ+A76d7r bfT0mcNcHubV1o9vP/9X0LXC5DFcQluChch+cB6nRYj6N/B9IVC6ULM8wvetHRPdW6EY aRGl0NlfgGsZ5q36cG41dRLXNeR4AdRmPjyzq7FYvyia670tPNd78Xnd8FydgimFN12A 5zmbbl7VtozFPuzU6U7YO1n9K8qnVdjKK1hQ00AwhJO9QiiSlfSBEztC8uWL5j519F/n MH2nx2YvIxAgnn1rJJSuwCR1UTnxMnFDSn4XguC6w9z57TEFLH9SzXI0Ay5otU6Ky6Gk Mplw== X-Gm-Message-State: APzg51DQ6VcIFw8TVaHzX1I4IfNKgd1p3A+GnCCpxVc+FvBTSj4EEwXh BtlSzAXADcPnPynJKytPSgOXrQ== X-Received: by 2002:a17:902:722:: with SMTP id 31-v6mr32164185pli.207.1536047458931; Tue, 04 Sep 2018 00:50:58 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id t86-v6sm28221836pfe.109.2018.09.04.00.50.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Sep 2018 00:50:58 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Tue, 4 Sep 2018 16:49:31 +0900 Message-Id: <20180904074948.18146-7-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180904074948.18146-1-takahiro.akashi@linaro.org> References: <20180904074948.18146-1-takahiro.akashi@linaro.org> Cc: xypron.glpk@gmx.de, agraf@suse.de, u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 06/23] 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" 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 4 07:49:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 145857 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3366773ljw; Tue, 4 Sep 2018 00:56:00 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZJn9sJiRZcgKS49pPq6y8J6AWFAgYqGPRubpweDOTQ6/wikft1DRW8SOiY3D7YR1GfPFFp X-Received: by 2002:a50:ef1a:: with SMTP id m26-v6mr35172696eds.136.1536047760325; Tue, 04 Sep 2018 00:56:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536047760; cv=none; d=google.com; s=arc-20160816; b=AQNcBL2nAPLLi5qRsV/uVfiIptQx4AyGzGLY7oUFLVGY4IYRSl/0iM768FWZxND7cN Yx74cZkcux+r3DHZa0GG+RmLdXwLMaAQL9A2R1k3KKSdddc2wicK96Dq3Fz5CBBXTScW XhhDUraB5Hk7J7HuZpVFZXDsNpvmxYthQgMJolZRHENmbZJteH+KtsS5eT1sRP3Z6imp oOgGKCY4kjxhe8OJtHZRKxXYrSFSDBBrdYPRT+jZmVWiVPYaTgOHbe32ACXS5YjBN0Dq mp5jwMTOMLTf8+MlHqU++NNaBBNip0IOmcaDhZ+173CWwz1a2/ajM00CAfPpbNNphYHH AWIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature:arc-authentication-results; bh=+WewJ1yx4oJlXk28CVxnS1fAPptzdiQHXGdXsfR+Qvo=; b=Aljw8Gbw42wFMrd7ENVr8hb6hawZ0AUR+ud/LAz7OXyN8hMT85lxVvtq/ITEj1EldA EQYpEgy+V7EFQcOGKw0bdxw2RmlCsYp24OuE9DdT2t2IpUjgNnnD/4TJlRg5dSYLpmJY izyZrYlUGtSkDUpi+HS8EDm/lanOUx92BP90uETBxvwQ/TleHlTJOipy+7Z2QizPGCaK AJcH0ax22CEIoyoX3j1+OsMmNQIhpReANHGWDLvR1Fvl6hLfH95f5q03gVD/jwW50m2Z +qFutpQENXvLEASJvp49YRpUYHPGcxdnwrUveV42hUXGWNfaqlpfz2UljTFPdA7NKwsv 0UUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b="a3hW/NU0"; 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 d89-v6si2146993edc.199.2018.09.04.00.56.00; Tue, 04 Sep 2018 00:56:00 -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="a3hW/NU0"; 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 DAF74C21F2A; Tue, 4 Sep 2018 07:53: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 09BF9C21F05; Tue, 4 Sep 2018 07:52:42 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 10191C21F37; Tue, 4 Sep 2018 07:51:10 +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 9B225C21EA2 for ; Tue, 4 Sep 2018 07:51:09 +0000 (UTC) Received: by mail-pg1-f194.google.com with SMTP id b129-v6so1232697pga.13 for ; Tue, 04 Sep 2018 00:51:09 -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=qNaJgioBe9gl2dduCmQpM6EPlZ0HJVibDPxhrX6FC3g=; b=a3hW/NU0n/L+vIlOhiuny/e0mXEyGxHzafHU2lEEvmJn3UmC8I/gbAgYqSOlk047Bl e7AiiNAWp8lHi6wgPEFe/kQ7CNg2m22mrr82Ua4yr8U80N5S9ZHJiYAspmeuI/hp0JGp hnUibIdH/npPCkWV9lVk/ziAUc9d6KxbAQEJE= 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=qNaJgioBe9gl2dduCmQpM6EPlZ0HJVibDPxhrX6FC3g=; b=YgZrEmwGgHHue72SxElZ8pwUPhwJLwXIlMU395UTfvbAC1tMsEtr5tHIBq5pppSuUB +/LDKCZ/u0IKKrlxAqFGNCW28WYMc+DgZcMmKs9PKvL6r2S6UjALQWJbI+lqBSm0TOAb R8XdKZFIr4Fok+GTqj/GgU+ZZX9GXWNCqSebKFbzO+Lv3vPWQ3Y6ky8RbnZ/DnadLvSj lg6hTuxd4tqP3zW3pyORutvJkm1obuL55H16Xme5Hzky8lJoFUXBViKoxIIZeGCjnYnE kc3bQMGxxNR9+22+dU905P1O30dhjDyDeQyl0RZgkE+/5ujolxdmrTXb6ZXcRJHkF+XD ah0w== X-Gm-Message-State: APzg51Ce3NgbLT2imhZ/5KHCMZ9IWRJfOpB3gUWsJZXCTf5Lx2Ah9nIi V90Mho7nzm+ZO9+xY5oPkukKHw== X-Received: by 2002:a63:fa0c:: with SMTP id y12-v6mr28138726pgh.177.1536047468309; Tue, 04 Sep 2018 00:51:08 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id n26-v6sm23409319pgv.78.2018.09.04.00.51.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Sep 2018 00:51:07 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Tue, 4 Sep 2018 16:49:32 +0900 Message-Id: <20180904074948.18146-8-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180904074948.18146-1-takahiro.akashi@linaro.org> References: <20180904074948.18146-1-takahiro.akashi@linaro.org> Cc: xypron.glpk@gmx.de, agraf@suse.de, u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 07/23] fs: fat: check and normailze 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" 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 4 07:49:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 145858 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3367020ljw; Tue, 4 Sep 2018 00:56:21 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYz05vol232MpdbKG8XSH3u6ab6Js4G4Tg0zC1EvZbyAnosNOqRAdM6Lt7pRbaG1H9Hnl23 X-Received: by 2002:a50:8978:: with SMTP id f53-v6mr34937171edf.166.1536047781411; Tue, 04 Sep 2018 00:56:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536047781; cv=none; d=google.com; s=arc-20160816; b=Eho9lT3CtQCcLag2r0RGKH8bdSmQALGX/Un2ai33zqKqsskCkOoGpm3Mzshr4PPolq 1WrAKW4DqTkR4P1vqitbSVAnj20hFoFCHaRDTeG6kM9qZMsYRi8bpFIQcudVoi5yuyuA 6h1zBCeHmDtWyzprk0clF8lLOI5migwrjPIUZ0/KduFBx1OzKyFuQwi5ttdhVnTc8TQq aE1ALL8ZD9OWZfwapMverTIcVWr7LnRkaQ1QEc+24hjiS6P+eRfHpUg5mbZu5SEGVHOM J8jwYV8ZUYw2uA2qj/GSIf/28TSQCl7fK4zcgXxvSN0JOhQwetWG2jFRfO25eyzG103e SJoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature:arc-authentication-results; bh=6jNPSIQQTiCZl4IUpS0iCF7DQqtgnM/PvSMEvzVYqfY=; b=Bqz0xVEnVisrWuK2vRtfyq8O4qOadzUy7mwpa7BLegmVm+PeXYGf/mEe8BRTQUiqfV iQ9hhUb2bgf6Ca2CJdmkDtJY8vCzjHQJZEfnorXn4HTb1c/6s/CfS+/iAzckf0hN6ea9 9jiYiHgBItCdUwkSbohO5ZViBrh7PEXhBSoREQo6cU9aoyTPtBmd6D33xYwF44akVaVc zTeIJel12wVwqAY8MkuxDVCg41yvRgcWkjv9CXjd4kkArXT4FEl+CIh16VI3QzzMqxVP KKllD4GhIMInjQL5WTywVrhiCJQ6Z3qzn1uwpNnTeKPePX/I5vQsdxucetkAvFmr8r3k 6Ykg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=bF3zRYbN; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id a58-v6si6888983edd.224.2018.09.04.00.56.21; Tue, 04 Sep 2018 00:56:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=bF3zRYbN; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.denx.de (Postfix, from userid 105) id 0F48CC21F3C; Tue, 4 Sep 2018 07:53:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 41E50C21F1B; Tue, 4 Sep 2018 07:52:38 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 0DD35C21F3C; Tue, 4 Sep 2018 07:51:23 +0000 (UTC) Received: from mail-pg1-f195.google.com (mail-pg1-f195.google.com [209.85.215.195]) by lists.denx.de (Postfix) with ESMTPS id D9359C21EBB for ; Tue, 4 Sep 2018 07:51:18 +0000 (UTC) Received: by mail-pg1-f195.google.com with SMTP id d1-v6so1261733pgo.3 for ; Tue, 04 Sep 2018 00:51:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=X7ZI/U94WrKfUolj3xO8yEJWPxPTuHmEgeLQAGDyIrQ=; b=bF3zRYbNyGVQDVQnM1onJhO9gjRaYYErLjgGkiAHPG8C8sw6/N9P5iJxl+a8+TmTT/ 23k5PbQWxWYGk+tjTdGK6ZcEy7DsJwtriCEV4l1sR8J7AbEUHzLloJDpEZC8Buj6x42W Rp2th4/LKfgY0fqg0/0jRWmc04UaSFUPVBaFI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=X7ZI/U94WrKfUolj3xO8yEJWPxPTuHmEgeLQAGDyIrQ=; b=UTT0oHvHIIcDM72l2E907ZaZQHvgDyFZQHMixAikd5lp3c5A/4TF7lv3hzLsDhfWuD glxlcS9nLD0NZCWaQHQqOl5vGwtr6nVGTfEhSqNC9n5a8q7CE1S9kkDH23MlTTYTll4B qqRXyfXGPsh37xUhHR4RUGGXV+flqQXW8TVCqiyOT7CzzSl1P7EJ4AUtcTnAUM5N0eCs YcCVaILzU9qt3qbEMR0lF93CleZavraOFPPsipyk+yUAvlrEx+AIiWFuvETuSRt7IUR9 WScajj1malSKeynd8F9nuqNp/PqG48J3zZ7Zhm8LFQFECIoHJXehY0OY0p55HpP7Axn5 2bsQ== X-Gm-Message-State: APzg51D2QVpipjYXY0ersAY/N5H+h62kOseD6mOWqW7MtcAfezofyPfD wNvkhZOucj17/Fn+iToMTeB89g== X-Received: by 2002:a65:608b:: with SMTP id t11-v6mr15589930pgu.259.1536047477502; Tue, 04 Sep 2018 00:51:17 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id l10-v6sm31807841pfj.179.2018.09.04.00.51.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Sep 2018 00:51:16 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Tue, 4 Sep 2018 16:49:33 +0900 Message-Id: <20180904074948.18146-9-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180904074948.18146-1-takahiro.akashi@linaro.org> References: <20180904074948.18146-1-takahiro.akashi@linaro.org> Cc: xypron.glpk@gmx.de, agraf@suse.de, u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 08/23] fs: fat: write returns error code instead of -1 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" It would be good that FAT write function return error code instead of just returning -1 as fat_read_file() does. This patch attempts to address this issue although it is 'best effort (or estimate)' for now. Signed-off-by: AKASHI Takahiro --- fs/fat/fat_write.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c index 6c715a70f447..1e4f5af9106d 100644 --- a/fs/fat/fat_write.c +++ b/fs/fat/fat_write.c @@ -956,7 +956,7 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, if (read_bootsectandvi(&bs, &volinfo, &mydata->fatsize)) { debug("error: reading boot sector\n"); - return -1; + return -EIO; } total_sector = bs.total_sect; @@ -997,7 +997,7 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, mydata->fatbuf = memalign(ARCH_DMA_MINALIGN, FATBUFSIZE); if (mydata->fatbuf == NULL) { debug("Error: allocating memory\n"); - return -1; + return -ENOMEM; } if (disk_read(cursect, @@ -1005,6 +1005,7 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, (mydata->clust_size) : PREFETCH_BLOCKS, do_fat_read_at_block) < 0) { debug("Error: reading rootdir block\n"); + ret = -EIO; goto exit; } dentptr = (dir_entry *) do_fat_read_at_block; @@ -1029,6 +1030,7 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, size); if (ret) { printf("Error: %llu overflow\n", size); + ret = -ENOSPC; goto exit; } } @@ -1036,6 +1038,7 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, ret = clear_fatent(mydata, start_cluster); if (ret) { printf("Error: clearing FAT entries\n"); + ret = -EIO; goto exit; } @@ -1045,12 +1048,14 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, ret = start_cluster = find_empty_cluster(mydata); if (ret < 0) { printf("Error: finding empty cluster\n"); + ret = -ENOSPC; goto exit; } ret = check_overflow(mydata, start_cluster, size); if (ret) { printf("Error: %llu overflow\n", size); + ret = -ENOSPC; goto exit; } @@ -1065,12 +1070,14 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, ret = start_cluster = find_empty_cluster(mydata); if (ret < 0) { printf("Error: finding empty cluster\n"); + ret = -ENOSPC; goto exit; } ret = check_overflow(mydata, start_cluster, size); if (ret) { printf("Error: %llu overflow\n", size); + ret = -ENOSPC; goto exit; } } else { @@ -1087,6 +1094,7 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, ret = set_contents(mydata, retdent, buffer, size, actwrite); if (ret < 0) { printf("Error: writing contents\n"); + ret = -EIO; goto exit; } debug("attempt to write 0x%llx bytes\n", *actwrite); @@ -1095,14 +1103,17 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, ret = flush_dirty_fat_buffer(mydata); if (ret) { printf("Error: flush fat buffer\n"); + ret = -EIO; goto exit; } /* Write directory table to device */ ret = set_cluster(mydata, dir_curclust, get_dentfromdir_block, mydata->clust_size * mydata->sect_size); - if (ret) + if (ret) { printf("Error: writing directory entry\n"); + ret = -EIO; + } exit: free(mydata->fatbuf); @@ -1114,7 +1125,7 @@ int file_fat_write(const char *filename, void *buffer, loff_t offset, { if (offset != 0) { printf("Error: non zero offset is currently not supported.\n"); - return -1; + return -EINVAL; } printf("writing %s\n", filename); From patchwork Tue Sep 4 07:49:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 145863 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3369174ljw; Tue, 4 Sep 2018 00:59:13 -0700 (PDT) X-Google-Smtp-Source: ANB0VdY+td7qJqMPh89zMyrvzQLsY6AE4VWE6agINM6S5/Se+8aIFNaN19urXW+uQiP+h7I1MROY X-Received: by 2002:a50:a542:: with SMTP id z2-v6mr34036728edb.77.1536047953800; Tue, 04 Sep 2018 00:59:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536047953; cv=none; d=google.com; s=arc-20160816; b=f28oTAklwByF7AxN4X+K8Fdl3lB+iWJgTJtJitJUxmV6zay2fKJvvnB7T3ams5RSkA 8dAmRdhOC+ahoD9hjH4lPSEuqQCki3prbI/sNWxdpDw+d6Qs67XVcQOdYfFmZm9cOsP0 ounsBs0kiuoyB5m4B+1X1VD2Nku7X0cVRTvqlM8e3lH3sFUUWP3Dsh4X01EiN/VXojVr /LPJDR+44UtE5gCA1DbPpAql45vlMEkhdcJbZNCjCa7aGoFFnLFXY1XdBReuBcXBsgTA nbpyM6h2OnpIX1meTQ5tN8fLSrSC16qsDaaFhQHL22fkzaZ4GZXfBDFw8j/BQLKQYF3a ZcUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature:arc-authentication-results; bh=fLqxWqGORp8MTNf4cdTEMEX+/i1CN2DQN7BE59htCNU=; b=BwlIDnadiOTIMByQMCST6YL/qlrnyxuRDW37Fzmr2oGF0LxhwmJeOOkWKDjT/DD2v+ MukeMdfGrB75/N6WjSGTCnl+WMnjBfRNB46mhXy+zCsN+f6YHhMTbVjZrkrE8aNKmIRg ogf8c2nHBKRQUhuqyrGaYnS5J4e91Br2syu+WO712fBfqrU6sw1Iki/sv17gPvctBnFB KExjOG3AjO0z2mJRfnpvElca02Kzu4IRy1kr9hYY3fMPSuSaHROSStAdFYA9fsxo286s VlSpSuRS7+k/A9ASQXKOtls50ESfM7QZJolFIWTD/JB8rju64eerJpNM+RsXOGVXRQHV 31HQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=dDzQ3Gn8; 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-v6si5669634edr.310.2018.09.04.00.59.13; Tue, 04 Sep 2018 00:59:13 -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=dDzQ3Gn8; 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 310ADC21F24; Tue, 4 Sep 2018 07:53:56 +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 94E86C21ECA; Tue, 4 Sep 2018 07:53:29 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 98D48C21F24; Tue, 4 Sep 2018 07:51:32 +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 B5B1CC21EE8 for ; Tue, 4 Sep 2018 07:51:30 +0000 (UTC) Received: by mail-pf1-f194.google.com with SMTP id x17-v6so1283464pfh.5 for ; Tue, 04 Sep 2018 00:51:30 -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=7MK5cV/TXifgsRuPZ/VNv9YmheAIRZiUBLDDi6Ypj3U=; b=dDzQ3Gn8QtsynsTErYS/G7TOy2D5mBEeS4OgN1Vv3eo0gXCijq3wYWUnVnpdz/AnTu 4MClH5Nwu02gKw1dD0WYkS6+55zi828A+syuKp3Uiya1qVhQsG9U0PJh+dkdNedYiI3R VQaqP9g5RIdSmEGZOcIy4mruvu0uvJ+334QLA= 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=7MK5cV/TXifgsRuPZ/VNv9YmheAIRZiUBLDDi6Ypj3U=; b=asQbI5rg6ZqFkKI8sY8wfst5bDcCVtujRpAPbHXNI4R+iDb1C+sqvPNNXKKpUhmBW1 oFlHWgGtrv97y+bx7a8+yfK//M/U8lR+VQS29ky87P97qQ6rlGRZq4E176MKqkDSaWB9 oQsUr6UzCgLqG7ly3MZdTrp+hARIX2GbgaOFTO+ri9DpqyrjzEkSMElUXu8es9w8ZzeR oONGWYknxpLg1oD53m8PR5m+a4ijgwS5SMuOcD4148K5C3ejyCvSKFBOVLA5CSXcoBRa sxUFliQyxpIBaC6sJoo3aUpqqalk8VUiRJ2ahs+kxfRfCj/o+qCAxmYNy9ejWNYcL7dl YxBQ== X-Gm-Message-State: APzg51D5pmqVBor8+nkw0QbBVhaux/3o13PlilPb+Ddoi3hGJdIXvmwE 9IynpcDxWDWvEqX2da8S5AIMGA== X-Received: by 2002:a63:2bc9:: with SMTP id r192-v6mr10224259pgr.386.1536047489035; Tue, 04 Sep 2018 00:51:29 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id s3-v6sm39946830pgj.84.2018.09.04.00.51.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Sep 2018 00:51:28 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Tue, 4 Sep 2018 16:49:34 +0900 Message-Id: <20180904074948.18146-10-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180904074948.18146-1-takahiro.akashi@linaro.org> References: <20180904074948.18146-1-takahiro.akashi@linaro.org> Cc: xypron.glpk@gmx.de, agraf@suse.de, u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 09/23] 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" 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 | 467 +++++++++++++++------------------------------ 2 files changed, 155 insertions(+), 321 deletions(-) diff --git a/fs/fat/fat.c b/fs/fat/fat.c index 1e414380d527..50c2d4f3c33d 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..cc55c94f1b72 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); @@ -1085,10 +926,10 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, } /* Set attribute as archieve for regular file */ - fill_dentry(mydata, empty_dentptr, filename, - start_cluster, size, 0x20); + 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 4 07:49:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 145861 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3368007ljw; Tue, 4 Sep 2018 00:57:39 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdbk/4Z8gv6IAU9jYW+yCF4MIgeJhjcrw0NU7iffwyiwptLqm+mZ0iHK9XlrxVRfgarMfv05 X-Received: by 2002:a50:b6e3:: with SMTP id f32-v6mr35709465ede.147.1536047859440; Tue, 04 Sep 2018 00:57:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536047859; cv=none; d=google.com; s=arc-20160816; b=A7JuV5JyJ42epXYtosqiW64AQUYQ/YcihzJFig+Uz6LkfN56yHc3IAKVGOhOdyCGCC hn4iJ7wCCiOZpBnvUPylf3uMkTVlLgjHWAkCwgToj3Pjt7mxiIyjPRFVTCjjVVGcGrj6 70VsrTHqaq6JENpGr/ORkmk1Yi4+AlG/MpP4SsmnF/kP7M0kzZ2SzbJkheeueZQ/+w3t HX5m1IChFgrXY4vBxMJUDeIkH9BcuhCM1AheZOgO6K+7nZW+HS1WfzNmzcLiiS1EtYHd /A2JtjEgdBOj9Pe9wwQeMVofkpTVIyf4jmYbjmA/jXfsVClwqZp31xoxR50jM46urS16 JjGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature:arc-authentication-results; bh=HOxU4OhxObChd5WJPRHhyFmUwVPc241LQweBm+YKRmQ=; b=ySI8+qcfKZVKrp8/hL0WUjPyU3/BIT/qCSFLSJviHZIPm/ly3RJOtUt4E+o+/ttVXO BNMIeNOCttkV9oSR1lotfQawUtvVyuqzJaWY6ArJNO9RofQH1HGYExx7JP+wkHG1yS3a PLcfRArMIlZi8c0qBSPjWRKLsxlrQ9sUacPUh/F5AUoqko4nVMZHc4sO1+0D5/5diklj 7vVLwP9cWF3zNHUl3ZCYZowNcsvW19c4gnx7nntJ26EMYxqrY+e9OlRe0y7OV9p7R9+m RdtiTfdn/AosHv9F6SbDCVBPCWjSHL4KJaBQUshBYpC1ZgtjCqaNywI5RF6qH+R8ohLX BFkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=FvLj5MVT; 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 r9-v6si4485165edp.9.2018.09.04.00.57.39; Tue, 04 Sep 2018 00:57: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=FvLj5MVT; 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 0EE29C21F2A; Tue, 4 Sep 2018 07:55: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 A870EC21E44; Tue, 4 Sep 2018 07:53:35 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id D2BD0C21EF1; Tue, 4 Sep 2018 07:51:39 +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 E40A5C21E4E for ; Tue, 4 Sep 2018 07:51:38 +0000 (UTC) Received: by mail-pf1-f195.google.com with SMTP id d4-v6so1296234pfn.0 for ; Tue, 04 Sep 2018 00:51:38 -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=62Cnji+Q6WSq+AxhlzBta2yfmUXHF/pflqMhI73rUqo=; b=FvLj5MVTNcRe8u74OPhasL5Au/DAEBJaE7tPmakRsSl+V3aLAcL6Ffqd24h4q2uXdx iHQvYoQscH0iZgsDPb3fzkfsuraVlmk/LiDxboB6X8M03IjcikoVqCyMHfNAzr3CLbA1 4FNABAnu+1NeRPVEyAXd/kk3kNjAzkFkJWQZ4= 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=62Cnji+Q6WSq+AxhlzBta2yfmUXHF/pflqMhI73rUqo=; b=LelS6WLSX0ktTyB+ZV50NZUAd8Do+p83cMV1fek2n09cHqOEBWwdKq66A71l9ugCj9 t1DfhCAkMLzQtfyR0UE+JNepyEL9UMroZV7EJyO4kkQOCDrvidqBm0ULmANBZnu+XAjI /IggbDer1g8r8PX0FP6aNfzrtJPTGg8/mMryDaJcdCQq1EY5MVYUY6ICBtEfkUbZPJoc UxzEOqr9MumukgX6ycZJCMoVBN9iQjJsGNXXdqRFYZsiR+PB03fIQFk/IpHpqpFLbWlY hjeWqlLDQb+ywhxO0q1Ve/RNye/cGWCPkIBjd8Oai/eL/SAp2GeV+oxv7zlb3+VPhK4e Yy0A== X-Gm-Message-State: APzg51DeRJlstKdERwK4JHBZDonKrqUXGYx2WTFU4E1pQXMaMwNNxI87 VWUmr0JMkH0UtvSGakaTQgx+nA== X-Received: by 2002:a62:4255:: with SMTP id p82-v6mr33672781pfa.238.1536047497448; Tue, 04 Sep 2018 00:51:37 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id d66-v6sm37287260pfd.121.2018.09.04.00.51.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Sep 2018 00:51:36 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Tue, 4 Sep 2018 16:49:35 +0900 Message-Id: <20180904074948.18146-11-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180904074948.18146-1-takahiro.akashi@linaro.org> References: <20180904074948.18146-1-takahiro.akashi@linaro.org> Cc: xypron.glpk@gmx.de, agraf@suse.de, u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 10/23] 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" 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 cc55c94f1b72..5db7830ad43c 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 archieve 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 4 07:49:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 145859 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3367295ljw; Tue, 4 Sep 2018 00:56:43 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZ9HOIPwoRoCB9xwuOdWOYIhxoEu7QN2os3+E4SYdC74CLm21xE/lBqZVKqLUqzPlHA0/yB X-Received: by 2002:a50:a7e2:: with SMTP id i89-v6mr34907514edc.176.1536047803295; Tue, 04 Sep 2018 00:56:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536047803; cv=none; d=google.com; s=arc-20160816; b=UMmjDLljLb/LEFjk+eZXVKI/14tL6D6ql/q1sQz7mjmhfXkPYeighGCwwQcS+WNyFs FkQA8Upqc0S0VVNbwxxQ2SDjCuZdOyy7JnCn9D3q+c5TNj9Z44UV+I+hBhqxntoN6jRx w30fgbWxdiIfEWJ2TXCy/JYA1czzHDlDVG7f7coANiqW7fSjDLK3cyf5YcEPHAzD/ACy BLCL24NUqfYAlgPRSOC/EST7hAJGp2XfwkKuXDxYwE7wc6GQk2gFUu2Lgt4U9GK+nRYV qJhq3XK/Wc9sEQXt74O9cnjL46cH/hrTlan2VehCE1xVwOrb++yvyuz2Y8H/gC2t12VK KpJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature:arc-authentication-results; bh=EiSNEH/irg+h5lXKlq2ZXgIGWlGdICNichzaJGlv2Ic=; b=Qp86w+oTooHDGK8VOgSdgO3l9Z8Jp4Qii3otjLdY+u0a6Fw/5EFIKWQ08ZFQjqRKvM sl9g44BLPfXwzMmwiICU+5jwAm9757ZHylvmPg22/3Nrg7WutVmG4riHR7TBVxkQsvLV nMF9/+nj8XMwOmXe72XYiNSDc9pce/+upwsDIHl9+m+Qr6ZsngbhdTsMFBVrJaMwvoHk 07FdIpcHvJGOaiLinndNf49Y/hwnkQEJvu2eNcnDXWMY4V+3FNeU9XgFkXh/9ZnMHOem bBzY+TX7j449gtTeayb9lfMPY2l/Ogd9GsAivDuVu9w5XssoQZMjsOXmjNxTg2DztyU9 ETsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Zd7832KA; 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 c8si4530807edw.301.2018.09.04.00.56.43; Tue, 04 Sep 2018 00:56: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=Zd7832KA; 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 D6AABC21F32; Tue, 4 Sep 2018 07:54: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 D91D3C21E4E; Tue, 4 Sep 2018 07:53:33 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 9EA03C21F32; Tue, 4 Sep 2018 07:51:47 +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 1C858C21F2A for ; Tue, 4 Sep 2018 07:51:47 +0000 (UTC) Received: by mail-pg1-f193.google.com with SMTP id x26-v6so1236997pge.12 for ; Tue, 04 Sep 2018 00:51: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=RjGLMDA1zC9xnkIUTqYOyNjFaMCbA7j71lV4+hyJf2s=; b=Zd7832KADnH8BdLtQB3Y/hEpWXheugOmKYxI/Db0j0gaJiFrQNv1DnRAotm9G8WzdO f9/AenQx0Jz24HHjFyh95o9CDwyLmf23aRjxAJxKRQid0yD1BoLJ4mcHCxIkxbkJtWLC An+UwZzLtRkUUbUvF1WucBxGTIP4y7QwBVrrk= 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=RjGLMDA1zC9xnkIUTqYOyNjFaMCbA7j71lV4+hyJf2s=; b=QC7ywH3uL+rfZpl/+WbiydK20Vs+VK3zdUeSGKjx/mmeWoWhfXgVueaWM6yRqFkdHC 4FX/8agGdCZLDKuNDdyswDVQLh6K2oi+cLPOZzLZYwQRLdbhNVYfJ0HuxwBN5qo3JOLh 6c97rRCbfSmLKpt0h4inqhtMz4Sldet1IeiQ4G1EUOdn84WizlHnSr5WBQaE5WvT8sct qNsfzqxPq8gFdLG/K/EhiIslrsKEql8T0LBlovYRjaAAEghrQd8iB7Xxlss9B55Fzqnp qmPJRKCYVCUMwEeS2lK/xWe677HyJM2FO8XVPBvHGaC38hGj0ZSdgQT/u/uRPZxN/2av SPdQ== X-Gm-Message-State: APzg51CrWRKvkPfO8k2y/FVPJHH43E6sWos9GbdQldq+igovcLwz2Ce9 3bShuXdfJcMM/NSAyzXi7zAP6A== X-Received: by 2002:a63:fc07:: with SMTP id j7-v6mr27763184pgi.1.1536047505708; Tue, 04 Sep 2018 00:51:45 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id b21-v6sm53522428pfm.97.2018.09.04.00.51.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Sep 2018 00:51:45 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Tue, 4 Sep 2018 16:49:36 +0900 Message-Id: <20180904074948.18146-12-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180904074948.18146-1-takahiro.akashi@linaro.org> References: <20180904074948.18146-1-takahiro.akashi@linaro.org> Cc: xypron.glpk@gmx.de, agraf@suse.de, u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 11/23] 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" 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 5db7830ad43c..523abd62c9e9 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 4 07:49:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 145865 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3369840ljw; Tue, 4 Sep 2018 01:00:13 -0700 (PDT) X-Google-Smtp-Source: ANB0VdY3KBICLNCKtls9wOqOXVG5qMxt5lcWTDqz91PLVO0bfMbuBo/4dqJc0ynkK2IzOYpeR8PZ X-Received: by 2002:a50:fa0a:: with SMTP id b10-v6mr35554139edq.138.1536048013617; Tue, 04 Sep 2018 01:00:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536048013; cv=none; d=google.com; s=arc-20160816; b=D2oYIz5x48DxxbTLl7ORgeZFl8fFx6RDMAFrNoPnawM5PkGPoZU19UcDhJ3Ca2tv7M GYA/6i6D1kwIi52f8oy2hqJc5SdFdivSoTBulVw1K7xWGl7zJZ9d+3hcfD8na0PfBwh2 jTAg3frvNSpTCr6BMdE95aAJVFSLsWR/ahweZLEOVF1rpnyRJcW/pmngXeEGEQkb15Sd s5PP+ukW74b+4+F8rw6y5Jhnbstzw8JA3ISLBAqQmVJENY03f5+dkqp0yKaDW3u6jeCo 87uiM9k1bfCEAs7pmeLpZcvqrG0+Fp9Zgz4fKoz3AL8ZidTe0NDQlAId+1EYmSgBm/WF ryjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature:arc-authentication-results; bh=lQOpiGIFJBkE8j3fJxdHzxZA6pxUJc+QMxm4HCItZzw=; b=AvNb0LHYRsTZdky9dhJnkuGZesceHKMIGKKFG/nt/bE8IKFhyFhUKSj+0umF96WOXC ScKNuAdSzDdiJKC/NI/ajVRUOvzxfG3Y69nGeiyuw093eem/kcQjxIL9cVNVsF8Ejb8E lk+RlsIlN7AIqNleQSX18YmVjECpj4k6TYo+CJN0rM6YijQnb4T5roTMqkRA/p/d5wYV pZ/li2xC1Tbtkyqh9q3LbA3IKfy/vFO/ww7o6PjX5r5wKEhGWpk0kJFqLkPvM5n5oHsv n46tPY+IFaPBrlE0YBvhhWpg/Ane5ftXyrnPM1WoyQN+A3brr3gl7n7Hd54EXB1URd0Q Ms7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b="hZ8nI/iX"; 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 b100-v6si8218744edf.286.2018.09.04.01.00.13; Tue, 04 Sep 2018 01:00:13 -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="hZ8nI/iX"; 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 3288AC21F6A; Tue, 4 Sep 2018 07:53: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 141CDC21F4A; Tue, 4 Sep 2018 07:52:41 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id ABF2DC21F3D; Tue, 4 Sep 2018 07:51:55 +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 8BED4C21EA2 for ; Tue, 4 Sep 2018 07:51:54 +0000 (UTC) Received: by mail-pf1-f194.google.com with SMTP id k21-v6so1268215pff.11 for ; Tue, 04 Sep 2018 00:51:54 -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=DHFvjeOmhKQ3GLYF5Mk7C5kpkZKBhEFreRCeYZsCrW0=; b=hZ8nI/iXeeHg2GBcDVj//tpFXocW7SGR2H7Kqx5mnZrsBI8WUqKW74pCPYE+XsELCs XKFzGer6peG5n2twCb25QJ6Z+Zp91vI9d1mCVZ92+6FD6HQlo982Lz1c9A95zhN3fqyU 0t79SX3Pc/u3F9wOsoG9faiWwDhIGQZNO3AFU= 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=DHFvjeOmhKQ3GLYF5Mk7C5kpkZKBhEFreRCeYZsCrW0=; b=cptJ0Z0lXIFFYZojvs8p7+CYTunXeguCL17MXJ3eP1MOlsrAOpYU/XykH1nbVrN9oo YRjslMuj4ZoX7XsKQicGCfVd6OhqA0Mh6+WR2q1Vb3D0P20PGK8HZFVXpswwOUl3Akf3 kT9ce+8IuYZwOp/SQBiBHitSuDsUfhVyIHzvzxFUqGBl/DkbtN/eKy7SL9H+N66VC1BQ /xdvkTJJwPJ9Im4rdel6HqfC+UlBbSVwvWpRUcaM2nHzq5r0z9fW+HBXrFHBvprP7YaW Gc1SFsgWzGy8FyET0dnAnBe2Hwg5tVMv6gBMggzDgaAB3v30Ik0EW9C3u+WvW9jOSbAm v8Gw== X-Gm-Message-State: APzg51BNSRye7In7LSvzrmvSBfLB5pOEN10e7AuhDeslI94FKoZCYFku ORYiYTnTxDfznag9BVBjZ/Sh6prC7eQ= X-Received: by 2002:a63:88c8:: with SMTP id l191-v6mr30024242pgd.340.1536047513245; Tue, 04 Sep 2018 00:51:53 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id 5-v6sm27063002pgc.86.2018.09.04.00.51.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Sep 2018 00:51:52 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Tue, 4 Sep 2018 16:49:37 +0900 Message-Id: <20180904074948.18146-13-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180904074948.18146-1-takahiro.akashi@linaro.org> References: <20180904074948.18146-1-takahiro.akashi@linaro.org> Cc: xypron.glpk@gmx.de, agraf@suse.de, u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 12/23] 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" 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 4 07:49:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 145866 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3370413ljw; Tue, 4 Sep 2018 01:00:46 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZHsFJN15574vo/W/RdS7yxTvv5ekuZu5WV0iXGjbmmY5U47qBmm/XO4fqTqe70lL2JFVGk X-Received: by 2002:aa7:c314:: with SMTP id l20-v6mr34781168edq.53.1536048046874; Tue, 04 Sep 2018 01:00:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536048046; cv=none; d=google.com; s=arc-20160816; b=yeWlULl02yx4Q/gt4Uuz9D35pqTDrVV19QWEV7BzAARG5SpV0vdlK7VCK8Riag9xwj 47WVQIXjVEyQ3jOpCCqnec0qBPbkGY68Q5EwdbEnK8KBeRMtdSMEXfiTyEZm8pKMQsEV VlvbJtzK9WMoC4xEMoRi2YcMaYzVM/cJpLGH/utgGzRBDFR1O1JGbp14JExTmdLDEy0E i+YOQ/SkiCXOJwf+e5CBQIw+8MMVpb4vbMvUBrOVvTprPFX4+FFFK17iYJk2rQvEI61/ frjzO0ddexNyk3Oac9l8vV6th+ieN6aaFp/3cFIwLUd670nt5ulFGEz/oSYpCpQBCO2I C0oA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature:arc-authentication-results; bh=+R6YZ3duVwlbHQsXGjFxi6nrRVyslT3IBlT1EvdBb2I=; b=DSs5fGKjq/vvoO2RxfXfjW/a62/iSqKuZF8mUtN/l7DtlhR+/dVj1KCkiQ0rK5eYdf DlXaA2K7hI817QpTjcCtGEPlum4fBRettjLrkDP4h1yCa6TH8u0uOORrqX9NmuyOkv+c T7tymzG+DB6dnb8lvCxySYp6V8PyXH+D9o1EeyEXw5LqHv5p3QlShnSf6ThzY4cAi+gn gcC/SWZia0qBSFnLDqKaymsENvny+7H8Mv3Kl+R+UFi4KzgJqWl8fCmk5nSFu2XpvxpH yFKRJE9nJve/vCvCRMYQTMVmI7dZJ6lTMzriYJ533tP5XoSHHnQwL4l1fuILIXLimAxD pj7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=JP3YyDuF; 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-v6si717851edr.290.2018.09.04.01.00.46; Tue, 04 Sep 2018 01:00: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=JP3YyDuF; 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 78C14C21E49; Tue, 4 Sep 2018 07:52:41 +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 5D37DC21F2F; Tue, 4 Sep 2018 07:52:27 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 46CC2C21F24; Tue, 4 Sep 2018 07:52:05 +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 0CDF5C21F05 for ; Tue, 4 Sep 2018 07:52:02 +0000 (UTC) Received: by mail-pf1-f196.google.com with SMTP id b11-v6so1289794pfo.3 for ; Tue, 04 Sep 2018 00:52:01 -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=KUbEBLLEiOGSfLLeu3DRSDyelWRj+eLD4n+pf52SbgA=; b=JP3YyDuFnVG5v6YVczvXPg1djkmEnjHi00g8TFmURbSd+XnZxzrsHUSWRp92fT+YXi JjATAgZl1E5YxSAw9LG3XaBC6g4kAYRXf10rTkR3nUJvvypOo4TkHqQOMu3Y963MWubg Grvu7PZwb6wWHlReTwya5wcXEZhX+vomlEX9Q= 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=KUbEBLLEiOGSfLLeu3DRSDyelWRj+eLD4n+pf52SbgA=; b=oBFQ4VWfk8uQyK2EOu9i99OCPB0N/+nFzWxKspGXrGRGxeS4bxEwkKHoyiZTqsqLIL cBKIp2toWYF9Ved5GcpkuR7i++59UXdXcG0Vpu51gwaPo4CgqFP6dhUZV9VFd5IZNyQ/ xXDMyeVc7l4h+L49ZKJWHDAReViJmd05O/uGNPZNl0NC72DEXv7vMSh1F025KE0dHjVF A72EoA0Jzx34HJj5tTemjeKbCaSbvdcCf04RG1ZXPR6O3QFyfB34Wc3mBFr7GJMmd1/z /fPAllFMk9ggUFdg+KRKM7uIg4Xs1sySeaPvtFrqv7z638GLi1WR6kY6Z8xY9xwcJ1Uu yEzQ== X-Gm-Message-State: APzg51Cjso/XOcDRhgv9U2fEOsQfWDnPp7Tlv1s/StwGWbygWi4k0qZj Mkd632sI4A2KYr619AdIQg225Q== X-Received: by 2002:a63:f26:: with SMTP id e38-v6mr29312557pgl.354.1536047520634; Tue, 04 Sep 2018 00:52:00 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id t17-v6sm41515487pfm.138.2018.09.04.00.51.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Sep 2018 00:52:00 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Tue, 4 Sep 2018 16:49:38 +0900 Message-Id: <20180904074948.18146-14-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180904074948.18146-1-takahiro.akashi@linaro.org> References: <20180904074948.18146-1-takahiro.akashi@linaro.org> Cc: xypron.glpk@gmx.de, agraf@suse.de, u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 13/23] 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" "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 4 07:49:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 145870 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3374417ljw; Tue, 4 Sep 2018 01:04:43 -0700 (PDT) X-Google-Smtp-Source: ANB0VdapVXO1tHlcBvxRkYL3KV881TZdA2BMKyS7VS1dW5yvnEWAr1Kc5DZYkhBw86zKPc0T0AEW X-Received: by 2002:a50:8ea1:: with SMTP id w30-v6mr35469044edw.197.1536048283730; Tue, 04 Sep 2018 01:04:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536048283; cv=none; d=google.com; s=arc-20160816; b=Do3xd8xmDRuL6Bb1QPpCf6TMQJ5dgoZC2y/OlBojH3YcFLGxHtlXccW/J+2OHZDeL4 vNJn6VfUPsGBQ2xIt22QAv+4xKlgt/BBOFPbISdhWTmRcbX4D3AxRmFCFvGrDrSMOaOI LCZr4TdZp3E74wVdBD4B10bRFEwJMrd2DU8oF6kjXVAKfp4f9p3vKwTkNL/UgI0fWKwD kUDuJWuiBMbrJvoZ0s9EKAAoI/Rrl6H+WdVqnulaqOthEAyfODrlXKFDPteDvkD5y0hp wwtLwp/oEj6KQv7uUEnJG4pf2BQky+wpIg68vwUTtnzcNeLVENkxtDZ28NjIEno1WCBu UUAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature:arc-authentication-results; bh=+7txp4mwSEZ+Tf6HrXA+7nus08wXv+6H1MlZZ5lw3j0=; b=ODMJfKa0EeqG800aRfHsqwK1MuqK9HAuNN/c5o5su8jmR/J1+rGHYZhbZ0s19C0XRX a//yjiRPvnm5DJtZOAk5Ykq8xMSvoQdWtJjOCVjv+e/2SfW+h3kdLmhVCruBTv83uqE9 YcgSbJK2Fyoalv5QFbmuEwSpXwfIJ5MhJFblh0pyMK70QloAFfWxkebP/GvF31LJXhBZ kkKaon8fMj36LhQCJAUD1FXOgXSc3iM3ElqdjIwTZZNS8FBU8t9oTXhbSbScHRywVrkt liA36/+WcDGmP+iVQAKlThG5zj14XmqICs9JvKE8XNu0iYUO+lsLl3up744mXEhK9q9T Vlqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=ZE17fQ3L; 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 y36-v6si8682011ede.17.2018.09.04.01.04.43; Tue, 04 Sep 2018 01:04: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=ZE17fQ3L; 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 2BE55C21F71; Tue, 4 Sep 2018 08:01: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 0C263C21F4D; Tue, 4 Sep 2018 08:00:57 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id D53B4C21F00; Tue, 4 Sep 2018 07:52:13 +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 1FABBC21F38 for ; Tue, 4 Sep 2018 07:52:09 +0000 (UTC) Received: by mail-pf1-f196.google.com with SMTP id j26-v6so1273242pfi.10 for ; Tue, 04 Sep 2018 00:52:09 -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=3jEU+po+IuyaRobaR3DZQwoIopckEtDLvCm3BLnsfns=; b=ZE17fQ3Lgp4KihKjf1HAwYE2mQr9X3k+0znAb042jj/sAKC7v6eprBTj+5mBDppDk9 aC2fO07pjd1Tutlpb3sXsz5O6VVrlQmRzAMAH76mJWosVUzOkOvXowac3pmMa/Zmpjpy xzb947PDqxxObmaoMqzgY0mLmYuu2DgwB79yE= 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=3jEU+po+IuyaRobaR3DZQwoIopckEtDLvCm3BLnsfns=; b=GsxU/77+EsjzRbaR/a7EivEAgjuBLIQvlkIxItyBRnrMV3EnQ6cWm5bEQOyaJB4Km/ q6vgHCOB0KIOqZ8YJ5vWax4wwd1waH4v/vzg+LVH68zwP+zZpljOWm8OkvJfrCuOIDib QkoqKGQWgwfqUhYRbxoz0RsCBmtE+0ZvNdEjGt9ajKEHp2qQZV0ucklNEIz0KVsfagrZ Nrzi7rbm0YUWsO2XJQ36kc/y07sKLhdE3TQBXXsqi/Qk8HxS1yN1+sNFCeE8/FSA1mOd e+Stix681m4MmTk3YPbrqarM5lKKXAj0UE/qnJnTzT0GPXlOTGQWW9CmdBngEsmUx5j5 w1uA== X-Gm-Message-State: APzg51BD7mJLjbQ5C/MkK2EIK7EJHpB/j7/asAJuvRVG43eVyPzpawac EpPgT0sgJFBTj0Cjp3b7GevnMg== X-Received: by 2002:a65:49cc:: with SMTP id t12-v6mr30020329pgs.27.1536047527824; Tue, 04 Sep 2018 00:52:07 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id a20-v6sm48768497pfc.14.2018.09.04.00.52.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Sep 2018 00:52:07 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Tue, 4 Sep 2018 16:49:39 +0900 Message-Id: <20180904074948.18146-15-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180904074948.18146-1-takahiro.akashi@linaro.org> References: <20180904074948.18146-1-takahiro.akashi@linaro.org> Cc: xypron.glpk@gmx.de, agraf@suse.de, u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 14/23] 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" 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 | 2 ++ include/fat.h | 1 + 2 files changed, 3 insertions(+) diff --git a/fs/fat/fat.c b/fs/fat/fat.c index 50c2d4f3c33d..bbd4b098afb5 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -643,6 +643,7 @@ 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; @@ -678,6 +679,7 @@ 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; diff --git a/include/fat.h b/include/fat.h index 9b114e3cbda4..05a993bfdcfe 100644 --- a/include/fat.h +++ b/include/fat.h @@ -199,6 +199,7 @@ static inline u32 sect_to_clust(fsdata *fsdata, int sect) 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 */ From patchwork Tue Sep 4 07:49:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 145873 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3375226ljw; Tue, 4 Sep 2018 01:05:37 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbmiG4P0SnAAiPoXR03d73KWkBqeKkMxSIpqkqTH59L10BhICwKK9HdX38sf5DJcJfRudL6 X-Received: by 2002:a50:97ba:: with SMTP id e55-v6mr35389055edb.58.1536048337488; Tue, 04 Sep 2018 01:05:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536048337; cv=none; d=google.com; s=arc-20160816; b=LKudk6Xp7rYvHVjeK7+Msm09+xlO6ZcqcuTRbIdGUefX7HNHZVWFplWdcFh2cYO2KP jprOjV4MNUvShOeJgbDJ+OiYV2Eg5f/WqxhRohuEHNUZwixiGriDntIGLd91vmuyyCkx Y8D1Dg0gjuAc7lzfQmsWzzV4rOPIM8Iv16O77FDVabkVxAvxqiazqoJzVm7DZ6JQaHhw QSaJYNrvOqP0e2rrvNx5chyNEvySjyQEVgKW7JlaiupI916AaazJ6Dc1XXdyouJYFAgD K4vy+jSz84Qu3fTt8ZMvCOxtf1jgxB9ZVTpttYGc8Hc8Obeb/T0qwumWk3w1n3sFcC+O RgDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature:arc-authentication-results; bh=1otUb2ar0UZs3N2xHqB7JVtuJU4ZjwqHURbpYvodeBY=; b=rrc3q6qRc9MDHcRkzzIl48tkbgIfOnpqO9eSlza0EYmE/qmKaVb+ccwVajrW2VGTt9 JKxL+t5utgOCjCD+Y3Xd/nLNVp0Fj5S1glzAsw8KBHF+j8Qmixfd/XEDgls47zS8t2y0 NfXEH6amoSY0uRAcL2hyEawsxvXvoIVMrLHH33cp0na0/7P8KnDO2kdzc8b3rASrmxcp YMAiUleFo9Ybr6gDFxcOsST74I1oI1gd06Gen9uhDEmhGluICEmJs6YcO/M4XQwayrJg kdCBiFacfUp6oxVLaHYBFtmDkSamlsAL/evlc4InqbjAu2xgTTqGyx0rXnarupC3oaz7 G4og== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=al2JDBNQ; 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 u9-v6si3063411edf.117.2018.09.04.01.05.37; Tue, 04 Sep 2018 01:05: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=al2JDBNQ; 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 0B345C21F4D; Tue, 4 Sep 2018 07:58:44 +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 1A3F5C21F3D; Tue, 4 Sep 2018 07:58:27 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 00F27C21F29; Tue, 4 Sep 2018 07:52:20 +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 7EB3DC21DEC for ; Tue, 4 Sep 2018 07:52:16 +0000 (UTC) Received: by mail-pf1-f196.google.com with SMTP id x17-v6so1284427pfh.5 for ; Tue, 04 Sep 2018 00:52: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=0jMhZ1yBMWcqnnjbqsMMAgNe5ndC1C+5DVRpxh8JmBo=; b=al2JDBNQfphCtYbKxH/9aLDPD57UdL6buPLUxR7ZqS8mJf03XDv5dqNkCU/qMGOCu4 8MoB2WEOAOFpR7lDg4iYF4lLs9OT5FHFrihjJTz5WlWRyj2UblQbNv4qkEY6vXy5+2W9 ytvWafLskF9lmTDPB3XUDVnWz2A33SFwWmdDg= 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=0jMhZ1yBMWcqnnjbqsMMAgNe5ndC1C+5DVRpxh8JmBo=; b=mTonwlvWutQBl7vOdizKxmFyPgJgoVq6UzR7ogqmE3yd9NY0uwopX9480eOHJ83oon vmt/RNbVZ2hWLSkhxwgwrvmdi/qgtZkY9Ej1VlA7UiqASnLEYD90hXdJbwjqsKbyItkE gNGJOWhhb0L9gie3+DCyszFnaH9pn4EvO6kwP2lCwkHmdlWwwujRFWpGpadZCnV2yADB VExi4oNdrMPYq9dlsg92DaxaBClaa+1aPhjPMrMQqqTnocQZxCd2tOIqLwMltxCRtCwj h+Gpmjrbfbi4Tu3C4Pujz14p0tNNm113vcoxCNzNsc3Yuptg+DR9Q6B+8TtcGmdlzeaN KUIQ== X-Gm-Message-State: APzg51BU+F2c+Nh6dMu5NDg+juiI1bJPmkfZF7GHlMsyJKK+qX52zvbY R4zh9zPxA+Gd4hEkwN5Dtq4fsg== X-Received: by 2002:a65:6550:: with SMTP id a16-v6mr29362274pgw.22.1536047535178; Tue, 04 Sep 2018 00:52:15 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id c1-v6sm26095234pfi.142.2018.09.04.00.52.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Sep 2018 00:52:14 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Tue, 4 Sep 2018 16:49:40 +0900 Message-Id: <20180904074948.18146-16-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180904074948.18146-1-takahiro.akashi@linaro.org> References: <20180904074948.18146-1-takahiro.akashi@linaro.org> Cc: xypron.glpk@gmx.de, agraf@suse.de, u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 15/23] 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" 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 523abd62c9e9..fe0265649200 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 archieve 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 05a993bfdcfe..c34eb8cec6bd 100644 --- a/include/fat.h +++ b/include/fat.h @@ -239,6 +239,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 4 07:49:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 145860 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3367714ljw; Tue, 4 Sep 2018 00:57:15 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZ06U5/oz5fnZ43KhXHcMBw3NdkcFtsiRWKaXcsm3LM2kw4Sk1nZu0LFyBqot5xmPtfC7k2 X-Received: by 2002:a50:9622:: with SMTP id y31-v6mr35299967eda.141.1536047834970; Tue, 04 Sep 2018 00:57:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536047834; cv=none; d=google.com; s=arc-20160816; b=ue8KpGUkn7ttkwpjVRqf77EblUJgv8BpDJ8GhmNrxQCu6UrfEVydVZTlTmAMSnJKZC uvp47JFJ4bL/FjB6RmiPOrQsCPwJrxA/Q+IRivnpJEFNtGju8DGagsJfHqTgRoDU5YNI JzheoxKhzf83VyKGD78i8agdJDrMBycq9MHLQWRCeSF/4BrzaGncjF5qmrzw6WDom1WZ vL84kewpWeeLOpCWRme73qwz9P0CFHVpGKluEszB8DoA3nsqr3IQxvdxHD47WkI8gEbZ R3HQjiL9eaK5svZvLxDgRZMcYvVLqEfIeRJz/Wzt03lxsf8kzVqUpVDw5PFLmYRLE87u EvBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature:arc-authentication-results; bh=F6k4WcV0obec+TH1Roxq5Na6faru4Ywd6MjlLFGKzcM=; b=ABM5fcfHKWfwbfFPva02vUcRBBApkvFEBv2qUSDDhSPvqKeuGFEoUV6fK7vQW0N4Wt AAtx1kPf+/BNuw6ymUi3Inpl+BryJ27H9uM0greyIXMZDAjTeP29a2uAh+Vu2I7dWTJt 2kSMeJpj/of33LyCJSkerEz56tvRGLWW+63SFevoAlIKpeIt2yjOY2lkgV1dXd+chBbg otaaODUFhdhJFRWI9C281Q2KRHpAXskEG0F7v/M/RZgTfDMrq+zC3sTASOop4/OFiOFl alAmi5Lj74dhpUozut7n3L8Q7+ofcdsWlK0spYxnQ3AuEFDH6zP22eEh94QaF3tGffiE ys7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=EVp8Hu7P; 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 v14-v6si4001140ede.25.2018.09.04.00.57.14; Tue, 04 Sep 2018 00:57:14 -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=EVp8Hu7P; 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 82BE2C21F3C; Tue, 4 Sep 2018 07:55:24 +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 EE982C21EFC; Tue, 4 Sep 2018 07:54:04 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 8DAD3C21F04; Tue, 4 Sep 2018 07:52:28 +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 A2926C21E44 for ; Tue, 4 Sep 2018 07:52:23 +0000 (UTC) Received: by mail-pl1-f195.google.com with SMTP id t19-v6so1226449ply.13 for ; Tue, 04 Sep 2018 00:52: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=1WJ2VRKAw/QFLc0XHXmrV+kM5cJOfMLPVaQ63hEmRAY=; b=EVp8Hu7PZoJNHhXo2Qh8Ksmc08QwtnQulwEpaYcOyhYVSAptpvgam+PBR6Ek07LiSp IU5EwEda216mgoEhS9cgd0ozK9a30+oigmiALKP57bbM7Bv2ynhGNz2IrYr+6H6xXpIc 6SuaQMiV6wGCsV0aOiFW+MH9/K+xR+7k0Mom4= 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=1WJ2VRKAw/QFLc0XHXmrV+kM5cJOfMLPVaQ63hEmRAY=; b=Jy3cbQFRH15tSNgx/SxZ9fhiTAo2c/uG+cF5OKq0RESw+OIzg5p19jVgtA9/BXlz9a f7kZoREy0g5AYcVbMqTkrf49OKRNJmiY3Ry0oI4JI8WLlpndpiW7ePZRBMfG4it1uK7U LB2Y4XDa1BnUM1zpnV9hEXBhG1bcJBJos8NIXClZEb9VKUm5lZVzh0EOlrha/UjlFs6C UQ3AVem3yrQr2QA5O4ZTk/lkS7kYohOJNoFpi+uS9cTP7LunZYm7YJv17T5UppWyjhp7 I7yClqlMKF65JXQ5ETWXOnNaRAujZRuFdJrPWPy7sDTQrQm0eDTU8TgjlnICgZte12+F a3Mg== X-Gm-Message-State: APzg51DB+0wv3ATbtEO/PAXWWTnTRGN61nDslsoWiDSQlNlL1BsGbswR /jF0fzlHuEm0JR/fEvM+hjyeIA== X-Received: by 2002:a17:902:9302:: with SMTP id bc2-v6mr32912879plb.280.1536047542386; Tue, 04 Sep 2018 00:52:22 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id u184-v6sm28806138pgd.46.2018.09.04.00.52.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Sep 2018 00:52:21 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Tue, 4 Sep 2018 16:49:41 +0900 Message-Id: <20180904074948.18146-17-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180904074948.18146-1-takahiro.akashi@linaro.org> References: <20180904074948.18146-1-takahiro.akashi@linaro.org> Cc: xypron.glpk@gmx.de, agraf@suse.de, u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 16/23] 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" 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 4 07:49:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 145871 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3374637ljw; Tue, 4 Sep 2018 01:04:59 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbTefPR0nPQukjQa02C0gDxGnXL//oyuq/yhHn3El0fcQcGQFM0Atg+ob/1HcIbo1t33+nr X-Received: by 2002:a50:fb8f:: with SMTP id e15-v6mr35185036edq.153.1536048299745; Tue, 04 Sep 2018 01:04:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536048299; cv=none; d=google.com; s=arc-20160816; b=c72ZxD7loy1wgAauq/xMxDVCn3awQe7KTYXt8vd+WInl5/me5jYvVK05IA9Zo87TyP Q0nP7V8e4C7F127jawtAGV0//VLgfYE+kR/A20zN4Ol8mkM26S4GHIsB8IVFYNu2JWra 5bkqkttaqoU8QaEMk6Sm0TfWnny9EjqRnssMg0I9g1tHTeTX5pXAAEpcs1FPkTTUYAm2 pw+v79suX8zLqVEZ33brfDKppNy4jrcJmwom8iFmiBpzKLFPAsrHfllEhnTArKqanpln bJBDkiM6o8LZKGfmyoEUmjZpFVpPtg9UEjlwZajDyqq3zNFO25b32+X/l0crz48eniXQ 5BFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature:arc-authentication-results; bh=qEumHJoma6I9rOhAXkRT27kYLV7UEVut3Z+Eb84uF4w=; b=eNeiNdEVZ0/a3xKQbgITaZxT4khm3pu0hHU28fX0ZfnTfSr3O3rvZt0veTndTdBo8Q MSL7E4YbRPqUENUh3h+bygRf6AdB5Ihc6UbLAU0Bby6zbWtAWyTx6m/oXSuX2XPnWumH /4JMXuCQTYF4WOcfj7I5oNp4iT1CI527Isn3lSDssAjyekNMJAg41lTqL1svT0hAQxpn +wcmQ3XZaQVSaxKWhHwMAjZITYibUzqhh2nAqlFzEUW0Mlp1p6WQCA+Q5ajTlRD6idwS WKIGth5omL8AWom4/XniGCgenVrlHt2GtpmHmzOOsS2/cbFFt8z3woC3CodMOC9py6UF /g/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=fqauzOqL; 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 r7-v6si2544330edr.289.2018.09.04.01.04.59; Tue, 04 Sep 2018 01:04: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=fqauzOqL; 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 51475C21F5E; Tue, 4 Sep 2018 08:00:26 +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 C2C29C21F4F; Tue, 4 Sep 2018 08:00:23 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 20F2EC21F24; Tue, 4 Sep 2018 07:52:35 +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 BD932C21F3C for ; Tue, 4 Sep 2018 07:52:31 +0000 (UTC) Received: by mail-pg1-f193.google.com with SMTP id s7-v6so1269117pgc.0 for ; Tue, 04 Sep 2018 00:52:31 -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=qs2D+cCVxC+acpJQJmuZkvuxYHb9rvuKa+A/1Qvufe8=; b=fqauzOqL+aldc6ZZlaTtODAJkYa1lh4TItRnewvM2/tHpTiylhh/Hv7p9u6zrQnTWz a7oc4ODTmRDBJQFK3FWV7s8G3gjP3bT/5JnT9U6fyU4CqS/HA5BmiZXbt0qNiF6PP73K NtVmFH+i/i2iqCEUyPYwMG4mwlOdsxt1sasHQ= 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=qs2D+cCVxC+acpJQJmuZkvuxYHb9rvuKa+A/1Qvufe8=; b=N2csKErAWYvht2W7vLsicXQz5kat/4cCv+/lOPAZL6mFbkbaGEd5NKdIQoSs3u51A2 5MXmgKAqZO/D8NylfEZMv9p7TmDD+LcSBHccgNq3AYhOpM8WOILHH0N7x9pfxX6GWMsl nIw7OBK5Fh4gxOqQkCLyrdmaAlnJc6CuwcP3SQiTxsHPOoABAni/PogCy/5h05tVfrZu xdfTKMTRnecmvixxKiQqv0UGnYJNcJi1kxsSeRL9Gjxjn6/si/aneKiG8bu1eblD/euU zbdKRJ7ZPijLV0s7yXCbeVBpCJ+ZqUfqKdDZyVwsrf1khaGHVbPS1C+MddzGlEMSReVT ku5w== X-Gm-Message-State: APzg51CNL3jjwMx00W6+zrkT5Q82yhAX2cLRPpEreCc1nvhSS572v958 8BehzG6GlF/TgWWG2oel5obThCDC364= X-Received: by 2002:a63:8f17:: with SMTP id n23-v6mr11109399pgd.131.1536047550480; Tue, 04 Sep 2018 00:52:30 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id 83-v6sm37996583pft.40.2018.09.04.00.52.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Sep 2018 00:52:29 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Tue, 4 Sep 2018 16:49:42 +0900 Message-Id: <20180904074948.18146-18-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180904074948.18146-1-takahiro.akashi@linaro.org> References: <20180904074948.18146-1-takahiro.akashi@linaro.org> Cc: xypron.glpk@gmx.de, agraf@suse.de, u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 17/23] 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" 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 4 07:49:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 145864 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3369276ljw; Tue, 4 Sep 2018 00:59:24 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZKcAUpJIXnwOvMLAuxTEmmCaVLkjwaRyRazJD1E3oHc9sq6MWv6hX72ee/xDVibMGuXEYW X-Received: by 2002:a50:aed8:: with SMTP id f24-v6mr36122285edd.271.1536047964330; Tue, 04 Sep 2018 00:59:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536047964; cv=none; d=google.com; s=arc-20160816; b=AAf4e/k4IJL6A43hWyWkPvW6rQJhC5YogLm0XTzpYmM5gCMXzxetDoD6J1lZ/T3cnV ZZ/bMOC1zj4dJNIcEQoRODzhe66F8e8tYG3PUXlj4jp6VSYhA4nh4n4fLf8y4NmIrw4+ EBtha5EwBUHvMQnDipqavqD6TEU5m6uj2nDyt7ohR1OvPHrgu2SfhKbejy15ZS3rdFAM Kr+HFvnUPpAGyioVlEEzz18PHV5A5UKlZ9QII7f+nKjmEnN5OdQ815TIZulFwTVZtNOo FmgFQ7svwW94nCE17bEZxehOpHVyxgwqAeaCv8hVbwhe1X1mU1fg69JE0tcG692t3Win o7NA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature:arc-authentication-results; bh=3hCfQYmct9NnT63Mbj0bmtcL9xb99lUDBmYmPga/d6k=; b=sWInIlkHemd/JSA5S9fYO4AqLHZ6gb6AkuI5YBPgKTTulqy42yXh58SC92qJXLZI0F I5qHVgHM3K/dIG7GIBgMJDQkY7zswJJY/2iyK3Jt0FsGcGwUH8KbMvpQvuBtH74bxf5T nI6AV//rHYnObUYc9Nq4SfyXSwzX5YIe4y0S+marPEiOmslcQw+hVVoZDIEP0bHSfS5J jhd+jpiH58SWJoahdXlIlhMAbqO0k3Ha82N7TpeSWvLYzpTup3Gigr7PI3CRc8Cyylxf oQ2uz5hfWmCsmeugukHsEDF0iHkHVHY7dDOdbOr4b3MNGMm2Oh5M/3rxlaw5r45y7pJI yt4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Vi1LaVhB; 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 h12-v6si3514585ede.283.2018.09.04.00.59.24; Tue, 04 Sep 2018 00:59:24 -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=Vi1LaVhB; 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 D1474C21F24; Tue, 4 Sep 2018 07:56:02 +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 7F670C21F49; Tue, 4 Sep 2018 07:54:56 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 66FA7C21E4E; Tue, 4 Sep 2018 07:52:44 +0000 (UTC) Received: from mail-pl1-f194.google.com (mail-pl1-f194.google.com [209.85.214.194]) by lists.denx.de (Postfix) with ESMTPS id 924CFC21F47 for ; Tue, 4 Sep 2018 07:52:40 +0000 (UTC) Received: by mail-pl1-f194.google.com with SMTP id s17-v6so1239077plp.7 for ; Tue, 04 Sep 2018 00:52: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=1N1WvShccCPkx+PSvMrGEH8WxvDadT+H1Di0NTSJhYU=; b=Vi1LaVhB0bghC14lRFxbWOQWbIv1pZ43atuPGXZ61APbDp0RfAXgLjERzBJDYl/pql ns2CNqhlBNyt2RixqVlj1HMhlJGlF5wfqI3wWWw2anqCNNIuEnBYYbVHotDQqKg7cb2F easacBigtIAQ09hnuEXm2smMGTzIcr+TfuaIo= 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=1N1WvShccCPkx+PSvMrGEH8WxvDadT+H1Di0NTSJhYU=; b=WCwPvbVDLmdb+n/44cAwsKZN0SmLPQGU1wty4/dwj4Av8dr7REW5jOMSAaQWbaoty1 gXkX0KdX1LPUeR1LHETC0hCTnzcaPeP0BYZrkLRki8cU+Fa2LA/HIcsq7IFI9ZJbqRot 8xp54Zlo5oorN47qkzHnFs9KV7X9kk5h1JXJD+vd1dBZSeUfZOslJSqKYSgCX6zfPzAz clS3gXl5fW4lRVkiuNp8IanNg4ePXLP1y8OOPVCH4Lb8HHWTJSCRX1TnDw5PwOtJrqiS lQNSxnZqRkd7Gp5uyjBkQhXj15kzhpbezo0guNHFSxemsOGe7/yXRfqfj3ENav+0y6qI ZJqg== X-Gm-Message-State: APzg51CiAS0KrUfIfEKO+k6LjVrRoNtz0kML09degjLtib0PcP52siH7 F/hcIn9mjuvdAJxx9M4sNWRPxA== X-Received: by 2002:a17:902:8a90:: with SMTP id p16-v6mr32698499plo.106.1536047559242; Tue, 04 Sep 2018 00:52:39 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id 16-v6sm33391867pfo.164.2018.09.04.00.52.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Sep 2018 00:52:38 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Tue, 4 Sep 2018 16:49:43 +0900 Message-Id: <20180904074948.18146-19-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180904074948.18146-1-takahiro.akashi@linaro.org> References: <20180904074948.18146-1-takahiro.akashi@linaro.org> Cc: xypron.glpk@gmx.de, agraf@suse.de, u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 18/23] efi_loader: implement a pseudo "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" This patch is necessary to run SCT.efi (UEFI Self-Certification Test). Returning EFI_SUCCESS can cheat SCT execution. Signed-off-by: AKASHI Takahiro --- lib/efi_loader/efi_file.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/efi_loader/efi_file.c b/lib/efi_loader/efi_file.c index 6ec98c80227e..12044a0c7196 100644 --- a/lib/efi_loader/efi_file.c +++ b/lib/efi_loader/efi_file.c @@ -226,12 +226,20 @@ static efi_status_t EFIAPI efi_file_close(struct efi_file_handle *file) return EFI_EXIT(file_close(fh)); } +static efi_status_t EFIAPI efi_file_write(struct efi_file_handle *file, + efi_uintn_t *buffer_size, + void *buffer); + static efi_status_t EFIAPI efi_file_delete(struct efi_file_handle *file) { struct file_handle *fh = to_fh(file); + efi_uintn_t size = 0; EFI_ENTRY("%p", file); + + /* TODO: implement real 'delete' */ + efi_file_write(file, &size, NULL); file_close(fh); - return EFI_EXIT(EFI_WARN_DELETE_FAILURE); + return EFI_SUCCESS; } static efi_status_t file_read(struct file_handle *fh, u64 *buffer_size, From patchwork Tue Sep 4 07:49:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 145868 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3371442ljw; Tue, 4 Sep 2018 01:01:48 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYX9RSumPODAag6zuopabIiLS4TmpPB60qE1irj6Xa4T88jYupcq1P9n5PTcXEryk4jVDc9 X-Received: by 2002:a50:b399:: with SMTP id s25-v6mr36276160edd.217.1536048108090; Tue, 04 Sep 2018 01:01:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536048108; cv=none; d=google.com; s=arc-20160816; b=L62Im9JhaVdIwJaW8TRHM0UTrbOC0MGfy98ucYmdAcwqvIj+VhBW2/XXbkfL9IkhuQ IxtgXeTmVnAthsdBCdV/hmHg9Gz8zh/JUK5Ci6BmHbE32aKOcCoUP5cOU/xRkLxDRqwQ zpoaMcBrIC6EhNXipsODPChxCZpwIHXbfpUPefdOZLTEXuvKzoit790lUB+Xu23PPOov KT3uQrTaOGQhibRY8xVdgNE2zC7FgTPBqtMvF4YEja5vkC18HxfUCZ+mFLm6x2iSVX+e cMGVg+Am8KjW9gVB0vWLxldwUl61RAqYSx1bqNw0T9uNz/JX+M3rqMUh/wz5dbGGgiFI YHnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature:arc-authentication-results; bh=zM1yzc7RqJtPxX6GUv7FAXzlxf/AjVY5GOv3CDZVjwA=; b=y+7zOyq5sZ0sP+Gv7GwSDreEtbBQ3Vh/1rY7VQEMPhDrsXiE73K71mvdFNnKyiEeUM b3dlgRcV3pB4T0mF1s6XsVxoA4NDDqGvhvIvGJBQ9LzAt05P28L9BXUEa96+le+P7/RL zArNSFso+mB0X+9bx93N1pCQcRlMIQdfdRNOkQwDeb/1vbKIC7darFNE6p9/TWC1C76T PV4y0wamRofPmlV7wyWSNSujB++5zEhgMc3LFAUSHoEKjQAbYUcPpEJzhKrTc18Y0Jux Xl2+oNib2PNnxrbFMdlQH1T4qlk17WuB4BS0FofVJYgNj9N0b7BIiZm9EIMCx49gcyEC 2qZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=QOlHvoeZ; 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 f5-v6si440707eda.356.2018.09.04.01.01.47; Tue, 04 Sep 2018 01:01:48 -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=QOlHvoeZ; 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 A4951C21EBB; Tue, 4 Sep 2018 07:56:53 +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 15F0CC21F3D; Tue, 4 Sep 2018 07:56:51 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 0E000C21F05; Tue, 4 Sep 2018 07:52:51 +0000 (UTC) Received: from mail-pl1-f193.google.com (mail-pl1-f193.google.com [209.85.214.193]) by lists.denx.de (Postfix) with ESMTPS id 01A2BC21ECA for ; Tue, 4 Sep 2018 07:52:47 +0000 (UTC) Received: by mail-pl1-f193.google.com with SMTP id j8-v6so1233854pll.12 for ; Tue, 04 Sep 2018 00:52: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=yZqRfBw18BKbIT5oQlIVw1kj6RuXbNe677ccHtfDmAg=; b=QOlHvoeZIPyssyP/5/KaW5fdmR3coiuA8Tu4OGc/s1kEvHgFwTnYukrZWiHR9/f5kk IJXsY/aDZFsU9XxO3rEdna4SO+ifohyX6ygFaSOi3+3C3Xtpt6deSOoqHhysfpi466l8 PdDJOzZ7XOaEvX89i2j7tc9NQDCTFtxvRnpjQ= 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=yZqRfBw18BKbIT5oQlIVw1kj6RuXbNe677ccHtfDmAg=; b=n8XCw2/IkDt8GDkanxa8no3jphb1wfQ9RiEr3l3egeYmSTY5bGGAGRCXI76FPnyxvy uh4zCxl9//+aXn7wfCrS7F8k1sw4cj97n1NghZ8lBeGfGHpVhk68c7u+Oec0xzVclNBD rYcPbHDhwu+T1RnBW6a6dLu/bZUrwDuXfJZzlyTnxe3ucED/3pkwDY/h40HP2cMpQlI4 25v4vETzOBwERDNbFKEnO7vyDcJFigKf1n3UFlWvNHneaOPSavbG8U1NCl8a+zsX9Zsj GGAxiT5JGG2fGKB+D5Gu4fKX1yXPhwoyh7KlYfmTYmWaa9bXm3ZJn3hs6ZJQQFoOammI lvvw== X-Gm-Message-State: APzg51AL5HfZXG7PRugOwE1mDAqc2f17pwGYPVZVQNKKpL5oExKVmkwM 2odgM/pOuCt6AXnBGsKhv2dfKA== X-Received: by 2002:a17:902:7803:: with SMTP id p3-v6mr32272749pll.119.1536047566698; Tue, 04 Sep 2018 00:52:46 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id s75-v6sm37114411pfd.108.2018.09.04.00.52.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Sep 2018 00:52:46 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Tue, 4 Sep 2018 16:49:44 +0900 Message-Id: <20180904074948.18146-20-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180904074948.18146-1-takahiro.akashi@linaro.org> References: <20180904074948.18146-1-takahiro.akashi@linaro.org> Cc: xypron.glpk@gmx.de, agraf@suse.de, u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 19/23] 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" 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 4 07:49:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 145874 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3375477ljw; Tue, 4 Sep 2018 01:05:57 -0700 (PDT) X-Google-Smtp-Source: ANB0VdamRhfrUb7RiJ9zVzjItKD3mb477AmApcjvFCj+61XsrEqOiDFeoSLLgSbx1e6kLcBnAvlS X-Received: by 2002:a50:c082:: with SMTP id k2-v6mr33759056edf.294.1536048356965; Tue, 04 Sep 2018 01:05:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536048356; cv=none; d=google.com; s=arc-20160816; b=eRqru5hKC1Slr0Xu/iLVOWbH5RGevxw3fOowdJjGL/PLacNmGVfY7kMOswiG6IRZd2 24a9NELR1EVnhelLdoRfwwfqEGhB4FktHuMz1Hv5VLvGL6TFUDp/4nhLEmf222ekbdGU O+XOEshBcPjgJj9JeZsrC2pc6En8wLbmdhShRhpsFoUxLjTreJ/Js3hmCU1/+pnIezrt EVY07EQDizyXtlH9LnlLlfLHlQWO/H4uMplvLFdMs/6FzFq9RJqZE41BpsjFY2+GvAol rg7dHAP1FBwfQSLp2T2Cf/2vZUU010DPSkeDDFNVMVKOQ1HpPxejuOh+arC18d9qdDDN 6hdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature:arc-authentication-results; bh=P4PkWlVMIJWoOn/clmUSjnOWB6Fqyxikn2iJNwQ8ypY=; b=bfy5j5N9ym+sOyqucL1oaEzETG2BY8RKe9/+jShFVE+xYeZCYacIXf8BIuDTYTzEcd QtWGUtgCNs47idh9gzMnqfSmQtZdQDimYsWvaMNoCfOFESSt30NZiyNIyzXxcGCSZ13Q 5nM8kp8bLJA+B4G0LO91akafjaUnvvLaAL8COqjKT9vNp4+vYcHRWPARIZuKojdRzr+6 NwPYamnJEvSJfkJKFcA5iMAkexIdAm1egRP4mtOvRcW6ON1K7Byn0uOclfSgSIH4j2q6 KlzOHz2DmgLpdGd8+pL9sE79Mrz78m3qw5EwrAeErONHJTb9kR/zTEYXWIuTCqn1qyzT SgYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=DOhtCIzo; 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 t1-v6si6487449edc.92.2018.09.04.01.05.56; Tue, 04 Sep 2018 01:05:56 -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=DOhtCIzo; 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 8FF42C21F49; Tue, 4 Sep 2018 07:59:29 +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 6007EC21F3D; Tue, 4 Sep 2018 07:59:27 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 8A9E4C21F2A; Tue, 4 Sep 2018 07:52:59 +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 C82A5C21F50 for ; Tue, 4 Sep 2018 07:52:55 +0000 (UTC) Received: by mail-pf1-f196.google.com with SMTP id h69-v6so1287595pfd.4 for ; Tue, 04 Sep 2018 00:52:55 -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=6NXd5MtaZOvCc2y97jwhkeGugeh0gaEZRhPPtszpVQ8=; b=DOhtCIzowv6bBqwVRII+cowusb3uKTVYZ5E/MSjlykndhx57U7ReKeaOrHcNBGGddO OEcwcNV2tNkJwLsv7S6pQWuPeMmfRScyLExBfiHlpQQwi6vZvryPYKMVZIhKPYNKmyjc 1mqTj7JC4GGRxcjoq9yhRArFaQh0JfVzg36rM= 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=6NXd5MtaZOvCc2y97jwhkeGugeh0gaEZRhPPtszpVQ8=; b=NYvlurvthBhBAGdtbj0NWh6ltwp/KeoHqtKQ1XqpVhXwkQ16J2WvQl04jM7X7Hgz81 5diIY3UXLOzdWLL9XkEi/WZhFHlnZUmBfprebDLpesQjxGV/WGSs97cVCB6Fv7xgRA11 O6rDD9fkFhli3+G3pVj4jiIVyrKW/7zdYuJxYKmY0/w6u4WQXXYxIdfVd4Nn/GK4QOAH f5F0+h2/f+wPV4fa7yuZ8dw5FeQ/YAk3T6Nk47BEV8VrexpGDBb5+X3nUv7gEMP+24Xf Dl3L2nj1Z5XHpQXQ+jXYbK/HjFjSYu9JWDHglSasS1KK3RN7UgB8Ewa/AVHN0FtQN1Fr sHgw== X-Gm-Message-State: APzg51CvgMmvgxFg9m7Lqj0hmKJ14NmFb4g3mu4sYRXfKZ6Jq2HxpS3u QxmGyiXBtrYrlIkoEiuHpepArw== X-Received: by 2002:a62:5ec3:: with SMTP id s186-v6mr33827247pfb.146.1536047574482; Tue, 04 Sep 2018 00:52:54 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id l70-v6sm36766571pge.36.2018.09.04.00.52.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Sep 2018 00:52:53 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Tue, 4 Sep 2018 16:49:45 +0900 Message-Id: <20180904074948.18146-21-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180904074948.18146-1-takahiro.akashi@linaro.org> References: <20180904074948.18146-1-takahiro.akashi@linaro.org> Cc: xypron.glpk@gmx.de, agraf@suse.de, u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 20/23] 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" 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 4 07:49:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 145869 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3372987ljw; Tue, 4 Sep 2018 01:03:25 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYqlZ0GjO0oQHLUi+iHI8fXdXCByls5wY9bzOj0Emu9jhzwQt0hTUKXlWX2ZuGVvl9Zuq5U X-Received: by 2002:a50:de03:: with SMTP id z3-v6mr36149228edk.245.1536048204974; Tue, 04 Sep 2018 01:03:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536048204; cv=none; d=google.com; s=arc-20160816; b=Fc+khf7swCLk9mDHh9d299UkjetWApKKDuYQ25Oi8v6qSyELXGzQvfMOaaL+5gLnVb EuguJ9pYn2xkzqlsSNuw4C0F4K3Wyn6bnNJyY2kPpaqH7uMTKExjW/Oe6rjbv5RWQ4Ia MaYGfX6OxiuZueXT4bayEl4dU7fnJOqiuGDvk5J+xYmPr6rl0CdnK7lV1fWzjBioXa4k 67ocwAVGojEqAXwRDgEsIx5/l4+lhLhYlCk6m7hUrpnJ8ghS5CYN4ngd9GwBnKFsOW3z S1uCtuUOCKG4JyVMVJj8aXz/dGoMvwiOdnLoNHdirtYDzmxF9nYv/J2PwjNWDHSA3t5p GyKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature:arc-authentication-results; bh=VW4Hdx4wEWecmHfb0Fg2ShaltByMnTAem+3wHkP5QDw=; b=dblvUZFDxADwp8K4Ieao8vsNEvB4w3lVOv5ri1nVO79GAAuBeyHY00SdDUy3A1Nytb P+050bBEGwRm4V1IJwo86gVJn2I0andG6s/xIddAgkZno3DkektMGjZ6jHRHN/8qfNpW VdwXhh4ch+DlgUC94NxE8WEQXvLStYaYiBWYe0PpaBVmV1oxJ2QhWzflISElzA7zFwhb 9dMy0U0HTJMdfRN0IFvlYuZqAjuGtesjXJxco5cdkInMMWtMEDXbrs5y64/VPY2dfckL 49sHz2VmfbpRzcle2Hyp8Zhdrmz/v7dFJBiM8qYYRrHiWLGQwvkyoiB8sNlUb/stp5uG PNmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=N6M2Szr5; 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 m26-v6si4137378edq.379.2018.09.04.01.03.24; Tue, 04 Sep 2018 01:03:24 -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=N6M2Szr5; 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 929A4C21EE0; Tue, 4 Sep 2018 07:58:03 +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 29B18C21F3D; Tue, 4 Sep 2018 07:57:56 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 5D0CBC21ECA; Tue, 4 Sep 2018 07:53:10 +0000 (UTC) Received: from mail-pl1-f194.google.com (mail-pl1-f194.google.com [209.85.214.194]) by lists.denx.de (Postfix) with ESMTPS id D5FA9C21F34 for ; Tue, 4 Sep 2018 07:53:05 +0000 (UTC) Received: by mail-pl1-f194.google.com with SMTP id f1-v6so1245478plt.4 for ; Tue, 04 Sep 2018 00:53: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=WCRpT4v1ICo+EMlG3bHhBzeqnKp5j/2s7dio1vIYKJo=; b=N6M2Szr5F6iuNUPzjNpBuumjdE0r6F1z54q8l8HCfMBsfL4qKotlaKQmWVtvFlnGRN AmmfaeMTGB+g1+JVAzQEmVUvMafWODu/egUGFWDQwrt37o2P82j0cDeozsRqlKdwLe8u gMjzRxWShxYhQy7Y2NQjcsJoiVovVWcGgsjg4= 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=WCRpT4v1ICo+EMlG3bHhBzeqnKp5j/2s7dio1vIYKJo=; b=dzVslOnjmnXLIG2jW7aam38x4Was+wEoW8sZKsQk2oo0u8NekE3mgWRKVE9wMORlvp 2g3n+pZ9//+THn9qGMrvpwv0wvgHv4M2XbcpaP3rRFc7v3HxWR8ZIpGxcBQskpfk/ES+ pdqCkKdpztUppuwE8+x4b/Eqh67OZwsOaDEbG+H9VS1ydkhijJPnL2gtM6tH7/sAU69o jq4CfSXEwgGdCua4uhybVUuZy/ORD0l7SpeNHQBYV+iuaYNOp0Wf99tH51R05RTXiLU0 FhjSh8eun+FHZzoFIgZ+B2QfrRWRg+rm2UmbKjfpMNUjqJ0CiqlyMUWxJYJEP3CVYkQf hw7Q== X-Gm-Message-State: APzg51BQWZChYKoyEIIoATFEHbxm+dxomKeV+MlakT9K5JWusZxj+agV ynQFe43kq63cUDEtuUVwS3icxw== X-Received: by 2002:a17:902:708a:: with SMTP id z10-v6mr28024058plk.229.1536047584254; Tue, 04 Sep 2018 00:53:04 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id b73-v6sm37538142pfj.93.2018.09.04.00.53.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Sep 2018 00:53:03 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Tue, 4 Sep 2018 16:49:46 +0900 Message-Id: <20180904074948.18146-22-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180904074948.18146-1-takahiro.akashi@linaro.org> References: <20180904074948.18146-1-takahiro.akashi@linaro.org> Cc: xypron.glpk@gmx.de, agraf@suse.de, u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 21/23] 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" 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 | 216 ++++++++++++++++++++ test/py/tests/test_fs/fstest_defs.py | 10 + test/py/tests/test_fs/test_basic.py | 287 +++++++++++++++++++++++++++ 3 files changed, 513 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..9155ccf84266 --- /dev/null +++ b/test/py/tests/test_fs/conftest.py @@ -0,0 +1,216 @@ +# 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(config, fs_type, device, mount_point): + fuse_mounted = False + + try: + if fs_type == 'ext4' and tool_is_in_path('fuse2fs'): + check_call('fuse2fs %s %s' % (device, mount_point), shell=True) + fuse_mounted = 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(config, fs_type, mount_point): + if fuse_mounted: + call('fusermount -u %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(u_boot_config, 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(u_boot_config, 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(u_boot_config, 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 4 07:49:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 145872 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3375082ljw; Tue, 4 Sep 2018 01:05:28 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYo2Pa/SEEIwS412487rPfzeetGI1PNgzEKPbrAj9gn54fK532/eOeZysIrVtvlvKpZi2c4 X-Received: by 2002:a50:d5d6:: with SMTP id g22-v6mr35849562edj.307.1536048328478; Tue, 04 Sep 2018 01:05:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536048328; cv=none; d=google.com; s=arc-20160816; b=DvQ6qnD/mIINztAZgz6i/VYHYjk80ehfpv3ooNkBB+g8mPTB7JqAJusir7BLPidUXS lYlATQCnG/KpeOCNIwTkoIG7mFtAZSWjni9ArHqFiwAqJhlNzLt12v3TlAk3+He+wtXj /E7b0DZy1lVL+Z3LVFEEjL6wo9dxpc/zjTaiYH44e8yIYFiRe6IYZ8hT1ZW9NHKV+h5+ ZhlOuVi3OPnsBy9CGsd4AqKm6s1QctruSiouWWf5wcU5cDSTGbVZzSKGGArjFl3aHGVM qmPPDRcJG8HJ18TGdtOfpIOrarB2TabiQ5lDKT0t+gTVXnOBANvyN66s2US6xMdnI1KV P6SQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature:arc-authentication-results; bh=M4njZNcmPT38z+wCogNAqsOyyME/wYfvhiiILxfkG0g=; b=bQhuNlVILwJKGb7qOyICDsEqGhK0ODjfT+6LSXSqrc1o5MSPz3vkagybYAnIQAtOWD lQ3yNWfxLHS86/OSNqCowx8JkzzGoY6XtFybVyMO0n6DabFxpJmPeZcG1lROKRSVZsI8 P2uPg8Uyv4V+jgSn0Zs5T0B+/X9RfkT/M9MJvyTEPUlBW8v1HVLWVIbn/+RWaDzv+d/Q fEeYxfmgmfsEcslrQtuoRfgCXWBPqVnm2ZocxbXcEGELSXif9kMtBQGdOXtrMuEkU2JP ZfRV+vVVTqsTzYAaspoVbYgmvNuU066Bn6falYPo6634o3XDIHdga4OWKTC3fDgl3Zpo nE4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=AyilLa0Y; 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 z42-v6si5900720edb.410.2018.09.04.01.05.28; Tue, 04 Sep 2018 01:05:28 -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=AyilLa0Y; 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 0717EC21EE0; Tue, 4 Sep 2018 08: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=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 2397BC21E85; Tue, 4 Sep 2018 08:00:59 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 0A3C1C21F47; Tue, 4 Sep 2018 07:53:18 +0000 (UTC) Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) by lists.denx.de (Postfix) with ESMTPS id 8338AC21DEC for ; Tue, 4 Sep 2018 07:53:14 +0000 (UTC) Received: by mail-pl1-f177.google.com with SMTP id t19-v6so1227523ply.13 for ; Tue, 04 Sep 2018 00:53: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=xbu0EuP2wRJQgbCqDt5Gitl/rRpQzy4rpg3CtXDcvfk=; b=AyilLa0YMA8U0Zlcmv8TvNJNIu2qXb1KqDeg9jstBzK0Oca+5E67t4F1G+0skQJxe3 4F2pV39/6RIMtP+VzyCsjydIM1Uu2jzTLhlucZAA5oHC4BdzOrnAeMwonqj6fqkI3Crb jGhlsExQzh3LvqfNAY22ikTOoDPsyeRvr2bCw= 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=xbu0EuP2wRJQgbCqDt5Gitl/rRpQzy4rpg3CtXDcvfk=; b=S8Wu2Nz/LMwWrbXMgcd28efT4ZOAbISdAO4YndVl9xkDHl55Iq/CGe45ZdrtZdmaIo PzWTtwUgogs/jTfYRQfN8ezLaEkb1akz1ab9EqoC3tW3TggZ24ouOVry/sOswT6a3qO6 Qk8rJsKc5MalRE21me/1P5q2syXfpYr35XKOpGeIp+VOVl4o54ljYuAF8smAXslfXMhV xn9Ourj2Z3JP3IQEkvfBE3F368GPJv1VItqu/eaNjSMgD2l4Obe9GanAbDuEMX8dxTyO SJwJufPducPrFD2Unfp77NhkEHXCq1hjVgg4V+kW34s4C/OBr6crPVst1Bufom7oUmmL Rw7Q== X-Gm-Message-State: APzg51DRfArbu652b1okoWnYsLtIhcamSl08/0ISb5CDyKjITqLgHn80 Ytp2j2Jqo5YSJDxgQj+g9iO5WA== X-Received: by 2002:a17:902:8c82:: with SMTP id t2-v6mr18195204plo.241.1536047593027; Tue, 04 Sep 2018 00:53:13 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id v23-v6sm27219504pfm.80.2018.09.04.00.53.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Sep 2018 00:53:12 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Tue, 4 Sep 2018 16:49:47 +0900 Message-Id: <20180904074948.18146-23-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180904074948.18146-1-takahiro.akashi@linaro.org> References: <20180904074948.18146-1-takahiro.akashi@linaro.org> Cc: xypron.glpk@gmx.de, agraf@suse.de, u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 22/23] 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" In this commit and the next one, 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 | 84 ++++++++++ test/py/tests/test_fs/fstest_defs.py | 3 + test/py/tests/test_fs/test_ext.py | 224 +++++++++++++++++++++++++++ 3 files changed, 311 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 9155ccf84266..f72d53d88fc8 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 @@ -214,3 +220,81 @@ 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(u_boot_config, 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(u_boot_config, 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(u_boot_config, 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 4 07:49:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 145867 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3370953ljw; Tue, 4 Sep 2018 01:01:18 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdao/xVnrsrTTyH4EgP7Uwm/9MHxgnd+8E+eZomi8tXOCujn+Xn+9WY90GJeafiUfzr3vuGG X-Received: by 2002:a50:a6c7:: with SMTP id f7-v6mr34956318edc.225.1536048078686; Tue, 04 Sep 2018 01:01:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536048078; cv=none; d=google.com; s=arc-20160816; b=BJUpbLHBMzqB+sfu6Lp++QdZrYHp86mKtL171SzA299YJ/ihJTA+czyklY9WTGtno5 kejxMmEu2SZPCH4DqtsaO93yOBFw/jjQ7BfdkP2+9SjVpVpbwTe1XHlOFJtyX5WHxiSf zORvLjnsSctarCS4eZDx+Epd9FJWnHgc4MIxrlYzpxI2ntsbPbwFEAsMqKVaG1fA6gWT vEO5K4yRdUEuLvV0IVbDAFCjj4Cm5OXlzBl65gNbDasWOFA0PkJ+cvlAU5zkkPQQgmk2 JGdz2VuK+d36sqC57hbs7oR+ebxauROFoRoC3O2r2VrZ50+7TXKcgFHeCdpWOdZfZna9 7wNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature:arc-authentication-results; bh=hQNSktGtweKigB3KZ18RE4VSCNW4cYTpfBBoJkFhfaM=; b=SOlDxUAIPpn6fG13fwYRjGK/QOi2pJm7UcdsAI05ENz7mYY9bzT/6DiEZ2aaj0Oftz QA/MsdQqPaETGzleb/A6PhHx6hmGPxlQkq1SXpu7tgu3SxFUM5pjRVJF19y24rtUke5Y /j36QqfRpzonhAkDEAf7polrvHl7mXwpXH7JG/s3+CWHo00vWTJam6XmrKz/GFdjaszL fnXVYkJdnJqSHyS0TeZ+ojRDUxiGayMGsvnZlV1L8to0MrhddhmAKTtQzR02brDXe+Lj 8FFUVj86Jv7JN1kzYe3bduJRV2wko6LorgFJ2T+p/UtsLtPpLj+kAjXeU5uBN9uRkTzv 5Vkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=a+SJ2axV; 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 z42-v6si5893043edb.410.2018.09.04.01.01.18; Tue, 04 Sep 2018 01:01:18 -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=a+SJ2axV; 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 4008AC21F2A; Tue, 4 Sep 2018 07:55:41 +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 375BCC21F04; Tue, 4 Sep 2018 07:54:40 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 46C67C21F29; Tue, 4 Sep 2018 07:53:27 +0000 (UTC) Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) by lists.denx.de (Postfix) with ESMTPS id 4F84CC21EF1 for ; Tue, 4 Sep 2018 07:53:23 +0000 (UTC) Received: by mail-pg1-f171.google.com with SMTP id y4-v6so1245744pgp.9 for ; Tue, 04 Sep 2018 00:53: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=LNqXESH8xabfDZs8ZJyhu6rbAdvR4aGrl3UkX0OxcCU=; b=a+SJ2axVtIZmpJWEPA5rKZ60Fb2pozhNQuxffqK4cioj7joCg3uEpG9blz+NqORnUY bgK2vJHRVdxh1X/02wCkNYg1siSDEr8EgPPy8hQB6ocqzjM268S5Cs7jWhbHzaPHNUKy dRA150+l9gAe+DQoLB7hhZQocgxQPo+dF6SGs= 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=LNqXESH8xabfDZs8ZJyhu6rbAdvR4aGrl3UkX0OxcCU=; b=Kaje3ORJ+hqv/sbBnZJrQzKozXp5wTh0AWMdtOiAebnE752DacunZQcFgGjrSF5bGh DBm/EVCmpgO+1AWecats9qBEYUldtbFWxWB6iGdnZP7Lji2Axe6L/ZUtnF1ZKEwTtCpJ i03sfqW9IAR7H7F/AllU2Ccb4jF3hkODv1b4gs4NApajYAIC1jmbSoqmYlv2VA6TFZFv 9qbYdHA7oORNiaebfeTmqlRDKBROKFsRo/TXzsS76AvejCtQOxExMrGMPMEhwFIA0Nz1 s4IakWBXuYFXT8TalruMLqUojTpLmNxBkBeX91FlAKOwn6Jhk9/QX5pxDmJ6M5HqQGp+ saYA== X-Gm-Message-State: APzg51AU3udH/+ovrw2gVW+2+/n8mPLPQaxbjjwkmSdTgYicELhW272j D6qyv1AKHzHzxbuN+kzm/xyjLA== X-Received: by 2002:a63:6485:: with SMTP id y127-v6mr29593990pgb.393.1536047601859; Tue, 04 Sep 2018 00:53:21 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id t12-v6sm35062042pgg.72.2018.09.04.00.53.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Sep 2018 00:53:21 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Tue, 4 Sep 2018 16:49:48 +0900 Message-Id: <20180904074948.18146-24-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180904074948.18146-1-takahiro.akashi@linaro.org> References: <20180904074948.18146-1-takahiro.akashi@linaro.org> Cc: xypron.glpk@gmx.de, agraf@suse.de, u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 23/23] 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" 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 | 31 ++++++++ test/py/tests/test_fs/test_mkdir.py | 112 ++++++++++++++++++++++++++++ 2 files changed, 143 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 f72d53d88fc8..0d909ed7789a 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 @@ -298,3 +304,28 @@ 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: + print 'Dummy' +# 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)