Rev 3602 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 3602 | Rev 3665 | ||
|---|---|---|---|
| Line 92... | Line 92... | ||
| 92 | (node->idx->pdi * sizeof(fat_dentry_t)) / bps, BLOCK_FLAGS_NONE); |
92 | (node->idx->pdi * sizeof(fat_dentry_t)) / bps, BLOCK_FLAGS_NONE); |
| 93 | 93 | ||
| 94 | d = ((fat_dentry_t *)b->data) + (node->idx->pdi % dps); |
94 | d = ((fat_dentry_t *)b->data) + (node->idx->pdi % dps); |
| 95 | 95 | ||
| 96 | d->firstc = host2uint16_t_le(node->firstc); |
96 | d->firstc = host2uint16_t_le(node->firstc); |
| 97 | if (node->type == FAT_FILE) |
97 | if (node->type == FAT_FILE) { |
| 98 | d->size = host2uint32_t_le(node->size); |
98 | d->size = host2uint32_t_le(node->size); |
| - | 99 | } else if (node->type == FAT_DIRECTORY) { |
|
| - | 100 | d->attr = FAT_ATTR_SUBDIR; |
|
| - | 101 | } |
|
| - | 102 | ||
| 99 | /* TODO: update other fields? (e.g time fields, attr field) */ |
103 | /* TODO: update other fields? (e.g time fields) */ |
| 100 | 104 | ||
| 101 | b->dirty = true; /* need to sync block */ |
105 | b->dirty = true; /* need to sync block */ |
| 102 | block_put(b); |
106 | block_put(b); |
| 103 | } |
107 | } |
| 104 | 108 | ||
| Line 214... | Line 218... | ||
| 214 | idxp->nodep = nodep; |
218 | idxp->nodep = nodep; |
| 215 | 219 | ||
| 216 | return nodep; |
220 | return nodep; |
| 217 | } |
221 | } |
| 218 | 222 | ||
| - | 223 | /* |
|
| - | 224 | * Forward declarations of FAT libfs operations. |
|
| - | 225 | */ |
|
| - | 226 | static void *fat_node_get(dev_handle_t, fs_index_t); |
|
| - | 227 | static void fat_node_put(void *); |
|
| - | 228 | static void *fat_create_node(dev_handle_t, int); |
|
| - | 229 | static int fat_destroy_node(void *); |
|
| - | 230 | static int fat_link(void *, void *, const char *); |
|
| - | 231 | static int fat_unlink(void *, void *); |
|
| - | 232 | static void *fat_match(void *, const char *); |
|
| - | 233 | static fs_index_t fat_index_get(void *); |
|
| - | 234 | static size_t fat_size_get(void *); |
|
| - | 235 | static unsigned fat_lnkcnt_get(void *); |
|
| - | 236 | static bool fat_has_children(void *); |
|
| - | 237 | static void *fat_root_get(dev_handle_t); |
|
| - | 238 | static char fat_plb_get_char(unsigned); |
|
| - | 239 | static bool fat_is_directory(void *); |
|
| - | 240 | static bool fat_is_file(void *node); |
|
| - | 241 | ||
| - | 242 | /* |
|
| - | 243 | * FAT libfs operations. |
|
| - | 244 | */ |
|
| - | 245 | ||
| 219 | /** Instantiate a FAT in-core node. */ |
246 | /** Instantiate a FAT in-core node. */ |
| 220 | static void *fat_node_get(dev_handle_t dev_handle, fs_index_t index) |
247 | void *fat_node_get(dev_handle_t dev_handle, fs_index_t index) |
| 221 | { |
248 | { |
| 222 | void *node; |
249 | void *node; |
| 223 | fat_idx_t *idxp; |
250 | fat_idx_t *idxp; |
| 224 | 251 | ||
| 225 | idxp = fat_idx_get_by_index(dev_handle, index); |
252 | idxp = fat_idx_get_by_index(dev_handle, index); |
| Line 229... | Line 256... | ||
| 229 | node = fat_node_get_core(idxp); |
256 | node = fat_node_get_core(idxp); |
| 230 | futex_up(&idxp->lock); |
257 | futex_up(&idxp->lock); |
| 231 | return node; |
258 | return node; |
| 232 | } |
259 | } |
| 233 | 260 | ||
| 234 | static void fat_node_put(void *node) |
261 | void fat_node_put(void *node) |
| 235 | { |
262 | { |
| 236 | fat_node_t *nodep = (fat_node_t *)node; |
263 | fat_node_t *nodep = (fat_node_t *)node; |
| - | 264 | bool destroy = false; |
|
| 237 | 265 | ||
| 238 | futex_down(&nodep->lock); |
266 | futex_down(&nodep->lock); |
| 239 | if (!--nodep->refcnt) { |
267 | if (!--nodep->refcnt) { |
| - | 268 | if (nodep->idx) { |
|
| 240 | futex_down(&ffn_futex); |
269 | futex_down(&ffn_futex); |
| 241 | list_append(&nodep->ffn_link, &ffn_head); |
270 | list_append(&nodep->ffn_link, &ffn_head); |
| 242 | futex_up(&ffn_futex); |
271 | futex_up(&ffn_futex); |
| - | 272 | } else { |
|
| - | 273 | /* |
|
| - | 274 | * The node does not have any index structure associated |
|
| - | 275 | * with itself. This can only mean that we are releasing |
|
| - | 276 | * the node after a failed attempt to allocate the index |
|
| - | 277 | * structure for it. |
|
| - | 278 | */ |
|
| - | 279 | destroy = true; |
|
| - | 280 | } |
|
| 243 | } |
281 | } |
| 244 | futex_up(&nodep->lock); |
282 | futex_up(&nodep->lock); |
| - | 283 | if (destroy) |
|
| - | 284 | free(node); |
|
| 245 | } |
285 | } |
| 246 | 286 | ||
| 247 | static void *fat_create(dev_handle_t dev_handle, int flags) |
287 | void *fat_create_node(dev_handle_t dev_handle, int flags) |
| 248 | { |
288 | { |
| - | 289 | fat_idx_t *idxp; |
|
| - | 290 | fat_node_t *nodep; |
|
| - | 291 | fat_bs_t *bs; |
|
| - | 292 | fat_cluster_t mcl, lcl; |
|
| - | 293 | uint16_t bps; |
|
| - | 294 | int rc; |
|
| - | 295 | ||
| - | 296 | bs = block_bb_get(dev_handle); |
|
| - | 297 | bps = uint16_t_le2host(bs->bps); |
|
| - | 298 | if (flags & L_DIRECTORY) { |
|
| - | 299 | /* allocate a cluster */ |
|
| - | 300 | rc = fat_alloc_clusters(bs, dev_handle, 1, &mcl, &lcl); |
|
| - | 301 | if (rc != EOK) |
|
| - | 302 | return NULL; |
|
| - | 303 | } |
|
| - | 304 | ||
| - | 305 | nodep = fat_node_get_new(); |
|
| - | 306 | if (!nodep) { |
|
| - | 307 | fat_free_clusters(bs, dev_handle, mcl); |
|
| - | 308 | return NULL; |
|
| - | 309 | } |
|
| - | 310 | idxp = fat_idx_get_new(dev_handle); |
|
| - | 311 | if (!idxp) { |
|
| - | 312 | fat_free_clusters(bs, dev_handle, mcl); |
|
| - | 313 | fat_node_put(nodep); |
|
| - | 314 | return NULL; |
|
| - | 315 | } |
|
| - | 316 | /* idxp->lock held */ |
|
| - | 317 | if (flags & L_DIRECTORY) { |
|
| - | 318 | int i; |
|
| - | 319 | block_t *b; |
|
| - | 320 | ||
| - | 321 | /* |
|
| - | 322 | * Populate the new cluster with unused dentries. |
|
| - | 323 | */ |
|
| - | 324 | for (i = 0; i < bs->spc; i++) { |
|
| - | 325 | b = _fat_block_get(bs, dev_handle, mcl, i, |
|
| - | 326 | BLOCK_FLAGS_NOREAD); |
|
| - | 327 | /* mark all dentries as never-used */ |
|
| - | 328 | memset(b->data, 0, bps); |
|
| - | 329 | b->dirty = false; |
|
| - | 330 | block_put(b); |
|
| - | 331 | } |
|
| - | 332 | nodep->type = FAT_DIRECTORY; |
|
| - | 333 | nodep->firstc = mcl; |
|
| - | 334 | nodep->size = bps * bs->spc; |
|
| - | 335 | } else { |
|
| - | 336 | nodep->type = FAT_FILE; |
|
| - | 337 | nodep->firstc = FAT_CLST_RES0; |
|
| - | 338 | nodep->size = 0; |
|
| - | 339 | } |
|
| 249 | return NULL; /* not supported at the moment */ |
340 | nodep->lnkcnt = 0; /* not linked anywhere */ |
| - | 341 | nodep->refcnt = 1; |
|
| - | 342 | nodep->dirty = true; |
|
| - | 343 | ||
| - | 344 | nodep->idx = idxp; |
|
| - | 345 | idxp->nodep = nodep; |
|
| - | 346 | ||
| - | 347 | futex_up(&idxp->lock); |
|
| - | 348 | return nodep; |
|
| 250 | } |
349 | } |
| 251 | 350 | ||
| 252 | static int fat_destroy(void *node) |
351 | int fat_destroy_node(void *node) |
| 253 | { |
352 | { |
| - | 353 | fat_node_t *nodep = (fat_node_t *)node; |
|
| - | 354 | fat_bs_t *bs; |
|
| - | 355 | ||
| - | 356 | /* |
|
| - | 357 | * The node is not reachable from the file system. This means that the |
|
| - | 358 | * link count should be zero and that the index structure cannot be |
|
| - | 359 | * found in the position hash. Obviously, we don't need to lock the node |
|
| - | 360 | * nor its index structure. |
|
| - | 361 | */ |
|
| - | 362 | assert(nodep->lnkcnt == 0); |
|
| - | 363 | ||
| - | 364 | /* |
|
| - | 365 | * The node may not have any children. |
|
| - | 366 | */ |
|
| - | 367 | assert(fat_has_children(node) == false); |
|
| - | 368 | ||
| - | 369 | bs = block_bb_get(nodep->idx->dev_handle); |
|
| - | 370 | if (nodep->firstc != FAT_CLST_RES0) { |
|
| - | 371 | assert(nodep->size); |
|
| 254 | return ENOTSUP; /* not supported at the moment */ |
372 | /* Free all clusters allocated to the node. */ |
| - | 373 | fat_free_clusters(bs, nodep->idx->dev_handle, nodep->firstc); |
|
| - | 374 | } |
|
| - | 375 | ||
| - | 376 | fat_idx_destroy(nodep->idx); |
|
| - | 377 | free(nodep); |
|
| - | 378 | return EOK; |
|
| 255 | } |
379 | } |
| 256 | 380 | ||
| 257 | static bool fat_link(void *prnt, void *chld, const char *name) |
381 | int fat_link(void *prnt, void *chld, const char *name) |
| 258 | { |
382 | { |
| - | 383 | fat_node_t *parentp = (fat_node_t *)prnt; |
|
| - | 384 | fat_node_t *childp = (fat_node_t *)chld; |
|
| - | 385 | fat_dentry_t *d; |
|
| - | 386 | fat_bs_t *bs; |
|
| - | 387 | block_t *b; |
|
| - | 388 | int i, j; |
|
| - | 389 | uint16_t bps; |
|
| - | 390 | unsigned dps; |
|
| - | 391 | unsigned blocks; |
|
| - | 392 | ||
| - | 393 | futex_down(&childp->lock); |
|
| - | 394 | if (childp->lnkcnt == 1) { |
|
| - | 395 | /* |
|
| 259 | return false; /* not supported at the moment */ |
396 | * On FAT, we don't support multiple hard links. |
| - | 397 | */ |
|
| - | 398 | futex_up(&childp->lock); |
|
| - | 399 | return EMLINK; |
|
| - | 400 | } |
|
| - | 401 | assert(childp->lnkcnt == 0); |
|
| - | 402 | futex_up(&childp->lock); |
|
| - | 403 | ||
| - | 404 | if (!fat_dentry_name_verify(name)) { |
|
| - | 405 | /* |
|
| - | 406 | * Attempt to create unsupported name. |
|
| - | 407 | */ |
|
| - | 408 | return ENOTSUP; |
|
| - | 409 | } |
|
| - | 410 | ||
| - | 411 | /* |
|
| - | 412 | * Get us an unused parent node's dentry or grow the parent and allocate |
|
| - | 413 | * a new one. |
|
| - | 414 | */ |
|
| - | 415 | ||
| - | 416 | futex_down(&parentp->idx->lock); |
|
| - | 417 | bs = block_bb_get(parentp->idx->dev_handle); |
|
| - | 418 | bps = uint16_t_le2host(bs->bps); |
|
| - | 419 | dps = bps / sizeof(fat_dentry_t); |
|
| - | 420 | ||
| - | 421 | blocks = parentp->size / bps; |
|
| - | 422 | ||
| - | 423 | for (i = 0; i < blocks; i++) { |
|
| - | 424 | b = fat_block_get(bs, parentp, i, BLOCK_FLAGS_NONE); |
|
| - | 425 | for (j = 0; j < dps; j++) { |
|
| - | 426 | d = ((fat_dentry_t *)b->data) + j; |
|
| - | 427 | switch (fat_classify_dentry(d)) { |
|
| - | 428 | case FAT_DENTRY_SKIP: |
|
| - | 429 | case FAT_DENTRY_VALID: |
|
| - | 430 | /* skipping used and meta entries */ |
|
| - | 431 | continue; |
|
| - | 432 | case FAT_DENTRY_FREE: |
|
| - | 433 | case FAT_DENTRY_LAST: |
|
| - | 434 | /* found an empty slot */ |
|
| - | 435 | goto hit; |
|
| - | 436 | } |
|
| - | 437 | } |
|
| - | 438 | block_put(b); |
|
| - | 439 | } |
|
| - | 440 | ||
| - | 441 | /* |
|
| - | 442 | * We need to grow the parent in order to create a new unused dentry. |
|
| - | 443 | */ |
|
| - | 444 | futex_up(&parentp->idx->lock); |
|
| - | 445 | return ENOTSUP; /* XXX */ |
|
| - | 446 | ||
| - | 447 | hit: |
|
| - | 448 | /* |
|
| - | 449 | * At this point we only establish the link between the parent and the |
|
| - | 450 | * child. The dentry, except of the name and the extension, will remain |
|
| - | 451 | * uninitialized until the the corresponding node is synced. Thus the |
|
| - | 452 | * valid dentry data is kept in the child node structure. |
|
| - | 453 | */ |
|
| - | 454 | memset(d, 0, sizeof(fat_dentry_t)); |
|
| - | 455 | fat_dentry_name_set(d, name); |
|
| - | 456 | b->dirty = true; /* need to sync block */ |
|
| - | 457 | block_put(b); |
|
| - | 458 | futex_up(&parentp->idx->lock); |
|
| - | 459 | ||
| - | 460 | futex_down(&childp->idx->lock); |
|
| - | 461 | ||
| - | 462 | /* |
|
| - | 463 | * If possible, create the Sub-directory Identifier Entry and the |
|
| - | 464 | * Sub-directory Parent Pointer Entry (i.e. "." and ".."). These entries |
|
| - | 465 | * are not mandatory according to Standard ECMA-107 and HelenOS VFS does |
|
| - | 466 | * not use them anyway, so this is rather a sign of our good will. |
|
| - | 467 | */ |
|
| - | 468 | b = fat_block_get(bs, childp, 0, BLOCK_FLAGS_NONE); |
|
| - | 469 | d = (fat_dentry_t *)b->data; |
|
| - | 470 | if (fat_classify_dentry(d) == FAT_DENTRY_LAST || |
|
| - | 471 | strcmp(d->name, FAT_NAME_DOT) == 0) { |
|
| - | 472 | memset(d, 0, sizeof(fat_dentry_t)); |
|
| - | 473 | strcpy(d->name, FAT_NAME_DOT); |
|
| - | 474 | strcpy(d->ext, FAT_EXT_PAD); |
|
| - | 475 | d->attr = FAT_ATTR_SUBDIR; |
|
| - | 476 | d->firstc = host2uint16_t_le(childp->firstc); |
|
| - | 477 | /* TODO: initialize also the date/time members. */ |
|
| - | 478 | } |
|
| - | 479 | d++; |
|
| - | 480 | if (fat_classify_dentry(d) == FAT_DENTRY_LAST || |
|
| - | 481 | strcmp(d->name, FAT_NAME_DOT_DOT) == 0) { |
|
| - | 482 | memset(d, 0, sizeof(fat_dentry_t)); |
|
| - | 483 | strcpy(d->name, FAT_NAME_DOT_DOT); |
|
| - | 484 | strcpy(d->ext, FAT_EXT_PAD); |
|
| - | 485 | d->attr = FAT_ATTR_SUBDIR; |
|
| - | 486 | d->firstc = (parentp->firstc == FAT_CLST_ROOT) ? |
|
| - | 487 | host2uint16_t_le(FAT_CLST_RES0) : |
|
| - | 488 | host2uint16_t_le(parentp->firstc); |
|
| - | 489 | /* TODO: initialize also the date/time members. */ |
|
| - | 490 | } |
|
| - | 491 | b->dirty = true; /* need to sync block */ |
|
| - | 492 | block_put(b); |
|
| - | 493 | ||
| - | 494 | childp->idx->pfc = parentp->firstc; |
|
| - | 495 | childp->idx->pdi = i * dps + j; |
|
| - | 496 | futex_up(&childp->idx->lock); |
|
| - | 497 | ||
| - | 498 | futex_down(&childp->lock); |
|
| - | 499 | childp->lnkcnt = 1; |
|
| - | 500 | childp->dirty = true; /* need to sync node */ |
|
| - | 501 | futex_up(&childp->lock); |
|
| - | 502 | ||
| - | 503 | /* |
|
| - | 504 | * Hash in the index structure into the position hash. |
|
| - | 505 | */ |
|
| - | 506 | fat_idx_hashin(childp->idx); |
|
| - | 507 | ||
| - | 508 | return EOK; |
|
| 260 | } |
509 | } |
| 261 | 510 | ||
| 262 | static int fat_unlink(void *prnt, void *chld) |
511 | int fat_unlink(void *prnt, void *chld) |
| 263 | { |
512 | { |
| - | 513 | fat_node_t *parentp = (fat_node_t *)prnt; |
|
| - | 514 | fat_node_t *childp = (fat_node_t *)chld; |
|
| - | 515 | fat_bs_t *bs; |
|
| - | 516 | fat_dentry_t *d; |
|
| - | 517 | uint16_t bps; |
|
| - | 518 | block_t *b; |
|
| - | 519 | ||
| - | 520 | futex_down(&parentp->lock); |
|
| - | 521 | futex_down(&childp->lock); |
|
| - | 522 | assert(childp->lnkcnt == 1); |
|
| - | 523 | futex_down(&childp->idx->lock); |
|
| - | 524 | bs = block_bb_get(childp->idx->dev_handle); |
|
| - | 525 | bps = uint16_t_le2host(bs->bps); |
|
| - | 526 | ||
| - | 527 | b = _fat_block_get(bs, childp->idx->dev_handle, childp->idx->pfc, |
|
| - | 528 | (childp->idx->pdi * sizeof(fat_dentry_t)) / bps, |
|
| - | 529 | BLOCK_FLAGS_NONE); |
|
| - | 530 | d = (fat_dentry_t *)b->data + |
|
| - | 531 | (childp->idx->pdi % (bps / sizeof(fat_dentry_t))); |
|
| - | 532 | /* mark the dentry as not-currently-used */ |
|
| - | 533 | d->name[0] = FAT_DENTRY_ERASED; |
|
| 264 | return ENOTSUP; /* not supported at the moment */ |
534 | b->dirty = true; /* need to sync block */ |
| - | 535 | block_put(b); |
|
| - | 536 | ||
| - | 537 | /* remove the index structure from the position hash */ |
|
| - | 538 | fat_idx_hashout(childp->idx); |
|
| - | 539 | /* clear position information */ |
|
| - | 540 | childp->idx->pfc = FAT_CLST_RES0; |
|
| - | 541 | childp->idx->pdi = 0; |
|
| - | 542 | futex_up(&childp->idx->lock); |
|
| - | 543 | childp->lnkcnt = 0; |
|
| - | 544 | childp->dirty = true; |
|
| - | 545 | futex_up(&childp->lock); |
|
| - | 546 | futex_up(&parentp->lock); |
|
| - | 547 | ||
| - | 548 | return EOK; |
|
| 265 | } |
549 | } |
| 266 | 550 | ||
| 267 | static void *fat_match(void *prnt, const char *component) |
551 | void *fat_match(void *prnt, const char *component) |
| 268 | { |
552 | { |
| 269 | fat_bs_t *bs; |
553 | fat_bs_t *bs; |
| 270 | fat_node_t *parentp = (fat_node_t *)prnt; |
554 | fat_node_t *parentp = (fat_node_t *)prnt; |
| 271 | char name[FAT_NAME_LEN + 1 + FAT_EXT_LEN + 1]; |
555 | char name[FAT_NAME_LEN + 1 + FAT_EXT_LEN + 1]; |
| 272 | unsigned i, j; |
556 | unsigned i, j; |
| Line 285... | Line 569... | ||
| 285 | b = fat_block_get(bs, parentp, i, BLOCK_FLAGS_NONE); |
569 | b = fat_block_get(bs, parentp, i, BLOCK_FLAGS_NONE); |
| 286 | for (j = 0; j < dps; j++) { |
570 | for (j = 0; j < dps; j++) { |
| 287 | d = ((fat_dentry_t *)b->data) + j; |
571 | d = ((fat_dentry_t *)b->data) + j; |
| 288 | switch (fat_classify_dentry(d)) { |
572 | switch (fat_classify_dentry(d)) { |
| 289 | case FAT_DENTRY_SKIP: |
573 | case FAT_DENTRY_SKIP: |
| - | 574 | case FAT_DENTRY_FREE: |
|
| 290 | continue; |
575 | continue; |
| 291 | case FAT_DENTRY_LAST: |
576 | case FAT_DENTRY_LAST: |
| 292 | block_put(b); |
577 | block_put(b); |
| 293 | futex_up(&parentp->idx->lock); |
578 | futex_up(&parentp->idx->lock); |
| 294 | return NULL; |
579 | return NULL; |
| 295 | default: |
580 | default: |
| 296 | case FAT_DENTRY_VALID: |
581 | case FAT_DENTRY_VALID: |
| 297 | dentry_name_canonify(d, name); |
582 | fat_dentry_name_get(d, name); |
| 298 | break; |
583 | break; |
| 299 | } |
584 | } |
| 300 | if (stricmp(name, component) == 0) { |
585 | if (fat_dentry_namecmp(name, component) == 0) { |
| 301 | /* hit */ |
586 | /* hit */ |
| 302 | void *node; |
587 | void *node; |
| 303 | /* |
588 | /* |
| 304 | * Assume tree hierarchy for locking. We |
589 | * Assume tree hierarchy for locking. We |
| 305 | * already have the parent and now we are going |
590 | * already have the parent and now we are going |
| Line 329... | Line 614... | ||
| 329 | 614 | ||
| 330 | futex_up(&parentp->idx->lock); |
615 | futex_up(&parentp->idx->lock); |
| 331 | return NULL; |
616 | return NULL; |
| 332 | } |
617 | } |
| 333 | 618 | ||
| 334 | static fs_index_t fat_index_get(void *node) |
619 | fs_index_t fat_index_get(void *node) |
| 335 | { |
620 | { |
| 336 | fat_node_t *fnodep = (fat_node_t *)node; |
621 | fat_node_t *fnodep = (fat_node_t *)node; |
| 337 | if (!fnodep) |
622 | if (!fnodep) |
| 338 | return 0; |
623 | return 0; |
| 339 | return fnodep->idx->index; |
624 | return fnodep->idx->index; |
| 340 | } |
625 | } |
| 341 | 626 | ||
| 342 | static size_t fat_size_get(void *node) |
627 | size_t fat_size_get(void *node) |
| 343 | { |
628 | { |
| 344 | return ((fat_node_t *)node)->size; |
629 | return ((fat_node_t *)node)->size; |
| 345 | } |
630 | } |
| 346 | 631 | ||
| 347 | static unsigned fat_lnkcnt_get(void *node) |
632 | unsigned fat_lnkcnt_get(void *node) |
| 348 | { |
633 | { |
| 349 | return ((fat_node_t *)node)->lnkcnt; |
634 | return ((fat_node_t *)node)->lnkcnt; |
| 350 | } |
635 | } |
| 351 | 636 | ||
| 352 | static bool fat_has_children(void *node) |
637 | bool fat_has_children(void *node) |
| 353 | { |
638 | { |
| 354 | fat_bs_t *bs; |
639 | fat_bs_t *bs; |
| 355 | fat_node_t *nodep = (fat_node_t *)node; |
640 | fat_node_t *nodep = (fat_node_t *)node; |
| 356 | unsigned bps; |
641 | unsigned bps; |
| 357 | unsigned dps; |
642 | unsigned dps; |
| Line 375... | Line 660... | ||
| 375 | b = fat_block_get(bs, nodep, i, BLOCK_FLAGS_NONE); |
660 | b = fat_block_get(bs, nodep, i, BLOCK_FLAGS_NONE); |
| 376 | for (j = 0; j < dps; j++) { |
661 | for (j = 0; j < dps; j++) { |
| 377 | d = ((fat_dentry_t *)b->data) + j; |
662 | d = ((fat_dentry_t *)b->data) + j; |
| 378 | switch (fat_classify_dentry(d)) { |
663 | switch (fat_classify_dentry(d)) { |
| 379 | case FAT_DENTRY_SKIP: |
664 | case FAT_DENTRY_SKIP: |
| - | 665 | case FAT_DENTRY_FREE: |
|
| 380 | continue; |
666 | continue; |
| 381 | case FAT_DENTRY_LAST: |
667 | case FAT_DENTRY_LAST: |
| 382 | block_put(b); |
668 | block_put(b); |
| 383 | futex_up(&nodep->idx->lock); |
669 | futex_up(&nodep->idx->lock); |
| 384 | return false; |
670 | return false; |
| Line 397... | Line 683... | ||
| 397 | 683 | ||
| 398 | futex_up(&nodep->idx->lock); |
684 | futex_up(&nodep->idx->lock); |
| 399 | return false; |
685 | return false; |
| 400 | } |
686 | } |
| 401 | 687 | ||
| 402 | static void *fat_root_get(dev_handle_t dev_handle) |
688 | void *fat_root_get(dev_handle_t dev_handle) |
| 403 | { |
689 | { |
| 404 | return fat_node_get(dev_handle, 0); |
690 | return fat_node_get(dev_handle, 0); |
| 405 | } |
691 | } |
| 406 | 692 | ||
| 407 | static char fat_plb_get_char(unsigned pos) |
693 | char fat_plb_get_char(unsigned pos) |
| 408 | { |
694 | { |
| 409 | return fat_reg.plb_ro[pos % PLB_SIZE]; |
695 | return fat_reg.plb_ro[pos % PLB_SIZE]; |
| 410 | } |
696 | } |
| 411 | 697 | ||
| 412 | static bool fat_is_directory(void *node) |
698 | bool fat_is_directory(void *node) |
| 413 | { |
699 | { |
| 414 | return ((fat_node_t *)node)->type == FAT_DIRECTORY; |
700 | return ((fat_node_t *)node)->type == FAT_DIRECTORY; |
| 415 | } |
701 | } |
| 416 | 702 | ||
| 417 | static bool fat_is_file(void *node) |
703 | bool fat_is_file(void *node) |
| 418 | { |
704 | { |
| 419 | return ((fat_node_t *)node)->type == FAT_FILE; |
705 | return ((fat_node_t *)node)->type == FAT_FILE; |
| 420 | } |
706 | } |
| 421 | 707 | ||
| 422 | /** libfs operations */ |
708 | /** libfs operations */ |
| 423 | libfs_ops_t fat_libfs_ops = { |
709 | libfs_ops_t fat_libfs_ops = { |
| 424 | .match = fat_match, |
710 | .match = fat_match, |
| 425 | .node_get = fat_node_get, |
711 | .node_get = fat_node_get, |
| 426 | .node_put = fat_node_put, |
712 | .node_put = fat_node_put, |
| 427 | .create = fat_create, |
713 | .create = fat_create_node, |
| 428 | .destroy = fat_destroy, |
714 | .destroy = fat_destroy_node, |
| 429 | .link = fat_link, |
715 | .link = fat_link, |
| 430 | .unlink = fat_unlink, |
716 | .unlink = fat_unlink, |
| 431 | .index_get = fat_index_get, |
717 | .index_get = fat_index_get, |
| 432 | .size_get = fat_size_get, |
718 | .size_get = fat_size_get, |
| 433 | .lnkcnt_get = fat_lnkcnt_get, |
719 | .lnkcnt_get = fat_lnkcnt_get, |
| Line 436... | Line 722... | ||
| 436 | .plb_get_char = fat_plb_get_char, |
722 | .plb_get_char = fat_plb_get_char, |
| 437 | .is_directory = fat_is_directory, |
723 | .is_directory = fat_is_directory, |
| 438 | .is_file = fat_is_file |
724 | .is_file = fat_is_file |
| 439 | }; |
725 | }; |
| 440 | 726 | ||
| - | 727 | /* |
|
| - | 728 | * VFS operations. |
|
| - | 729 | */ |
|
| - | 730 | ||
| 441 | void fat_mounted(ipc_callid_t rid, ipc_call_t *request) |
731 | void fat_mounted(ipc_callid_t rid, ipc_call_t *request) |
| 442 | { |
732 | { |
| 443 | dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request); |
733 | dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request); |
| 444 | fat_bs_t *bs; |
734 | fat_bs_t *bs; |
| 445 | uint16_t bps; |
735 | uint16_t bps; |
| Line 605... | Line 895... | ||
| 605 | o < bps / sizeof(fat_dentry_t); |
895 | o < bps / sizeof(fat_dentry_t); |
| 606 | o++, pos++) { |
896 | o++, pos++) { |
| 607 | d = ((fat_dentry_t *)b->data) + o; |
897 | d = ((fat_dentry_t *)b->data) + o; |
| 608 | switch (fat_classify_dentry(d)) { |
898 | switch (fat_classify_dentry(d)) { |
| 609 | case FAT_DENTRY_SKIP: |
899 | case FAT_DENTRY_SKIP: |
| - | 900 | case FAT_DENTRY_FREE: |
|
| 610 | continue; |
901 | continue; |
| 611 | case FAT_DENTRY_LAST: |
902 | case FAT_DENTRY_LAST: |
| 612 | block_put(b); |
903 | block_put(b); |
| 613 | goto miss; |
904 | goto miss; |
| 614 | default: |
905 | default: |
| 615 | case FAT_DENTRY_VALID: |
906 | case FAT_DENTRY_VALID: |
| 616 | dentry_name_canonify(d, name); |
907 | fat_dentry_name_get(d, name); |
| 617 | block_put(b); |
908 | block_put(b); |
| 618 | goto hit; |
909 | goto hit; |
| 619 | } |
910 | } |
| 620 | } |
911 | } |
| 621 | block_put(b); |
912 | block_put(b); |
| Line 797... | Line 1088... | ||
| 797 | fat_node_put(nodep); |
1088 | fat_node_put(nodep); |
| 798 | ipc_answer_0(rid, rc); |
1089 | ipc_answer_0(rid, rc); |
| 799 | return; |
1090 | return; |
| 800 | } |
1091 | } |
| 801 | 1092 | ||
| - | 1093 | void fat_destroy(ipc_callid_t rid, ipc_call_t *request) |
|
| - | 1094 | { |
|
| - | 1095 | dev_handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request); |
|
| - | 1096 | fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request); |
|
| - | 1097 | int rc; |
|
| - | 1098 | ||
| - | 1099 | fat_node_t *nodep = fat_node_get(dev_handle, index); |
|
| - | 1100 | if (!nodep) { |
|
| - | 1101 | ipc_answer_0(rid, ENOENT); |
|
| - | 1102 | return; |
|
| - | 1103 | } |
|
| - | 1104 | ||
| - | 1105 | rc = fat_destroy_node(nodep); |
|
| - | 1106 | ipc_answer_0(rid, rc); |
|
| - | 1107 | } |
|
| - | 1108 | ||
| 802 | /** |
1109 | /** |
| 803 | * @} |
1110 | * @} |
| 804 | */ |
1111 | */ |