mirror of
https://github.com/apache/nuttx.git
synced 2026-05-31 23:40:19 +08:00
fs/fs.h: Add register_driver_with_size function
It acts as register_driver but also populates the inode size. This allows to return a non-zero size when calling stat() on an eeprom driver. The conditions (CONFIG_PSEUDOFS_FILE or CONFIG_FS_SHMFS) for the declaration of the inode size field have also been removed so that other drivers can populate this field in the future. Signed-off-by: Antoine Juckler <6445757+ajuckler@users.noreply.github.com>
This commit is contained in:
committed by
Alan C. Assis
parent
934dfdf645
commit
23de88e70e
@@ -924,5 +924,6 @@ int ee24xx_initialize(FAR struct i2c_master_s *bus, uint8_t devaddr,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return register_driver(devname, &g_ee24xx_fops, 0666, eedev);
|
return register_driver_with_size(devname, &g_ee24xx_fops, 0666, eedev,
|
||||||
|
eedev->size);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -860,5 +860,6 @@ int ee25xx_initialize(FAR struct spi_dev_s *dev, FAR char *devname,
|
|||||||
"%u per page, addrlen %u, readonly %d\n",
|
"%u per page, addrlen %u, readonly %d\n",
|
||||||
devname, eedev->size, eedev->pgsize, eedev->addrlen, eedev->readonly);
|
devname, eedev->size, eedev->pgsize, eedev->addrlen, eedev->readonly);
|
||||||
|
|
||||||
return register_driver(devname, &g_ee25xx_fops, 0666, eedev);
|
return register_driver_with_size(devname, &g_ee25xx_fops, 0666, eedev,
|
||||||
|
eedev->size);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,16 +40,18 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: register_driver
|
* Name: register_driver_with_size
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Register a character driver inode the pseudo file system.
|
* Register a character driver inode into the pseudo file system and
|
||||||
|
* assign a size to it.
|
||||||
*
|
*
|
||||||
* Input Parameters:
|
* Input Parameters:
|
||||||
* path - The path to the inode to create
|
* path - The path to the inode to create
|
||||||
* fops - The file operations structure
|
* fops - The file operations structure
|
||||||
* mode - inmode privileges
|
* mode - inmode privileges
|
||||||
* priv - Private, user data that will be associated with the inode.
|
* priv - Private, user data that will be associated with the inode.
|
||||||
|
* size - Size in bytes to assign to the driver
|
||||||
*
|
*
|
||||||
* Returned Value:
|
* Returned Value:
|
||||||
* Zero on success (with the inode point in 'inode'); A negated errno
|
* Zero on success (with the inode point in 'inode'); A negated errno
|
||||||
@@ -62,9 +64,9 @@
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int register_driver(FAR const char *path,
|
int register_driver_with_size(FAR const char *path,
|
||||||
FAR const struct file_operations *fops,
|
FAR const struct file_operations *fops,
|
||||||
mode_t mode, FAR void *priv)
|
mode_t mode, FAR void *priv, size_t size)
|
||||||
{
|
{
|
||||||
FAR struct inode *node;
|
FAR struct inode *node;
|
||||||
int ret;
|
int ret;
|
||||||
@@ -87,13 +89,46 @@ int register_driver(FAR const char *path,
|
|||||||
|
|
||||||
node->u.i_ops = fops;
|
node->u.i_ops = fops;
|
||||||
node->i_private = priv;
|
node->i_private = priv;
|
||||||
|
node->i_size = size;
|
||||||
|
|
||||||
inode_unlock();
|
inode_unlock();
|
||||||
#ifdef CONFIG_FS_NOTIFY
|
#ifdef CONFIG_FS_NOTIFY
|
||||||
notify_create(path);
|
notify_create(path);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
inode_unlock();
|
inode_unlock();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: register_driver
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Register a character driver inode into the pseudo file system.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* path - The path to the inode to create
|
||||||
|
* fops - The file operations structure
|
||||||
|
* mode - inmode privileges
|
||||||
|
* priv - Private, user data that will be associated with the inode.
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Zero on success (with the inode point in 'inode'); A negated errno
|
||||||
|
* value is returned on a failure (all error values returned by
|
||||||
|
* inode_reserve):
|
||||||
|
*
|
||||||
|
* EINVAL - 'path' is invalid for this operation
|
||||||
|
* EEXIST - An inode already exists at 'path'
|
||||||
|
* ENOMEM - Failed to allocate in-memory resources for the operation
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int register_driver(FAR const char *path,
|
||||||
|
FAR const struct file_operations *fops,
|
||||||
|
mode_t mode, FAR void *priv)
|
||||||
|
{
|
||||||
|
return register_driver_with_size(path, fops, mode, priv, 0);
|
||||||
|
}
|
||||||
|
|||||||
+1
-1
@@ -428,9 +428,9 @@ int inode_stat(FAR struct inode *inode, FAR struct stat *buf, int resolve)
|
|||||||
{
|
{
|
||||||
/* What is it if it also has child inodes? */
|
/* What is it if it also has child inodes? */
|
||||||
|
|
||||||
#ifdef CONFIG_PSEUDOFS_FILE
|
|
||||||
buf->st_size = inode->i_size;
|
buf->st_size = inode->i_size;
|
||||||
|
|
||||||
|
#ifdef CONFIG_PSEUDOFS_FILE
|
||||||
if (inode_is_pseudofile(inode))
|
if (inode_is_pseudofile(inode))
|
||||||
{
|
{
|
||||||
buf->st_mode |= S_IFREG;
|
buf->st_mode |= S_IFREG;
|
||||||
|
|||||||
+29
-2
@@ -407,9 +407,7 @@ struct inode
|
|||||||
uint16_t i_flags; /* Flags for inode */
|
uint16_t i_flags; /* Flags for inode */
|
||||||
union inode_ops_u u; /* Inode operations */
|
union inode_ops_u u; /* Inode operations */
|
||||||
ino_t i_ino; /* Inode serial number */
|
ino_t i_ino; /* Inode serial number */
|
||||||
#if defined(CONFIG_PSEUDOFS_FILE) || defined(CONFIG_FS_SHMFS)
|
|
||||||
size_t i_size; /* The size of per inode driver */
|
size_t i_size; /* The size of per inode driver */
|
||||||
#endif
|
|
||||||
#ifdef CONFIG_PSEUDOFS_ATTRIBUTES
|
#ifdef CONFIG_PSEUDOFS_ATTRIBUTES
|
||||||
mode_t i_mode; /* Access mode flags */
|
mode_t i_mode; /* Access mode flags */
|
||||||
uid_t i_owner; /* Owner */
|
uid_t i_owner; /* Owner */
|
||||||
@@ -625,6 +623,35 @@ int register_driver(FAR const char *path,
|
|||||||
FAR const struct file_operations *fops, mode_t mode,
|
FAR const struct file_operations *fops, mode_t mode,
|
||||||
FAR void *priv);
|
FAR void *priv);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: register_driver_with_size
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Register a character driver inode into the pseudo file system and
|
||||||
|
* assign a size to it.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* path - The path to the inode to create
|
||||||
|
* fops - The file operations structure
|
||||||
|
* mode - inmode privileges
|
||||||
|
* priv - Private, user data that will be associated with the inode.
|
||||||
|
* size - Size in bytes to assign to the driver
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Zero on success (with the inode point in 'inode'); A negated errno
|
||||||
|
* value is returned on a failure (all error values returned by
|
||||||
|
* inode_reserve):
|
||||||
|
*
|
||||||
|
* EINVAL - 'path' is invalid for this operation
|
||||||
|
* EEXIST - An inode already exists at 'path'
|
||||||
|
* ENOMEM - Failed to allocate in-memory resources for the operation
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int register_driver_with_size(FAR const char *path,
|
||||||
|
FAR const struct file_operations *fops,
|
||||||
|
mode_t mode, FAR void *priv, size_t size);
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: register_blockdriver
|
* Name: register_blockdriver
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user