From b294303e4186507d2d1d23177a85af33a27ea495 Mon Sep 17 00:00:00 2001 From: ligd Date: Tue, 30 Nov 2021 21:43:09 +0800 Subject: [PATCH] hostfs: add lock to hostfs_rewinddir Signed-off-by: ligd --- fs/hostfs/hostfs.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/fs/hostfs/hostfs.c b/fs/hostfs/hostfs.c index ca3033337a..317f19e4fc 100644 --- a/fs/hostfs/hostfs.c +++ b/fs/hostfs/hostfs.c @@ -970,14 +970,30 @@ static int hostfs_readdir(FAR struct inode *mountpt, static int hostfs_rewinddir(FAR struct inode *mountpt, FAR struct fs_dirent_s *dir) { + FAR struct hostfs_mountpt_s *fs; + int ret; + /* Sanity checks */ DEBUGASSERT(mountpt != NULL && mountpt->i_private != NULL); + /* Recover our private data from the inode instance */ + + fs = mountpt->i_private; + + /* Take the semaphore */ + + ret = hostfs_semtake(fs); + if (ret < 0) + { + return ret; + } + /* Call the host and let it do all the work */ host_rewinddir(dir->u.hostfs.fs_dir); + hostfs_semgive(fs); return OK; } @@ -997,7 +1013,8 @@ static int hostfs_bind(FAR struct inode *blkdriver, FAR const void *data, { FAR struct hostfs_mountpt_s *fs; FAR char *options; - char *ptr, *saveptr; + char *saveptr; + char *ptr; int len; int ret;