fs:add syncfs api for sync whole fs data
Signed-off-by: guohao15 <guohao15@xiaomi.com>
This commit is contained in:
parent
a41f68da84
commit
2bce0f404c
@ -25,7 +25,7 @@ CSRCS += fs_fchstat.c fs_fstat.c fs_fstatfs.c fs_ioctl.c fs_lseek.c
|
||||
CSRCS += fs_mkdir.c fs_open.c fs_poll.c fs_pread.c fs_pwrite.c fs_read.c
|
||||
CSRCS += fs_rename.c fs_rmdir.c fs_select.c fs_sendfile.c fs_stat.c
|
||||
CSRCS += fs_statfs.c fs_unlink.c fs_write.c fs_dir.c fs_fsync.c
|
||||
CSRCS += fs_truncate.c
|
||||
CSRCS += fs_syncfs.c fs_truncate.c
|
||||
|
||||
# Certain interfaces are not available if there is no mountpoint support
|
||||
|
||||
|
102
fs/vfs/fs_syncfs.c
Normal file
102
fs/vfs/fs_syncfs.c
Normal file
@ -0,0 +1,102 @@
|
||||
/****************************************************************************
|
||||
* fs/vfs/fs_syncfs.c
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/cancelpt.h>
|
||||
#include <nuttx/fs/fs.h>
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: file_syncfs
|
||||
*
|
||||
* Description:
|
||||
* Equivalent to the standard syncsf() function except that is accepts a
|
||||
* struct file instance instead of a fd descriptor and it does not set
|
||||
* the errno variable
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int file_syncfs(FAR struct file *filep)
|
||||
{
|
||||
FAR struct inode *inode = filep->f_inode;
|
||||
|
||||
if (inode != NULL)
|
||||
{
|
||||
#ifndef CONFIG_DISABLE_MOUNTPOINT
|
||||
if (INODE_IS_MOUNTPT(inode) && inode->u.i_mops &&
|
||||
inode->u.i_mops->syncfs)
|
||||
{
|
||||
return inode->u.i_mops->syncfs(inode);
|
||||
}
|
||||
#endif /* !CONFIG_DISABLE_MOUNTPOINT */
|
||||
}
|
||||
|
||||
return -EBADF;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: syncfs
|
||||
*
|
||||
* Description:
|
||||
* syncfs() is like sync(), but synchronizes just the filesystem
|
||||
* containing file referred to by the open file descriptor fd.
|
||||
*
|
||||
* Returned Value:
|
||||
* syncfs() returns 0 on success; on error, it returns -1 and sets
|
||||
* errno to indicate the error.
|
||||
*
|
||||
* Assumptions:
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int syncfs(int fd)
|
||||
{
|
||||
FAR struct file *filep;
|
||||
int ret;
|
||||
|
||||
enter_cancellation_point();
|
||||
|
||||
ret = fs_getfilep(fd, &filep);
|
||||
if (ret == OK)
|
||||
{
|
||||
DEBUGASSERT(filep != NULL);
|
||||
ret = file_syncfs(filep);
|
||||
}
|
||||
|
||||
leave_cancellation_point();
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
set_errno(-ret);
|
||||
ret = ERROR;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -33,14 +33,14 @@
|
||||
* clock_nanosleep() msgsnd() read() sigwaitinfo()
|
||||
* close() msync() readv() sleep()
|
||||
* connect() nanosleep() recv() system()
|
||||
* creat() open() recvfrom() tcdrain()
|
||||
* fcntl() pause() recvmsg() usleep()
|
||||
* fdatasync() poll() select() wait()
|
||||
* fsync() pread() sem_timedwait() waitid()
|
||||
* getmsg() pselect() sem_wait() waitpid()
|
||||
* getpmsg() pthread_cond_timedwait() send() write()
|
||||
* lockf() pthread_cond_wait() sendmsg() writev()
|
||||
* mq_receive() pthread_join() sendto()
|
||||
* creat() open() recvfrom() syncfs()
|
||||
* fcntl() pause() recvmsg() tcdrain()
|
||||
* fdatasync() poll() select() usleep()
|
||||
* fsync() pread() sem_timedwait() wait()
|
||||
* getmsg() pselect() sem_wait() waitid()
|
||||
* getpmsg() pthread_cond_timedwait() send() waitpid()
|
||||
* lockf() pthread_cond_wait() sendmsg() write()
|
||||
* mq_receive() pthread_join() sendto() writev()
|
||||
* mq_send() pthread_testcancel() sigpause()
|
||||
* mq_timedreceive() putmsg() sigsuspend()
|
||||
*
|
||||
|
@ -364,6 +364,7 @@ struct mountpt_operations
|
||||
FAR struct stat *buf);
|
||||
CODE int (*chstat)(FAR struct inode *mountpt, FAR const char *relpath,
|
||||
FAR const struct stat *buf, int flags);
|
||||
CODE int (*syncfs)(FAR struct inode *mountpt);
|
||||
};
|
||||
#endif /* CONFIG_DISABLE_MOUNTPOINT */
|
||||
|
||||
@ -1382,6 +1383,18 @@ off_t nx_seek(int fd, off_t offset, int whence);
|
||||
|
||||
int file_fsync(FAR struct file *filep);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: file_syncfs
|
||||
*
|
||||
* Description:
|
||||
* Equivalent to the standard syncsf() function except that is accepts a
|
||||
* struct file instance instead of a fd descriptor and it does not set
|
||||
* the errno variable
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int file_syncfs(FAR struct file *filep);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: file_truncate
|
||||
*
|
||||
|
@ -258,7 +258,6 @@
|
||||
|
||||
/* Helpers and legacy compatibility definitions */
|
||||
|
||||
#define syncfs(f) fsync(f)
|
||||
#define fdatasync(f) fsync(f)
|
||||
#define getdtablesize(f) ((int)sysconf(_SC_OPEN_MAX))
|
||||
#define getpagesize(f) ((int)sysconf(_SC_PAGESIZE))
|
||||
@ -441,6 +440,7 @@ int setregid(gid_t rgid, gid_t egid);
|
||||
int getentropy(FAR void *buffer, size_t length);
|
||||
|
||||
void sync(void);
|
||||
int syncfs(int fd);
|
||||
|
||||
#if CONFIG_FORTIFY_SOURCE > 0
|
||||
fortify_function(getcwd) FAR char *getcwd(FAR char *buf,
|
||||
|
Loading…
Reference in New Issue
Block a user