From patchwork Sat Sep 9 17:16:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 811976 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="ZZW9V8zF"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3xqLcK2YHhz9t16 for ; Sun, 10 Sep 2017 03:22:57 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 1FE12C21E8C; Sat, 9 Sep 2017 17:19:43 +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 18ECBC21E8C; Sat, 9 Sep 2017 17:18:57 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 6FDB4C21E7C; Sat, 9 Sep 2017 17:17:08 +0000 (UTC) Received: from mail-qk0-f196.google.com (mail-qk0-f196.google.com [209.85.220.196]) by lists.denx.de (Postfix) with ESMTPS id 779DBC21D04 for ; Sat, 9 Sep 2017 17:17:02 +0000 (UTC) Received: by mail-qk0-f196.google.com with SMTP id i14so3230435qke.3 for ; Sat, 09 Sep 2017 10:17:02 -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=ZZW9V8zFnUvS/zTEclRCsnJqWNfuL100hYRlbNJ6oVszi5yMijUTDrsHEoTFhIEIDg ANRbk47AKZFEjp5dGEl5UFUGrDVobNHCqTaGn4KGFmIm2b7v/uNrrL963Vn6uV8hOQQB iMBW88fU1A8AYZm8zX2r9DAJqI6Ty6pNGPqlErUewXmnD0d6LJNLx94afmRsuXItBYZH dFDn3IVLtUYpZe+pCXNoxxjgGkPzeb6Q+8NnxKWKSo3WwjY2I2ajfIaLWoaUAl4ob3Vl nwtRE/QPtJ3v4HRdUXFbTtRo/30JSF3Bl6IDm90O/MXB6NBv31fe+wEO3r/x4a7+ZeoA 1aTA== 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=BUfo7rzPWRRIKLT/8HLToErOS2RWpX5ssdjUC6lwEFEBPKVVS7wEFaAemnP0yxXUG3 3+KXGrtxuJ1fENS+Fy5JWXly+2xxw4T+KSWz8hTGF+nZISlPiRiBiMuvdPYGrWnlpoeD QDxGB3RGRIUMdRVE9qbYN7qIiToIZGU2+AIQtFCgmMLgQJdY7eWYxFR+208uIIaYT754 jR5DmSRhRuxVSe8gsAXLG+fL9PrI2xbvi+XgZ8CJwNUGRQr/piAQl4O3yzig2ruXUJ8H yV8U5Ohp4gdHDJYC6FcK7m9J1R6EmEURhW2eXdB1MNYO9ZSzg9BOsz9gxceE6KyyHxBD 018g== X-Gm-Message-State: AHPjjUhzqAsaGeg4JMYf9NV4wyrPLjA7bWaRKYeoi+69+zUUqHFSskWC N/FUStl05GgOBg+pwbY= X-Google-Smtp-Source: AOwi7QBPQ3QjAhmBaUvwg5AV9caiWRYvXLBhKrE3tqgiTprYxZFTGzPhhsnLcCz/4h+D6qODC+SIqw== X-Received: by 10.55.52.135 with SMTP id b129mr9259762qka.308.1504977421139; Sat, 09 Sep 2017 10:17:01 -0700 (PDT) Received: from localhost ([2601:184:4780:aac0:25f8:dd96:a084:785a]) by smtp.gmail.com with ESMTPSA id 20sm3233360qtu.77.2017.09.09.10.16.59 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 09 Sep 2017 10:17:00 -0700 (PDT) From: Rob Clark To: U-Boot Mailing List Date: Sat, 9 Sep 2017 13:16:00 -0400 Message-Id: <20170909171606.20029-10-robdclark@gmail.com> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170909171606.20029-1-robdclark@gmail.com> References: <20170909171606.20029-1-robdclark@gmail.com> Cc: Philipp Skadorov , Heinrich Schuchardt , 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 Reviewed-by: Simon Glass --- 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);