From 46565f594a9601734b51be16999ad4914798bfc6 Mon Sep 17 00:00:00 2001 From: Amaury Pouly Date: Mon, 15 Mar 2010 12:31:24 +0000 Subject: [PATCH] fat: make fat_open more flexible by accepting the file==&dir->file and make fat_opendir also more flexible by accepting dir==parent_dir git-svn-id: svn://svn.rockbox.org/rockbox/trunk@25202 a1c6a512-1295-4272-9138-f99709370657 --- firmware/drivers/fat.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c index 169672f08e..d0b697ef60 100644 --- a/firmware/drivers/fat.c +++ b/firmware/drivers/fat.c @@ -1632,6 +1632,15 @@ int fat_open(IF_MV2(int volume,) struct fat_file *file, const struct fat_dir* dir) { + /* Remember where the file's dir entry is located + * Do it befoe assigning other fields so that fat_open + * can be called with file == &dir->file (see fat_opendir) */ + if ( dir ) { + file->direntry = dir->entry - 1; + file->direntries = dir->entrycount; + file->dircluster = dir->file.firstcluster; + } + file->firstcluster = startcluster; file->lastcluster = startcluster; file->lastsector = 0; @@ -1648,12 +1657,6 @@ int fat_open(IF_MV2(int volume,) } #endif - /* remember where the file's dir entry is located */ - if ( dir ) { - file->direntry = dir->entry - 1; - file->direntries = dir->entrycount; - file->dircluster = dir->file.firstcluster; - } LDEBUGF("fat_open(%lx), entry %d\n",startcluster,file->direntry); return 0; } @@ -2301,9 +2304,6 @@ int fat_opendir(IF_MV2(int volume,) #endif int rc; - dir->entry = 0; - dir->sector = 0; - if (startcluster == 0) startcluster = fat_bpb->bpb_rootclus; @@ -2314,6 +2314,11 @@ int fat_opendir(IF_MV2(int volume,) " (error code %d)\n", rc); return rc * 10 - 1; } + + /* assign them after fat_open call so that fat_opendir can be called with the same + * fat_dir as parent and result */ + dir->entry = 0; + dir->sector = 0; return 0; }