s3: [3/3]: Fix a delete on close divergence from windows and the associated torture...
[kai/samba.git] / source3 / locking / locking.c
index ca61a886a60489de450d3a520b5f527f7565d0a1..a70f9d20feb69d7921f1ec418e8bf8241aaaed07 100644 (file)
@@ -77,8 +77,8 @@ const char *lock_flav_name(enum brl_flavour lock_flav)
 
 bool is_locked(files_struct *fsp,
                uint32 smbpid,
-               SMB_BIG_UINT count,
-               SMB_BIG_UINT offset, 
+               uint64_t count,
+               uint64_t offset, 
                enum brl_type lock_type)
 {
        int strict_locking = lp_strict_locking(fsp->conn->params);
@@ -144,8 +144,8 @@ bool is_locked(files_struct *fsp,
 
 NTSTATUS query_lock(files_struct *fsp,
                        uint32 *psmbpid,
-                       SMB_BIG_UINT *pcount,
-                       SMB_BIG_UINT *poffset,
+                       uint64_t *pcount,
+                       uint64_t *poffset,
                        enum brl_type *plock_type,
                        enum brl_flavour lock_flav)
 {
@@ -184,8 +184,8 @@ NTSTATUS query_lock(files_struct *fsp,
 struct byte_range_lock *do_lock(struct messaging_context *msg_ctx,
                        files_struct *fsp,
                        uint32 lock_pid,
-                       SMB_BIG_UINT count,
-                       SMB_BIG_UINT offset,
+                       uint64_t count,
+                       uint64_t offset,
                        enum brl_type lock_type,
                        enum brl_flavour lock_flav,
                        bool blocking_lock,
@@ -251,8 +251,8 @@ struct byte_range_lock *do_lock(struct messaging_context *msg_ctx,
 NTSTATUS do_unlock(struct messaging_context *msg_ctx,
                        files_struct *fsp,
                        uint32 lock_pid,
-                       SMB_BIG_UINT count,
-                       SMB_BIG_UINT offset,
+                       uint64_t count,
+                       uint64_t offset,
                        enum brl_flavour lock_flav)
 {
        bool ok = False;
@@ -304,8 +304,8 @@ NTSTATUS do_unlock(struct messaging_context *msg_ctx,
 
 NTSTATUS do_lock_cancel(files_struct *fsp,
                        uint32 lock_pid,
-                       SMB_BIG_UINT count,
-                       SMB_BIG_UINT offset,
+                       uint64_t count,
+                       uint64_t offset,
                        enum brl_flavour lock_flav)
 {
        bool ok = False;
@@ -1067,13 +1067,10 @@ static void add_share_mode_entry(struct share_mode_lock *lck,
 }
 
 void set_share_mode(struct share_mode_lock *lck, files_struct *fsp,
-                       uid_t uid, uint16 mid, uint16 op_type, bool initial_delete_on_close_allowed)
+                   uid_t uid, uint16 mid, uint16 op_type)
 {
        struct share_mode_entry entry;
        fill_share_mode_entry(&entry, fsp, uid, mid, op_type);
-       if (initial_delete_on_close_allowed) {
-               entry.flags |= SHARE_MODE_ALLOW_INITIAL_DELETE_ON_CLOSE;
-       }
        add_share_mode_entry(lck, &entry);
 }
 
@@ -1271,22 +1268,6 @@ NTSTATUS can_set_delete_on_close(files_struct *fsp, bool delete_on_close,
        return NT_STATUS_OK;
 }
 
-/****************************************************************************
- Do we have an open file handle that created this entry ?
-****************************************************************************/
-
-bool can_set_initial_delete_on_close(const struct share_mode_lock *lck)
-{
-       int i;
-
-       for (i=0; i<lck->num_share_modes; i++) {
-               if (lck->share_modes[i].flags & SHARE_MODE_ALLOW_INITIAL_DELETE_ON_CLOSE) {
-                       return True;
-               }
-       }
-       return False;
-}
-
 /*************************************************************************
  Return a talloced copy of a UNIX_USER_TOKEN. NULL on fail.
  (Should this be in locking.c.... ?).
@@ -1380,55 +1361,53 @@ bool set_delete_on_close(files_struct *fsp, bool delete_on_close, UNIX_USER_TOKE
        return True;
 }
 
-/****************************************************************************
- Sets the allow initial delete on close flag for this share mode.
-****************************************************************************/
-
-bool set_allow_initial_delete_on_close(struct share_mode_lock *lck, files_struct *fsp, bool delete_on_close)
+bool set_sticky_write_time(struct file_id fileid, struct timespec write_time)
 {
-       struct share_mode_entry entry, *e;
+       struct share_mode_lock *lck;
 
-       /* Don't care about the pid owner being correct here - just a search. */
-       fill_share_mode_entry(&entry, fsp, (uid_t)-1, 0, NO_OPLOCK);
+       DEBUG(5,("set_sticky_write_time: %s id=%s\n",
+                timestring(debug_ctx(),
+                           convert_timespec_to_time_t(write_time)),
+                file_id_string_tos(&fileid)));
 
-       e = find_share_mode_entry(lck, &entry);
-       if (e == NULL) {
+       lck = get_share_mode_lock(NULL, fileid, NULL, NULL, NULL);
+       if (lck == NULL) {
                return False;
        }
 
-       if (delete_on_close) {
-               e->flags |= SHARE_MODE_ALLOW_INITIAL_DELETE_ON_CLOSE;
-       } else {
-               e->flags &= ~SHARE_MODE_ALLOW_INITIAL_DELETE_ON_CLOSE;
+       if (timespec_compare(&lck->changed_write_time, &write_time) != 0) {
+               lck->modified = True;
+               lck->changed_write_time = write_time;
        }
-       lck->modified = True;
+
+       TALLOC_FREE(lck);
        return True;
 }
 
-bool set_write_time(struct file_id fileid, struct timespec write_time,
-                   bool overwrite)
+bool set_write_time(struct file_id fileid, struct timespec write_time)
 {
        struct share_mode_lock *lck;
 
-       DEBUG(5,("set_write_time: %s overwrite=%d id=%s\n",
+       DEBUG(5,("set_write_time: %s id=%s\n",
                 timestring(debug_ctx(),
                            convert_timespec_to_time_t(write_time)),
-                overwrite, file_id_string_tos(&fileid)));
+                file_id_string_tos(&fileid)));
 
        lck = get_share_mode_lock(NULL, fileid, NULL, NULL, NULL);
        if (lck == NULL) {
                return False;
        }
 
-       if (overwrite || null_timespec(lck->changed_write_time)) {
+       if (timespec_compare(&lck->old_write_time, &write_time) != 0) {
                lck->modified = True;
-               lck->changed_write_time = write_time;
+               lck->old_write_time = write_time;
        }
 
        TALLOC_FREE(lck);
        return True;
 }
 
+
 struct forall_state {
        void (*fn)(const struct share_mode_entry *entry,
                   const char *sharepath,