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.c b/fs/fat/fat.c
index 65873a2..f5f74c1 100644
--- a/fs/fat/fat.c
+++ b/fs/fat/fat.c
@@ -257,8 +257,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;
}
@@ -594,9 +593,8 @@
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;