summaryrefslogtreecommitdiff
path: root/sysutils/k3b-kde4/files/patch-src-device-k3bdevicemanager.cpp
diff options
context:
space:
mode:
authorMark Linimon <linimon@FreeBSD.org>2004-05-28 05:52:01 +0000
committerMark Linimon <linimon@FreeBSD.org>2004-05-28 05:52:01 +0000
commit7b2a844d4f0ada056bd21e55082c6788546119b5 (patch)
tree2308a9c96cccba77806e86ba3c6f70895b454638 /sysutils/k3b-kde4/files/patch-src-device-k3bdevicemanager.cpp
parentHandle NeverEmbed CJK TrueType into PDF, and write correct glyph widths (diff)
Upgrade to 0.11.9.
Note: upgraders from 0.11.6 or below should note the changed topic 3C in pkg-message. PR: ports/67238 Submitted by: Heiner Eichmann <h.eichmann at gmx dot de> (maintainer)
Notes
Notes: svn path=/head/; revision=110165
Diffstat (limited to 'sysutils/k3b-kde4/files/patch-src-device-k3bdevicemanager.cpp')
-rw-r--r--sysutils/k3b-kde4/files/patch-src-device-k3bdevicemanager.cpp303
1 files changed, 142 insertions, 161 deletions
diff --git a/sysutils/k3b-kde4/files/patch-src-device-k3bdevicemanager.cpp b/sysutils/k3b-kde4/files/patch-src-device-k3bdevicemanager.cpp
index 75ba9c14b38f..7b40314e293a 100644
--- a/sysutils/k3b-kde4/files/patch-src-device-k3bdevicemanager.cpp
+++ b/sysutils/k3b-kde4/files/patch-src-device-k3bdevicemanager.cpp
@@ -1,5 +1,5 @@
---- src/device/k3bdevicemanager.cpp.orig Wed Jan 21 11:20:10 2004
-+++ src/device/k3bdevicemanager.cpp Fri Feb 13 21:03:38 2004
+--- src/device/k3bdevicemanager.cpp.orig Sun Feb 29 13:52:41 2004
++++ src/device/k3bdevicemanager.cpp Tue May 11 22:57:03 2004
@@ -49,6 +49,12 @@
#include <sys/stat.h>
#include <sys/ioctl.h>
@@ -13,7 +13,7 @@
#ifdef Q_OS_LINUX
-@@ -196,6 +202,22 @@
+@@ -196,6 +202,13 @@
{
m_foundDevices = 0;
@@ -22,21 +22,12 @@
+// and asks their properties. If they are indeed cd drives, they are added to a device list. This does not work
+// on FreeBSD (no corresponding ioctls). Here cdrecord is asked for a list of scsi device, which work as cd
+// drives. The device points of those devices are added to the device list.
-+ bsd_scan_devices(false);
-+ kdDebug() << "(K3bDeviceManager) analyze found device" << endl;
-+ for ( QValueList<BSDDevice>::iterator it = m_devices.begin(); it != m_devices.end(); ++it )
-+ {
-+ if( addDevice( (*it).m_name ) )
-+ {
-+ kdDebug() << "(K3bDeviceManager) Device " << (*it).m_name << " added" << endl;
-+ m_foundDevices++;
-+ }
-+ }
++ bsd_scan_devices();
+#else
QFile info("/proc/sys/dev/cdrom/info");
QString line,devstring;
info.open(IO_ReadOnly);
-@@ -286,6 +308,7 @@
+@@ -286,6 +299,7 @@
// m_foundDevices++;
// }
@@ -44,7 +35,7 @@
scanFstab();
return m_foundDevices;
-@@ -427,6 +450,7 @@
+@@ -427,6 +441,7 @@
bool K3bCdDevice::DeviceManager::testForCdrom(const QString& devicename)
{
bool ret = false;
@@ -52,7 +43,7 @@
int cdromfd = K3bCdDevice::openDevice( devicename.ascii() );
if (cdromfd < 0) {
kdDebug() << "could not open device " << devicename << " (" << strerror(errno) << ")" << endl;
-@@ -467,11 +491,51 @@
+@@ -467,11 +482,36 @@
}
::close( cdromfd );
@@ -66,45 +57,30 @@
+// this piece of code extracts some device parameter, like scsi or ide device. The whole process
+// fails on FreeBSD. Here the device name is simply looked up in a list of devices found by a
+// call of cdrecord --scanbus.
-+ K3bDevice* device = 0;
-+ if (!m_lastRefresh.isValid())
-+ bsd_scan_devices(false);
-+ bool found = false;
-+ for ( QValueList<BSDDevice>::iterator it = m_devices.begin(); it != m_devices.end(); ++it )
-+ {
-+ if( (*it).m_name == devicename )
-+ {
-+ device = new K3bDevice((*it).m_name.latin1());
-+ device->m_bus = (*it).m_bus;
-+ device->m_target = (*it).m_target;
-+ device->m_lun = (*it).m_lun;
-+ device->m_passDevice = (*it).m_passDevice;
-+ device->m_vendor = (*it).m_vendor;
-+ device->m_description = (*it).m_product;
-+ device->m_version = (*it).m_revision;
-+ found = true;
-+ break;
-+ }
-+ }
-+ if (!found)
-+ {
++ K3bDevice* device = findDevice(devicename);
++ if (device)
++ return 0;
+ // resolve all symlinks
+ QString resolved = resolveSymLink( devicename );
+ kdDebug() << "(K3bDeviceManager) " << devicename << " resolved to " << resolved << endl;
-+ int bus, target, lun;
-+ if( K3bDevice* oldDev = findDevice( bus, target, lun ) )
++ if( K3bDevice* oldDev = findDevice( resolved ) )
+ {
-+ kdDebug() << "(K3bDeviceManager) dev already found" << endl;
-+ oldDev->addDeviceNode( resolved );
++ kdDebug() << "(K3bDeviceManager) dev already found" << endl;
++ oldDev->addDeviceNode( resolved );
++ return 0;
+ }
-+ return 0;
-+ }
++ device = new K3bDevice(resolved.latin1());
++ return addDevice( device );
++}
+
++K3bDevice* K3bCdDevice::DeviceManager::addDevice( CdDevice* device )
++{
++ const QString devicename = device->devicename();
+#else
K3bDevice* device = 0;
// resolve all symlinks
-@@ -503,6 +567,7 @@
+@@ -503,6 +543,7 @@
device->m_target = target;
device->m_lun = lun;
}
@@ -112,7 +88,7 @@
if( !device->init() ) {
kdDebug() << "Could not initialize device " << devicename << endl;
-@@ -578,9 +643,20 @@
+@@ -578,9 +619,20 @@
if( K3bDevice* dev = findDevice( resolveSymLink(md) ) )
{
@@ -133,7 +109,7 @@
dev->setMountDevice( md );
dev->m_supermount = supermount;
}
-@@ -589,6 +665,8 @@
+@@ -589,6 +641,8 @@
{
// compare bus, id, lun since the same device can for example be
// determined as /dev/srX or /dev/scdX
@@ -142,7 +118,7 @@
int bus = -1, id = -1, lun = -1;
if( determineBusIdLun( mountInfo->fs_spec, bus, id, lun ) ) {
if( K3bDevice* dev = findDevice( bus, id, lun ) ) {
-@@ -599,6 +677,17 @@
+@@ -599,6 +653,17 @@
}
}
}
@@ -160,129 +136,134 @@
}
-@@ -673,5 +762,126 @@
+@@ -674,5 +739,131 @@
return QString::fromLatin1( resolved );
}
+
+#ifdef __FreeBSD__
-+// Calls "camcontrol devlist" to get a list of all available cd devices.
-+// The sudo flag indicates, that "camcontrol devlist" should be
-+// called. This is tried, if bsd_scan_devices(false) fails.
-+// The result of the scan ist stored in m_devices. If within 3
-+// seconds after the last call to bsd_scan_devices this function
-+// is called again, the last result is used (prevents to call
-+// camcontrol several times within a short time).
-+void K3bCdDevice::DeviceManager::bsd_scan_devices(bool sudo)
++#include <cam/cam.h>
++#include <cam/scsi/scsi_pass.h>
++#include <camlib.h>
++void K3bCdDevice::DeviceManager::bsd_scan_devices()
+{
-+ QDateTime now = QDateTime::currentDateTime();
-+ if (m_lastRefresh.isValid() && m_lastRefresh.secsTo(now) < 3)
-+ return;
-+ m_lastRefresh = now;
-+ m_devices.clear();
-+ kdDebug() << "(K3bDeviceManager) Scanning for devices: " << sudo << endl;
-+ KTempFile tmpfile;
-+ tmpfile.setAutoDelete(true);
++ union ccb ccb;
++ int fd, i;
++ int need_close = 0;
++ int skip_device = 0;
++ int bus, target, lun;
++ QString dev1, dev2;
++
++ if ((fd = open(XPT_DEVICE, O_RDWR)) == -1)
++ {
++ kdDebug() << "couldn't open %s " << XPT_DEVICE << endl;
++ return;
++ }
++
++ memset(&ccb, 0, sizeof(ccb));
++
++ ccb.ccb_h.func_code = XPT_DEV_MATCH;
++ char buffer[100*sizeof(struct dev_match_result)];
++ ccb.cdm.match_buf_len = 100*sizeof(struct dev_match_result);
++ ccb.cdm.matches = (struct dev_match_result *)buffer;
++ ccb.cdm.num_matches = 0;
++ ccb.cdm.num_patterns = 0;
++ ccb.cdm.pattern_buf_len = 0;
++ do {
++ if (ioctl(fd, CAMIOCOMMAND, &ccb) == -1) {
++ kdDebug() << "(bsd_scan_devices) error sending CAMIOCOMMAND ioctl: " << errno << endl;
++ break;
++ }
++
++ if ((ccb.ccb_h.status != CAM_REQ_CMP)
++ || ((ccb.cdm.status != CAM_DEV_MATCH_LAST) && (ccb.cdm.status != CAM_DEV_MATCH_MORE))) {
++ kdDebug() << "(bsd_scan_devices) got CAM error " << ccb.ccb_h.status << ", CDM error %d" << ccb.cdm.status << endl;
++ break;
++ }
++ kdDebug() << "(bsd_scan_devices) number of matches " << (int)ccb.cdm.num_matches << endl;
++ for (int i = 0; i < (int)ccb.cdm.num_matches; i++) {
++ switch (ccb.cdm.matches[i].type) {
++ case DEV_MATCH_DEVICE: {
++ struct device_match_result *dev_result = &ccb.cdm.matches[i].result.device_result;
++
++ if (dev_result->flags & DEV_RESULT_UNCONFIGURED)
++ {
++ skip_device = 1;
++ break;
++ }
++ else
++ skip_device = 0;
++ if (need_close)
++ {
++ QString pass = dev1;
++ QString dev = "/dev/" + dev2;
++ if (dev2.startsWith("pass"))
++ {
++ pass = dev2;
++ dev = "/dev/" + dev1;
++ }
++#if __FreeBSD_version < 500100
++ dev += "c";
++#endif
+
-+ // create call
-+ QString call = "/bin/sh -c \"";
-+ if (sudo)
-+ call += "sudo ";
-+ call += "camcontrol devlist > " + tmpfile.name() + " 2>&1 \"";
-+ kdDebug() << "(K3bDeviceManager) Reading device list : " << call << endl;
-+ if (system(call.latin1()))
-+ {
-+ if (!sudo)
-+ {
-+ m_lastRefresh = m_lastRefresh.addDays(-1);
-+ bsd_scan_devices(true);
-+ }
-+ return;
-+ }
++ K3bDevice* device = new K3bDevice(dev.latin1());
++ device->m_bus = bus;
++ device->m_target = target;
++ device->m_lun = lun;
++ device->m_passDevice = "/dev/" + pass;
++ kdDebug() << "(bsd_scan_devices) add device " << dev << ":" << bus << ":" << target << ":" << lun << endl;
++ addDevice(device);
++ need_close = 0;
++ }
++ bus = dev_result->path_id;
++ target = dev_result->target_id;
++ lun = dev_result->target_lun;
+
-+ // read tmp file line by line
-+ QFile tmp (tmpfile.name());
-+ if ( tmp.open( IO_ReadOnly ) )
-+ {
-+ QTextStream stream( &tmp );
-+ while ( !stream.eof() )
++ need_close = 1;
++
++ break;
++ }
++ case DEV_MATCH_PERIPH: {
++ struct periph_match_result *periph_result = &ccb.cdm.matches[i].result.periph_result;
++
++ if (skip_device != 0)
++ break;
++
++ if (need_close > 1)
++ dev1 = periph_result->periph_name + QString::number(periph_result->unit_number);
++ else
++ dev2 = periph_result->periph_name + QString::number(periph_result->unit_number);
++
++ need_close++;
++ break;
++ }
++ }
++ }
++
++ } while ((ccb.ccb_h.status == CAM_REQ_CMP)
++ && (ccb.cdm.status == CAM_DEV_MATCH_MORE));
++
++ if (need_close)
+ {
-+ QString str = stream.readLine();
-+ if (!str.startsWith("<"))
-+ continue;
-+ str.remove(0,1);
-+ int i = str.find(">");
-+ if (i < 0)
-+ continue;
-+ QStringList details = QStringList::split(" ", str.left(i));
-+ i = str.find("at scbus", i);
-+ if (i < 0)
-+ continue;
-+ str.remove(0, i+8);
-+ i = str.find(" ");
-+ if (i < 0)
-+ continue;
-+ bool ok;
-+ int bus = str.left(i).toInt(&ok);
-+ if (!ok)
-+ continue;
-+ i = str.find("target ", i);
-+ if (i < 0)
-+ continue;
-+ str.remove(0, i+7);
-+ i = str.find(" ");
-+ if (i < 0)
-+ continue;
-+ int target = str.left(i).toInt(&ok);
-+ if (!ok)
-+ continue;
-+ i = str.find("lun ", i);
-+ if (i < 0)
-+ continue;
-+ str.remove(0, i+4);
-+ i = str.find(" ");
-+ if (i < 0)
-+ continue;
-+ int lun = str.left(i).toInt(&ok);
-+ if (!ok)
-+ continue;
-+ i = str.find("(", i);
-+ if (i < 0)
-+ continue;
-+ str.remove(0, i+1);
-+ i = str.find(",");
-+ if (i < 0)
-+ continue;
-+ QString name = str.left(i);
-+ str.remove(0, i+1);
-+ i = str.find(")");
-+ if (i < 0)
-+ continue;
-+ QString pass = name;
-+ if (name.startsWith("pass"))
-+ name = str.left(i);
-+ else
-+ pass = str.left(i);
-+ QString vendor, product, revision;
-+ if (details.count() > 0)
-+ revision = details.last();
-+ details.pop_back();
-+ if (details.count() > 0)
-+ product = details.last();
-+ details.pop_back();
-+ if (details.count() > 0)
-+ vendor = details.join(" ");
-+ if (!name.startsWith("cd"))
-+ continue;
-+ kdDebug() << "(K3bDeviceManager) Found device " << name << ", pass = " << pass << ", bus = " << bus << ", target = " << target << ", lun = " << lun << endl;
-+ kdDebug() << "(K3bDeviceManager) vendor: " << vendor << ", product: " << product << ", revision: " << revision << ", target = " << target << ", lun = " << lun << endl;
-+#if __FreeBSD_version >= 500100
-+ m_devices.push_back(BSDDevice("/dev/" + name, "/dev/" + pass, vendor, product, revision, bus, target, lun));
-+#else
-+ m_devices.push_back(BSDDevice("/dev/" + name + "c", "/dev/" + pass, vendor, product, revision, bus, target, lun));
++ QString pass = dev1;
++ QString dev = "/dev/" + dev2;
++ if (dev2.startsWith("pass"))
++ {
++ pass = dev2;
++ dev = "/dev/" + dev1;
++ }
++#if __FreeBSD_version < 500100
++ dev += "c";
+#endif
-+ }
-+ }
++ K3bDevice* device = new K3bDevice(dev.latin1());
++ device->m_bus = bus;
++ device->m_target = target;
++ device->m_lun = lun;
++ device->m_passDevice = "/dev/" + pass;
++ kdDebug() << "(bsd_scan_devices) add device " << dev << ":" << bus << ":" << target << ":" << lun << endl;
++ addDevice(device);
++ }
++ close(fd);
+}
+#endif