| 743 | ****************************************************************************/ |
| 744 | |
| 745 | static int tmpfs_create_directory(FAR struct tmpfs_s *fs, |
| 746 | FAR const char *relpath, |
| 747 | FAR struct tmpfs_directory_s **tdo) |
| 748 | { |
| 749 | FAR struct tmpfs_directory_s *parent; |
| 750 | FAR struct tmpfs_directory_s *newtdo; |
| 751 | FAR const char *name; |
| 752 | int ret; |
| 753 | |
| 754 | /* Separate the path into the file name and the path to the parent |
| 755 | * directory. |
| 756 | */ |
| 757 | |
| 758 | name = strrchr(relpath, '/'); |
| 759 | if (name && name[1] == '\0') |
| 760 | { |
| 761 | /* Ignore the tail '/' */ |
| 762 | |
| 763 | name = memrchr(relpath, '/', name - relpath); |
| 764 | } |
| 765 | |
| 766 | if (name == NULL) |
| 767 | { |
| 768 | /* No subdirectories... use the root directory */ |
| 769 | |
| 770 | name = relpath; |
| 771 | parent = (FAR struct tmpfs_directory_s *)fs->tfs_root.tde_object; |
| 772 | |
| 773 | ret = tmpfs_lock_directory(parent); |
| 774 | if (ret < 0) |
| 775 | { |
| 776 | return ret; |
| 777 | } |
| 778 | |
| 779 | parent->tdo_refs++; |
| 780 | } |
| 781 | else |
| 782 | { |
| 783 | /* Locate the parent directory that should contain this name. |
| 784 | * On success, tmpfs_find_directory() will lockthe parent |
| 785 | * directory and increment the reference count. |
| 786 | */ |
| 787 | |
| 788 | ret = tmpfs_find_directory(fs, relpath, name - relpath, &parent, NULL); |
| 789 | if (ret < 0) |
| 790 | { |
| 791 | return ret; |
| 792 | } |
| 793 | |
| 794 | /* Skip the '/' path separator */ |
| 795 | |
| 796 | name++; |
| 797 | } |
| 798 | |
| 799 | /* Verify that no object of this name already exists in the directory */ |
| 800 | |
| 801 | ret = tmpfs_find_dirent(parent, name, strlen(name)); |
| 802 | if (ret != -ENOENT) |
no test coverage detected