New API function burn_drive_equals_adr()

This commit is contained in:
Thomas Schmitt 2007-09-23 16:33:21 +00:00
parent 87f1c84c63
commit 344d3baaf5
3 changed files with 149 additions and 1 deletions

View File

@ -1 +1 @@
#define Cdrskin_timestamP "2007.09.22.151712"
#define Cdrskin_timestamP "2007.09.23.163301"

View File

@ -2207,3 +2207,123 @@ int burn_drive_get_drive_role(struct burn_drive *d)
return d->drive_role;
}
/* ts A70923
Hands out pointers *dpt to directory path and *npt to basename.
Caution: the last '/' in adr gets replaced by a 0.
*/
static int burn__split_path(char *adr, char **dpt, char **npt)
{
*dpt = adr;
*npt = strrchr(*dpt, '/');
if (*npt == NULL) {
*npt = *dpt;
*dpt = ".";
return 1;
}
**npt = 0;
if(*npt == *dpt)
*dpt = "/";
(*npt)++;
return 2;
}
/* ts A70923 : API */
int burn_drive_equals_adr(struct burn_drive *d1, char *adr2, int role2)
{
struct stat stbuf1, stbuf2;
char adr1[BURN_DRIVE_ADR_LEN];
char conv_adr1[BURN_DRIVE_ADR_LEN], conv_adr2[BURN_DRIVE_ADR_LEN];
char *npt1, *dpt1, *npt2, *dpt2;
int role1, stat_ret1, stat_ret2, conv_ret2;
role1 = burn_drive_get_drive_role(d1);
burn_drive_d_get_adr(d1, adr1);
stat_ret1 = stat(adr1, &stbuf1);
if (strlen(adr2) >= BURN_DRIVE_ADR_LEN)
return -1;
stat_ret2 = stat(adr2, &stbuf2);
conv_ret2 = burn_drive_convert_fs_adr(adr2, conv_adr2);
if (strcmp(adr1, adr2) == 0 && role1 == role2)
return(1); /* equal role and address */
if (role1 == 1 && role2 == 1) {
/* MMC drive meets wannabe MMC drive */
if (conv_ret2 <= 0)
return 0; /* no MMC drive at adr2 */
if (strcmp(adr1, conv_adr2) == 0)
return 1; /* equal real MMC drives */
return 0;
} else if (role1 == 0 || role2 == 0)
return 0; /* one null-drive, one not */
else if (role1 != 1 && role2 != 1) {
/* pseudo-drive meets file object */
if (stat_ret1 == -1 || stat_ret2 == -1) {
if (stat_ret1 != -1 || stat_ret2 != -1)
return 0; /* one adress existing, one not */
/* Two non-existing file objects */
strcpy(conv_adr1, adr1);
burn__split_path(conv_adr1, &dpt1, &npt1);
strcpy(conv_adr2, adr2);
burn__split_path(conv_adr2, &dpt2, &npt2);
if (strcmp(npt1, npt2))
return 0; /* basenames differ */
stat_ret1= stat(adr1, &stbuf1);
stat_ret2= stat(adr2, &stbuf2);
if (stat_ret1 != stat_ret2)
return 0; /* one dir existing, one not */
/* Both directories exist. The basenames are equal.
So the adresses are equal if the directories are
equal.*/
}
if (stbuf1.st_ino == stbuf2.st_ino &&
stbuf1.st_dev == stbuf2.st_dev)
return 1; /* same filesystem object */
if (S_ISBLK(stbuf1.st_mode) && S_ISBLK(stbuf2.st_mode) &&
stbuf1.st_rdev == stbuf2.st_rdev)
return 1; /* same major,minor device number */
/* Are both filesystem objects related to the same MMC drive */
if (conv_ret2 <= 0)
return 0; /* no MMC drive at adr2 */
if (burn_drive_convert_fs_adr(adr1, conv_adr1) <= 0)
return 0; /* no MMC drive at adr1 */
if (strcmp(conv_adr1, conv_adr2) == 0)
return 1; /* same MMC drive */
return 0; /* all filesystem disguises are checked */
} else if (role1 == 1 && role2 != 1) {
/* MMC drive meets file object */
if (conv_ret2 <= 0)
return 0; /* no MMC drive at adr2 */
if (strcmp(adr1, conv_adr2) == 0)
return 1; /* same MMC drive */
return 0;
} else if (role1 != 1 && role2 == 1) {
/* stdio-drive meets wannabe MMC drive */
if (conv_ret2 <= 0)
return 0; /* no MMC drive at adr2 */
if (burn_drive_convert_fs_adr(adr1, conv_adr1) <= 0)
return 0; /* no MMC drive at adr1 */
if (strcmp(conv_adr1, conv_adr2) == 0)
return 1; /* same MMC drive */
return 0;
}
return 0; /* now i believe they are really not equal */
}

View File

@ -1998,6 +1998,7 @@ int burn_read_data(struct burn_drive *d, off_t byte_address,
char data[], off_t data_size, off_t *data_count, int flag);
/* A70904 */
/** Inquire wether the drive object is a real MMC drive or a pseudo-drive
created by burn_drive_dummy().
@param d The drive to inquire
@ -2008,6 +2009,33 @@ int burn_read_data(struct burn_drive *d, off_t byte_address,
int burn_drive_get_drive_role(struct burn_drive *d);
/* ts A70923 */
/** Find out wether a given address string would lead to the given drive
object. This should be done in advance for track source addresses
with parameter drive_role set to 2.
Although a real MMC drive should hardly exist as two drive objects at
the same time, this can easily happen with stdio-drives. So if more than
one drive is used by the application, then this gesture is advised:
burn_drive_d_get_adr(d2, adr2);
if (burn_drive_equals_adr(d1, adr2, burn_drive_get_drive_role(d2)))
... Both drive objects point to the same storage facility ...
@param d1 Existing drive object
@param adr2 Address string to be tested. Prefix "stdio:" overrides
parameter drive_role2 by either 0 or 2 as appropriate.
The string must be shorter than BURN_DRIVE_ADR_LEN.
@param drive_role2 Role as burn_drive_get_drive_role() would attribute
to adr2 if it was a drive. Use value 2 for checking track
sources resp. pseudo-drive addresses without "stdio:".
Use 1 for checking drive addresses including those with
prefix "stdio:".
@return 1= adr2 leads to d1 , 0= adr2 seems not to lead to d1,
-1 = adr2 is bad
*/
int burn_drive_equals_adr(struct burn_drive *d1, char *adr2, int drive_role2);
#ifndef DOXYGEN
BURN_END_DECLS