summaryrefslogtreecommitdiff
path: root/nuttx/fs/fat/fs_fat32util.c
diff options
context:
space:
mode:
Diffstat (limited to 'nuttx/fs/fat/fs_fat32util.c')
-rw-r--r--nuttx/fs/fat/fs_fat32util.c48
1 files changed, 47 insertions, 1 deletions
diff --git a/nuttx/fs/fat/fs_fat32util.c b/nuttx/fs/fat/fs_fat32util.c
index c6680b6f0..f38cc3741 100644
--- a/nuttx/fs/fat/fs_fat32util.c
+++ b/nuttx/fs/fat/fs_fat32util.c
@@ -44,6 +44,7 @@
****************************************************************************/
#include <nuttx/config.h>
+
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
@@ -2303,7 +2304,8 @@ int fat_ffcacheinvalidate(struct fat_mountpt_s *fs, struct fat_file_s *ff)
/* Then discard the current cache contents */
- ff->ff_bflags &= ~FFBUFF_VALID;
+ ff->ff_bflags &= ~FFBUFF_VALID;
+ ff->ff_cachesector = 0;
}
return OK;
}
@@ -2461,3 +2463,47 @@ int fat_nfreeclusters(struct fat_mountpt_s *fs, size_t *pfreeclusters)
return OK;
}
+/****************************************************************************
+ * Name: fat_nfreeclusters
+ *
+ * Desciption:
+ * Given the file position, set the correct current sector to access.
+ *
+ ****************************************************************************/
+
+int fat_currentsector(struct fat_mountpt_s *fs, struct fat_file_s *ff,
+ off_t position)
+{
+ int sectoroffset;
+
+ if (position <= ff->ff_size )
+ {
+ /* sectoroffset is the sector number offset into the current cluster */
+
+ sectoroffset = SEC_NSECTORS(fs, position) & CLUS_NDXMASK(fs);
+
+ /* The current cluster is the the first sector of the cluster plus
+ * the sector offset
+ */
+
+ ff->ff_currentsector = fat_cluster2sector(fs, ff->ff_currentcluster)
+ + sectoroffset;
+
+ /* The remainder is the number of sectors left in the cluster to be
+ * read/written
+ */
+
+ ff->ff_sectorsincluster = fs->fs_fatsecperclus - sectoroffset;
+
+ fvdbg("position=%d currentsector=%d sectorsincluster=%d\n",
+ position, ff->ff_currentsector, ff->ff_sectorsincluster);
+
+ return OK;
+ }
+
+ /* The position does not lie within the file */
+
+ return -ENOSPC;
+}
+
+