Skip to content

Commit af7633d

Browse files
fs/dir: reuse close_mountpoint/close_pseudodir helpers in dir_close
dir_close() open-coded the same mountpoint and pseudodir cleanup sequences that already exist as the close_mountpoint() and close_pseudodir() helpers (used by closedir()). Switch dir_close() to call those helpers so the two close paths share identical logic and future fixes only need to be applied in one place. The helpers do not propagate the underlying mops->closedir() return value, so dir_close() now always returns OK; this matches the behaviour of closedir(), which has used the helpers since they were introduced and never surfaced that error to callers either. Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
1 parent 64ca343 commit af7633d

1 file changed

Lines changed: 3 additions & 25 deletions

File tree

fs/vfs/fs_dir.c

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,6 @@ static int dir_close(FAR struct file *filep)
412412
FAR struct fs_dirent_s *dir = filep->f_priv;
413413
FAR struct inode *inode = dir->fd_root;
414414
FAR char *relpath = dir->fd_path;
415-
int ret = 0;
416415

417416
/* This is the 'root' inode of the directory. This means different
418417
* things with different filesystems.
@@ -425,40 +424,19 @@ static int dir_close(FAR struct file *filep)
425424

426425
if (INODE_IS_MOUNTPT(inode))
427426
{
428-
/* The node is a file system mointpoint. Verify that the
429-
* mountpoint supports the closedir() method (not an error if it
430-
* does not)
431-
*/
432-
433-
if (inode->u.i_mops->closedir != NULL)
434-
{
435-
ret = inode->u.i_mops->closedir(inode, dir);
436-
}
427+
close_mountpoint(inode, dir);
437428
}
438429
else
439430
#endif
440431
{
441-
FAR struct fs_pseudodir_s *pdir = filep->f_priv;
442-
443-
/* The node is part of the root pseudo file system, release
444-
* our contained reference to the 'next' inode.
445-
*/
446-
447-
if (pdir->next != NULL)
448-
{
449-
inode_release(pdir->next);
450-
}
451-
452-
/* Then release the container */
453-
454-
fs_heap_free(dir);
432+
close_pseudodir(dir);
455433
}
456434

457435
/* Release our references on the contained 'root' inode */
458436

459437
inode_release(inode);
460438
fs_heap_free(relpath);
461-
return ret;
439+
return OK;
462440
}
463441

464442
static ssize_t dir_read(FAR struct file *filep, FAR char *buffer,

0 commit comments

Comments
 (0)