New API function isoburn_get_mount_params()

This commit is contained in:
Thomas Schmitt 2008-12-05 17:10:27 +00:00
parent 6aea5f981f
commit c8d9e6d91d
3 changed files with 120 additions and 9 deletions

View File

@ -24,6 +24,7 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <time.h>
#include <regex.h>
#ifndef Xorriso_standalonE
@ -1041,7 +1042,9 @@ int isoburn_read_iso_head(struct burn_drive *d, int lba,
}
ret= isoburn_read_iso_head_parse(d, buffer+32*1024, image_blocks, info,
info_mode);
if(ret<=0)
return(ret);
return(1);
}
@ -1509,12 +1512,14 @@ int isoburn_drive_set_msgs_submit(struct burn_drive *d,
/* @param flag bit0= with adr_mode 3: adr_value might be 16 blocks too high
bit1= insist in seeing a disc object with at least one session
bit2= with adr_mode 4: use adr_value as regular expression
*/
int isoburn_set_msc1(struct burn_drive *d, int adr_mode, char *adr_value,
int flag)
{
int ret, num_sessions, num_tracks, adr_num, i, j, total_tracks;
int lba, best_lba, size;
int lba, best_lba, size, re_valid= 0;
char volid[33], msg[160];
struct isoburn *o;
struct isoburn_toc_disc *disc= NULL;
@ -1522,6 +1527,8 @@ int isoburn_set_msc1(struct burn_drive *d, int adr_mode, char *adr_value,
struct isoburn_toc_track **tracks= NULL;
static char mode_names[][20]= {"auto", "session", "track", "lba", "volid"};
static int max_mode_names= 4;
regex_t re;
regmatch_t match[1];
ret= isoburn_find_emulator(&o, d, 0);
if(ret<0)
@ -1530,7 +1537,7 @@ int isoburn_set_msc1(struct burn_drive *d, int adr_mode, char *adr_value,
return(-1);
adr_num= atoi(adr_value);
if(adr_mode!=3) {
if(adr_mode!=3 || (flag & 2)) {
disc= isoburn_toc_drive_get_disc(d);
if(disc==NULL) {
not_found:;
@ -1589,6 +1596,13 @@ not_found:;
}
} else if(adr_mode==4) {
/* search for volume id that is equal to adr_value */
if(flag & 4) {
ret= regcomp(&re, adr_value, 0);
if(ret != 0)
flag&= ~4;
else
re_valid= 1;
}
best_lba= -1;
for(i=0; i<num_sessions; i++) {
tracks= isoburn_toc_session_get_tracks(sessions[i], &num_tracks);
@ -1599,8 +1613,14 @@ not_found:;
ret= isoburn_read_iso_head(d, lba, &size, volid, 1);
if(ret<=0)
continue;
if(flag & 4) {
ret= regexec(&re, volid, 1, match, 0);
if(ret != 0)
continue;
} else {
if(strcmp(volid, adr_value)!=0)
continue;
}
best_lba= lba;
}
}
@ -1618,7 +1638,64 @@ unknown_mode:;
ex:;
if(disc!=NULL)
isoburn_toc_disc_free(disc);
if((flag & 4) && re_valid)
regfree(&re);
return(ret);
}
int isoburn_get_mount_params(struct burn_drive *d,
int adr_mode, char *adr_value,
int *lba, int *track, int *session,
char volid[33], int flag)
{
int msc1_mem, ret, total_tracks, num_sessions, num_tracks, i, j, track_lba;
int size, is_iso= 0;
struct isoburn *o;
struct isoburn_toc_disc *disc= NULL;
struct isoburn_toc_session **sessions= NULL;
struct isoburn_toc_track **tracks= NULL;
*lba= *track= *session= -1;
volid[0]= 0;
ret= isoburn_find_emulator(&o, d, 0);
if(ret < 0 || o == NULL)
return(-1);
msc1_mem= o->fabricated_msc1;
ret= isoburn_set_msc1(d, adr_mode, adr_value, 2 | (flag & 4));
if(ret <= 0)
return(ret);
*lba= o->fabricated_msc1;
disc= isoburn_toc_drive_get_disc(d);
if(disc==NULL)
{ret= -1; goto ex;} /* cannot happen because checked by isoburn_set_msc1 */
sessions= isoburn_toc_disc_get_sessions(disc, &num_sessions);
if(sessions==NULL || num_sessions<=0)
{ret= -1; goto ex;} /* cannot happen because checked by isoburn_set_msc1 */
total_tracks= 0;
for(i=0; i<num_sessions && *session < 0; i++) {
tracks= isoburn_toc_session_get_tracks(sessions[i], &num_tracks);
if(tracks==NULL)
continue;
for(j= 0; j<num_tracks && *track < 0; j++) {
total_tracks++;
isoburn_get_track_lba(tracks[j], &track_lba, 0);
if(track_lba == *lba) {
*track= total_tracks;
*session= i + 1;
}
}
}
ret= isoburn_read_iso_head(d, *lba, &size, volid, 1);
if(ret <= 0)
volid[0]= 0;
else
is_iso= 1;
ex:;
o->fabricated_msc1= msc1_mem;
return(2 - is_iso);
}

View File

@ -336,7 +336,8 @@ int isoburn_set_msgs_submit(int (*msgs_submit)(void *handle, int error_code,
(cdrom/burner). Thus use with driveno 0 only. On failure
the array has no valid elements at all.
The returned array should be freed via burn_drive_info_free()
when the drive is no longer needed.
when the drive is no longer needed. But before this is done
one has to call isoburn_drive_release(drive_infos[0].drive).
@param adr The persistent address of the desired drive.
@param load 1 attempt to load the disc tray. 0 no attempt,rather failure.
@return 1 = success , 0 = drive not found , <0 = other error
@ -353,7 +354,8 @@ int isoburn_drive_scan_and_grab(struct burn_drive_info *drive_infos[],
(cdrom/burner). Thus use with driveno 0 only. On failure
the array has no valid elements at all.
The returned array should be freed via burn_drive_info_free()
when the drive is no longer needed.
when the drive is no longer needed. But before this is done
one has to call isoburn_drive_release(drive_infos[0].drive).
@param adr The persistent address of the desired drive.
@param flag bit0= attempt to load the disc tray.
Else: failure if not loaded.
@ -375,6 +377,7 @@ int isoburn_drive_aquire(struct burn_drive_info *drive_infos[],
Wrapper for: burn_drive_grab()
@since 0.1.0
@param drive The drive to grab. E.g. drive_infos[1].drive .
Call isoburn_drive_release(drive) when it it no longer needed.
@param load 1 attempt to load the disc tray. 0 no attempt, rather failure.
@return 1 success, <=0 failure
*/
@ -450,12 +453,14 @@ void isoburn_disc_erase(struct burn_drive *drive, int fast);
3= adr_value itself is the lba to be used
4= start lba of last session with volume id
given by adr_value
@parm adr_value A string describing the value to be eventually used.
@param adr_value A string describing the value to be eventually used.
@param flag Bitfield for control purposes.
bit0= @since 0.2.2
with adr_mode 3: adr_value might be 16 blocks too high
(e.g. -C stemming from growisofs). Probe for ISO head
at adr_value-16 and eventually adjust setting.
bit1= insist in seeing a disc object with at least one session
bit2= with adr_mode 4: use adr_value as regular expression
*/
int isoburn_set_msc1(struct burn_drive *d, int adr_mode, char *adr_value,
int flag);
@ -600,6 +605,35 @@ int isoburn_read_iso_head(struct burn_drive *d, int lba,
int *image_blocks, char *info, int flag);
/** Try to convert the given entity address into various entity addresses
which would describe it.
Note: Sessions and tracks are counted beginning with 1, not with 0.
@since 0.3.2
@param drive The drive where msc1 is to be set
@param adr_mode Determines how to interpret the input adr_value.
If adr_value shall represent a number then decimal ASCII
digits are expected.
0= start lba of last session in TOC, ignore adr_value
1= start lba of session number given by adr_value
2= start lba of track given number by adr_value
3= adr_value itself is the lba to be used
4= start lba of last session with volume id
given by adr_value
@param adr_value A string describing the value to be eventually used.
@param lba returns the block address of the entity, -1 means invalid
@param track returns the track number of the entity, -1 means invalid
@param session returns the session number of the entity, -1 means invalid
@param volid returns the volume id of the entity if it is a ISO session
@param flag Bitfield for control purposes.
bit2= with adr_mode 4: use adr_value as regular expression
@return <=0 error , 1 ok, ISO session, 2 ok, not an ISO session
*/
int isoburn_get_mount_params(struct burn_drive *d,
int adr_mode, char *adr_value,
int *lba, int *track, int *session,
char volid[33], int flag);
/* ----------------------------------------------------------------------- */
/*
@ -1243,7 +1277,7 @@ void isoburn_disc_write(struct burn_write_opts *o, struct burn_disc *disc);
Hint: If only burn_write_opts and not burn_drive is known, then the drive
can be obtained by burn_write_opts_get_drive().
@since 0.1.0
@parm d The drive to which the track with the fifo gets burned.
@param d The drive to which the track with the fifo gets burned.
@param size The total size of the fifo
@param free_bytes The current free capacity of the fifo
@param status_text Returns a pointer to a constant text, see below

View File

@ -1 +1 @@
#define Xorriso_timestamP "2008.12.04.175459"
#define Xorriso_timestamP "2008.12.05.171005"