Rev 2856 | Rev 2876 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2856 | Rev 2864 | ||
---|---|---|---|
Line 137... | Line 137... | ||
137 | uint16_t firstc_lo; /* FAT32 */ |
137 | uint16_t firstc_lo; /* FAT32 */ |
138 | }; |
138 | }; |
139 | uint32_t size; |
139 | uint32_t size; |
140 | } __attribute__ ((packed)) fat_dentry_t; |
140 | } __attribute__ ((packed)) fat_dentry_t; |
141 | 141 | ||
- | 142 | typedef uint16_t fat_cluster_t; |
|
- | 143 | ||
142 | typedef enum { |
144 | typedef enum { |
143 | FAT_INVALID, |
145 | FAT_INVALID, |
144 | FAT_DIRECTORY, |
146 | FAT_DIRECTORY, |
145 | FAT_FILE |
147 | FAT_FILE |
146 | } fat_node_type_t; |
148 | } fat_node_type_t; |
147 | 149 | ||
- | 150 | struct fat_node; |
|
- | 151 | ||
148 | /** FAT in-core node. */ |
152 | /** FAT index structure. |
- | 153 | * |
|
- | 154 | * This structure exists to help us to overcome certain limitations of the FAT |
|
- | 155 | * file system design. The problem with FAT is that it is hard to find |
|
- | 156 | * an entity which could represent a VFS index. There are two candidates: |
|
- | 157 | * |
|
- | 158 | * a) number of the node's first cluster |
|
- | 159 | * b) the pair of the parent directory's first cluster and the dentry index |
|
- | 160 | * within the parent directory |
|
- | 161 | * |
|
- | 162 | * We need VFS indices to be: |
|
- | 163 | * A) unique |
|
- | 164 | * B) stable in time, at least until the next mount |
|
- | 165 | * |
|
- | 166 | * Unfortunately a) does not meet the A) criterion because zero-length files |
|
- | 167 | * will have the first cluster field cleared. And b) does not meet the B) |
|
- | 168 | * criterion because unlink() and rename() will both free up the original |
|
- | 169 | * dentry, which contains all the essential info about the file. |
|
- | 170 | * |
|
- | 171 | * Therefore, a completely opaque indices are used and the FAT server maintains |
|
- | 172 | * a mapping between them and otherwise nice b) variant. On rename(), the VFS |
|
- | 173 | * index stays unaltered, while the internal FAT "physical tree address" |
|
- | 174 | * changes. The unlink case is also handled this way thanks to an in-core node |
|
- | 175 | * pointer embedded in the index structure. |
|
- | 176 | */ |
|
149 | typedef struct { |
177 | typedef struct { |
- | 178 | dev_handle_t dev_handle; |
|
- | 179 | fs_index_t index; |
|
- | 180 | /** |
|
- | 181 | * Parent first cluster. |
|
- | 182 | * Zero is used if this node is not linked, in which case nodep must |
|
- | 183 | * contain a pointer to the in-core node structure. |
|
- | 184 | * One is used when the parent is the root directory. |
|
- | 185 | */ |
|
- | 186 | fat_cluster_t pfc; |
|
- | 187 | /** Parent directory entry index. */ |
|
- | 188 | unsigned pdi; |
|
150 | /** Protects an instance of this type. */ |
189 | /** Pointer to in-core node instance. */ |
151 | futex_t lock; |
190 | struct fat_node *nodep; |
- | 191 | } fat_idx_t; |
|
- | 192 | ||
- | 193 | /** FAT in-core node. */ |
|
- | 194 | typedef struct fat_node { |
|
152 | fat_node_type_t type; |
195 | fat_node_type_t type; |
153 | /** VFS index is the node's first allocated cluster. */ |
- | |
154 | fs_index_t index; |
196 | fat_idx_t *idx; |
- | 197 | /** |
|
- | 198 | * Node's first cluster. |
|
155 | /** VFS index of the parent node. */ |
199 | * Zero is used for zero-length nodes. |
156 | fs_index_t pindex; |
200 | * One is used to mark root directory. |
- | 201 | */ |
|
157 | dev_handle_t dev_handle; |
202 | fat_cluster_t firstc; |
158 | /** FAT in-core node hash table link. */ |
203 | /** FAT in-core node hash table link. */ |
159 | link_t fin_link; |
204 | link_t fin_link; |
160 | /** FAT in-core node free list link. */ |
205 | /** FAT in-core node free list link. */ |
161 | link_t ffn_link; |
206 | link_t ffn_link; |
162 | size_t size; |
207 | size_t size; |