fs/fat: Clean up open-coded sector <-> cluster conversions
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>
Reviewed-by: Simon Glass <sjg@chromium.org>
diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c
index d0468ba..9d2e0ed 100644
--- a/fs/fat/fat_write.c
+++ b/fs/fat/fat_write.c
@@ -502,8 +502,7 @@
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 @@
__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 *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);