[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [k3b/multisession] libk3b/projects: Multisession implemented as Thomas suggested
From: Leslie Zhai <xiangzhai83 () gmail ! com>
Date: 2016-09-22 3:48:32
Message-ID: E1bmuzw-00037d-SH () code ! kde ! org
[Download RAW message or body]
Git commit ae0413daf1df44cb2c8c6e88a5b86180f1f52c3a by Leslie Zhai.
Committed on 22/09/2016 at 03:42.
Pushed by lesliezhai into branch 'multisession'.
Multisession implemented as Thomas suggested
Summary:
- validate file descriptor
- check for the ISO 9660 magic number
- convert the 4 bytes into a 32 bit number by interpreting them as
little-endian number
- A generic checker for GrowisofsWriter (growisofs) and IsoImager (mkisofs)
CCBUG: 367639
M +1 -0 libk3b/projects/datacd/k3bdatajob.cpp
M +41 -0 libk3b/projects/datacd/k3bisoimager.cpp
M +2 -30 libk3b/projects/k3bgrowisofswriter.cpp
http://commits.kde.org/k3b/ae0413daf1df44cb2c8c6e88a5b86180f1f52c3a
diff --git a/libk3b/projects/datacd/k3bdatajob.cpp b/libk3b/projects/datacd/k3bdatajob.cpp
index 315845a..b3b4ebd 100644
--- a/libk3b/projects/datacd/k3bdatajob.cpp
+++ b/libk3b/projects/datacd/k3bdatajob.cpp
@@ -1151,6 +1151,7 @@ bool K3b::DataJob::setupGrowisofsJob()
if( usedMultiSessionMode() != K3b::DataDoc::NONE ) {
//
+ // TODO: KDEBUG-367639
// growisofs wants a valid -C parameter for multisession, so we get it from the
// K3b::MsInfoFetcher (see K3b::DataJob::prepareWriting)
//
diff --git a/libk3b/projects/datacd/k3bisoimager.cpp b/libk3b/projects/datacd/k3bisoimager.cpp
index 28fcae5..74c956b 100644
--- a/libk3b/projects/datacd/k3bisoimager.cpp
+++ b/libk3b/projects/datacd/k3bisoimager.cpp
@@ -473,6 +473,46 @@ void K3b::IsoImager::setMultiSessionInfo( const QString& info, K3b::Device::Devi
{
m_multiSessionInfo = info;
m_device = dev;
+ if (m_multiSessionInfo.isEmpty())
+ return;
+ QStringList ms = m_multiSessionInfo.split(',');
+ if (ms.size() != 2)
+ return;
+ if (ms[0] != "0" && ms[1] != "0")
+ return;
+ int imgfd = -1;
+ char* in_image = "/dev/fd/0";
+ // Validate file descriptor
+ if (sscanf(in_image, "/dev/fd/%u", &imgfd) == 1)
+ imgfd = dup(imgfd);
+ else
+ imgfd = open(in_image, O_RDONLY);
+ if (imgfd == -1)
+ return;
+ char buf[6] = { '\0' };
+ if (lseek(imgfd, 32 * 1024, SEEK_SET) != -1) {
+ if (read(imgfd, buf, sizeof(buf)) == sizeof(buf)) {
+ // Check for the ISO 9660 magic number
+ if (buf[0] == 0x01 && buf[1] == 'C' && buf[2] == 'D' &&
+ buf[3] == '0' && buf[4] == '0' && buf[5] == '1') {
+ if (lseek(imgfd, 32 * 1024 + 80, SEEK_SET) != -1) {
+ uint32_t c2;
+ uint8_t buf[4] = { '\0' };
+ if (read(imgfd, buf, sizeof(buf)) == sizeof(buf)) {
+ // Interpret the read bytes as little-endian number
+ c2 = buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24);
+ // Round up to full multipes of 16
+ c2 += 15;
+ c2 /= 16;
+ c2 *= 16;
+ m_multiSessionInfo = ms[0] + "," + QString::number(c2);
+ }
+ }
+ }
+ }
+ }
+ close(imgfd);
+ imgfd = -1;
}
@@ -501,6 +541,7 @@ static void truncateTheHardWay( QString& s, int max )
bool K3b::IsoImager::addMkisofsParameters( bool printSize )
{
+ // TODO: KDEBUG-367639
// add multisession info
if( !m_multiSessionInfo.isEmpty() ) {
*m_process << "-cdrecord-params" << m_multiSessionInfo;
diff --git a/libk3b/projects/k3bgrowisofswriter.cpp b/libk3b/projects/k3bgrowisofswriter.cpp
index c8fdcdc..d3d4d85 100644
--- a/libk3b/projects/k3bgrowisofswriter.cpp
+++ b/libk3b/projects/k3bgrowisofswriter.cpp
@@ -197,36 +197,8 @@ bool K3b::GrowisofsWriter::prepareProcess()
else
s += d->image;
- // TODO: KDEBUG-367639
- if( d->multiSession && !d->multiSessionInfo.isEmpty() ) {
- QStringList ms = d->multiSessionInfo.split(',');
- if (ms.size() == 2) {
- if (ms[0] == 0 || ms[1] == "0") {
- FILE* fptr = NULL;
- if (d->image.isEmpty())
- fptr = fopen("/dev/fd/0", "r");
- else
- fptr = fopen(d->image.toStdString().c_str(), "r");
- if (fptr) {
- if (fseek(fptr, 32 * 1024 + 80, SEEK_SET) == 0) {
- char buf[4] = { '\0' };
- fread(buf, 1, sizeof(buf), fptr);
- int next = atoi(buf);
- bool ok;
- int last = ms[0].toInt(&ok);
- if (ok && next > last)
- d->process << "-C " << ms[0] << "," << buf;
- } else {
- qWarning() << strerror(errno);
- }
- fclose(fptr);
- fptr = NULL;
- }
- } else {
- d->process << "-C" << d->multiSessionInfo;
- }
- }
- }
+ if (d->multiSession && !d->multiSessionInfo.isEmpty())
+ d->process << "-C" << d->multiSessionInfo;
if( d->multiSession )
d->process << "-M";
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic