--- unetbootin.cpp.orig 2020-11-09 01:52:38 UTC +++ unetbootin.cpp @@ -296,8 +296,13 @@ bool unetbootin::ubninitialize(QListcurrentText(); devluid = getdevluid(targetDev); ginstallDir = ""; installDir = ginstallDir; targetDrive = QString("%1/").arg(locatemountpoint(targetDev)); +#endif +#ifdef Q_OS_FREEBSD + QStringList driveinfo = driveselect->currentText().split(":"); + if (driveinfo.size() < 2) { + QTextStream out(stdout); + out << "/!\\ Target drive must be passed as " + ":" << endl << flush; + QApplication::exit(); + exit(1); + } + targetDev = driveinfo.at(0); + installDir = ginstallDir = ""; + targetDrive = QString("%1/").arg(driveinfo.at(1)); +#endif } #ifdef Q_OS_LINUX if (targetDev.contains(QRegExp("p\\d$"))) @@ -3470,7 +3562,7 @@ void unetbootin::runinst() else rawtargetDev = QString(targetDev).remove(QRegExp("\\d$")); #endif -#ifdef Q_OS_MAC +#ifdef Q_OS_UNIX rawtargetDev = QString(targetDev).remove(QRegExp("s\\d$")); #endif #endif @@ -4223,21 +4315,47 @@ void unetbootin::runinstusb() instIndvfl("libutil.c32", QString("%1libutil.c32").arg(targetPath)); instIndvfl("libcom32.c32", QString("%1libcom32.c32").arg(targetPath)); } + setuppersspace(); +#ifdef Q_OS_FREEBSD + /* + * On FreeBSD, we only support installing on MSDOSFS (no + * extlinux in the ports). This also simplifies things + * a bit, and that's what most users usually want anyway. + * + * Because of syslinux' stupidity, we have to remove any + * existing ldlinux.c32 and ldlinux.sys files, otherwise + * it will fail to install loader (even with -f switch). + * Then we have to unmount the filesystem to avoid the + * "Operation not permitted" error, and must enforce it + * because syslinux expects a block device, and, well, + * there are no "block devices" in FreeBSD. + */ + rmFile(targetPath + "ldlinux.c32"); + rmFile(targetPath + "ldlinux.sys"); + callexternapp("umount", targetDev); + callexternapp(syslinuxcommand, "-i -f " + targetDev); + + if (rawtargetDev != targetDev) + { + /* + * We have partition table (not operating on raw + * disk), so we need to install MBR and mark our + * partition as active. Assume our targetDev is + * /dev/{da,mmcsd}XsY and use the last digit as + * partition index for gpart(8). + */ + QString idx = targetDev.right(1); + callexternapp("gpart", + "bootcode -b /boot/mbr " + rawtargetDev); + callexternapp("gpart", "set -a " + "active -i " + idx + " " + rawtargetDev); + } +#endif fininstall(); } -void unetbootin::killApplication() +void unetbootin::setuppersspace() { - exit(0); -} - -void unetbootin::fininstall() -{ - #ifdef Q_OS_UNIX - this->tprogress->setValue(this->tprogress->maximum()*2/3); - pdesc1->setText(tr("Syncing filesystems")); - callexternapp("sync", ""); - #endif if (this->persistenceSpaceMB > 0) { pdesc1->setText(tr("Setting up persistence")); @@ -4276,6 +4394,20 @@ void unetbootin::fininstall() rmFile(mke2fscommand); #endif } +} + +void unetbootin::killApplication() +{ + exit(0); +} + +void unetbootin::fininstall() +{ + #ifdef Q_OS_UNIX + this->tprogress->setValue(this->tprogress->maximum()*2/3); + pdesc1->setText(tr("Syncing filesystems")); + callexternapp("sync", ""); + #endif pdesc1->setText(""); progresslayer->setEnabled(false); progresslayer->hide();