Changeset 1e2e5795 in mainline for uspace/lib/c/generic/vfs/vfs.c
- Timestamp:
- 2017-04-02T19:20:21Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d96d9bc
- Parents:
- d4067a7
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/vfs/vfs.c
rd4067a7 r1e2e5795 630 630 } 631 631 632 static int get_parent_and_child(const char *path, char **child) 633 { 634 size_t size; 635 char *apath = vfs_absolutize(path, &size); 636 if (!apath) 637 return ENOMEM; 638 639 char *slash = str_rchr(apath, L'/'); 640 int parent; 641 if (slash == apath) { 642 parent = vfs_root(); 643 *child = apath; 644 } else { 645 *slash = '\0'; 646 parent = vfs_lookup(apath, WALK_DIRECTORY); 647 if (parent < 0) { 648 free(apath); 649 return parent; 650 } 651 *slash = '/'; 652 *child = str_dup(slash); 653 free(apath); 654 if (!*child) { 655 vfs_put(parent); 656 return ENOMEM; 657 } 658 } 659 660 return parent; 661 } 662 632 663 int vfs_link(int parent, const char *child, vfs_file_kind_t kind) 633 664 { … … 651 682 int vfs_link_path(const char *path, vfs_file_kind_t kind) 652 683 { 653 size_t pa_size; 654 char *pa = vfs_absolutize(path, &pa_size); 655 if (!pa) 656 return ENOMEM; 657 658 int parent; 659 char *slash = str_rchr(pa, L'/'); 660 if (slash != pa) { 661 *slash = '\0'; 662 parent = vfs_lookup(pa, WALK_DIRECTORY); 663 *slash = '/'; 664 } else { 665 parent = vfs_root(); 666 } 667 668 if (parent < 0) { 669 free(pa); 684 char *child; 685 int parent = get_parent_and_child(path, &child); 686 if (parent < 0) 670 687 return parent; 671 } 672 673 int rc = vfs_link(parent, slash, kind); 674 675 free(pa); 688 689 int rc = vfs_link(parent, child, kind); 690 691 free(child); 676 692 vfs_put(parent); 677 693 return rc; … … 705 721 int vfs_unlink_path(const char *path) 706 722 { 707 size_t pa_size;708 char *pa = vfs_absolutize(path, &pa_size);709 if (!pa)710 return ENOMEM;711 712 int parent;713 723 int expect = vfs_lookup(path, 0); 714 if (expect < 0) { 715 free(pa); 724 if (expect < 0) 716 725 return expect; 717 } 718 719 char *slash = str_rchr(pa, L'/'); 720 if (slash != pa) { 721 *slash = '\0'; 722 parent = vfs_lookup(pa, 0); 723 *slash = '/'; 724 } else { 725 parent = vfs_root(); 726 } 727 726 727 char *child; 728 int parent = get_parent_and_child(path, &child); 728 729 if (parent < 0) { 729 free(pa);730 730 vfs_put(expect); 731 731 return parent; 732 732 } 733 733 734 int rc = vfs_unlink(parent, slash, expect);735 736 free( pa);734 int rc = vfs_unlink(parent, child, expect); 735 736 free(child); 737 737 vfs_put(parent); 738 738 vfs_put(expect);
Note:
See TracChangeset
for help on using the changeset viewer.