diff --git a/include/ntfs/inode.h b/include/ntfs/inode.h index 22d35c89..e43f6932 100644 --- a/include/ntfs/inode.h +++ b/include/ntfs/inode.h @@ -171,6 +171,9 @@ static __inline__ void ntfs_inode_mark_dirty(ntfs_inode *ni) NInoSetDirty(ni->base_ni); } +extern void ntfs_inode_update_atime(ntfs_inode *ni); +extern void ntfs_inode_update_time(ntfs_inode *ni); + extern int ntfs_inode_sync(ntfs_inode *ni); extern int ntfs_inode_add_attrlist(ntfs_inode *ni); diff --git a/libntfs/attrib.c b/libntfs/attrib.c index 859cb054..0282cdea 100644 --- a/libntfs/attrib.c +++ b/libntfs/attrib.c @@ -55,7 +55,6 @@ #include "compress.h" #include "bitmap.h" #include "logging.h" -#include "ntfstime.h" ntfschar AT_UNNAMED[] = { const_cpu_to_le16('\0') }; @@ -771,14 +770,10 @@ s64 ntfs_attr_pread(ntfs_attr *na, const s64 pos, s64 count, void *b) return -1; } vol = na->ni->vol; - /* Update access time if accessing unnamed data attribute. */ - if (!NVolReadOnly(vol) && !NVolNoATime(vol) && na->ni->mft_no >= - FILE_first_user && na->type == AT_DATA && - na->name == AT_UNNAMED) { - na->ni->last_access_time = time(NULL); - NInoFileNameSetDirty(na->ni); - NInoSetDirty(na->ni); - } + /* Update access time if needed. */ + if (na->type == AT_DATA || na->type == AT_INDEX_ROOT || + na->type == AT_INDEX_ALLOCATION) + ntfs_inode_update_atime(na->ni); if (!count) return 0; /* Truncate reads beyond end of attribute. */ @@ -960,14 +955,10 @@ s64 ntfs_attr_pwrite(ntfs_attr *na, const s64 pos, s64 count, const void *b) errno = EOPNOTSUPP; return -1; } - /* Update time if writing to unnamed data attribute. */ - if (na->ni->mft_no >= FILE_first_user && na->type == AT_DATA && - na->name == AT_UNNAMED) { - na->ni->last_data_change_time = time(NULL); - na->ni->last_mft_change_time = time(NULL); - NInoFileNameSetDirty(na->ni); - NInoSetDirty(na->ni); - } + /* Update access and change times if needed. */ + if (na->type == AT_DATA || na->type == AT_INDEX_ROOT || + na->type == AT_INDEX_ALLOCATION) + ntfs_inode_update_time(na->ni); if (!count) return 0; /* If the write reaches beyond the end, extend the attribute. */ @@ -4932,10 +4923,8 @@ int ntfs_attr_truncate(ntfs_attr *na, const s64 newsize) ret = ntfs_non_resident_attr_shrink(na, newsize); } else ret = ntfs_resident_attr_resize(na, newsize); - /* Set FILE_NAME dirty flag, to update length and time in the index. */ + /* Set FILE_NAME dirty flag, to update file length in the index. */ if (na->type == AT_DATA && na->name == AT_UNNAMED) { - na->ni->last_data_change_time = time(NULL); - na->ni->last_mft_change_time = time(NULL); na->ni->data_size = na->data_size; /* * If attribute sparse or compressed then allocated size in @@ -4948,5 +4937,9 @@ int ntfs_attr_truncate(ntfs_attr *na, const s64 newsize) na->ni->allocated_size = na->allocated_size; NInoFileNameSetDirty(na->ni); } + /* Update access and change times if needed. */ + if (na->type == AT_DATA || na->type == AT_INDEX_ROOT || + na->type == AT_INDEX_ALLOCATION) + ntfs_inode_update_time(na->ni); return ret; } diff --git a/libntfs/inode.c b/libntfs/inode.c index bca5c3a1..6410f397 100644 --- a/libntfs/inode.c +++ b/libntfs/inode.c @@ -1058,6 +1058,45 @@ put_err_out: return -1; } +/** + * ntfs_inode_update_atime - update access time for ntfs inode + * @ni: ntfs inode for which update access time + * + * This function usually get called when user read not metadata from inode. + * Do not update time for system files. + */ +void ntfs_inode_update_atime(ntfs_inode *ni) +{ + if (!NVolReadOnly(ni->vol) && !NVolNoATime(ni->vol) && (ni->mft_no >= + FILE_first_user /*|| ni->mft_no == FILE_root*/)) { + ni->last_access_time = time(NULL); + NInoFileNameSetDirty(ni); + NInoSetDirty(ni); + } +} + +/** + * ntfs_inode_update_time - update all times for ntfs inode + * @ni: ntfs inode for which udpate times + * + * This function updates last access, mft and data change times. Usually + * get called when user write not metadata to inode. Do not update time for + * system files. + */ +void ntfs_inode_update_time(ntfs_inode *ni) +{ + if (!NVolReadOnly(ni->vol) && !NVolNoATime(ni->vol) && (ni->mft_no >= + FILE_first_user /*|| ni->mft_no == FILE_root*/)) { + time_t now; + + now = time(NULL); + ni->last_access_time = now; + ni->last_data_change_time = now; + ni->last_mft_change_time = now; + NInoFileNameSetDirty(ni); + NInoSetDirty(ni); + } +} #ifdef NTFS_RICH