fs/hostfs: Add ftruncate support.

This commit is contained in:
Xiang Xiao 2018-08-22 06:08:34 -06:00 committed by Gregory Nutt
parent 9bbacc44ff
commit c43b3e5a34
2 changed files with 53 additions and 0 deletions

View File

@ -250,6 +250,15 @@ int host_fstat(int fd, struct nuttx_stat_s *buf)
return ret;
}
/****************************************************************************
* Name: host_truncate
****************************************************************************/
int host_ftruncate(int fd, off_t length)
{
return ftruncate(fd, length);
}
/****************************************************************************
* Name: host_opendir
****************************************************************************/

View File

@ -82,6 +82,8 @@ static int hostfs_dup(FAR const struct file *oldp,
FAR struct file *newp);
static int hostfs_fstat(FAR const struct file *filep,
FAR struct stat *buf);
static int hostfs_ftruncate(FAR struct file *filep,
off_t length);
static int hostfs_opendir(FAR struct inode *mountpt,
FAR const char *relpath,
@ -139,6 +141,7 @@ const struct mountpt_operations hostfs_operations =
hostfs_sync, /* sync */
hostfs_dup, /* dup */
hostfs_fstat, /* fstat */
hostfs_ftruncate, /* ftruncate */
hostfs_opendir, /* opendir */
hostfs_closedir, /* closedir */
@ -722,6 +725,47 @@ static int hostfs_fstat(FAR const struct file *filep, FAR struct stat *buf)
return ret;
}
/****************************************************************************
* Name: hostfs_ftruncate
*
* Description:
* Set the length of the open, regular file associated with the file
* structure 'filep' to 'length'.
*
****************************************************************************/
static int hostfs_ftruncate(FAR struct file *filep, off_t length)
{
FAR struct inode *inode;
FAR struct hostfs_mountpt_s *fs;
FAR struct hostfs_ofile_s *hf;
int ret = OK;
/* Sanity checks */
DEBUGASSERT(filep != NULL);
/* Recover our private data from the struct file instance */
DEBUGASSERT(filep->f_priv != NULL && filep->f_inode != NULL);
hf = filep->f_priv;
inode = filep->f_inode;
fs = inode->i_private;
DEBUGASSERT(fs != NULL);
/* Take the semaphore */
hostfs_semtake(fs);
/* Call the host to perform the truncate */
ret = host_ftruncate(hf->fd, length);
hostfs_semgive(fs);
return ret;
}
/****************************************************************************
* Name: hostfs_opendir
*