svn commit: samba r13822 - in trunk/source: include locking smbd
jra at samba.org
jra at samba.org
Fri Mar 3 19:43:58 GMT 2006
Author: jra
Date: 2006-03-03 19:43:57 +0000 (Fri, 03 Mar 2006)
New Revision: 13822
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=13822
Log:
Added external interface to posix lock/unlock.
No getlock yet. No blocking locks supported. Now
just need Stevef to get here to start testing...
Jeremy.
Modified:
trunk/source/include/trans2.h
trunk/source/locking/brlock.c
trunk/source/locking/locking.c
trunk/source/smbd/trans2.c
Changeset:
Modified: trunk/source/include/trans2.h
===================================================================
--- trunk/source/include/trans2.h 2006-03-03 19:39:59 UTC (rev 13821)
+++ trunk/source/include/trans2.h 2006-03-03 19:43:57 UTC (rev 13822)
@@ -576,4 +576,28 @@
#define SMB_POSIX_ACL_ENTRY_SIZE 10
#define SMB_POSIX_IGNORE_ACE_ENTRIES 0xFFFF
+
+/* Definition of SMB_SET_POSIX_LOCK */
+/*
+ [2 bytes] lock_type - 0 = Read, 1 = Write, 2 = Unlock
+ [2 bytes] lock_flags - 1 = Wait (only valid for setlock)
+ [4 bytes] pid = locking context.
+ [8 bytes] start = unsigned 64 bits.
+ [8 bytes] length = unsigned 64 bits.
+*/
+
+#define POSIX_LOCK_TYPE_OFFSET 0
+#define POSIX_LOCK_FLAGS_OFFSET 2
+#define POSIX_LOCK_PID_OFFSET 4
+#define POSIX_LOCK_START_OFFSET 8
+#define POSIX_LOCK_LEN_OFFSET 16
+#define POSIX_LOCK_DATA_SIZE 24
+
+#define POSIX_LOCK_FLAG_NOWAIT 0
+#define POSIX_LOCK_FLAG_WAIT 1
+
+#define POSIX_LOCK_TYPE_READ 0
+#define POSIX_LOCK_TYPE_WRITE 1
+#define POSIX_LOCK_TYPE_UNLOCK 2
+
#endif
Modified: trunk/source/locking/brlock.c
===================================================================
--- trunk/source/locking/brlock.c 2006-03-03 19:39:59 UTC (rev 13821)
+++ trunk/source/locking/brlock.c 2006-03-03 19:43:57 UTC (rev 13822)
@@ -170,7 +170,7 @@
}
/* One is read, the other write, context or fnum are different,
- do the overlap ? */
+ do they overlap ? */
return brl_overlap(lck1, lck2);
}
@@ -429,9 +429,9 @@
| plock | ex | - different lock types.
+---------------+-------+
OR....
- +---------------+-------+
+ +-----------------------+
| ex | - same lock type.
- +---------------+-------+
+ +-----------------------+
**********************************************/
if ( (ex->start >= plock->start) &&
@@ -474,9 +474,9 @@
+-------+---------------+
OR
- +-------+---------------+
+ +-----------------------+
| ex | - same lock type.
- +-------+---------------+
+ +-----------------------+
**********************************************/
Modified: trunk/source/locking/locking.c
===================================================================
--- trunk/source/locking/locking.c 2006-03-03 19:39:59 UTC (rev 13821)
+++ trunk/source/locking/locking.c 2006-03-03 19:43:57 UTC (rev 13822)
@@ -148,7 +148,7 @@
Utility function called by locking requests.
****************************************************************************/
-static NTSTATUS do_lock(files_struct *fsp,
+NTSTATUS do_lock(files_struct *fsp,
uint16 lock_pid,
SMB_BIG_UINT count,
SMB_BIG_UINT offset,
Modified: trunk/source/smbd/trans2.c
===================================================================
--- trunk/source/smbd/trans2.c 2006-03-03 19:39:59 UTC (rev 13821)
+++ trunk/source/smbd/trans2.c 2006-03-03 19:43:57 UTC (rev 13822)
@@ -4336,6 +4336,83 @@
}
#endif
+ case SMB_SET_POSIX_LOCK:
+ {
+ SMB_BIG_UINT count;
+ SMB_BIG_UINT offset;
+ uint16 lock_pid;
+ BOOL lock_blocking;
+ enum brl_type lock_type;
+ BOOL my_lock_ctx;
+
+ if (fsp == NULL || fsp->fh->fd == -1) {
+ return ERROR_NT(NT_STATUS_INVALID_HANDLE);
+ }
+
+ if (total_data < POSIX_LOCK_DATA_SIZE) {
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+ }
+
+ switch (SVAL(pdata, POSIX_LOCK_TYPE_OFFSET)) {
+ case POSIX_LOCK_TYPE_READ:
+ lock_type = READ_LOCK;
+ break;
+ case POSIX_LOCK_TYPE_WRITE:
+ lock_type = WRITE_LOCK;
+ break;
+ case POSIX_LOCK_TYPE_UNLOCK:
+ lock_type = UNLOCK_LOCK;
+ break;
+ default:
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+ }
+
+ if (SVAL(pdata,POSIX_LOCK_FLAGS_OFFSET) == POSIX_LOCK_FLAG_NOWAIT) {
+ lock_blocking = False;
+ } else if (SVAL(pdata,POSIX_LOCK_FLAGS_OFFSET) == POSIX_LOCK_FLAG_WAIT) {
+ lock_blocking = True;
+ } else {
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+ }
+
+ lock_pid = (uint16)IVAL(pdata, POSIX_LOCK_PID_OFFSET);
+#if defined(HAVE_LONGLONG)
+ offset = (((SMB_BIG_UINT) IVAL(pdata,(POSIX_LOCK_START_OFFSET+4))) << 32) |
+ ((SMB_BIG_UINT) IVAL(pdata,POSIX_LOCK_START_OFFSET));
+ count = (((SMB_BIG_UINT) IVAL(pdata,(POSIX_LOCK_LEN_OFFSET+4))) << 32) |
+ ((SMB_BIG_UINT) IVAL(pdata,POSIX_LOCK_LEN_OFFSET));
+#else /* HAVE_LONGLONG */
+ offset = (SMB_BIG_UINT)IVAL(pdata,POSIX_LOCK_START_OFFSET);
+ count = (SMB_BIG_UINT)IVAL(pdata,POSIX_LOCK_LEN_OFFSET);
+#endif /* HAVE_LONGLONG */
+
+ if (lock_type == UNLOCK_LOCK) {
+ status = do_unlock(fsp,
+ lock_pid,
+ count,
+ offset,
+ POSIX_LOCK);
+ } else {
+ status = do_lock(fsp,
+ lock_pid,
+ count,
+ offset,
+ lock_type,
+ POSIX_LOCK,
+ &my_lock_ctx);
+
+ /* TODO: Deal with rescheduling blocking lock fail here... */
+ }
+
+ if (!NT_STATUS_IS_OK(status)) {
+ return ERROR_NT(status);
+ }
+
+ SSVAL(params,0,0);
+ send_trans2_replies(outbuf, bufsize, params, 2, *ppdata, 0);
+ return(-1);
+ }
+
default:
return ERROR_DOS(ERRDOS,ERRunknownlevel);
}
More information about the samba-cvs
mailing list