Implemented persistent drive adresses, method to leave all drives but one untouched

This commit is contained in:
Mario Danic 2006-08-15 20:40:30 +00:00
parent 2f2c115e08
commit 12ebc4002d
3 changed files with 64 additions and 0 deletions

View File

@ -367,3 +367,46 @@ int burn_drive_get_write_speed(struct burn_drive *d)
{
return d->mdata->max_write_speed;
}
/* ts A51221 */
static char *enumeration_whitelist[BURN_DRIVE_WHITELIST_LEN];
static int enumeration_whitelist_top = -1;
/** Add a device to the list of permissible drives. As soon as some entry is in
the whitelist all non-listed drives are banned from enumeration.
@return 1 success, <=0 failure
*/
int burn_drive_add_whitelist(char *device_address)
{
char *new_item;
if(enumeration_whitelist_top+1 >= BURN_DRIVE_WHITELIST_LEN)
return 0;
enumeration_whitelist_top++;
new_item = malloc(strlen(device_address) + 1);
if (new_item == NULL)
return -1;
strcpy(new_item, device_address);
enumeration_whitelist[enumeration_whitelist_top] = new_item;
return 1;
}
/** Remove all drives from whitelist. This enables all possible drives. */
void burn_drive_clear_whitelist(void)
{
int i;
for (i = 0; i <= enumeration_whitelist_top; i++)
free(enumeration_whitelist[i]);
enumeration_whitelist_top = -1;
}
int burn_drive_is_banned(char *device_address)
{
int i;
if(enumeration_whitelist_top<0)
return 0;
for (i = 0; i <= enumeration_whitelist_top; i++)
if (strcmp(enumeration_whitelist[i], device_address) == 0)
return 0;
return 1;
}

View File

@ -451,6 +451,18 @@ struct burn_message* burn_get_message(void);
/** Frees a burn_message structure */
void burn_message_free(struct burn_message *msg);
/* ts A51221 */
/** Maximum number of particularly permissible drive addresses */
#define BURN_DRIVE_WHITELIST_LEN 255
/** Add a device to the list of permissible drives. As soon as some entry is in
the whitelist all non-listed drives are banned from enumeration.
@return 1 success, <=0 failure
*/
int burn_drive_add_whitelist(char *device_address);
/** Remove all drives from whitelist. This enables all possible drives. */
void burn_drive_clear_whitelist(void);
/** Scans for drives. This function MUST be called until it returns nonzero.
No drives can be in use when this is called or it will assert.
All drive pointers are invalidated by using this function. Do NOT store

View File

@ -25,6 +25,9 @@
static void enumerate_common(char *fname);
/* ts A51221 */
int burn_drive_is_banned(char *device_address);
static int sgio_test(int fd)
{
unsigned char test_ops[] = { 0, 0, 0, 0, 0, 0 };
@ -50,6 +53,9 @@ void ata_enumerate(void)
/* open O_RDWR so we don't think read only drives are
in some way useful
*/
/* ts A51221 */
if (burn_drive_is_banned(fname))
continue;
fd = open(fname, O_RDWR | O_NONBLOCK);
if (fd == -1)
continue;
@ -85,6 +91,9 @@ void sg_enumerate(void)
/* open RDWR so we don't accidentally think read only drives
are in some way useful
*/
/* ts A51221 */
if (burn_drive_is_banned(fname))
continue;
fd = open(fname, O_RDWR);
if (fd == -1)
continue;