mirror of
https://github.com/apache/nuttx.git
synced 2025-01-13 02:48:37 +08:00
fs:notify add support for inotify
support API: open close read write unlink mkdir rename fchstat rmdir symlink Signed-off-by: guohao15 <guohao15@xiaomi.com>
This commit is contained in:
parent
6e1dfe2777
commit
86e00896d3
38 changed files with 1852 additions and 8 deletions
|
@ -118,6 +118,7 @@ source "fs/mqueue/Kconfig"
|
|||
source "fs/shm/Kconfig"
|
||||
source "fs/mmap/Kconfig"
|
||||
source "fs/partition/Kconfig"
|
||||
source "fs/notify/Kconfig"
|
||||
source "fs/fat/Kconfig"
|
||||
source "fs/nfs/Kconfig"
|
||||
source "fs/nxffs/Kconfig"
|
||||
|
|
|
@ -59,6 +59,7 @@ include rpmsgfs/Make.defs
|
|||
include zipfs/Make.defs
|
||||
include mnemofs/Make.defs
|
||||
include v9fs/Make.defs
|
||||
include notify/Make.defs
|
||||
endif
|
||||
|
||||
CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)fs
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include <nuttx/fs/fs.h>
|
||||
|
||||
#include "inode/inode.h"
|
||||
#include "notify/notify.h"
|
||||
|
||||
#ifndef CONFIG_DISABLE_MOUNTPOINT
|
||||
|
||||
|
@ -90,7 +91,11 @@ int register_blockdriver(FAR const char *path,
|
|||
|
||||
node->u.i_bops = bops;
|
||||
node->i_private = priv;
|
||||
ret = OK;
|
||||
inode_unlock();
|
||||
#ifdef CONFIG_FS_NOTIFY
|
||||
notify_create(path);
|
||||
#endif
|
||||
return OK;
|
||||
}
|
||||
|
||||
inode_unlock();
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include <nuttx/sched_note.h>
|
||||
|
||||
#include "inode/inode.h"
|
||||
#include "notify/notify.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
|
@ -89,7 +90,11 @@ int register_driver(FAR const char *path,
|
|||
|
||||
node->u.i_ops = fops;
|
||||
node->i_private = priv;
|
||||
ret = OK;
|
||||
inode_unlock();
|
||||
#ifdef CONFIG_FS_NOTIFY
|
||||
notify_create(path);
|
||||
#endif
|
||||
return OK;
|
||||
}
|
||||
|
||||
inode_unlock();
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include <nuttx/mtd/mtd.h>
|
||||
|
||||
#include "inode/inode.h"
|
||||
#include "notify/notify.h"
|
||||
|
||||
#if defined(CONFIG_MTD) && !defined(CONFIG_DISABLE_MOUNTPOINT)
|
||||
|
||||
|
@ -90,7 +91,11 @@ int register_mtddriver(FAR const char *path, FAR struct mtd_dev_s *mtd,
|
|||
|
||||
node->u.i_mtd = mtd;
|
||||
node->i_private = priv;
|
||||
ret = OK;
|
||||
inode_unlock();
|
||||
#ifdef CONFIG_FS_NOTIFY
|
||||
notify_create(path);
|
||||
#endif
|
||||
return OK;
|
||||
}
|
||||
|
||||
inode_unlock();
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include <nuttx/fs/fs.h>
|
||||
|
||||
#include "inode/inode.h"
|
||||
#include "notify/notify.h"
|
||||
|
||||
#ifdef CONFIG_PIPES
|
||||
|
||||
|
@ -88,7 +89,11 @@ int register_pipedriver(FAR const char *path,
|
|||
|
||||
node->u.i_ops = fops;
|
||||
node->i_private = priv;
|
||||
ret = OK;
|
||||
inode_unlock();
|
||||
#ifdef CONFIG_FS_NOTIFY
|
||||
notify_create(path);
|
||||
#endif
|
||||
return OK;
|
||||
}
|
||||
|
||||
inode_unlock();
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include <nuttx/fs/fs.h>
|
||||
|
||||
#include "inode/inode.h"
|
||||
#include "notify/notify.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
|
@ -49,7 +50,12 @@ int unregister_blockdriver(FAR const char *path)
|
|||
{
|
||||
ret = inode_remove(path);
|
||||
inode_unlock();
|
||||
#ifdef CONFIG_FS_NOTIFY
|
||||
notify_unlink(path);
|
||||
#endif
|
||||
return OK;
|
||||
}
|
||||
|
||||
inode_unlock();
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include <nuttx/fs/fs.h>
|
||||
|
||||
#include "inode/inode.h"
|
||||
#include "notify/notify.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
|
@ -59,7 +60,12 @@ int unregister_driver(FAR const char *path)
|
|||
{
|
||||
ret = inode_remove(path);
|
||||
inode_unlock();
|
||||
#ifdef CONFIG_FS_NOTIFY
|
||||
notify_unlink(path);
|
||||
#endif
|
||||
return OK;
|
||||
}
|
||||
|
||||
inode_unlock();
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include <nuttx/mtd/mtd.h>
|
||||
|
||||
#include "inode/inode.h"
|
||||
#include "notify/notify.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
|
@ -50,7 +51,12 @@ int unregister_mtddriver(FAR const char *path)
|
|||
{
|
||||
ret = inode_remove(path);
|
||||
inode_unlock();
|
||||
#ifdef CONFIG_FS_NOTIFY
|
||||
notify_unlink(path);
|
||||
#endif
|
||||
return OK;
|
||||
}
|
||||
|
||||
inode_unlock();
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include <nuttx/fs/fs.h>
|
||||
|
||||
#include "inode/inode.h"
|
||||
#include "notify/notify.h"
|
||||
|
||||
#ifdef CONFIG_PIPES
|
||||
|
||||
|
@ -51,8 +52,13 @@ int unregister_pipedriver(FAR const char *path)
|
|||
{
|
||||
ret = inode_remove(path);
|
||||
inode_unlock();
|
||||
#ifdef CONFIG_FS_NOTIFY
|
||||
notify_unlink(path);
|
||||
#endif
|
||||
return OK;
|
||||
}
|
||||
|
||||
inode_unlock();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include <nuttx/reboot_notifier.h>
|
||||
#include <nuttx/trace.h>
|
||||
|
||||
#include "notify/notify.h"
|
||||
#include "rpmsgfs/rpmsgfs.h"
|
||||
#include "inode/inode.h"
|
||||
#include "aio/aio.h"
|
||||
|
@ -97,6 +98,10 @@ void fs_initialize(void)
|
|||
rpmsgfs_server_init();
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_FS_NOTIFY
|
||||
notify_initialize();
|
||||
#endif
|
||||
|
||||
register_reboot_notifier(&g_sync_nb);
|
||||
fs_trace_end();
|
||||
}
|
||||
|
|
|
@ -33,8 +33,9 @@
|
|||
|
||||
#include <nuttx/fs/fs.h>
|
||||
|
||||
#include "inode/inode.h"
|
||||
#include "driver/driver.h"
|
||||
#include "inode/inode.h"
|
||||
#include "notify/notify.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
|
@ -494,6 +495,9 @@ int nx_mount(FAR const char *source, FAR const char *target,
|
|||
|
||||
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
|
||||
RELEASE_SEARCH(&desc);
|
||||
#endif
|
||||
#ifdef CONFIG_FS_NOTIFY
|
||||
notify_create(target);
|
||||
#endif
|
||||
return OK;
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include <nuttx/fs/fs.h>
|
||||
|
||||
#include "inode/inode.h"
|
||||
#include "notify/notify.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
|
@ -184,6 +185,9 @@ int nx_umount2(FAR const char *target, unsigned int flags)
|
|||
}
|
||||
|
||||
RELEASE_SEARCH(&desc);
|
||||
#ifdef CONFIG_FS_NOTIFY
|
||||
notify_unmount(target);
|
||||
#endif
|
||||
return OK;
|
||||
|
||||
/* A lot of goto's! But they make the error handling much simpler */
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
|
||||
#include "inode/inode.h"
|
||||
#include "mqueue/mqueue.h"
|
||||
#include "notify/notify.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions Prototypes
|
||||
|
@ -331,6 +332,9 @@ static int file_mq_vopen(FAR struct file *mq, FAR const char *mq_name,
|
|||
|
||||
RELEASE_SEARCH(&desc);
|
||||
leave_critical_section(flags);
|
||||
#ifdef CONFIG_FS_NOTIFY
|
||||
notify_open(fullpath, oflags);
|
||||
#endif
|
||||
return OK;
|
||||
|
||||
errout_with_inode:
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
|
||||
#include "inode/inode.h"
|
||||
#include "mqueue/mqueue.h"
|
||||
#include "notify/notify.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
|
@ -173,6 +174,9 @@ int file_mq_unlink(FAR const char *mq_name)
|
|||
inode_unlock();
|
||||
mq_inode_release(inode);
|
||||
RELEASE_SEARCH(&desc);
|
||||
#ifdef CONFIG_FS_NOTIFY
|
||||
notify_unlink(fullpath);
|
||||
#endif
|
||||
return OK;
|
||||
|
||||
errout_with_lock:
|
||||
|
|
25
fs/notify/Kconfig
Normal file
25
fs/notify/Kconfig
Normal file
|
@ -0,0 +1,25 @@
|
|||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||
#
|
||||
|
||||
config FS_NOTIFY
|
||||
bool "FS Notify System"
|
||||
default n
|
||||
---help---
|
||||
The Fsnotify System
|
||||
|
||||
if FS_NOTIFY
|
||||
config FSNOTIFY_BUCKET_SIZE
|
||||
int "Dir hash bucket size"
|
||||
default 64
|
||||
|
||||
config FSNOTIFY_MAX_EVENTS
|
||||
int "Max events in one notify device"
|
||||
default 1024
|
||||
|
||||
config FSNOTIFY_FD_POLLWAITERS
|
||||
int "Max pollwaiters in one notify devcie"
|
||||
default 2
|
||||
|
||||
endif # FS_NOTIFY
|
29
fs/notify/Make.defs
Normal file
29
fs/notify/Make.defs
Normal file
|
@ -0,0 +1,29 @@
|
|||
############################################################################
|
||||
# fs/notify/Make.defs
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
# contributor license agreements. See the NOTICE file distributed with
|
||||
# this work for additional information regarding copyright ownership. The
|
||||
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance with the
|
||||
# License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
# Include FSNOTIFY build support
|
||||
|
||||
|
||||
ifeq ($(CONFIG_FS_NOTIFY),y)
|
||||
CSRCS += inotify.c
|
||||
endif
|
||||
|
||||
DEPPATH += --dep-path notify
|
||||
VPATH += :notify
|
1356
fs/notify/inotify.c
Normal file
1356
fs/notify/inotify.c
Normal file
File diff suppressed because it is too large
Load diff
58
fs/notify/notify.h
Normal file
58
fs/notify/notify.h
Normal file
|
@ -0,0 +1,58 @@
|
|||
/****************************************************************************
|
||||
* fs/notify/notify.h
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __FS_NOTIFY_NOTIFY_H
|
||||
#define __FS_NOTIFY_NOTIFY_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/fs/fs.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Type Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/* 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_close2(FAR struct inode *inode);
|
||||
void notify_read(FAR struct file *filep);
|
||||
void notify_write(FAR struct file *filep);
|
||||
void notify_chstat(FAR struct file *filep);
|
||||
void notify_unlink(FAR const char *path);
|
||||
void notify_unmount(FAR const char *path);
|
||||
void notify_mkdir(FAR const char *path);
|
||||
void notify_create(FAR const char *path);
|
||||
void notify_rename(FAR const char *oldpath, bool oldisdir,
|
||||
FAR const char *newpath, bool newisdir);
|
||||
void notify_initialize(void);
|
||||
|
||||
#endif
|
|
@ -33,6 +33,7 @@
|
|||
#include <nuttx/fs/fs.h>
|
||||
|
||||
#include "inode/inode.h"
|
||||
#include "notify/notify.h"
|
||||
|
||||
#ifdef CONFIG_FS_NAMED_SEMAPHORES
|
||||
|
||||
|
@ -116,7 +117,9 @@ int nxsem_close(FAR sem_t *sem)
|
|||
*/
|
||||
|
||||
inode_unlock();
|
||||
|
||||
#ifdef CONFIG_FS_NOTIFY
|
||||
notify_close2(inode);
|
||||
#endif
|
||||
DEBUGASSERT(inode->i_peer == NULL);
|
||||
inode_free(inode);
|
||||
return OK;
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
#include <nuttx/fs/fs.h>
|
||||
|
||||
#include "inode/inode.h"
|
||||
#include "notify/notify.h"
|
||||
#include "semaphore/semaphore.h"
|
||||
|
||||
#ifdef CONFIG_FS_NAMED_SEMAPHORES
|
||||
|
@ -222,6 +223,9 @@ int nxsem_open(FAR sem_t **sem, FAR const char *name, int oflags, ...)
|
|||
}
|
||||
|
||||
RELEASE_SEARCH(&desc);
|
||||
#ifdef CONFIG_FS_NOTIFY
|
||||
notify_open(fullpath, oflags);
|
||||
#endif
|
||||
return OK;
|
||||
|
||||
errout_with_inode:
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include <nuttx/semaphore.h>
|
||||
|
||||
#include "inode/inode.h"
|
||||
#include "notify/notify.h"
|
||||
#include "semaphore/semaphore.h"
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -138,6 +139,9 @@ int nxsem_unlink(FAR const char *name)
|
|||
inode_unlock();
|
||||
ret = nxsem_close(&inode->u.i_nsem->ns_sem);
|
||||
RELEASE_SEARCH(&desc);
|
||||
#ifdef CONFIG_FS_NOTIFY
|
||||
notify_unlink(fullpath);
|
||||
#endif
|
||||
return ret;
|
||||
|
||||
errout_with_lock:
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include <errno.h>
|
||||
|
||||
#include "inode/inode.h"
|
||||
#include "notify/notify.h"
|
||||
#include "shm/shmfs.h"
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -149,6 +150,13 @@ errout_with_sem:
|
|||
inode_unlock();
|
||||
errout_with_search:
|
||||
RELEASE_SEARCH(&desc);
|
||||
#ifdef CONFIG_FS_NOTIFY
|
||||
if (ret >= 0)
|
||||
{
|
||||
notify_open(fullpath, oflags);
|
||||
}
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include <errno.h>
|
||||
|
||||
#include "inode/inode.h"
|
||||
#include "notify/notify.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
|
@ -140,6 +141,13 @@ errout_with_sem:
|
|||
inode_unlock();
|
||||
errout_with_search:
|
||||
RELEASE_SEARCH(&desc);
|
||||
#ifdef CONFIG_FS_NOTIFY
|
||||
if (ret >= 0)
|
||||
{
|
||||
notify_unlink(fullpath);
|
||||
}
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
|
||||
#include <nuttx/fs/fs.h>
|
||||
|
||||
#include "notify/notify.h"
|
||||
#include "inode/inode.h"
|
||||
#include "vfs/lock.h"
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
|
||||
#include <nuttx/fs/fs.h>
|
||||
|
||||
#include "notify/notify.h"
|
||||
#include "inode/inode.h"
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -191,6 +192,13 @@ int file_fchstat(FAR struct file *filep, FAR struct stat *buf, int flags)
|
|||
ret = inode_chstat(inode, buf, flags, 0);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_FS_NOTIFY
|
||||
if (ret >= 0)
|
||||
{
|
||||
notify_chstat(filep);
|
||||
}
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
|
||||
#include <nuttx/fs/fs.h>
|
||||
|
||||
#include "notify/notify.h"
|
||||
#include "inode/inode.h"
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -165,6 +166,9 @@ int mkdir(const char *pathname, mode_t mode)
|
|||
/* Directory successfully created */
|
||||
|
||||
RELEASE_SEARCH(&desc);
|
||||
#ifdef CONFIG_FS_NOTIFY
|
||||
notify_mkdir(pathname);
|
||||
#endif
|
||||
return OK;
|
||||
|
||||
errout_with_inode:
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
|
||||
#include "inode/inode.h"
|
||||
#include "driver/driver.h"
|
||||
#include "notify/notify.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
|
@ -196,7 +197,15 @@ static int file_vopen(FAR struct file *filep, FAR const char *path,
|
|||
|
||||
/* Get the file structure of the opened character driver proxy */
|
||||
|
||||
return block_proxy(filep, path, oflags);
|
||||
ret = block_proxy(filep, path, oflags);
|
||||
#ifdef CONFIG_FS_NOTIFY
|
||||
if (ret >= 0)
|
||||
{
|
||||
notify_open(path, filep->f_oflags);
|
||||
}
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -255,6 +264,9 @@ static int file_vopen(FAR struct file *filep, FAR const char *path,
|
|||
}
|
||||
|
||||
RELEASE_SEARCH(&desc);
|
||||
#ifdef CONFIG_FS_NOTIFY
|
||||
notify_open(path, filep->f_oflags);
|
||||
#endif
|
||||
return OK;
|
||||
|
||||
errout_with_inode:
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#include <nuttx/lib/math32.h>
|
||||
|
||||
#include "inode/inode.h"
|
||||
#include "notify/notify.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
|
@ -505,6 +506,9 @@ int pseudofile_create(FAR struct inode **node, FAR const char *path,
|
|||
(*node)->i_private = pf;
|
||||
|
||||
inode_unlock();
|
||||
#ifdef CONFIG_FS_NOTIFY
|
||||
notify_create(path);
|
||||
#endif
|
||||
return 0;
|
||||
|
||||
reserve_err:
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
|
||||
#include <nuttx/cancelpt.h>
|
||||
|
||||
#include "notify/notify.h"
|
||||
#include "inode/inode.h"
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -96,6 +97,13 @@ ssize_t file_read(FAR struct file *filep, FAR void *buf, size_t nbytes)
|
|||
|
||||
/* Return the number of bytes read (or possibly an error code) */
|
||||
|
||||
#ifdef CONFIG_FS_NOTIFY
|
||||
if (ret > 0)
|
||||
{
|
||||
notify_read(filep);
|
||||
}
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include <nuttx/fs/fs.h>
|
||||
#include <nuttx/lib/lib.h>
|
||||
|
||||
#include "notify/notify.h"
|
||||
#include "inode/inode.h"
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -67,6 +68,9 @@ static int pseudorename(FAR const char *oldpath, FAR struct inode *oldinode,
|
|||
struct inode_search_s newdesc;
|
||||
FAR struct inode *newinode;
|
||||
FAR char *subdir = NULL;
|
||||
#ifdef CONFIG_FS_NOTIFY
|
||||
bool isdir = INODE_IS_PSEUDODIR(oldinode);
|
||||
#endif
|
||||
int ret;
|
||||
|
||||
/* According to POSIX, any new inode at this path should be removed
|
||||
|
@ -160,6 +164,9 @@ next_subdir:
|
|||
*/
|
||||
|
||||
inode_remove(newpath);
|
||||
#ifdef CONFIG_FS_NOTIFY
|
||||
notify_unlink(newpath);
|
||||
#endif
|
||||
}
|
||||
|
||||
inode_release(newinode);
|
||||
|
@ -244,6 +251,13 @@ errout_with_lock:
|
|||
|
||||
errout:
|
||||
RELEASE_SEARCH(&newdesc);
|
||||
#ifdef CONFIG_FS_NOTIFY
|
||||
if (ret >= 0)
|
||||
{
|
||||
notify_rename(oldpath, isdir, newpath, isdir);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (subdir != NULL)
|
||||
{
|
||||
lib_free(subdir);
|
||||
|
@ -270,6 +284,10 @@ static int mountptrename(FAR const char *oldpath, FAR struct inode *oldinode,
|
|||
FAR struct inode *newinode;
|
||||
FAR const char *newrelpath;
|
||||
FAR char *subdir = NULL;
|
||||
#ifdef CONFIG_FS_NOTIFY
|
||||
bool newisdir = false;
|
||||
bool oldisdir = false;
|
||||
#endif
|
||||
int ret;
|
||||
|
||||
DEBUGASSERT(oldinode->u.i_mops);
|
||||
|
@ -338,13 +356,26 @@ static int mountptrename(FAR const char *oldpath, FAR struct inode *oldinode,
|
|||
{
|
||||
struct stat buf;
|
||||
|
||||
#ifdef CONFIG_FS_NOTIFY
|
||||
ret = oldinode->u.i_mops->stat(oldinode, oldpath, &buf);
|
||||
if (ret >= 0)
|
||||
{
|
||||
oldisdir = S_ISDIR(buf.st_mode);
|
||||
}
|
||||
#endif
|
||||
|
||||
next_subdir:
|
||||
ret = oldinode->u.i_mops->stat(oldinode, newrelpath, &buf);
|
||||
if (ret >= 0)
|
||||
{
|
||||
/* Is the directory entry a directory? */
|
||||
|
||||
#ifdef CONFIG_FS_NOTIFY
|
||||
newisdir = S_ISDIR(buf.st_mode);
|
||||
if (newisdir)
|
||||
#else
|
||||
if (S_ISDIR(buf.st_mode))
|
||||
#endif
|
||||
{
|
||||
FAR char *subdirname;
|
||||
|
||||
|
@ -417,6 +448,9 @@ next_subdir:
|
|||
*/
|
||||
|
||||
oldinode->u.i_mops->unlink(oldinode, newrelpath);
|
||||
#ifdef CONFIG_FS_NOTIFY
|
||||
notify_unlink(newrelpath);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -438,6 +472,13 @@ errout_with_newsearch:
|
|||
lib_free(subdir);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_FS_NOTIFY
|
||||
if (ret >= 0)
|
||||
{
|
||||
notify_rename(oldpath, oldisdir, newpath, newisdir);
|
||||
}
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif /* CONFIG_DISABLE_MOUNTPOINT */
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
|
||||
#include <nuttx/fs/fs.h>
|
||||
|
||||
#include "notify/notify.h"
|
||||
#include "inode/inode.h"
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -165,6 +166,9 @@ int rmdir(FAR const char *pathname)
|
|||
|
||||
inode_release(inode);
|
||||
RELEASE_SEARCH(&desc);
|
||||
#ifdef CONFIG_FS_NOTIFY
|
||||
notify_unlink(pathname);
|
||||
#endif
|
||||
return OK;
|
||||
|
||||
errout_with_inode:
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include <nuttx/lib/lib.h>
|
||||
#include <nuttx/fs/fs.h>
|
||||
|
||||
#include "notify/notify.h"
|
||||
#include "inode/inode.h"
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -167,6 +168,9 @@ int symlink(FAR const char *path1, FAR const char *path2)
|
|||
/* Symbolic link successfully created */
|
||||
|
||||
RELEASE_SEARCH(&desc);
|
||||
#ifdef CONFIG_FS_NOTIFY
|
||||
notify_create(path2);
|
||||
#endif
|
||||
return OK;
|
||||
|
||||
errout_with_inode:
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
|
||||
#include <nuttx/fs/fs.h>
|
||||
|
||||
#include "notify/notify.h"
|
||||
#include "inode/inode.h"
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -190,6 +191,9 @@ int nx_unlink(FAR const char *pathname)
|
|||
|
||||
inode_release(inode);
|
||||
RELEASE_SEARCH(&desc);
|
||||
#ifdef CONFIG_FS_NOTIFY
|
||||
notify_unlink(pathname);
|
||||
#endif
|
||||
return OK;
|
||||
|
||||
#if !defined(CONFIG_DISABLE_MOUNTPOINT) || !defined(CONFIG_DISABLE_PSEUDOFS_OPERATIONS)
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
|
||||
#include <nuttx/cancelpt.h>
|
||||
|
||||
#include "notify/notify.h"
|
||||
#include "inode/inode.h"
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -68,6 +69,7 @@ ssize_t file_write(FAR struct file *filep, FAR const void *buf,
|
|||
size_t nbytes)
|
||||
{
|
||||
FAR struct inode *inode;
|
||||
ssize_t ret;
|
||||
|
||||
/* Was this file opened for write access? */
|
||||
|
||||
|
@ -86,7 +88,15 @@ ssize_t file_write(FAR struct file *filep, FAR const void *buf,
|
|||
|
||||
/* Yes, then let the driver perform the write */
|
||||
|
||||
return inode->u.i_ops->write(filep, buf, nbytes);
|
||||
ret = inode->u.i_ops->write(filep, buf, nbytes);
|
||||
#ifdef CONFIG_FS_NOTIFY
|
||||
if (ret > 0)
|
||||
{
|
||||
notify_write(filep);
|
||||
}
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
|
169
include/sys/inotify.h
Normal file
169
include/sys/inotify.h
Normal file
|
@ -0,0 +1,169 @@
|
|||
/****************************************************************************
|
||||
* include/sys/inotify.h
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_SYS_INOTIFY_H
|
||||
#define __INCLUDE_SYS_INOTIFY_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define IN_ACCESS 0x00000001 /* File was accessed */
|
||||
#define IN_MODIFY 0x00000002 /* File was modified */
|
||||
#define IN_ATTRIB 0x00000004 /* Metadata changed */
|
||||
#define IN_CLOSE_WRITE 0x00000008 /* Writtable file was closed */
|
||||
#define IN_CLOSE_NOWRITE 0x00000010 /* Unwrittable file closed */
|
||||
#define IN_OPEN 0x00000020 /* File was opened */
|
||||
#define IN_MOVED_FROM 0x00000040 /* File was moved from X */
|
||||
#define IN_MOVED_TO 0x00000080 /* File was moved to Y */
|
||||
#define IN_CREATE 0x00000100 /* Subfile was created */
|
||||
#define IN_DELETE 0x00000200 /* Subfile was deleted */
|
||||
#define IN_DELETE_SELF 0x00000400 /* Self was deleted */
|
||||
#define IN_MOVE_SELF 0x00000800 /* Self was moved */
|
||||
|
||||
#define IN_UNMOUNT 0x00002000 /* Backing fs was unmounted */
|
||||
#define IN_Q_OVERFLOW 0x00004000 /* Event queued overflowed */
|
||||
#define IN_IGNORED 0x00008000 /* File was ignored */
|
||||
|
||||
#define IN_ONLYDIR 0x01000000 /* Only watch the path if it is a directory. */
|
||||
#define IN_DONT_FOLLOW 0x02000000 /* Do not follow a sym link. */
|
||||
#define IN_EXCL_UNLINK 0x04000000 /* Exclude events on unlinked objects. */
|
||||
#define IN_MASK_CREATE 0x10000000 /* Only create watches. */
|
||||
|
||||
#define IN_MASK_ADD 0x20000000 /* Add to the mask of an already existing watch */
|
||||
#define IN_ISDIR 0x40000000 /* Event occurred against dir */
|
||||
#define IN_ONESHOT 0x80000000 /* Only send event once */
|
||||
|
||||
#define IN_CLOSE (IN_CLOSE_WRITE | IN_CLOSE_NOWRITE) /* Close */
|
||||
#define IN_MOVE (IN_MOVED_FROM | IN_MOVED_TO) /* Moves */
|
||||
|
||||
#define IN_ALL_EVENTS (IN_ACCESS | IN_MODIFY | IN_ATTRIB | IN_CLOSE_WRITE | \
|
||||
IN_CLOSE_NOWRITE | IN_OPEN | IN_MOVED_FROM | IN_MOVED_TO | \
|
||||
IN_CREATE | IN_DELETE | IN_DELETE_SELF | IN_MOVE_SELF)
|
||||
|
||||
#define IN_CLOEXEC O_CLOEXEC /* Set close_on_exec for the inotify file descriptor */
|
||||
#define IN_NONBLOCK O_NONBLOCK /* Set O_NONBLOCK for the inotify file descriptor */
|
||||
|
||||
/****************************************************************************
|
||||
* Type Definitions
|
||||
****************************************************************************/
|
||||
|
||||
struct inotify_event
|
||||
{
|
||||
int wd; /* Watch descriptor */
|
||||
uint32_t mask; /* Mask describing event */
|
||||
uint32_t cookie; /* Unique cookie associating related events (for rename(2)) */
|
||||
uint32_t len; /* Size of name field */
|
||||
char name[0]; /* Stub for possible name */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: inotify_init
|
||||
*
|
||||
* Description:
|
||||
* Initializes a new inotify instance and returns a file descriptor
|
||||
* associated with a new inotify event queue.
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, these system calls return a new file descriptor.
|
||||
* On error, -1 is returned and errno is set appropriately.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int inotify_init(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: inotify_init1
|
||||
*
|
||||
* Description:
|
||||
* Initializes a new inotify instance and returns a file descriptor
|
||||
* associated with a new inotify event queue.
|
||||
*
|
||||
* Input Parameters:
|
||||
* flags - The following values are recognized in flags:
|
||||
* IN_NONBLOCK - Set the O_NONBLOCK file status flag on the new open file
|
||||
* description. Using this flag saves extra calls to fcntl(2) to achieve
|
||||
* the same result.
|
||||
* IN_CLOEXEC - Set the close-on-exec (FD_CLOEXEC) flag on the new file
|
||||
* descriptor. See the description of the O_CLOEXEC flag in open(2) for
|
||||
* reasons why this may be useful.
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, these system calls return a new file descriptor.
|
||||
* On error, -1 is returned and errno is set appropriately.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int inotify_init1(int flags);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: inotify_add_watch
|
||||
*
|
||||
* Description:
|
||||
* Adds a new watch, or modifies an existing watch, for the file whose
|
||||
* location is specified in pathname; the caller must have read permission
|
||||
* for this file. The fd argument is a file descriptor referring to the
|
||||
* inotify instance whose watch list is to be modified. The events to be
|
||||
* monitored for pathname are specified in the mask bit-mask argument.
|
||||
*
|
||||
* Input Parameters:
|
||||
* fd - The file descriptor associated with an instance of inotify.
|
||||
* pathname - The path to the file to be monitored.
|
||||
* mask - The bit mask of events to be monitored.
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, inotify_add_watch() returns a nonnegative watch descriptor.
|
||||
* On error, -1 is returned and errno is set appropriately.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int inotify_add_watch(int fd, FAR const char *pathname, uint32_t mask);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: inotify_rm_watch
|
||||
*
|
||||
* Description:
|
||||
* Removes the watch associated with the watch descriptor wd from the
|
||||
* inotify instance associated with the file descriptor fd.
|
||||
*
|
||||
* Input Parameters:
|
||||
* fd - The file descriptor associated with an instance of inotify.
|
||||
* wd - The watch descriptor to be removed.
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, inotify_rm_watch() returns zero. On error, -1 is returned
|
||||
* and errno is set appropriately.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int inotify_rm_watch(int fd, int wd);
|
||||
|
||||
#endif
|
|
@ -286,6 +286,15 @@ SYSCALL_LOOKUP(munmap, 2)
|
|||
SYSCALL_LOOKUP(shm_unlink, 1)
|
||||
#endif
|
||||
|
||||
/* The following are defined if the file system notify is enabled */
|
||||
|
||||
#ifdef CONFIG_FS_NOTIFY
|
||||
SYSCALL_LOOKUP(inotify_add_watch, 3)
|
||||
SYSCALL_LOOKUP(inotify_init, 0)
|
||||
SYSCALL_LOOKUP(inotify_init1, 1)
|
||||
SYSCALL_LOOKUP(inotify_rm_watch, 2)
|
||||
#endif
|
||||
|
||||
/* The following are defined if pthreads are enabled */
|
||||
|
||||
#ifndef CONFIG_DISABLE_PTHREAD
|
||||
|
|
|
@ -50,6 +50,10 @@
|
|||
"gettid","unistd.h","","pid_t"
|
||||
"gettimeofday","sys/time.h","","int","FAR struct timeval *","FAR struct timezone *"
|
||||
"getuid","unistd.h","defined(CONFIG_SCHED_USER_IDENTITY)","uid_t"
|
||||
"inotify_add_watch","sys/inotify.h","defined(CONFIG_FS_NOTIFY)","int","int","FAR const char *","uint32_t"
|
||||
"inotify_init","sys/inotify.h","defined(CONFIG_FS_NOTIFY)","int"
|
||||
"inotify_init1","sys/inotify.h","defined(CONFIG_FS_NOTIFY)","int","int"
|
||||
"inotify_rm_watch","sys/inotify.h","defined(CONFIG_FS_NOTIFY)","int","int","int"
|
||||
"insmod","nuttx/module.h","defined(CONFIG_MODULE)","FAR void *","FAR const char *","FAR const char *"
|
||||
"ioctl","sys/ioctl.h","","int","int","int","...","unsigned long"
|
||||
"kill","signal.h","","int","pid_t","int"
|
||||
|
|
Can't render this file because it has a wrong number of fields in line 2.
|
Loading…
Reference in a new issue