s3: Make some arguments to (parse|unparse)_share_modes() const
[samba.git] / source3 / locking / locking.c
index e9a5f757e517f20b65e47ca50812c20f7d7041e3..cf6e02f24855ceb800e5a3b0648013ef23055842 100644 (file)
@@ -75,69 +75,89 @@ const char *lock_flav_name(enum brl_flavour lock_flav)
  Called in the read/write codepath.
 ****************************************************************************/
 
-bool is_locked(files_struct *fsp,
-               uint32 smbpid,
-               uint64_t count,
-               uint64_t offset, 
-               enum brl_type lock_type)
+void init_strict_lock_struct(files_struct *fsp,
+                               uint32 smbpid,
+                               br_off start,
+                               br_off size,
+                               enum brl_type lock_type,
+                               struct lock_struct *plock)
+{
+       SMB_ASSERT(lock_type == READ_LOCK || lock_type == WRITE_LOCK);
+
+       plock->context.smbpid = smbpid;
+        plock->context.tid = fsp->conn->cnum;
+        plock->context.pid = procid_self();
+        plock->start = start;
+        plock->size = size;
+        plock->fnum = fsp->fnum;
+        plock->lock_type = lock_type;
+        plock->lock_flav = lp_posix_cifsu_locktype(fsp);
+}
+
+bool strict_lock_default(files_struct *fsp, struct lock_struct *plock)
 {
        int strict_locking = lp_strict_locking(fsp->conn->params);
-       enum brl_flavour lock_flav = lp_posix_cifsu_locktype(fsp);
-       bool ret = True;
-       
-       if (count == 0) {
-               return False;
+       bool ret = False;
+
+       if (plock->size == 0) {
+               return True;
        }
 
        if (!lp_locking(fsp->conn->params) || !strict_locking) {
-               return False;
+               return True;
        }
 
        if (strict_locking == Auto) {
-               if  (EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type) && (lock_type == READ_LOCK || lock_type == WRITE_LOCK)) {
+               if  (EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type) && (plock->lock_type == READ_LOCK || plock->lock_type == WRITE_LOCK)) {
                        DEBUG(10,("is_locked: optimisation - exclusive oplock on file %s\n", fsp->fsp_name ));
-                       ret = False;
+                       ret = True;
                } else if ((fsp->oplock_type == LEVEL_II_OPLOCK) &&
-                          (lock_type == READ_LOCK)) {
+                          (plock->lock_type == READ_LOCK)) {
                        DEBUG(10,("is_locked: optimisation - level II oplock on file %s\n", fsp->fsp_name ));
-                       ret = False;
+                       ret = True;
                } else {
                        struct byte_range_lock *br_lck = brl_get_locks_readonly(talloc_tos(), fsp);
                        if (!br_lck) {
-                               return False;
+                               return True;
                        }
-                       ret = !brl_locktest(br_lck,
-                                       smbpid,
-                                       procid_self(),
-                                       offset,
-                                       count,
-                                       lock_type,
-                                       lock_flav);
+                       ret = brl_locktest(br_lck,
+                                       plock->context.smbpid,
+                                       plock->context.pid,
+                                       plock->start,
+                                       plock->size,
+                                       plock->lock_type,
+                                       plock->lock_flav);
                        TALLOC_FREE(br_lck);
                }
        } else {
                struct byte_range_lock *br_lck = brl_get_locks_readonly(talloc_tos(), fsp);
                if (!br_lck) {
-                       return False;
+                       return True;
                }
-               ret = !brl_locktest(br_lck,
-                               smbpid,
-                               procid_self(),
-                               offset,
-                               count,
-                               lock_type,
-                               lock_flav);
+               ret = brl_locktest(br_lck,
+                               plock->context.smbpid,
+                               plock->context.pid,
+                               plock->start,
+                               plock->size,
+                               plock->lock_type,
+                               plock->lock_flav);
                TALLOC_FREE(br_lck);
        }
 
-       DEBUG(10,("is_locked: flavour = %s brl start=%.0f len=%.0f %s for fnum %d file %s\n",
-                       lock_flav_name(lock_flav),
-                       (double)offset, (double)count, ret ? "locked" : "unlocked",
-                       fsp->fnum, fsp->fsp_name ));
+       DEBUG(10,("strict_lock_default: flavour = %s brl start=%.0f "
+                       "len=%.0f %s for fnum %d file %s\n",
+                       lock_flav_name(plock->lock_flav),
+                       (double)plock->start, (double)plock->size,
+                       ret ? "unlocked" : "locked",
+                       plock->fnum, fsp->fsp_name ));
 
        return ret;
 }
 
+void strict_unlock_default(files_struct *fsp, struct lock_struct *plock)
+{
+}
+
 /****************************************************************************
  Find out if a lock could be granted - return who is blocking us if we can't.
 ****************************************************************************/
@@ -504,7 +524,7 @@ static void print_share_mode_table(struct locking_data *data)
  Get all share mode entries for a dev/inode pair.
 ********************************************************************/
 
-static bool parse_share_modes(TDB_DATA dbuf, struct share_mode_lock *lck)
+static bool parse_share_modes(const TDB_DATA dbuf, struct share_mode_lock *lck)
 {
        struct locking_data data;
        int i;
@@ -639,7 +659,7 @@ static bool parse_share_modes(TDB_DATA dbuf, struct share_mode_lock *lck)
        return True;
 }
 
-static TDB_DATA unparse_share_modes(struct share_mode_lock *lck)
+static TDB_DATA unparse_share_modes(const struct share_mode_lock *lck)
 {
        TDB_DATA result;
        int num_valid = 0;
@@ -867,7 +887,8 @@ struct share_mode_lock *fetch_share_mode_unlocked(TALLOC_CTX *mem_ctx,
        }
 
        if (!fill_share_mode_lock(lck, id, servicepath, fname, data, NULL)) {
-               DEBUG(3, ("fill_share_mode_lock failed\n"));
+               DEBUG(10, ("fetch_share_mode_unlocked: no share_mode record "
+                          "around (file not open)\n"));
                TALLOC_FREE(lck);
                return NULL;
        }
@@ -1376,11 +1397,11 @@ bool set_delete_on_close(files_struct *fsp, bool delete_on_close, const UNIX_USE
 
        if (fsp->conn->admin_user) {
                tok_copy = copy_unix_token(lck, tok);
-               tok_copy->uid = (uid_t)0;
                if (tok_copy == NULL) {
                        TALLOC_FREE(lck);
                        return false;
                }
+               tok_copy->uid = (uid_t)0;
                tok = tok_copy;
        }