From kde-commits Thu Sep 22 03:48:32 2016 From: Leslie Zhai Date: Thu, 22 Sep 2016 03:48:32 +0000 To: kde-commits Subject: [k3b/multisession] libk3b/projects: Multisession implemented as Thomas suggested Message-Id: X-MARC-Message: https://marc.info/?l=kde-commits&m=147451612206798 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() !=3D K3b::DataDoc::NONE ) { // + // TODO: KDEBUG-367639 // growisofs wants a valid -C parameter for multisession, so we ge= t it from the // K3b::MsInfoFetcher (see K3b::DataJob::prepareWriting) // diff --git a/libk3b/projects/datacd/k3bisoimager.cpp b/libk3b/projects/data= cd/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 QStrin= g& info, K3b::Device::Devi { m_multiSessionInfo =3D info; m_device =3D dev; + if (m_multiSessionInfo.isEmpty()) + return; + QStringList ms =3D m_multiSessionInfo.split(','); + if (ms.size() !=3D 2) + return; + if (ms[0] !=3D "0" && ms[1] !=3D "0") + return; + int imgfd =3D -1; + char* in_image =3D "/dev/fd/0"; + // Validate file descriptor + if (sscanf(in_image, "/dev/fd/%u", &imgfd) =3D=3D 1) + imgfd =3D dup(imgfd); + else + imgfd =3D open(in_image, O_RDONLY); + if (imgfd =3D=3D -1) + return; + char buf[6] =3D { '\0' }; + if (lseek(imgfd, 32 * 1024, SEEK_SET) !=3D -1) { + if (read(imgfd, buf, sizeof(buf)) =3D=3D sizeof(buf)) { + // Check for the ISO 9660 magic number + if (buf[0] =3D=3D 0x01 && buf[1] =3D=3D 'C' && buf[2] =3D=3D '= D' && + buf[3] =3D=3D '0' && buf[4] =3D=3D '0' && buf[5] =3D=3D '= 1') { + if (lseek(imgfd, 32 * 1024 + 80, SEEK_SET) !=3D -1) { + uint32_t c2; + uint8_t buf[4] =3D { '\0' }; + if (read(imgfd, buf, sizeof(buf)) =3D=3D sizeof(buf)) { + // Interpret the read bytes as little-endian number + c2 =3D buf[0] | (buf[1] << 8) | (buf[2] << 16) | (= buf[3] << 24); + // Round up to full multipes of 16 + c2 +=3D 15; + c2 /=3D 16; + c2 *=3D 16; + m_multiSessionInfo =3D ms[0] + "," + QString::numb= er(c2); + } + } + } + } + } + close(imgfd); + imgfd =3D -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/k3bgr= owisofswriter.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 +=3D d->image; = - // TODO: KDEBUG-367639 - if( d->multiSession && !d->multiSessionInfo.isEmpty() ) { - QStringList ms =3D d->multiSessionInfo.split(','); - if (ms.size() =3D=3D 2) { - if (ms[0] =3D=3D 0 || ms[1] =3D=3D "0") { - FILE* fptr =3D NULL; - if (d->image.isEmpty()) - fptr =3D fopen("/dev/fd/0", "r"); - else - fptr =3D fopen(d->image.toStdString().c_str(), "r"); - if (fptr) { - if (fseek(fptr, 32 * 1024 + 80, SEEK_SET) =3D=3D 0) { - char buf[4] =3D { '\0' }; - fread(buf, 1, sizeof(buf), fptr); - int next =3D atoi(buf); - bool ok; - int last =3D ms[0].toInt(&ok); - if (ok && next > last) - d->process << "-C " << ms[0] << "," << buf; - } else { - qWarning() << strerror(errno); - } - fclose(fptr); - fptr =3D NULL; - } - } else { - d->process << "-C" << d->multiSessionInfo; - } - } - } + if (d->multiSession && !d->multiSessionInfo.isEmpty()) + d->process << "-C" << d->multiSessionInfo; = if( d->multiSession ) d->process << "-M";