Made use of SCSI_IOCTL_GET_BUS_NUMBER in hope of cdrecord compatibility

This commit is contained in:
2006-10-05 14:21:34 +00:00
parent 1fe7f68b43
commit b6831605b2
7 changed files with 111 additions and 68 deletions

View File

@ -806,7 +806,8 @@ int burn_drive_find_devno(dev_t devno, char adr[])
/** Try to obtain host,channel,target,lun from path.
@return 1 = success , 0 = failure , -1 = severe error
*/
int burn_drive_obtain_scsi_adr(char *path, int *host_no, int *channel_no,
int burn_drive_obtain_scsi_adr(char *path,
int *bus_no, int *host_no, int *channel_no,
int *target_no, int *lun_no)
{
int ret, i;
@ -824,6 +825,7 @@ int burn_drive_obtain_scsi_adr(char *path, int *host_no, int *channel_no,
*channel_no = drive_array[i].channel;
*target_no = drive_array[i].id;
*lun_no = drive_array[i].lun;
*bus_no = drive_array[i].bus_no;
if (*host_no < 0 || *channel_no < 0 ||
*target_no < 0 || *lun_no < 0)
return 0;
@ -831,21 +833,22 @@ int burn_drive_obtain_scsi_adr(char *path, int *host_no, int *channel_no,
}
}
ret = sg_obtain_scsi_adr(path, host_no, channel_no, target_no, lun_no);
ret = sg_obtain_scsi_adr(path, bus_no, host_no, channel_no,
target_no, lun_no);
return ret;
}
/* ts A60923 */
int burn_drive_convert_scsi_adr(int host_no, int channel_no, int target_no,
int lun_no, char adr[])
int burn_drive_convert_scsi_adr(int bus_no, int host_no, int channel_no,
int target_no, int lun_no, char adr[])
{
char fname[4096],msg[4096+100];
int i, ret = 0, first = 1;
int i, ret = 0, first = 1, i_bus_no = -1;
int i_host_no = -1, i_channel_no = -1, i_target_no = -1, i_lun_no = -1;
sprintf(msg,"burn_drive_convert_scsi_adr( %d,%d,%d,%d )",
host_no, channel_no, target_no, lun_no);
sprintf(msg,"burn_drive_convert_scsi_adr( %d,%d,%d,%d,%d )",
bus_no, host_no, channel_no, target_no, lun_no);
burn_drive_adr_debug_msg(msg, NULL);
while (1) {
@ -853,9 +856,11 @@ int burn_drive_convert_scsi_adr(int host_no, int channel_no, int target_no,
if(ret <= 0)
break;
first = 0;
ret = burn_drive_obtain_scsi_adr(fname, &i_host_no,
ret = burn_drive_obtain_scsi_adr(fname, &i_bus_no, &i_host_no,
&i_channel_no, &i_target_no, &i_lun_no);
if(ret <= 0)
continue;
if(bus_no >=0 && i_bus_no != bus_no)
continue;
if(host_no >=0 && i_host_no != host_no)
continue;
@ -881,23 +886,23 @@ int burn_drive_convert_scsi_adr(int host_no, int channel_no, int target_no,
int burn_drive_find_scsi_equiv(char *path, char adr[])
{
int ret = 0;
int host_no, channel_no, target_no, lun_no;
int bus_no, host_no, channel_no, target_no, lun_no;
char msg[4096];
ret = burn_drive_obtain_scsi_adr(path, &host_no, &channel_no,
&target_no, &lun_no);
ret = burn_drive_obtain_scsi_adr(path, &bus_no, &host_no, &channel_no,
&target_no, &lun_no);
if(ret <= 0) {
sprintf(msg,"burn_drive_obtain_scsi_adr( %s ) returns %d\n",
path, ret);
burn_drive_adr_debug_msg(msg, NULL);
return 0;
}
sprintf(msg, "burn_drive_find_scsi_equiv( %s ) : %d,%d,%d,%d",
path, host_no, channel_no, target_no, lun_no);
sprintf(msg, "burn_drive_find_scsi_equiv( %s ) : (%d),%d,%d,%d,%d",
path, bus_no, host_no, channel_no, target_no, lun_no);
burn_drive_adr_debug_msg(msg, NULL);
ret= burn_drive_convert_scsi_adr(host_no, channel_no, target_no,
lun_no, adr);
ret= burn_drive_convert_scsi_adr(-1, host_no, channel_no, target_no,
lun_no, adr);
return ret;
}

View File

@ -568,27 +568,27 @@ int burn_drive_is_enumerable_adr(char *adr);
int burn_drive_convert_fs_adr(char *path, char adr[]);
/* ts A60923 */
/** Try to convert a given SCSI address of bus, channel, target, lun into
/** Try to convert a given SCSI address of bus,host,channel,target,lun into
a persistent drive address. If a SCSI address component parameter is < 0
then it is not decisive and the first enumerated address which matches
the >= 0 parameters is taken as result.
Note: bus and (host,channel) are supposed to be redundant.
@param adr An application provided array of at least BURN_DRIVE_ADR_LEN
characters size. The persistent address gets copied to it.
@return 1 = success , 0 = failure , -1 = severe error
*/
int burn_drive_convert_scsi_adr(int host_no, int channel_no, int target_no,
int lun_no, char adr[]);
int burn_drive_convert_scsi_adr(int bus_no, int host_no, int channel_no,
int target_no, int lun_no, char adr[]);
/* ts A60923 */
/** Try to obtain host,channel,target,lun from path. If there is an SCSI
/* ts A60923 - A61005 */
/** Try to obtain bus,host,channel,target,lun from path. If there is an SCSI
address at all, then this call should succeed with a persistent
drive address obtained via burn_drive_get_adr(). It is also supposed to
succeed with any device file of a (possibly emulated) SCSI device.
@return 1 = success , 0 = failure , -1 = severe error
*/
int burn_drive_obtain_scsi_adr(char *path, int *host_no, int *channel_no,
int *target_no, int *lun_no);
int burn_drive_obtain_scsi_adr(char *path, int *bus_no, int *host_no,
int *channel_no, int *target_no, int *lun_no);
/** Grab a drive. This must be done before the drive can be used (for reading,
writing, etc).

View File

@ -26,8 +26,8 @@
#include "libdax_msgs.h"
extern struct libdax_msgs *libdax_messenger;
static void enumerate_common(char *fname, int host_no, int channel_no,
int target_no, int lun_no);
static void enumerate_common(char *fname, int bus_no, int host_no,
int channel_no, int target_no, int lun_no);
/* ts A51221 */
int burn_drive_is_banned(char *device_address);
@ -156,9 +156,6 @@ int sg_is_enumerable_adr(char *adr)
ret= sg_give_next_adr(&i, fname, sizeof(fname), first);
if(ret <= 0)
break;
/* <<<
fprintf(stderr,"libburn experimental: idx %d : %s\n",i,fname);
*/
first = 0;
if (strcmp(adr, fname) == 0)
return 1;
@ -243,7 +240,7 @@ int sg_open_scsi_siblings(char *path, int driveno,
int sibling_fds[], int *sibling_count,
int host_no, int channel_no, int id_no, int lun_no)
{
int tld, i, ret, fd;
int tld, i, ret, fd, i_bus_no = -1;
int i_host_no = -1, i_channel_no = -1, i_target_no = -1, i_lun_no = -1;
char msg[161], fname[81];
@ -257,7 +254,7 @@ int sg_open_scsi_siblings(char *path, int driveno,
for (tld = 0; tldev[tld][0] != 0; tld++) {
for (i = 0; i < 32; i++) {
sprintf(fname, tldev[tld], i);
ret = sg_obtain_scsi_adr(fname, &i_host_no,
ret = sg_obtain_scsi_adr(fname, &i_bus_no, &i_host_no,
&i_channel_no, &i_target_no, &i_lun_no);
if (ret <= 0)
continue;
@ -340,7 +337,7 @@ void ata_enumerate(void)
}
if (sg_close_drive_fd(fname, -1, &fd, 1) <= 0)
continue;
enumerate_common(fname, -1, -1, -1, -1);
enumerate_common(fname, -1, -1, -1, -1, -1);
}
}
@ -348,6 +345,7 @@ void sg_enumerate(void)
{
struct sg_scsi_id sid;
int i, fd, sibling_fds[LIBBURN_SG_MAX_SIBLINGS], sibling_count= 0, ret;
int bus_no = -1;
char fname[10];
for (i = 0; i < 32; i++) {
@ -362,6 +360,13 @@ void sg_enumerate(void)
/* found a drive */
ioctl(fd, SG_GET_SCSI_ID, &sid);
#ifdef SCSI_IOCTL_GET_BUS_NUMBER
/* Hearsay A61005 */
if (ioctl(fd, SCSI_IOCTL_GET_BUS_NUMBER, &bus_no) == -1)
bus_no = -1;
#endif
if (sg_close_drive_fd(fname, -1, &fd,
sid.scsi_type == TYPE_ROM ) <= 0)
continue;
@ -381,20 +386,27 @@ void sg_enumerate(void)
/* the final occupation will be done in sg_grab() */
sg_release_siblings(sibling_fds, &sibling_count);
}
enumerate_common(fname, sid.host_no, sid.channel,
sid.scsi_id, sid.lun);
#ifdef SCSI_IOCTL_GET_BUS_NUMBER
if(bus_no == -1)
bus_no = 1000 * (sid.host_no + 1) + sid.channel;
#else
bus_no = sid.host_no;
#endif
enumerate_common(fname, bus_no, sid.host_no, sid.channel,
sid.scsi_id, sid.lun);
}
}
/* ts A60923 : introduced new SCSI parameters */
static void enumerate_common(char *fname, int host_no, int channel_no,
int target_no, int lun_no)
/* ts A60923 - A61005 : introduced new SCSI parameters */
static void enumerate_common(char *fname, int bus_no, int host_no,
int channel_no, int target_no, int lun_no)
{
int i;
struct burn_drive *t;
struct burn_drive out;
/* ts A60923 */
out.bus_no = bus_no;
out.host = host_no;
out.id = target_no;
out.channel = channel_no;
@ -731,7 +743,7 @@ enum response scsi_error(struct burn_drive *d, unsigned char *sense,
/** Try to obtain SCSI address parameters.
@return 1 is success , 0 is failure
*/
int sg_obtain_scsi_adr(char *path, int *host_no, int *channel_no,
int sg_obtain_scsi_adr(char *path, int *bus_no, int *host_no, int *channel_no,
int *target_no, int *lun_no)
{
int fd, ret;
@ -749,8 +761,14 @@ int sg_obtain_scsi_adr(char *path, int *host_no, int *channel_no,
if(fd < 0)
return 0;
#ifdef SCSI_IOCTL_GET_BUS_NUMBER
/* Hearsay A61005 */
if (ioctl(fd, SCSI_IOCTL_GET_BUS_NUMBER, bus_no) == -1)
*bus_no = -1;
#endif
/* http://www.tldp.org/HOWTO/SCSI-Generic-HOWTO/scsi_g_idlun.html */
ret= ioctl(fd, SCSI_IOCTL_GET_IDLUN, &idlun);
ret = ioctl(fd, SCSI_IOCTL_GET_IDLUN, &idlun);
sg_close_drive_fd(path, -1, &fd, 0);
if (ret == -1)
@ -759,5 +777,11 @@ int sg_obtain_scsi_adr(char *path, int *host_no, int *channel_no,
*channel_no= (idlun.x>>16)&255;
*target_no= (idlun.x)&255;
*lun_no= (idlun.x>>8)&255;
#ifdef SCSI_IOCTL_GET_BUS_NUMBER
if(*bus_no == -1)
*bus_no = 1000 * (*host_no + 1) + *channel_no;
#else
*bus_no= *host_no;
#endif
return 1;
}

View File

@ -15,7 +15,7 @@ int sg_close_drive_fd(char *fname, int driveno, int *fd, int sorry);
/* ts A60922 ticket 33 */
int sg_give_next_adr(int *idx, char adr[], int adr_size, int initialize);
int sg_is_enumerable_adr(char *adr);
int sg_obtain_scsi_adr(char *path, int *host_no, int *channel_no,
int sg_obtain_scsi_adr(char *path, int *bus_no, int *host_no, int *channel_no,
int *target_no, int *lun_no);
/* ts A60926 : ticket 33 ++ */

View File

@ -95,6 +95,7 @@ struct scsi_mode_data
/** Gets initialized in enumerate_common() and burn_drive_register() */
struct burn_drive
{
int bus_no;
int host;
int id;
int channel;