fs/hostfs: Add ftruncate support.
This commit is contained in:
parent
9bbacc44ff
commit
c43b3e5a34
|
@ -250,6 +250,15 @@ int host_fstat(int fd, struct nuttx_stat_s *buf)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: host_truncate
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int host_ftruncate(int fd, off_t length)
|
||||||
|
{
|
||||||
|
return ftruncate(fd, length);
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: host_opendir
|
* Name: host_opendir
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
|
@ -82,6 +82,8 @@ static int hostfs_dup(FAR const struct file *oldp,
|
||||||
FAR struct file *newp);
|
FAR struct file *newp);
|
||||||
static int hostfs_fstat(FAR const struct file *filep,
|
static int hostfs_fstat(FAR const struct file *filep,
|
||||||
FAR struct stat *buf);
|
FAR struct stat *buf);
|
||||||
|
static int hostfs_ftruncate(FAR struct file *filep,
|
||||||
|
off_t length);
|
||||||
|
|
||||||
static int hostfs_opendir(FAR struct inode *mountpt,
|
static int hostfs_opendir(FAR struct inode *mountpt,
|
||||||
FAR const char *relpath,
|
FAR const char *relpath,
|
||||||
|
@ -139,6 +141,7 @@ const struct mountpt_operations hostfs_operations =
|
||||||
hostfs_sync, /* sync */
|
hostfs_sync, /* sync */
|
||||||
hostfs_dup, /* dup */
|
hostfs_dup, /* dup */
|
||||||
hostfs_fstat, /* fstat */
|
hostfs_fstat, /* fstat */
|
||||||
|
hostfs_ftruncate, /* ftruncate */
|
||||||
|
|
||||||
hostfs_opendir, /* opendir */
|
hostfs_opendir, /* opendir */
|
||||||
hostfs_closedir, /* closedir */
|
hostfs_closedir, /* closedir */
|
||||||
|
@ -722,6 +725,47 @@ static int hostfs_fstat(FAR const struct file *filep, FAR struct stat *buf)
|
||||||
return ret;
|
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
|
* Name: hostfs_opendir
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue