Using libburn call burn_lookup_device_link()

This commit is contained in:
Thomas Schmitt 2011-07-28 19:51:21 +00:00
parent 982836fa0a
commit 36cfb38adc
2 changed files with 5 additions and 84 deletions

View File

@ -1119,87 +1119,6 @@ ex:;
}
/* @param link_adr must point to NULL or to allocated memory that may be freed
*/
int Xorriso_lookup_device_link(struct XorrisO *xorriso, char *dev_adr,
char **link_adr, int flag)
{
struct DirseQ *dirseq= NULL;
struct stat link_stbuf;
char *adr= NULL, *namept, *sys_adr= NULL;
int ret, name_rank, found_rank= 0x7fffffff;
static char ranks[][8] = {"dvdrw", "cdrw", "dvd", "cdrom", "cd", ""};
adr= calloc(SfileadrL + 5, 1);
sys_adr= calloc(BURN_DRIVE_ADR_LEN, 1);
if(adr == NULL || sys_adr == NULL) {
Xorriso_no_malloc_memory(xorriso, NULL, 0);
{ret= -1; goto ex;}
}
namept= adr + 5;
/* Search for candidates in /dev */
ret= Dirseq_new(&dirseq, "/dev", 1);
if(ret<0) {
sprintf(xorriso->info_text, "Cannot obtain disk directory iterator");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
{ret= -1; goto ex;}
}
strcpy(adr, "/dev/");
while(1) {
ret= Dirseq_next_adr(dirseq, namept, 0);
if(ret < 0)
goto ex;
if(ret == 0)
break;
if(lstat(adr, &link_stbuf) == -1)
{ret= 0; goto ex;}
if((link_stbuf.st_mode & S_IFMT) != S_IFLNK)
continue;
/* Determine rank and omit uninteresting ones */
for(name_rank= 0; ranks[name_rank][0]; name_rank++)
if(strncmp(namept, ranks[name_rank], strlen(ranks[name_rank])) == 0)
break;
if(ranks[name_rank][0] == 0 ||
name_rank >= found_rank) /* we look for lowest rank */
continue;
/* Does name point to the same device as dev_adr ? */
ret= burn_drive_convert_fs_adr(adr, sys_adr);
if(ret < 0)
goto ex;
if(ret == 0)
continue;
if(strcmp(dev_adr, sys_adr) == 0) {
if(*link_adr != NULL)
free(*link_adr);
*link_adr= strdup(adr);
if(*link_adr == NULL) {
Xorriso_no_malloc_memory(xorriso, NULL, 0);
{ret= -1; goto ex;}
}
found_rank= name_rank;
if(found_rank == 0)
break;
}
}
ret= 2;
if(found_rank < 0x7fffffff)
ret= 1;
ex:;
Xorriso_process_msg_queues(xorriso,0);
if(dirseq != NULL)
Dirseq_destroy(&dirseq, 0);
if(adr != NULL)
free(adr);
if(sys_adr != NULL)
free(sys_adr);
return(ret);
}
/* @param flag bit0= try to find 'meaningful' links for enumerated devices
*/
int Xorriso_show_devices(struct XorrisO *xorriso, int flag)
@ -1212,6 +1131,7 @@ int Xorriso_show_devices(struct XorrisO *xorriso, int flag)
struct stat stbuf;
Xorriso_alloc_meM(adr, char, BURN_DRIVE_ADR_LEN);
Xorriso_alloc_meM(link_adr, char, BURN_DRIVE_ADR_LEN);
sprintf(xorriso->info_text, "Beginning to scan for devices ...\n");
Xorriso_info(xorriso,0);
@ -1243,7 +1163,7 @@ int Xorriso_show_devices(struct XorrisO *xorriso, int flag)
Xorriso_process_msg_queues(xorriso,0);
adrpt= adr;
if(flag & 1) {
ret= Xorriso_lookup_device_link(xorriso, adr, &link_adr, 0);
ret= burn_lookup_device_link(adr, link_adr, "/dev", NULL, 0, 0);
if(ret < 0)
goto ex;
if(ret == 1)
@ -1269,7 +1189,7 @@ int Xorriso_show_devices(struct XorrisO *xorriso, int flag)
}
adrpt= adr;
if(flag & 1) {
ret= Xorriso_lookup_device_link(xorriso, adr, &link_adr, 0);
ret= burn_lookup_device_link(adr, link_adr, "/dev", NULL, 0, 0);
if(ret < 0)
goto ex;
if(ret == 1)
@ -1292,6 +1212,7 @@ int Xorriso_show_devices(struct XorrisO *xorriso, int flag)
ex:;
Xorriso_process_msg_queues(xorriso,0);
Xorriso_free_meM(adr);
Xorriso_free_meM(link_adr);
return(ret);
}

View File

@ -1 +1 @@
#define Xorriso_timestamP "2011.07.28.192110"
#define Xorriso_timestamP "2011.07.28.195103"