mirror of
https://github.com/RGBCube/serenity
synced 2025-05-20 18:15:07 +00:00
Kernel: Update atime/ctime/mtime timestamps atomically
Instead of having three separate APIs (one for each timestamp), there's now only Inode::update_timestamps() and it takes 3x optional timestamps. The non-empty timestamps are updated while holding the inode mutex, and the outside world no longer has to look at intermediate timestamp states.
This commit is contained in:
parent
35b2e9c663
commit
280694bb46
18 changed files with 34 additions and 109 deletions
|
@ -213,8 +213,7 @@ ErrorOr<void> VirtualFileSystem::utime(Credentials const& credentials, StringVie
|
|||
if (custody->is_readonly())
|
||||
return EROFS;
|
||||
|
||||
TRY(inode.set_atime(atime));
|
||||
TRY(inode.set_mtime(mtime));
|
||||
TRY(inode.update_timestamps(atime, {}, mtime));
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -228,10 +227,10 @@ ErrorOr<void> VirtualFileSystem::utimensat(Credentials const& credentials, Strin
|
|||
return EROFS;
|
||||
|
||||
// NOTE: A standard ext2 inode cannot store nanosecond timestamps.
|
||||
if (atime.tv_nsec != UTIME_OMIT)
|
||||
TRY(inode.set_atime(atime.tv_sec));
|
||||
if (mtime.tv_nsec != UTIME_OMIT)
|
||||
TRY(inode.set_mtime(mtime.tv_sec));
|
||||
TRY(inode.update_timestamps(
|
||||
(atime.tv_nsec != UTIME_OMIT) ? atime.tv_nsec : Optional<time_t> {},
|
||||
{},
|
||||
(mtime.tv_nsec != UTIME_OMIT) ? mtime.tv_nsec : Optional<time_t> {}));
|
||||
|
||||
return {};
|
||||
}
|
||||
|
@ -321,7 +320,7 @@ ErrorOr<NonnullLockRefPtr<OpenFileDescription>> VirtualFileSystem::open(Credenti
|
|||
|
||||
if (should_truncate_file) {
|
||||
TRY(inode.truncate(0));
|
||||
TRY(inode.set_mtime(kgettimeofday().to_truncated_seconds()));
|
||||
TRY(inode.update_timestamps({}, {}, kgettimeofday().to_truncated_seconds()));
|
||||
}
|
||||
auto description = TRY(OpenFileDescription::try_create(custody));
|
||||
description->set_rw_mode(options);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue