mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-11-25 06:00:43 +00:00
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>
This commit is contained in:
parent
21a24c3bf3
commit
265edc03d5
3 changed files with 11 additions and 11 deletions
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue