Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inotify: support truncate and close calls #13869

Merged
merged 3 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Documentation/components/filesystem/inotify.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,16 @@ calling inotify_add_watch and may be returned in the mask field returned by re

**IN_ACCESS** :File was accessed

**IN_MODIFY** :File was modified
**IN_MODIFY** :File was modified (``write()`` or ``truncate()``)

**IN_ATTRIB** :Metadata changed

**IN_OPEN** :File was opened

**IN_CLOSE_WRITE** :File opened for writing was closed

**IN_CLOSE_NOWRITE** : File not opened for writing was closed

**IN_MOVED_FROM** :File was moved from X

**IN_MOVED_TO** :File was moved to Y
Expand Down
8 changes: 4 additions & 4 deletions fs/notify/inotify.c
Original file line number Diff line number Diff line change
Expand Up @@ -1342,15 +1342,15 @@ void notify_open(FAR const char *path, int oflags)
*
****************************************************************************/

void notify_close(FAR struct file *filep)
void notify_close(FAR const char *path, int oflags)
{
if (filep->f_oflags & O_WROK)
if (oflags & O_WROK)
{
notify_queue_filep_event(filep, IN_CLOSE_WRITE);
notify_queue_path_event(path, IN_CLOSE_WRITE);
}
else
{
notify_queue_filep_event(filep, IN_CLOSE_NOWRITE);
notify_queue_path_event(path, IN_CLOSE_NOWRITE);
}
}

Expand Down
2 changes: 1 addition & 1 deletion fs/notify/notify.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
/* These are internal OS interface and are not available to applications */

void notify_open(FAR const char *path, int oflags);
void notify_close(FAR struct file *filep);
void notify_close(FAR const char *path, int oflags);
void notify_close2(FAR struct inode *inode);
void notify_read(FAR struct file *filep);
void notify_write(FAR struct file *filep);
Expand Down
46 changes: 46 additions & 0 deletions fs/vfs/fs_close.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,33 @@
#include "inode/inode.h"
#include "vfs/lock.h"

/****************************************************************************
* Private Functions
****************************************************************************/

#ifdef CONFIG_FS_NOTIFY
static FAR char *file_get_path(FAR struct file *filep)
{
FAR char *pathbuffer;
int ret;

pathbuffer = lib_get_pathbuffer();
if (pathbuffer == NULL)
{
return NULL;
}

ret = file_fcntl(filep, F_GETPATH, pathbuffer);
if (ret < 0)
{
lib_put_pathbuffer(pathbuffer);
return NULL;
}

return pathbuffer;
}
#endif

/****************************************************************************
* Public Functions
****************************************************************************/
Expand All @@ -60,11 +87,22 @@
int file_close_without_clear(FAR struct file *filep)
{
struct inode *inode;
#ifdef CONFIG_FS_NOTIFY
FAR char *path;
#endif
int ret = OK;

DEBUGASSERT(filep != NULL);
inode = filep->f_inode;

#ifdef CONFIG_FS_NOTIFY
/* We lose the path and inode during close and release, so obtain it
* in advance. Then we pass it to notify_close function.
*/

path = file_get_path(filep);
#endif

/* Check if the struct file is open (i.e., assigned an inode) */

if (inode)
Expand All @@ -84,6 +122,14 @@ int file_close_without_clear(FAR struct file *filep)

if (ret >= 0)
{
#ifdef CONFIG_FS_NOTIFY
if (path != NULL)
{
notify_close(path, filep->f_oflags);
xiaoxiang781216 marked this conversation as resolved.
Show resolved Hide resolved
lib_put_pathbuffer(path);
}
#endif

inode_release(inode);
}
}
Expand Down
4 changes: 4 additions & 0 deletions fs/vfs/fs_truncate.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include <nuttx/fs/fs.h>

#include "notify/notify.h"
#include "inode/inode.h"

/****************************************************************************
Expand Down Expand Up @@ -180,6 +181,9 @@ int ftruncate(int fd, off_t length)
fs_putfilep(filep);
if (ret >= 0)
{
#ifdef CONFIG_FS_NOTIFY
notify_write(filep);
#endif
return 0;
}

Expand Down
Loading