UbixOS V2 2.0

fat_cache.c
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 //-----------------------------------------------------------------------------
3 // FAT16/32 File IO Library
4 // V2.6
5 // Ultra-Embedded.com
6 // Copyright 2003 - 2012
7 //
8 // Email: admin@ultra-embedded.com
9 //
10 // License: GPL
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 //-----------------------------------------------------------------------------
14 //
15 // This file is part of FAT File IO Library.
16 //
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.
21 //
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.
26 //
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 //-----------------------------------------------------------------------------
32 #include <string.h>
33 #include "fat_cache.h"
34
35 // Per file cluster chain caching used to improve performance.
36 // This does not have to be enabled for architectures with low
37 // memory space.
38
39 //-----------------------------------------------------------------------------
40 // fatfs_cache_init:
41 //-----------------------------------------------------------------------------
42 int fatfs_cache_init(struct fatfs *fs, FL_FILE *file)
43 {
44 #ifdef FAT_CLUSTER_CACHE_ENTRIES
45 int i;
46
47 for (i=0;i<FAT_CLUSTER_CACHE_ENTRIES;i++)
48 {
49 file->cluster_cache_idx[i] = 0xFFFFFFFF; // Not used
50 file->cluster_cache_data[i] = 0;
51 }
52 #endif
53
54 return 1;
55 }
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)
60 {
61 #ifdef FAT_CLUSTER_CACHE_ENTRIES
62 uint32 slot = clusterIdx % FAT_CLUSTER_CACHE_ENTRIES;
63
64 if (file->cluster_cache_idx[slot] == clusterIdx)
65 {
66 *pNextCluster = file->cluster_cache_data[slot];
67 return 1;
68 }
69 #endif
70
71 return 0;
72 }
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)
77 {
78 #ifdef FAT_CLUSTER_CACHE_ENTRIES
79 uint32 slot = clusterIdx % FAT_CLUSTER_CACHE_ENTRIES;
80
81 if (file->cluster_cache_idx[slot] == clusterIdx)
82 file->cluster_cache_data[slot] = nextCluster;
83 else
84 {
85 file->cluster_cache_idx[slot] = clusterIdx;
86 file->cluster_cache_data[slot] = nextCluster;
87 }
88 #endif
89
90 return 1;
91 }
fatfs_cache_set_next_cluster
int fatfs_cache_set_next_cluster(struct fatfs *fs, FL_FILE *file, uint32 clusterIdx, uint32 nextCluster)
Definition: fat_cache.c:76
fat_cache.h
string.h
file
Definition: descrip.h:67
fs
Definition: fs.h:260
fatfs_cache_init
int fatfs_cache_init(struct fatfs *fs, FL_FILE *file)
Definition: fat_cache.c:42
sFL_FILE
Definition: fat_filelib.h:38
uint32
unsigned long uint32
Definition: fat_types.h:23
fatfs_cache_get_next_cluster
int fatfs_cache_get_next_cluster(struct fatfs *fs, FL_FILE *file, uint32 clusterIdx, uint32 *pNextCluster)
Definition: fat_cache.c:59
fatfs
Definition: fat_access.h:57