Implemented finding matching /dev/sgN from /dev/srM or /dev/scdK

This commit is contained in:
Thomas Schmitt 2006-09-22 19:29:11 +00:00
parent d0d0af1ba5
commit b67c555b30
3 changed files with 86 additions and 6 deletions

View File

@ -724,7 +724,7 @@ int burn_drive_find_devno(dev_t devno, char adr[])
if(strlen(fname) >= BURN_DRIVE_ADR_LEN)
return -1;
fprintf(stderr,"libburn experimental: burn_drive_find_devno( 0x%llX ) found %s\n", (long long) devno, fname);
fprintf(stderr,"libburn experimental: burn_drive_find_devno( 0x%lX ) found %s\n", (long) devno, fname);
strcpy(adr, fname);
return 1;
@ -732,6 +732,52 @@ fprintf(stderr,"libburn experimental: burn_drive_find_devno( 0x%llX ) found %s\n
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_adr(char *path, char adr[])
{
char fname[4096];
int i, ret = 0, first = 1;
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,
&lun_no);
if(ret <= 0) {
fprintf(stderr,"libburn experimental: sg_obtain_scsi_adr( %s ) returns %d\n", path, ret);
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);
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 == -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;
}
/* ts A60922 ticket 33 */
/** Try to convert a given existing filesystem address into a persistent drive
address. */
@ -768,11 +814,9 @@ fprintf(stderr,"libburn experimental: lstat( %s ) returns -1\n",path);
ret = burn_drive_find_devno(stbuf.st_rdev, adr);
if(ret > 0)
return 1;
/* >>> if SCSI device :
try to find enumerated device with same Bus,Target,Lun
*/;
ret = burn_drive_find_scsi_adr(path, adr);
if(ret > 0)
return 1;
}
fprintf(stderr,"libburn experimental: Nothing found for %s \n",path);

View File

@ -248,6 +248,9 @@ void sg_enumerate(void)
close(fd);
if (sid.scsi_type != TYPE_ROM)
continue;
/* <<< ts A60922 (use SCSI_IOCTL_GET_IDLUN on block devices)
fprintf(stderr,"libburn experimental: SCSI triple: %d,%d,%d\n",sid.host_no,sid.scsi_id,sid.lun);
*/
enumerate_common(fname);
}
@ -556,3 +559,34 @@ enum response scsi_error(struct burn_drive *d, unsigned char *sense,
burn_print(1, "key:0x%x, asc:0x%x, ascq:0x%x\n", key, asc, ascq);
return FAIL;
}
/* ts A60922 */
/** 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 *target_no, int *lun_no)
{
int fd, ret;
struct my_scsi_idlun {
int x;
int host_unique_id;
};
struct my_scsi_idlun idlun;
fd = open(path, O_RDONLY | O_NONBLOCK);
if(fd < 0)
return 0;
/* http://www.tldp.org/HOWTO/SCSI-Generic-HOWTO/scsi_g_idlun.html */
ret= ioctl(fd, SCSI_IOCTL_GET_IDLUN, &idlun);
close(fd);
if(ret == -1)
return(0);
*host_no= (idlun.x>>24)&255;
*channel_no= (idlun.x>>16)&255;
*target_no= (idlun.x)&255;
*lun_no= (idlun.x>>8)&255;
return 1;
}

View File

@ -12,6 +12,8 @@ enum response
/* 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 *target_no, int *lun_no);
void sg_enumerate(void);
void ata_enumerate(void);