kernel/fs: Notify node monitor when opening files with O_TRUNC

Opening files with the O_TRUNC flag will now notify the node monitor if
this resulted in the file size changing.
Implemented on filesystems with write support:
 * BFS
 * EXT2
 * FAT
 * NTFS
 * write_overlay

Change-Id: I4ae7d6b93727a9cc83f64d649b118beb94b16657
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10923
Reviewed-by: waddlesplash <[email protected]>
Haiku-Format: Haiku-format Bot <[email protected]>
Tested-by: Commit checker robot <[email protected]>
This commit is contained in:
Nathan Patrizi
2026-05-05 06:13:53 +00:00
committed by Adrien Destugues
parent caf5c2722d
commit b5e907c11e
5 changed files with 26 additions and 2 deletions
@@ -1384,6 +1384,11 @@ bfs_open(fs_volume* _volume, fs_vnode* _node, int openMode, void** _cookie)
status = transaction.Done();
if (status != B_OK)
return status;
if (cookie->last_size != 0) {
cookie->last_size = inode->Size();
notify_stat_changed(volume->ID(), inode->ParentID(), inode->ID(), B_STAT_SIZE);
}
}
fileCacheEnabler.Detach();
@@ -1164,7 +1164,10 @@ ext2_open(fs_volume* _volume, fs_vnode* _node, int openMode, void** _cookie)
if (status != B_OK)
return status;
// TODO: No need to notify file size changed?
if (cookie->last_size != 0) {
cookie->last_size = inode->Size();
notify_stat_changed(volume->ID(), -1, inode->ID(), B_STAT_SIZE);
}
}
fileCacheEnabler.Detach();
@@ -2207,6 +2207,11 @@ dosfs_open(fs_volume* volume, fs_vnode* vnode, int openMode, void** _cookie)
status = file_cache_set_size(bsdNode->v_cache, 0);
if (status != B_OK)
RETURN_ERROR(status);
if (cookie->fLastSize != 0) {
cookie->fLastSize = fatNode->de_FileSize;
notify_stat_changed(volume->id, bsdNode->v_parent, fatNode->de_inode, B_STAT_SIZE);
}
}
cookieDeleter.Detach();
@@ -582,9 +582,11 @@ OverlayInode::Open(int openMode, void **_cookie)
*_cookie = cookie;
if (fIsVirtual) {
if (openMode & O_TRUNC) {
if ((openMode & O_TRUNC) && fStat.st_size != 0) {
fStat.st_size = 0;
_TrimBuffers();
notify_stat_changed(SuperVolume()->id, -1, fInodeNumber, B_STAT_SIZE);
}
return B_OK;
@@ -600,6 +602,8 @@ OverlayInode::Open(int openMode, void **_cookie)
_TrimBuffers();
if (!fIsDataModified)
SetDataModified();
notify_stat_changed(SuperVolume()->id, -1, fInodeNumber, B_STAT_SIZE);
}
}
@@ -831,6 +831,8 @@ fs_open(fs_volume* _volume, fs_vnode* _node, int openMode, void** _cookie)
ObjectDeleter<file_cookie> cookieDeleter(cookie);
cookie->open_mode = openMode;
cookie->last_size = node->size;
cookie->last_notification = system_time();
// We don't actually support uncached mode; it would require us to handle
// passing user buffers to libntfs, among other things.
@@ -858,6 +860,11 @@ fs_open(fs_volume* _volume, fs_vnode* _node, int openMode, void** _cookie)
return errno;
node->size = na->data_size;
file_cache_set_size(node->file_cache, node->size);
if (cookie->last_size != 0) {
cookie->last_size = node->size;
notify_stat_changed(_volume->id, node->parent_inode, node->inode, B_STAT_SIZE);
}
}
cookieDeleter.Detach();