From b614227bfdce1528385195b25028c35322dbbb76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Wed, 26 Nov 2008 10:24:11 +0000 Subject: [PATCH] * In bfs_write_stat() B_STAT_UID, B_STAT_GID, and B_STAT_MODE now also trigger an update of st_mtime. This is a work-around for the unmaintained st_ctime, and this also fixes bug #3143. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28734 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../file_systems/bfs/kernel_interface.cpp | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp b/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp index 2a9c44fc60..77a51671b6 100644 --- a/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp +++ b/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp @@ -730,6 +730,7 @@ bfs_write_stat(fs_volume* _volume, fs_vnode* _node, const struct stat* stat, inode->WriteLockInTransaction(transaction); bfs_inode& node = inode->Node(); + bool updateTime = false; if ((mask & B_STAT_SIZE) != 0) { // Since WSTAT_SIZE is the only thing that can fail directly, we @@ -755,33 +756,44 @@ bfs_write_stat(fs_volume* _volume, fs_vnode* _node, const struct stat* stat, Index index(volume); index.UpdateSize(transaction, inode); - if ((mask & B_STAT_MODIFICATION_TIME) == 0) - index.UpdateLastModified(transaction, inode); + updateTime = true; } } } + // Note, the following changes (mode/uid/gid) would update st_ctime; + // since we don't have that, we'll use st_mtime instead. + if ((mask & B_STAT_MODE) != 0) { PRINT(("original mode = %ld, stat->st_mode = %d\n", node.Mode(), stat->st_mode)); node.mode = HOST_ENDIAN_TO_BFS_INT32((node.Mode() & ~S_IUMSK) | (stat->st_mode & S_IUMSK)); + updateTime = true; } - if ((mask & B_STAT_UID) != 0) + if ((mask & B_STAT_UID) != 0) { node.uid = HOST_ENDIAN_TO_BFS_INT32(stat->st_uid); - if ((mask & B_STAT_GID) != 0) + updateTime = true; + } + if ((mask & B_STAT_GID) != 0) { node.gid = HOST_ENDIAN_TO_BFS_INT32(stat->st_gid); + updateTime = true; + } + + if ((mask & B_STAT_MODIFICATION_TIME) != 0 || updateTime) { + bigtime_t newTime; + if ((mask & B_STAT_MODIFICATION_TIME) == 0) + newTime = (bigtime_t)time(NULL) << INODE_TIME_SHIFT; + else + newTime = stat->st_mtime << INODE_TIME_SHIFT; - if ((mask & B_STAT_MODIFICATION_TIME) != 0) { if (!inode->InLastModifiedIndex()) { // directory modification times are not part of the index - node.last_modified_time = HOST_ENDIAN_TO_BFS_INT64( - (bigtime_t)stat->st_mtime << INODE_TIME_SHIFT); + node.last_modified_time = HOST_ENDIAN_TO_BFS_INT64(newTime); } else if (!inode->IsDeleted()) { // Index::UpdateLastModified() will set the new time in the inode Index index(volume); - index.UpdateLastModified(transaction, inode, - (bigtime_t)stat->st_mtime << INODE_TIME_SHIFT); + index.UpdateLastModified(transaction, inode, newTime); } } if ((mask & B_STAT_CREATION_TIME) != 0) {