From patchwork Fri Dec 9 18:55:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Philipp Skadorov X-Patchwork-Id: 704703 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 3tbNVJ3sHxz9vFX for ; Sat, 10 Dec 2016 20:05:27 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id C68B4A75B7; Sat, 10 Dec 2016 10:05:22 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id UqXHJ8tzo2eu; Sat, 10 Dec 2016 10:05:22 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id AE1DB4BA35; Sat, 10 Dec 2016 10:05:21 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 6A1394BA35 for ; Fri, 9 Dec 2016 22:22:04 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id H4jdARKUXF_o for ; Fri, 9 Dec 2016 22:22:04 +0100 (CET) X-Greylist: delayed 4200 seconds by postgrey-1.34 at theia; Fri, 09 Dec 2016 22:22:00 CET X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail.savoirfairelinux.com (mail.savoirfairelinux.com [208.88.110.44]) by theia.denx.de (Postfix) with ESMTPS id 230EB4BA16 for ; Fri, 9 Dec 2016 22:22:00 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by mail.savoirfairelinux.com (Postfix) with ESMTP id D3ED79C1C68 for ; Fri, 9 Dec 2016 13:55:53 -0500 (EST) Received: from mail.savoirfairelinux.com ([127.0.0.1]) by localhost (mail.savoirfairelinux.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id z47LK9ZPyPLx; Fri, 9 Dec 2016 13:55:52 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by mail.savoirfairelinux.com (Postfix) with ESMTP id 2974E9C1C39; Fri, 9 Dec 2016 13:55:52 -0500 (EST) X-Virus-Scanned: amavisd-new at mail.savoirfairelinux.com Received: from mail.savoirfairelinux.com ([127.0.0.1]) by localhost (mail.savoirfairelinux.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id ALk5cy0Gb9lX; Fri, 9 Dec 2016 13:55:52 -0500 (EST) Received: from pc-pskadorov.mtl.sfl (unknown [192.168.48.252]) by mail.savoirfairelinux.com (Postfix) with ESMTPSA id 02ECA9C1B4D; Fri, 9 Dec 2016 13:55:52 -0500 (EST) From: Philipp Skadorov To: u-boot@lists.denx.de Date: Fri, 9 Dec 2016 13:55:37 -0500 Message-Id: <1481309737-3740-1-git-send-email-philipp.skadorov@savoirfairelinux.com> X-Mailer: git-send-email 2.7.4 X-Mailman-Approved-At: Sat, 10 Dec 2016 10:05:20 +0100 Cc: Philipp Skadorov Subject: [U-Boot] [PATCH v1] fat: fatwrite: fix the command for FAT12 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" The u-boot command fatwrite empties FAT clusters from the beginning till the end of the file. Specifically for FAT12 it fails to detect the end of the file and goes beyond the file bounds thus corrupting the file system. The users normally workaround this by re-formatting the partition as FAT16/FAT32, like here: https://github.com/FEDEVEL/openrex-uboot-v2015.10/issues/1 The patch is to check file bounds by already-existing macro that accounts for FAT12. The command then works correctly for all types of FAT. Signed-off-by: Philipp Skadorov Cc:Donggeun Kim Reviewed-by: Benoît Thébaudeau --- fs/fat/fat_write.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c index 40a3860..e4f600e 100644 --- a/fs/fat/fat_write.c +++ b/fs/fat/fat_write.c @@ -670,16 +670,13 @@ static int clear_fatent(fsdata *mydata, __u32 entry) { __u32 fat_val; - while (1) { + while (!CHECK_CLUST(entry, mydata->fatsize)) { fat_val = get_fatent_value(mydata, entry); if (fat_val != 0) set_fatent_value(mydata, entry, 0); else break; - if (fat_val == 0xfffffff || fat_val == 0xffff) - break; - entry = fat_val; }