1 //-----------------------------------------------------------------------------
2 //-----------------------------------------------------------------------------
3 // FAT16/32 File IO Library
6 // Copyright 2003 - 2012
8 // Email: admin@ultra-embedded.com
11 // If you would like a version with a more permissive license for use in
12 // closed source commercial applications please contact me for details.
13 //-----------------------------------------------------------------------------
15 // This file is part of FAT File IO Library.
17 // FAT File IO Library is free software; you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation; either version 2 of the License, or
20 // (at your option) any later version.
22 // FAT File IO Library is distributed in the hope that it will be useful,
23 // but WITHOUT ANY WARRANTY; without even the implied warranty of
24 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 // GNU General Public License for more details.
27 // You should have received a copy of the GNU General Public License
28 // along with FAT File IO Library; if not, write to the Free Software
29 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 //-----------------------------------------------------------------------------
31 //-----------------------------------------------------------------------------
33 #include "fat_cache.h"
35 // Per file cluster chain caching used to improve performance.
36 // This does not have to be enabled for architectures with low
39 //-----------------------------------------------------------------------------
41 //-----------------------------------------------------------------------------
42 int fatfs_cache_init(struct fatfs
*fs
, FL_FILE
*file
)
44 #ifdef FAT_CLUSTER_CACHE_ENTRIES
47 for (i
=0;i
<FAT_CLUSTER_CACHE_ENTRIES
;i
++)
49 file
->cluster_cache_idx
[i
] = 0xFFFFFFFF; // Not used
50 file
->cluster_cache_data
[i
] = 0;
56 //-----------------------------------------------------------------------------
57 // fatfs_cache_get_next_cluster:
58 //-----------------------------------------------------------------------------
59 int fatfs_cache_get_next_cluster(struct fatfs
*fs
, FL_FILE
*file
, uint32 clusterIdx
, uint32
*pNextCluster
)
61 #ifdef FAT_CLUSTER_CACHE_ENTRIES
62 uint32 slot
= clusterIdx
% FAT_CLUSTER_CACHE_ENTRIES
;
64 if (file
->cluster_cache_idx
[slot
] == clusterIdx
)
66 *pNextCluster
= file
->cluster_cache_data
[slot
];
73 //-----------------------------------------------------------------------------
74 // fatfs_cache_set_next_cluster:
75 //-----------------------------------------------------------------------------
76 int fatfs_cache_set_next_cluster(struct fatfs
*fs
, FL_FILE
*file
, uint32 clusterIdx
, uint32 nextCluster
)
78 #ifdef FAT_CLUSTER_CACHE_ENTRIES
79 uint32 slot
= clusterIdx
% FAT_CLUSTER_CACHE_ENTRIES
;
81 if (file
->cluster_cache_idx
[slot
] == clusterIdx
)
82 file
->cluster_cache_data
[slot
] = nextCluster
;
85 file
->cluster_cache_idx
[slot
] = clusterIdx
;
86 file
->cluster_cache_data
[slot
] = nextCluster
;