annotate packages/fs/fat/current/src/fatfs_ncache.c @ 2729:74dbf4c3f2e1 after-copyright-change-20090129

Update all copyright banners to reflect FSF ownership; fix and improve licence text.
author jlarmour
date Thu, 29 Jan 2009 17:47:46 +0000
parents 71a7aa469387
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
1 //==========================================================================
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
2 //
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
3 // fatfs_ncache.c
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
4 //
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
5 // FAT file system node cache functions
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
6 //
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
7 //==========================================================================
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1784
diff changeset
8 // ####ECOSGPLCOPYRIGHTBEGIN####
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1784
diff changeset
9 // -------------------------------------------
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1784
diff changeset
10 // This file is part of eCos, the Embedded Configurable Operating System.
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1784
diff changeset
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
12 //
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1784
diff changeset
13 // eCos is free software; you can redistribute it and/or modify it under
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1784
diff changeset
14 // the terms of the GNU General Public License as published by the Free
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1784
diff changeset
15 // Software Foundation; either version 2 or (at your option) any later
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1784
diff changeset
16 // version.
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
17 //
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1784
diff changeset
18 // eCos is distributed in the hope that it will be useful, but WITHOUT
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1784
diff changeset
19 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1784
diff changeset
20 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1784
diff changeset
21 // for more details.
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
22 //
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1784
diff changeset
23 // You should have received a copy of the GNU General Public License
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1784
diff changeset
24 // along with eCos; if not, write to the Free Software Foundation, Inc.,
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1784
diff changeset
25 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
26 //
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1784
diff changeset
27 // As a special exception, if other files instantiate templates or use
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1784
diff changeset
28 // macros or inline functions from this file, or you compile this file
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1784
diff changeset
29 // and link it with other works to produce a work based on this file,
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1784
diff changeset
30 // this file does not by itself cause the resulting work to be covered by
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1784
diff changeset
31 // the GNU General Public License. However the source code for this file
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1784
diff changeset
32 // must still be made available in accordance with section (3) of the GNU
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1784
diff changeset
33 // General Public License v2.
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
34 //
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1784
diff changeset
35 // This exception does not invalidate any other reasons why a work based
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1784
diff changeset
36 // on this file might be covered by the GNU General Public License.
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1784
diff changeset
37 // -------------------------------------------
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 1784
diff changeset
38 // ####ECOSGPLCOPYRIGHTEND####
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
39 //==========================================================================
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
40 //#####DESCRIPTIONBEGIN####
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
41 //
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
42 // Author(s): Savin Zlobec <savin@elatec.si>
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
43 // Date: 2003-06-26
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
44 //
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
45 //####DESCRIPTIONEND####
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
46 //
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
47 //==========================================================================
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
48
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
49 #include <pkgconf/fs_fat.h>
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
50 #include <pkgconf/infra.h>
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
51 #include <cyg/infra/cyg_type.h>
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
52 #include <cyg/infra/cyg_ass.h>
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
53 #include <cyg/infra/cyg_trac.h>
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
54 #include <cyg/infra/diag.h>
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
55 #include <sys/types.h>
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
56 #include <ctype.h>
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
57
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
58 #include "fatfs.h"
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
59
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
60 //==========================================================================
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
61 // Defines & macros
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
62
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
63 #ifdef CYGDBG_USE_ASSERTS
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
64 # define USE_ASSERTS 1
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
65 #endif
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
66
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
67 #ifdef FATFS_NODE_CACHE_EXTRA_CHECKS
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
68 # define USE_XCHECKS 1
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
69 #endif
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
70
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
71 #ifdef FATFS_TRACE_NODE_CACHE
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
72 # define TNC 1
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
73 #else
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
74 # define TNC 0
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
75 #endif
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
76
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
77 // This defines how many nodes should always be kept in dead list -
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
78 // it should be >= 2 or the file finding code may not work correctly!
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
79 #define DLIST_KEEP_NUM 2
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
80
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
81 //==========================================================================
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
82 // Node list functions
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
83
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
84 static void
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
85 node_list_init(fatfs_node_list_t *list)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
86 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
87 list->size = 0;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
88 list->first = list->last = NULL;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
89 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
90
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
91 static __inline__ int
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
92 node_list_get_size(fatfs_node_list_t *list)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
93 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
94 return (list->size);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
95 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
96
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
97 static __inline__ fatfs_node_t*
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
98 node_list_get_head(fatfs_node_list_t *list)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
99 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
100 return (list->first);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
101 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
102
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
103 static __inline__ fatfs_node_t*
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
104 node_list_get_tail(fatfs_node_list_t *list)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
105 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
106 return (list->last);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
107 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
108
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
109 static __inline__ fatfs_node_t*
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
110 node_list_get_next(fatfs_node_t *node)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
111 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
112 return (node->list_next);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
113 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
114
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
115 static __inline__ fatfs_node_t*
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
116 node_list_get_prev(fatfs_node_t *node)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
117 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
118 return (node->list_prev);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
119 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
120
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
121 static __inline__ bool
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
122 node_list_is_last(fatfs_node_t *node)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
123 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
124 return (NULL == node->list_next);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
125 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
126
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
127 static __inline__ bool
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
128 node_list_is_first(fatfs_node_t *node)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
129 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
130 return (NULL == node->list_prev);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
131 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
132
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
133 static void
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
134 node_list_head_add(fatfs_node_list_t *list, fatfs_node_t *node)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
135 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
136 node->list_prev = NULL;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
137 node->list_next = list->first;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
138
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
139 if (NULL == list->first)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
140 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
141 CYG_ASSERTC(list->size == 0);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
142 list->last = node;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
143 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
144 else
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
145 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
146 list->first->list_prev = node;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
147 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
148
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
149 list->first = node;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
150 list->size++;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
151 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
152
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
153 #if 0
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
154 static __inline__ fatfs_node_t*
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
155 node_list_head_get(fatfs_node_list_t *list)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
156 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
157 return list->first;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
158 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
159
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
160 static void
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
161 node_list_tail_add(fatfs_node_list_t *list, fatfs_node_t *node)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
162 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
163 node->list_prev = list->last;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
164 node->list_next = NULL;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
165
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
166 if (NULL == list->last)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
167 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
168 CYG_ASSERTC(list->size == 0);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
169 list->first = node;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
170 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
171 else
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
172 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
173 list->last->list_next = node;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
174 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
175
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
176 list->last = node;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
177 list->size++;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
178 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
179 #endif
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
180
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
181 static __inline__ fatfs_node_t*
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
182 node_list_tail_get(fatfs_node_list_t *list)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
183 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
184 return list->last;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
185 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
186
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
187 static void
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
188 node_list_remove(fatfs_node_list_t *list, fatfs_node_t *node)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
189 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
190 if (list->first == list->last)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
191 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
192 if (list->first == node)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
193 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
194 CYG_ASSERTC(list->size == 1);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
195 list->first = list->last = NULL;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
196 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
197 else
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
198 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
199 CYG_ASSERT(false, "chain node not in list!");
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
200 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
201 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
202 else if (list->first == node)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
203 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
204 CYG_ASSERTC(node->list_prev == NULL);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
205 list->first = node->list_next;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
206 list->first->list_prev = NULL;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
207 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
208 else if (list->last == node)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
209 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
210 CYG_ASSERTC(node->list_next == NULL);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
211 list->last = node->list_prev;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
212 list->last->list_next = NULL;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
213 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
214 else
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
215 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
216 CYG_ASSERTC(node->list_prev != NULL && node->list_next != NULL);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
217 node->list_prev->list_next = node->list_next;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
218 node->list_next->list_prev = node->list_prev;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
219 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
220 list->size--;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
221 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
222
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
223 #ifdef USE_XCHECKS
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
224 static void
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
225 node_list_check(fatfs_node_list_t *list, int min_ref, int max_ref)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
226 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
227 int i;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
228 fatfs_node_t *node, *pnode;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
229
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
230 CYG_ASSERT((list->last == NULL && list->first == NULL) ||
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
231 (list->last != NULL && list->first != NULL),
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
232 "list->first and list->last broken!");
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
233
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
234 if (list->first == NULL)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
235 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
236 CYG_ASSERTC(list->size == 0);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
237 return;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
238 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
239
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
240 CYG_ASSERTC(list->first->list_prev == NULL);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
241 CYG_ASSERTC(list->last->list_next == NULL);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
242
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
243 CYG_ASSERTC(list->first->refcnt >= min_ref &&
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
244 list->first->refcnt <= max_ref);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
245 CYG_ASSERTC(list->last->refcnt >= min_ref &&
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
246 list->last->refcnt <= max_ref);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
247
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
248 i = 1;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
249 node = list->first;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
250 pnode = NULL;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
251 while (node->list_next != NULL)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
252 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
253 i++;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
254 CYG_ASSERTC(node->list_prev == pnode);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
255 CYG_ASSERTC(node->refcnt >= min_ref && node->refcnt <= max_ref);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
256 pnode = node;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
257 node = node->list_next;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
258 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
259 CYG_ASSERTC(node->list_prev == pnode);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
260 CYG_ASSERTC(list->size == i);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
261 CYG_ASSERTC(node == list->last);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
262 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
263
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
264 static void
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
265 node_lists_check(fatfs_disk_t* disk)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
266 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
267 node_list_check(&disk->live_nlist, 1, 99999);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
268 node_list_check(&disk->dead_nlist, 0, 0);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
269 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
270 #endif // USE_XCHECKS
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
271
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
272 //==========================================================================
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
273 // Node hash functions
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
274
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
275 static unsigned int
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
276 hash_fn(const char *str, unsigned int strlen)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
277 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
278 unsigned int i = 0, val = 0;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
279
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
280 while (i++ < strlen)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
281 val = (val ^ (int)toupper(*str++)) << 1;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
282 return(val);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
283 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
284
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
285 static void
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
286 node_hash_init(fatfs_hash_table_t *tbl)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
287 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
288 int i;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
289
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
290 // Set size and clear all slots
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
291 tbl->size = FATFS_HASH_TABLE_SIZE;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
292 for (i = 0; i < tbl->size; i++)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
293 tbl->nodes[i] = NULL;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
294 tbl->n = 0;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
295 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
296
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
297 static bool
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
298 node_hash_add(fatfs_hash_table_t *tbl, fatfs_node_t *node)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
299 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
300 unsigned int hval;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
301
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
302 // Calculate hash of given node filename
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
303 hval = hash_fn(node->dentry.filename,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
304 strlen(node->dentry.filename)) % tbl->size;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
305
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
306 CYG_TRACE2(TNC, "name='%s' hval=%d", node->dentry.filename, hval);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
307
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
308 if (tbl->nodes[hval] == NULL)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
309 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
310 // First node in this slot
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
311 node->hash_next = NULL;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
312 tbl->nodes[hval] = node;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
313 tbl->n++;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
314 return true;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
315 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
316 else
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
317 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
318 // More nodes in this slot
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
319 fatfs_node_t *lnode, *pnode;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
320
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
321 pnode = NULL;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
322 lnode = tbl->nodes[hval];
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
323
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
324 // Insert node into list so that it is sorted by filename
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
325 while (lnode != NULL)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
326 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
327 if (lnode == node)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
328 return false;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
329
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
330 if (strcasecmp(lnode->dentry.filename, node->dentry.filename) > 0)
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
331 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
332 if (pnode != NULL)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
333 pnode->hash_next = node; // Insert in the middle
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
334 else
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
335 tbl->nodes[hval] = node; // Insert at the beginning
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
336 node->hash_next = lnode;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
337 tbl->n++;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
338 return true;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
339 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
340
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
341 pnode = lnode;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
342 lnode = lnode->hash_next;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
343 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
344 // Insert at the end
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
345 pnode->hash_next = node;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
346 node->hash_next = NULL;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
347 tbl->n++;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
348 return true;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
349 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
350 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
351
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
352 static fatfs_node_t*
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
353 node_hash_find(fatfs_hash_table_t *tbl,
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
354 const char *name,
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
355 unsigned int namelen,
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
356 unsigned int parent_cluster)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
357 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
358 unsigned int hval;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
359 fatfs_node_t *node;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
360
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
361 // Calculate hash of name and get the first node in slot
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
362 hval = hash_fn(name, namelen) % tbl->size;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
363 node = tbl->nodes[hval];
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
364
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
365 CYG_TRACE2(TNC, "name='%s' hval=%d\n", name, hval);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
366
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
367 // Find the node in list wich matches the
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
368 // given name and parent_cluster
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
369 while (node != NULL)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
370 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
371 // First compare the parent cluster number and
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
372 // check filename length since it is faster than
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
373 // comparing filenames
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
374 if (parent_cluster == node->dentry.parent_cluster &&
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
375 '\0' == node->dentry.filename[namelen])
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
376 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
377 int i = strncasecmp(node->dentry.filename, name, namelen);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
378
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
379 if (i == 0)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
380 return node;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
381 else if (i > 0)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
382 return NULL; // Stop searching - we have a
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
383 // sorted list so there can't be
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
384 // any matching filename further on
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
385 // if i > 0 - look at node_hash_add
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
386 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
387 node = node->hash_next;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
388 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
389
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
390 // No such node found
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
391 return NULL;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
392 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
393
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
394 static bool
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
395 node_hash_remove_keyless(fatfs_hash_table_t *tbl, fatfs_node_t *node)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
396 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
397 int i;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
398 fatfs_node_t *lnode, *pnode;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
399
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
400 // Look in all slots, since we have no key
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
401 for (i = 0; i < tbl->size; i++)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
402 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
403 // Look in list and remove it if there
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
404 lnode = tbl->nodes[i];
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
405 pnode = NULL;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
406 while (lnode != NULL)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
407 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
408 if (lnode == node)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
409 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
410 if (pnode == NULL)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
411 tbl->nodes[i] = lnode->hash_next;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
412 else
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
413 pnode->hash_next = lnode->hash_next;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
414 node->hash_next = NULL;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
415 tbl->n--;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
416
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
417 // All done
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
418 return true;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
419 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
420 pnode = lnode;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
421 lnode = lnode->hash_next;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
422 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
423 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
424 return false;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
425 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
426
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
427 static bool
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
428 node_hash_remove(fatfs_hash_table_t *tbl, fatfs_node_t *node)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
429 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
430 unsigned int hval;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
431 fatfs_node_t *lnode, *pnode;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
432
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
433 // Calculate hash of name and get the first node in slot
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
434 hval = hash_fn(node->dentry.filename,
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
435 strlen(node->dentry.filename)) % tbl->size;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
436 lnode = tbl->nodes[hval];
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
437
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
438 // Now find the node in list and remove it
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
439 pnode = NULL;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
440 while (lnode != NULL)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
441 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
442 if (lnode == node)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
443 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
444 if (pnode == NULL)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
445 tbl->nodes[hval] = lnode->hash_next;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
446 else
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
447 pnode->hash_next = lnode->hash_next;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
448 node->hash_next = NULL;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
449 tbl->n--;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
450
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
451 // All done
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
452 return true;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
453 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
454 pnode = lnode;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
455 lnode = lnode->hash_next;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
456 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
457
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
458 // Node not in list
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
459 return false;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
460 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
461
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
462 #ifdef USE_XCHECKS
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
463 static void
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
464 node_hash_check(fatfs_hash_table_t *tbl)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
465 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
466 int i, n;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
467
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
468 n = 0;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
469 for (i = 0; i < tbl->size; i++)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
470 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
471 fatfs_node_t *lnode, *pnode;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
472
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
473 pnode = NULL;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
474 lnode = tbl->nodes[i];
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
475
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
476 while (lnode != NULL)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
477 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
478 if (pnode != NULL)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
479 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
480 int c = strcasecmp(pnode->dentry.filename, lnode->dentry.filename);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
481 CYG_ASSERT(c <= 0, "hash table not sorted");
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
482 CYG_ASSERT(pnode->dentry.parent_cluster != lnode->dentry.parent_cluster ||
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
483 0 != c, "duplicated node in hash table");
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
484 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
485 n++;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
486 pnode = lnode;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
487 lnode = lnode->hash_next;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
488 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
489 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
490 CYG_ASSERTC(tbl->n == n);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
491 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
492
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
493 static void
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
494 node_hash_not_found_check(fatfs_disk_t *disk,
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
495 const char *name,
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
496 unsigned int namelen,
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
497 unsigned int parent_cluster)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
498 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
499 fatfs_node_t* node;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
500
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
501 node = node_list_get_head(&disk->live_nlist);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
502 while (NULL != node)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
503 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
504 if (node->dentry.parent_cluster == parent_cluster &&
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
505 namelen == strlen(node->dentry.filename) &&
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
506 0 == strncasecmp(name, node->dentry.filename, namelen))
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
507 CYG_ASSERT(false, "node not found in hash, "
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
508 "but exists in live list");
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
509 node = node_list_get_next(node);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
510 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
511
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
512 node = node_list_get_head(&disk->dead_nlist);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
513 while (NULL != node)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
514 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
515 if (node->dentry.parent_cluster == parent_cluster &&
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
516 namelen == strlen(node->dentry.filename) &&
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
517 0 == strncasecmp(name, node->dentry.filename, namelen))
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
518 CYG_ASSERT(false, "node not found in hash, "
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
519 "but exists in dead list");
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
520 node = node_list_get_next(node);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
521 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
522 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
523
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
524 static void
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
525 node_hash_found_check(fatfs_disk_t *disk,
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
526 const char *name,
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
527 unsigned int namelen,
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
528 unsigned int parent_cluster,
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
529 fatfs_node_t* node)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
530 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
531 fatfs_node_t *n;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
532
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
533 n = node_list_get_head(&disk->live_nlist);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
534 while (NULL != n)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
535 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
536 if (n == node)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
537 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
538 if (node->dentry.parent_cluster != parent_cluster ||
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
539 namelen != strlen(node->dentry.filename) ||
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
540 0 != strncasecmp(name, node->dentry.filename, namelen))
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
541 CYG_ASSERT(false, "node_hash_find returned wrong node");
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
542 return;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
543 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
544 n = node_list_get_next(n);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
545 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
546
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
547 n = node_list_get_head(&disk->dead_nlist);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
548 while (NULL != n)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
549 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
550 if (n == node)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
551 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
552 if (node->dentry.parent_cluster != parent_cluster ||
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
553 namelen != strlen(node->dentry.filename) ||
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
554 0 != strncasecmp(name, node->dentry.filename, namelen))
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
555 CYG_ASSERT(false, "node_hash_find returned wrong node");
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
556 return;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
557 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
558 n = node_list_get_next(n);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
559 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
560
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
561 CYG_ASSERT(false, "node not found in dead or live lists, "
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
562 "but exists in hash.");
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
563 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
564 #endif // USE_XCHECKS
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
565
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
566 //--------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
567
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
568 #ifdef USE_XCHECKS
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
569
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
570 # define SANITY_CHECK() \
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
571 CYG_MACRO_START \
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
572 node_lists_check(disk); \
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
573 node_hash_check(&disk->node_hash); \
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
574 CYG_ASSERTC((disk->live_nlist.size + disk->dead_nlist.size) == \
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
575 disk->node_hash.n); \
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
576 CYG_MACRO_END
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
577
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
578 # define NODE_FIND_CHECK() \
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
579 CYG_MACRO_START \
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
580 if (NULL == node) \
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
581 node_hash_not_found_check(disk, name, namelen, parent_cluster); \
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
582 else \
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
583 node_hash_found_check(disk, name, namelen, parent_cluster, node); \
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
584 CYG_MACRO_END
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
585
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
586 #else // USE_XCHECKS
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
587 # define SANITY_CHECK() CYG_EMPTY_STATEMENT
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
588 # define NODE_FIND_CHECK() CYG_EMPTY_STATEMENT
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
589 #endif // not USE_XCHECKS
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
590
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
591 //==========================================================================
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
592 // Node pool allocation functions
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
593
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
594 static void
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
595 node_pool_init(fatfs_disk_t *disk)
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
596 {
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
597 int i;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
598
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
599 for (i = 0; i < FATFS_NODE_POOL_SIZE; i++)
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
600 disk->node_pool[i] = &disk->node_pool_base[i];
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
601
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
602 disk->node_pool_free_cnt = i;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
603 }
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
604
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
605 static fatfs_node_t *
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
606 node_pool_alloc(fatfs_disk_t *disk)
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
607 {
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
608 fatfs_node_t *node = NULL;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
609
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
610 if (disk->node_pool_free_cnt > 0)
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
611 node = disk->node_pool[--disk->node_pool_free_cnt];
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
612
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
613 return node;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
614 }
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
615
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
616 static void
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
617 node_pool_free(fatfs_disk_t *disk, fatfs_node_t *node)
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
618 {
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
619 disk->node_pool[disk->node_pool_free_cnt++] = node;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
620 }
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
621
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
622 //==========================================================================
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
623 //==========================================================================
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
624 // Exported functions
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
625
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
626 //--------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
627 // fatfs_node_cache_init()
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
628 // Initializes node cache of given disk.
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
629
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
630 void
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
631 fatfs_node_cache_init(fatfs_disk_t *disk)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
632 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
633 CYG_CHECK_DATA_PTRC(disk);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
634
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
635 node_list_init(&disk->live_nlist);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
636 node_list_init(&disk->dead_nlist);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
637 node_hash_init(&disk->node_hash);
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
638 node_pool_init(disk);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
639
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
640 SANITY_CHECK();
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
641 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
642
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
643 //--------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
644 // fatfs_node_cache_flush()
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
645 // Frees all node cache of given disk.
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
646
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
647 void
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
648 fatfs_node_cache_flush(fatfs_disk_t *disk)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
649 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
650 fatfs_node_t *node, *next_node;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
651
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
652 node = node_list_get_head(&disk->live_nlist);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
653
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
654 while (NULL != node)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
655 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
656 next_node = node_list_get_next(node);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
657 node_list_remove(&disk->live_nlist, node);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
658 if (!node_hash_remove(&disk->node_hash, node))
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
659 CYG_ASSERT(false, "Node not in hash");
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
660 node_pool_free(disk, node);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
661 node = next_node;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
662 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
663
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
664 node = node_list_get_head(&disk->dead_nlist);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
665
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
666 while (NULL != node)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
667 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
668 next_node = node_list_get_next(node);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
669 node_list_remove(&disk->dead_nlist, node);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
670 if (!node_hash_remove(&disk->node_hash, node))
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
671 CYG_ASSERT(false, "Node not in hash");
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
672 node_pool_free(disk, node);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
673 node = next_node;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
674 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
675
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
676 SANITY_CHECK();
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
677 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
678
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
679 //--------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
680 // fatfs_node_alloc()
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
681 // Allocates a new node.
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
682
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
683 fatfs_node_t*
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
684 fatfs_node_alloc(fatfs_disk_t *disk, fatfs_dir_entry_t *dentry)
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
685 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
686 fatfs_node_t *node;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
687
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
688 CYG_CHECK_DATA_PTRC(disk);
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
689 CYG_CHECK_DATA_PTRC(dentry);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
690
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
691 node = node_pool_alloc(disk);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
692
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
693 if (NULL == node)
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
694 {
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
695 CYG_TRACE2(TNC, "getting node from dead list (size=%d keep=%d)",
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
696 node_list_get_size(&disk->dead_nlist), DLIST_KEEP_NUM);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
697
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
698 if (node_list_get_size(&disk->dead_nlist) <= DLIST_KEEP_NUM)
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
699 return NULL;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
700
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
701 node = node_list_tail_get(&disk->dead_nlist);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
702 if (NULL == node)
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
703 return NULL;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
704
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
705 CYG_TRACE1(TNC, "recycling node='%s'", node->dentry.filename);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
706
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
707 node_list_remove(&disk->dead_nlist, node);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
708 if (!node_hash_remove(&disk->node_hash, node))
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
709 CYG_ASSERT(false, "node not in hash");
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
710 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
711
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
712 // Init new node
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
713 node->dentry = *dentry;
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
714 node->refcnt = 0;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
715
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
716 node_list_head_add(&disk->dead_nlist, node);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
717 if (!node_hash_add(&disk->node_hash, node))
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
718 CYG_ASSERT(false, "node already in hash");
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
719
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
720 SANITY_CHECK();
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
721
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
722 return node;
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
723 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
724
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
725 //--------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
726 // fatfs_node_touch()
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
727 // Moves given node to top of its list.
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
728 // (When reusing dead node it is always taken from the bottom of list)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
729
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
730 void
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
731 fatfs_node_touch(fatfs_disk_t *disk, fatfs_node_t *node)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
732 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
733 CYG_CHECK_DATA_PTRC(disk);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
734 CYG_CHECK_DATA_PTRC(node);
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
735 CYG_TRACE2(TNC, "node='%s' refcnt=%d", node->dentry.filename, node->refcnt);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
736
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
737 if (node->refcnt == 0)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
738 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
739 node_list_remove(&disk->dead_nlist, node);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
740 node_list_head_add(&disk->dead_nlist, node);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
741 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
742 else
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
743 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
744 node_list_remove(&disk->live_nlist, node);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
745 node_list_head_add(&disk->live_nlist, node);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
746 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
747
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
748 SANITY_CHECK();
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
749 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
750
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
751 //--------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
752 // fatfs_node_ref()
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
753 // Increases the given node reference count.
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
754 // If the reference goes from 0 to 1, than the node
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
755 // is moved from dead list to live list.
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
756
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
757 void
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
758 fatfs_node_ref(fatfs_disk_t *disk, fatfs_node_t *node)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
759 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
760 CYG_CHECK_DATA_PTRC(disk);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
761 CYG_CHECK_DATA_PTRC(node);
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
762 CYG_TRACE2(TNC, "node='%s' refcnt=%d", node->dentry.filename, node->refcnt);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
763
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
764 node->refcnt++;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
765 if (1 == node->refcnt)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
766 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
767 // First reference - move node from dead to live list
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
768
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
769 CYG_TRACE1(TNC, "node='%s' to live list", node->dentry.filename);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
770
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
771 node_list_remove(&disk->dead_nlist, node);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
772 node_list_head_add(&disk->live_nlist, node);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
773 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
774
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
775 SANITY_CHECK();
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
776 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
777
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
778 //--------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
779 // fatfs_node_unref()
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
780 // Decreases the given node reference count.
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
781 // If the reference goes from 1 to 0, than the node
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
782 // is moved from live list to top of dead list.
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
783 // (When reusing dead node it is always taken from the bottom of list)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
784
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
785 void
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
786 fatfs_node_unref(fatfs_disk_t *disk, fatfs_node_t *node)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
787 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
788 CYG_CHECK_DATA_PTRC(disk);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
789 CYG_CHECK_DATA_PTRC(node);
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
790 CYG_TRACE2(TNC, "node='%s' refcnt=%d", node->dentry.filename, node->refcnt);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
791 CYG_ASSERT(node->refcnt > 0, "node->refcnt <= 0");
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
792
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
793 node->refcnt--;
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
794 if (0 == node->refcnt)
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
795 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
796 // No more references - move node from live to dead list
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
797
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
798 CYG_TRACE1(TNC, "node='%s' to dead list", node->dentry.filename);
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
799
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
800 node_list_remove(&disk->live_nlist, node);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
801 node_list_head_add(&disk->dead_nlist, node);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
802 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
803
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
804 SANITY_CHECK();
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
805 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
806
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
807 //--------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
808 // fatfs_node_free()
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
809 // Frees node memory and removes it from its list and hash.
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
810 // This function must not be called on a referenced node.
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
811
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
812 void
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
813 fatfs_node_free(fatfs_disk_t *disk, fatfs_node_t *node)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
814 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
815 CYG_CHECK_DATA_PTRC(disk);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
816 CYG_CHECK_DATA_PTRC(node);
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
817 CYG_TRACE2(TNC, "node='%s' refcnt=%d", node->dentry.filename, node->refcnt);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
818 CYG_ASSERTC(node->refcnt == 0);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
819 CYG_ASSERTC(node != disk->root);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
820
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
821 // Remove from dead list, from hash and free ptr
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
822
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
823 node_list_remove(&disk->dead_nlist, node);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
824 if (!node_hash_remove(&disk->node_hash, node))
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
825 CYG_ASSERT(false, "node not in hash");
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
826
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
827 node_pool_free(disk, node);
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
828
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
829 SANITY_CHECK();
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
830 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
831
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
832 //--------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
833 // fatfs_node_rehash()
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
834 // Recalculates given node hash key.
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
835
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
836 void
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
837 fatfs_node_rehash(fatfs_disk_t *disk, fatfs_node_t *node)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
838 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
839 CYG_CHECK_DATA_PTRC(disk);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
840 CYG_CHECK_DATA_PTRC(node);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
841
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
842 if (!node_hash_remove_keyless(&disk->node_hash, node))
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
843 CYG_ASSERT(false, "node not in hash");
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
844
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
845 if (!node_hash_add(&disk->node_hash, node))
1784
71a7aa469387 Major update of fatfs. FAT32 support and changes to the node cache.
asl
parents: 1476
diff changeset
846 CYG_ASSERT(false, "node already in hash");
1476
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
847
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
848 SANITY_CHECK();
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
849 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
850
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
851 //--------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
852 // fatfs_node_find()
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
853 // Finds node in hash by its name and parent cluster.
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
854 // If no node found NULL is returned.
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
855
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
856 fatfs_node_t*
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
857 fatfs_node_find(fatfs_disk_t *disk,
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
858 const char *name,
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
859 unsigned int namelen,
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
860 unsigned int parent_cluster)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
861 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
862 fatfs_node_t *node;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
863
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
864 CYG_CHECK_DATA_PTRC(disk);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
865 CYG_CHECK_DATA_PTRC(name);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
866
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
867 node = node_hash_find(&disk->node_hash, name, namelen, parent_cluster);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
868
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
869 NODE_FIND_CHECK();
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
870
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
871 CYG_TRACE3(TNC, "node name=%s pcluster=%d %s found in cache\n",
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
872 name, parent_cluster, ((node != NULL) ? "" : "not"));
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
873
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
874 return node;
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
875 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
876
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
877 //--------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
878 // fatfs_get_live_node_count()
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
879 // Gets the number of live nodes.
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
880
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
881 int
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
882 fatfs_get_live_node_count(fatfs_disk_t *disk)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
883 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
884 return node_list_get_size(&disk->live_nlist);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
885 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
886
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
887 //--------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
888 // fatfs_get_dead_node_count()
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
889 // Gets the number of dead nodes.
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
890
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
891 int
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
892 fatfs_get_dead_node_count(fatfs_disk_t *disk)
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
893 {
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
894 return node_list_get_size(&disk->dead_nlist);
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
895 }
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
896
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
897 // -------------------------------------------------------------------------
f2453fae08d4 Added support for FAT filesystem. Several packages, see the individual
nickg
parents:
diff changeset
898 // EOF fatfs_ncache.c