summaryrefslogtreecommitdiff
path: root/source3/locking/brlock.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2001-08-27 08:19:43 +0000
committerAndrew Tridgell <tridge@samba.org>2001-08-27 08:19:43 +0000
commite8e98c9ea0690e3acf1126b50882e59e1056c7b3 (patch)
tree2fa75bc825f7e5da041809fe49080e3319656506 /source3/locking/brlock.c
parent3820578473da81b7ae0dfa978605da809be59f62 (diff)
downloadsamba-e8e98c9ea0690e3acf1126b50882e59e1056c7b3.tar.gz
samba-e8e98c9ea0690e3acf1126b50882e59e1056c7b3.tar.bz2
samba-e8e98c9ea0690e3acf1126b50882e59e1056c7b3.zip
converted smbd to use NTSTATUS by default
major changes include: - added NSTATUS type - added automatic mapping between dos and nt error codes - changed all ERROR() calls to ERROR_DOS() and many to ERROR_NT() these calls auto-translate to the client error code system - got rid of the cached error code and the writebmpx code We eventually will need to also: - get rid of BOOL, so we don't lose error info - replace all ERROR_DOS() calls with ERROR_NT() calls but that is too much for one night (This used to be commit 83d9896c1ea8be796192b51a4678c2a3b87f7518)
Diffstat (limited to 'source3/locking/brlock.c')
-rw-r--r--source3/locking/brlock.c71
1 files changed, 60 insertions, 11 deletions
diff --git a/source3/locking/brlock.c b/source3/locking/brlock.c
index dc2f39e7d9..e21effe6eb 100644
--- a/source3/locking/brlock.c
+++ b/source3/locking/brlock.c
@@ -30,6 +30,8 @@
extern int DEBUGLEVEL;
+#define ZERO_ZERO 0
+
/* This contains elements that differentiate locks. The smbpid is a
client supplied pid, and is essentially the locking context for
this client */
@@ -116,6 +118,32 @@ static BOOL brl_conflict(struct lock_struct *lck1,
return True;
}
+#if ZERO_ZERO
+static BOOL brl_conflict1(struct lock_struct *lck1,
+ struct lock_struct *lck2)
+{
+ if (lck1->lock_type == READ_LOCK && lck2->lock_type == READ_LOCK) {
+ return False;
+ }
+
+ if (brl_same_context(&lck1->context, &lck2->context) &&
+ lck2->lock_type == READ_LOCK && lck1->fnum == lck2->fnum) {
+ return False;
+ }
+
+ if (lck2->start == 0 && lck2->size == 0 && lck1->size != 0) {
+ return True;
+ }
+
+ if (lck1->start >= (lck2->start + lck2->size) ||
+ lck2->start >= (lck1->start + lck1->size)) {
+ return False;
+ }
+
+ return True;
+}
+#endif
+
/****************************************************************************
Check to see if this lock conflicts, but ignore our own locks on the
same fnum only.
@@ -231,6 +259,21 @@ void brl_shutdown(int read_only)
tdb_close(tdb);
}
+#if ZERO_ZERO
+/****************************************************************************
+compare two locks for sorting
+****************************************************************************/
+static int lock_compare(struct lock_struct *lck1,
+ struct lock_struct *lck2)
+{
+ if (lck1->start != lck2->start) return (lck1->start - lck2->start);
+ if (lck2->size != lck1->size) {
+ return ((int)lck1->size - (int)lck2->size);
+ }
+ return 0;
+}
+#endif
+
/****************************************************************************
Lock a range of bytes.
****************************************************************************/
@@ -249,10 +292,10 @@ BOOL brl_lock(SMB_DEV_T dev, SMB_INO_T ino, int fnum,
dbuf.dptr = NULL;
-#if 0
+#if !ZERO_ZERO
if (start == 0 && size == 0) {
- tdb_delete(tdb, kbuf);
- return True;
+ DEBUG(0,("client sent 0/0 lock - please report this\n"));
+ return False;
}
#endif
@@ -275,23 +318,27 @@ BOOL brl_lock(SMB_DEV_T dev, SMB_INO_T ino, int fnum,
if (brl_conflict(&locks[i], &lock)) {
goto fail;
}
+#if ZERO_ZERO
+ if (lock.start == 0 && lock.size == 0 &&
+ locks[i].size == 0) {
+ break;
+ }
+#endif
}
}
-#if 0
- if (start == 0 && size == 0) {
- if (dbuf.dptr) free(dbuf.dptr);
- tdb_chainunlock(tdb, kbuf);
- return True;
- }
-#endif
-
/* no conflicts - add it to the list of locks */
tp = Realloc(dbuf.dptr, dbuf.dsize + sizeof(*locks));
if (!tp) goto fail;
else dbuf.dptr = tp;
memcpy(dbuf.dptr + dbuf.dsize, &lock, sizeof(lock));
dbuf.dsize += sizeof(lock);
+
+#if ZERO_ZERO
+ /* sort the lock list */
+ qsort(dbuf.dptr, dbuf.dsize/sizeof(lock), sizeof(lock), lock_compare);
+#endif
+
tdb_store(tdb, kbuf, dbuf, TDB_REPLACE);
free(dbuf.dptr);
@@ -337,6 +384,7 @@ BOOL brl_unlock(SMB_DEV_T dev, SMB_INO_T ino, int fnum,
locks = (struct lock_struct *)dbuf.dptr;
count = dbuf.dsize / sizeof(*locks);
+#if ZERO_ZERO
for (i=0; i<count; i++) {
struct lock_struct *lock = &locks[i];
@@ -362,6 +410,7 @@ BOOL brl_unlock(SMB_DEV_T dev, SMB_INO_T ino, int fnum,
return True;
}
}
+#endif
locks = (struct lock_struct *)dbuf.dptr;
count = dbuf.dsize / sizeof(*locks);