* this function will unlink (remove) a specified path file from file system. * * @param path the specified path file to be unlinked. * * @return 0 on successful, -1 on failed. */
| 482 | * @return 0 on successful, -1 on failed. |
| 483 | */ |
| 484 | int dfs_file_unlink(const char *path) |
| 485 | { |
| 486 | int result; |
| 487 | char *fullpath; |
| 488 | struct dfs_filesystem *fs; |
| 489 | |
| 490 | /* Make sure we have an absolute path */ |
| 491 | fullpath = dfs_normalize_path(NULL, path); |
| 492 | if (fullpath == NULL) |
| 493 | { |
| 494 | return -EINVAL; |
| 495 | } |
| 496 | |
| 497 | /* Check whether file is already open */ |
| 498 | if (dfs_file_is_open(fullpath)) |
| 499 | { |
| 500 | result = -EBUSY; |
| 501 | goto __exit; |
| 502 | } |
| 503 | |
| 504 | /* get filesystem */ |
| 505 | if ((fs = dfs_filesystem_lookup(fullpath)) == NULL) |
| 506 | { |
| 507 | result = -ENOENT; |
| 508 | goto __exit; |
| 509 | } |
| 510 | |
| 511 | if (fs->ops->unlink != NULL) |
| 512 | { |
| 513 | if (!(fs->ops->flags & DFS_FS_FLAG_FULLPATH)) |
| 514 | { |
| 515 | if (dfs_subdir(fs->path, fullpath) == NULL) |
| 516 | result = fs->ops->unlink(fs, "/"); |
| 517 | else |
| 518 | result = fs->ops->unlink(fs, dfs_subdir(fs->path, fullpath)); |
| 519 | } |
| 520 | else |
| 521 | result = fs->ops->unlink(fs, fullpath); |
| 522 | } |
| 523 | else result = -ENOSYS; |
| 524 | |
| 525 | __exit: |
| 526 | rt_free(fullpath); |
| 527 | return result; |
| 528 | } |
| 529 | |
| 530 | /** |
| 531 | * this function will write some specified length data to file system. |