github.com/metacubex/gvisor@v0.0.0-20240320004321-933faba989ec/pkg/sentry/fsimpl/gofer/time.go (about) 1 // Copyright 2019 The gVisor Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package gofer 16 17 import ( 18 "golang.org/x/sys/unix" 19 "github.com/metacubex/gvisor/pkg/abi/linux" 20 "github.com/metacubex/gvisor/pkg/sentry/vfs" 21 ) 22 23 func dentryTimestamp(t linux.StatxTimestamp) int64 { 24 return t.ToNsec() 25 } 26 27 func dentryTimestampFromUnix(t unix.Timespec) int64 { 28 return dentryTimestamp(linux.StatxTimestamp{Sec: t.Sec, Nsec: uint32(t.Nsec)}) 29 } 30 31 // Preconditions: d.cachedMetadataAuthoritative() == true. 32 func (d *dentry) touchAtime(mnt *vfs.Mount) { 33 if opts := mnt.Options(); opts.Flags.NoATime || opts.ReadOnly { 34 return 35 } 36 if err := mnt.CheckBeginWrite(); err != nil { 37 return 38 } 39 now := d.fs.clock.Now().Nanoseconds() 40 d.metadataMu.Lock() 41 d.atime.Store(now) 42 d.atimeDirty.Store(1) 43 d.metadataMu.Unlock() 44 mnt.EndWrite() 45 } 46 47 // Preconditions: d.metadataMu is locked. d.cachedMetadataAuthoritative() == true. 48 func (d *dentry) touchAtimeLocked(mnt *vfs.Mount) { 49 if opts := mnt.Options(); opts.Flags.NoATime || opts.ReadOnly { 50 return 51 } 52 if err := mnt.CheckBeginWrite(); err != nil { 53 return 54 } 55 now := d.fs.clock.Now().Nanoseconds() 56 d.atime.Store(now) 57 d.atimeDirty.Store(1) 58 mnt.EndWrite() 59 } 60 61 // Preconditions: 62 // - d.cachedMetadataAuthoritative() == true. 63 // - The caller has successfully called vfs.Mount.CheckBeginWrite(). 64 func (d *dentry) touchCtime() { 65 now := d.fs.clock.Now().Nanoseconds() 66 d.metadataMu.Lock() 67 d.ctime.Store(now) 68 d.metadataMu.Unlock() 69 } 70 71 // Preconditions: 72 // - d.cachedMetadataAuthoritative() == true. 73 // - The caller has successfully called vfs.Mount.CheckBeginWrite(). 74 func (d *dentry) touchCMtime() { 75 now := d.fs.clock.Now().Nanoseconds() 76 d.metadataMu.Lock() 77 d.mtime.Store(now) 78 d.ctime.Store(now) 79 d.mtimeDirty.Store(1) 80 d.metadataMu.Unlock() 81 } 82 83 // Preconditions: 84 // - d.cachedMetadataAuthoritative() == true. 85 // - The caller has locked d.metadataMu. 86 func (d *dentry) touchCMtimeLocked() { 87 now := d.fs.clock.Now().Nanoseconds() 88 d.mtime.Store(now) 89 d.ctime.Store(now) 90 d.mtimeDirty.Store(1) 91 }