Rev 2890 | Rev 2893 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2890 | Rev 2891 | ||
---|---|---|---|
Line 119... | Line 119... | ||
119 | #define FAT_CLST_FIRST 0x0002 |
119 | #define FAT_CLST_FIRST 0x0002 |
120 | #define FAT_CLST_BAD 0xfff7 |
120 | #define FAT_CLST_BAD 0xfff7 |
121 | #define FAT_CLST_LAST1 0xfff8 |
121 | #define FAT_CLST_LAST1 0xfff8 |
122 | #define FAT_CLST_LAST8 0xffff |
122 | #define FAT_CLST_LAST8 0xffff |
123 | 123 | ||
- | 124 | #define fat_block_get(np, off) \ |
|
- | 125 | _fat_block_get((np)->idx->dev_handle, (np)->firstc, (off)) |
|
- | 126 | ||
- | 127 | static block_t * |
|
124 | static block_t *fat_block_get(fat_node_t *nodep, off_t offset) |
128 | _fat_block_get(dev_handle_t dev_handle, fat_cluster_t fc, off_t offset) |
125 | { |
129 | { |
126 | block_t *bb; |
130 | block_t *bb; |
127 | block_t *b; |
131 | block_t *b; |
128 | unsigned bps; |
132 | unsigned bps; |
129 | unsigned spc; |
133 | unsigned spc; |
Line 132... | Line 136... | ||
132 | unsigned rde; |
136 | unsigned rde; |
133 | unsigned rds; /* root directory size */ |
137 | unsigned rds; /* root directory size */ |
134 | unsigned sf; |
138 | unsigned sf; |
135 | unsigned ssa; /* size of the system area */ |
139 | unsigned ssa; /* size of the system area */ |
136 | unsigned clusters; |
140 | unsigned clusters; |
137 | fat_cluster_t clst = nodep->firstc; |
141 | fat_cluster_t clst = fc; |
138 | unsigned i; |
142 | unsigned i; |
139 | 143 | ||
140 | bb = block_get(nodep->idx->dev_handle, BS_BLOCK); |
144 | bb = block_get(dev_handle, BS_BLOCK); |
141 | bps = uint16_t_le2host(FAT_BS(bb)->bps); |
145 | bps = uint16_t_le2host(FAT_BS(bb)->bps); |
142 | spc = FAT_BS(bb)->spc; |
146 | spc = FAT_BS(bb)->spc; |
143 | rscnt = uint16_t_le2host(FAT_BS(bb)->rscnt); |
147 | rscnt = uint16_t_le2host(FAT_BS(bb)->rscnt); |
144 | fatcnt = FAT_BS(bb)->fatcnt; |
148 | fatcnt = FAT_BS(bb)->fatcnt; |
145 | rde = uint16_t_le2host(FAT_BS(bb)->root_ent_max); |
149 | rde = uint16_t_le2host(FAT_BS(bb)->root_ent_max); |
Line 148... | Line 152... | ||
148 | 152 | ||
149 | rds = (sizeof(fat_dentry_t) * rde) / bps; |
153 | rds = (sizeof(fat_dentry_t) * rde) / bps; |
150 | rds += ((sizeof(fat_dentry_t) * rde) % bps != 0); |
154 | rds += ((sizeof(fat_dentry_t) * rde) % bps != 0); |
151 | ssa = rscnt + fatcnt * sf + rds; |
155 | ssa = rscnt + fatcnt * sf + rds; |
152 | 156 | ||
153 | if (nodep->idx->index == FAT_CLST_RES1) { |
157 | if (fc == FAT_CLST_RES1) { |
154 | /* root directory special case */ |
158 | /* root directory special case */ |
155 | assert(offset < rds); |
159 | assert(offset < rds); |
156 | b = block_get(nodep->idx->dev_handle, |
- | |
157 | rscnt + fatcnt * sf + offset); |
160 | b = block_get(dev_handle, rscnt + fatcnt * sf + offset); |
158 | return b; |
161 | return b; |
159 | } |
162 | } |
160 | 163 | ||
161 | clusters = offset / spc; |
164 | clusters = offset / spc; |
162 | for (i = 0; i < clusters; i++) { |
165 | for (i = 0; i < clusters; i++) { |
Line 165... | Line 168... | ||
165 | 168 | ||
166 | assert(clst >= FAT_CLST_FIRST && clst < FAT_CLST_BAD); |
169 | assert(clst >= FAT_CLST_FIRST && clst < FAT_CLST_BAD); |
167 | fsec = (clst * sizeof(fat_cluster_t)) / bps; |
170 | fsec = (clst * sizeof(fat_cluster_t)) / bps; |
168 | fidx = clst % (bps / sizeof(fat_cluster_t)); |
171 | fidx = clst % (bps / sizeof(fat_cluster_t)); |
169 | /* read FAT1 */ |
172 | /* read FAT1 */ |
170 | b = block_get(nodep->idx->dev_handle, rscnt + fsec); |
173 | b = block_get(dev_handle, rscnt + fsec); |
171 | clst = uint16_t_le2host(((fat_cluster_t *)b->data)[fidx]); |
174 | clst = uint16_t_le2host(((fat_cluster_t *)b->data)[fidx]); |
172 | assert(clst != FAT_CLST_BAD); |
175 | assert(clst != FAT_CLST_BAD); |
173 | assert(clst < FAT_CLST_LAST1); |
176 | assert(clst < FAT_CLST_LAST1); |
174 | block_put(b); |
177 | block_put(b); |
175 | } |
178 | } |
176 | 179 | ||
177 | b = block_get(nodep->idx->dev_handle, ssa + |
180 | b = block_get(dev_handle, ssa + (clst - FAT_CLST_FIRST) * spc + |
178 | (clst - FAT_CLST_FIRST) * spc + offset % spc); |
181 | offset % spc); |
179 | 182 | ||
180 | return b; |
183 | return b; |
181 | } |
184 | } |
182 | 185 | ||
183 | static void fat_node_initialize(fat_node_t *node) |
186 | static void fat_node_initialize(fat_node_t *node) |
Line 239... | Line 242... | ||
239 | { |
242 | { |
240 | /* TODO */ |
243 | /* TODO */ |
241 | } |
244 | } |
242 | 245 | ||
243 | /** Instantiate a FAT in-core node. */ |
246 | /** Instantiate a FAT in-core node. */ |
244 | static void * |
- | |
245 | fat_node_get(dev_handle_t dev_handle, fs_index_t index) |
247 | static void *fat_node_get(dev_handle_t dev_handle, fs_index_t index) |
246 | { |
248 | { |
- | 249 | fat_idx_t *idx; |
|
- | 250 | block_t *b; |
|
- | 251 | fat_dentry_t *d; |
|
- | 252 | fat_node_t *nodep; |
|
- | 253 | unsigned bps; |
|
- | 254 | unsigned dps; |
|
- | 255 | ||
- | 256 | idx = fat_idx_get_by_index(dev_handle, index); |
|
- | 257 | if (!idx) |
|
247 | return NULL; /* TODO */ |
258 | return NULL; |
- | 259 | ||
- | 260 | if (idx->nodep) { |
|
- | 261 | /* |
|
- | 262 | * We are lucky. |
|
- | 263 | * The node is already instantiated in memory. |
|
- | 264 | */ |
|
- | 265 | idx->nodep->refcnt++; |
|
- | 266 | return idx->nodep; |
|
- | 267 | } |
|
- | 268 | ||
- | 269 | /* |
|
- | 270 | * We must instantiate the node from the file system. |
|
- | 271 | */ |
|
- | 272 | ||
- | 273 | assert(idx->pfc); |
|
- | 274 | ||
- | 275 | nodep = (fat_node_t *)malloc(sizeof(fat_node_t)); |
|
- | 276 | if (!nodep) |
|
- | 277 | return NULL; |
|
- | 278 | fat_node_initialize(nodep); |
|
- | 279 | ||
- | 280 | bps = fat_bps_get(dev_handle); |
|
- | 281 | dps = bps / sizeof(fat_dentry_t); |
|
- | 282 | ||
- | 283 | b = _fat_block_get(dev_handle, idx->pfc, |
|
- | 284 | (idx->pdi * sizeof(fat_dentry_t)) / bps); |
|
- | 285 | ||
- | 286 | assert(b); |
|
- | 287 | ||
- | 288 | d = ((fat_dentry_t *)b->data) + (idx->pdi % dps); |
|
- | 289 | /* XXX */ |
|
248 | } |
290 | } |
249 | 291 | ||
250 | static void fat_node_put(void *node) |
292 | static void fat_node_put(void *node) |
251 | { |
293 | { |
252 | /* TODO */ |
294 | /* TODO */ |
Line 396... | Line 438... | ||
396 | return false; |
438 | return false; |
397 | } |
439 | } |
398 | 440 | ||
399 | static void *fat_root_get(dev_handle_t dev_handle) |
441 | static void *fat_root_get(dev_handle_t dev_handle) |
400 | { |
442 | { |
401 | return fat_node_get(dev_handle, FAT_CLST_RES1); |
443 | return fat_node_get(dev_handle, 0); /* TODO */ |
402 | } |
444 | } |
403 | 445 | ||
404 | static char fat_plb_get_char(unsigned pos) |
446 | static char fat_plb_get_char(unsigned pos) |
405 | { |
447 | { |
406 | return fat_reg.plb_ro[pos % PLB_SIZE]; |
448 | return fat_reg.plb_ro[pos % PLB_SIZE]; |