diff options
author | Volker Lendecke <vl@samba.org> | 2019-08-16 15:56:23 +0200 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2019-09-17 22:49:37 +0000 |
commit | 18c8b46e8176ea56f24a853d1f6c5ca484df7d81 (patch) | |
tree | ee40739cba878aa6e2acc41c29defdf83d0083b4 /source3/locking | |
parent | 434028518403e7e1d216a4acb9b229caccc44149 (diff) | |
download | samba-18c8b46e8176ea56f24a853d1f6c5ca484df7d81.tar.gz |
smbd: Use share_mode_forall_entries() in file_has_open_streams()
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'source3/locking')
-rw-r--r-- | source3/locking/locking.c | 51 |
1 files changed, 33 insertions, 18 deletions
diff --git a/source3/locking/locking.c b/source3/locking/locking.c index 58546538500..f26f5821a5e 100644 --- a/source3/locking/locking.c +++ b/source3/locking/locking.c @@ -1269,35 +1269,50 @@ struct timespec get_share_mode_write_time(struct share_mode_lock *lck) return d->old_write_time; } +struct file_has_open_streams_state { + bool found_one; +}; + +static bool file_has_open_streams_fn( + struct share_mode_entry *e, + bool *modified, + void *private_data) +{ + struct file_has_open_streams_state *state = private_data; + + if ((e->private_options & + NTCREATEX_OPTIONS_PRIVATE_STREAM_BASEOPEN) == 0) { + return false; + } + + if (share_entry_stale_pid(e)) { + return false; + } + + state->found_one = true; + return true; +} + bool file_has_open_streams(files_struct *fsp) { + struct file_has_open_streams_state state = { .found_one = false }; struct share_mode_lock *lock = NULL; - struct share_mode_data *d = NULL; - uint32_t i; + bool ok; 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; - } + ok = share_mode_forall_entries( + lock, file_has_open_streams_fn, &state); + TALLOC_FREE(lock); - if (e->private_options & - NTCREATEX_OPTIONS_PRIVATE_STREAM_BASEOPEN) - { - TALLOC_FREE(lock); - return true; - } + if (!ok) { + DBG_DEBUG("share_mode_forall_entries failed\n"); + return false; } - - TALLOC_FREE(lock); - return false; + return state.found_one; } bool share_mode_forall_entries( |