public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Rob Clark <robdclark@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v3 9/9] fs/fat: Clean up open-coded sector <-> cluster conversions
Date: Sun, 10 Sep 2017 07:21:35 -0400	[thread overview]
Message-ID: <20170910112149.21358-19-robdclark@gmail.com> (raw)
In-Reply-To: <20170910112149.21358-1-robdclark@gmail.com>

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 <robdclark@gmail.com>
---
 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);
-- 
2.13.5

  parent reply	other threads:[~2017-09-10 11:21 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-10 11:21 [U-Boot] [PATCH v2 00/21] efi_loader: enough UEFI for standard distro boot Rob Clark
2017-09-10 11:21 ` [U-Boot] [PATCH v3 1/9] fs/fat: split out helper to init fsdata Rob Clark
2017-09-10 11:21 ` [U-Boot] [PATCH v2 01/21] part: move efi_guid_t Rob Clark
2017-09-11 22:55   ` Heinrich Schuchardt
2017-09-12 12:29   ` Simon Glass
2017-09-10 11:21 ` [U-Boot] [PATCH v3 2/9] fs/fat: introduce new director iterators Rob Clark
2017-09-12 12:29   ` Simon Glass
2017-09-10 11:21 ` [U-Boot] [PATCH v2 02/21] part: extract MBR signature from partitions Rob Clark
2017-09-12 12:29   ` Simon Glass
2017-09-10 11:21 ` [U-Boot] [PATCH v2 03/21] efi: add some missing __packed Rob Clark
2017-09-12 12:30   ` Simon Glass
2017-09-10 11:21 ` [U-Boot] [PATCH v3 3/9] fat/fs: convert to directory iterators Rob Clark
2017-09-10 11:21 ` [U-Boot] [PATCH v2 04/21] efi: add some more device path structures Rob Clark
2017-09-12 12:30   ` Simon Glass
2017-09-10 11:21 ` [U-Boot] [PATCH v3 4/9] fs: add fs_readdir() Rob Clark
2017-09-10 11:21 ` [U-Boot] [PATCH v2 05/21] efi_loader: add device-path utils Rob Clark
2017-09-12 12:30   ` Simon Glass
2017-09-12 13:05     ` Rob Clark
2017-09-10 11:21 ` [U-Boot] [PATCH v3 5/9] fs/fat: implement opendir/readdir/closedir Rob Clark
2017-09-10 11:21 ` [U-Boot] [PATCH v2 06/21] efi_loader: drop redundant efi_device_path_protocol Rob Clark
2017-09-10 11:21 ` [U-Boot] [PATCH v3 6/9] fat/fs: remove a bunch of dead code Rob Clark
2017-09-10 11:21 ` [U-Boot] [PATCH v2 07/21] efi_loader: flesh out device-path to text Rob Clark
2017-09-10 11:21 ` [U-Boot] [PATCH v3 7/9] fat/fs: move ls to generic implementation Rob Clark
2017-09-10 11:21 ` [U-Boot] [PATCH v2 08/21] efi_loader: use proper device-paths for partitions Rob Clark
2017-09-10 11:21 ` [U-Boot] [PATCH v3 8/9] fs/fat: fix case for FAT shortnames Rob Clark
2017-09-10 11:21 ` [U-Boot] [PATCH v2 09/21] efi_loader: use proper device-paths for net Rob Clark
2017-09-10 11:21 ` Rob Clark [this message]
2017-09-10 11:21 ` [U-Boot] [PATCH v2 10/21] efi_loader: refactor boot device and loaded_image handling Rob Clark
2017-09-10 11:21 ` [U-Boot] [PATCH v2 11/21] efi_loader: add file/filesys support Rob Clark
2017-09-12 12:30   ` Simon Glass
2017-09-10 11:21 ` [U-Boot] [PATCH v2 12/21] efi_loader: support load_image() from a file-path Rob Clark
2017-09-10 11:21 ` [U-Boot] [PATCH v2 13/21] efi_loader: make pool allocations cacheline aligned Rob Clark
2017-09-10 11:21 ` [U-Boot] [PATCH v2 14/21] efi_loader: efi variable support Rob Clark
2017-09-12 12:30   ` Simon Glass
2017-09-12 13:10     ` Rob Clark
2017-09-10 11:21 ` [U-Boot] [PATCH v2 15/21] efi_loader: add bootmgr Rob Clark
2017-09-12 12:30   ` Simon Glass
2017-09-10 11:21 ` [U-Boot] [PATCH v2 16/21] efi_loader: file_path should be variable length Rob Clark
2017-09-10 11:21 ` [U-Boot] [PATCH v2 17/21] efi_loader: set loaded image code/data type properly Rob Clark
2017-09-10 11:21 ` [U-Boot] [PATCH v2 18/21] efi_loader: print GUIDs Rob Clark
2017-09-10 11:21 ` [U-Boot] [PATCH v2 19/21] efi_loader: split out escape sequence based size query Rob Clark
2017-09-10 11:21 ` [U-Boot] [PATCH v2 20/21] efi_loader: Correctly figure out size for vidconsole Rob Clark
2017-09-10 11:21 ` [U-Boot] [PATCH v2 21/21] efi_loader: Some console improvements " Rob Clark
2017-09-12 12:30   ` Simon Glass
2017-09-10 11:38 ` [U-Boot] [PATCH v2 00/21] efi_loader: enough UEFI for standard distro boot Rob Clark
  -- strict thread matches above, loose matches on Subject: below --
2017-09-09 17:15 [U-Boot] [PATCH v3 0/9] fs/fat: cleanups + readdir implementation Rob Clark
2017-09-09 17:16 ` [U-Boot] [PATCH v3 9/9] fs/fat: Clean up open-coded sector <-> cluster conversions Rob Clark
2017-09-12 12:29   ` Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170910112149.21358-19-robdclark@gmail.com \
    --to=robdclark@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox