smartfs: add support for FIOC_FILEPATH ioctl
The FIOC_FILEPATH ioctl call is required if smartfs is to be used together with inotify monitoring system. This implements the call support to smartfs file system. The path to the file has to be stored in smartfs_ofile_s structure during file open (and is freed during close) as smartfs currently is not able to obtain the path knowing only the file node. The full path is concatenated with the file name and creates the full path needed for inotify to detect whether the file is on the watchlist. Signed-off-by: Michal Lenc <michallenc@seznam.cz>
This commit is contained in:
parent
0ac21a911b
commit
01bed328ef
@ -307,6 +307,7 @@ struct smartfs_ofile_s
|
||||
* a seek, or more data is written that
|
||||
* causes the sector to change.
|
||||
*/
|
||||
char path[1]; /* The full path to the file */
|
||||
};
|
||||
|
||||
/* This structure represents the overall mountpoint state. An instance of
|
||||
|
@ -44,6 +44,7 @@
|
||||
#include <nuttx/mtd/mtd.h>
|
||||
#include <nuttx/fs/smart.h>
|
||||
|
||||
#include "inode/inode.h"
|
||||
#include "smartfs.h"
|
||||
|
||||
/****************************************************************************
|
||||
@ -181,6 +182,7 @@ static int smartfs_open(FAR struct file *filep, FAR const char *relpath,
|
||||
FAR struct smartfs_mountpt_s *fs;
|
||||
int ret;
|
||||
uint16_t parentdirsector;
|
||||
size_t pathlen;
|
||||
FAR const char *filename;
|
||||
FAR struct smartfs_ofile_s *sf;
|
||||
#ifdef CONFIG_SMARTFS_USE_SECTOR_BUFFER
|
||||
@ -210,13 +212,20 @@ static int smartfs_open(FAR struct file *filep, FAR const char *relpath,
|
||||
|
||||
/* Locate the directory entry for this path */
|
||||
|
||||
sf = kmm_malloc(sizeof *sf);
|
||||
pathlen = strlen(relpath) + 1;
|
||||
sf = kmm_malloc(sizeof(*sf) + pathlen - 1);
|
||||
if (sf == NULL)
|
||||
{
|
||||
ret = -ENOMEM;
|
||||
goto errout_with_lock;
|
||||
}
|
||||
|
||||
/* Save the full path to smartfs_ofile_s stuctrue. This is needed
|
||||
* to FIOC_FILEPATH ioctlc all support.
|
||||
*/
|
||||
|
||||
memcpy(sf->path, relpath, pathlen);
|
||||
|
||||
/* Allocate a sector buffer if CRC enabled in the MTD layer */
|
||||
|
||||
#ifdef CONFIG_SMARTFS_USE_SECTOR_BUFFER
|
||||
@ -997,9 +1006,39 @@ static off_t smartfs_seek(FAR struct file *filep, off_t offset, int whence)
|
||||
|
||||
static int smartfs_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
|
||||
{
|
||||
/* We don't use any ioctls */
|
||||
FAR struct smartfs_ofile_s *priv;
|
||||
FAR struct inode *inode;
|
||||
int ret;
|
||||
|
||||
return -ENOSYS;
|
||||
/* Recover our private data from the struct file instance */
|
||||
|
||||
priv = filep->f_priv;
|
||||
inode = filep->f_inode;
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
case FIOC_FILEPATH:
|
||||
{
|
||||
FAR char *path = (FAR char *)(uintptr_t)arg;
|
||||
ret = inode_getpath(inode, path, PATH_MAX);
|
||||
if (ret >= 0)
|
||||
{
|
||||
size_t len = strlen(path);
|
||||
if (path[len - 1] != '/')
|
||||
{
|
||||
path[len++] = '/';
|
||||
}
|
||||
|
||||
strlcat(path, priv->path, PATH_MAX - len);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ret = -ENOSYS;
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
Loading…
Reference in New Issue
Block a user