- fixed warnings, produced by Haiku version of gcc;
- space-based indentations replaced with tab-based; - a bit of cleanup; git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18782 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
d8b1cf0703
commit
2db0303fdc
@ -1,7 +1,14 @@
|
||||
/*
|
||||
* Copyright (c) 2003-2005 by Siarzhuk Zharski <imker@gmx.li>
|
||||
* Distributed under the terms of the BSD License.
|
||||
/**
|
||||
*
|
||||
* TODO: description
|
||||
*
|
||||
* This file is a part of USB SCSI CAM for Haiku OS.
|
||||
* May be used under terms of the MIT License
|
||||
*
|
||||
* Author(s):
|
||||
* Siarzhuk Zharski <imker@gmx.li>
|
||||
*
|
||||
*
|
||||
*/
|
||||
#include "usb_scsi.h"
|
||||
|
||||
@ -12,77 +19,77 @@
|
||||
#include "fake_device.h"
|
||||
|
||||
/* duplication! Hope this fake file will be not required in Haiku version*/
|
||||
#define INQ_VENDOR_LEN 0x08
|
||||
#define INQ_PRODUCT_LEN 0x10
|
||||
#define INQ_REVISION_LEN 0x04
|
||||
|
||||
#define INQ_VENDOR_LEN 0x08
|
||||
#define INQ_PRODUCT_LEN 0x10
|
||||
#define INQ_REVISION_LEN 0x04
|
||||
|
||||
void fake_inquiry_request(usb_device_info *udi, CCB_SCSIIO *ccbio)
|
||||
{
|
||||
uint8 *data = ccbio->cam_data_ptr;
|
||||
if(ccbio->cam_ch.cam_flags & CAM_SCATTER_VALID){
|
||||
TRACE_ALWAYS("fake_inquiry: problems!!! scatter gatter ....=-(\n");
|
||||
} else {
|
||||
memset(data, 0, ccbio->cam_dxfer_len);
|
||||
/* data[0] = 0x1F;*/ /* we can play here with type of device */
|
||||
data[1] = 0x80;
|
||||
data[2] = 0x02;
|
||||
data[3] = 0x02;
|
||||
data[4] = (0 != udi) ? 5 : 31; /* udi != 0 - mean FIX_NO_INQUIRY */
|
||||
if(ccbio->cam_dxfer_len >= 0x24){
|
||||
strncpy(&data[8], "USB SCSI", INQ_VENDOR_LEN);
|
||||
strncpy(&data[16], "Reserved", INQ_PRODUCT_LEN);
|
||||
strncpy(&data[32], "N/A", INQ_REVISION_LEN);
|
||||
}
|
||||
}
|
||||
uint8 *data = ccbio->cam_data_ptr;
|
||||
if(ccbio->cam_ch.cam_flags & CAM_SCATTER_VALID){
|
||||
TRACE_ALWAYS("fake_inquiry: problems!!! scatter gatter ....=-(\n");
|
||||
} else {
|
||||
memset(data, 0, ccbio->cam_dxfer_len);
|
||||
/* data[0] = 0x1F;*/ /* we can play here with type of device */
|
||||
data[1] = 0x80;
|
||||
data[2] = 0x02;
|
||||
data[3] = 0x02;
|
||||
data[4] = (0 != udi) ? 5 : 31; /* udi != 0 - mean FIX_NO_INQUIRY */
|
||||
if(ccbio->cam_dxfer_len >= 0x24){
|
||||
strncpy(&data[8], "USB SCSI", INQ_VENDOR_LEN);
|
||||
strncpy(&data[16], "Reserved", INQ_PRODUCT_LEN);
|
||||
strncpy(&data[32], "N/A", INQ_REVISION_LEN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void fake_test_unit_ready_request(CCB_SCSIIO *ccbio)
|
||||
{
|
||||
if(ccbio->cam_sense_ptr != NULL){
|
||||
scsi_sense_data *sense_data = (scsi_sense_data *)ccbio->cam_sense_ptr;
|
||||
memset(sense_data, 0, ccbio->cam_sense_len);
|
||||
sense_data->error_code = SSD_CURRENT_ERROR;
|
||||
sense_data->flags = SSD_KEY_NOT_READY;
|
||||
ccbio->cam_ch.cam_status = CAM_REQ_CMP_ERR | CAM_AUTOSNS_VALID;
|
||||
ccbio->cam_scsi_status = SCSI_STATUS_CHECK_CONDITION;
|
||||
} else {
|
||||
ccbio->cam_ch.cam_status = CAM_REQ_CMP_ERR;
|
||||
ccbio->cam_scsi_status = SCSI_STATUS_OK;
|
||||
}
|
||||
if(ccbio->cam_sense_ptr != NULL){
|
||||
scsi_sense_data *sense_data = (scsi_sense_data *)ccbio->cam_sense_ptr;
|
||||
memset(sense_data, 0, ccbio->cam_sense_len);
|
||||
sense_data->error_code = SSD_CURRENT_ERROR;
|
||||
sense_data->flags = SSD_KEY_NOT_READY;
|
||||
ccbio->cam_ch.cam_status = CAM_REQ_CMP_ERR | CAM_AUTOSNS_VALID;
|
||||
ccbio->cam_scsi_status = SCSI_STATUS_CHECK_CONDITION;
|
||||
} else {
|
||||
ccbio->cam_ch.cam_status = CAM_REQ_CMP_ERR;
|
||||
ccbio->cam_scsi_status = SCSI_STATUS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
\fn:fake_scsi_io
|
||||
\param ccbio: ????
|
||||
\return: ???
|
||||
|
||||
xpt_scsi_io - handle XPT_SCSI_IO sim action
|
||||
\fn:fake_scsi_io
|
||||
\param ccbio: ????
|
||||
\return: ???
|
||||
|
||||
xpt_scsi_io - handle XPT_SCSI_IO sim action
|
||||
*/
|
||||
status_t fake_scsi_io(CCB_SCSIIO *ccbio)
|
||||
{
|
||||
status_t status = B_BAD_VALUE;
|
||||
uint8 *cmd;
|
||||
scsi_cmd_generic *command;
|
||||
if(ccbio->cam_ch.cam_flags & CAM_CDB_POINTER){
|
||||
cmd = ccbio->cam_cdb_io.cam_cdb_ptr;
|
||||
}else{
|
||||
cmd = ccbio->cam_cdb_io.cam_cdb_bytes;
|
||||
}
|
||||
command = (scsi_cmd_generic *)cmd;
|
||||
switch(command->opcode){
|
||||
case TEST_UNIT_READY:{
|
||||
fake_test_unit_ready_request(ccbio);
|
||||
status = B_OK;
|
||||
}break;
|
||||
case INQUIRY:{
|
||||
fake_inquiry_request(NULL, ccbio);
|
||||
ccbio->cam_ch.cam_status = CAM_REQ_CMP;
|
||||
status = B_OK;
|
||||
}break;
|
||||
default:
|
||||
ccbio->cam_ch.cam_status = CAM_REQ_INVALID;
|
||||
break;
|
||||
}
|
||||
return status;
|
||||
status_t status = B_BAD_VALUE;
|
||||
uint8 *cmd;
|
||||
scsi_cmd_generic *command;
|
||||
if(ccbio->cam_ch.cam_flags & CAM_CDB_POINTER){
|
||||
cmd = ccbio->cam_cdb_io.cam_cdb_ptr;
|
||||
}else{
|
||||
cmd = ccbio->cam_cdb_io.cam_cdb_bytes;
|
||||
}
|
||||
command = (scsi_cmd_generic *)cmd;
|
||||
switch(command->opcode){
|
||||
case TEST_UNIT_READY:{
|
||||
fake_test_unit_ready_request(ccbio);
|
||||
status = B_OK;
|
||||
}break;
|
||||
case INQUIRY:{
|
||||
fake_inquiry_request(NULL, ccbio);
|
||||
ccbio->cam_ch.cam_status = CAM_REQ_CMP;
|
||||
status = B_OK;
|
||||
}break;
|
||||
default:
|
||||
ccbio->cam_ch.cam_status = CAM_REQ_INVALID;
|
||||
break;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
|
@ -1,13 +1,20 @@
|
||||
/*
|
||||
* Copyright (c) 2003-2005 by Siarzhuk Zharski <imker@gmx.li>
|
||||
* Distributed under the terms of the BSD License.
|
||||
/**
|
||||
*
|
||||
* TODO: description
|
||||
*
|
||||
* This file is a part of USB SCSI CAM for Haiku OS.
|
||||
* May be used under terms of the MIT License
|
||||
*
|
||||
* Author(s):
|
||||
* Siarzhuk Zharski <imker@gmx.li>
|
||||
*
|
||||
*
|
||||
*/
|
||||
#ifndef _FAKE_DEVICE_H_
|
||||
#define _FAKE_DEVICE_H_
|
||||
#define _FAKE_DEVICE_H_
|
||||
|
||||
void fake_inquiry_request(usb_device_info *udi, CCB_SCSIIO *ccbio);
|
||||
void fake_test_unit_ready_request(CCB_SCSIIO *ccbio);
|
||||
status_t fake_scsi_io(CCB_SCSIIO *ccbio);
|
||||
|
||||
|
||||
#endif /* _FAKE_DEVICE_H_ */
|
||||
|
@ -1,39 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2003-2005 by Siarzhuk Zharski <imker@gmx.li>
|
||||
* Distributed under the terms of the BSD License.
|
||||
/**
|
||||
*
|
||||
* TODO: description
|
||||
*
|
||||
* This file is a part of USB SCSI CAM for Haiku OS.
|
||||
* May be used under terms of the MIT License
|
||||
*
|
||||
* Author(s):
|
||||
* Siarzhuk Zharski <imker@gmx.li>
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/** driver settings support implementation */
|
||||
|
||||
#include "usb_scsi.h"
|
||||
#include "settings.h"
|
||||
//#include "proto_common.h"
|
||||
|
||||
#include <stdlib.h> /* strtoul */
|
||||
#include <stdlib.h> /* strtoul */
|
||||
#include <strings.h> /* strncpy */
|
||||
#include <driver_settings.h>
|
||||
#include "tracing.h"
|
||||
|
||||
#define DEF_DEVS 2 /**< default amount of reserved devices */
|
||||
#define S_DEF_DEVS "2" /**< default amount of reserved devices */
|
||||
#define DEF_LUNS 4 /**< default amount of reserved LUNs */
|
||||
#define S_DEF_LUNS "4" /**< default amount of reserved LUNs */
|
||||
#define DEF_DEVS 2 /**< default amount of reserved devices */
|
||||
#define S_DEF_DEVS "2" /**< default amount of reserved devices */
|
||||
#define DEF_LUNS 4 /**< default amount of reserved LUNs */
|
||||
#define S_DEF_LUNS "4" /**< default amount of reserved LUNs */
|
||||
/** count of device entries, to be reserved for fake devices */
|
||||
int reserved_devices = DEF_DEVS;
|
||||
int reserved_devices = DEF_DEVS;
|
||||
/** count of Logical Unit Numbers, to be reserved for fake devices */
|
||||
int reserved_luns = DEF_LUNS;
|
||||
int reserved_luns = DEF_LUNS;
|
||||
|
||||
bool b_reservation_on = true;
|
||||
bool b_reservation_on = true;
|
||||
bool b_ignore_sysinit2 = false;
|
||||
/**
|
||||
support of some kind rudimentary "quick" search. Indexes in
|
||||
settings_keys array.
|
||||
support of some kind rudimentary "quick" search. Indexes in
|
||||
settings_keys array.
|
||||
*/
|
||||
enum SKKeys{
|
||||
skkVendor = 0,
|
||||
skkDevice,
|
||||
// skkName,
|
||||
skkVendor = 0,
|
||||
skkDevice,
|
||||
// skkName,
|
||||
// skkTransport,
|
||||
skkProtocol,
|
||||
skkCommandSet,
|
||||
@ -45,296 +51,291 @@ enum SKKeys{
|
||||
skkNoPreventMedia,
|
||||
skkUseModeSense10,
|
||||
skkForceReadOnly,
|
||||
skkProtoBulk,
|
||||
skkProtoCB,
|
||||
skkProtoBulk,
|
||||
skkProtoCB,
|
||||
skkProtoCBI,
|
||||
// skkProtoFreecom,
|
||||
skkCmdSetSCSI,
|
||||
skkCmdSetUFI,
|
||||
skkCmdSetATAPI,
|
||||
skkCmdSetRBC,
|
||||
skkCmdSetQIC157,
|
||||
skkCmdSetSCSI,
|
||||
skkCmdSetUFI,
|
||||
skkCmdSetATAPI,
|
||||
skkCmdSetRBC,
|
||||
skkCmdSetQIC157,
|
||||
|
||||
skkKeysCount,
|
||||
// skkTransportBase = skkSubClassSCSI,
|
||||
skkProtoBegin = skkProtoBulk,
|
||||
skkProtoEnd = skkProtoCBI,
|
||||
skkProtoEnd = skkProtoCBI,
|
||||
skkCmdSetBegin = skkCmdSetSCSI,
|
||||
skkCmdSetEnd = skkCmdSetQIC157,
|
||||
skkCmdSetEnd = skkCmdSetQIC157,
|
||||
};
|
||||
/**
|
||||
helper struct, used in our "quick" search algorithm
|
||||
helper struct, used in our "quick" search algorithm
|
||||
*/
|
||||
struct _settings_key{
|
||||
union _hash{
|
||||
char name[32];
|
||||
uint16 key;
|
||||
}hash;
|
||||
uint32 property;
|
||||
}settings_keys[] = { /**< array of keys, used in our settings files */
|
||||
{{"vendor" }, 0}, /* MUST BE SYNCHRONISED WITH skk*** indexes!!! */
|
||||
{{"device" }, 0},
|
||||
// {{"name" }, 0},
|
||||
// {{"transport"}, 0},
|
||||
{{"protocol"}, 0},
|
||||
{{"commandset"}, 0},
|
||||
{{"fake_inquiry" }, 0},
|
||||
{{"use_rw6_byte_cmd" }, 0},
|
||||
{{"trans_test_unit" }, 0},
|
||||
{{"no_test_unit" }, 0},
|
||||
{{"no_get_max_lun"}, 0},
|
||||
{{"no_prevent_media"}, 0},
|
||||
{{"use_mode_sense_10"}, 0},
|
||||
{{"force_read_only"}, 0},
|
||||
{{"BULK" }, PROTO_BULK_ONLY},
|
||||
{{"CB" }, PROTO_CB},
|
||||
{{"CBI" }, PROTO_CBI},
|
||||
// {{"Freecom"}, PROTO_FREECOM},
|
||||
{{"SCSI" }, CMDSET_SCSI},
|
||||
{{"UFI" }, CMDSET_UFI},
|
||||
{{"ATAPI" }, CMDSET_ATAPI},
|
||||
{{"RBC" }, CMDSET_RBC},
|
||||
{{"QIC157" }, CMDSET_QIC157},
|
||||
union _hash{
|
||||
char name[32];
|
||||
uint16 key;
|
||||
}hash;
|
||||
uint32 property;
|
||||
}settings_keys[] = { /**< array of keys, used in our settings files */
|
||||
{{"vendor" }, 0}, /* MUST BE SYNCHRONISED WITH skk*** indexes!!! */
|
||||
{{"device" }, 0},
|
||||
// {{"name" }, 0},
|
||||
// {{"transport"}, 0},
|
||||
{{"protocol"}, 0},
|
||||
{{"commandset"}, 0},
|
||||
{{"fake_inquiry" }, 0},
|
||||
{{"use_rw6_byte_cmd" }, 0},
|
||||
{{"trans_test_unit" }, 0},
|
||||
{{"no_test_unit" }, 0},
|
||||
{{"no_get_max_lun"}, 0},
|
||||
{{"no_prevent_media"}, 0},
|
||||
{{"use_mode_sense_10"}, 0},
|
||||
{{"force_read_only"}, 0},
|
||||
{{"BULK" }, PROTO_BULK_ONLY},
|
||||
{{"CB" }, PROTO_CB},
|
||||
{{"CBI" }, PROTO_CBI},
|
||||
// {{"Freecom"}, PROTO_FREECOM},
|
||||
{{"SCSI" }, CMDSET_SCSI},
|
||||
{{"UFI" }, CMDSET_UFI},
|
||||
{{"ATAPI" }, CMDSET_ATAPI},
|
||||
{{"RBC" }, CMDSET_RBC},
|
||||
{{"QIC157" }, CMDSET_QIC157},
|
||||
};
|
||||
/**
|
||||
\define:SK_EQUAL
|
||||
checks is the __name parameter correspond to value, pointed by __id index
|
||||
in settings_keys array. The magic of our "quick" search algorithm =-))
|
||||
\define:SK_EQUAL
|
||||
checks is the __name parameter correspond to value, pointed by __id index
|
||||
in settings_keys array. The magic of our "quick" search algorithm =-))
|
||||
*/
|
||||
#define CAST_SK(__name) (*(uint16 *)(__name))
|
||||
#define SK_EQUAL(__name, __id) ((CAST_SK(__name) == (settings_keys[__id].hash.key)) && \
|
||||
(0 == strcmp(__name, settings_keys[__id].hash.name)))
|
||||
(0 == strcmp(__name, settings_keys[__id].hash.name)))
|
||||
/**
|
||||
\fn:load_module_settings
|
||||
loads driver settings from extarnal settings file through BeOS driver
|
||||
settings API. Called on initialization of the module
|
||||
*/
|
||||
void load_module_settings()
|
||||
\fn:load_module_settings
|
||||
loads driver settings from extarnal settings file through BeOS driver
|
||||
settings API. Called on initialization of the module
|
||||
*/
|
||||
void load_module_settings(void)
|
||||
{
|
||||
void *sh = load_driver_settings(MODULE_NAME);
|
||||
if(sh){
|
||||
load_log_settings(sh);
|
||||
/* devices "reservation". Workaround for plug-n-play device attaching*/
|
||||
reserved_devices = strtoul(get_driver_parameter(sh, "reserve_devices",
|
||||
S_DEF_DEVS, S_DEF_DEVS), NULL, 0);
|
||||
reserved_luns = strtoul(get_driver_parameter(sh, "reserve_luns",
|
||||
S_DEF_LUNS, S_DEF_LUNS), NULL, 0);
|
||||
b_ignore_sysinit2 = get_driver_boolean_parameter(sh, "ignore_sysinit2",
|
||||
b_ignore_sysinit2, false);
|
||||
if(reserved_devices > MAX_DEVICES_COUNT)
|
||||
reserved_devices = MAX_DEVICES_COUNT;
|
||||
if(reserved_luns > MAX_LUNS_COUNT)
|
||||
reserved_luns = MAX_LUNS_COUNT;
|
||||
b_reservation_on = (reserved_devices != 0);
|
||||
|
||||
unload_driver_settings(sh);
|
||||
} else {
|
||||
TRACE("settings:load:file '%s' was not found. Using default setting...\n",
|
||||
MODULE_NAME);
|
||||
}
|
||||
void *sh = load_driver_settings(MODULE_NAME);
|
||||
if(sh){
|
||||
load_log_settings(sh);
|
||||
/* devices "reservation". Workaround for plug-n-play device attaching*/
|
||||
reserved_devices = strtoul(get_driver_parameter(sh, "reserve_devices",
|
||||
S_DEF_DEVS, S_DEF_DEVS), NULL, 0);
|
||||
reserved_luns = strtoul(get_driver_parameter(sh, "reserve_luns",
|
||||
S_DEF_LUNS, S_DEF_LUNS), NULL, 0);
|
||||
b_ignore_sysinit2 = get_driver_boolean_parameter(sh, "ignore_sysinit2",
|
||||
b_ignore_sysinit2, false);
|
||||
if(reserved_devices > MAX_DEVICES_COUNT)
|
||||
reserved_devices = MAX_DEVICES_COUNT;
|
||||
if(reserved_luns > MAX_LUNS_COUNT)
|
||||
reserved_luns = MAX_LUNS_COUNT;
|
||||
b_reservation_on = (reserved_devices != 0);
|
||||
|
||||
unload_driver_settings(sh);
|
||||
} else {
|
||||
TRACE("settings:load:file '%s' was not found. Using default setting...\n",
|
||||
MODULE_NAME);
|
||||
}
|
||||
}
|
||||
/**
|
||||
\fn:strncpy_value
|
||||
\param to: buffer for copied string
|
||||
\param dp: driver_parameter, from wich copied string come
|
||||
\param size: maximal size of copied string
|
||||
copies a string, containing value[0] of this parameter, from driver_parameter,
|
||||
pointed by dp, to buffer pointed by to. Semantic of this function is similar
|
||||
to standard strncpy() one.
|
||||
\fn:strncpy_value
|
||||
\param to: buffer for copied string
|
||||
\param dp: driver_parameter, from wich copied string come
|
||||
\param size: maximal size of copied string
|
||||
copies a string, containing value[0] of this parameter, from driver_parameter,
|
||||
pointed by dp, to buffer pointed by to. Semantic of this function is similar
|
||||
to standard strncpy() one.
|
||||
*/
|
||||
/*static void
|
||||
strncpy_value(char *to, driver_parameter *dp, size_t size)
|
||||
{
|
||||
to[0] = 0;
|
||||
if(dp->value_count > 0){
|
||||
strncpy(to, dp->values[0], size);
|
||||
}
|
||||
to[0] = 0;
|
||||
if(dp->value_count > 0){
|
||||
strncpy(to, dp->values[0], size);
|
||||
}
|
||||
}*/
|
||||
/**
|
||||
\fn:parse_transport
|
||||
\param dp: driver_parameter, containing device transport information
|
||||
\return: a bitmasked value from PROP_-defined flags for USB subclass and \
|
||||
protocol
|
||||
parse the transport driver_parameter for known USB subclasses, protocols and
|
||||
compose a bitmasked value from those settings
|
||||
\fn:parse_transport
|
||||
\param dp: driver_parameter, containing device transport information
|
||||
\return: a bitmasked value from PROP_-defined flags for USB subclass and \
|
||||
protocol
|
||||
parse the transport driver_parameter for known USB subclasses, protocols and
|
||||
compose a bitmasked value from those settings
|
||||
*/
|
||||
static uint32
|
||||
parse_transport(driver_parameter *dp,
|
||||
int skkBase, int skkEnd,
|
||||
uint32 vendor_prop, char *vendor_prop_name)
|
||||
parse_transport(driver_parameter *dp, int skkBase, int skkEnd,
|
||||
uint32 vendor_prop, char *vendor_prop_name)
|
||||
{
|
||||
uint32 ret = 0;
|
||||
if(dp->value_count > 0){
|
||||
char *value = dp->values[0];
|
||||
int skkIdx = skkBase;
|
||||
for(; skkIdx <= skkEnd; skkIdx++){
|
||||
if(SK_EQUAL(value, skkIdx)){
|
||||
ret |= settings_keys[skkIdx].property;
|
||||
break;
|
||||
}
|
||||
} /* for(...) enumerate protocol and commandset keys */
|
||||
if(skkIdx > skkEnd){ /* not found - assume vendor prop */
|
||||
ret |= vendor_prop;
|
||||
strncpy(vendor_prop_name, value, VENDOR_PROP_NAME_LEN);
|
||||
}
|
||||
if(dp->value_count > 1){
|
||||
TRACE("settings:parse_transport:accept '%s', ignore extra...\n", value);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
uint32 ret = 0;
|
||||
if(dp->value_count > 0){
|
||||
char *value = dp->values[0];
|
||||
int skkIdx = skkBase;
|
||||
for(; skkIdx <= skkEnd; skkIdx++){
|
||||
if(SK_EQUAL(value, skkIdx)){
|
||||
ret |= settings_keys[skkIdx].property;
|
||||
break;
|
||||
}
|
||||
} /* for(...) enumerate protocol and commandset keys */
|
||||
if(skkIdx > skkEnd){ /* not found - assume vendor prop */
|
||||
ret |= vendor_prop;
|
||||
strncpy(vendor_prop_name, value, VENDOR_PROP_NAME_LEN);
|
||||
}
|
||||
if(dp->value_count > 1){
|
||||
TRACE("settings:parse_transport:accept '%s', ignore extra...\n", value);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
/**
|
||||
\fn:lookup_device_info
|
||||
\param product_id: product id of device to be checked for private settings
|
||||
\param dp: driver_parameter, containing device information
|
||||
\param udd: on return contains name,protocol etc. information about device
|
||||
\return: "true" if private settings for device found - "false" otherwise
|
||||
looks through device parameter, pointed by dp, obtains the name and other
|
||||
parameters of private device settings if available
|
||||
\fn:lookup_device_info
|
||||
\param product_id: product id of device to be checked for private settings
|
||||
\param dp: driver_parameter, containing device information
|
||||
\param udd: on return contains name,protocol etc. information about device
|
||||
\return: "true" if private settings for device found - "false" otherwise
|
||||
looks through device parameter, pointed by dp, obtains the name and other
|
||||
parameters of private device settings if available
|
||||
*/
|
||||
static bool
|
||||
lookup_device_info(uint16 product_id,
|
||||
driver_parameter *dp,
|
||||
usb_device_settings *uds)
|
||||
lookup_device_info(uint16 product_id, driver_parameter *dp,
|
||||
usb_device_settings *uds)
|
||||
{
|
||||
bool b_found = false;
|
||||
if(dp){
|
||||
int i = 0;
|
||||
for(; i < dp->value_count; i++){
|
||||
uint16 id = strtoul(dp->values[0], NULL, 0) & 0xffff;
|
||||
if(product_id == id){
|
||||
int prm = 0;
|
||||
uds->product_id = product_id;
|
||||
for(; prm < dp->parameter_count; prm++){
|
||||
/* if(SK_EQUAL(dp->parameters[prm].name, skkName)){
|
||||
strncpy_value(udd->product_name, &dp->parameters[prm], INQ_PRODUCT_LEN);
|
||||
} else*/
|
||||
/* if(SK_EQUAL(dp->parameters[prm].name, skkTransport)){
|
||||
udd->properties |= parse_transport(&dp->parameters[prm]);
|
||||
} else*/
|
||||
if(SK_EQUAL(dp->parameters[prm].name, skkProtocol)){
|
||||
uds->properties |= parse_transport(&dp->parameters[prm],
|
||||
skkProtoBegin, skkProtoEnd,
|
||||
PROTO_VENDOR,
|
||||
uds->vendor_protocol);
|
||||
} else
|
||||
if(SK_EQUAL(dp->parameters[prm].name, skkCommandSet)){
|
||||
uds->properties |= parse_transport(&dp->parameters[prm],
|
||||
skkCmdSetBegin, skkCmdSetEnd,
|
||||
CMDSET_VENDOR,
|
||||
uds->vendor_commandset);
|
||||
} else
|
||||
if(SK_EQUAL(dp->parameters[prm].name, skkFakeInq)){
|
||||
uds->properties |= FIX_NO_INQUIRY;
|
||||
} else
|
||||
if(SK_EQUAL(dp->parameters[prm].name, skk6ByteCmd)){
|
||||
uds->properties |= FIX_FORCE_RW_TO_6;
|
||||
} else
|
||||
if(SK_EQUAL(dp->parameters[prm].name, skkTransTU)){
|
||||
uds->properties |= FIX_TRANS_TEST_UNIT;
|
||||
} else
|
||||
if(SK_EQUAL(dp->parameters[prm].name, skkNoTU)){
|
||||
uds->properties |= FIX_NO_TEST_UNIT;
|
||||
} else
|
||||
if(SK_EQUAL(dp->parameters[prm].name, skkNoPreventMedia)){
|
||||
uds->properties |= FIX_NO_PREVENT_MEDIA;
|
||||
} else
|
||||
if(SK_EQUAL(dp->parameters[prm].name, skkUseModeSense10)){
|
||||
uds->properties |= FIX_FORCE_MS_TO_10;
|
||||
} else
|
||||
if(SK_EQUAL(dp->parameters[prm].name, skkForceReadOnly)){
|
||||
uds->properties |= FIX_FORCE_READ_ONLY;
|
||||
} else
|
||||
if(SK_EQUAL(dp->parameters[prm].name, skkNoGetMaxLUN)){
|
||||
uds->properties |= FIX_NO_GETMAXLUN;
|
||||
} else {
|
||||
TRACE("settings:device:ignore unknown parameter:%s\n",
|
||||
dp->parameters[prm].name);
|
||||
}
|
||||
} /* for(...) enumerate device parameters */
|
||||
b_found = true;
|
||||
break;
|
||||
} /* if(product_id == id){ */
|
||||
} /*enumerate parameter values (product ids) */
|
||||
} /* if(dp) */
|
||||
return b_found;
|
||||
bool b_found = false;
|
||||
if(dp){
|
||||
int i = 0;
|
||||
for(; i < dp->value_count; i++){
|
||||
uint16 id = strtoul(dp->values[0], NULL, 0) & 0xffff;
|
||||
if(product_id == id){
|
||||
int prm = 0;
|
||||
uds->product_id = product_id;
|
||||
for(; prm < dp->parameter_count; prm++){
|
||||
/* if(SK_EQUAL(dp->parameters[prm].name, skkName)){
|
||||
strncpy_value(udd->product_name, &dp->parameters[prm], INQ_PRODUCT_LEN);
|
||||
} else*/
|
||||
/* if(SK_EQUAL(dp->parameters[prm].name, skkTransport)){
|
||||
udd->properties |= parse_transport(&dp->parameters[prm]);
|
||||
} else*/
|
||||
if(SK_EQUAL(dp->parameters[prm].name, skkProtocol)){
|
||||
uds->properties |= parse_transport(&dp->parameters[prm],
|
||||
skkProtoBegin, skkProtoEnd,
|
||||
PROTO_VENDOR, uds->vendor_protocol);
|
||||
} else
|
||||
if(SK_EQUAL(dp->parameters[prm].name, skkCommandSet)){
|
||||
uds->properties |= parse_transport(&dp->parameters[prm],
|
||||
skkCmdSetBegin, skkCmdSetEnd,
|
||||
CMDSET_VENDOR, uds->vendor_commandset);
|
||||
} else
|
||||
if(SK_EQUAL(dp->parameters[prm].name, skkFakeInq)){
|
||||
uds->properties |= FIX_NO_INQUIRY;
|
||||
} else
|
||||
if(SK_EQUAL(dp->parameters[prm].name, skk6ByteCmd)){
|
||||
uds->properties |= FIX_FORCE_RW_TO_6;
|
||||
} else
|
||||
if(SK_EQUAL(dp->parameters[prm].name, skkTransTU)){
|
||||
uds->properties |= FIX_TRANS_TEST_UNIT;
|
||||
} else
|
||||
if(SK_EQUAL(dp->parameters[prm].name, skkNoTU)){
|
||||
uds->properties |= FIX_NO_TEST_UNIT;
|
||||
} else
|
||||
if(SK_EQUAL(dp->parameters[prm].name, skkNoPreventMedia)){
|
||||
uds->properties |= FIX_NO_PREVENT_MEDIA;
|
||||
} else
|
||||
if(SK_EQUAL(dp->parameters[prm].name, skkUseModeSense10)){
|
||||
uds->properties |= FIX_FORCE_MS_TO_10;
|
||||
} else
|
||||
if(SK_EQUAL(dp->parameters[prm].name, skkForceReadOnly)){
|
||||
uds->properties |= FIX_FORCE_READ_ONLY;
|
||||
} else
|
||||
if(SK_EQUAL(dp->parameters[prm].name, skkNoGetMaxLUN)){
|
||||
uds->properties |= FIX_NO_GETMAXLUN;
|
||||
} else {
|
||||
TRACE("settings:device:ignore unknown parameter:%s\n",
|
||||
dp->parameters[prm].name);
|
||||
}
|
||||
} /* for(...) enumerate device parameters */
|
||||
b_found = true;
|
||||
break;
|
||||
} /* if(product_id == id){ */
|
||||
} /*enumerate parameter values (product ids) */
|
||||
} /* if(dp) */
|
||||
return b_found;
|
||||
}
|
||||
/**
|
||||
\fn:lookup_vendor_info
|
||||
\param vendor_id: vendor id of device to be checked for private settings
|
||||
\param product_id: product id of device to be checked for private settings
|
||||
\param dp: driver_parameter, containing vendor information
|
||||
\param udd: on return contains name, protocol etc. information about device
|
||||
\return: "true" if private settings for device found - "false" otherwise
|
||||
looks through vendor parameter, pointed by dp, obtains the name of vendor and
|
||||
device information if available
|
||||
\fn:lookup_vendor_info
|
||||
\param vendor_id: vendor id of device to be checked for private settings
|
||||
\param product_id: product id of device to be checked for private settings
|
||||
\param dp: driver_parameter, containing vendor information
|
||||
\param udd: on return contains name, protocol etc. information about device
|
||||
\return: "true" if private settings for device found - "false" otherwise
|
||||
looks through vendor parameter, pointed by dp, obtains the name of vendor and
|
||||
device information if available
|
||||
*/
|
||||
static bool
|
||||
lookup_vendor_info(uint16 vendor_id,
|
||||
uint16 product_id,
|
||||
driver_parameter *dp,
|
||||
usb_device_settings *uds)
|
||||
lookup_vendor_info(uint16 vendor_id, uint16 product_id,
|
||||
driver_parameter *dp, usb_device_settings *uds)
|
||||
{
|
||||
bool b_found = false;
|
||||
if(dp && dp->value_count > 0 && dp->values[0]){
|
||||
uint16 id = strtoul(dp->values[0], NULL, 0) & 0xffff;
|
||||
if(vendor_id == id){
|
||||
int i = 0;
|
||||
for( i = 0; i < dp->parameter_count; i++){
|
||||
if(!b_found && SK_EQUAL(dp->parameters[i].name, skkDevice)){
|
||||
b_found = lookup_device_info(product_id, &dp->parameters[i], uds);
|
||||
} /*else
|
||||
if(SK_EQUAL(dp->parameters[i].name, skkName)){
|
||||
strncpy_value(udd->vendor_name, &dp->parameters[i], INQ_VENDOR_LEN);
|
||||
} */else {
|
||||
TRACE("settings:vendor:ignore unknown parameter:%s\n",
|
||||
dp->parameters[i].name);
|
||||
}
|
||||
} /*for(...) enumerate "vendor" parameters*/
|
||||
} /*if(vendor_id == id){*/
|
||||
} /* if(dp && ... etc */
|
||||
return b_found;
|
||||
bool b_found = false;
|
||||
if(dp && dp->value_count > 0 && dp->values[0]){
|
||||
uint16 id = strtoul(dp->values[0], NULL, 0) & 0xffff;
|
||||
if(vendor_id == id){
|
||||
int i = 0;
|
||||
for( i = 0; i < dp->parameter_count; i++){
|
||||
if(!b_found && SK_EQUAL(dp->parameters[i].name, skkDevice)){
|
||||
b_found = lookup_device_info(product_id, &dp->parameters[i], uds);
|
||||
} /*else
|
||||
if(SK_EQUAL(dp->parameters[i].name, skkName)){
|
||||
strncpy_value(udd->vendor_name, &dp->parameters[i], INQ_VENDOR_LEN);
|
||||
} */else {
|
||||
TRACE("settings:vendor:ignore unknown parameter:%s\n",
|
||||
dp->parameters[i].name);
|
||||
}
|
||||
} /*for(...) enumerate "vendor" parameters*/
|
||||
} /*if(vendor_id == id){*/
|
||||
} /* if(dp && ... etc */
|
||||
return b_found;
|
||||
}
|
||||
/**
|
||||
\fn:lookup_device_settings
|
||||
\param vendor_id: vendor id of device to be checked for private settings
|
||||
\param product_id: product id of device to be checked for private settings
|
||||
\param udd: on return contains name,protocol etc. information about device
|
||||
\return: "true" if private settings for device found - "false" otherwise
|
||||
looks through driver settings file for private device description and load it
|
||||
if available into struct pointed by udd
|
||||
\fn:lookup_device_settings
|
||||
\param vendor_id: vendor id of device to be checked for private settings
|
||||
\param product_id: product id of device to be checked for private settings
|
||||
\param udd: on return contains name,protocol etc. information about device
|
||||
\return: "true" if private settings for device found - "false" otherwise
|
||||
looks through driver settings file for private device description and load it
|
||||
if available into struct pointed by udd
|
||||
*/
|
||||
bool lookup_device_settings(const usb_device_descriptor *udd,
|
||||
usb_device_settings *uds)
|
||||
usb_device_settings *uds)
|
||||
{
|
||||
bool b_found = false;
|
||||
if(uds){
|
||||
void *sh = load_driver_settings(MODULE_NAME);
|
||||
if(sh){
|
||||
const driver_settings *ds = get_driver_settings(sh);
|
||||
if(ds){
|
||||
int i = 0;
|
||||
for(i = 0; i < ds->parameter_count; i++){
|
||||
if(SK_EQUAL(ds->parameters[i].name, skkVendor)){
|
||||
b_found = lookup_vendor_info(udd->vendor_id,
|
||||
udd->product_id,
|
||||
&ds->parameters[i], uds);
|
||||
if(b_found){
|
||||
uds->vendor_id = udd->vendor_id;
|
||||
break; //we've got it - stop enumeration.
|
||||
}
|
||||
}
|
||||
} /*for(...) - enumerate "root" parameters*/
|
||||
} /* if(ds) */
|
||||
unload_driver_settings(sh);
|
||||
} /* if(sh) */
|
||||
if(b_found){
|
||||
//TRACE("settings:loaded settings:'%s(%04x)/%s(%04x)/%08x'\n",
|
||||
TRACE("settings:loaded settings:'%04x/%04x/%08x'\n",
|
||||
/*descr->vendor_name,*/ uds->vendor_id,
|
||||
/*descr->product_name,*/
|
||||
uds->product_id, uds->properties);
|
||||
}
|
||||
} /* if(descr)*/
|
||||
return b_found;
|
||||
bool b_found = false;
|
||||
if(uds){
|
||||
void *sh = load_driver_settings(MODULE_NAME);
|
||||
if(sh){
|
||||
const driver_settings *ds = get_driver_settings(sh);
|
||||
if(ds){
|
||||
int i = 0;
|
||||
for(i = 0; i < ds->parameter_count; i++){
|
||||
if(SK_EQUAL(ds->parameters[i].name, skkVendor)){
|
||||
b_found = lookup_vendor_info(udd->vendor_id,
|
||||
udd->product_id,
|
||||
&ds->parameters[i], uds);
|
||||
if(b_found){
|
||||
uds->vendor_id = udd->vendor_id;
|
||||
break; //we've got it - stop enumeration.
|
||||
}
|
||||
}
|
||||
} /*for(...) - enumerate "root" parameters*/
|
||||
} /* if(ds) */
|
||||
unload_driver_settings(sh);
|
||||
} /* if(sh) */
|
||||
if(b_found){
|
||||
//TRACE("settings:loaded settings:'%s(%04x)/%s(%04x)/%08x'\n",
|
||||
TRACE("settings:loaded settings:'%04x/%04x/%08x'\n",
|
||||
/*descr->vendor_name,*/ uds->vendor_id,
|
||||
/*descr->product_name,*/
|
||||
uds->product_id, uds->properties);
|
||||
}
|
||||
} /* if(descr)*/
|
||||
return b_found;
|
||||
}
|
||||
|
||||
|
@ -1,31 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) 2003-2005 by Siarzhuk Zharski <imker@gmx.li>
|
||||
* Distributed under the terms of the BSD License.
|
||||
/**
|
||||
*
|
||||
* TODO: description
|
||||
*
|
||||
* This file is a part of USB SCSI CAM for Haiku OS.
|
||||
* May be used under terms of the MIT License
|
||||
*
|
||||
* Author(s):
|
||||
* Siarzhuk Zharski <imker@gmx.li>
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/** driver settings support definitions */
|
||||
|
||||
#ifndef _USB_SCSI_SETTINGS_H_
|
||||
#define _USB_SCSI_SETTINGS_H_
|
||||
#define _USB_SCSI_SETTINGS_H_
|
||||
|
||||
void load_module_settings();
|
||||
void load_module_settings(void);
|
||||
|
||||
typedef struct{
|
||||
uint16 vendor_id;
|
||||
uint16 product_id;
|
||||
uint32 properties;
|
||||
#define VENDOR_PROP_NAME_LEN 0x08
|
||||
char vendor_protocol[VENDOR_PROP_NAME_LEN + 1];
|
||||
char vendor_commandset[VENDOR_PROP_NAME_LEN + 1];
|
||||
uint16 vendor_id;
|
||||
uint16 product_id;
|
||||
uint32 properties;
|
||||
#define VENDOR_PROP_NAME_LEN 0x08
|
||||
char vendor_protocol[VENDOR_PROP_NAME_LEN + 1];
|
||||
char vendor_commandset[VENDOR_PROP_NAME_LEN + 1];
|
||||
}usb_device_settings;
|
||||
|
||||
bool lookup_device_settings(const usb_device_descriptor *udd,
|
||||
usb_device_settings *uds);
|
||||
usb_device_settings *uds);
|
||||
|
||||
extern int reserved_devices;
|
||||
extern int reserved_luns;
|
||||
extern int reserved_devices;
|
||||
extern int reserved_luns;
|
||||
extern bool b_reservation_on;
|
||||
extern bool b_ignore_sysinit2;
|
||||
|
||||
#endif /*_USB_SCSI_SETTINGS_H_*/
|
||||
|
||||
|
@ -1,9 +1,15 @@
|
||||
/*
|
||||
* Copyright (c) 2003-2005 by Siarzhuk Zharski <imker@gmx.li>
|
||||
* Distributed under the terms of the BSD License.
|
||||
/**
|
||||
*
|
||||
* TODO: description
|
||||
*
|
||||
* This file is a part of USB SCSI CAM for Haiku OS.
|
||||
* May be used under terms of the MIT License
|
||||
*
|
||||
* Author(s):
|
||||
* Siarzhuk Zharski <imker@gmx.li>
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/** handling SCSI data-buffer (both usual "plain" and scatter/gather ones) */
|
||||
|
||||
#include <string.h>
|
||||
@ -15,159 +21,160 @@
|
||||
#include "sg_buffer.h"
|
||||
|
||||
/**
|
||||
\fn:init_sg_buffer
|
||||
TODO!!!
|
||||
\fn:init_sg_buffer
|
||||
TODO!!!
|
||||
*/
|
||||
status_t
|
||||
init_sg_buffer(sg_buffer *sgb, CCB_SCSIIO *ccbio)
|
||||
{
|
||||
status_t status = B_NO_INIT;
|
||||
if(0 != sgb){
|
||||
memset(sgb, 0, sizeof(sg_buffer));
|
||||
/* setup scatter/gather if exists in CCBIO*/
|
||||
if(ccbio->cam_ch.cam_flags & CAM_SCATTER_VALID) {
|
||||
sgb->piov = (iovec *) ccbio->cam_data_ptr;
|
||||
sgb->count = ccbio->cam_sglist_cnt;
|
||||
} else {
|
||||
sgb->iov.iov_base = (iovec *) ccbio->cam_data_ptr;
|
||||
sgb->iov.iov_len = ccbio->cam_dxfer_len;
|
||||
sgb->piov = &sgb->iov;
|
||||
sgb->count = 1;
|
||||
}
|
||||
status = B_OK;
|
||||
} else {
|
||||
TRACE_ALWAYS("init_sg_buffer fatal: not initialized!\n");
|
||||
}
|
||||
return status;
|
||||
status_t status = B_NO_INIT;
|
||||
if(0 != sgb){
|
||||
memset(sgb, 0, sizeof(sg_buffer));
|
||||
/* setup scatter/gather if exists in CCBIO*/
|
||||
if(ccbio->cam_ch.cam_flags & CAM_SCATTER_VALID) {
|
||||
sgb->piov = (iovec *) ccbio->cam_data_ptr;
|
||||
sgb->count = ccbio->cam_sglist_cnt;
|
||||
} else {
|
||||
sgb->iov.iov_base = (iovec *) ccbio->cam_data_ptr;
|
||||
sgb->iov.iov_len = ccbio->cam_dxfer_len;
|
||||
sgb->piov = &sgb->iov;
|
||||
sgb->count = 1;
|
||||
}
|
||||
status = B_OK;
|
||||
} else {
|
||||
TRACE_ALWAYS("init_sg_buffer fatal: not initialized!\n");
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
\fn:alloc_sg_buffer
|
||||
TODO!!!
|
||||
\fn:alloc_sg_buffer
|
||||
TODO!!!
|
||||
*/
|
||||
status_t
|
||||
realloc_sg_buffer(sg_buffer *sgb, size_t size)
|
||||
{
|
||||
status_t status = B_NO_INIT;
|
||||
if(0 != sgb){
|
||||
/* NOTE: no check for previously allocations! May be dangerous!*/
|
||||
void *ptr = malloc(size);
|
||||
status = (0 != ptr) ? B_OK : B_NO_MEMORY;
|
||||
if(B_OK == status) {
|
||||
memset(ptr, 0, size);
|
||||
sgb->iov.iov_base = (iovec *)ptr;
|
||||
sgb->iov.iov_len = size;
|
||||
sgb->piov = &sgb->iov;
|
||||
sgb->count = 1;
|
||||
sgb->b_own = true;
|
||||
status = B_OK;
|
||||
}
|
||||
} else {
|
||||
TRACE_ALWAYS("realloc_sg_buffer fatal: not initialized!\n");
|
||||
}
|
||||
return status;
|
||||
status_t status = B_NO_INIT;
|
||||
if(0 != sgb){
|
||||
/* NOTE: no check for previously allocations! May be dangerous!*/
|
||||
void *ptr = malloc(size);
|
||||
status = (0 != ptr) ? B_OK : B_NO_MEMORY;
|
||||
if(B_OK == status) {
|
||||
memset(ptr, 0, size);
|
||||
sgb->iov.iov_base = (iovec *)ptr;
|
||||
sgb->iov.iov_len = size;
|
||||
sgb->piov = &sgb->iov;
|
||||
sgb->count = 1;
|
||||
sgb->b_own = true;
|
||||
status = B_OK;
|
||||
}
|
||||
} else {
|
||||
TRACE_ALWAYS("realloc_sg_buffer fatal: not initialized!\n");
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
status_t
|
||||
sg_access_byte(sg_buffer *sgb, off_t offset, uchar *byte, bool b_set)
|
||||
{
|
||||
status_t status = B_ERROR;
|
||||
int i = 0;
|
||||
for(; i < sgb->count; i++){
|
||||
if(offset >= sgb->piov[i].iov_len){
|
||||
offset -= sgb->piov[i].iov_len;
|
||||
} else {
|
||||
uchar *ptr = (uchar *)sgb->piov[i].iov_base;
|
||||
if(b_set){
|
||||
ptr[offset] = *byte;
|
||||
}else{
|
||||
*byte = ptr[offset];
|
||||
}
|
||||
status = B_OK;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
status_t status = B_ERROR;
|
||||
int i = 0;
|
||||
for(; i < sgb->count; i++){
|
||||
if(offset >= sgb->piov[i].iov_len){
|
||||
offset -= sgb->piov[i].iov_len;
|
||||
} else {
|
||||
uchar *ptr = (uchar *)sgb->piov[i].iov_base;
|
||||
if(b_set){
|
||||
ptr[offset] = *byte;
|
||||
}else{
|
||||
*byte = ptr[offset];
|
||||
}
|
||||
status = B_OK;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
status_t
|
||||
sg_memcpy(sg_buffer *d_sgb, off_t d_offset,
|
||||
sg_buffer *s_sgb, off_t s_offset, size_t size)
|
||||
sg_buffer *s_sgb, off_t s_offset, size_t size)
|
||||
{
|
||||
status_t status = B_NO_INIT;
|
||||
while(0 != d_sgb && 0 != s_sgb){
|
||||
uchar *d_ptr = 0;
|
||||
uchar *s_ptr = 0;
|
||||
status = B_ERROR;
|
||||
if(1 == d_sgb->count){
|
||||
d_ptr = d_sgb->piov->iov_base + d_offset;
|
||||
if((d_offset + size) > d_sgb->piov->iov_len){
|
||||
TRACE_ALWAYS("sg_memcpy fatal: dest buffer overflow: has:%d req:%d\n",
|
||||
d_sgb->piov->iov_len, d_offset + size);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(1 == s_sgb->count){
|
||||
s_ptr = s_sgb->piov->iov_base + s_offset;
|
||||
if((s_offset + size) > s_sgb->piov->iov_len){
|
||||
TRACE_ALWAYS("sg_memcpy fatal: src buffer overflow: has:%d req:%d\n",
|
||||
s_sgb->piov->iov_len, s_offset + size);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(0 != d_ptr && 0 != s_ptr){
|
||||
memcpy(d_ptr, s_ptr, size);
|
||||
} else {
|
||||
uchar byte = 0;
|
||||
int i = 0;
|
||||
for(; i < size; i++){
|
||||
status = sg_access_byte(s_sgb, s_offset + i, &byte, false);
|
||||
if(B_OK == status)
|
||||
status = sg_access_byte(d_sgb, d_offset + i, &byte, true);
|
||||
if(B_OK != status){
|
||||
TRACE_ALWAYS("sg_memcpy fatal: dest:%d src:%d size:%d/%d\n",
|
||||
d_offset, s_offset, i, size);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
status = B_OK;
|
||||
break;
|
||||
}
|
||||
if(B_NO_INIT == status)
|
||||
TRACE_ALWAYS("sg_memcpy fatal: not initialized");
|
||||
return status;
|
||||
status_t status = B_NO_INIT;
|
||||
while(0 != d_sgb && 0 != s_sgb){
|
||||
uchar *d_ptr = 0;
|
||||
uchar *s_ptr = 0;
|
||||
status = B_ERROR;
|
||||
if(1 == d_sgb->count){
|
||||
d_ptr = d_sgb->piov->iov_base + d_offset;
|
||||
if((d_offset + size) > d_sgb->piov->iov_len){
|
||||
TRACE_ALWAYS("sg_memcpy fatal: dest buffer overflow: has:%d req:%d\n",
|
||||
d_sgb->piov->iov_len, d_offset + size);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(1 == s_sgb->count){
|
||||
s_ptr = s_sgb->piov->iov_base + s_offset;
|
||||
if((s_offset + size) > s_sgb->piov->iov_len){
|
||||
TRACE_ALWAYS("sg_memcpy fatal: src buffer overflow: has:%d req:%d\n",
|
||||
s_sgb->piov->iov_len, s_offset + size);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(0 != d_ptr && 0 != s_ptr){
|
||||
memcpy(d_ptr, s_ptr, size);
|
||||
} else {
|
||||
uchar byte = 0;
|
||||
int i = 0;
|
||||
for(; i < size; i++){
|
||||
status = sg_access_byte(s_sgb, s_offset + i, &byte, false);
|
||||
if(B_OK == status)
|
||||
status = sg_access_byte(d_sgb, d_offset + i, &byte, true);
|
||||
if(B_OK != status){
|
||||
TRACE_ALWAYS("sg_memcpy fatal: dest:%d src:%d size:%d/%d\n",
|
||||
d_offset, s_offset, i, size);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
status = B_OK;
|
||||
break;
|
||||
}
|
||||
if(B_NO_INIT == status)
|
||||
TRACE_ALWAYS("sg_memcpy fatal: not initialized");
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
\fn:free_sg_buffer
|
||||
TODO!!!
|
||||
\fn:free_sg_buffer
|
||||
TODO!!!
|
||||
*/
|
||||
void
|
||||
free_sg_buffer(sg_buffer *sgb)
|
||||
{
|
||||
if(0 != sgb && sgb->b_own){
|
||||
int i = 0;
|
||||
for(; i < sgb->count; i++){
|
||||
free(sgb->piov[i].iov_base);
|
||||
}
|
||||
memset(sgb, 0, sizeof(sg_buffer));
|
||||
}
|
||||
if(0 != sgb && sgb->b_own){
|
||||
int i = 0;
|
||||
for(; i < sgb->count; i++){
|
||||
free(sgb->piov[i].iov_base);
|
||||
}
|
||||
memset(sgb, 0, sizeof(sg_buffer));
|
||||
}
|
||||
}
|
||||
|
||||
status_t
|
||||
sg_buffer_len(sg_buffer *sgb, size_t *size)
|
||||
{
|
||||
status_t status = B_NO_INIT;
|
||||
if(0!=sgb && 0!=size){
|
||||
int i = 0;
|
||||
*size = 0;
|
||||
for(; i < sgb->count; i++){
|
||||
*size += sgb->piov[i].iov_len;
|
||||
}
|
||||
status = B_OK;
|
||||
} else {
|
||||
TRACE_ALWAYS("sg_buffer_len fatal: not initialized (sgb:%x/size:%x)", sgb, size);
|
||||
}
|
||||
return status;
|
||||
status_t status = B_NO_INIT;
|
||||
if(0!=sgb && 0!=size){
|
||||
int i = 0;
|
||||
*size = 0;
|
||||
for(; i < sgb->count; i++){
|
||||
*size += sgb->piov[i].iov_len;
|
||||
}
|
||||
status = B_OK;
|
||||
} else {
|
||||
TRACE_ALWAYS("sg_buffer_len fatal: not initialized (sgb:%x/size:%x)", sgb, size);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
|
@ -1,26 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) 2003-2005 by Siarzhuk Zharski <imker@gmx.li>
|
||||
* Distributed under the terms of the BSD License.
|
||||
/**
|
||||
*
|
||||
* TODO: description
|
||||
*
|
||||
* This file is a part of USB SCSI CAM for Haiku OS.
|
||||
* May be used under terms of the MIT License
|
||||
*
|
||||
* Author(s):
|
||||
* Siarzhuk Zharski <imker@gmx.li>
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/** handling SCSI data-buffer (both usual "plain" and scatter/gather ones) */
|
||||
|
||||
#ifndef _SG_BUFFER_H_
|
||||
#define _SG_BUFFER_H_
|
||||
#define _SG_BUFFER_H_
|
||||
|
||||
#ifndef _IOVEC_H
|
||||
#include <iovec.h>
|
||||
#include <iovec.h>
|
||||
#endif/*_IOVEC_H*/
|
||||
|
||||
/**
|
||||
\struct:_sg_buffer
|
||||
\struct:_sg_buffer
|
||||
*/
|
||||
typedef struct _sg_buffer{
|
||||
iovec iov; /**< to avoid extra memory allocations */
|
||||
iovec *piov; /**< ptr to scatter/gather list, default is equal to &iov */
|
||||
int count; /**< count of scatter/gather vector entries */
|
||||
bool b_own; /**< was allocated - must be freed */
|
||||
iovec iov; /**< to avoid extra memory allocations */
|
||||
iovec *piov; /**< ptr to scatter/gather list, default is equal to &iov */
|
||||
int count; /**< count of scatter/gather vector entries */
|
||||
bool b_own; /**< was allocated - must be freed */
|
||||
} sg_buffer;
|
||||
|
||||
#define member_offset(__type, __member) ((size_t)&(((__type *)0)->__member))
|
||||
@ -31,7 +37,8 @@ status_t realloc_sg_buffer(sg_buffer *sgb, size_t size);
|
||||
status_t sg_buffer_len(sg_buffer *sgb, size_t *size);
|
||||
status_t sg_access_byte(sg_buffer *sgb, off_t offset, uchar *byte, bool b_set);
|
||||
status_t sg_memcpy(sg_buffer *dest_sgb, off_t dest_offset,
|
||||
sg_buffer *src_sgb, off_t src_offset, size_t size);
|
||||
void free_sg_buffer(sg_buffer *sgb);
|
||||
sg_buffer *src_sgb, off_t src_offset, size_t size);
|
||||
void free_sg_buffer(sg_buffer *sgb);
|
||||
|
||||
#endif /*_SG_BUFFER_H_*/
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user