From patchwork Sun Sep 10 11:21:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 812120 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; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="gIEJyrNE"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3xqpy357qyz9sDB for ; Sun, 10 Sep 2017 21:39:55 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 5B76BC21F14; Sun, 10 Sep 2017 11:30:06 +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=FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, 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 1FB3FC21E41; Sun, 10 Sep 2017 11:26:35 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id DB32FC21F45; Sun, 10 Sep 2017 11:23:33 +0000 (UTC) Received: from mail-qt0-f196.google.com (mail-qt0-f196.google.com [209.85.216.196]) by lists.denx.de (Postfix) with ESMTPS id 03587C21EA8 for ; Sun, 10 Sep 2017 11:23:30 +0000 (UTC) Received: by mail-qt0-f196.google.com with SMTP id l25so1177894qtf.2 for ; Sun, 10 Sep 2017 04:23:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=jouUYn8AbqMaxmwkCld1nTQE8E82NXJX/dNooW9ErIs=; b=gIEJyrNEHMaCpDUs1KWdN8zhVGuekY1bv18ZlpiLPMrU5mjJog7H1lGdzlWieEZioi 2beoq77YAEFC6mDIjT/QSsgqV488lGETMLUSPaTS5+tLGJPNECZuShXOP+GJlwTqIukH dPAv8jLc+gUhEqwnb8DUTEcIlDekCR5KrYlb4UJTrOJb0sM0/5cCObS+WuLG9xmL9U++ Mf/Nro30i/f7H2MiTuvYBCH883/dBhHuVK3tTHVW+4GmNXTK9+uOOw9gVOfPIbRS85tp OFheRfnga4HcNcZiLslHbP9Qkb+zVluJuRx0reodxt5scT1LYwp7mFhmf2bCERkvYh3p SrGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=jouUYn8AbqMaxmwkCld1nTQE8E82NXJX/dNooW9ErIs=; b=N+Pk/jIweuxWqIOII3zacCeY8mJ8l5Y1ynJakBvz+WReTHZJj5L6z2dKOH93fkGJcI wHjgwSmmBEs/MV1S+PhzuXIovJOa1MXRxqWVjFZZ0GFbafve0gOL+x0zbdPEB5IlXois RUbAafdxhr3TafZPr8FqA738V0ZVeZN2yDO61AMnRYL23uJHjm+koGPnk5ZZdfO89lg2 RyrvxtATt6FDCZ4moZsGEezaoCYr9SKg3WemlYP9Iqf+oNOlXQH8XXVQDlsumsvTa5eW fcbea/2+aWxec9TEaiPubz4Lxwv4K6kBRdIsTs1dngrF29AP2QBiTOwBRQJRPWogRiNV ik7A== X-Gm-Message-State: AHPjjUhdtXijWzj13lhnGgFmghDPqX9HX48XEkWocVm/7PUJIjja6POb zFUDfn9+Jy3jDC1c4jw= X-Google-Smtp-Source: AOwi7QD2/nBrW+GWIVYXtpy6sUrMHSDeC53HmM3Fa6DUHCG/LfOkjUhujLunVtOUu+Ny7xc7Lkrwew== X-Received: by 10.200.40.231 with SMTP id j36mr11589446qtj.270.1505042608744; Sun, 10 Sep 2017 04:23:28 -0700 (PDT) Received: from localhost ([2601:184:4780:aac0:25f8:dd96:a084:785a]) by smtp.gmail.com with ESMTPSA id h40sm4368336qte.73.2017.09.10.04.23.27 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 10 Sep 2017 04:23:27 -0700 (PDT) From: Rob Clark To: U-Boot Mailing List Date: Sun, 10 Sep 2017 07:21:35 -0400 Message-Id: <20170910112149.21358-19-robdclark@gmail.com> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170910112149.21358-1-robdclark@gmail.com> References: <20170910112149.21358-1-robdclark@gmail.com> Cc: Stephen Warren , Heinrich Schuchardt , Philipp Skadorov , Genevieve Chan , Tien Fong Chee Subject: [U-Boot] [PATCH v3 9/9] fs/fat: Clean up open-coded sector <-> cluster conversions X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Use the clust_to_sect() helper that was introduced earlier, and add an inverse sect_to_clust(), plus update the various spots that open-coded this conversion previously. Signed-off-by: Rob Clark --- fs/fat/fat.c | 8 +++----- fs/fat/fat_write.c | 8 +++----- include/fat.h | 6 +++++- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/fs/fat/fat.c b/fs/fat/fat.c index 65873a2c2a..f5f74c12ff 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -257,8 +257,7 @@ get_cluster(fsdata *mydata, __u32 clustnum, __u8 *buffer, unsigned long size) int ret; if (clustnum > 0) { - startsect = mydata->data_begin + - clustnum * mydata->clust_size; + startsect = clust_to_sect(mydata, clustnum); } else { startsect = mydata->rootdir_sect; } @@ -594,9 +593,8 @@ static int get_fs_info(fsdata *mydata) mydata->data_begin = mydata->rootdir_sect + mydata->rootdir_size - (mydata->clust_size * 2); - mydata->root_cluster = (mydata->rootdir_sect - - mydata->data_begin) / - mydata->clust_size; + mydata->root_cluster = + sect_to_clust(mydata, mydata->rootdir_sect); } mydata->fatbufnum = -1; diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c index d0468baf8f..9d2e0ed74c 100644 --- a/fs/fat/fat_write.c +++ b/fs/fat/fat_write.c @@ -502,8 +502,7 @@ set_cluster(fsdata *mydata, __u32 clustnum, __u8 *buffer, int ret; if (clustnum > 0) - startsect = mydata->data_begin + - clustnum * mydata->clust_size; + startsect = clust_to_sect(mydata, clustnum); else startsect = mydata->rootdir_sect; @@ -751,8 +750,7 @@ static int check_overflow(fsdata *mydata, __u32 clustnum, loff_t size) __u32 startsect, sect_num, offset; if (clustnum > 0) { - startsect = mydata->data_begin + - clustnum * mydata->clust_size; + startsect = clust_to_sect(mydata, clustnum); } else { startsect = mydata->rootdir_sect; } @@ -791,7 +789,7 @@ static dir_entry *empty_dentptr; static dir_entry *find_directory_entry(fsdata *mydata, int startsect, char *filename, dir_entry *retdent, __u32 start) { - __u32 curclust = (startsect - mydata->data_begin) / mydata->clust_size; + __u32 curclust = sect_to_clust(mydata, startsect); debug("get_dentfromdir: %s\n", filename); diff --git a/include/fat.h b/include/fat.h index 0f58939124..bdeda95e6d 100644 --- a/include/fat.h +++ b/include/fat.h @@ -177,12 +177,16 @@ typedef struct { __u32 root_cluster; /* First cluster of root dir for FAT32 */ } fsdata; -/* TODO clean up places that are open-coding this: */ static inline u32 clust_to_sect(fsdata *fsdata, u32 clust) { return fsdata->data_begin + clust * fsdata->clust_size; } +static inline u32 sect_to_clust(fsdata *fsdata, u32 sect) +{ + return (sect - fsdata->data_begin) / fsdata->clust_size; +} + int file_fat_detectfs(void); int fat_exists(const char *filename); int fat_size(const char *filename, loff_t *size);