diff --git a/fs/vfs/fs_lock.c b/fs/vfs/fs_lock.c index bfb430577b..1c4bb006f9 100644 --- a/fs/vfs/fs_lock.c +++ b/fs/vfs/fs_lock.c @@ -30,6 +30,7 @@ #include #include +#include #include #include #include @@ -715,6 +716,10 @@ retry: goto out; } + /* Update filep lock state */ + + filep->locked = true; + /* When there is a lock change, we need to wake up the blocking lock */ if (bucket->nwaiter > 0) @@ -751,6 +756,11 @@ void file_closelk(FAR struct file *filep) bool deleted = false; int ret; + if (filep->locked == false) + { + return; + } + path = lib_get_pathbuffer(); if (path == NULL) { @@ -784,6 +794,7 @@ void file_closelk(FAR struct file *filep) { deleted = true; file_lock_delete(file_lock); + filep->locked = false; } } diff --git a/include/nuttx/fs/fs.h b/include/nuttx/fs/fs.h index 939a8dd546..04f8c07558 100644 --- a/include/nuttx/fs/fs.h +++ b/include/nuttx/fs/fs.h @@ -480,6 +480,10 @@ struct file #if CONFIG_FS_BACKTRACE > 0 FAR void *f_backtrace[CONFIG_FS_BACKTRACE]; /* Backtrace to while file opens */ #endif + +#if CONFIG_FS_LOCK_BUCKET_SIZE > 0 + bool locked; /* Filelock state: false - unlocked, true - locked */ +#endif }; /* This defines a two layer array of files indexed by the file descriptor.