* Removed *_BEN() macros.
* Minor cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40222 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
/*
|
||||
* Copyright 2004-2008, Haiku, Inc. All RightsReserved.
|
||||
* Copyright 2004-2011, Haiku, Inc. All RightsReserved.
|
||||
* Copyright 2002-2003, Thomas Kurschel. All rights reserved.
|
||||
*
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
//! Handling of block device (currently, only a capacity check is provided)
|
||||
|
||||
|
||||
@@ -51,13 +52,13 @@ periph_check_capacity(scsi_periph_device_info *device, scsi_ccb *request)
|
||||
return B_DEV_MEDIA_CHANGED;
|
||||
}
|
||||
|
||||
ACQUIRE_BEN(&device->mutex);
|
||||
mutex_lock(&device->mutex);
|
||||
|
||||
if (res == B_OK && request->data_resid == 0) {
|
||||
capacity = B_BENDIAN_TO_HOST_INT32(capacityResult.lba);
|
||||
|
||||
if (capacity == UINT_MAX) {
|
||||
RELEASE_BEN(&device->mutex);
|
||||
mutex_unlock(&device->mutex);
|
||||
|
||||
scsi_cmd_read_capacity_long *cmd
|
||||
= (scsi_cmd_read_capacity_long *)request->cdb;
|
||||
@@ -73,7 +74,7 @@ periph_check_capacity(scsi_periph_device_info *device, scsi_ccb *request)
|
||||
|
||||
res = periph_safe_exec(device, request);
|
||||
|
||||
ACQUIRE_BEN(&device->mutex);
|
||||
mutex_lock(&device->mutex);
|
||||
|
||||
if (res == B_OK && request->data_resid == 0) {
|
||||
capacity = B_BENDIAN_TO_HOST_INT64(capacityLongResult.lba);
|
||||
@@ -105,7 +106,7 @@ periph_check_capacity(scsi_periph_device_info *device, scsi_ccb *request)
|
||||
return ERR_DEV_GENERAL;
|
||||
}*/
|
||||
|
||||
RELEASE_BEN(&device->mutex);
|
||||
mutex_unlock(&device->mutex);
|
||||
|
||||
SHOW_FLOW(3, "done (%s)", strerror(res));
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
/*
|
||||
* Copyright 2004-2008, Haiku, Inc. All RightsReserved.
|
||||
* Copyright 2004-2011, Haiku, Inc. All RightsReserved.
|
||||
* Copyright 2002/03, Thomas Kurschel. All rights reserved.
|
||||
*
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
//! Basic handling of device.
|
||||
|
||||
|
||||
@@ -52,26 +53,21 @@ periph_compose_device_name(device_node *node, const char *prefix)
|
||||
|
||||
|
||||
status_t
|
||||
periph_register_device(periph_device_cookie periph_device, scsi_periph_callbacks *callbacks,
|
||||
scsi_device scsi_device, scsi_device_interface *scsi, device_node *node,
|
||||
periph_register_device(periph_device_cookie periph_device,
|
||||
scsi_periph_callbacks *callbacks, scsi_device scsi_device,
|
||||
scsi_device_interface *scsi, device_node *node,
|
||||
bool removable, int preferredCcbSize, scsi_periph_device *driver)
|
||||
{
|
||||
scsi_periph_device_info *device;
|
||||
status_t res;
|
||||
SHOW_FLOW0(3, "");
|
||||
|
||||
SHOW_FLOW0( 3, "" );
|
||||
|
||||
device = (scsi_periph_device_info *)malloc(sizeof(*device));
|
||||
scsi_periph_device_info *device
|
||||
= (scsi_periph_device_info *)malloc(sizeof(*device));
|
||||
if (device == NULL)
|
||||
return B_NO_MEMORY;
|
||||
|
||||
memset(device, 0, sizeof(*device));
|
||||
|
||||
if (INIT_BEN(&device->mutex, "SCSI_PERIPH") != B_OK) {
|
||||
res = B_NO_MEMORY;
|
||||
goto err1;
|
||||
}
|
||||
|
||||
mutex_init(&device->mutex, "SCSI_PERIPH");
|
||||
device->scsi_device = scsi_device;
|
||||
device->scsi = scsi;
|
||||
device->periph_device = periph_device;
|
||||
@@ -87,9 +83,10 @@ periph_register_device(periph_device_cookie periph_device, scsi_periph_callbacks
|
||||
device->rw10_enabled = true;
|
||||
|
||||
// launch sync daemon
|
||||
res = register_kernel_daemon(periph_sync_queue_daemon, device, 60*10);
|
||||
if (res != B_OK)
|
||||
goto err2;
|
||||
status_t status = register_kernel_daemon(periph_sync_queue_daemon, device,
|
||||
60*10);
|
||||
if (status != B_OK)
|
||||
goto err1;
|
||||
|
||||
*driver = device;
|
||||
|
||||
@@ -97,11 +94,10 @@ periph_register_device(periph_device_cookie periph_device, scsi_periph_callbacks
|
||||
|
||||
return B_OK;
|
||||
|
||||
err2:
|
||||
DELETE_BEN(&device->mutex);
|
||||
err1:
|
||||
mutex_destroy(&device->mutex);
|
||||
free(device);
|
||||
return res;
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,20 +1,17 @@
|
||||
/*
|
||||
* Copyright 2002/03, Thomas Kurschel. All rights reserved.
|
||||
* Copyright 2011, Haiku, Inc. All RightsReserved.
|
||||
* Copyright 2002-03, Thomas Kurschel. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
/*
|
||||
Part of Open SCSI Peripheral Driver
|
||||
|
||||
Error handling
|
||||
*/
|
||||
//! Error handling
|
||||
|
||||
|
||||
#include "scsi_periph_int.h"
|
||||
|
||||
|
||||
/** decode sense data and generate error code */
|
||||
|
||||
/*! Decode sense data and generate error code. */
|
||||
static
|
||||
err_res check_sense(scsi_periph_device_info *device, scsi_ccb *request)
|
||||
{
|
||||
@@ -86,9 +83,9 @@ err_res check_sense(scsi_periph_device_info *device, scsi_ccb *request)
|
||||
|
||||
case SCSIS_ASC_REMOVAL_REQUESTED:
|
||||
SHOW_INFO0(2, "Removal requested");
|
||||
ACQUIRE_BEN(&device->mutex);
|
||||
mutex_lock(&device->mutex);
|
||||
device->removal_requested = true;
|
||||
RELEASE_BEN(&device->mutex);
|
||||
mutex_unlock(&device->mutex);
|
||||
|
||||
return MK_ERROR(err_act_retry, B_DEV_MEDIA_CHANGE_REQUESTED);
|
||||
|
||||
@@ -207,8 +204,7 @@ err_res check_sense(scsi_periph_device_info *device, scsi_ccb *request)
|
||||
}
|
||||
|
||||
|
||||
/** check scsi status, using sense if available */
|
||||
|
||||
/*! Check scsi status, using sense if available. */
|
||||
static err_res
|
||||
check_scsi_status(scsi_periph_device_info *device, scsi_ccb *request)
|
||||
{
|
||||
@@ -238,12 +234,11 @@ check_scsi_status(scsi_periph_device_info *device, scsi_ccb *request)
|
||||
}
|
||||
|
||||
|
||||
/** check result of request
|
||||
/*! Check result of request
|
||||
* 1. check SCSI subsystem problems
|
||||
* 2. if request hit device, check SCSI status
|
||||
* 3. if request got executed, check sense
|
||||
*/
|
||||
|
||||
err_res
|
||||
periph_check_error(scsi_periph_device_info *device, scsi_ccb *request)
|
||||
{
|
||||
|
||||
@@ -1,24 +1,23 @@
|
||||
/*
|
||||
** Copyright 2002/03, Thomas Kurschel. All rights reserved.
|
||||
** Distributed under the terms of the OpenBeOS License.
|
||||
*/
|
||||
* Copyright 2011, Haiku, Inc. All RightsReserved.
|
||||
* Copyright 2002-03, Thomas Kurschel. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
/*
|
||||
Part of Open SCSI Peripheral Driver
|
||||
|
||||
Basic handling of file handles.
|
||||
*/
|
||||
//! Basic handling of file handles.
|
||||
|
||||
|
||||
#include "scsi_periph_int.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "dl_list.h"
|
||||
#include <malloc.h>
|
||||
|
||||
|
||||
status_t
|
||||
periph_handle_open(scsi_periph_device_info *device, periph_handle_cookie periph_handle,
|
||||
scsi_periph_handle_info **res_handle)
|
||||
periph_handle_open(scsi_periph_device_info *device,
|
||||
periph_handle_cookie periph_handle, scsi_periph_handle_info **res_handle)
|
||||
{
|
||||
scsi_periph_handle_info *handle;
|
||||
|
||||
@@ -32,9 +31,9 @@ periph_handle_open(scsi_periph_device_info *device, periph_handle_cookie periph_
|
||||
handle->device = device;
|
||||
handle->pending_error = B_OK;
|
||||
|
||||
ACQUIRE_BEN(&device->mutex);
|
||||
mutex_lock(&device->mutex);
|
||||
ADD_DL_LIST_HEAD(handle, device->handles, );
|
||||
RELEASE_BEN(&device->mutex);
|
||||
mutex_unlock(&device->mutex);
|
||||
|
||||
*res_handle = handle;
|
||||
|
||||
@@ -59,9 +58,9 @@ periph_handle_free(scsi_periph_handle_info *handle)
|
||||
|
||||
// SHOW_FLOW( 3, "handle=%p, device=%p", handle, handle->device );
|
||||
|
||||
ACQUIRE_BEN(&device->mutex);
|
||||
mutex_lock(&device->mutex);
|
||||
REMOVE_DL_LIST(handle, device->handles, );
|
||||
RELEASE_BEN(&device->mutex);
|
||||
mutex_unlock(&device->mutex);
|
||||
|
||||
free(handle);
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
/*
|
||||
* Copyright 2004-2007, Haiku, Inc. All RightsReserved.
|
||||
* Copyright 2004-2011, Haiku, Inc. All RightsReserved.
|
||||
* Copyright 2002-2003, Thomas Kurschel. All rights reserved.
|
||||
*
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
//! Handling of removable media.
|
||||
|
||||
|
||||
@@ -70,14 +71,14 @@ periph_media_changed_public(scsi_periph_device_info *device)
|
||||
{
|
||||
scsi_periph_handle_info *handle;
|
||||
|
||||
ACQUIRE_BEN(&device->mutex);
|
||||
mutex_lock(&device->mutex);
|
||||
|
||||
// when medium has changed, tell all handles
|
||||
// (this must be atomic for each handle!)
|
||||
for (handle = device->handles; handle; handle = handle->next)
|
||||
handle->pending_error = B_DEV_MEDIA_CHANGED;
|
||||
|
||||
RELEASE_BEN(&device->mutex);
|
||||
mutex_unlock(&device->mutex);
|
||||
}
|
||||
|
||||
|
||||
@@ -151,7 +152,7 @@ periph_get_media_status(scsi_periph_handle_info *handle)
|
||||
err_res res;
|
||||
status_t err;
|
||||
|
||||
ACQUIRE_BEN(&device->mutex);
|
||||
mutex_lock(&device->mutex);
|
||||
|
||||
// removal requests are returned to exactly one handle
|
||||
// (no real problem, as noone check medias status "by mistake")
|
||||
@@ -170,7 +171,7 @@ periph_get_media_status(scsi_periph_handle_info *handle)
|
||||
|
||||
SHOW_FLOW0( 3, "" );
|
||||
|
||||
RELEASE_BEN(&device->mutex);
|
||||
mutex_unlock(&device->mutex);
|
||||
|
||||
// finally, ask the device itself
|
||||
|
||||
@@ -187,7 +188,7 @@ periph_get_media_status(scsi_periph_handle_info *handle)
|
||||
return res.error_code;
|
||||
|
||||
err:
|
||||
RELEASE_BEN(&device->mutex);
|
||||
mutex_unlock(&device->mutex);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,18 +1,11 @@
|
||||
#ifndef _WRAPPER_H
|
||||
#define _WRAPPER_H
|
||||
|
||||
|
||||
#include <KernelExport.h>
|
||||
#include <lock.h>
|
||||
|
||||
|
||||
// benaphores
|
||||
|
||||
#define INIT_BEN(x, prefix) (mutex_init_etc(x, prefix, MUTEX_FLAG_CLONE_NAME), \
|
||||
B_OK)
|
||||
#define DELETE_BEN(x) mutex_destroy(x)
|
||||
#define ACQUIRE_BEN(x) mutex_lock(x)
|
||||
#define RELEASE_BEN(x) mutex_unlock(x)
|
||||
|
||||
// debug output
|
||||
|
||||
#ifdef DEBUG_WAIT_ON_MSG
|
||||
@@ -87,4 +80,5 @@
|
||||
dprintf( "%s%s: "format"\n", FUNC_NAME); DEBUG_WAIT_ERROR \
|
||||
}} while( 0 )
|
||||
|
||||
#endif /* _BENAPHORE_H */
|
||||
|
||||
#endif /* _WRAPPER_H */
|
||||
|
||||
Reference in New Issue
Block a user