struct byte_range_lock *do_lock(files_struct *fsp, uint32 lock_pid, SMB_BIG_UINT count, SMB_BIG_UINT offset, enum brl_type lock_type, enum brl_flavour lock_flav, BOOL blocking_lock, NTSTATUS *perr, uint32 *plock_pid) { struct byte_range_lock *br_lck = NULL; if (!fsp->can_lock) { *perr = fsp->is_directory ? NT_STATUS_INVALID_DEVICE_REQUEST : NT_STATUS_INVALID_HANDLE; return NULL; } if (!lp_locking(fsp->conn->params)) { *perr = NT_STATUS_OK; return NULL; } /* NOTE! 0 byte long ranges ARE allowed and should be stored */ DEBUG(10,("do_lock: lock flavour %s lock type %s start=%.0f len=%.0f requested for fnum %d file %s\n", lock_flav_name(lock_flav), lock_type_name(lock_type), (double)offset, (double)count, fsp->fnum, fsp->fsp_name )); br_lck = brl_get_locks(NULL, fsp); if (!br_lck) { *perr = NT_STATUS_NO_MEMORY; return NULL; } *perr = brl_lock(br_lck, lock_pid, procid_self(), offset, count, lock_type, lock_flav, blocking_lock, plock_pid); if (lock_flav == WINDOWS_LOCK && fsp->current_lock_count != NO_LOCKING_COUNT) { /* blocking ie. pending, locks also count here, * as this is an efficiency counter to avoid checking * the lock db. on close. JRA. */ fsp->current_lock_count++; } else { /* Notice that this has had a POSIX lock request. * We can't count locks after this so forget them. */ fsp->current_lock_count = NO_LOCKING_COUNT; } return br_lck; }
static NTSTATUS do_lock(files_struct *fsp,connection_struct *conn, uint16 lock_pid, SMB_BIG_UINT count,SMB_BIG_UINT offset,enum brl_type lock_type) { NTSTATUS status; if (!lp_locking(SNUM(conn))) return NT_STATUS_OK; /* NOTE! 0 byte long ranges ARE allowed and should be stored */ DEBUG(10,("do_lock: lock type %s start=%.0f len=%.0f requested for file %s\n", lock_type_name(lock_type), (double)offset, (double)count, fsp->fsp_name )); if (OPEN_FSP(fsp) && fsp->can_lock && (fsp->conn == conn)) { status = brl_lock(fsp->dev, fsp->inode, fsp->fnum, lock_pid, sys_getpid(), conn->cnum, offset, count, lock_type); if (NT_STATUS_IS_OK(status) && lp_posix_locking(SNUM(conn))) { /* * Try and get a POSIX lock on this range. * Note that this is ok if it is a read lock * overlapping on a different fd. JRA. */ if (!set_posix_lock(fsp, offset, count, lock_type)) { status = NT_STATUS_LOCK_NOT_GRANTED; /* * We failed to map - we must now remove the brl * lock entry. */ (void)brl_unlock(fsp->dev, fsp->inode, fsp->fnum, lock_pid, sys_getpid(), conn->cnum, offset, count, False); } } } return status; }
NTSTATUS do_lock(files_struct *fsp, uint16 lock_pid, SMB_BIG_UINT count, SMB_BIG_UINT offset, enum brl_type lock_type, enum brl_flavour lock_flav, BOOL *my_lock_ctx) { struct byte_range_lock *br_lck = NULL; NTSTATUS status = NT_STATUS_LOCK_NOT_GRANTED; if (!OPEN_FSP(fsp) || !fsp->can_lock) { return NT_STATUS_INVALID_HANDLE; } if (!lp_locking(SNUM(fsp->conn))) { return NT_STATUS_OK; } /* NOTE! 0 byte long ranges ARE allowed and should be stored */ DEBUG(10,("do_lock: lock flavour %s lock type %s start=%.0f len=%.0f requested for fnum %d file %s\n", lock_flav_name(lock_flav), lock_type_name(lock_type), (double)offset, (double)count, fsp->fnum, fsp->fsp_name )); br_lck = brl_get_locks(fsp); if (!br_lck) { return NT_STATUS_NO_MEMORY; } status = brl_lock(br_lck, lock_pid, procid_self(), offset, count, lock_type, lock_flav, my_lock_ctx); byte_range_lock_destructor(br_lck); return status; }
BOOL do_lock(uint16 smbpid, files_struct * fsp, struct vfs_connection_struct *conn, SMB_BIG_UINT count, SMB_BIG_UINT offset, enum brl_type lock_type, uint32 *err) { BOOL ok = False; if (!lp_locking(conn->snum)) return (True); if (count == 0) { *err = NT_STATUS_ACCESS_DENIED; return False; } DEBUG(10, ("do_lock: lock type %s start=%.0f len=%.0f requested for file %s\n", lock_type_name(lock_type), (double)offset, (double)count, smbstrA(fsp->fsp_name))); if (OPEN_FSP(fsp) && fsp->can_lock && (fsp->conn == conn)) { ok = brl_lock(fsp->sbuf.st_dev, fsp->sbuf.st_ino, fsp->fnum, smbpid, sys_getpid(), conn->snum, offset, count, lock_type); if (ok && lp_posix_locking(conn->snum)) { /* * Try and get a POSIX lock on this range. * Note that this is ok if it is a read lock * overlapping on a different fd. JRA. */ ok = set_posix_lock(fsp, offset, count, lock_type); if (!ok) { /* * We failed to map - we must now remove the brl * lock entry. */ (void)brl_unlock(fsp->sbuf.st_dev, fsp->sbuf.st_ino, fsp->fnum, smbpid, sys_getpid(), conn->snum, offset, count); } } } if (!ok) { *err = NT_STATUS_LOCK_NOT_GRANTED; return False; } return True; /* Got lock */ }
struct byte_range_lock *do_lock(struct messaging_context *msg_ctx, files_struct *fsp, uint64_t smblctx, uint64_t count, uint64_t offset, enum brl_type lock_type, enum brl_flavour lock_flav, bool blocking_lock, NTSTATUS *perr, uint64_t *psmblctx, struct blocking_lock_record *blr) { struct byte_range_lock *br_lck = NULL; /* silently return ok on print files as we don't do locking there */ if (fsp->print_file) { *perr = NT_STATUS_OK; return NULL; } if (!fsp->can_lock) { *perr = fsp->is_directory ? NT_STATUS_INVALID_DEVICE_REQUEST : NT_STATUS_INVALID_HANDLE; return NULL; } if (!lp_locking(fsp->conn->params)) { *perr = NT_STATUS_OK; return NULL; } /* NOTE! 0 byte long ranges ARE allowed and should be stored */ DEBUG(10,("do_lock: lock flavour %s lock type %s start=%.0f len=%.0f " "blocking_lock=%s requested for %s file %s\n", lock_flav_name(lock_flav), lock_type_name(lock_type), (double)offset, (double)count, blocking_lock ? "true" : "false", fsp_fnum_dbg(fsp), fsp_str_dbg(fsp))); br_lck = brl_get_locks(talloc_tos(), fsp); if (!br_lck) { *perr = NT_STATUS_NO_MEMORY; return NULL; } *perr = brl_lock(msg_ctx, br_lck, smblctx, messaging_server_id(fsp->conn->sconn->msg_ctx), offset, count, lock_type, lock_flav, blocking_lock, psmblctx, blr); DEBUG(10, ("do_lock: returning status=%s\n", nt_errstr(*perr))); increment_current_lock_count(fsp, lock_flav); return br_lck; }