[Debburn-changes] r607 - in cdrkit/trunk: . libusal
Eduard Bloch
blade at alioth.debian.org
Sun Dec 10 18:55:42 CET 2006
Author: blade
Date: 2006-12-10 18:55:42 +0100 (Sun, 10 Dec 2006)
New Revision: 607
Modified:
cdrkit/trunk/Changelog
cdrkit/trunk/TODO
cdrkit/trunk/libusal/scsi-linux-sg.c
Log:
Max. DMA buffer size fishing in sysfs
Modified: cdrkit/trunk/Changelog
===================================================================
--- cdrkit/trunk/Changelog 2006-12-10 13:06:12 UTC (rev 606)
+++ cdrkit/trunk/Changelog 2006-12-10 17:55:42 UTC (rev 607)
@@ -11,6 +11,7 @@
* cleanup with unused embedded CVS revision strings from Schilling and
more gcc -Wall correctness
* reenabled -format functionality (bug in program function control flow)
+ * get maximum DMA buffer size from sysfs on Linux, where possible
[ Thomas Schmidt ]
* workaround for older libmagic API
Modified: cdrkit/trunk/TODO
===================================================================
--- cdrkit/trunk/TODO 2006-12-10 13:06:12 UTC (rev 606)
+++ cdrkit/trunk/TODO 2006-12-10 17:55:42 UTC (rev 607)
@@ -1,3 +1,6 @@
+ - import libcuefile from on cuetools-1.3.1/src/lib (after generating the
+ parser with its build system), add CMakeLists.txt, drop cue.c and make wodim
+ make use of the parsed CUE data if available.
- check the REMOTE method, especially with real device names and ssh.
Something is going wrong.
Modified: cdrkit/trunk/libusal/scsi-linux-sg.c
===================================================================
--- cdrkit/trunk/libusal/scsi-linux-sg.c 2006-12-10 13:06:12 UTC (rev 606)
+++ cdrkit/trunk/libusal/scsi-linux-sg.c 2006-12-10 17:55:42 UTC (rev 607)
@@ -65,6 +65,8 @@
*/
#include <linux/version.h>
+#include <sys/types.h>
+#include <dirent.h>
#ifndef LINUX_VERSION_CODE /* Very old kernel? */
# define LINUX_VERSION_CODE 0
@@ -241,6 +243,8 @@
int sg_open_excl(char *device, int mode);
+static BOOL get_max_secs(char *dirpath, int *outval);
+
int
sg_open_excl(char *device, int mode)
@@ -936,6 +940,7 @@
static long
usalo_maxdma(SCSI *usalp, long amt)
{
+ struct stat stbuf;
long maxdma = MAX_DMA_LINUX;
#if defined(SG_SET_RESERVED_SIZE) && defined(SG_GET_RESERVED_SIZE)
@@ -946,6 +951,46 @@
if (usallocal(usalp)->drvers >= 20134)
maxdma = sg_raisedma(usalp, amt);
#endif
+ /*
+ * First try the modern kernel 2.6.1x way to detect the real maximum
+ * DMA for this specific device, then try the other methods.
+ */
+ if(0==fstat(usallocal(usalp)->usalfile, &stbuf)) {
+ /* that's ugly, there are so many symlinks in sysfs but none from major:minor to the relevant directory */
+ static char *basedirs[] = { "/sys/block", "/sys/class/scsi_generic" };
+ int i,j;
+ char buf[256], idbuf[10];
+ int l;
+ l=snprintf(idbuf, sizeof(idbuf), "%d:%d", stbuf.st_rdev>>8, stbuf.st_rdev&0xFF);
+ if (usalp->debug > 0)
+ fprintf(stderr, "Looking for data for major:minor: %s\n", idbuf);
+ for(i=0;i<2;i++) {
+ struct dirent *dent;
+ DIR *ddesc = opendir(basedirs[i]);
+ if(!ddesc) continue;
+ while( NULL != (dent = readdir(ddesc))) {
+ FILE *fd;
+ if(dent->d_name[0]=='.')
+ continue;
+ snprintf(buf, 256, "%s/%s/dev", basedirs[i], dent->d_name);
+ fd=fopen(buf, "r");
+ if(!fd) continue;
+ buf[0]='\0';
+ fgets(buf, sizeof(buf)-1, fd);
+ fclose(fd);
+ if(0==strncmp(idbuf, buf, l)) { /* got the right dir */
+ snprintf(buf, 256, "%s/%s/queue/max_sectors_kb", basedirs[i], dent->d_name);
+ fd=fopen(buf, "r");
+ if(!fd) continue;
+ buf[0]='\0';
+ fgets(buf, sizeof(buf)-1, fd);
+ fclose(fd);
+ return(512*atoi(buf));
+ }
+ }
+ closedir(ddesc);
+ }
+ }
#ifdef SG_GET_BUFSIZE
/*
* We assume that all /dev/sg instances use the same
@@ -1632,3 +1677,4 @@
sg_settimeout(f, usalp->deftimeout);
return (0);
}
+
More information about the Debburn-changes
mailing list