inode更新mtime和ctime

/**
 *	file_update_time-- update mtime and ctime time
 *	@file: file accessed
 *
 *	Update the mtime and ctime members of an inode and mark the inode
 *	for writeback.  Note that this function is meant exclusively for
 *	usage in the file write path of filesystems, and filesystems may
 *	choose to explicitly ignore update via this function with the
 *	S_NOCMTIME inode flag, e.g. for network filesystem where these
 *	timestamps are handled by the server.  This can return an error for
 *	file systems who need to allocate space in order to update an inode.
 */


int file_update_time(struct file *file)
{
	struct inode *inode = file_inode(file);
	struct timespec now;
	int sync_it = 0;
	int ret;


	/* First try to exhaust all avenues to not sync */
	if (IS_NOCMTIME(inode))
		return 0;


	now = current_time(inode);
	if (!timespec_equal(&inode->i_mtime, &now))
		sync_it = S_MTIME;


	if (!timespec_equal(&inode->i_ctime, &now))
		sync_it |= S_CTIME;


	if (IS_I_VERSION(inode))
		sync_it |= S_VERSION;


	if (!sync_it)
		return 0;


	/* Finally allowed to write? Takes lock. */
	if (__mnt_want_write_file(file))
		return 0;


	ret = update_time(inode, &now, sync_it);
	__mnt_drop_write_file(file);


	return ret;
}
 
/*
 * This does the actual work of updating an inodes time or version.  Must have
 * had called mnt_want_write() before calling this.
 */
static int update_time(struct inode *inode, struct timespec *time, int flags)
{
	int (*update_time)(struct inode *, struct timespec *, int);


	update_time = inode->i_op->update_time ? inode->i_op->update_time :
		generic_update_time;


	return update_time(inode, time, flags);
}

                
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值