BPicture: Fix archive constructor.
[haiku.git] / src / add-ons / kernel / file_systems / nfs4 / Cookie.cpp
blob0275fd41e50ebf93d95c3588ab2fac1cef1e6518
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 */
10 #include "Cookie.h"
12 #include "Inode.h"
13 #include "Request.h"
16 LockOwner::LockOwner(uint32 owner)
18 fSequence(0),
19 fOwner(owner),
20 fUseCount(0),
21 fNext(NULL),
22 fPrev(NULL)
24 memset(fStateId, 0, sizeof(fStateId));
25 mutex_init(&fLock, NULL);
29 LockOwner::~LockOwner()
31 mutex_destroy(&fLock);
35 LockInfo::LockInfo(LockOwner* owner)
37 fOwner(owner)
39 ASSERT(owner != NULL);
40 fOwner->fUseCount++;
44 LockInfo::~LockInfo()
46 fOwner->fUseCount--;
50 bool
51 LockInfo::operator==(const struct flock& lock) const
53 bool eof = lock.l_len + lock.l_start == OFF_MAX;
54 uint64 start = static_cast<uint64>(lock.l_start);
55 uint64 length = static_cast<uint64>(lock.l_len);
57 return fStart == start && (fLength == length
58 || (eof && fLength == UINT64_MAX));
62 bool
63 LockInfo::operator==(const LockInfo& lock) const
65 return fOwner == lock.fOwner && fStart == lock.fStart
66 && fLength == lock.fLength && fType == lock.fType;
70 Cookie::Cookie(FileSystem* fileSystem)
72 fFileSystem(fileSystem),
73 fRequests(NULL),
74 fSnoozeCancel(create_sem(1, NULL))
76 acquire_sem(fSnoozeCancel);
77 mutex_init(&fRequestLock, NULL);
81 Cookie::~Cookie()
83 delete_sem(fSnoozeCancel);
84 mutex_destroy(&fRequestLock);
88 status_t
89 Cookie::RegisterRequest(RPC::Request* request)
91 ASSERT(request != NULL);
93 RequestEntry* entry = new RequestEntry;
94 if (entry == NULL)
95 return B_NO_MEMORY;
97 MutexLocker _(fRequestLock);
98 entry->fRequest = request;
99 entry->fNext = fRequests;
100 fRequests = entry;
102 return B_OK;
106 status_t
107 Cookie::UnregisterRequest(RPC::Request* request)
109 ASSERT(request != NULL);
111 MutexLocker _(fRequestLock);
112 RequestEntry* entry = fRequests;
113 RequestEntry* previous = NULL;
114 while (entry != NULL) {
115 if (entry->fRequest == request) {
116 if (previous == NULL)
117 fRequests = entry->fNext;
118 else
119 previous->fNext = entry->fNext;
120 delete entry;
121 break;
124 previous = entry;
125 entry = entry->fNext;
128 return B_OK;
132 status_t
133 Cookie::CancelAll()
135 release_sem(fSnoozeCancel);
137 MutexLocker _(fRequestLock);
138 RequestEntry* entry = fRequests;
139 while (entry != NULL) {
140 fFileSystem->Server()->WakeCall(entry->fRequest);
141 entry = entry->fNext;
144 return B_OK;
148 OpenStateCookie::OpenStateCookie(FileSystem* fileSystem)
150 Cookie(fileSystem)
155 OpenFileCookie::OpenFileCookie(FileSystem* fileSystem)
157 OpenStateCookie(fileSystem),
158 fLocks(NULL)
163 void
164 OpenFileCookie::AddLock(LockInfo* lock)
166 ASSERT(lock != NULL);
168 lock->fCookieNext = fLocks;
169 fLocks = lock;
173 void
174 OpenFileCookie::RemoveLock(LockInfo* lock, LockInfo* previous)
176 if (previous != NULL)
177 previous->fCookieNext = lock->fCookieNext;
178 else {
179 ASSERT(previous == NULL && fLocks == lock);
180 fLocks = lock->fCookieNext;
185 OpenDirCookie::OpenDirCookie(FileSystem* fileSystem)
187 Cookie(fileSystem),
188 fSnapshot(NULL)
193 OpenDirCookie::~OpenDirCookie()
195 if (fSnapshot != NULL)
196 fSnapshot->ReleaseReference();
200 OpenAttrCookie::OpenAttrCookie(FileSystem* fileSystem)
202 OpenStateCookie(fileSystem)