···1212#include <linux/security.h>1313#include <linux/cdev.h>1414#include <linux/memblock.h>1515-#include <linux/fscrypt.h>1615#include <linux/fsnotify.h>1716#include <linux/mount.h>1817#include <linux/posix_acl.h>···23132314 return timestamp_truncate(now, inode);23142315}23152316EXPORT_SYMBOL(current_time);23162316-23172317-/*23182318- * Generic function to check FS_IOC_SETFLAGS values and reject any invalid23192319- * configurations.23202320- *23212321- * Note: the caller should be holding i_mutex, or else be sure that they have23222322- * exclusive access to the inode structure.23232323- */23242324-int vfs_ioc_setflags_prepare(struct inode *inode, unsigned int oldflags,23252325- unsigned int flags)23262326-{23272327- /*23282328- * The IMMUTABLE and APPEND_ONLY flags can only be changed by23292329- * the relevant capability.23302330- *23312331- * This test looks nicer. Thanks to Pauline Middelink23322332- */23332333- if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL) &&23342334- !capable(CAP_LINUX_IMMUTABLE))23352335- return -EPERM;23362336-23372337- return fscrypt_prepare_setflags(inode, oldflags, flags);23382338-}23392339-EXPORT_SYMBOL(vfs_ioc_setflags_prepare);23402340-23412341-/*23422342- * Generic function to check FS_IOC_FSSETXATTR values and reject any invalid23432343- * configurations.23442344- *23452345- * Note: the caller should be holding i_mutex, or else be sure that they have23462346- * exclusive access to the inode structure.23472347- */23482348-int vfs_ioc_fssetxattr_check(struct inode *inode, const struct fsxattr *old_fa,23492349- struct fsxattr *fa)23502350-{23512351- /*23522352- * Can't modify an immutable/append-only file unless we have23532353- * appropriate permission.23542354- */23552355- if ((old_fa->fsx_xflags ^ fa->fsx_xflags) &23562356- (FS_XFLAG_IMMUTABLE | FS_XFLAG_APPEND) &&23572357- !capable(CAP_LINUX_IMMUTABLE))23582358- return -EPERM;23592359-23602360- /*23612361- * Project Quota ID state is only allowed to change from within the init23622362- * namespace. Enforce that restriction only if we are trying to change23632363- * the quota ID state. Everything else is allowed in user namespaces.23642364- */23652365- if (current_user_ns() != &init_user_ns) {23662366- if (old_fa->fsx_projid != fa->fsx_projid)23672367- return -EINVAL;23682368- if ((old_fa->fsx_xflags ^ fa->fsx_xflags) &23692369- FS_XFLAG_PROJINHERIT)23702370- return -EINVAL;23712371- }23722372-23732373- /* Check extent size hints. */23742374- if ((fa->fsx_xflags & FS_XFLAG_EXTSIZE) && !S_ISREG(inode->i_mode))23752375- return -EINVAL;23762376-23772377- if ((fa->fsx_xflags & FS_XFLAG_EXTSZINHERIT) &&23782378- !S_ISDIR(inode->i_mode))23792379- return -EINVAL;23802380-23812381- if ((fa->fsx_xflags & FS_XFLAG_COWEXTSIZE) &&23822382- !S_ISREG(inode->i_mode) && !S_ISDIR(inode->i_mode))23832383- return -EINVAL;23842384-23852385- /*23862386- * It is only valid to set the DAX flag on regular files and23872387- * directories on filesystems.23882388- */23892389- if ((fa->fsx_xflags & FS_XFLAG_DAX) &&23902390- !(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode)))23912391- return -EINVAL;23922392-23932393- /* Extent size hints of zero turn off the flags. */23942394- if (fa->fsx_extsize == 0)23952395- fa->fsx_xflags &= ~(FS_XFLAG_EXTSIZE | FS_XFLAG_EXTSZINHERIT);23962396- if (fa->fsx_cowextsize == 0)23972397- fa->fsx_xflags &= ~FS_XFLAG_COWEXTSIZE;23982398-23992399- return 0;24002400-}24012401-EXPORT_SYMBOL(vfs_ioc_fssetxattr_check);
-12
include/linux/fs.h
···35713571extern int generic_fadvise(struct file *file, loff_t offset, loff_t len,35723572 int advice);3573357335743574-int vfs_ioc_setflags_prepare(struct inode *inode, unsigned int oldflags,35753575- unsigned int flags);35763576-35773577-int vfs_ioc_fssetxattr_check(struct inode *inode, const struct fsxattr *old_fa,35783578- struct fsxattr *fa);35793579-35803580-static inline void simple_fill_fsxattr(struct fsxattr *fa, __u32 xflags)35813581-{35823582- memset(fa, 0, sizeof(*fa));35833583- fa->fsx_xflags = xflags;35843584-}35853585-35863574/*35873575 * Flush file data before changing attributes. Caller must hold any locks35883576 * required to prevent further writes to this file until we're done setting