github.com/SagerNet/gvisor@v0.0.0-20210707092255-7731c139d75c/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 "sync/atomic" 19 20 "github.com/SagerNet/gvisor/pkg/sentry/vfs" 21 ) 22 23 func dentryTimestampFromP9(s, ns uint64) int64 { 24 return int64(s*1e9 + ns) 25 } 26 27 // Preconditions: d.cachedMetadataAuthoritative() == true. 28 func (d *dentry) touchAtime(mnt *vfs.Mount) { 29 if mnt.Flags.NoATime || mnt.ReadOnly() { 30 return 31 } 32 if err := mnt.CheckBeginWrite(); err != nil { 33 return 34 } 35 now := d.fs.clock.Now().Nanoseconds() 36 d.metadataMu.Lock() 37 atomic.StoreInt64(&d.atime, now) 38 atomic.StoreUint32(&d.atimeDirty, 1) 39 d.metadataMu.Unlock() 40 mnt.EndWrite() 41 } 42 43 // Preconditions: d.metadataMu is locked. d.cachedMetadataAuthoritative() == true. 44 func (d *dentry) touchAtimeLocked(mnt *vfs.Mount) { 45 if mnt.Flags.NoATime || mnt.ReadOnly() { 46 return 47 } 48 if err := mnt.CheckBeginWrite(); err != nil { 49 return 50 } 51 now := d.fs.clock.Now().Nanoseconds() 52 atomic.StoreInt64(&d.atime, now) 53 atomic.StoreUint32(&d.atimeDirty, 1) 54 mnt.EndWrite() 55 } 56 57 // Preconditions: 58 // * d.cachedMetadataAuthoritative() == true. 59 // * The caller has successfully called vfs.Mount.CheckBeginWrite(). 60 func (d *dentry) touchCtime() { 61 now := d.fs.clock.Now().Nanoseconds() 62 d.metadataMu.Lock() 63 atomic.StoreInt64(&d.ctime, now) 64 d.metadataMu.Unlock() 65 } 66 67 // Preconditions: 68 // * d.cachedMetadataAuthoritative() == true. 69 // * The caller has successfully called vfs.Mount.CheckBeginWrite(). 70 func (d *dentry) touchCMtime() { 71 now := d.fs.clock.Now().Nanoseconds() 72 d.metadataMu.Lock() 73 atomic.StoreInt64(&d.mtime, now) 74 atomic.StoreInt64(&d.ctime, now) 75 atomic.StoreUint32(&d.mtimeDirty, 1) 76 d.metadataMu.Unlock() 77 } 78 79 // Preconditions: 80 // * d.cachedMetadataAuthoritative() == true. 81 // * The caller has locked d.metadataMu. 82 func (d *dentry) touchCMtimeLocked() { 83 now := d.fs.clock.Now().Nanoseconds() 84 atomic.StoreInt64(&d.mtime, now) 85 atomic.StoreInt64(&d.ctime, now) 86 atomic.StoreUint32(&d.mtimeDirty, 1) 87 }