inode更新mtime和ctime

    xiaoxiao2021-03-25  67

    /**  * 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); }
    转载请注明原文地址: https://ju.6miu.com/read-36683.html

    最新回复(0)