summaryrefslogtreecommitdiff
path: root/firmware/drivers/fat.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/drivers/fat.c')
-rw-r--r--firmware/drivers/fat.c20
1 files changed, 7 insertions, 13 deletions
diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c
index c97772361e..c640e6e737 100644
--- a/firmware/drivers/fat.c
+++ b/firmware/drivers/fat.c
@@ -1967,7 +1967,7 @@ int fat_rename(struct fat_file* file,
1967 int attr) 1967 int attr)
1968{ 1968{
1969 int rc; 1969 int rc;
1970 struct fat_dir olddir; 1970 struct fat_file olddir_file;
1971 struct fat_file newfile = *file; 1971 struct fat_file newfile = *file;
1972 unsigned char* entry = NULL; 1972 unsigned char* entry = NULL;
1973 unsigned short* clusptr = NULL; 1973 unsigned short* clusptr = NULL;
@@ -1988,11 +1988,6 @@ int fat_rename(struct fat_file* file,
1988 return -2; 1988 return -2;
1989 } 1989 }
1990 1990
1991 /* create a temporary file handle */
1992 rc = fat_opendir(IF_MV2(file->volume,) &olddir, file->dircluster, NULL);
1993 if (rc < 0)
1994 return rc * 10 - 1;
1995
1996 /* create new name */ 1991 /* create new name */
1997 rc = add_dir_entry(dir, &newfile, newname, false, false); 1992 rc = add_dir_entry(dir, &newfile, newname, false, false);
1998 if (rc < 0) 1993 if (rc < 0)
@@ -2016,18 +2011,17 @@ int fat_rename(struct fat_file* file,
2016 it points to its parent directory (we don't check if it was a move) */ 2011 it points to its parent directory (we don't check if it was a move) */
2017 if(FAT_ATTR_DIRECTORY == attr) { 2012 if(FAT_ATTR_DIRECTORY == attr) {
2018 unsigned char buf[SECTOR_SIZE]; 2013 unsigned char buf[SECTOR_SIZE];
2019 /* open the dir that was renamed, we re-use the olddir struct */ 2014 /* open the dir that was renamed, we re-use the olddir_file struct */
2020 rc = fat_opendir(IF_MV2(file->volume,) &olddir, newfile.firstcluster, 2015 rc = fat_open(IF_MV2(volume,) newfile.firstcluster, &olddir_file, NULL);
2021 NULL);
2022 if (rc < 0) 2016 if (rc < 0)
2023 return rc * 10 - 6; 2017 return rc * 10 - 6;
2024 2018
2025 /* get the first sector of the dir */ 2019 /* get the first sector of the dir */
2026 rc = fat_seek(&olddir.file, 0); 2020 rc = fat_seek(&olddir_file, 0);
2027 if (rc < 0) 2021 if (rc < 0)
2028 return rc * 10 - 7; 2022 return rc * 10 - 7;
2029 2023
2030 rc = fat_readwrite(&olddir.file, 1, buf, false); 2024 rc = fat_readwrite(&olddir_file, 1, buf, false);
2031 if (rc < 0) 2025 if (rc < 0)
2032 return rc * 10 - 8; 2026 return rc * 10 - 8;
2033 2027
@@ -2051,11 +2045,11 @@ int fat_rename(struct fat_file* file,
2051 *clusptr = htole16(parentcluster & 0xffff); 2045 *clusptr = htole16(parentcluster & 0xffff);
2052 2046
2053 /* write back this sector */ 2047 /* write back this sector */
2054 rc = fat_seek(&olddir.file, 0); 2048 rc = fat_seek(&olddir_file, 0);
2055 if (rc < 0) 2049 if (rc < 0)
2056 return rc * 10 - 7; 2050 return rc * 10 - 7;
2057 2051
2058 rc = fat_readwrite(&olddir.file, 1, buf, true); 2052 rc = fat_readwrite(&olddir_file, 1, buf, true);
2059 if (rc < 1) 2053 if (rc < 1)
2060 return rc * 10 - 8; 2054 return rc * 10 - 8;
2061 } 2055 }