From 42585d6bcf7cc40a32d54823f7b5eec9bdb0764c Mon Sep 17 00:00:00 2001 From: Mario Danic Date: Tue, 15 Aug 2006 20:40:30 +0000 Subject: [PATCH] Implemented persistent drive adresses, method to leave all drives but one untouched --- trunk/libburn/drive.c | 43 +++++++++++++++++++++++++++++++++++++++++ trunk/libburn/libburn.h | 12 ++++++++++++ trunk/libburn/sg.c | 9 +++++++++ 3 files changed, 64 insertions(+) diff --git a/trunk/libburn/drive.c b/trunk/libburn/drive.c index a96816a4..a33260b6 100644 --- a/trunk/libburn/drive.c +++ b/trunk/libburn/drive.c @@ -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; +} diff --git a/trunk/libburn/libburn.h b/trunk/libburn/libburn.h index 7506ed3b..fa7fb6ab 100644 --- a/trunk/libburn/libburn.h +++ b/trunk/libburn/libburn.h @@ -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 diff --git a/trunk/libburn/sg.c b/trunk/libburn/sg.c index cbcbf1e9..b9de49e6 100644 --- a/trunk/libburn/sg.c +++ b/trunk/libburn/sg.c @@ -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;