BPicture: Fix archive constructor.
[haiku.git] / src / add-ons / kernel / file_systems / nfs4 / MetadataCache.h
blob82e44c6496005baa50247a420f1e5c493207bbe2
1 /*
2 * Copyright 2012 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Paweł Dziepak, pdziepak@quarnos.org
7 */
8 #ifndef METADATACACHE_H
9 #define METADATACACHE_H
12 #include <fs_interface.h>
13 #include <lock.h>
14 #include <SupportDefs.h>
15 #include <util/AutoLock.h>
16 #include <util/AVLTreeMap.h>
19 class Inode;
21 struct AccessEntry {
22 time_t fExpire;
23 bool fForceValid;
25 uint32 fAllowed;
28 class MetadataCache {
29 public:
30 MetadataCache(Inode* inode);
31 ~MetadataCache();
33 status_t GetStat(struct stat* st);
34 void SetStat(const struct stat& st);
35 void GrowFile(size_t newSize);
37 status_t GetAccess(uid_t uid, uint32* allowed);
38 void SetAccess(uid_t uid, uint32 allowed);
40 status_t LockValid();
41 void UnlockValid();
43 inline void InvalidateStat();
44 inline void InvalidateAccess();
46 inline void Invalidate();
48 static const time_t kExpirationTime = 60;
50 protected:
51 void NotifyChanges(const struct stat* oldStat,
52 const struct stat* newStat);
54 private:
55 struct stat fStatCache;
56 time_t fExpire;
57 bool fForceValid;
59 Inode* fInode;
60 bool fInited;
62 AVLTreeMap<uid_t, AccessEntry> fAccessCache;
64 mutex fLock;
68 inline void
69 MetadataCache::InvalidateStat()
71 MutexLocker _(fLock);
72 if (!fForceValid)
73 fExpire = 0;
77 inline void
78 MetadataCache::InvalidateAccess()
80 MutexLocker _(fLock);
81 if (!fForceValid)
82 fAccessCache.MakeEmpty();
86 inline void
87 MetadataCache::Invalidate()
89 InvalidateStat();
90 InvalidateAccess();
94 #endif // METADATACACHE_H