From patchwork Mon May 13 05:49:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1098658 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="s2pCmrv+"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 452VK05WR0z9sML for ; Mon, 13 May 2019 15:50:12 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 7AEE4C21E9F; Mon, 13 May 2019 05:50:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 06773C21EFF; Mon, 13 May 2019 05:50:02 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 6E071C21ECC; Mon, 13 May 2019 05:49:50 +0000 (UTC) Received: from mail-pf1-f193.google.com (mail-pf1-f193.google.com [209.85.210.193]) by lists.denx.de (Postfix) with ESMTPS id 53CEDC21EBA for ; Mon, 13 May 2019 05:49:47 +0000 (UTC) Received: by mail-pf1-f193.google.com with SMTP id t87so6583294pfa.2 for ; Sun, 12 May 2019 22:49:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AAhQEX44O5X3JEUnudGCfeufOkZXjDBNdVxokerRGyg=; b=s2pCmrv+yspi4WOh9vi/L/Qgugtnk24wakGp1V842mbH9nLJ8LSWT2eLDI8kLl1fsV KBGz4ijxnL+dEmah7R0TCpDEBiVlQc8unf4VG6AJG9dQUmaKnm/421z61ZAFTS7gdP9q LXs/Qs8P6uYkxuc5qgcqaJO4BB17xlGH/zWIRY20LxKM0yGAm41d/KNJB4EXmrSquQ/K oR7XyIa4S46+4vLDarGO0bixR7Qv8qfcLINvfzXVyR4HN0DADMfdJwSPoM361pXRrt4A 8Xs7DtPjycgvgoVWuRiz8PbIhBio+WMxulWAk2iraReCe/5f7iKwvLmsmZlM5CPaZZvO 7CNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AAhQEX44O5X3JEUnudGCfeufOkZXjDBNdVxokerRGyg=; b=bstWS+uIZm0R4CuXQPQhiYid3VPzWL9v3Vqy+eXL15NqCjGQ9dNq7s3Yt9z9OgC4fz bQkYT6Z9w9WgHV79d5sGez78XNfasFAm9zoR7gzEGkXjkvgKbYxTCNDxLVEq5036rSDV t7bMej1zg7kOtGSNKvbWrLgnfDAaGMktphHI+DG+vBRYNOYY0FUBQSbpY15YkVocLGKS EaOip4aFDx7kHQRItpZk9cOqFriS8BhCq4ECxkbzU2bLyWa9TwdK2xsDbwy7nuClTVPW KPEoS1tzac0yBJZhdVzO7f0zsOZyJMoz3N3YeiuThFoCqkKq+AjYFng+j96RITwKJBxv zL4Q== X-Gm-Message-State: APjAAAVEP6VcO2pmLjRo+dClnEtNzmfAShhLqWkabChyqt/YfFNPLWQV 52oJ1UFhp2mpILDrf6kEfuDDmQ== X-Google-Smtp-Source: APXvYqx1S+77Ox7uKO/9JKdjfzGHqjjbq6qiOasKNdAhIgNvZp7X/aEfA92NN6M2bT2h7Bnzryggjw== X-Received: by 2002:a63:d016:: with SMTP id z22mr29419915pgf.116.1557726585604; Sun, 12 May 2019 22:49:45 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id r9sm15966560pfc.173.2019.05.12.22.49.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 12 May 2019 22:49:45 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Mon, 13 May 2019 14:49:24 +0900 Message-Id: <20190513054927.17890-2-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190513054927.17890-1-takahiro.akashi@linaro.org> References: <20190513054927.17890-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH 1/4] fs: fat: write to non-cluster-aligned root directory X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" With the commit below, fat now correctly handles a file read under a non-cluster-aligned root directory of fat12/16. Write operation should be fixed in the same manner. Fixes: commit 9b18358dc05d ("fs: fat: fix reading non-cluster-aligned root directory") Signed-off-by: AKASHI Takahiro Cc: Anssi Hannula Tested-by: Heinrich Schuchardt --- fs/fat/fat.c | 15 ++++----- fs/fat/fat_write.c | 78 +++++++++++++++++++++++++++++++--------------- 2 files changed, 61 insertions(+), 32 deletions(-) diff --git a/fs/fat/fat.c b/fs/fat/fat.c index c5997c21735f..fccaa385d187 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -619,13 +619,14 @@ static int get_fs_info(fsdata *mydata) return -1; } - debug("FAT%d, fat_sect: %d, fatlength: %d\n", - mydata->fatsize, mydata->fat_sect, mydata->fatlength); - debug("Rootdir begins at cluster: %d, sector: %d, offset: %x\n" - "Data begins at: %d\n", - mydata->root_cluster, - mydata->rootdir_sect, - mydata->rootdir_sect * mydata->sect_size, mydata->data_begin); + debug("FAT%d, fat_sect: %d, fatlength: %d, num: %d\n", + mydata->fatsize, mydata->fat_sect, mydata->fatlength, + mydata->fats); + debug("Rootdir begins at cluster: %d, sector: %d, size: %x\n" + "Data begins at: %d\n", + mydata->root_cluster, + mydata->rootdir_sect, + mydata->rootdir_size * mydata->sect_size, mydata->data_begin); debug("Sector size: %d, cluster size: %d\n", mydata->sect_size, mydata->clust_size); diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c index 852f874e5817..3bc0dd637521 100644 --- a/fs/fat/fat_write.c +++ b/fs/fat/fat_write.c @@ -388,29 +388,23 @@ static __u32 determine_fatent(fsdata *mydata, __u32 entry) } /** - * set_cluster() - write data to cluster + * set_sectors() - write data to sectors * - * Write 'size' bytes from 'buffer' into the specified cluster. + * Write 'size' bytes from 'buffer' into the specified sector. * * @mydata: data to be written - * @clustnum: cluster to be written to + * @startsect: sector to be written to * @buffer: data to be written * @size: bytes to be written (but not more than the size of a cluster) * Return: 0 on success, -1 otherwise */ static int -set_cluster(fsdata *mydata, u32 clustnum, u8 *buffer, u32 size) +set_sectors(fsdata *mydata, u32 startsect, u8 *buffer, u32 size) { - u32 idx = 0; - u32 startsect; + u32 nsects = 0; int ret; - if (clustnum > 0) - startsect = clust_to_sect(mydata, clustnum); - else - startsect = mydata->rootdir_sect; - - debug("clustnum: %d, startsect: %d\n", clustnum, startsect); + debug("startsect: %d\n", startsect); if ((unsigned long)buffer & (ARCH_DMA_MINALIGN - 1)) { ALLOC_CACHE_ALIGN_BUFFER(__u8, tmpbuf, mydata->sect_size); @@ -429,17 +423,16 @@ set_cluster(fsdata *mydata, u32 clustnum, u8 *buffer, u32 size) size -= mydata->sect_size; } } else if (size >= mydata->sect_size) { - idx = size / mydata->sect_size; - ret = disk_write(startsect, idx, buffer); - if (ret != idx) { + nsects = size / mydata->sect_size; + ret = disk_write(startsect, nsects, buffer); + if (ret != nsects) { debug("Error writing data (got %d)\n", ret); return -1; } - startsect += idx; - idx *= mydata->sect_size; - buffer += idx; - size -= idx; + startsect += nsects; + buffer += nsects * mydata->sect_size; + size -= nsects * mydata->sect_size; } if (size) { @@ -457,6 +450,44 @@ set_cluster(fsdata *mydata, u32 clustnum, u8 *buffer, u32 size) return 0; } +/** + * set_cluster() - write data to cluster + * + * Write 'size' bytes from 'buffer' into the specified cluster. + * + * @mydata: data to be written + * @clustnum: cluster to be written to + * @buffer: data to be written + * @size: bytes to be written (but not more than the size of a cluster) + * Return: 0 on success, -1 otherwise + */ +static int +set_cluster(fsdata *mydata, u32 clustnum, u8 *buffer, u32 size) +{ + return set_sectors(mydata, clust_to_sect(mydata, clustnum), + buffer, size); +} + +static int +flush_dir(fat_itr *itr) +{ + fsdata *mydata = itr->fsdata; + u32 startsect, sect_offset, nsects; + + if (!itr->is_root || mydata->fatsize == 32) + return set_cluster(mydata, itr->clust, itr->block, + mydata->clust_size * mydata->sect_size); + + sect_offset = itr->clust * mydata->clust_size; + startsect = mydata->rootdir_sect + sect_offset; + /* do not write past the end of rootdir */ + nsects = min_t(u32, mydata->clust_size, + mydata->rootdir_size - sect_offset); + + return set_sectors(mydata, startsect, itr->block, + nsects * mydata->sect_size); +} + static __u8 tmpbuf_cluster[MAX_CLUSTSIZE] __aligned(ARCH_DMA_MINALIGN); /* @@ -1171,8 +1202,7 @@ int file_fat_write_at(const char *filename, loff_t pos, void *buffer, } /* Write directory table to device */ - ret = set_cluster(mydata, itr->clust, itr->block, - mydata->clust_size * mydata->sect_size); + ret = flush_dir(itr); if (ret) { printf("Error: writing directory entry\n"); ret = -EIO; @@ -1249,8 +1279,7 @@ static int delete_dentry(fat_itr *itr) memset(dentptr, 0, sizeof(*dentptr)); dentptr->name[0] = 0xe5; - if (set_cluster(mydata, itr->clust, itr->block, - mydata->clust_size * mydata->sect_size) != 0) { + if (flush_dir(itr)) { printf("error: writing directory entry\n"); return -EIO; } @@ -1452,8 +1481,7 @@ int fat_mkdir(const char *new_dirname) } /* Write directory table to device */ - ret = set_cluster(mydata, itr->clust, itr->block, - mydata->clust_size * mydata->sect_size); + ret = flush_dir(itr); if (ret) printf("Error: writing directory entry\n"); From patchwork Mon May 13 05:49:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1098659 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="DKFrrIPH"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 452VKk3GGJz9sBr for ; Mon, 13 May 2019 15:50:50 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id DCA45C21EBA; Mon, 13 May 2019 05:50:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id DAC38C21F0F; Mon, 13 May 2019 05:50:05 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 258AFC21EE3; Mon, 13 May 2019 05:49:52 +0000 (UTC) Received: from mail-pg1-f195.google.com (mail-pg1-f195.google.com [209.85.215.195]) by lists.denx.de (Postfix) with ESMTPS id B2CCAC21EFF for ; Mon, 13 May 2019 05:49:49 +0000 (UTC) Received: by mail-pg1-f195.google.com with SMTP id 145so6163495pgg.9 for ; Sun, 12 May 2019 22:49:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RmWAE/9zqFCfxkavOj0kQFVD7zr+Lb3aHMtoNL5nXO4=; b=DKFrrIPHNTVrTybl5HcNFQZrfx7PwbF31a2EXRfFfCZ8dYwTPMRG4evEfy7fPahcBa cDD3XkBXc3rV1lTbC+TJjAKeAfRzkC3/JvppRMRusDRHm0v/ERHRDC2TMQSABtTJ4U0c HRKcMqMStz2A6+O14k7nqY7fUfz0uEIP+BJ2CbVNPtyY1XGHeG8+KeJxpJJeb8WNVa9h DHu29D0RIXD80OrTHZbqhE8xJXHryGMvU2O+cv9rgPPpSeEYEtUwgUxrwRePzOqsHikR OE26mXPFZBaABVpzer6BgTeCi88AsGw9V3mGe9YLMGUSK7moizKxczT+hP1HkiZPL9OC Ok9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RmWAE/9zqFCfxkavOj0kQFVD7zr+Lb3aHMtoNL5nXO4=; b=aWo4ksKaxjrz3II4DSZAxtLv4GJBSWuxuGVLFwU0Wnsp6PK+MGloGpboVZe14o90fM YwmBqzN7Y5rIzDV9exw5I+59dfrOkoE+KtHU0yEeHbph8kwkgEcxU1pvT16HX0zXZ6Pi JT3qFlDxNHi52ad7uOPQv5yYpT/MnG7nyeefV3jb33TfhZnczkhpedRcNuJ2ggbIkj0W 6r/2Nqj2bMiRayjRw2deuRO7bEPXydssEVd5bR6sOhRpOXuqSEc1oaaFO9aq9cjGYdLq Mr+wI3fFsmqwAZOfwnPwNRfA7zYyHSxbhYqV2ooe/fZKzvzvuOv7W9hykzLcMg2mBXZW idDg== X-Gm-Message-State: APjAAAUi4tHE89yD3oRCbzWlAcy+AX1QIRQ/21fvHc4oLBpZNLiny7kW 6FXVJQTR4q9pzZ8z6iNKDo877g== X-Google-Smtp-Source: APXvYqzil63SPGNEZ4bTvtmCb01T7s4TRe5B+ahSYXkDKcEdo8l9ds3O6UIoFhfk7z+PF0XVoElcTw== X-Received: by 2002:a63:2118:: with SMTP id h24mr29285535pgh.320.1557726588398; Sun, 12 May 2019 22:49:48 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id z124sm16062375pfz.116.2019.05.12.22.49.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 12 May 2019 22:49:47 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Mon, 13 May 2019 14:49:25 +0900 Message-Id: <20190513054927.17890-3-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190513054927.17890-1-takahiro.akashi@linaro.org> References: <20190513054927.17890-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH 2/4] fs: fat: flush a directory cluster properly X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" When a long name directory entry is created, multiple directory entries may be occupied across a directory cluster boundary. Since only one directory cluster is cached in a directory iterator, a first cluster must be written back to device before switching over a second cluster. Without this patch, some added files may be lost even if you don't see any failures on write operation. Signed-off-by: AKASHI Takahiro Tested-by: Heinrich Schuchardt --- fs/fat/fat_write.c | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c index 3bc0dd637521..da1753d545ac 100644 --- a/fs/fat/fat_write.c +++ b/fs/fat/fat_write.c @@ -209,7 +209,8 @@ name11_12: return 1; } -static int flush_dir_table(fat_itr *itr); +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 @@ -242,19 +243,15 @@ fill_dir_slot(fat_itr *itr, const char *l_name) memcpy(itr->dent, slotptr, sizeof(dir_slot)); slotptr--; counter--; + + if (itr->remaining == 0) + flush_dir(itr); + if (!fat_itr_next(itr)) - if (!itr->dent && !itr->is_root && flush_dir_table(itr)) + if (!itr->dent && !itr->is_root && new_dir_table(itr)) return -1; } - if (!itr->dent && !itr->is_root) - /* - * don't care return value here because we have already - * finished completing an entry with name, only ending up - * no more entry left - */ - flush_dir_table(itr); - return 0; } @@ -621,18 +618,14 @@ static int find_empty_cluster(fsdata *mydata) } /* - * Write directory entries in itr's buffer to block device + * Allocate a cluster for additional directory entries */ -static int flush_dir_table(fat_itr *itr) +static int new_dir_table(fat_itr *itr) { fsdata *mydata = itr->fsdata; int dir_newclust = 0; unsigned int bytesperclust = mydata->clust_size * mydata->sect_size; - if (set_cluster(mydata, itr->clust, itr->block, bytesperclust) != 0) { - printf("error: writing directory entry\n"); - return -1; - } dir_newclust = find_empty_cluster(mydata); set_fatent_value(mydata, itr->clust, dir_newclust); if (mydata->fatsize == 32) @@ -987,7 +980,7 @@ static dir_entry *find_directory_entry(fat_itr *itr, char *filename) return itr->dent; } - if (!itr->dent && !itr->is_root && flush_dir_table(itr)) + if (!itr->dent && !itr->is_root && new_dir_table(itr)) /* indicate that allocating dent failed */ itr->dent = NULL; @@ -1172,14 +1165,16 @@ int file_fat_write_at(const char *filename, loff_t pos, void *buffer, memset(itr->dent, 0, sizeof(*itr->dent)); - /* Set short name to set alias checksum field in dir_slot */ + /* Calculate checksum for short name */ set_name(itr->dent, filename); + + /* Set long name entries */ if (fill_dir_slot(itr, filename)) { ret = -EIO; goto exit; } - /* Set attribute as archive for regular file */ + /* Set short name entry */ fill_dentry(itr->fsdata, itr->dent, filename, 0, size, 0x20); retdent = itr->dent; From patchwork Mon May 13 05:49:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1098661 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="DmyPas7/"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 452VLR6S7xz9sBr for ; Mon, 13 May 2019 15:51:27 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 90B1DC21EE5; Mon, 13 May 2019 05:50:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id B1932C21ECA; Mon, 13 May 2019 05:50:02 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 0FE1DC21EE3; Mon, 13 May 2019 05:49:53 +0000 (UTC) Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com [209.85.210.195]) by lists.denx.de (Postfix) with ESMTPS id ADA1DC21EE3 for ; Mon, 13 May 2019 05:49:52 +0000 (UTC) Received: by mail-pf1-f195.google.com with SMTP id v80so6577870pfa.3 for ; Sun, 12 May 2019 22:49:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=92navjrFEoO+jjF1XDsnouVBrx0e0+dsjONl8lKaFSU=; b=DmyPas7/QZk5IVOB6Wk2QsLnENlEnDc/9BfvlrtPKlSJxNAEHGxQVfF74D3NiOxFDQ V7iLz0IbZc/pgYPEAA6HgCNqIRqjCLDj57L5J2urj++zPfbdFH962Y4FREkmgepuC13b VNYZfs89i+f8IBLuQIvH8MvSnQVuekmZNNirpgOk+2d9wlbJ3xVJNkmcjYkQkGP45EMr fXH1zED+oWsI4RJV+xIdyxTPWEWvit8sZ9x3fL3Mndcd3MBbuGfuZm6zKAVbB96ZrUh3 7BL37ZJ6nElCxpm449z8qW6G4SFW7JA46VkhzYx7IRBBRk7ljqf3dZIqn7d6Pv+s5IhZ AYGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=92navjrFEoO+jjF1XDsnouVBrx0e0+dsjONl8lKaFSU=; b=SpuxkzRVPR09apZ2qiZ/14q1OLYiyBUUDntN4CMbHBGBZW9FlyCFzTbNYblqL7oCE3 pbnOG1UdO5K296mptVFsZNhzl9yP7IGWuHDyKRwgyvoPBkE5sfWyZ9OXQV89XuNUCiAN hkNRwerbkNd4D+28pFVdNGT1CfjiYeDYztq4ClNFTB725nFYsqR22RPPp5DxCo7INkMv yyl8jy1uR4XIuckEYRkqp5qqUKNfNW3a0b2pzIoMiJ82J2lDrQsbtOrkNCOcvJM0uzRx xVY+PtLCPRgHRKAonUvkEf9U2PdPWzRTT4+c7B0pD0iLZ4TtLw7ToMTUfkYw3XFi4IuW teGQ== X-Gm-Message-State: APjAAAVKlUtZdRyLqh4MtuiSRNOyFVayaZOt1lSBFHAWpIxHkYGv/aOV DmanCAuUTvlZgVCrLjjK9VPgSg== X-Google-Smtp-Source: APXvYqx7N6AS1jXqJxm9KY1Ws4I7XmqHrb+q6uJP93rivacZ72k10X6PD6v+3DTJxSM5eq7omScYDw== X-Received: by 2002:a63:7887:: with SMTP id t129mr28519517pgc.339.1557726591395; Sun, 12 May 2019 22:49:51 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id r124sm9602168pgr.91.2019.05.12.22.49.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 12 May 2019 22:49:50 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Mon, 13 May 2019 14:49:26 +0900 Message-Id: <20190513054927.17890-4-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190513054927.17890-1-takahiro.akashi@linaro.org> References: <20190513054927.17890-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH 3/4] fs: fat: allocate a new cluster for root directory of fat32 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Contrary to fat12/16, fat32 can have root directory at any location and its size can be expanded. Without this patch, root directory won't grow properly and so we will eventually fail to add files under root directory. Please note that this can happen even if you delete many files as deleted directory entries are not reclaimed but just marked as "deleted" under the current implementation. Signed-off-by: AKASHI Takahiro Tested-by: Heinrich Schuchardt --- fs/fat/fat_write.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c index da1753d545ac..3bb9eac097eb 100644 --- a/fs/fat/fat_write.c +++ b/fs/fat/fat_write.c @@ -247,8 +247,11 @@ fill_dir_slot(fat_itr *itr, const char *l_name) if (itr->remaining == 0) flush_dir(itr); + /* allocate a cluster for more entries */ if (!fat_itr_next(itr)) - if (!itr->dent && !itr->is_root && new_dir_table(itr)) + if (!itr->dent && + (!itr->is_root || itr->fsdata->fatsize == 32) && + new_dir_table(itr)) return -1; } @@ -980,7 +983,10 @@ static dir_entry *find_directory_entry(fat_itr *itr, char *filename) return itr->dent; } - if (!itr->dent && !itr->is_root && new_dir_table(itr)) + /* 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; From patchwork Mon May 13 05:49:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1098660 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="rxHFTVME"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 452VL4514Bz9sBr for ; Mon, 13 May 2019 15:51:08 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 63EE3C21E1A; Mon, 13 May 2019 05:50:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 4FF01C21EFF; Mon, 13 May 2019 05:50:05 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 3D92AC21EA8; Mon, 13 May 2019 05:49:55 +0000 (UTC) Received: from mail-pl1-f195.google.com (mail-pl1-f195.google.com [209.85.214.195]) by lists.denx.de (Postfix) with ESMTPS id 726B8C21F07 for ; Mon, 13 May 2019 05:49:55 +0000 (UTC) Received: by mail-pl1-f195.google.com with SMTP id f97so776648plb.5 for ; Sun, 12 May 2019 22:49:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OtudRxkpVsPGnu/d4oKlB2NmGILNJ5VYh8b5JrI/WoE=; b=rxHFTVMEcnIFmaClKhMv6ZixR721xbX/1VHqLzQGPD+WTZwFBQVHa/uj5knDXVSPyI O3ZknS9xNBKK0MC13Y/7XqofzE7jkzOVPGT4THGmVSHeg+yC8fBlk8Az1jwH7Dyqaivx DYDQG2Y2inGWvX+h9MNQS5TGVOaUT9KETXg/alOs/5nJA3us7QZ059x3kfZPDROVjatw 0WWaVPUiLwIOK8nDTuHGiS68VLasc78/Nxxtn8uZE3z7hEfvwoWo2pJBb+XeTEHCdMdz AFGIvP4/tytoKla2JTTmTKMGtc12n+funz1S66QdRUa5LdWK2PWICXT/8YyAmRyqwENx 500A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OtudRxkpVsPGnu/d4oKlB2NmGILNJ5VYh8b5JrI/WoE=; b=TlcCc406bDy+mKvqduamWPHstCM/52PQzjjg9YwRVDkaFIeqkYogUdy7VTbz9k3RL+ i74oIANsFbnneU6SKRLXLxQZXdaD3lOO2oulmlmH9efGKJa1etVODUWLZ56WWgyM2Bee u4oS2dXOs/pFtqG/+Egw3NcUt08lp46DgJq2IKpeExGawSaEHXi9LWIZ3r8JwF7iJlfv p946MZmBnFjrRCrtZ7kFL+SQe+GDZmFUa5N5X0CYjBMQNmLcpp+17FYe3Bb/SAWkAoar bYR0QVGECakG212Eb1i+9Kyxh6rXpxTVbAeeFq+nkHBjxZQe+aKPxeOHkNPowB0D3NPK DYrA== X-Gm-Message-State: APjAAAVPdEUVUh2r5I0+IGJp6rWO8mFVzgBEOoj8rpd+nxAulXbxo0f6 nmHPIfo8lS1DwLNPAm+Zyg3/0w== X-Google-Smtp-Source: APXvYqwD1n73UWbv/u7zwteRyHPnJj5agay91J0ZBRq2I1MG5ZiP5vpNvEGKVGaQ20xu+mnh4q4QjA== X-Received: by 2002:a17:902:12f:: with SMTP id 44mr28748485plb.193.1557726594122; Sun, 12 May 2019 22:49:54 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id v2sm5837778pgr.2.2019.05.12.22.49.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 12 May 2019 22:49:53 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Mon, 13 May 2019 14:49:27 +0900 Message-Id: <20190513054927.17890-5-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190513054927.17890-1-takahiro.akashi@linaro.org> References: <20190513054927.17890-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH 4/4] test/py: test_fs: add tests for creating/deleting many files X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Two test cases are added under test_fs_ext: test case 10: for root directory test case 11: for non-root directory Those will verify a behavior fixed by the commits related to root directory ("fs: fat: allocate a new cluster for root directory of fat32" and "fs: fat: flush a directory cluster properly"). Signed-off-by: AKASHI Takahiro --- test/py/tests/test_fs/test_ext.py | 84 +++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/test/py/tests/test_fs/test_ext.py b/test/py/tests/test_fs/test_ext.py index 2c47738b8df2..361f440dd6d4 100644 --- a/test/py/tests/test_fs/test_ext.py +++ b/test/py/tests/test_fs/test_ext.py @@ -233,3 +233,87 @@ class TestFsExt(object): % (fs_type, ADDR, MIN_FILE)]) assert('Unable to write "/dir1' in ''.join(output)) assert_fs_integrity(fs_type, fs_img) + + def test_fs_ext10(self, u_boot_console, fs_obj_ext): + """ + 'Test Case 10 - create/delete as many directories under root directory + as amount of directory entries goes beyond one cluster size)' + """ + fs_type,fs_img,md5val = fs_obj_ext + with u_boot_console.log.section('Test Case 10 - create/delete (many)'): + # Test Case 10a - Create many files + # Please note that the size of directory entry is 32 bytes. + # So one typical cluster may holds 64 (2048/32) entries. + output = u_boot_console.run_command( + 'host bind 0 %s' % fs_img) + + for i in range(0, 66): + output = u_boot_console.run_command( + '%swrite host 0:0 %x /FILE0123456789_%02x 100' + % (fs_type, ADDR, i)) + output = u_boot_console.run_command('%sls host 0:0 /' % fs_type) + assert('FILE0123456789_00' in output) + assert('FILE0123456789_41' in output) + + # Test Case 10b - Delete many files + for i in range(0, 66): + output = u_boot_console.run_command( + '%srm host 0:0 /FILE0123456789_%02x' + % (fs_type, i)) + output = u_boot_console.run_command('%sls host 0:0 /' % fs_type) + assert(not 'FILE0123456789_00' in output) + assert(not 'FILE0123456789_41' in output) + + # Test Case 10c - Create many files again + # Please note no.64 and 65 are intentionally re-created + for i in range(64, 128): + output = u_boot_console.run_command( + '%swrite host 0:0 %x /FILE0123456789_%02x 100' + % (fs_type, ADDR, i)) + output = u_boot_console.run_command('%sls host 0:0 /' % fs_type) + assert('FILE0123456789_40' in output) + assert('FILE0123456789_79' in output) + + assert_fs_integrity(fs_type, fs_img) + + def test_fs_ext11(self, u_boot_console, fs_obj_ext): + """ + 'Test Case 11 - create/delete as many directories under non-root + directory as amount of directory entries goes beyond one cluster size)' + """ + fs_type,fs_img,md5val = fs_obj_ext + with u_boot_console.log.section('Test Case 10 - create/delete (many)'): + # Test Case 11a - Create many files + # Please note that the size of directory entry is 32 bytes. + # So one typical cluster may holds 64 (2048/32) entries. + output = u_boot_console.run_command( + 'host bind 0 %s' % fs_img) + + for i in range(0, 66): + output = u_boot_console.run_command( + '%swrite host 0:0 %x /dir1/FILE0123456789_%02x 100' + % (fs_type, ADDR, i)) + output = u_boot_console.run_command('%sls host 0:0 /dir1' % fs_type) + assert('FILE0123456789_00' in output) + assert('FILE0123456789_41' in output) + + # Test Case 11b - Delete many files + for i in range(0, 66): + output = u_boot_console.run_command( + '%srm host 0:0 /dir1/FILE0123456789_%02x' + % (fs_type, i)) + output = u_boot_console.run_command('%sls host 0:0 /dir1' % fs_type) + assert(not 'FILE0123456789_00' in output) + assert(not 'FILE0123456789_41' in output) + + # Test Case 11c - Create many files again + # Please note no.64 and 65 are intentionally re-created + for i in range(64, 128): + output = u_boot_console.run_command( + '%swrite host 0:0 %x /dir1/FILE0123456789_%02x 100' + % (fs_type, ADDR, i)) + output = u_boot_console.run_command('%sls host 0:0 /dir1' % fs_type) + assert('FILE0123456789_40' in output) + assert('FILE0123456789_79' in output) + + assert_fs_integrity(fs_type, fs_img)