--- cdrdao-1.2.0.orig/scsilib/libscg/scsitransp.c +++ cdrdao-1.2.0/scsilib/libscg/scsitransp.c @@ -52,8 +52,8 @@ * Choose your name instead of "schily" and make clear that the version * string is related to a modified source. */ -LOCAL char _scg_version[] = "0.8"; /* The global libscg version */ -LOCAL char _scg_auth_schily[] = "schily"; /* The author for this module */ +LOCAL char _scg_version[] = "0.8ubuntu1"; /* The global libscg version */ +LOCAL char _scg_auth_ubuntu[] = "ubuntu"; /* The author for this module */ #define DEFTIMEOUT 20 /* Default timeout for SCSI command transport */ @@ -137,7 +137,7 @@ * return "schily" for the SCG_AUTHOR request. */ case SCG_AUTHOR: - return (_scg_auth_schily); + return (_scg_auth_ubuntu); case SCG_SCCS_ID: return (sccsid); default: --- cdrdao-1.2.0.orig/scsilib/libscg/scsi-linux-ata.c +++ cdrdao-1.2.0/scsilib/libscg/scsi-linux-ata.c @@ -267,7 +267,7 @@ starget, slun; - f = open(device, O_RDWR | O_NONBLOCK); + f = sg_open_excl(device, O_RDWR | O_NONBLOCK); if (f < 0) { if (scgp->errstr) @@ -319,7 +319,7 @@ for (i = 0; globbuf.gl_pathv && globbuf.gl_pathv[i] != NULL ; i++) { device = globbuf.gl_pathv[i]; - if ((f = open(device, O_RDWR | O_NONBLOCK)) < 0) { + if ((f = sg_open_excl(device, O_RDWR | O_NONBLOCK)) < 0) { if (errno != ENOENT && errno != ENXIO && errno != ENODEV && errno != EACCES) { if (scgp->debug > 4) { js_fprintf((FILE *) scgp->errfile, --- cdrdao-1.2.0.orig/scsilib/libscg/scsi-linux-pg.c +++ cdrdao-1.2.0/scsilib/libscg/scsi-linux-pg.c @@ -211,7 +211,7 @@ return (0); #endif js_snprintf(devname, sizeof (devname), "/dev/pg%d", tgt); - f = open(devname, O_RDWR | O_NONBLOCK); + f = sg_open_excl(devname, O_RDWR | O_NONBLOCK); if (f < 0) { if (scgp->errstr) js_snprintf(scgp->errstr, SCSI_ERRSTR_SIZE, @@ -228,7 +228,7 @@ for (i = 0; globbuf.gl_pathv && globbuf.gl_pathv[i] != NULL ; i++) { dev = globbuf.gl_pathv[i]; tgt = atoi(&dev[7]); - f = open(dev, O_RDWR | O_NONBLOCK); + f = sg_open_excl(dev, O_RDWR | O_NONBLOCK); if (f < 0) { /* * Set up error string but let us clear it later @@ -261,7 +261,7 @@ if (tlun < 0) return (0); - f = open(device, O_RDWR | O_NONBLOCK); + f = sg_open_excl(device, O_RDWR | O_NONBLOCK); /* if (f < 0 && errno == ENOENT) {*/ if (f < 0) { if (scgp->errstr) --- cdrdao-1.2.0.orig/scsilib/libscg/scsi-linux-sg.c +++ cdrdao-1.2.0/scsilib/libscg/scsi-linux-sg.c @@ -199,6 +199,8 @@ /*#define MISALIGN*/ /*#undef SG_GET_BUFSIZE*/ +int sg_open_excl __PR((char *device, int mode)); + #if defined(USE_PG) && !defined(USE_PG_ONLY) #include "scsi-linux-pg.c" #endif @@ -225,6 +227,30 @@ #endif LOCAL void sg_settimeout __PR((int f, int timeout)); + +int +sg_open_excl(device, mode) + char *device; + int mode; +{ + int f; + int i; + f = open(device, mode|O_EXCL); + if (f == -1 && (errno == EACCES || errno == EBUSY)) { + fprintf(stderr, "Error trying to open %s exclusively (%s)...retrying...\n", device, strerror(errno)); + } + for (i = 0; (i < 10) && (f == -1 && (errno == EACCES || errno == EBUSY)); i++) { + usleep(1000000 + 100000.0 * rand()/(RAND_MAX+1.0)); + f = open(device, mode|O_EXCL); + } + /* Open it anyway to make scanbus happy */ + if (f == -1) { + f = open(device, mode); + } + return f; +} + + /* * Return version information for the low level SCSI transport code. * This has been introduced to make it easier to trace down problems @@ -407,7 +433,7 @@ for (i = 0; globbuf.gl_pathv && globbuf.gl_pathv[i] != NULL ; i++) { devname = globbuf.gl_pathv[i]; - f = open(devname, O_RDWR | O_NONBLOCK); + f = sg_open_excl(devname, O_RDWR | O_NONBLOCK); if (f < 0) { /* * Set up error string but let us clear it later @@ -452,12 +478,13 @@ if (nopen == 0) { glob("/dev/scd[0-9]", GLOB_NOSORT, NULL, &globbuf); glob("/dev/scd[0-9][0-9]", GLOB_NOSORT|GLOB_APPEND, NULL, &globbuf); - /*glob("/dev/sg[a-z]", GLOB_NOSORT|GLOB_APPEND, NULL, &globbuf);*/ + glob("/dev/sg[a-z]", GLOB_NOSORT|GLOB_APPEND, NULL, &globbuf); + glob("/dev/sg[0-9]", GLOB_NOSORT|GLOB_APPEND, NULL, &globbuf); for (i = 0; globbuf.gl_pathv && globbuf.gl_pathv[i] != NULL ; i++) { devname = globbuf.gl_pathv[i]; - f = open(devname, O_RDWR | O_NONBLOCK); + f = sg_open_excl(devname, O_RDWR | O_NONBLOCK); if (f < 0) { /* * Set up error string but let us clear it later @@ -466,7 +493,7 @@ if (scgp->errstr) js_snprintf(scgp->errstr, SCSI_ERRSTR_SIZE, "Cannot open '/dev/scd*'"); - if (errno != ENOENT && errno != ENXIO && errno != ENODEV) { + if (errno != ENOENT && errno != ENXIO && errno != ENODEV && errno != EROFS) { if (scgp->errstr) js_snprintf(scgp->errstr, SCSI_ERRSTR_SIZE, "Cannot open '%s'", devname); @@ -510,7 +537,7 @@ "Warning: Open by 'devname' is unintentional and not supported.\n"); } /* O_NONBLOCK is dangerous */ - f = open(device, O_RDWR | O_NONBLOCK); + f = sg_open_excl(device, O_RDWR | O_NONBLOCK); /* if (f < 0 && errno == ENOENT)*/ /* goto openpg;*/