Restructured SCSI search, removed a potential bug with hdX

This commit is contained in:
Thomas Schmitt 2006-09-23 07:58:43 +00:00
parent 1bcb837db2
commit f29b20dc24
2 changed files with 50 additions and 29 deletions

View File

@ -1 +1 @@
#define Cdrskin_timestamP "2006.09.22.203939" #define Cdrskin_timestamP "2006.09.23.080015"

View File

@ -733,14 +733,54 @@ fprintf(stderr,"libburn experimental: burn_drive_find_devno( 0x%lX ) found %s\n"
} }
/* ts A60922 ticket 33 */ /* ts A60922 ticket 33 */
/* Try to find an enumerated address with the same host,channel,target,lun /* Try to find an enumerated address with the same host,channel,target,lun.
as path */ If a _no parameter is < 0 then it matches any number.
int burn_drive_find_scsi_adr(char *path, char adr[]) */
int burn_drive_convert_scsi_adr(int host_no, int channel_no, int target_no,
int lun_no, char adr[])
{ {
char fname[4096]; char fname[4096];
int i, ret = 0, first = 1; int i, ret = 0, first = 1;
int i_host_no = -1, i_channel_no = -1, i_target_no = -1, i_lun_no = -1;
fprintf(stderr,"libburn experimental: burn_drive_convert_scsi_adr( %d,%d,%d,%d )\n", host_no, channel_no, target_no, lun_no);
while (1) {
ret= sg_give_next_adr(&i, fname, sizeof(fname), first);
if(ret <= 0)
break;
first = 0;
ret = sg_obtain_scsi_adr(fname, &i_host_no, &i_channel_no,
&i_target_no, &i_lun_no);
if(ret <= 0)
continue;
if(host_no >=0 && i_host_no != host_no)
continue;
if(channel_no >= 0 && i_channel_no != channel_no)
continue;
if(target_no >= 0 && i_target_no != target_no)
continue;
if(lun_no >= 0 && i_lun_no != lun_no)
continue;
if(strlen(fname) >= BURN_DRIVE_ADR_LEN)
return -1;
fprintf(stderr,"libburn experimental: burn_drive_convert_scsi_adr() found %s\n", fname);
strcpy(adr, fname);
return 1;
}
return 0;
}
/* ts A60922 ticket 33 */
/* Try to find an enumerated address with the same host,channel,target,lun
as path */
int burn_drive_find_scsi_equiv(char *path, char adr[])
{
int ret = 0;
int host_no, channel_no, target_no, lun_no; int host_no, channel_no, target_no, lun_no;
int i_host_no, i_channel_no, i_target_no, i_lun_no;
ret = sg_obtain_scsi_adr(path, &host_no, &channel_no, &target_no, ret = sg_obtain_scsi_adr(path, &host_no, &channel_no, &target_no,
&lun_no); &lun_no);
@ -751,30 +791,11 @@ fprintf(stderr,"libburn experimental: sg_obtain_scsi_adr( %s ) returns %d\n", pa
return 0; return 0;
} }
fprintf(stderr,"libburn experimental: burn_drive_find_scsi_adr( %s ) : %d,%d,%d,%d\n", path, host_no, channel_no, target_no, lun_no); fprintf(stderr,"libburn experimental: burn_drive_find_scsi_equiv( %s ) : %d,%d,%d,%d\n", path, host_no, channel_no, target_no, lun_no);
ret= burn_drive_convert_scsi_adr(host_no, channel_no, target_no,
while (1) { lun_no, adr);
ret= sg_give_next_adr(&i, fname, sizeof(fname), first); return ret;
if(ret <= 0)
break;
first = 0;
ret = sg_obtain_scsi_adr(fname, &i_host_no, &i_channel_no,
&i_target_no, &i_lun_no);
if(ret == -1)
continue;
if(i_host_no != host_no || i_channel_no != channel_no ||
i_target_no != target_no || i_lun_no != lun_no)
continue;
if(strlen(fname) >= BURN_DRIVE_ADR_LEN)
return -1;
fprintf(stderr,"libburn experimental: burn_drive_find_scsi_adr( %s ) found %s\n", path, fname);
strcpy(adr, fname);
return 1;
}
return 0;
} }
@ -814,7 +835,7 @@ fprintf(stderr,"libburn experimental: lstat( %s ) returns -1\n",path);
ret = burn_drive_find_devno(stbuf.st_rdev, adr); ret = burn_drive_find_devno(stbuf.st_rdev, adr);
if(ret > 0) if(ret > 0)
return 1; return 1;
ret = burn_drive_find_scsi_adr(path, adr); ret = burn_drive_find_scsi_equiv(path, adr);
if(ret > 0) if(ret > 0)
return 1; return 1;
} }