MCPcopy Create free account
hub / github.com/apache/nuttx / tmpfs_create_file

Function tmpfs_create_file

fs/tmpfs/fs_tmpfs.c:597–708  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

595 ****************************************************************************/
596
597static int tmpfs_create_file(FAR struct tmpfs_s *fs,
598 FAR const char *relpath,
599 FAR struct tmpfs_file_s **tfo)
600{
601 FAR struct tmpfs_directory_s *parent;
602 FAR struct tmpfs_file_s *newtfo;
603 FAR const char *name;
604 int ret;
605
606 /* Separate the path into the file name and the path to the parent
607 * directory.
608 */
609
610 name = strrchr(relpath, '/');
611 if (name == NULL)
612 {
613 /* No subdirectories... use the root directory */
614
615 name = relpath;
616 parent = (FAR struct tmpfs_directory_s *)fs->tfs_root.tde_object;
617
618 /* Lock the root directory to emulate the behavior of
619 * tmpfs_find_directory()
620 */
621
622 ret = tmpfs_lock_directory(parent);
623 if (ret < 0)
624 {
625 return ret;
626 }
627
628 parent->tdo_refs++;
629 }
630 else if (name[1] != '\0')
631 {
632 /* Locate the parent directory that should contain this name.
633 * On success, tmpfs_find_directory() will lock the parent
634 * directory and increment the reference count.
635 */
636
637 ret = tmpfs_find_directory(fs, relpath, name - relpath, &parent, NULL);
638 if (ret < 0)
639 {
640 return ret;
641 }
642
643 /* Skip the '/' path separator */
644
645 name++;
646 }
647 else
648 {
649 return -EISDIR;
650 }
651
652 /* Verify that no object of this name already exists in the directory */
653
654 ret = tmpfs_find_dirent(parent, name, strlen(name));

Callers 1

tmpfs_openFunction · 0.85

Calls 8

tmpfs_find_directoryFunction · 0.85
tmpfs_find_direntFunction · 0.85
tmpfs_alloc_fileFunction · 0.85
tmpfs_add_direntFunction · 0.85
nxrmutex_destroyFunction · 0.85
fs_heap_freeFunction · 0.85
strrchrFunction · 0.50
strlenFunction · 0.50

Tested by

no test coverage detected