From patchwork Sun Nov 29 02:01:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1407774 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.a=rsa-sha256 header.s=badeba3b8450 header.b=bpCWmEFl; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CkBVz3NZkz9s0b for ; Sun, 29 Nov 2020 13:04:11 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1A10682788; Sun, 29 Nov 2020 03:03:18 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.b="bpCWmEFl"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 05F0182779; Sun, 29 Nov 2020 03:02:53 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 5E30D82741 for ; Sun, 29 Nov 2020 03:02:42 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1606615348; bh=1ZVVRxFg4GJkxr90o4JFPHOTH/6VWYqqoNj/d8H2zpc=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=bpCWmEFlUL4nCCXyY+ub5zvXa7VEcpFs/QEQIJy0Cjh4imzLX2XHeE41g3mKCnwOL LpJmyRV8wwsOWBUnlSdQVWH4ChPjp/QqwvHMdqHGT7QKcWGHIkojvhZoi9d/8ZOdR2 PxSrTgxX99D7o3XBegCLNSfZxgzcBdlv08GkEpaI= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from mcbin.fritz.box ([62.143.246.89]) by mail.gmx.com (mrgmx005 [212.227.17.184]) with ESMTPSA (Nemesis) id 1MUosN-1kaDlV2eO1-00QiD6; Sun, 29 Nov 2020 03:02:28 +0100 From: Heinrich Schuchardt To: Tom Rini Cc: Simon Glass , Christian Gmeiner , Jason Wessel , AKASHI Takahiro , Marek Szyprowski , Bin Meng , Reuben Dowle , Marcin Juszkiewicz , Thomas Hebb , Samer El-Haj-Mahmoud , u-boot@lists.denx.de, Heinrich Schuchardt Subject: [PATCH 01/18] fs: fat: avoid NULL dereference when root dir is full Date: Sun, 29 Nov 2020 03:01:59 +0100 Message-Id: <20201129020216.4865-2-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201129020216.4865-1-xypron.glpk@gmx.de> References: <20201129020216.4865-1-xypron.glpk@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:7VpDXhZCYbC3KsZJGSFunf0fpQzDsweBKohpq1PHZohCTHvufUO bguApBtobswtSvL1zlTEhE92WvJiamyM71aTOepVAQQdrtCI11bxPG14pHrU147IJ0pvG8R c6h8DTifI+osd0YBEpiGvBluEcS19qVZ3pllGMbv8hV69wwstF0BLqTd9aYxUOKKzp8f3cG Mu6V0gxF8EyCKlTAJWWSg== X-UI-Out-Filterresults: notjunk:1;V03:K0:nzSupXHOOfs=:0PDvaJWsz5DWGpPJXJoCdO 4QH29upTwz1IkUG2bQKzZpSwZwdmJRgFVRMDFEeqdcsfCvyCSAE9KG2Jex2HN40v0VZwE/G8n voT3GdaB5ry2gJDgBgQJYubmq48ixYDIYEVFIRqyAcaaa80OdIBhHSAM9YZdDxHBW63CPo4W3 XvrEKzrq8TlgslrrDGbVsUDi2gthZUcwXc+Jp5WnAWUJTdBuXtJBmpPjW6A0uCzu9SJ5mGjJ7 nnFxBbwj7au5twfZU5DeBQD4QBW+16Txm27f2fgSBp56ROKdNujh4d1HNqat8wRz8oYa9QEll GDG5DkUqP0NDPV9SicHfGd0qFyHPx4TteWr8hjstFHk8QJZ5C/D4m5du4J/wXD8oHV0FnvqMP y0ECJQg0VCXIYANzH5h2jNWLKyMrK22TBG+rcZqOC+EPwCKpvs8qvH5BSdljnMuxDGschDfc0 nbmzvpNxEflJ/QrLH6JhIkG3KeZDhAaZsCAuRNnuhD8Bpf7u8LoaEBWBs2wmXgOgTlzifykH/ lsFSiRVaO7NlLDemZwld5LeTSfleKvoj7QKOnUqMMLWj34jCco7fNuFAk4zcEzg89TAHK0Wog 2auMtELr5QUH0MdmaAB4FiZffCntWa2JtsCmdpaykYE3MSOj39CnT8o0Rzm1GvPP9UC7lTVrq WOkEV1HOnYEWB1/Rp6mq/CBmY2SQGuAUPHS5niioFL7c7qsZu1SHp+6P6AxL/L9r62ttlmDMV V02X2t2cxoNNhlBae9oKcNd8ZKHRdFijyftFr55NV37y1tOSP2UVrtRBOv1Oq9pgpqHhb6Wkw D/HwVSAu5UybbVADTvBclD8E79+mYGwRSM2Y6O1IWeYPVkdVHFU9EuJwhTY9MVD4YjTx90uKt aocwk1BnPnM2nZAOIA9g== X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean When trying to create a file in the full root directory of a FAT32 filesystem a NULL dereference can be observed. When the root directory of a FAT16 filesystem is full fill_dir_slot() must return -1 to signal that a new directory entry could not be allocated. Fixes: cd2d727fff7e ("fs: fat: allocate a new cluster for root directory of fat32") Signed-off-by: Heinrich Schuchardt --- fs/fat/fat_write.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) -- 2.29.2 diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c index a2682b5f46..fc932df953 100644 --- a/fs/fat/fat_write.c +++ b/fs/fat/fat_write.c @@ -260,9 +260,8 @@ fill_dir_slot(fat_itr *itr, const char *l_name) flush_dir(itr); /* allocate a cluster for more entries */ - if (!fat_itr_next(itr)) - if (!itr->dent && - (!itr->is_root || itr->fsdata->fatsize == 32) && + if (!fat_itr_next(itr) && !itr->dent) + if ((itr->is_root && itr->fsdata->fatsize != 32) || new_dir_table(itr)) return -1; } From patchwork Sun Nov 29 02:02:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1407779 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.a=rsa-sha256 header.s=badeba3b8450 header.b=U2e5Ueco; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CkBX308Nfz9s0b for ; Sun, 29 Nov 2020 13:05:06 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 60850827A4; Sun, 29 Nov 2020 03:03:47 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.b="U2e5Ueco"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BE97282779; Sun, 29 Nov 2020 03:02:59 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 814EF8274A for ; Sun, 29 Nov 2020 03:02:43 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1606615349; bh=2ExQanTB7Kjf8MnmeQo0725hytL88xyK3+2kJ5uxQrM=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=U2e5UecoBBVQBH3Ca5Qv17t7wp5U0y5xxJkVW4LLISGrXA938X3KPBU1x14c4cwVN fnS5qObrMpu+e3G+LqGqXYzHV/upV4JmdnGzk6jv4e5DJsDF0Sl1iRqaT9dIO2jRBZ OK3pWn6iuHBI9YVFnPhD2++mRhXqLT3e8rDZAxsQ= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from mcbin.fritz.box ([62.143.246.89]) by mail.gmx.com (mrgmx005 [212.227.17.184]) with ESMTPSA (Nemesis) id 1MS3ir-1kbsj80bil-00TTMc; Sun, 29 Nov 2020 03:02:29 +0100 From: Heinrich Schuchardt To: Tom Rini Cc: Simon Glass , Christian Gmeiner , Jason Wessel , AKASHI Takahiro , Marek Szyprowski , Bin Meng , Reuben Dowle , Marcin Juszkiewicz , Thomas Hebb , Samer El-Haj-Mahmoud , u-boot@lists.denx.de, Heinrich Schuchardt Subject: [PATCH 02/18] fs: fat: directory entries starting with 0x05 Date: Sun, 29 Nov 2020 03:02:00 +0100 Message-Id: <20201129020216.4865-3-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201129020216.4865-1-xypron.glpk@gmx.de> References: <20201129020216.4865-1-xypron.glpk@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:ncUavtdN+FvqBgeiHcQ3LR2i+kUwk7zGS41RjmrWnf0T1TMPbWC DTp16kmz9dB+PlPcvrqU8ADmLva3vK699WXbWFKdIuNHJ3WGrl82DoYpUSOjLVj2TpYmTr+ JREHMUrgYxM15sO9JV45k+Xvwhr10G01DqJxYBDlWBERmO8jtxxtG7fOt+j4XO7aApZkIPI ON3pHu8BiQzH8J1sBYSZg== X-UI-Out-Filterresults: notjunk:1;V03:K0:e1xC4rgASqc=:sb90jTlz8hRmj3H9ih8oEf 3qprjx3ixN+Y8wVRcif+x8MWa6PWz5Rqd4963wh579Wb5pVGYmy1mSodBTWeMJrTmaapRg6hA iQYZdIEzHo1eG4yRjJVPzOO3MQwS0PiCgDCUjPxSNIK86GLD00WRX0pdYyA9Wq+vyr+LhW4T6 dmBUPr+WhsIBlEazMTM5gZa0FBemFFz69El6xiVbOr7mir/+4p7GpO4fAH7j9kQ8qMQhXxCWy eEfqhisKbdkIFIj68MOfOos/3vNECcWn+pmGlrYdHxgWXizMu4yusGBMsOzLmB71gYxRzFEdW W1XsQH0zvKxNwTluG15vG8wy0+CDmQ3zaYg87CgpE3RfqRwbIkdq4rZQxb847CNckt7Hju+xn swIGqPKBH7ABJb8188F2fdZQastXVEuyU8htKsdUa7RMFQfAkTy0kKKUgPCoRqaQuaOBnjtVY vFLoGI61hPso91c06tZGJ78MZ5ELJY1KSOHFgRMQL5OYkMPYJHMpyMZe2zqpjWQ3TIICmjTvm 3drghHp4on3aQffR8HpRb9a5BiWipLGk8D0DzV5CZDVYgF2r6T4ERK4sqdKuQ7Z8MPfRQWQ7q 5hUtnUM6yvjqYRijRUWCjuogO1xtF5MJA1hBrPxwaASlJH8ZffpSQrKK6+lsrQtdzAKePLB2P WYOPLkaR/8IfhUXi3ePV4f9nEZBZZ8GbQq+OgyBUTAdOW8TNt2Cew0YLguKWlwXBP7zwuPSYp c/PfcgDJhEJJEWVhTH381NsGbdoBr9oBjhx9N4IOc47134VpukUGzLqCZi149Uq84VQZlgq/i KcEryfGEUiNEz3WnjLrVU1AS2fJXbCr88ck4J9SPRYUwO28ZcBLEiHu0lDrSKhMfYxPKJaFiU h/vLSdlQ6vju+cNzLU6w== X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean 0x05 is used as replacement letter for 0xe5 at the first position of short file names. We must not skip over directory entries starting with 0x05. Cf. Microsoft FAT Specification, August 30 2005 Fixes: 39606d462c97 ("fs: fat: handle deleted directory entries correctly") Signed-off-by: Heinrich Schuchardt Reviewed-by: Christian Gmeiner Reviewed-by: Simon Glass --- fs/fat/fat.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) -- 2.29.2 diff --git a/fs/fat/fat.c b/fs/fat/fat.c index 28aa5aaa9f..fb6ba89466 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -926,8 +926,7 @@ static int fat_itr_next(fat_itr *itr) if (!dent) return 0; - if (dent->name[0] == DELETED_FLAG || - dent->name[0] == aRING) + if (dent->name[0] == DELETED_FLAG) continue; if (dent->attr & ATTR_VOLUME) { From patchwork Sun Nov 29 02:02:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1407768 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.a=rsa-sha256 header.s=badeba3b8450 header.b=Xq1kmcD7; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CkBTd3xX4z9sSf for ; Sun, 29 Nov 2020 13:02:56 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C0A4682762; Sun, 29 Nov 2020 03:02:46 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.b="Xq1kmcD7"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 830D382754; Sun, 29 Nov 2020 03:02:44 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id BCA6082732 for ; Sun, 29 Nov 2020 03:02:41 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1606615349; bh=t3w5P2lSMatUVMhP3d22mdiMeUX4CAB41ipCulaV6Wo=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=Xq1kmcD78wXHqnjc593lt0PXUKpUW99Oq2IPmKptOQ45NTObwmgQClRjjMSorlB+n saXDD2y3LghIbXHIu2POhO71D1XHYvgNOrtXSYCMNdr8PESulOi3FXm0tY5oYSZe9N Az5PJRM09i/ngoZtev+p29Cg+F8N8+YLviAYAz4w= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from mcbin.fritz.box ([62.143.246.89]) by mail.gmx.com (mrgmx005 [212.227.17.184]) with ESMTPSA (Nemesis) id 1MxUnz-1jyx922lsP-00xq7A; Sun, 29 Nov 2020 03:02:29 +0100 From: Heinrich Schuchardt To: Tom Rini Cc: Simon Glass , Christian Gmeiner , Jason Wessel , AKASHI Takahiro , Marek Szyprowski , Bin Meng , Reuben Dowle , Marcin Juszkiewicz , Thomas Hebb , Samer El-Haj-Mahmoud , u-boot@lists.denx.de, Heinrich Schuchardt Subject: [PATCH 03/18] fs: fat: use ATTR_ARCH instead of anonymous 0x20 Date: Sun, 29 Nov 2020 03:02:01 +0100 Message-Id: <20201129020216.4865-4-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201129020216.4865-1-xypron.glpk@gmx.de> References: <20201129020216.4865-1-xypron.glpk@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:/Qsefu83tQEwCCUKLSJYDtZYqMuTG/nGlcRblrbYkjIq8jg8zK2 INZhZXOTHQZU3d28IYzHOm55FQRSh+5mvStLg9w/q3PAPKYuipqVN9KDB73FHVSXTCSPeNK aiL2dkhK9p6OSEQU+GO2q5kjFKDukmSHLHsAkf+h/hWDA1Vno7I6KzLY0Pt/st6Mk2/o+CP lt8VGZ/ZtZ5Twje/PogCA== X-UI-Out-Filterresults: notjunk:1;V03:K0:KzirYkeLFc4=:0I4DF8oO0frx4DKktQzJRW CRMn4BzMnfRloP1ERG264p1mgms6TNIaRwFrqnTtXR/sEp4ijxb/svqxAWTB9IWqDZAyh9k59 SxZkiMjFKJztfeEmcCOxsbzs1Qx14IsyE2bL99jUBl6eD1H8Msj3j7ijxLESkjxtY7Dkx9x5U lua0l0D7DbH3hD/hcrr4KaE4dIc4VslaFnXrKhb63UblEUO4s6biMCEdIVyFHiyYonGfzF9Oa ZxrvtuY6kqrlQ8RksNjBmnEUJvVhVNoaWk3c3mw/bTXt4z+Cc5MaC2ocfddEDpMS9+3DNCz22 P6wrCDWJGMdS4kY+yIXR42+wivLrx33m8jY2WUSQ+9C2RJhXslTCXLiTL70Cuwj0g5s0Xl3Lv q2aWPnujXPEqv0seMuyri8Q0NPHhLvB7ToEP3zrQMIMBkTNiZcqyCvOkzkPY9Lb5dboF7XntB EZDQV6OeJPF5sHAorP0GMBNLsrFafcc1jS0uVWwRip6aWGH1nQqlU7mXDjp2NcmeapTI87fbj 2VskOGZ7U+JZS6Cpf4ToH3S1v+1uXjLjIaT5xWCsUWO/p/hMV6rDaEGV5Ffp44LWJno393IrP YmSfsaXJL/2DjQkeZ/WTtQyfNUtPNKmDtVxpmRam/KY0NAQJPxbIckqjcevvncgB5WMQ6qPRU OK1mzvGyvPXAl0mTJKBaA7ysIJNpUD1S858kPaEFnNnnxwJ5jofeueDxM9vHTw9BdChAVVrV9 8PL0f3urMs9dy+d4ELW8u7Qk5tbe2hD5ugjIWMgGpY6Yexv+ez6Z7kf2isLC2Q5Uf7g4Vg2yD bQrHk7rWkJBLYAyR9g/VOCsnKkF1RSHzoNsAIus2U0ZFvtn2UWbnb0NZotQzGvo/0tBOf5Ghw xXVd7uX81j1PYwiJoAKw== X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean Using constants instead of anonymous numbers increases code readability. Fixes: 704df6aa0a28 ("fs: fat: refactor write interface for a file offset") Signed-off-by: Heinrich Schuchardt --- fs/fat/fat_write.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) -- 2.29.2 diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c index fc932df953..7afc8388b2 100644 --- a/fs/fat/fat_write.c +++ b/fs/fat/fat_write.c @@ -1191,7 +1191,8 @@ int file_fat_write_at(const char *filename, loff_t pos, void *buffer, } /* Set short name entry */ - fill_dentry(itr->fsdata, itr->dent, filename, 0, size, 0x20); + fill_dentry(itr->fsdata, itr->dent, filename, 0, size, + ATTR_ARCH); retdent = itr->dent; } From patchwork Sun Nov 29 02:02:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1407770 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.a=rsa-sha256 header.s=badeba3b8450 header.b=FY5r4aWI; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CkBV24YtWz9sSf for ; Sun, 29 Nov 2020 13:03:22 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id AB38A82754; Sun, 29 Nov 2020 03:03:05 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.b="FY5r4aWI"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1323082785; Sun, 29 Nov 2020 03:02:49 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 31FB48273B for ; Sun, 29 Nov 2020 03:02:42 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1606615350; bh=Vp4TRE0IADRg9nH/Jn3Hi0APxhWPesZeZ7if3S8gGco=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=FY5r4aWIEcSjorR3AD7EhIG6mniQa0TRIoc94mHebLMBy5NO64h98z4gxxI+/4G2t 7WZvOB6b271QcTjH6dQHkHrCoWZOOTJiy+9QJOcFtDNOa9gbA8MGTxqzRM+bFvEGhS bTTgRNcrwES7/RTVuOyIAMyCjUg1qc5xJiX2Y7Is= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from mcbin.fritz.box ([62.143.246.89]) by mail.gmx.com (mrgmx005 [212.227.17.184]) with ESMTPSA (Nemesis) id 1MAOJV-1ktPZt1vx5-00BwVq; Sun, 29 Nov 2020 03:02:30 +0100 From: Heinrich Schuchardt To: Tom Rini Cc: Simon Glass , Christian Gmeiner , Jason Wessel , AKASHI Takahiro , Marek Szyprowski , Bin Meng , Reuben Dowle , Marcin Juszkiewicz , Thomas Hebb , Samer El-Haj-Mahmoud , u-boot@lists.denx.de, Heinrich Schuchardt Subject: [PATCH 04/18] fs: fat: correct first cluster for '..' Date: Sun, 29 Nov 2020 03:02:02 +0100 Message-Id: <20201129020216.4865-5-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201129020216.4865-1-xypron.glpk@gmx.de> References: <20201129020216.4865-1-xypron.glpk@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:WQQ+vFL4BMfCyfCALhRkQG03EIOId+gmhOGWQ2dbERS+vf22qse d+MwmJBqjuiIOSEo6vH37cya686e5C3DvH/a0sJ0X5Z81Iuj/mNbR2cXF6sx7K8/z43cRAc 3mFSrMKesYqbRu4QAmYiw0iXGTZwRDGkEVNeXCbm8j8IWib4F05xeqC97wYOBS7KR3FEgn+ qAtPeUiPMcZ2lbzqZn+KQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:abi9cBEo/8M=:nY4c++LLGhn1NrfGxz5hXF fuXsnyGNIuvEQD+ThvShpqoDujTf/B3vGLg8DxEU4wuZ9GCl34LPC/UMeIEUy/WMHhFy8nacR /8hzPr5kDlAnmvz3RXMVxX5eW6oaaNZfyGsLB0jxm61PtOemWjtt37Zr3PiADDQ/VFAcvATKF WO4Jd4yyMNYOLDhtLvimTjmcaV3WXXaHJG5XTcFcFQLajPV+AC57b1X9c0HXibip+ZCko7T5+ lg8KzpnIYq+8ZPR1utlknxW1oWCg8ugC58KIappAIl0AmJO+g6NVqeoytRnB9TBDX156WJ8E4 qaLNAZg/JlLnY1drA84OE6ugaoWdIUQJk2xG3IGQeek5Anp9m72Viv51Dtcu2P9/vABBNKaYA cepZdldlUN/CHcwoq9A8d1syrUvxkkaApaG/Xxnbq8q1bwvItivx3Rh2a2udmJ/2Y9pNAVW6Z xmo2wa7P9dEJCzSEgXmYiE9UQyBcBo5O4IDTs8H3B6iECFby0tcf+9e8MPknUUfJOlOv3NGUe Nc6R/CAqLHgoHHIuwLhJHB8KjS79WKiC2GvmQyMkLSAniZUypKM+gvNcX3An/amU+nQRm8wAS xrxeub9L44kjCIkHnyC7KkTJMvTz01QstLDWPYkhu2kdZU7nIERtDcYiUImatoc7gJewlPuFC 5HvDWlbEyTJsg4J1fWn1q953bj97gjyFVBI7fMixJwV18/mr1t+nYnmb/5s9Ki/YldpdpRbWS oKAZYfaHxHK33TYbbq7+pEKX6MtQZXDwdK0wBoMX21TrQLsDxjn0K+i9PitbldWviLW7mWgx9 Fyg9VRlLm+ewmZWx3dI0TiJzlhsi/9lf0W1pTg5VEazwxBZ9jHgWnZxEpNiY6071m+PmBTsnz 1Uq5I+SNv2xbuGwMa9ig== X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean The FAT specification [1] requires that for a '..' directory entry pointing to the root directory the fields DIR_FstClusHi and DIR_FstClusLo are 0. [1] Microsoft FAT Specification, Microsoft Corporation, August 30 2005 Fixes: 31a18d570d96 ("fs: fat: support mkdir") Signed-off-by: Heinrich Schuchardt Acked-by: Marek Szyprowski --- fs/fat/fat_write.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) -- 2.29.2 diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c index 7afc8388b2..4da342f9c9 100644 --- a/fs/fat/fat_write.c +++ b/fs/fat/fat_write.c @@ -1468,7 +1468,11 @@ int fat_mkdir(const char *new_dirname) 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); + + if (itr->is_root) + set_start_cluster(mydata, &dotdent[1], 0); + else + set_start_cluster(mydata, &dotdent[1], itr->start_clust); ret = set_contents(mydata, retdent, 0, (__u8 *)dotdent, bytesperclust, &actwrite); From patchwork Sun Nov 29 02:02:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1407772 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.a=rsa-sha256 header.s=badeba3b8450 header.b=eKjixKQU; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CkBVV1Cfhz9s0b for ; Sun, 29 Nov 2020 13:03:46 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A24CC82777; Sun, 29 Nov 2020 03:03:12 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.b="eKjixKQU"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id ABCF882745; Sun, 29 Nov 2020 03:02:50 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id E91DC82749 for ; Sun, 29 Nov 2020 03:02:42 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1606615351; bh=B5puKpH3ZvT5QGyREjKOV6nnMxF95Q7welVpHWemkZA=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=eKjixKQUy9CC/iqT6+qMKbmi6Ns5mz+zFUiNxjQZFQRIIshTIllKLpNuzj4xE0Noj Xbbem0ZmHLlsoyvkJ5x9NQaoq9JiKQ0gSlwJ/fJiXeXp4+mbBtGBrKlwnyufNtKnU8 mp/JdFMAyynnINKFEGJIeUv1whDgW4rlbEEGMSLE= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from mcbin.fritz.box ([62.143.246.89]) by mail.gmx.com (mrgmx005 [212.227.17.184]) with ESMTPSA (Nemesis) id 1M26rD-1kl7r542TR-002Yaq; Sun, 29 Nov 2020 03:02:31 +0100 From: Heinrich Schuchardt To: Tom Rini Cc: Simon Glass , Christian Gmeiner , Jason Wessel , AKASHI Takahiro , Marek Szyprowski , Bin Meng , Reuben Dowle , Marcin Juszkiewicz , Thomas Hebb , Samer El-Haj-Mahmoud , u-boot@lists.denx.de, Heinrich Schuchardt Subject: [PATCH 05/18] fs: fat: export fat_next_cluster() Date: Sun, 29 Nov 2020 03:02:03 +0100 Message-Id: <20201129020216.4865-6-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201129020216.4865-1-xypron.glpk@gmx.de> References: <20201129020216.4865-1-xypron.glpk@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:9gWRCbcQy2wUsney9PpKMLZN6pxDeSLwBd+52mFxoQ9m3vEOcWz a4m9a03GO8CIZX5EkIwKfqvBNNvF/B/n4mrw0BsIcFHs/qkhmYe/NxYXLgsz4wLlGYnRpjw INyp83Ty4YGKmtXOkJK7VWzySpkxMocXxFAOnXhc6R+5r7VzNTPFfc/2vCQAQ8qnKQdonf6 xYHfVJ8cEkWc0aGoxIz7Q== X-UI-Out-Filterresults: notjunk:1;V03:K0:JW1KjfSad7Y=:yCvir5sdbhWeF+grSXABC5 aBOKf/Sv/5FQ94OTmy8ZJixSQZ6omOfUwHHm6dDzIcg4NN7+guefDtqvDFQrJXGtpBDqI8DMt pkLyrcNyMXwZTPczUAA0Ka+etmTwg3PgR1c0aphAZPcrCkV3xmVzacPZ9R88tebCfQl5ezaQS 5vw9yoccrQ76iBPGFDpla1miLM5LiqTWG1P8ByzhqMHObWwHOYrKaRxw9oB9sDeK4LwUwSDFh LfulE/vHIqaLIKWGgLYHZwtfTq7pv+VU37yBIkiNSqqe1DWp98yIQJlLswK8F974j636ZzU+L ckbguQrvBFymsLGNMuN2g3bhJCjdXzaTnMvtEhapLtNKlrrDGh4zz/oX6uAh6jWCCN2XCy3yZ ySn/MLNGK8NjrNxmkTvzMvl+Kj5s8Tq3vkmInUR1fUqzY3YxJynzIUsVlqFoHLBqKt0zLUm2I 7pOJ1R5wlU88silHcWjhhEE8E60h+gyIPj3G58sHAnyRVvc6TKWmGH8Kw5rRcWIPrVcrzFmB2 sJELY+2wGsWNBZaV07Uvqn8G9l3dJYh5zNqkXOe6XGkZ7kw2Fj8++7VRksFcpFR18Csb/kRfR 0ooQreJ0dgjwsyXYbyw0kIRRHlTVBheqcZbEvnDNOeQ3M7t75zpBsFosYIZf4xXyTjAmpS8sU Nac0Ow12cYRuAJXucHVUnfnZwv9KT1AMyjOZ3edRK/YvRlN9C4X3YKYhFrDB1B9coJlonbYHD 1YWrzet9QZBvQT/H7fuIHjkz3cdlyxsvdMb37NanrurgvBxcaXKD+pAPIFwr8LV/qwPO278O4 TMMgJBfsVDisftcDsckrJx3TlCPj51gvIo4Y0Qtiooxbrh7iflPIjl/Qq0bG8kcBJGqrPqPRW DwdzY/0YdvsQjf4MJ09g== X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean Rename function next_cluster() to fat_next_cluster() and export it. When creating a new directory entries we should reuse deleted entries. This requires re-scanning the directory. Signed-off-by: Heinrich Schuchardt --- fs/fat/fat.c | 106 +++++++++++++++++++++++++++++++++++--------------- include/fat.h | 7 +++- 2 files changed, 80 insertions(+), 33 deletions(-) -- 2.29.2 diff --git a/fs/fat/fat.c b/fs/fat/fat.c index fb6ba89466..674236d68a 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -621,7 +621,7 @@ static int get_fs_info(fsdata *mydata) /* * The root directory is not cluster-aligned and may be on a * "negative" cluster, this will be handled specially in - * next_cluster(). + * fat_next_cluster(). */ mydata->root_cluster = 0; } @@ -647,44 +647,76 @@ static int get_fs_info(fsdata *mydata) return 0; } - -/* - * Directory iterator, to simplify filesystem traversal +/** + * struct fat_itr - directory iterator, to simplify filesystem traversal * * Implements an iterator pattern to traverse directory tables, * transparently handling directory tables split across multiple * clusters, and the difference between FAT12/FAT16 root directory * (contiguous) and subdirectories + FAT32 root (chained). * - * Rough usage: + * Rough usage * - * for (fat_itr_root(&itr, fsdata); fat_itr_next(&itr); ) { - * // to traverse down to a subdirectory pointed to by - * // current iterator position: - * fat_itr_child(&itr, &itr); - * } + * .. code-block:: c * - * For more complete example, see fat_itr_resolve() + * for (fat_itr_root(&itr, fsdata); fat_itr_next(&itr); ) { + * // to traverse down to a subdirectory pointed to by + * // current iterator position: + * fat_itr_child(&itr, &itr); + * } + * + * For a more complete example, see fat_itr_resolve(). */ - -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 */ - 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; +struct fat_itr { + /** + * @fsdata: filesystem parameters + */ + fsdata *fsdata; + /** + * @start_clust: first cluster + */ + unsigned int start_clust; + /** + * @clust: current cluster + */ + unsigned int clust; + /** + * @next_clust: next cluster if remaining == 0 + */ + unsigned int next_clust; + /** + * @last_cluster: set if last cluster of directory reached + */ + int last_cluster; + /** + * @is_root: is iterator at root directory + */ + int is_root; + /** + * @remaining: remaining directory entries in current cluster + */ + int remaining; + /** + * @dent: current directory entry + */ + dir_entry *dent; + /** + * @l_name: long name of current directory entry + */ + char l_name[VFAT_MAXLEN_BYTES]; + /** + * @s_name: short 8.3 name of current directory entry + */ + char s_name[14]; + /** + * @name: l_name if there is one, else s_name + */ + char *name; + /** + * @block: buffer for current cluster + */ + u8 block[MAX_CLUSTSIZE] __aligned(ARCH_DMA_MINALIGN); +}; static int fat_itr_isdir(fat_itr *itr); @@ -753,7 +785,17 @@ static void fat_itr_child(fat_itr *itr, fat_itr *parent) itr->last_cluster = 0; } -static void *next_cluster(fat_itr *itr, unsigned *nbytes) +/** + * fat_next_cluster() - load next FAT cluster + * + * The function is used when iterating through directories. It loads the + * next cluster with directory entries + * + * @itr: directory iterator + * @nbytes: number of bytes read, 0 on error + * Return: first directory entry, NULL on error + */ +void *fat_next_cluster(fat_itr *itr, unsigned int *nbytes) { fsdata *mydata = itr->fsdata; /* for silly macros */ int ret; @@ -825,7 +867,7 @@ static dir_entry *next_dent(fat_itr *itr) { if (itr->remaining == 0) { unsigned nbytes; - struct dir_entry *dent = next_cluster(itr, &nbytes); + struct dir_entry *dent = fat_next_cluster(itr, &nbytes); /* have we reached the last cluster? */ if (!dent) { diff --git a/include/fat.h b/include/fat.h index 02742f92a5..3c29a4484d 100644 --- a/include/fat.h +++ b/include/fat.h @@ -9,8 +9,9 @@ #ifndef _FAT_H_ #define _FAT_H_ -#include #include +#include +#include struct disk_partition; @@ -179,6 +180,9 @@ typedef struct { int fats; /* Number of FATs */ } fsdata; +struct fat_itr; +typedef struct fat_itr fat_itr; + static inline u32 clust_to_sect(fsdata *fsdata, u32 clust) { return fsdata->data_begin + clust * fsdata->clust_size; @@ -208,4 +212,5 @@ void fat_closedir(struct fs_dir_stream *dirs); int fat_unlink(const char *filename); int fat_mkdir(const char *dirname); void fat_close(void); +void *fat_next_cluster(fat_itr *itr, unsigned int *nbytes); #endif /* _FAT_H_ */ From patchwork Sun Nov 29 02:02:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1407769 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.a=rsa-sha256 header.s=badeba3b8450 header.b=iSpVFKEL; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CkBTy2bbCz9sSf for ; Sun, 29 Nov 2020 13:03:18 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 34AC682783; Sun, 29 Nov 2020 03:02:58 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.b="iSpVFKEL"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DDF1982762; Sun, 29 Nov 2020 03:02:45 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id E189C82738 for ; Sun, 29 Nov 2020 03:02:41 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1606615351; bh=B9bjVajdq2dL0FYLbOHU5ny+QlNA/mrhIEEWqQL+1Tw=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=iSpVFKELYjev/fZVd6IAvoM6xsG3At/ZBpoSR8PJPwHBsikB+dMfKSR9GrJ0DknHo ijZ6O2IYFPI5C3CLSZp5+MTpkFsIerbSB5kib1aL1RvkO2LYe/dxqhOppJZX+shWEf hgJ+kXjwRCnqFGU2dVYkrUH4nrvzB5Yq4SV8YxU0= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from mcbin.fritz.box ([62.143.246.89]) by mail.gmx.com (mrgmx005 [212.227.17.184]) with ESMTPSA (Nemesis) id 1MpUZ4-1kQhGF1xSG-00pxlR; Sun, 29 Nov 2020 03:02:31 +0100 From: Heinrich Schuchardt To: Tom Rini Cc: Simon Glass , Christian Gmeiner , Jason Wessel , AKASHI Takahiro , Marek Szyprowski , Bin Meng , Reuben Dowle , Marcin Juszkiewicz , Thomas Hebb , Samer El-Haj-Mahmoud , u-boot@lists.denx.de, Heinrich Schuchardt Subject: [PATCH 06/18] fs: fat: create correct short names Date: Sun, 29 Nov 2020 03:02:04 +0100 Message-Id: <20201129020216.4865-7-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201129020216.4865-1-xypron.glpk@gmx.de> References: <20201129020216.4865-1-xypron.glpk@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:yyNGjlBcRgs2g6eC+HLuzNIIN/juN1G7BwY9kgoGO1noFNHdBCp tqCGw7duHR0pxg0889BoaRkPFCTY6RBEjxuFFEtHB13l47YEeQ7X6by6QcyzbC4uI4k92EA VkRNYjZuSoKmIJWeo9L1nQSmorMqI9SCSjfvhkx3skhz6IO2vOxcPv2F+nhQmtWkcP83TV1 63iIGEVrJL55nBB4wrezQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:3uO66j5Xgpc=:/nTXUHvinyH37X4oQzy5Dn ooLOPkyoRofhldhox2k3P/Pcp+q+xKIxG4z5s2B1QRIAkz2qXcW5xyImkzjwMIsH8t0njNBkL EHyjiyaqaAoH2pvYxlV0BLGIqlmrT1drvHwxtLFDaDzb59QN323Vty2T2nvLPCLaRHEjFJeYw RnwfXWGkYxallSxPsciLszAgw/Ht5M3cTqlxnW57ryccrjfbrXUTG/93epQ+cEN2lCb9AdTGB 7EnV6FGBTWcnJ2/NZljtThAn8FuYKNg9mFg+DtpBvK6a77ZdOBQ5Iqy7C7/C3Iyc04lwTGvBb iuWLBP04p3ANt1TwWTTjQ1RbIUUQxlc9ecVDeTKyX+VD4uGgZkIlc3JkRtSjrcbE2lwEenYex Saou8bY9pGm0ABVNHdRNSexfO4kXhk6co1vkhUaOWihOU0r5Gt503hWroaK3d79HZ1eGzDQ26 TaBELFxKMjPOa53HMW2xkY2sksA0mHLiwkreWHTy3sjGc6B3+Ukwvzb95Az4YNpIRh1SMdZcw 4yw0z8PPwLc7C5IZCGYM1D09E8vXyxll277rAG4XUCpBG1t26yjIiQbh0HBbr7Ibu1F2nRZAS NlF8ztTmOI7V/Syuzx2cbPRtWsCCCFJOtwVupoKbm1K+axsBLCKc2yHAMeCleo0w93L5R0wpS xaSa7EQRjjg9BFw+iFpumGZjmG3uRWgEQ2KGc+kRm9J8E+tmF2y3Dd9KNlYJc++SgztMsATw5 sXR86/iRlJO8cKYoNlOgpick6m9ZuB6XsFV9xGMCsywoiJP7oPe2yep8yV4hILXBQR74EMyl7 BPboN08a2aFH2AaEHE95koRR+3KX27QNzxxYwK536X5p87SJbfbeEYwDhwSx0osU/xDsOTImQ vnlJEPQiVqrm6IsfcAdw== X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean The current function set_name() used to create short names has the following deficiencies resolved by this patch: * Long names (e.g. FOO.TXT) are stored even if a short name is enough. * Short names with spaces are created, e.g. "A ~1.TXT". * Short names with illegal characters are created, e.g. "FOO++BAR". * Debug output does not not consider that the short file name has no concluding '\0'. The solution for the following bug is split of into a separate patch: * Short file names must be unique. This patch only provides the loop over possible short file names. Fixes: c30a15e590c ("FAT: Add FAT write feature") Signed-off-by: Heinrich Schuchardt --- fs/fat/fat_write.c | 215 +++++++++++++++++++++++++++++---------------- lib/Kconfig | 2 +- 2 files changed, 140 insertions(+), 77 deletions(-) -- 2.29.2 diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c index 4da342f9c9..058b566629 100644 --- a/fs/fat/fat_write.c +++ b/fs/fat/fat_write.c @@ -8,25 +8,140 @@ #include #include #include +#include #include #include #include -#include #include +#include +#include #include #include -#include #include #include "fat.c" -static void uppercase(char *str, int len) +/* Characters that may only be used in long file names */ +static const char LONG_ONLY_CHARS[] = "+,;=[]"; + +/** + * str2fat() - convert string to valid FAT name characters + * + * Stop when reaching end of @src or a period. + * Ignore spaces. + * Replace characters that may only be used in long names by underscores. + * Convert lower case characters to upper case. + * + * To avoid assumptions about the code page we do not use characters + * above 0x7f for the short name. + * + * @dest: destination buffer + * @src: source buffer + * @length: size of destination buffer + * Return: number of bytes in destination buffer + */ +static int str2fat(char *dest, char *src, int length) +{ + int i; + + for (i = 0; i < length; ++src) { + char c = *src; + + if (!c || c == '.') + break; + if (c == ' ') + continue; + if (strchr(LONG_ONLY_CHARS, c) || c > 0x7f) + c = '_'; + else if (c >= 'a' && c <= 'z') + c &= 0xdf; + dest[i] = c; + ++i; + } + return i; +} + +/** + * set_name() - set short name in directory entry + * + * The function determines if the @filename is a valid short name. + * In this case no long name is needed. + * + * If a long name is needed, a short name is constructed. + * + * @dirent: directory entry + * @filename: long file name + * Return: number of directory entries needed, negative on error + */ +static int set_name(dir_entry *dirent, const char *filename) { + char *period; + char *pos; + int period_location; + char buf[13]; int i; - for (i = 0; i < len; i++) { - *str = toupper(*str); - str++; + if (!filename) + return -EIO; + + /* Initialize buffers */ + memset(dirent->name, ' ', sizeof(dirent->name)); + memset(dirent->ext, ' ', sizeof(dirent->ext)); + + /* Convert filename to upper case short name */ + period = strrchr(filename, '.'); + pos = (char *)filename; + if (*pos == '.') { + pos = period + 1; + period = 0; + } + if (period) + str2fat(dirent->ext, period + 1, sizeof(dirent->ext)); + period_location = str2fat(dirent->name, pos, sizeof(dirent->name)); + if (period_location < 0) + return period_location; + if (*dirent->name == ' ') + *dirent->name = '_'; + /* 0xe5 signals a deleted directory entry. Replace it by 0x05. */ + if (*dirent->name == 0xe5) + *dirent->name = 0x05; + + /* If filename and short name are the same, quit. */ + sprintf(buf, "%.*s.%.3s", period_location, dirent->name, dirent->ext); + if (!strcmp(buf, filename)) + return 1; + + /* Construct an indexed short name */ + for (i = 1; i < 0x200000; ++i) { + int suffix_len; + int suffix_start; + int j; + + /* To speed up the search use random numbers */ + if (i < 10) { + j = i; + } else { + j = 30 - fls(i); + j = 10 + (rand() >> j); + } + sprintf(buf, "~%d", j); + suffix_len = strlen(buf); + suffix_start = 8 - suffix_len; + if (suffix_start > period_location) + suffix_start = period_location; + memcpy(dirent->name + suffix_start, buf, suffix_len); + if (*dirent->ext != ' ') + sprintf(buf, "%.*s.%.3s", suffix_start + suffix_len, + dirent->name, dirent->ext); + else + sprintf(buf, "%.*s", suffix_start + suffix_len, + dirent->name); + debug("short name: %s\n", buf); + /* TODO: Check that the short name does not exist yet. */ + + /* Each long name directory entry takes 13 characters. */ + return (strlen(filename) + 25) / 13; } + return -EIO; } static int total_sector; @@ -50,67 +165,6 @@ static int disk_write(__u32 block, __u32 nr_blocks, void *buf) return ret; } -/** - * set_name() - set short name in directory entry - * - * @dirent: directory entry - * @filename: long file name - */ -static void set_name(dir_entry *dirent, const char *filename) -{ - char s_name[VFAT_MAXLEN_BYTES]; - char *period; - int period_location, len, i, ext_num; - - if (filename == NULL) - return; - - len = strlen(filename); - if (len == 0) - return; - - strncpy(s_name, filename, VFAT_MAXLEN_BYTES - 1); - s_name[VFAT_MAXLEN_BYTES - 1] = '\0'; - uppercase(s_name, len); - - period = strchr(s_name, '.'); - if (period == NULL) { - period_location = len; - ext_num = 0; - } else { - period_location = period - s_name; - ext_num = len - period_location - 1; - } - - /* Pad spaces when the length of file name is shorter than eight */ - if (period_location < 8) { - memcpy(dirent->name, s_name, period_location); - for (i = period_location; i < 8; i++) - dirent->name[i] = ' '; - } else if (period_location == 8) { - memcpy(dirent->name, s_name, period_location); - } else { - memcpy(dirent->name, s_name, 6); - /* - * TODO: Translating two long names with the same first six - * characters to the same short name is utterly wrong. - * Short names must be unique. - */ - dirent->name[6] = '~'; - dirent->name[7] = '1'; - } - - if (ext_num < 3) { - memcpy(dirent->ext, s_name + period_location + 1, ext_num); - for (i = ext_num; i < 3; i++) - dirent->ext[i] = ' '; - } else - memcpy(dirent->ext, s_name + period_location + 1, 3); - - debug("name : %s\n", dirent->name); - debug("ext : %s\n", dirent->ext); -} - /* * Write fat buffer into block device */ @@ -1181,13 +1235,15 @@ int file_fat_write_at(const char *filename, loff_t pos, void *buffer, memset(itr->dent, 0, sizeof(*itr->dent)); - /* Calculate checksum for short name */ - set_name(itr->dent, filename); - - /* Set long name entries */ - if (fill_dir_slot(itr, filename)) { - ret = -EIO; + /* Check if long name is needed */ + ret = set_name(itr->dent, filename); + if (ret < 0) goto exit; + if (ret > 1) { + /* Set long name entries */ + ret = fill_dir_slot(itr, filename); + if (ret) + goto exit; } /* Set short name entry */ @@ -1441,9 +1497,16 @@ int fat_mkdir(const char *new_dirname) 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); + /* Check if long name is needed */ + ret = set_name(itr->dent, dirname); + if (ret < 0) + goto exit; + if (ret > 1) { + /* Set long name entries */ + ret = fill_dir_slot(itr, dirname); + if (ret) + goto exit; + } /* Set attribute as archive for regular file */ fill_dentry(itr->fsdata, itr->dent, dirname, 0, 0, diff --git a/lib/Kconfig b/lib/Kconfig index 7673d2e4e0..06eb8d07dc 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -168,7 +168,7 @@ config REGEX choice prompt "Pseudo-random library support type" depends on NET_RANDOM_ETHADDR || RANDOM_UUID || CMD_UUID || \ - RNG_SANDBOX || UT_LIB && AES + RNG_SANDBOX || UT_LIB && AES || FAT_WRITE default LIB_RAND help Select the library to provide pseudo-random number generator From patchwork Sun Nov 29 02:02:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1407771 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.a=rsa-sha256 header.s=badeba3b8450 header.b=jn5pOzVR; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CkBVG0nQsz9sSf for ; Sun, 29 Nov 2020 13:03:34 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A766882750; Sun, 29 Nov 2020 03:03:09 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.b="jn5pOzVR"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C9CCB82779; Sun, 29 Nov 2020 03:02:49 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id B7DCD82745 for ; Sun, 29 Nov 2020 03:02:42 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1606615352; bh=6slALVuFo+Vj9x8vTcJwOaebJ5ALI8gUz1dh9OyDk7M=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=jn5pOzVR0xBZ+2Dsz8/fyiWqhHW3Oj4n3TkNkUBa14AeYKhNFyfqxmeeNtc01SNOF gLZ0dIxozAXoeA/thF7Q+blOYU5e4Dks4Ic/2Qishd6MxjTQW8FIAJXs3yUmxxkKv0 TbuacSXK3q/QUtXKkcHfZHyUQkKxqnSb0nUIUxU0= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from mcbin.fritz.box ([62.143.246.89]) by mail.gmx.com (mrgmx005 [212.227.17.184]) with ESMTPSA (Nemesis) id 1MdvqW-1kAgqE02IY-00b3X9; Sun, 29 Nov 2020 03:02:32 +0100 From: Heinrich Schuchardt To: Tom Rini Cc: Simon Glass , Christian Gmeiner , Jason Wessel , AKASHI Takahiro , Marek Szyprowski , Bin Meng , Reuben Dowle , Marcin Juszkiewicz , Thomas Hebb , Samer El-Haj-Mahmoud , u-boot@lists.denx.de, Heinrich Schuchardt Subject: [PATCH 07/18] fs: fat: pass shortname to fill_dir_slot Date: Sun, 29 Nov 2020 03:02:05 +0100 Message-Id: <20201129020216.4865-8-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201129020216.4865-1-xypron.glpk@gmx.de> References: <20201129020216.4865-1-xypron.glpk@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:FQtfHFInBqRmtFvnRU36V+nDi1NmjpcdSGzITmbQ66eilGEP/yw JWhDjdrOa0BlBh2O10y09TKCpcxqSsYfb2pXoWgdT1gUK+rBu4Rhdwwy3M8x312pQq7oz0r gfWQgtJvo/hJAYfLbBZY6KAI//QYAuJuxBMZ8/uZ1KKBEQKILZOckgH+hlUbVGaaGNLXYDq +Tg7mGgVrX/mqajKBVtzw== X-UI-Out-Filterresults: notjunk:1;V03:K0:O7ogYoU4Q3k=:DkTf2qvHLEBEXBkmTuXs7L V+QMMoI70miG4iCYO6JAKnX+mIUuN59Hvpz3KKzeGfdHD5urLjxUvBog4OP/YV3cU+Dy9nH1o 6ony0WgabsxLru0ruEA+eLqQjAgV749N7K475z45w+S7sc0drLp1Jx03MfcrQgBxM3Ey3Rxq4 CZ3aZRRr8kBKXCxgkmFizSQzqiTT+ZI4YUOXv5duMmFjG1timw82XyQkKxecS+CuCKjR+Nvds rSBqbNh7r1Bg0+l1jJ8/AwBxKHUPZKMtay3jw7NID90ONtEwLya3m1vI3TEYWzcjOoB5HYlUZ lEwvurmP13u2Oa+B8NXTk4d5a3aNED6hzEIUE/xq2dCpLqBxPAw+9UCYUH+k68L3tyvZ7uw8l E/CGOkprR+CrXL/EqE0Ov4cE4XS1/vOiB6PLr6p9g+ryWOXFZMxP9YgGXon648BIH3uA+cdWw lTDIvlHiNIfZBl+LrwBlk8GB1TUSrVO7qLvdudeZex7u3oVIpO+GUao+opS9XsEThJs9SYDYe DYuJA+F4I/oq8YBCY4DBbnzmFIIWBgsHR93nb/V1EBX411zVXN/bFZ/D0D/eQpdrJ641jz8Oa 98UB+dRp5GAjyI+RonpMFBGWuG530e5Ty4zbJ7qKElouH+Fpb8CQLsXDPVXuw/RLdCddGX1h2 8uTmL94AC3S4y8d9vuted5+AZKtMUihLxi7IXuq78EDCY29S/TmQ5a8tJMqQhQbbUKCxkfpWF rOe3XwU1sCjSxfsPX+zBaj2540gQas/6nLxvq6AoYRqCwFOHGakCr7ixt5tuWwcf5bdygSai/ ShEQ4vSDpAQEGpFJ9bHI1WgEOKY47orSISU3YmV6TwKVaXJLQjZuxNNW4YtEKbUA3yTPtK/0y GL15zQbJNnfXEh9prfXQ== X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean Currently we pass the short name via the directory iterator. Pass it explicitly as a parameter. This removes the requirement to set the short name in the iterator before writing the long name. Signed-off-by: Heinrich Schuchardt --- fs/fat/fat_write.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) -- 2.29.2 diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c index 058b566629..7e8886791c 100644 --- a/fs/fat/fat_write.c +++ b/fs/fat/fat_write.c @@ -278,12 +278,16 @@ name11_12: static int new_dir_table(fat_itr *itr); static int flush_dir(fat_itr *itr); -/* - * Fill dir_slot entries with appropriate name, id, and attr - * 'itr' will point to a next entry +/** + * fill_dir_slot() - fill directory entries for long name + * + * @itr: directory iterator + * @l_name: long name + * @shortname: short name + * Return: 0 for success, -errno otherwise */ static int -fill_dir_slot(fat_itr *itr, const char *l_name) +fill_dir_slot(fat_itr *itr, const char *l_name, const char *shortname) { __u8 temp_dir_slot_buffer[MAX_LFN_SLOT * sizeof(dir_slot)]; dir_slot *slotptr = (dir_slot *)temp_dir_slot_buffer; @@ -291,7 +295,7 @@ fill_dir_slot(fat_itr *itr, const char *l_name) int idx = 0, ret; /* Get short file name checksum value */ - checksum = mkcksum(itr->dent->name, itr->dent->ext); + checksum = mkcksum(shortname, shortname + 8); do { memset(slotptr, 0x00, sizeof(dir_slot)); @@ -317,7 +321,7 @@ fill_dir_slot(fat_itr *itr, const char *l_name) if (!fat_itr_next(itr) && !itr->dent) if ((itr->is_root && itr->fsdata->fatsize != 32) || new_dir_table(itr)) - return -1; + return -EIO; } return 0; @@ -1241,7 +1245,7 @@ int file_fat_write_at(const char *filename, loff_t pos, void *buffer, goto exit; if (ret > 1) { /* Set long name entries */ - ret = fill_dir_slot(itr, filename); + ret = fill_dir_slot(itr, filename, itr->dent->name); if (ret) goto exit; } @@ -1503,7 +1507,7 @@ int fat_mkdir(const char *new_dirname) goto exit; if (ret > 1) { /* Set long name entries */ - ret = fill_dir_slot(itr, dirname); + ret = fill_dir_slot(itr, dirname, itr->dent->name); if (ret) goto exit; } From patchwork Sun Nov 29 02:02:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1407782 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.a=rsa-sha256 header.s=badeba3b8450 header.b=aa8ODtgW; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CkBXd49zMz9s0b for ; Sun, 29 Nov 2020 13:05:37 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 06FCA82777; Sun, 29 Nov 2020 03:03:53 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.b="aa8ODtgW"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id EB0D28274A; Sun, 29 Nov 2020 03:03:05 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 7A1BF8275D for ; Sun, 29 Nov 2020 03:02:45 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1606615352; bh=Vw2QIncgvWVmgKYZVyAU270NrPvsrnAonT4ZfFNEfOo=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=aa8ODtgWUDdimgj5eVOZKy64zpg+a00aEAtWeiXWzivkP5PHtY4iXrDKfvlXE6XJl rOmeMPW1O4lLwf7n+l658PNIOLGrqOxyQDrfD3BB01z5AMxxDCB5AWxAn5wt1AweXI tld+IdozSgWxBXdRQ1QNdfdNhk2KkXQkWdpnfs2k= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from mcbin.fritz.box ([62.143.246.89]) by mail.gmx.com (mrgmx005 [212.227.17.184]) with ESMTPSA (Nemesis) id 1Mw9UE-1jthxE2VQC-00s29Z; Sun, 29 Nov 2020 03:02:32 +0100 From: Heinrich Schuchardt To: Tom Rini Cc: Simon Glass , Christian Gmeiner , Jason Wessel , AKASHI Takahiro , Marek Szyprowski , Bin Meng , Reuben Dowle , Marcin Juszkiewicz , Thomas Hebb , Samer El-Haj-Mahmoud , u-boot@lists.denx.de, Heinrich Schuchardt Subject: [PATCH 08/18] fs: fat: call set_name() only once Date: Sun, 29 Nov 2020 03:02:06 +0100 Message-Id: <20201129020216.4865-9-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201129020216.4865-1-xypron.glpk@gmx.de> References: <20201129020216.4865-1-xypron.glpk@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:f6yBLQId+9u9/4mpimJa5zvSOv/wISR3tkMXphtmhXEbFkqNPzj D3AfCgyCSrTFRkd0dSk78lFPBGearLpUDCPq0bNqSM5P7OTAAOKAv7q5M0mW2PN5pGFUWRX u23XoRK1mbFQ2ol4V4mohJjqSqt/L6nVFOGJHaQhBviyrlqoWR07rZ7deU8fLKGRiQ9fMOD j4vQyY3BDCpfwb2Qql63g== X-UI-Out-Filterresults: notjunk:1;V03:K0:D0m3TQ50qPk=:65LbPS0UyWTASM+eI+4hNY GupDZ9JlxLyFC9pEsCjW/VuIUVdpeKie8QwwMYOTrJe2g8VYdVbbpqgxUBWvC+0ezTr9Id10q q7LypmH0Dz0YesuQ+4bvZehkg7d+/6TTEZnJ/DUZKYCPnP2nrI4heyypfZjT8CkBPh7ZbHEde jgvj14ohC9Q4q4qfGs5iWBuoiB0GE29vWXf04lHUObEG7N90ojUvij9JtOCxKrRAF2Homyg6C cE6Qr7u01vbger2rImViR4N88cpgM8o6t/bCJa0PHzhlXmllPzN9TZGC3W4hMxmf8yMRZu5j6 6UFPyA2ZfdLYPoA0Sq9gVbcnM4WUCeTAL2IstTan6vKYwBCIYL0QLPIHt6UXdwweJl6qW/+tC vMi1g9Xo4XRJTnAImUPtIpfadVPoA3ylUDtOXrH2TnHCKm9xlOq4esAV9OqLqZ1Gz5jU8pr8q Iqhyjy8h9HcmPzJLrayfTU+v5Paf9UvBsvpzLJI7mc0xeIsVJ2a4xCl3t2UYIXe2yHD8Zc9fe TapV100s4g/1EsYYE04+MrAU+4wxrvSuIxJzPUzubeOouF5bHYjl7xaScpSw5smhrmwoPH+zA ZIi4FsDYSYJ4ul3FICDDCEL2M2VDajjIQE6Hzf6B2Cbo+AB6GP+nl2rlKPrgcRiw2fPvw7cSN 3ZF0QSz0wZMrDlXvYQ8yQMxsagWzmWtroBl1Nq1t46ZvWis1GnpAEkS91W2F5MMifbLtRKmXz 2GIcg6L7Y6iZc2ZS12hJAOGMfwIbXa7e4Psclas5iCDHXh6eW+8gLhZm8m0ga45ahJQS1pbN2 5wvWBc3ys+9bhtepP5qPaDXpF+Gj0JWaF0OHYa1/jgN7e9G/dvOxveI6mxz6SnDuj5VQxtc66 wn3MrHsaztYveWpL84cw== X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean In set_name() we select the short name. Once this is correctly implemented this will be a performance intensive operation because we need to check that the name does not exist yet. So set_name should only be called once. Signed-off-by: Heinrich Schuchardt --- fs/fat/fat_write.c | 87 ++++++++++++++++++++++++++++------------------ 1 file changed, 54 insertions(+), 33 deletions(-) -- 2.29.2 diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c index 7e8886791c..716b6a6627 100644 --- a/fs/fat/fat_write.c +++ b/fs/fat/fat_write.c @@ -23,6 +23,9 @@ /* Characters that may only be used in long file names */ static const char LONG_ONLY_CHARS[] = "+,;=[]"; +/* Combined size of the name and ext fields in the directory entry */ +#define SHORT_NAME_SIZE 11 + /** * str2fat() - convert string to valid FAT name characters * @@ -68,24 +71,28 @@ static int str2fat(char *dest, char *src, int length) * * If a long name is needed, a short name is constructed. * - * @dirent: directory entry * @filename: long file name + * @shortname: buffer of 11 bytes to receive chosen short name and extension * Return: number of directory entries needed, negative on error */ -static int set_name(dir_entry *dirent, const char *filename) +static int set_name(const char *filename, char *shortname) { char *period; char *pos; int period_location; char buf[13]; int i; + int ret; + struct { + char name[8]; + char ext[3]; + } dirent; if (!filename) return -EIO; - /* Initialize buffers */ - memset(dirent->name, ' ', sizeof(dirent->name)); - memset(dirent->ext, ' ', sizeof(dirent->ext)); + /* Initialize buffer */ + memset(&dirent, ' ', sizeof(dirent)); /* Convert filename to upper case short name */ period = strrchr(filename, '.'); @@ -95,20 +102,22 @@ static int set_name(dir_entry *dirent, const char *filename) period = 0; } if (period) - str2fat(dirent->ext, period + 1, sizeof(dirent->ext)); - period_location = str2fat(dirent->name, pos, sizeof(dirent->name)); + str2fat(dirent.ext, period + 1, sizeof(dirent.ext)); + period_location = str2fat(dirent.name, pos, sizeof(dirent.name)); if (period_location < 0) return period_location; - if (*dirent->name == ' ') - *dirent->name = '_'; + if (*dirent.name == ' ') + *dirent.name = '_'; /* 0xe5 signals a deleted directory entry. Replace it by 0x05. */ - if (*dirent->name == 0xe5) - *dirent->name = 0x05; + if (*dirent.name == 0xe5) + *dirent.name = 0x05; /* If filename and short name are the same, quit. */ - sprintf(buf, "%.*s.%.3s", period_location, dirent->name, dirent->ext); - if (!strcmp(buf, filename)) - return 1; + sprintf(buf, "%.*s.%.3s", period_location, dirent.name, dirent.ext); + if (!strcmp(buf, filename)) { + ret = 1; + goto out; + } /* Construct an indexed short name */ for (i = 1; i < 0x200000; ++i) { @@ -128,20 +137,24 @@ static int set_name(dir_entry *dirent, const char *filename) suffix_start = 8 - suffix_len; if (suffix_start > period_location) suffix_start = period_location; - memcpy(dirent->name + suffix_start, buf, suffix_len); - if (*dirent->ext != ' ') + memcpy(dirent.name + suffix_start, buf, suffix_len); + if (*dirent.ext != ' ') sprintf(buf, "%.*s.%.3s", suffix_start + suffix_len, - dirent->name, dirent->ext); + dirent.name, dirent.ext); else sprintf(buf, "%.*s", suffix_start + suffix_len, - dirent->name); + dirent.name); debug("short name: %s\n", buf); /* TODO: Check that the short name does not exist yet. */ /* Each long name directory entry takes 13 characters. */ - return (strlen(filename) + 25) / 13; + ret = (strlen(filename) + 25) / 13; + goto out; } return -EIO; +out: + memcpy(shortname, dirent.name, SHORT_NAME_SIZE); + return ret; } static int total_sector; @@ -1019,18 +1032,27 @@ getit: return 0; } -/* - * Fill dir_entry +/** + * fill_dentry() - fill directory entry with shortname + * + * @mydata: private filesystem parameters + * @dentptr: directory entry + * @shortname: chosen short name + * @start_cluster: first cluster of file + * @size: file size + * @attr: file attributes */ static void fill_dentry(fsdata *mydata, dir_entry *dentptr, - const char *filename, __u32 start_cluster, __u32 size, __u8 attr) + const char *shortname, __u32 start_cluster, __u32 size, __u8 attr) { + memset(dentptr, 0, sizeof(*dentptr)); + set_start_cluster(mydata, dentptr, start_cluster); dentptr->size = cpu_to_le32(size); dentptr->attr = attr; - set_name(dentptr, filename); + memcpy(dentptr->name, shortname, SHORT_NAME_SIZE); } /* @@ -1215,6 +1237,7 @@ int file_fat_write_at(const char *filename, loff_t pos, void *buffer, retdent->size = cpu_to_le32(pos + size); } else { /* Create a new file */ + char shortname[SHORT_NAME_SIZE]; if (itr->is_root) { /* root dir cannot have "." or ".." */ @@ -1237,21 +1260,19 @@ int file_fat_write_at(const char *filename, loff_t pos, void *buffer, goto exit; } - memset(itr->dent, 0, sizeof(*itr->dent)); - /* Check if long name is needed */ - ret = set_name(itr->dent, filename); + ret = set_name(filename, shortname); if (ret < 0) goto exit; if (ret > 1) { /* Set long name entries */ - ret = fill_dir_slot(itr, filename, itr->dent->name); + ret = fill_dir_slot(itr, filename, shortname); if (ret) goto exit; } /* Set short name entry */ - fill_dentry(itr->fsdata, itr->dent, filename, 0, size, + fill_dentry(itr->fsdata, itr->dent, shortname, 0, size, ATTR_ARCH); retdent = itr->dent; @@ -1484,6 +1505,8 @@ int fat_mkdir(const char *new_dirname) ret = -EEXIST; goto exit; } else { + char shortname[SHORT_NAME_SIZE]; + if (itr->is_root) { /* root dir cannot have "." or ".." */ if (!strcmp(l_dirname, ".") || @@ -1499,21 +1522,19 @@ int fat_mkdir(const char *new_dirname) goto exit; } - memset(itr->dent, 0, sizeof(*itr->dent)); - /* Check if long name is needed */ - ret = set_name(itr->dent, dirname); + ret = set_name(dirname, shortname); if (ret < 0) goto exit; if (ret > 1) { /* Set long name entries */ - ret = fill_dir_slot(itr, dirname, itr->dent->name); + ret = fill_dir_slot(itr, dirname, shortname); if (ret) goto exit; } /* Set attribute as archive for regular file */ - fill_dentry(itr->fsdata, itr->dent, dirname, 0, 0, + fill_dentry(itr->fsdata, itr->dent, shortname, 0, 0, ATTR_DIR | ATTR_ARCH); retdent = itr->dent; From patchwork Sun Nov 29 02:02:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1407780 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.a=rsa-sha256 header.s=badeba3b8450 header.b=Xg2sn1Ea; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CkBXG17MXz9s0b for ; Sun, 29 Nov 2020 13:05:18 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6C11B82797; Sun, 29 Nov 2020 03:03:49 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.b="Xg2sn1Ea"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5683A82749; Sun, 29 Nov 2020 03:03:01 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 19C7982753 for ; Sun, 29 Nov 2020 03:02:45 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1606615353; bh=OGL69GBI266oI5B0G1LbAbZRXYWdzjB+rT9VF9xIan0=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=Xg2sn1EapiIl6UMhMcWPl4+v/ovseQblciBoBIGe5Gbiow8NPCEXxDBi0fkr+IlKa opJN0P+h4oZKRvk3qqNEvmvKOj7hq3cWuS6z/qJWjO4zsj2LVfPlN/urp1N2qmt8CY OxdnpRSSlHdi7ls27WvX0FCvEbKg3CW+JOpQMD24= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from mcbin.fritz.box ([62.143.246.89]) by mail.gmx.com (mrgmx005 [212.227.17.184]) with ESMTPSA (Nemesis) id 1MtfJd-1jv5nS0jnz-00v4QE; Sun, 29 Nov 2020 03:02:33 +0100 From: Heinrich Schuchardt To: Tom Rini Cc: Simon Glass , Christian Gmeiner , Jason Wessel , AKASHI Takahiro , Marek Szyprowski , Bin Meng , Reuben Dowle , Marcin Juszkiewicz , Thomas Hebb , Samer El-Haj-Mahmoud , u-boot@lists.denx.de, Heinrich Schuchardt Subject: [PATCH 09/18] fs: fat: generate unique short names Date: Sun, 29 Nov 2020 03:02:07 +0100 Message-Id: <20201129020216.4865-10-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201129020216.4865-1-xypron.glpk@gmx.de> References: <20201129020216.4865-1-xypron.glpk@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:A6tUyZDEOfraRZkq6qkFa4219TcfM9bOZiTiXXUqaHh9eju+YXJ v2qBugzecskMKugkAsf3EtVHxDdZ40LJ+Tp8hnTgBiN3bGdg6vsPTX0evZdTA0wHxZiqtx3 IPAwiZecYB+nQ3not2oT108+mnr4GAdFKPtnOqAl6ff1+EZ303vN5o+60RH22xuyQVxSY/Z bsKxuiCgw9LjXEOJtecPg== X-UI-Out-Filterresults: notjunk:1;V03:K0:McrmyWWl/Q8=:ED1r2zIV9lE+JBppUphDjy VNa3HykaPFf72pTXapMmha+toV5PF9f1JqNaEwcymkKmna820/nEpDm8wsoQMBGJbJo59SkWV lk7zKPdp48123PT86j8XzibcPfWjOpLgF0cdk8X1eKBnA56CF3ZihWaD+Fj5V+xbX+yX8odJ+ p1Ma6nKFqgCc/SKfxa+pnU8XK2lby3m9zJxnO9mxsprPAvjq2GylYWlhFUlQXezmPDoidaI3v Ktunfl+N8yCq3Gq7JScoqkOEsx+3vWXjAC3Z8pljHoEvks8fEMZMKDrfc0Nrwm0TA+1j3TmyS UY7M5LwxN9C9ss/lDCPml/hWeziH+Oidfcr9Epr7jcvbKwrB1Rs1JM6lDhcpRktxiafFZHFLG TUoxREGEl7GiL9ByTIlk/I2gkpGqnINxLyF39SwBpZiNOiteDpSvRwycSCJMNZ4ixm4M70vPq N/ZpENRukg4aYvUduRtn8UsPmpPxlX3Duh9jEsOu2DaGya4AHpm+QSYwTSQ+ZXT7rZbRGF2EP 4ZMQEJP58uYNv0WVmWdhbkrs/r7Um6i4WRMP544hO+jOJf3sgG371MRG7svL2jUXEo+6+eGkO z4pxAEOFt9/XlGIX/vnCbm2290l359ibC8iOwPxRIxPIm0ZrhHXyAgwJM0o+JboxXGXTF2QR1 FOzTsjQOGU5PAPFECyZJC7Y4Bnz+G7xJHnEH8T1vzqaNabQG/mEL/pZs5aovuqCjqvDCPTu3U 4QcZI5deiUJ3qof9zXTBuzjoYidN2gQG7LDL3j2sCOygAsPB2z1zSOMugD/rMSAhTFIRfVzmU eQPm7a62NVibnKhihOkIMwroi0ml+U1EgtB2OiJj+3E2H6YOvMQ3DuCJ3OJH9SEMdn4o6q0/R EUdA1ksf41/ZzJmrMZNg== X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean File names must be unique within their directory. So before assigning a short name we must check that it is unique. Signed-off-by: Heinrich Schuchardt --- fs/fat/fat_write.c | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) -- 2.29.2 diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c index 716b6a6627..59cffef34e 100644 --- a/fs/fat/fat_write.c +++ b/fs/fat/fat_write.c @@ -20,6 +20,8 @@ #include #include "fat.c" +static dir_entry *find_directory_entry(fat_itr *itr, char *filename); + /* Characters that may only be used in long file names */ static const char LONG_ONLY_CHARS[] = "+,;=[]"; @@ -63,6 +65,27 @@ static int str2fat(char *dest, char *src, int length) return i; } +/** + * fat_move_to_cluster() - position to first directory entry in cluster + * + * @itr: directory iterator + * @cluster cluster + * Return: 0 for success, -EIO on error + */ +static int fat_move_to_cluster(fat_itr *itr, unsigned int cluster) +{ + unsigned int nbytes; + + /* position to the start of the directory */ + itr->next_clust = cluster; + itr->last_cluster = 0; + if (!fat_next_cluster(itr, &nbytes)) + return -EIO; + itr->dent = (dir_entry *)itr->block; + itr->remaining = nbytes / sizeof(dir_entry) - 1; + return 0; +} + /** * set_name() - set short name in directory entry * @@ -71,11 +94,12 @@ static int str2fat(char *dest, char *src, int length) * * If a long name is needed, a short name is constructed. * + * @itr: directory iterator * @filename: long file name * @shortname: buffer of 11 bytes to receive chosen short name and extension * Return: number of directory entries needed, negative on error */ -static int set_name(const char *filename, char *shortname) +static int set_name(fat_itr *itr, const char *filename, char *shortname) { char *period; char *pos; @@ -144,9 +168,16 @@ static int set_name(const char *filename, char *shortname) else sprintf(buf, "%.*s", suffix_start + suffix_len, dirent.name); - debug("short name: %s\n", buf); - /* TODO: Check that the short name does not exist yet. */ + debug("generated short name: %s\n", buf); + + /* Check that the short name does not exist yet. */ + ret = fat_move_to_cluster(itr, itr->start_clust); + if (ret) + return ret; + if (find_directory_entry(itr, buf)) + continue; + debug("chosen short name: %s\n", buf); /* Each long name directory entry takes 13 characters. */ ret = (strlen(filename) + 25) / 13; goto out; @@ -1261,7 +1292,7 @@ int file_fat_write_at(const char *filename, loff_t pos, void *buffer, } /* Check if long name is needed */ - ret = set_name(filename, shortname); + ret = set_name(itr, filename, shortname); if (ret < 0) goto exit; if (ret > 1) { @@ -1523,7 +1554,7 @@ int fat_mkdir(const char *new_dirname) } /* Check if long name is needed */ - ret = set_name(dirname, shortname); + ret = set_name(itr, dirname, shortname); if (ret < 0) goto exit; if (ret > 1) { From patchwork Sun Nov 29 02:02:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1407775 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.a=rsa-sha256 header.s=badeba3b8450 header.b=PnOt4YPv; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CkBWC1SHmz9sSf for ; Sun, 29 Nov 2020 13:04:23 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8656C8278F; Sun, 29 Nov 2020 03:03:20 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.b="PnOt4YPv"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7253382749; Sun, 29 Nov 2020 03:02:53 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id BCF968274E for ; Sun, 29 Nov 2020 03:02:43 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1606615353; bh=zPd9/fSzNQ39WR7MnOA3pd76M547aXsyDDCrym0++VE=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=PnOt4YPvxp1iSopltqRT7aP3Kc+FMMZhZZn8rVTW6F4VKjr8D6qeVTy7qE9PfrX+I 3iyUbg/2HDiOyBCnEco8oPD2GtxAHuoEM8ADd9CLB6wQiRVkOFHCQCqyssZztmhL0a XtIoHDemtElwH6xDDN6ASc8gwCoL/u8KKya+tNRw= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from mcbin.fritz.box ([62.143.246.89]) by mail.gmx.com (mrgmx005 [212.227.17.184]) with ESMTPSA (Nemesis) id 1MnakR-1kJnNU2tK1-00jc6a; Sun, 29 Nov 2020 03:02:33 +0100 From: Heinrich Schuchardt To: Tom Rini Cc: Simon Glass , Christian Gmeiner , Jason Wessel , AKASHI Takahiro , Marek Szyprowski , Bin Meng , Reuben Dowle , Marcin Juszkiewicz , Thomas Hebb , Samer El-Haj-Mahmoud , u-boot@lists.denx.de, Heinrich Schuchardt Subject: [PATCH 10/18] fs: fat: dentry iterator for fill_dir_slot() Date: Sun, 29 Nov 2020 03:02:08 +0100 Message-Id: <20201129020216.4865-11-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201129020216.4865-1-xypron.glpk@gmx.de> References: <20201129020216.4865-1-xypron.glpk@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:Lik4y9+6j1U6QrEvUDtXlfgk2z0qZil5o9YgV6H5ROY80PWmFFb n2t/npcVSI5k+CdmuyTtFCyFyIrIRW0scrNXkLjw/kvPKEGudWh3xxJ+DrpPj96EyY02SHg 0iqCEoiS9NuezE0LJdqjikOWLG6JVTpjIMhc74riPF3f7gK+5E2geJtKJw4J3eKG67fYpuw 9nKb1XfeFrXtDzBAz5Rpg== X-UI-Out-Filterresults: notjunk:1;V03:K0:BXuAW9hAPio=:EPLvCkhQYD1jqNM3NRAR49 XCW3e5EeFJZMbG0A+iNM0ltayPqutGiGDJqAa4DDg7Mj3iltkfHZ0xie2yUEXzSakVlwtstdH VSrDG/5tRbBVnSO3gsGnNZmBWyO9TfQ99yWxvqMaTL0YGcZPflfyVQxUe5IoBs7bKzqbnKwDC xETl1ZECendiYYa7ssPa+PVmZrKoLzBY5pVNSQ+Z1AYi3XhCrfvjaTn7QxXxEhqPiCPsbtAUp 1pWZyC2/cQ8v+cp6nrOolkmLOrEARjOEB5L8USWiHfuFAQkaHQebVDJVFTBEML5JvN0V7l/TH SJxp4QbGbkzmrgCdRR6Gj8ZtfNKAKpnzHiQpkar8oLPGX8xsiSbg5C+vzfXidOEP5w1We+s94 qI57wvK8vXHMms5oGv0K6enlMiRYwcoVcC6xZgKsQG5BgX6hw07A9bnb/YWLZuvaVPHQk5D0b ar0+kttkwak4gHQeT38WiKbFQSMn6i+VR9FbicEN4D1s/zaooTEpq8tj3RJksaHHM4qwGHmHQ RzEePR2QJ1nTPL4zZDqYL7Mn4NcSeMUi++XHjwYLlu7ahz2IzDOrM1m7Xt8Mf2ALmoQ95Lcp2 0DHG+JXDnSJDt4lVjct7HAqa9j/hNY7Kvjyz0c5FQbLcputc5hgrQXbIhWt82g3z9rqTmQ0ac APczeF7iiS9A2TGKsOihbKb8U42HhoQYsKuRUEMccPkDV1PDLTVGHyTc0k4Sdmo8X0ruCMn6c TWtGQ4GqjbVgAlMeTu8kZCaTzFd+Acc3vJheQwHGqU+6k2lgpEtTjzFiREBjR33w0ZqFo67Oq rMGE3YkkUkEbSwzr4V6CQcQAT+ZMSvxzwyRTsfejtnUv4QMF24dKc2Me2sfQUYL41OPxxqt0h i3J1In/Jytn8t47NXDMQ== X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean For reusing deleted directory entries we have to adjust the function called to step to the next directory entry. This patch alone is not enough to actually reuse deleted directory entries as the fill_dir_slot() is still called with first never used directory entry. Signed-off-by: Heinrich Schuchardt --- fs/fat/fat_write.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.29.2 diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c index 59cffef34e..0746d73f8d 100644 --- a/fs/fat/fat_write.c +++ b/fs/fat/fat_write.c @@ -362,7 +362,7 @@ fill_dir_slot(fat_itr *itr, const char *l_name, const char *shortname) flush_dir(itr); /* allocate a cluster for more entries */ - if (!fat_itr_next(itr) && !itr->dent) + if (!next_dent(itr) && !itr->dent) if ((itr->is_root && itr->fsdata->fatsize != 32) || new_dir_table(itr)) return -EIO; From patchwork Sun Nov 29 02:02:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1407778 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.a=rsa-sha256 header.s=badeba3b8450 header.b=lTNWKUrj; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CkBWs2sRDz9sSf for ; Sun, 29 Nov 2020 13:04:57 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 16D108274E; Sun, 29 Nov 2020 03:03:45 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.b="lTNWKUrj"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E71DC8274A; Sun, 29 Nov 2020 03:02:59 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 402A582754 for ; Sun, 29 Nov 2020 03:02:45 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1606615354; bh=7JDpDkddGAvF/p7nJkZP9HQEphRYUfT5SK88R2OSOS8=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=lTNWKUrjT0M39KbKD+Dy6FjwNQIYYUH2WVAkfiK543xQTH03qo4vT1ReA2UUNhiQV BRjQMMJBJIkpgDxz9SBmYjQ7MkDUd+3rMN3AFeMrzG9t7Jm9Bqw5FdXZUJMS1i/BiT Blrc/HgoY9GaSHNp22tKE1LwRi7zhtGM3jJeEEnI= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from mcbin.fritz.box ([62.143.246.89]) by mail.gmx.com (mrgmx005 [212.227.17.184]) with ESMTPSA (Nemesis) id 1MwwZd-1jyPB30jsJ-00yOLW; Sun, 29 Nov 2020 03:02:34 +0100 From: Heinrich Schuchardt To: Tom Rini Cc: Simon Glass , Christian Gmeiner , Jason Wessel , AKASHI Takahiro , Marek Szyprowski , Bin Meng , Reuben Dowle , Marcin Juszkiewicz , Thomas Hebb , Samer El-Haj-Mahmoud , u-boot@lists.denx.de, Heinrich Schuchardt Subject: [PATCH 11/18] fs: fat: set start cluster for root directory Date: Sun, 29 Nov 2020 03:02:09 +0100 Message-Id: <20201129020216.4865-12-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201129020216.4865-1-xypron.glpk@gmx.de> References: <20201129020216.4865-1-xypron.glpk@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:QfdIvUUuu6tFl0tPV++TqPj5/RPc/tUYsO1T2jJkl8Q6N1QR04W iDBTR91fCued6emxkKT0VEXzfzNMtmJhln6eKPHa9uBDqNKTnNOaPZ4HeQZ2CBK1nkgIY5d 2Nomo9CtAXWLBt9QqZNUk00U5g4M2RjSOwczTn0Ec4m7HynlRowUdPJe3sNAM/R4SP/OK34 CSNGO4jacBIxVqbpphBnA== X-UI-Out-Filterresults: notjunk:1;V03:K0:NiNsBCQoUuY=:QIzlPZgE0WBDXCwUSNdiF4 NhIoviHMzGyVnWPlAdOCZUy1ZwlcTCXwkaKSXEPToI16dKFZNlNZhxVrN0BA59EGp91cZRRuH kx/5A902fkPcY+rXuMW0K/9upi03S5LsagwDZ0Ld2Y9IGHVFGJgKAUXPjyketIWWoSejKoitg uSh+VJk3Pxa19nF8QmB31/hrJy0qnYjl0acClD/uYpJqQ5S+HifDGRx/7ETOGEM+TQ8A/lyxx +Wx/RMWc6+XydDTX8x+ZN/0bJ7pt77LvMVf4aaqcZYb6Lw3lxgUYsFIPjWFjwIXvtcrnxekiN a7X40ZqqJ5PXOS5dkW6HXJzClPqO6fdDPIjJzjHRju90DQ/vRtCNlZ6UWYVdBuOimF/wPkOxf icN3VJB7ghZb9yNr758zQJfwXOu+GoPcJwYzFFS01K8omXSvRKG15GQQh+0NHiD2geDOjMZ68 lVwJiUHo7ONk82VZp5TfmgeivDqFoGUW2m/LpIr0mwVEqsl7nD2EjgW9v4O5owPweJP6OMBrB 1WW8zbQwzBzgjXDT13W3jgucrt3UgkLl4HbGBuOOm3zuUHqkQqzYCBDAPvN58Z5GnCkTPIU6y lZo+N/MRPU7ljkwqiYIKbLJZ6U+hPCvS0cN5e5oT5xU+91s2w9rgX+rbic6Wubb1TspJr5f9w DfJbdydPki3DeS2zOc6SxOd2CiOQcW1aTK8Bw4OPIBHObR23zzRCodhLizDi3WkEj2tFg+OBP X91HHImU3iRxMOymquP4Y1MuVzftcBFtTlDX0n9dScvbMryJchEkaajL/hdmFrGJI8rQ8argQ GSTFuGhCmNt37bhMwPG4SICNs6RzTlqEIXZSeZlYbQOI4xwCKOGFnoNmIMVDHBLPla5Famr+h pgVO6P6Qq1DwouhxwHdA== X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean When iterating over a child directory we set itr->start_clust. Do the same when over the root directory. When looking for deleted directory entries or existing short names we will have to iterate over directories a second and third time. With this patch we do not need any special logic for the root directory. Signed-off-by: Heinrich Schuchardt --- fs/fat/fat.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) -- 2.29.2 diff --git a/fs/fat/fat.c b/fs/fat/fat.c index 674236d68a..5a418cfbb7 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -734,7 +734,7 @@ static int fat_itr_root(fat_itr *itr, fsdata *fsdata) return -ENXIO; itr->fsdata = fsdata; - itr->start_clust = 0; + itr->start_clust = fsdata->root_cluster; itr->clust = fsdata->root_cluster; itr->next_clust = fsdata->root_cluster; itr->dent = NULL; @@ -778,6 +778,7 @@ static void fat_itr_child(fat_itr *itr, fat_itr *parent) } else { itr->clust = parent->fsdata->root_cluster; itr->next_clust = parent->fsdata->root_cluster; + itr->start_clust = parent->fsdata->root_cluster; itr->is_root = 1; } itr->dent = NULL; @@ -1067,6 +1068,7 @@ static int fat_itr_resolve(fat_itr *itr, const char *path, unsigned type) /* point back to itself */ itr->clust = itr->fsdata->root_cluster; itr->next_clust = itr->fsdata->root_cluster; + itr->start_clust = itr->fsdata->root_cluster; itr->dent = NULL; itr->remaining = 0; itr->last_cluster = 0; From patchwork Sun Nov 29 02:02:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1407776 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.a=rsa-sha256 header.s=badeba3b8450 header.b=HwgTIqGm; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CkBWQ6h1Kz9sSf for ; Sun, 29 Nov 2020 13:04:34 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6D0B382798; Sun, 29 Nov 2020 03:03:22 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.b="HwgTIqGm"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 98BC182750; Sun, 29 Nov 2020 03:02:57 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id BEF3482750 for ; Sun, 29 Nov 2020 03:02:43 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1606615354; bh=/rZzV6KyNMDRKg6tEOMyFK40orgSgAobqHCMvEnCkEY=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=HwgTIqGmTBJ+5k88sFjHIjRheNilQX7LaFy7TcDIhUtBwj4EdAuejGuP7MZfV/SpF o1keTJbMSuzQ3wgL3Tgh0NqJBC7178eYoiLFmRd48yWn8yuh92PKnZHRdkMsZUSbJS wR6Wq5XhSb9VN0nTM/4dhUkhvpIMPK7IZzDZkfuE= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from mcbin.fritz.box ([62.143.246.89]) by mail.gmx.com (mrgmx005 [212.227.17.184]) with ESMTPSA (Nemesis) id 1MbzuH-1kCceD2riZ-00dXZS; Sun, 29 Nov 2020 03:02:34 +0100 From: Heinrich Schuchardt To: Tom Rini Cc: Simon Glass , Christian Gmeiner , Jason Wessel , AKASHI Takahiro , Marek Szyprowski , Bin Meng , Reuben Dowle , Marcin Juszkiewicz , Thomas Hebb , Samer El-Haj-Mahmoud , u-boot@lists.denx.de, Heinrich Schuchardt Subject: [PATCH 12/18] fs: fat: flush new directory cluster Date: Sun, 29 Nov 2020 03:02:10 +0100 Message-Id: <20201129020216.4865-13-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201129020216.4865-1-xypron.glpk@gmx.de> References: <20201129020216.4865-1-xypron.glpk@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:akaMEyoknLBzfn8elOMBSl37BYLo/9tfFgj9DQNTEW1xYLJxEkh rPU0rTRAtv8tvzeE20rcxeQoG/6gKD9Ev8qaziHApcosUi3txqs2drHJELjCPG5AJ69umOg kxiyxTe+CdjfNph+ytBj0n7O5Muzoxf4Vov+loi0i/da/mIaO9k02Htb5512alIG7qgsoa4 a0GyjA4+K46nX58BOqNGA== X-UI-Out-Filterresults: notjunk:1;V03:K0:AApAhb0zRUY=:li8B/o8phVmlJjJ5AX8c1D vvDx61JLlQuP7MRkpIOh7944eBIqaTuhw4IyOZzu/QOVSEq5XJ06xt1qGG5mnKWugcQpL7B7T 9vA1pH+/AJYmtnqf70fVP07KyrljJudpzl+24egsxunkw3TuIiAdve5E6SSc1KD4VEHNgTw// QLKe1shRPksC8AX7rtrNRRoQFgC6gU6bP0iLOnbCUxu9HfEP/IuYzVP9bb9oIp1UHDEYOczQP khmwHT8hjjf8LyZMGTC9ziM+UwaIA5Ne/cnYKbyw13TVCbMq8EQqHLPxBXsXuzI+3f6dbiIh7 53ZQCQ9YuEXmvdWWuPJKXwvEuN2ehdfMNQc6rmXsgjNGR2JXnGRVTjny52mzATo1wxEVRUSc0 hDj2i8cifdPSp6p6itGEuDhFSmEoAUPJCyLdlMdnMbT4seasKltHyqCsjUWiEFumqjRz1HLr2 VnYkxjQSXFEdNMiHEopJ1OhTMwFUHcke+ElxIoPEqeO4RhT7ohOMSvm8FPFFPJ0ueeLZOHJ/W wsrRiJLTfVj/FEehK7QvLwpf+U68ZBrKW6a7s79VE6Ub3V3Wvx1zJ1rQ9nyLayheugc3IqUDx zd5+6A03E9XnjHhs0YS7bE4WcqWzv9hE90tVxhyzw+9N2OPhZCqfEP5MVhrlyu4WOUGJNpEsp bn8/uv97o6AKHrcNL5EhCdLn/08rwWxpmE8R8sKs3m20AzJ7te5e1Im2aNMnYM516aX32KJJu O46w++A3sBLJy4BSwSstW+To2gmuOGs6gdKa4n+sfblnz+Aby+giH6qRTyV8IL+gdCHEAk8NI F0+RyALoWHqjBtQbMPwzUQKEpNKREwAeAQFM5cVOcJ13nlZeuCnIYLok3r5Im+ksu+Jz0MLWw gVItOhsyo0eyvxl7+5xw== X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean When handling long file names directory entries may be split over multiple clusters. We must make sure that new clusters are zero filled on disk. When allocating a new cluster for a directory flush it. The flushing should be executed before updating the FAT. This way if flushing fails, we still have a valid directory structure. Signed-off-by: Heinrich Schuchardt --- fs/fat/fat_write.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) -- 2.29.2 diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c index 0746d73f8d..941f8789ab 100644 --- a/fs/fat/fat_write.c +++ b/fs/fat/fat_write.c @@ -738,17 +738,32 @@ static int find_empty_cluster(fsdata *mydata) return entry; } -/* - * Allocate a cluster for additional directory entries +/** + * new_dir_table() - allocate a cluster for additional directory entries + * + * @itr: directory iterator + * Return: 0 on success, -EIO otherwise */ static int new_dir_table(fat_itr *itr) { fsdata *mydata = itr->fsdata; int dir_newclust = 0; + int dir_oldclust = itr->clust; unsigned int bytesperclust = mydata->clust_size * mydata->sect_size; dir_newclust = find_empty_cluster(mydata); - set_fatent_value(mydata, itr->clust, dir_newclust); + + /* + * Flush before updating FAT to ensure valid directory structure + * in case of failure. + */ + itr->clust = dir_newclust; + itr->next_clust = dir_newclust; + memset(itr->block, 0x00, bytesperclust); + if (flush_dir(itr)) + return -EIO; + + set_fatent_value(mydata, dir_oldclust, dir_newclust); if (mydata->fatsize == 32) set_fatent_value(mydata, dir_newclust, 0xffffff8); else if (mydata->fatsize == 16) @@ -756,13 +771,8 @@ static int new_dir_table(fat_itr *itr) else if (mydata->fatsize == 12) set_fatent_value(mydata, dir_newclust, 0xff8); - itr->clust = dir_newclust; - itr->next_clust = dir_newclust; - if (flush_dirty_fat_buffer(mydata) < 0) - return -1; - - memset(itr->block, 0x00, bytesperclust); + return -EIO; itr->dent = (dir_entry *)itr->block; itr->last_cluster = 1; From patchwork Sun Nov 29 02:02:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1407781 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.a=rsa-sha256 header.s=badeba3b8450 header.b=Gdt46nLH; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CkBXS1sKYz9s0b for ; Sun, 29 Nov 2020 13:05:28 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 84C12827AB; Sun, 29 Nov 2020 03:03:51 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.b="Gdt46nLH"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 487B382754; Sun, 29 Nov 2020 03:03:04 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 838CB82761 for ; Sun, 29 Nov 2020 03:02:45 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1606615355; bh=mOM5OCjdGrWsaTHb3jm38+XX+01Eb9llLr8orxfTWD0=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=Gdt46nLH7DgOHL3gkBGVTks3M7iE4wwGefmFEsA4EbgWb0sqGyqB+Yo04fgPeL59A cldav2/Tgc7aoyjK0AcovFD6hdvS+LPZZ+Y4xjjkkCTK5HaV+SfSR0euJGbypiciIK efIiZX6uz67P/EqRKUKB8a8JE3sj31fcpt6wlvDg= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from mcbin.fritz.box ([62.143.246.89]) by mail.gmx.com (mrgmx005 [212.227.17.184]) with ESMTPSA (Nemesis) id 1MJVHe-1kTs7H0kdU-00JoKT; Sun, 29 Nov 2020 03:02:35 +0100 From: Heinrich Schuchardt To: Tom Rini Cc: Simon Glass , Christian Gmeiner , Jason Wessel , AKASHI Takahiro , Marek Szyprowski , Bin Meng , Reuben Dowle , Marcin Juszkiewicz , Thomas Hebb , Samer El-Haj-Mahmoud , u-boot@lists.denx.de, Heinrich Schuchardt Subject: [PATCH 13/18] fs: fat: fat_find_empty_dentries() Date: Sun, 29 Nov 2020 03:02:11 +0100 Message-Id: <20201129020216.4865-14-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201129020216.4865-1-xypron.glpk@gmx.de> References: <20201129020216.4865-1-xypron.glpk@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:HsodJm0jw53Ey2te7aYqi7zKCcqwAu0G/w4Ui/4eSK2Sr4qfjFy 1aqsP1SRFSZHVBmpa6pIQuohff7GNwvL95UgXc2k3iGv63S2nFiyFb89MP4Taso5uF4saP9 JXV+bvt0DZUV0OqiOb5rvb1008p10tHpehD7ZUdN0bhkXW2U7Z1PTRKYHATRQiuGScqp3J+ H3QlUZk3N2Pfz3CD5IWcQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:gWK6vxMAYt8=:osM107KcMzQcUUXC8fK+4A cmF5o+KxIOmPC49Oz3d46AWByz5rs3OFyMb2wVkdd/yDCx3OEhhcGW46Q98M0V1TpdsTEzTGz 0XeUnEKHxKRUGxLRRu6FrK2OyDRuC3HhJpP2zFUnMZtGfhZg2r0NcRBPLV5z1ITVTeD0V3Bze oO0MybmnYeO95WjsRpa+fEUfRLplNeuins/cJ4FPufGoQiu97QdI8eAGGnqZTzXKbCC/4RHti 4AQ42D0OJvCWbnrwWEE++Nf2VOiceHp8hntuqmcLNEWjut5hCll5w6OfFeFxVG0AFYzGHrK+S ecO8gQrvyCJo0ltcyOkqTL/1tQEqRxg4kEbQJhmuUI5oYwQhEVd3Wzl7kkcmLuNZz+iRAFrPU ZQcJRUAygSsuF6lEjF//6zl799KZ92T+/yC+dqKuhhKy6t/mwQSbxOChVf22pZHTQKSOJCISr 2BP6DEexkH1Y2jCKMo1KE3Anu537Ob7NMdqSaJlpWXE2CguunNlV+MA8q3j4BZhRLZvg0iw5p 4oF9GVLq2mXAHLNF5TT/C91dk8d+uuj0ncgiWqTEOJ2313fPypcJ/ZAP7L3EtM+UefA+0GVX8 R7EyJ6s+YSQROMNOnRCReeWdmIV86vVMMboS+VB/0QPRzr5q2RoKhyIwRChpQa/a4xr/bGCO7 uGgA/qgqdrzPtxH3y+FHfobvYtp4fDtbLcsgNCZnMNfVkYRxuCFiPeGx6JjuDMPpk7TDGANXJ /1ZL0VG+B8laDqZFBqisXnlz8oGKBxBbDs0760qlPbqv70l3rJDqGvU5FtcSdxaIYMEF6hcNw QvUHqq64rUssS8cq5Ql2wvXvEx785yAeKJu0p02NMo/vKpWVjuvfwdWUJlUpNz4kZjKJQVxHG 5ccWwgSLHS1P2HDJJmkw== X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean Provide a function to find a series of empty directory entries. The current directory is scanned for deleted entries. Signed-off-by: Heinrich Schuchardt --- fs/fat/fat_write.c | 62 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) -- 2.29.2 diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c index 941f8789ab..d560b94b60 100644 --- a/fs/fat/fat_write.c +++ b/fs/fat/fat_write.c @@ -21,6 +21,7 @@ #include "fat.c" static dir_entry *find_directory_entry(fat_itr *itr, char *filename); +static int new_dir_table(fat_itr *itr); /* Characters that may only be used in long file names */ static const char LONG_ONLY_CHARS[] = "+,;=[]"; @@ -250,6 +251,66 @@ static int flush_dirty_fat_buffer(fsdata *mydata) return 0; } +/** + * fat_find_empty_dentries() - find a sequence of available directory entries + * + * @itr: directory iterator + * @count: number of directory entries to find + * Return: 0 on success or negative error number + */ +static int __maybe_unused fat_find_empty_dentries(fat_itr *itr, int count) +{ + unsigned int cluster; + dir_entry *dent; + int remaining; + unsigned int n = 0; + int ret; + + ret = fat_move_to_cluster(itr, itr->start_clust); + if (ret) + return ret; + + for (;;) { + if (!itr->dent) { + log_debug("Not enough directory entries available\n"); + return -ENOSPC; + } + switch (itr->dent->name[0]) { + case 0x00: + case DELETED_FLAG: + if (!n) { + /* Remember first deleted directory entry */ + cluster = itr->clust; + dent = itr->dent; + remaining = itr->remaining; + } + ++n; + if (n == count) + goto out; + break; + default: + n = 0; + break; + } + + next_dent(itr); + if (!itr->dent && + (!itr->is_root || itr->fsdata->fatsize == 32) && + new_dir_table(itr)) + return -ENOSPC; + } +out: + /* Position back to first directory entry */ + if (itr->clust != cluster) { + ret = fat_move_to_cluster(itr, cluster); + if (ret) + return ret; + } + itr->dent = dent; + itr->remaining = remaining; + return 0; +} + /* * Set the file name information from 'name' into 'slotptr', */ @@ -319,7 +380,6 @@ name11_12: return 1; } -static int new_dir_table(fat_itr *itr); static int flush_dir(fat_itr *itr); /** From patchwork Sun Nov 29 02:02:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1407777 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.a=rsa-sha256 header.s=badeba3b8450 header.b=Epx1R4UM; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CkBWf1bZzz9sSf for ; Sun, 29 Nov 2020 13:04:46 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id CD32A8279F; Sun, 29 Nov 2020 03:03:24 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.b="Epx1R4UM"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C2E1582750; Sun, 29 Nov 2020 03:02:58 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 470498275B for ; Sun, 29 Nov 2020 03:02:45 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1606615356; bh=CyZNfGWNfn4pkh/TTmqRGhGKN5aEw5nCX2GlGcxB/Kw=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=Epx1R4UMObvsn/28OSTwimPvWeay05BDnT/kkHjAdQ4KGAMUxdYUdgOmEWY0Od9Tp /CFoH9DsFuMitQLWNd/lHGa855fM888M1jUnQrFOluCOi4CRMiX8nI2vZQ4EtP9BCx t+SW/F7YwCwVdpPmhfKYCF3yRE2pl5qYcWuEWnFw= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from mcbin.fritz.box ([62.143.246.89]) by mail.gmx.com (mrgmx005 [212.227.17.184]) with ESMTPSA (Nemesis) id 1MnakR-1kJnNW3X0v-00jc6a; Sun, 29 Nov 2020 03:02:36 +0100 From: Heinrich Schuchardt To: Tom Rini Cc: Simon Glass , Christian Gmeiner , Jason Wessel , AKASHI Takahiro , Marek Szyprowski , Bin Meng , Reuben Dowle , Marcin Juszkiewicz , Thomas Hebb , Samer El-Haj-Mahmoud , u-boot@lists.denx.de, Heinrich Schuchardt Subject: [PATCH 14/18] fs: fat: reuse deleted directory entries Date: Sun, 29 Nov 2020 03:02:12 +0100 Message-Id: <20201129020216.4865-15-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201129020216.4865-1-xypron.glpk@gmx.de> References: <20201129020216.4865-1-xypron.glpk@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:bdMURUkxFdh9SUEHN+0nzuQ25qKGUUNN2Ar+qdju3nmrVkdCDEp IHA2Mz+P3FVYxWz4Uee00noZ4d3R+w3sVgdwYCnUa9tQcgqGr+9FE14IHHPAwK+0O5OBGJc bL62YvOCiPKfjaXasDQ2xlS0Kc91kG57SKkSr7b9d19j6Ys77ISAj55yW+OHH01TrTKAWW2 2qP+J1gEVaymUlnVmgQTA== X-UI-Out-Filterresults: notjunk:1;V03:K0:2x8TSqAMBCo=:inSodNZAhY8pCHw03fE7eu A9S/4sS4tg+N2hXnRu27yrZprF52BsswuMrqH1Nh7OVx9Pg8944HkUveQfdlQ5A6/7QVKikj0 F67jhdZjck7KesFJzdO1SqUCCF5TD7zL5xKWWAhEuEB8hG0SW0C4dqN4ZiLcFLzIfvKslaap1 uUvF5/o22rZW18PY+DM+n0/DF1jw4p6poHmnsp83VL3/dokLTcbiOHfIRM4eBcwGnwHpygDVq IZ9pvUfsyU9pj+fbJghWDVy6/IfUPtw7K9ji00WlnvkLIc6ahu2G5VIcxK1TqhCX6zfKTetUJ hLELSbCAqqtbSm4caupCUc+G4c7XLbk2PiScKwoHdzE2a07tcS0UADLCfe23skhdBsSChPPTs Rwmp1d6IyxyXfm2LMDozJGQEb/gjdkWWc2+LS05yTfRhOs0L1fSAOvtI359slUSU3XqIuM7gH bTWPxctLrGVkO4LsrRI7fHrhB+R9Dz9urff0VN1QtotVK814xK0tUm1bixdmOEA35pG4xTvh4 j6QBOUOdwtj3qYBcoQfK91Xt6/+7AyemQqzi9lakyPaXwPBZT8nf9pdO2MkISEdqoXhzL3dzb 0ZFPbk7LjxOvcLfSLS3fciHNAcpygev15m9p/B3VUEoc50rgP+PxvuRZFNns1vuDSyqDX/mXs NYJn1htgPpFaWFFtZwhoFHWOplBTKRXeIPgQ4M9OMb+7XLFbI58S3bTSH8vzcNmGtS8nklk+1 CyI/z7LtpUY0L0VT+G7yKRpDVYWDcARb5nYDFqk4hC9JMyq82VM9Nn11lVoK+oHvpBTKJUxNz Q7JmGkhjbS5UyFBY7/PPkx7LhFdxZWSvnvQXFSt6lX1KDSgWysJHs7rkt4FBZwDh8d2Ix8j/J jxpRdsfwVKs8PG+OfcJw== X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean When creating new directory entries try to reuse entries marked as deleted. In fill_dir_slot() do not allocate new clusters as this has already been done in fat_find_empty_dentries(). Signed-off-by: Heinrich Schuchardt --- fs/fat/fat_write.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) -- 2.29.2 diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c index d560b94b60..a029ef8ed6 100644 --- a/fs/fat/fat_write.c +++ b/fs/fat/fat_write.c @@ -258,7 +258,7 @@ static int flush_dirty_fat_buffer(fsdata *mydata) * @count: number of directory entries to find * Return: 0 on success or negative error number */ -static int __maybe_unused fat_find_empty_dentries(fat_itr *itr, int count) +static int fat_find_empty_dentries(fat_itr *itr, int count) { unsigned int cluster; dir_entry *dent; @@ -421,11 +421,9 @@ fill_dir_slot(fat_itr *itr, const char *l_name, const char *shortname) if (itr->remaining == 0) flush_dir(itr); - /* allocate a cluster for more entries */ - if (!next_dent(itr) && !itr->dent) - if ((itr->is_root && itr->fsdata->fatsize != 32) || - new_dir_table(itr)) - return -EIO; + next_dent(itr); + if (!itr->dent) + return -EIO; } return 0; @@ -1339,6 +1337,7 @@ int file_fat_write_at(const char *filename, loff_t pos, void *buffer, } else { /* Create a new file */ char shortname[SHORT_NAME_SIZE]; + int ndent; if (itr->is_root) { /* root dir cannot have "." or ".." */ @@ -1362,10 +1361,15 @@ int file_fat_write_at(const char *filename, loff_t pos, void *buffer, } /* Check if long name is needed */ - ret = set_name(itr, filename, shortname); - if (ret < 0) + ndent = set_name(itr, filename, shortname); + if (ndent < 0) { + ret = ndent; + goto exit; + } + ret = fat_find_empty_dentries(itr, ndent); + if (ret) goto exit; - if (ret > 1) { + if (ndent > 1) { /* Set long name entries */ ret = fill_dir_slot(itr, filename, shortname); if (ret) @@ -1607,6 +1611,7 @@ int fat_mkdir(const char *new_dirname) goto exit; } else { char shortname[SHORT_NAME_SIZE]; + int ndent; if (itr->is_root) { /* root dir cannot have "." or ".." */ @@ -1624,10 +1629,15 @@ int fat_mkdir(const char *new_dirname) } /* Check if long name is needed */ - ret = set_name(itr, dirname, shortname); - if (ret < 0) + ndent = set_name(itr, dirname, shortname); + if (ndent < 0) { + ret = ndent; + goto exit; + } + ret = fat_find_empty_dentries(itr, ndent); + if (ret) goto exit; - if (ret > 1) { + if (ndent > 1) { /* Set long name entries */ ret = fill_dir_slot(itr, dirname, shortname); if (ret) From patchwork Sun Nov 29 02:02:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1407783 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.a=rsa-sha256 header.s=badeba3b8450 header.b=XbCw50b2; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CkBXq4F47z9s0b for ; Sun, 29 Nov 2020 13:05:47 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B77B5827B2; Sun, 29 Nov 2020 03:03:55 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.b="XbCw50b2"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A21A982785; Sun, 29 Nov 2020 03:03:07 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 439CD82732 for ; Sun, 29 Nov 2020 03:02:46 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1606615356; bh=u3VztDnQ0Zu5aYbT3Ng/eVIcQ/4RZt8wulbCJEER2Hg=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=XbCw50b2AT39LTRQb3zGJhTZSsuE9Vi6a4vXgIjhbzrNHwZhY6xiiq88n6RKdL7KJ 9FsRUW0e15ZorTa7Jl9JYtakawlxAjiJ5uIsGgi5A6TsQwcKXGhyCaLpIuK99MjpS7 aCK9xEP0iJ9AcgcQq+z8GiBkoBowexBPLguTEjzU= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from mcbin.fritz.box ([62.143.246.89]) by mail.gmx.com (mrgmx005 [212.227.17.184]) with ESMTPSA (Nemesis) id 1MtwZ4-1jvusK1m4S-00uF4j; Sun, 29 Nov 2020 03:02:36 +0100 From: Heinrich Schuchardt To: Tom Rini Cc: Simon Glass , Christian Gmeiner , Jason Wessel , AKASHI Takahiro , Marek Szyprowski , Bin Meng , Reuben Dowle , Marcin Juszkiewicz , Thomas Hebb , Samer El-Haj-Mahmoud , u-boot@lists.denx.de, Heinrich Schuchardt Subject: [PATCH 15/18] fs: fat: search file should not allocate cluster Date: Sun, 29 Nov 2020 03:02:13 +0100 Message-Id: <20201129020216.4865-16-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201129020216.4865-1-xypron.glpk@gmx.de> References: <20201129020216.4865-1-xypron.glpk@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:PXkriH6Q417hP51xhKbj4XEw2f8jMomCCy5JrJmGaRz0rF9icNV 4w7AwFnfHyPnvCEd68m6U6xhSCPHlDQSG+07pikBY0ciDQ4N3W2/i7/7oaEkbZ47/8Oxbgn jr/VvEmP7k9MpQB1TFD9sqoCCd1wLnZGMqpT4tRlRqc0Lww0I0faC47jONq5Scoo9lmJly2 LkUgTkW6oyPG5USRGZHAw== X-UI-Out-Filterresults: notjunk:1;V03:K0:E8a7nBuIEtM=:Lh09p0ItvU8QSv2C6azeCE 4Dxaj0av5Tb1ZnvbiXC6HkNUHOz2HHpmBw3onaxsLPdkKOFF48VsX2IOrX7OFyvoocQuc6a0l nqDyZbE7ce7H69sPx5WOFsguVkpNwlX1tDYZWm/UcCsmWL2EgFP42wpFyqyJUGEseedtyuh0f /RSgzOKxg+Jh8uIiaCdaJwkSKDKQ0UZZDreakh09JsuDgwpw7JKs7BFJoDXLk96wAtdko2BLW 9VfbUBaRUYS8MKRw4biQCT5Ij5QNWc32YqS53fCXk6tH6YTZkDTTubJI0R1mFS0wfITBfUdgj yOnGzwpmHksC2d/xZMbFzO2wW11pnR1X90D6ccWOxvztcEvp4i8Aj4XXGzOECBmLgd2z8Wyo5 BMngKiY8N7vzH14VieXf7FW3jQRsw1YP3nfqT1P8nUcs729HTaw+3wab4jVgTtGb5FJeBa008 R6wh0xOUZGTsDswoWpJFSiLNKfeXP33P6AnFR9qYD3xpPrrt/nHWsnA4AgTkoFvPBV8K5yVAz zhxflQ58uDt54oWwrxLWt2iNovCZygyQXItmWbeRs2Y8tyKeTeGmN4fw2Oz5GvozkFfqdILhe rwrTpUEbkkLOlOJqevdqP/tO+kd1ylgqTDm/QZ3j3sq0Gw1uObvuhhPZGyyKdzcRblNgcc1SG MrsrID1KCKiLNpSi/Ln7HAPr6KrglA+rMlC4FlGiJilR9rZ0eiAKPZukuXawrmyF2k6sKKw5i UjoHabcfZMub4+aCKJMWcCUgj1auGDM2MmCib42h8FhZCfF46spIwxjCMGPop8T340fNT7fFx cXzXpfGBhVxzjzBxGxvMvSDNASU5wgTCmNg9mDYfN/7EVncfURsnDCqwK33y/miTvwBOt5/Ti gEe5+vz1EGuU3CbWe6iA== X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean Searching for a file is not a write operation. So it should not lead to the allocation of a new cluster to the directory. If we reuse deleted entries, we might not even use the new cluster and due to not flushing it the directory could be corrupted. Signed-off-by: Heinrich Schuchardt --- fs/fat/fat_write.c | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) -- 2.29.2 diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c index a029ef8ed6..56ea28553b 100644 --- a/fs/fat/fat_write.c +++ b/fs/fat/fat_write.c @@ -1154,10 +1154,12 @@ static void fill_dentry(fsdata *mydata, dir_entry *dentptr, memcpy(dentptr->name, shortname, SHORT_NAME_SIZE); } -/* - * 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 +/** + * find_directory_entry() - find a directory entry by filename + * + * @itr: directory iterator + * @filename: name of file to find + * Return: directory entry or NULL */ static dir_entry *find_directory_entry(fat_itr *itr, char *filename) { @@ -1180,13 +1182,6 @@ static dir_entry *find_directory_entry(fat_itr *itr, char *filename) return itr->dent; } - /* allocate a cluster for more entries */ - if (!itr->dent && - (!itr->is_root || itr->fsdata->fatsize == 32) && - new_dir_table(itr)) - /* indicate that allocating dent failed */ - itr->dent = NULL; - return NULL; } @@ -1348,12 +1343,6 @@ int file_fat_write_at(const char *filename, loff_t pos, void *buffer, } } - if (!itr->dent) { - printf("Error: allocating new dir entry\n"); - ret = -EIO; - goto exit; - } - if (pos) { /* No hole allowed */ ret = -EINVAL; @@ -1622,12 +1611,6 @@ int fat_mkdir(const char *new_dirname) } } - if (!itr->dent) { - printf("Error: allocating new dir entry\n"); - ret = -EIO; - goto exit; - } - /* Check if long name is needed */ ndent = set_name(itr, dirname, shortname); if (ndent < 0) { From patchwork Sun Nov 29 02:02:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1407786 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.a=rsa-sha256 header.s=badeba3b8450 header.b=i0PoUGju; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CkBYM5Spmz9s0b for ; Sun, 29 Nov 2020 13:06:15 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A95B0827BB; Sun, 29 Nov 2020 03:04:04 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.b="i0PoUGju"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A63B282777; Sun, 29 Nov 2020 03:03:10 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id C49C082770 for ; Sun, 29 Nov 2020 03:02:46 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1606615357; bh=A5IaZT/1F7KkbjyFDkNJxo8PElxolkZ6eS3O4mNW3lU=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=i0PoUGjukcNH084D/pG3fhn/D1C1UApoICBDBdw4Wvy8jvsYKODXO3/W/B5AATvxe H6wHDXOC+0aWSWrkUnhN1DrMU4nNOkkgOTN3dL8tBrY2jo+EhYgyHVmoJXzDBsRyer xSPqVcpcPPonrPVsD6qHn7YIgCZlqZ3sizimu8C0= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from mcbin.fritz.box ([62.143.246.89]) by mail.gmx.com (mrgmx005 [212.227.17.184]) with ESMTPSA (Nemesis) id 1M8hV5-1knKm540kD-004lWW; Sun, 29 Nov 2020 03:02:37 +0100 From: Heinrich Schuchardt To: Tom Rini Cc: Simon Glass , Christian Gmeiner , Jason Wessel , AKASHI Takahiro , Marek Szyprowski , Bin Meng , Reuben Dowle , Marcin Juszkiewicz , Thomas Hebb , Samer El-Haj-Mahmoud , u-boot@lists.denx.de, Heinrich Schuchardt Subject: [PATCH 16/18] fs: fat: use constant DELETED_FLAG Date: Sun, 29 Nov 2020 03:02:14 +0100 Message-Id: <20201129020216.4865-17-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201129020216.4865-1-xypron.glpk@gmx.de> References: <20201129020216.4865-1-xypron.glpk@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:ft8zYpL9MFAGp0zTonzbEIHY916E4fGtG+8O/EG8hdZoH0oCOKY 3STksDI3GDzv0Kh80kYkhymkmaeWCmh1EAuyXtz9y1rev7TGwttxFd3FDapO3wal4ikihMb oafvUMaPbMoUhGxcfk1tzQiiF7gun0E8Y+HY1AVM8L4PlufIVRRyYMGRGxbNHaLPoNqVPKJ MxBVWOnT1K9NkdRAzNqtA== X-UI-Out-Filterresults: notjunk:1;V03:K0:0wFummheuzI=:3p8vDQQ0CjB90uGruZtRUf xp3OnVMssriNsfvIs+rXTMvsiiTAG65FbmJJH+8ha787XtdWNdYoXg9/JVx6nybAK+Vac2ZsX ibEJgAY0aVFA5vLVZrpuBm5s7GnXKNTPBHICpUUCmFXbbuMDZTFISHrE8Ql7ird9CD4ds6XYa gErLgZrs8IUo4vW6vKgfM2M5LyMuewupQ3tzI7yxpOuJOlh98xT+EHyPpoQ1MQ5+jAh/QhJ97 0VdtN3OAdppOYJzzHHS6RnwWMZ55a3/kyO8D1ASSEDC3uJU5+JBOOw1bLUg6/MUejdoDmvKJU nxY3EPoLkU3CDpxEvBIHC8jEYlJvmusY14R2eVNGU7XeKOvUkq7lTjN6SDdlDfEcBCKtBKIeY cFjhBt/KXn7g1mFgYj3iUc2WvGPHvi0NjW+uUEn2pu9nKJvIBs/HcRXCg4a5Iy++eC70lCeZU d16s1rcO+CKepbvX7UNP5OKnq00157YdcjsbXS3rEWvELBr+1AjiwQmfJekgH0wfnh/YK+DdH mrWigifYEtYogN/PLWzWWYeiyVXcNP9K1mM3r3ajeDSPthTMCQxdVDWJO4wZpZhqVl6thmUxe VuRRSqZWovicxWIjee/byxpO+6a0fUq4LRpwVcDnLPI4KWayptoaFq5gDaD0vMwwHdoalbGpD 9jjlwnqIT8eLUrtsTqRyRWKXU+mjwivwK8qSIUw5odhyI/RjLQZNnGnIhrK1B5ulnTvsLauDj xYLk1mzWiAXpfw25EUKin63G2utoHOAUHq102DACUJVZ7DvRpeQNF1sFQuJ6ieJERToYi3mLe KfTVya89cmVNRYxn8Fn/09kyJwB5I/UUyFj/CCJ3vbtZyiT/iBdC3M0cOfIj1FM8cLtTAFDrm D61a8peG7ikc4zKrDESA== X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean When deleting a directory entry 0xe5 is written to name[0]. We have a constant for this value and should use it consistently. Signed-off-by: Heinrich Schuchardt --- fs/fat/fat_write.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.29.2 diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c index 56ea28553b..c403d7d5c6 100644 --- a/fs/fat/fat_write.c +++ b/fs/fat/fat_write.c @@ -1464,7 +1464,7 @@ static int delete_dentry(fat_itr *itr) * - find and mark the "new" first invalid entry as name[0]=0x00 */ memset(dentptr, 0, sizeof(*dentptr)); - dentptr->name[0] = 0xe5; + dentptr->name[0] = DELETED_FLAG; if (flush_dir(itr)) { printf("error: writing directory entry\n"); From patchwork Sun Nov 29 02:02:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1407784 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.a=rsa-sha256 header.s=badeba3b8450 header.b=h0PnF83y; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CkBY04FFXz9s0b for ; Sun, 29 Nov 2020 13:05:56 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A17F6827B6; Sun, 29 Nov 2020 03:03:57 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.b="h0PnF83y"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6AE408275B; Sun, 29 Nov 2020 03:03:08 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id BEC4F8277A for ; Sun, 29 Nov 2020 03:02:47 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1606615357; bh=O3kWMxDYZzZx1Zv6Ad87TApUhfa1FVrtEmILx0qAOhE=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=h0PnF83yuGRVBIn/y3rCnvHYsLgQEQBRZ7LPSZanjaxsCcD0wDZKypZFmTiP2m7+E FSo5urqaJtlwrKiyWSQgQ8fJFJgMSdFqbn4I3jEgRd0vKCgz9YK+LJLIx86DJUB3mv ewFV56lO/vlD+X7tZFqADnLXharBX4SKEGCD43ug= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from mcbin.fritz.box ([62.143.246.89]) by mail.gmx.com (mrgmx005 [212.227.17.184]) with ESMTPSA (Nemesis) id 1Mzhj9-1jwkDk22SH-00vdC0; Sun, 29 Nov 2020 03:02:37 +0100 From: Heinrich Schuchardt To: Tom Rini Cc: Simon Glass , Christian Gmeiner , Jason Wessel , AKASHI Takahiro , Marek Szyprowski , Bin Meng , Reuben Dowle , Marcin Juszkiewicz , Thomas Hebb , Samer El-Haj-Mahmoud , u-boot@lists.denx.de, Heinrich Schuchardt Subject: [PATCH 17/18] fs: fat: first dentry of long name in FAT iterator Date: Sun, 29 Nov 2020 03:02:15 +0100 Message-Id: <20201129020216.4865-18-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201129020216.4865-1-xypron.glpk@gmx.de> References: <20201129020216.4865-1-xypron.glpk@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:cu2hcPNg/rkUCvegylDs/xxDztzf8kzIG6ArT1NNJ0y4UjQFzEy OfUa8pvW5mnKzE74bx6higt2+plMYXdzOWa6a3Vw8xDy0aQWnWt/hbXvItZbufP1GvYScsQ nFuIWhHafhgU2HsmI1Yw2Fof7cmuew/THYbgNaKAhKuRocOjjp9vDxaKVLQKWelKGc4/BSn 6h2310d+35bnxrXP1Mfew== X-UI-Out-Filterresults: notjunk:1;V03:K0:Z0OGpHoxjBQ=:rQo3iVyKZUBl4QHetRiPOL 2+ve3OTO5SzeWb4pG8ys0hzCGyxlkumvrKDzJkEIWcEb66cnQo5pwSIYgr87uHs/rsIjlSjZM hdGZbLINbturVrqNk0CES0BzKQatcPIj4l8NBUul0ssBlQOAd2bemcm+n3kb0FCeIwno/WA9Q kLZeO5iq7efjAcGE7LipUBUY6Ox1ZmxTnjgrG/qFuTgfVeMIqXJN7HWS+nby03NKckrKalDm1 iLpVRe9ci0Lm4+8aDr1/9mPU0l5OYYxN7FUvc8aF7hqXT8ky58z4BCxyWahOax33tKm/5Ung4 6PLMH0Xx0T/kVJPakhzqqrzZpC1UwKQ/RGhCcMIygZk1E0uTZrWEYy1epy22cORdczNG8QS1F oKYPomHLfML6CrmfIIOJgetV/DbKOAQW0BzYwkT4cSuUSthLwJOM3WVj2+7ejXQUFMmfp+qTF z9HTe7MERPC0e0o1PiG4f7wROBnY0s3EpOS3K+qm6yclM2EURBGJloZ4QhMZq53mJstN8UPgp so/0EM9rxXkpY40ek5nrniX51PEKygPMxV0PgS9LaokT/sHLrkImZ07g2DHkvi8fcGYMg9/FT kCgCnFI8W8ycGRr5Us/2mO7LmxQaviw09AzX7VT4gW6Hq2x/rXkAhHLJK85BDeokmMjm2z+m6 iAiRapcEKfCBli+aBF/Vl6LhvqoSv+HcyumsjFsoX1J/n422uAb6iUDdBuDjuerx0Tt0EzL04 o6wtcQ1NOVZApD5RfjGnx5M5TSGUrx8l+RUj6M6MIm23dOvTbY0xOpjY0IeP1zWH9vp/9iryP ILnSugKxleKiG8R5hoAQsN8EOLRxfm1LjmrHyvUXr6ZwpHCjTPjgJp1CVOwSJC6HshO00uJIG 69rfiBSgX+3RmjH/Q5Sg== X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean A long name is split over multiple directory entries. When deleting a file with a long name we need the first directory entry to be able to delete the whole chain. Add the necessary fields to the FAT iterator: * cluster of first directory entry * address of first directory entry * remaining entries in cluster Signed-off-by: Heinrich Schuchardt --- fs/fat/fat.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) -- 2.29.2 diff --git a/fs/fat/fat.c b/fs/fat/fat.c index 5a418cfbb7..47344bb57e 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -700,6 +700,18 @@ struct fat_itr { * @dent: current directory entry */ dir_entry *dent; + /** + * @dent_rem: remaining entries after long name start + */ + int dent_rem; + /** + * @dent_clust: cluster of long name start + */ + unsigned int dent_clust; + /** + * @dent_start: first directory entry for long name + */ + dir_entry *dent_start; /** * @l_name: long name of current directory entry */ @@ -966,9 +978,13 @@ static int fat_itr_next(fat_itr *itr) while (1) { dent = next_dent(itr); - if (!dent) + if (!dent) { + itr->dent_start = NULL; return 0; - + } + itr->dent_rem = itr->remaining; + itr->dent_start = itr->dent; + itr->dent_clust = itr->clust; if (dent->name[0] == DELETED_FLAG) continue; From patchwork Sun Nov 29 02:02:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1407785 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.a=rsa-sha256 header.s=badeba3b8450 header.b=X/iAk+mq; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CkBYB3NXbz9s0b for ; Sun, 29 Nov 2020 13:06:06 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9B3BC827BF; Sun, 29 Nov 2020 03:04:00 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.b="X/iAk+mq"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 920218277A; Sun, 29 Nov 2020 03:03:09 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 303EB82786 for ; Sun, 29 Nov 2020 03:02:49 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1606615358; bh=juDNgc2N6Uz9as72HLIxuRZqgbhqd//C2hYLRaK9TK0=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=X/iAk+mqKVQCbGgkX5METUlb2YHHvpZu8gnUk+nI0lDw1b/4O8c5MRz+vXjSPtO+w fM4SxPwH2AMDVGpPGxQ3VOBMbR/qm8QQODJFjFTeFfMllVDkxgFeQK56bqBwAHVMgz w02OYFCZB9IqVRGaRrtqgEBGevvwkamP5i9iMOYg= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from mcbin.fritz.box ([62.143.246.89]) by mail.gmx.com (mrgmx005 [212.227.17.184]) with ESMTPSA (Nemesis) id 1MJVHe-1kTs7J47cO-00JoKT; Sun, 29 Nov 2020 03:02:38 +0100 From: Heinrich Schuchardt To: Tom Rini Cc: Simon Glass , Christian Gmeiner , Jason Wessel , AKASHI Takahiro , Marek Szyprowski , Bin Meng , Reuben Dowle , Marcin Juszkiewicz , Thomas Hebb , Samer El-Haj-Mahmoud , u-boot@lists.denx.de, Heinrich Schuchardt Subject: [PATCH 18/18] fs: fat: deletion of long file names Date: Sun, 29 Nov 2020 03:02:16 +0100 Message-Id: <20201129020216.4865-19-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201129020216.4865-1-xypron.glpk@gmx.de> References: <20201129020216.4865-1-xypron.glpk@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:hdfQDJmXwzMgNmVAE8zKpSlLFye0JI169UwNXIyTTOSVDbPHgj7 tTu5QVnCJ5fqfY3StE+I8MvvpdWIjdApTSTm5rKQAKfflxyZgjd8x5mtG01Ot6DvgmK8L2t Wn2Hj4rtrmCS+le2QfzYe7zKvMDaN2okbZH50ycc2IwFZF04/8EAS937X6pdK7EOEkTddlt ePv//XZ1thReott1kNvDQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:oYCmY9jKGBQ=:XpMkaMgpT9Z5XjQQ517wnA z0KxBO2hYOGLJIqXk7JVrNCJv3/FrsvxZaDsp/H6jG8kFFY/BVH6+qGeimA+n2ZbXd+oBB7Al Hs/QyrnzB4d7XmunjKm2x5I5ZqJi080a8ZLRgigqmZ2EeXKGwYZayGHB24NgJUsa+huWtwY8f 63iluGDaWzyTQBtb7lyHv92N4d8g/s3tG9lAcDvvNixv3NvHYbZBpAKc9HeY0gzkpzoPlSb6v Og5CPl1cTUf4ZVJ5/CZ015Z7XNILui5T1p02p4xtY5K6BXGmeyRc9GYZ7eXOZKmtjLmpBMiK4 YGX7Dr+u5lntEf600/Rm8kb6me/osklg32HiELe+W9S4430u2ko8qFmcIQIW+F/jKN8g3+Gz5 7TOTtnFRgiZIgTJpNt64y3jIV3Id+iXgJ7z0Sa9lKDERSgqq/li+KV7bTQLmD/giF9Wp/BUi3 GViKpf6bBBzEb7yTbtHCX+u4EVmnEHWOUESeCAbvMNL3PvLoPWyWDvXmqDXFYuoOJWrSXD2HE iP3ZyK99bYMyjjB1EZv3UfcHflnTqmuYjuvWScrMSwiYZmoJuq8i2rMSzSCm26dPPOCBDkQXK vRNGzeAOKLqwYxw+mRKRFYBfL5nN0isimXts8PrWEv6FecEbGW+vca0FTXFx8/vOfmn1LjJSB KGaPG/ImdE+tJPTG6Zugok64qcF6Ka8dlLs6S2QkGTCMmcQU+yMGAvRmHz6pQaulb3wbhzX6N +3mm69aztD0V+HgPU8t4KMUYDeUXAStbpgNHWlszVB/eNj4JG7R8nnd/CohXK+lpD0nqqRkDf PV8nU0Q60pUqUufQ9XFZ2mvCrLX+uMee6cdBa83qU97Uup9i5c7FIAk83C9zmynOMasw42J2M g2xn4E1PYmsknUA2ybjg== X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean Long file names are stored in multiple directory entries. When deleting a file we must delete all of them. Signed-off-by: Heinrich Schuchardt --- fs/fat/fat_write.c | 88 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 76 insertions(+), 12 deletions(-) -- 2.29.2 diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c index c403d7d5c6..20a54a2418 100644 --- a/fs/fat/fat_write.c +++ b/fs/fat/fat_write.c @@ -1445,27 +1445,91 @@ exit: return count; } -static int delete_dentry(fat_itr *itr) +/** + * delete_single_dentry() - delete a single directory entry + * + * @itr: directory iterator + * Return: 0 for success + */ +static int delete_single_dentry(fat_itr *itr) +{ + struct dir_entry *dent = itr->dent; + + memset(dent, 0, sizeof(*dent)); + dent->name[0] = DELETED_FLAG; + + if (!itr->remaining) { + if (flush_dir(itr)) { + printf("error: writing directory entry\n"); + return -EIO; + } + } + return 0; +} + +/** + * delete_long_name() - delete long name directory entries + * + * @itr: directory iterator + * Return: 0 for success + */ +static int delete_long_name(fat_itr *itr) +{ + struct dir_entry *dent = itr->dent; + int seqn = itr->dent->name[0] & ~LAST_LONG_ENTRY_MASK; + + while (seqn--) { + int ret; + + ret = delete_single_dentry(itr); + if (ret) + return ret; + dent = next_dent(itr); + if (!dent) + return -EIO; + } + return 0; +} + +/** + * delete_dentry_long() - remove directory entry + * + * @itr: directory iterator + * Return: 0 for success + */ +static int delete_dentry_long(fat_itr *itr) { fsdata *mydata = itr->fsdata; - dir_entry *dentptr = itr->dent; + dir_entry *dent = itr->dent; /* free cluster blocks */ - clear_fatent(mydata, START(dentptr)); + clear_fatent(mydata, START(dent)); if (flush_dirty_fat_buffer(mydata) < 0) { printf("Error: flush fat buffer\n"); return -EIO; } + /* Position to first directory entry for long name */ + if (itr->clust != itr->dent_clust) { + int ret; - /* - * update a directory entry - * TODO: - * - long file name support - * - find and mark the "new" first invalid entry as name[0]=0x00 - */ - memset(dentptr, 0, sizeof(*dentptr)); - dentptr->name[0] = DELETED_FLAG; + ret = fat_move_to_cluster(itr, itr->dent_clust); + if (ret) + return ret; + } + itr->dent = itr->dent_start; + itr->remaining = itr->dent_rem; + dent = itr->dent_start; + /* Delete long name */ + if ((dent->attr & ATTR_VFAT) == ATTR_VFAT && + (dent->name[0] & LAST_LONG_ENTRY_MASK)) { + int ret; + ret = delete_long_name(itr); + if (ret) + return ret; + } + /* Delete short name */ + delete_single_dentry(itr); if (flush_dir(itr)) { printf("error: writing directory entry\n"); return -EIO; @@ -1535,7 +1599,7 @@ int fat_unlink(const char *filename) } } - ret = delete_dentry(itr); + ret = delete_dentry_long(itr); exit: free(fsdata.fatbuf);