From patchwork Fri May 24 05:10:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1104601 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=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="kP+GR31t"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 459F0r75BKz9s4V for ; Fri, 24 May 2019 15:14:36 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 94A23C21E42; Fri, 24 May 2019 05:10:59 +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 5DA01C21E29; Fri, 24 May 2019 05:10:31 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id EAA86C21E3A; Fri, 24 May 2019 05:10:20 +0000 (UTC) Received: from mail-pf1-f194.google.com (mail-pf1-f194.google.com [209.85.210.194]) by lists.denx.de (Postfix) with ESMTPS id A744AC21E8A for ; Fri, 24 May 2019 05:10:16 +0000 (UTC) Received: by mail-pf1-f194.google.com with SMTP id n19so4579084pfa.1 for ; Thu, 23 May 2019 22:10:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gT83Bnam5qj34g0r19V2uzwN1+LyES5WYbniRadcb3Y=; b=kP+GR31tZ4VLvaUNk6GgShGKqscAe5Rt3mUI+JrSp/aEhVirPjBUavSQOOAcmDYRmz MKpZW1x3M2Lwsbovrp3HZ06eIRFtWf9vBUbEnvxG+G5JIqQN6FeweFWnT8a27pb9DUlE ndDypgWkk9d3GbubaSJWh261miC2kSIKCKlTXxafE/KhSmIDz5YP3n4kqTgZ554izPWY t++JnfJX/qqqPcxrBOVd1KZ+dP/+4OWooEVA2gOmOBlh0hLslt7OJ1MGtiGwm5ZlYzXh 1IOqhvO/XsflRPXdH7MVvLKOwlaFBMgXKlFJS5cJqeYsTC3d+K0SvFp9bXNV+6HGhgjn hvCw== 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=gT83Bnam5qj34g0r19V2uzwN1+LyES5WYbniRadcb3Y=; b=Bc9jWhh0ggnZi1iCaw+9mkse6TKKKO1+L22pvQiiIq2Tckc/gozfP3NOUjE+Ou8+oA jzfqQtQXDEO9Z8ZAVZy3wsLOXXBGD3WmZisFcn+yjwYL312+NCdzSdqIVUswhT+BsIH2 E6qKr3c6leBXW0vZuwuEjFuWJYRfYETAwXKXfmlsNVZadvb2Z8RdDxJ/6Pe0WPDoCFT1 aki52IMPTlPfmWg5Joo90GMnF9c96t3+pRtC5JWvVVOR0FHPxUzDFkWWiLmXnwDjZzp7 dG9UECb0mxymt9+g1nQ0Vqj0o8alGOWcUem+puiqCPjgGjKT5lEIXWwe68I5UDq73/95 U+jw== X-Gm-Message-State: APjAAAWgxtyogIU1I9dOMUzjkfK4nBhOQbNXU4CwCBcQ50xBfT513Z4e UEPkCd+QXAJMAyn4nlIXZzymCg== X-Google-Smtp-Source: APXvYqy0BGBxmP0rpMtR29CY6tw5quzCNbW1LMVPDcHAm8D8jfhhtJichkn1B5NIlBMRJbpklJblFg== X-Received: by 2002:a17:90a:5d15:: with SMTP id s21mr6437913pji.126.1558674615259; Thu, 23 May 2019 22:10:15 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id r71sm3863835pjb.2.2019.05.23.22.10.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 May 2019 22:10:14 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Fri, 24 May 2019 14:10:35 +0900 Message-Id: <20190524051039.32460-2-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190524051039.32460-1-takahiro.akashi@linaro.org> References: <20190524051039.32460-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de, xypron.glpk@gmx.de Subject: [U-Boot] [PATCH v2 1/5] 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_write.c | 78 +++++++++++++++++++++++++++++++--------------- 1 file changed, 53 insertions(+), 25 deletions(-) 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 Fri May 24 05:10:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1104596 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=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="RTnfgSaC"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 459Dwx5B2wz9s00 for ; Fri, 24 May 2019 15:11:13 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 68FB1C21E45; Fri, 24 May 2019 05:10:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id D7E7DC21E7D; Fri, 24 May 2019 05:10:30 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id A8B5EC21EFC; Fri, 24 May 2019 05:10:24 +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 B5387C21EE7 for ; Fri, 24 May 2019 05:10:19 +0000 (UTC) Received: by mail-pf1-f195.google.com with SMTP id y11so4547084pfm.13 for ; Thu, 23 May 2019 22:10:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YjMijJq/KLTPbeRIkRrr6O68114GKgB+GxJiZK8XNzQ=; b=RTnfgSaCcIBXI5a5c0/YY0VtlxPFbdJZVi7VVCUbzSyhNBqZZmDFu4VgmGxX3p0zDv d0nw2W39WfhbUdQmEBfint2D1lpCVIgvjo9LtlKAVN8GbNuJ8oVKqqKZ4QRX22BYpq/L iixYQNaNgOVJ9dnYSpNEEk/wbdmH9OYvBd2NeFQlsDfBjfA81h9URSCgsSgWEuISnXCO xgJf9Ecu4hhCSTR1CFzKAell5byf8sq9jq2+i0wPojZOrS8IT2lCVV3RIQo4Hsig2OLq GT26fFjjuPapYUAel6Jq1J5/YWfUREHMGzO119v/2122GRC1LC+XGT2eHq5eUryaw7jS bzEQ== 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=YjMijJq/KLTPbeRIkRrr6O68114GKgB+GxJiZK8XNzQ=; b=oupEFFykDa4hGjHCVdkalu9teu+m/fsR5rI9rdFyypvrCMqa3gvwUam+PLqBXMZ/aK R7fyFLg99MiF9y4ulWwXz1AU3bLKzrUYsJWyWz1R9ZouHUqcOi5O2Ic9OYRhWpsk3tE7 KLbaBroyKmTqlefJZoSsgo68Nomu0pXZ5RDLlzO+vw0L3/xGFFmbOsKHR+E5nzCsBBIK 9wmm8clc5hmXKOXY7cWhvlL2o6cWI6PaueqCyhqXqKOVTyVJGxPV3iDXuvO9HFv3o1/I /yCR0BR5IjK6rWRcN9Z036Xnm3ELWYkxtF5J8Sivr7ZdcleT/nOBLFvvtAcRJ49GxKrF Zp6A== X-Gm-Message-State: APjAAAUABcUlBYXAaN1DNA2tGBCZLwOo0A7bkUV4WFGeWdh08I2u6KhY nczEXfYFV0N7LRrnub9Y149UIw== X-Google-Smtp-Source: APXvYqxsUQYmKybSD7kMKab5Suzjjb++qviesAvZX35NSEC2hV4BvMZZaTJVA8DhXwaQGoeeR2F+/g== X-Received: by 2002:a63:364f:: with SMTP id d76mr46339024pga.100.1558674618332; Thu, 23 May 2019 22:10:18 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id e24sm911973pgl.94.2019.05.23.22.10.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 May 2019 22:10:17 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Fri, 24 May 2019 14:10:36 +0900 Message-Id: <20190524051039.32460-3-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190524051039.32460-1-takahiro.akashi@linaro.org> References: <20190524051039.32460-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de, xypron.glpk@gmx.de Subject: [U-Boot] [PATCH v2 2/5] 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 Fri May 24 05:10:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1104599 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=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="vAsCsnUW"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 459Dz12YKjz9s3l for ; Fri, 24 May 2019 15:13:01 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id E758AC21EFB; Fri, 24 May 2019 05:11:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id E67D7C21DC1; Fri, 24 May 2019 05:10:31 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id E5EDCC21E42; Fri, 24 May 2019 05:10:24 +0000 (UTC) Received: from mail-pf1-f194.google.com (mail-pf1-f194.google.com [209.85.210.194]) by lists.denx.de (Postfix) with ESMTPS id 8F1E3C21EE8 for ; Fri, 24 May 2019 05:10:22 +0000 (UTC) Received: by mail-pf1-f194.google.com with SMTP id n19so4579241pfa.1 for ; Thu, 23 May 2019 22:10:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LyUAgKtaHDdnOdsheMra9+lKr/rtSI+YJ7rAfU01YRQ=; b=vAsCsnUWSC9SvxZg+eNFz2C8H5KTf/DH2Ms63xCWF66zW52uJqepqJc/Ayhda6Xdr8 0CCLY0L5MG+Ba+kJlY8U/TQAcwwPK195xmhB+yHr/he/7QEv3E9zTOMCui5qp+HgCxrb wKBtJ2R8X4Ea1JA4Q4Xl5jnP12QrCvZyxykqDcm71FN1HJ2pEEjRtNcF880l2qrEIzzz r8qnCKkv352lLiZwinDYfQQh7vIQHmKvcCz0jcF8Wld6AGLbqB9piNzjK4VvEeZbza9I SzDapqjbTdOD4/ATOAbRTY/rqv2vxBRyKLSu0BEt02sP5qlKXDZqlRzWScks7E71nDBM m1lQ== 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=LyUAgKtaHDdnOdsheMra9+lKr/rtSI+YJ7rAfU01YRQ=; b=t8eExQb1fQnJBJZNWoekIrCv2eYD5Z0AaLktxUFfA5l/wBu739bg3ltZgwGfyAATgD ruXLoePANVW/5mDnLyFs5/kPdt8nJZb3JnmTImpVVURtwyWCttl7RmzMOsFnTZ2AoBVB 91w+UfvbS4dP6pt+J6iG1Wmqtcac1rVeSO8Rz8hKW3ep5Ty375m2CpVFI8lejt+4F9on qdRsygEsS4GhDth3CxtHyLF/mjPkH+BQR335+qHq/3Vke4cWonG7YJ6GDwxQJsf6iV+c tJTTwasuUgC/Da4GK5qDhMMer1PRyBUOfl4Wkr4QR7szLjqBVZ95gJPsD6Jum8HsWMWb pbVQ== X-Gm-Message-State: APjAAAWnVgejEtlIZ91J1m8+vl5cGC3EelXbEbGR1akWEdcU3gRgAFm8 WmxDxvPbGrzVOH0GizGKVu1Tew== X-Google-Smtp-Source: APXvYqz7R+sUx5z8iOL/3oNVH24ZU1xTv34zPfmmqezWREcbM4cGzA+xsdFDevvKPzzxw1HTHJ03Yw== X-Received: by 2002:a62:1cd5:: with SMTP id c204mr71184077pfc.205.1558674621290; Thu, 23 May 2019 22:10:21 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id t64sm3816778pjb.0.2019.05.23.22.10.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 May 2019 22:10:20 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Fri, 24 May 2019 14:10:37 +0900 Message-Id: <20190524051039.32460-4-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190524051039.32460-1-takahiro.akashi@linaro.org> References: <20190524051039.32460-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de, xypron.glpk@gmx.de Subject: [U-Boot] [PATCH v2 3/5] 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 Fri May 24 05:10:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1104598 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=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="NU0+mMk/"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 459Dxz2k4Bz9s3l for ; Fri, 24 May 2019 15:12:07 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 0B804C21E15; Fri, 24 May 2019 05:11:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 76166C21EE8; Fri, 24 May 2019 05:10:37 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 922F9C21EF2; Fri, 24 May 2019 05:10:26 +0000 (UTC) Received: from mail-pg1-f193.google.com (mail-pg1-f193.google.com [209.85.215.193]) by lists.denx.de (Postfix) with ESMTPS id A5B3FC21E42 for ; Fri, 24 May 2019 05:10:25 +0000 (UTC) Received: by mail-pg1-f193.google.com with SMTP id d30so4354260pgm.7 for ; Thu, 23 May 2019 22:10:25 -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=hYfCDiMMk6aXknv2ebdLzEAt8ZkcMLFEvgzvtSNPA90=; b=NU0+mMk/A5CmpZqkuXOYbbRssPpq3DtylhBx/k1LWmJ3IZPTgeu7A4dMXoRItx6xVB UVXyWVg7hBehiMkYvz8T18MaNfiTook37/WVsoPCwajCH8+gt+kjhYrV2J+J4GSKZOo7 fILvd8kX4/mddqI/l7GdIj9cS83nmc3RrjdHDW0Kd8KooXtLOV4Y+fU8tTfSW4vi0FIf vB5sLnH5zUKTqXrw+iMFSB3jG27D6uTGoC3I+ef12J1p6PaSBv3lXpCzo8D3Uv4qnmJ/ EOekNXndm+uGDFOWrFySnf1rsdakT6dl9+8Ku4Iv97K3CYyCz/XoBiJLnkla+yMiW3H9 9QCQ== 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=hYfCDiMMk6aXknv2ebdLzEAt8ZkcMLFEvgzvtSNPA90=; b=gN9Wi/J7lIdaldmASgrm31f0vBMaXH/d67UQpHJwfxRUqNK1WdeHJNZMHTWvrACdvw krk8iB5XEg79R/yJXU+66rcZK5KneqKVSNQy8wy/Mqhb6i7O0l7Unvn+B0CoxPbw1uWC JXvPmSRwVBBWy8U6u0YUvmnPyqxQh9WoKGYUfk0iwCX7O8d9KJ2MS9jZ36+++iPu6SvS L5cmNQSaOWGa3XDK7GxnVi5xTN4wCeeWbwQBAtAI/PbXX9dVrLQ6XXOlpps4zBqO6J7o yx0jZl9koe8+fkkE2cMfHgKT/KyOqBkwWwq3/BirhasdXutSzErjgSfrea0DheWrR0xm z1tA== X-Gm-Message-State: APjAAAU6xewoXXUCzFUhkaGZjtYlFWrogq4PXkgoqSMO2RLXi/k2bTHy Lw0tyVLbbXMzdVMs4d1b1b7z2w== X-Google-Smtp-Source: APXvYqwKCF9vcFOkifmIOVHI38YVN2zmWzk9Vz00lwlA+i4EJ/XkPEm5VQYCbl4SkXGCgqNyLBNtHg== X-Received: by 2002:a63:c64a:: with SMTP id x10mr101833689pgg.195.1558674624144; Thu, 23 May 2019 22:10:24 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id v93sm948626pjb.6.2019.05.23.22.10.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 May 2019 22:10:23 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Fri, 24 May 2019 14:10:38 +0900 Message-Id: <20190524051039.32460-5-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190524051039.32460-1-takahiro.akashi@linaro.org> References: <20190524051039.32460-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de, xypron.glpk@gmx.de Subject: [U-Boot] [PATCH v2 4/5] 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"), and focus on handling long-file-name directory entries under a directory. 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) From patchwork Fri May 24 05:10:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1104600 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=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="x0Z14Afu"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 459DzM15zzz9s3l for ; Fri, 24 May 2019 15:13:19 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id CE9C5C21EE8; Fri, 24 May 2019 05:11:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 1086CC21EC8; Fri, 24 May 2019 05:10:48 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 158DBC21DB3; Fri, 24 May 2019 05:10:29 +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 7525FC21DAF for ; Fri, 24 May 2019 05:10:28 +0000 (UTC) Received: by mail-pl1-f195.google.com with SMTP id g21so3688563plq.0 for ; Thu, 23 May 2019 22:10:28 -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=1sGywnKJfHoDeb0TWTZuvn/ivF87HwqCvlXTsi5myw8=; b=x0Z14AfuAfK3UYPmeRsd7BcYxB3LjrRSg7Ypaw0SrI9/SmDjcKIeYo9FESzp4Fs50T d4V8phOMV1bpDaKgquG/YMmU8sTyNHOA825lFPJ5neml/yfnbHbqguhNC9+CQuXHxilP P+qiOwj5pQbZzV3RiQ72ifwYUNhfloazjLOu72iIJdqTdxx3Zd3MkJPAdma9C5zNUXof s9Wnlr9JcyDYtEbPS9KVy3QLfbuc2aDKAhcUCe7tPQHGm+wEo49TKHNbzY+y2O2Eka0b 1NDu3bI8iHtBy3u8OxWKSfWXHQdqH9zulmWAwmjwS7hC1ewJUCrpxXmoS/2mw84x73I7 KJdA== 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=1sGywnKJfHoDeb0TWTZuvn/ivF87HwqCvlXTsi5myw8=; b=l1OOb3h27WZLqU99isNk86gHCKtb7wqsNP2dEtSckQ9k6iiizK+YOSFYqYZy23xLvZ ikPDZc7AL/g/6VLz4LKOz+3aF5lq1yo74NNUc1eeUyZPN7Mk4G8liI2yNVzWVoUUTCh9 Cf2rleyU2P0IWGQ/vjU7K9l0SYEkP0sgI03yfMyEHm9iUSd5CvAsaH0dwEusWPtBOM/u vIYRqJ5kHBFlkJvxax+Rzad/JCioLu0hEkyaTeLTxd2lJJZI6YEK+UL8LhM9O5zrfZvt 08yxhwtAekCusTwkKfhfq3LvYOqFYGeiYPC3rYrypvUTRunmWCDXoVWF1nuPmnInrSzT 8YVQ== X-Gm-Message-State: APjAAAV0bfzO+M5TrUgSNxxJPrVTSXoNCrgg+raHFTq8j22FcF9TQpro YznJRirQzbhviM1093CtvNMewA== X-Google-Smtp-Source: APXvYqxPkHL8qVebwW3JXnF67xC1li8BBROqvyOKNRbASvNQtDAJz7BKA/Dahk5QivIgWdyoxwjyww== X-Received: by 2002:a17:902:e18d:: with SMTP id cd13mr36162329plb.301.1558674626938; Thu, 23 May 2019 22:10:26 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id c127sm1146358pfb.107.2019.05.23.22.10.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 May 2019 22:10:26 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Fri, 24 May 2019 14:10:39 +0900 Message-Id: <20190524051039.32460-6-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190524051039.32460-1-takahiro.akashi@linaro.org> References: <20190524051039.32460-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de, xypron.glpk@gmx.de Subject: [U-Boot] [PATCH v2 5/5] test/py: clarify a package dependency for test_fs 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" File system tests, test_fs, relies on guestmount so that it can be executed in a user mode. Describe this in README.md. Signed-off-by: AKASHI Takahiro --- test/py/README.md | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/test/py/README.md b/test/py/README.md index 2156661d6c42..50b174b51960 100644 --- a/test/py/README.md +++ b/test/py/README.md @@ -25,15 +25,16 @@ On Debian or Debian-like distributions, the following packages are required. Some packages are required to execute any test, and others only for specific tests. Similar package names should exist in other distributions. -| Package | Version tested (Ubuntu 14.04) | -| -------------- | ----------------------------- | -| python | 2.7.5-5ubuntu3 | -| python-pytest | 2.5.1-1 | -| python-subunit | - | -| gdisk | 0.8.8-1ubuntu0.1 | -| dfu-util | 0.5-1 | -| dtc | 1.4.0+dfsg-1 | -| openssl | 1.0.1f-1ubuntu2.22 | +| Package | Version tested (Ubuntu 14.04) | +| --------------- | ----------------------------- | +| python | 2.7.5-5ubuntu3 | +| python-pytest | 2.5.1-1 | +| python-subunit | - | +| gdisk | 0.8.8-1ubuntu0.1 | +| dfu-util | 0.5-1 | +| dtc | 1.4.0+dfsg-1 | +| openssl | 1.0.1f-1ubuntu2.22 | +| libguestfs-tools| 1:1.32.2-4ubuntu2.2 | The test script supports either: