Rev 3612 | Rev 3675 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 3612 | Rev 3623 | ||
|---|---|---|---|
| Line 214... | Line 214... | ||
| 214 | idxp->nodep = nodep; |
214 | idxp->nodep = nodep; |
| 215 | 215 | ||
| 216 | return nodep; |
216 | return nodep; |
| 217 | } |
217 | } |
| 218 | 218 | ||
| - | 219 | /* |
|
| - | 220 | * Forward declarations of FAT libfs operations. |
|
| - | 221 | */ |
|
| - | 222 | static void *fat_node_get(dev_handle_t, fs_index_t); |
|
| - | 223 | static void fat_node_put(void *); |
|
| - | 224 | static void *fat_create_node(dev_handle_t, int); |
|
| - | 225 | static int fat_destroy_node(void *); |
|
| - | 226 | static bool fat_link(void *, void *, const char *); |
|
| - | 227 | static int fat_unlink(void *, void *); |
|
| - | 228 | static void *fat_match(void *, const char *); |
|
| - | 229 | static fs_index_t fat_index_get(void *); |
|
| - | 230 | static size_t fat_size_get(void *); |
|
| - | 231 | static unsigned fat_lnkcnt_get(void *); |
|
| - | 232 | static bool fat_has_children(void *); |
|
| - | 233 | static void *fat_root_get(dev_handle_t); |
|
| - | 234 | static char fat_plb_get_char(unsigned); |
|
| - | 235 | static bool fat_is_directory(void *); |
|
| - | 236 | static bool fat_is_file(void *node); |
|
| - | 237 | ||
| - | 238 | /* |
|
| - | 239 | * FAT libfs operations. |
|
| - | 240 | */ |
|
| - | 241 | ||
| 219 | /** Instantiate a FAT in-core node. */ |
242 | /** Instantiate a FAT in-core node. */ |
| 220 | static void *fat_node_get(dev_handle_t dev_handle, fs_index_t index) |
243 | void *fat_node_get(dev_handle_t dev_handle, fs_index_t index) |
| 221 | { |
244 | { |
| 222 | void *node; |
245 | void *node; |
| 223 | fat_idx_t *idxp; |
246 | fat_idx_t *idxp; |
| 224 | 247 | ||
| 225 | idxp = fat_idx_get_by_index(dev_handle, index); |
248 | idxp = fat_idx_get_by_index(dev_handle, index); |
| Line 229... | Line 252... | ||
| 229 | node = fat_node_get_core(idxp); |
252 | node = fat_node_get_core(idxp); |
| 230 | futex_up(&idxp->lock); |
253 | futex_up(&idxp->lock); |
| 231 | return node; |
254 | return node; |
| 232 | } |
255 | } |
| 233 | 256 | ||
| 234 | static void fat_node_put(void *node) |
257 | void fat_node_put(void *node) |
| 235 | { |
258 | { |
| 236 | fat_node_t *nodep = (fat_node_t *)node; |
259 | fat_node_t *nodep = (fat_node_t *)node; |
| 237 | bool destroy = false; |
260 | bool destroy = false; |
| 238 | 261 | ||
| 239 | futex_down(&nodep->lock); |
262 | futex_down(&nodep->lock); |
| Line 255... | Line 278... | ||
| 255 | futex_up(&nodep->lock); |
278 | futex_up(&nodep->lock); |
| 256 | if (destroy) |
279 | if (destroy) |
| 257 | free(node); |
280 | free(node); |
| 258 | } |
281 | } |
| 259 | 282 | ||
| 260 | static void *fat_create_node(dev_handle_t dev_handle, int flags) |
283 | void *fat_create_node(dev_handle_t dev_handle, int flags) |
| 261 | { |
284 | { |
| 262 | fat_idx_t *idxp; |
285 | fat_idx_t *idxp; |
| 263 | fat_node_t *nodep; |
286 | fat_node_t *nodep; |
| 264 | 287 | ||
| 265 | nodep = fat_node_get_new(); |
288 | nodep = fat_node_get_new(); |
| Line 286... | Line 309... | ||
| 286 | 309 | ||
| 287 | futex_up(&idxp->lock); |
310 | futex_up(&idxp->lock); |
| 288 | return nodep; |
311 | return nodep; |
| 289 | } |
312 | } |
| 290 | 313 | ||
| 291 | static int fat_destroy_node(void *node) |
314 | int fat_destroy_node(void *node) |
| 292 | { |
315 | { |
| - | 316 | fat_node_t *nodep = (fat_node_t *)node; |
|
| - | 317 | fat_bs_t *bs; |
|
| - | 318 | ||
| - | 319 | /* |
|
| - | 320 | * The node is not reachable from the file system. This means that the |
|
| - | 321 | * link count should be zero and that the index structure cannot be |
|
| - | 322 | * found in the position hash. Obviously, we don't need to lock the node |
|
| - | 323 | * nor its index structure. |
|
| - | 324 | */ |
|
| - | 325 | assert(nodep->lnkcnt == 0); |
|
| - | 326 | ||
| - | 327 | /* |
|
| - | 328 | * The node may not have any children. |
|
| - | 329 | */ |
|
| - | 330 | assert(fat_has_children(node) == false); |
|
| - | 331 | ||
| - | 332 | bs = block_bb_get(nodep->idx->dev_handle); |
|
| - | 333 | if (nodep->firstc != FAT_CLST_RES0) { |
|
| - | 334 | assert(nodep->size); |
|
| 293 | return ENOTSUP; /* not supported at the moment */ |
335 | /* Free all clusters allocated to the node. */ |
| - | 336 | fat_free_clusters(bs, nodep->idx->dev_handle, nodep->firstc); |
|
| - | 337 | } |
|
| - | 338 | ||
| - | 339 | fat_idx_destroy(nodep->idx); |
|
| - | 340 | free(nodep); |
|
| - | 341 | return EOK; |
|
| 294 | } |
342 | } |
| 295 | 343 | ||
| 296 | static bool fat_link(void *prnt, void *chld, const char *name) |
344 | bool fat_link(void *prnt, void *chld, const char *name) |
| 297 | { |
345 | { |
| 298 | return false; /* not supported at the moment */ |
346 | return false; /* not supported at the moment */ |
| 299 | } |
347 | } |
| 300 | 348 | ||
| 301 | static int fat_unlink(void *prnt, void *chld) |
349 | int fat_unlink(void *prnt, void *chld) |
| 302 | { |
350 | { |
| 303 | return ENOTSUP; /* not supported at the moment */ |
351 | return ENOTSUP; /* not supported at the moment */ |
| 304 | } |
352 | } |
| 305 | 353 | ||
| 306 | static void *fat_match(void *prnt, const char *component) |
354 | void *fat_match(void *prnt, const char *component) |
| 307 | { |
355 | { |
| 308 | fat_bs_t *bs; |
356 | fat_bs_t *bs; |
| 309 | fat_node_t *parentp = (fat_node_t *)prnt; |
357 | fat_node_t *parentp = (fat_node_t *)prnt; |
| 310 | char name[FAT_NAME_LEN + 1 + FAT_EXT_LEN + 1]; |
358 | char name[FAT_NAME_LEN + 1 + FAT_EXT_LEN + 1]; |
| 311 | unsigned i, j; |
359 | unsigned i, j; |
| Line 368... | Line 416... | ||
| 368 | 416 | ||
| 369 | futex_up(&parentp->idx->lock); |
417 | futex_up(&parentp->idx->lock); |
| 370 | return NULL; |
418 | return NULL; |
| 371 | } |
419 | } |
| 372 | 420 | ||
| 373 | static fs_index_t fat_index_get(void *node) |
421 | fs_index_t fat_index_get(void *node) |
| 374 | { |
422 | { |
| 375 | fat_node_t *fnodep = (fat_node_t *)node; |
423 | fat_node_t *fnodep = (fat_node_t *)node; |
| 376 | if (!fnodep) |
424 | if (!fnodep) |
| 377 | return 0; |
425 | return 0; |
| 378 | return fnodep->idx->index; |
426 | return fnodep->idx->index; |
| 379 | } |
427 | } |
| 380 | 428 | ||
| 381 | static size_t fat_size_get(void *node) |
429 | size_t fat_size_get(void *node) |
| 382 | { |
430 | { |
| 383 | return ((fat_node_t *)node)->size; |
431 | return ((fat_node_t *)node)->size; |
| 384 | } |
432 | } |
| 385 | 433 | ||
| 386 | static unsigned fat_lnkcnt_get(void *node) |
434 | unsigned fat_lnkcnt_get(void *node) |
| 387 | { |
435 | { |
| 388 | return ((fat_node_t *)node)->lnkcnt; |
436 | return ((fat_node_t *)node)->lnkcnt; |
| 389 | } |
437 | } |
| 390 | 438 | ||
| 391 | static bool fat_has_children(void *node) |
439 | bool fat_has_children(void *node) |
| 392 | { |
440 | { |
| 393 | fat_bs_t *bs; |
441 | fat_bs_t *bs; |
| 394 | fat_node_t *nodep = (fat_node_t *)node; |
442 | fat_node_t *nodep = (fat_node_t *)node; |
| 395 | unsigned bps; |
443 | unsigned bps; |
| 396 | unsigned dps; |
444 | unsigned dps; |
| Line 436... | Line 484... | ||
| 436 | 484 | ||
| 437 | futex_up(&nodep->idx->lock); |
485 | futex_up(&nodep->idx->lock); |
| 438 | return false; |
486 | return false; |
| 439 | } |
487 | } |
| 440 | 488 | ||
| 441 | static void *fat_root_get(dev_handle_t dev_handle) |
489 | void *fat_root_get(dev_handle_t dev_handle) |
| 442 | { |
490 | { |
| 443 | return fat_node_get(dev_handle, 0); |
491 | return fat_node_get(dev_handle, 0); |
| 444 | } |
492 | } |
| 445 | 493 | ||
| 446 | static char fat_plb_get_char(unsigned pos) |
494 | char fat_plb_get_char(unsigned pos) |
| 447 | { |
495 | { |
| 448 | return fat_reg.plb_ro[pos % PLB_SIZE]; |
496 | return fat_reg.plb_ro[pos % PLB_SIZE]; |
| 449 | } |
497 | } |
| 450 | 498 | ||
| 451 | static bool fat_is_directory(void *node) |
499 | bool fat_is_directory(void *node) |
| 452 | { |
500 | { |
| 453 | return ((fat_node_t *)node)->type == FAT_DIRECTORY; |
501 | return ((fat_node_t *)node)->type == FAT_DIRECTORY; |
| 454 | } |
502 | } |
| 455 | 503 | ||
| 456 | static bool fat_is_file(void *node) |
504 | bool fat_is_file(void *node) |
| 457 | { |
505 | { |
| 458 | return ((fat_node_t *)node)->type == FAT_FILE; |
506 | return ((fat_node_t *)node)->type == FAT_FILE; |
| 459 | } |
507 | } |
| 460 | 508 | ||
| 461 | /** libfs operations */ |
509 | /** libfs operations */ |
| Line 836... | Line 884... | ||
| 836 | fat_node_put(nodep); |
884 | fat_node_put(nodep); |
| 837 | ipc_answer_0(rid, rc); |
885 | ipc_answer_0(rid, rc); |
| 838 | return; |
886 | return; |
| 839 | } |
887 | } |
| 840 | 888 | ||
| - | 889 | void fat_destroy(ipc_callid_t rid, ipc_call_t *request) |
|
| - | 890 | { |
|
| - | 891 | dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request); |
|
| - | 892 | fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request); |
|
| - | 893 | int rc; |
|
| - | 894 | ||
| - | 895 | fat_node_t *nodep = fat_node_get(dev_handle, index); |
|
| - | 896 | if (!nodep) { |
|
| - | 897 | ipc_answer_0(rid, ENOENT); |
|
| - | 898 | return; |
|
| - | 899 | } |
|
| - | 900 | ||
| - | 901 | rc = fat_destroy_node(nodep); |
|
| - | 902 | ipc_answer_0(rid, rc); |
|
| - | 903 | } |
|
| - | 904 | ||
| 841 | /** |
905 | /** |
| 842 | * @} |
906 | * @} |
| 843 | */ |
907 | */ |