s3:locking: add file_has_open_streams()
authorRalph Boehme <slow@samba.org>
Sun, 27 May 2018 11:03:25 +0000 (13:03 +0200)
committerJeremy Allison <jra@samba.org>
Wed, 30 May 2018 17:10:26 +0000 (19:10 +0200)
This can be used to check if a file opened by fsp also has stream opens.

Bug: https://bugzilla.samba.org/show_bug.cgi?id=13451

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/locking/locking.c
source3/locking/proto.h

index 791878c6383a63cda05e1db9c8e2ca451d7f61fb..e962fee89abe32e34c87ff16f4887fe8c1f8b99c 100644 (file)
@@ -1316,3 +1316,34 @@ struct timespec get_share_mode_write_time(struct share_mode_lock *lck)
        }
        return d->old_write_time;
 }
+
+bool file_has_open_streams(files_struct *fsp)
+{
+       struct share_mode_lock *lock = NULL;
+       struct share_mode_data *d = NULL;
+       uint32_t i;
+
+       lock = get_existing_share_mode_lock(talloc_tos(), fsp->file_id);
+       if (lock == NULL) {
+               return false;
+       }
+       d = lock->data;
+
+       for (i = 0; i < d->num_share_modes; i++) {
+               struct share_mode_entry *e = &d->share_modes[i];
+
+               if (share_mode_stale_pid(d, i)) {
+                       continue;
+               }
+
+               if (e->private_options &
+                   NTCREATEX_OPTIONS_PRIVATE_STREAM_BASEOPEN)
+               {
+                       TALLOC_FREE(lock);
+                       return true;
+               }
+       }
+
+       TALLOC_FREE(lock);
+       return false;
+}
index afd5373772acecec454d045eb313d842b56ccf02..403729c934a5f887c58ca5bde486c6e52a0399a2 100644 (file)
@@ -207,6 +207,7 @@ bool is_delete_on_close_set(struct share_mode_lock *lck, uint32_t name_hash);
 bool set_sticky_write_time(struct file_id fileid, struct timespec write_time);
 bool set_write_time(struct file_id fileid, struct timespec write_time);
 struct timespec get_share_mode_write_time(struct share_mode_lock *lck);
+bool file_has_open_streams(files_struct *fsp);
 int share_mode_forall(int (*fn)(struct file_id fid,
                                const struct share_mode_data *data,
                                void *private_data),