1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
|
--- unetbootin.cpp.orig 2017-07-14 08:54:12 UTC
+++ unetbootin.cpp
@@ -301,8 +301,13 @@ bool unetbootin::ubninitialize(QList<QPair<QString, QS
#endif
sevzcommand = locatecommand("7z", tr("either"), "p7zip-full");
#endif // Q_OS_LINUX
+#ifdef Q_OS_FREEBSD
+ syslinuxcommand = locatecommand("syslinux", tr("FAT32-formatted USB drive"), "syslinux");
+ sevzcommand = locatecommand("7z", tr("either"), "p7zip");
+ mke2fscommand = locatecommand("mke2fs", tr("LiveUSB persistence"), "e2fsprogs");
+#endif // Q_OS_FREEBSD
ubntmpf = QDir::toNativeSeparators(QString("%1/").arg(QDir::tempPath()));
- #ifdef Q_OS_LINUX
+ #ifdef Q_OS_UNIX
if (ubntmpf.isEmpty() || ubntmpf == "/")
{
ubntmpf = "/tmp/";
@@ -649,6 +654,57 @@ QStringList unetbootin::listsanedrives()
}
*/
#endif
+#ifdef Q_OS_FREEBSD
+ struct xvfsconf fsconf;
+ struct statfs *fslist;
+
+ /*
+ * Make sure that MSDOSFS is configured with the kernel.
+ * As a nice side effect, this would allow to compare a
+ * number (assigned by VFS) instead of "msdosfs" string
+ * when iterating over mounted filesystems.
+ */
+ if (getvfsbyname("msdosfs", &fsconf) == -1)
+ goto out;
+
+ /*
+ * Quick sanity check of the number of active mountpoints
+ * using the filesystem (we need mounted storage to work).
+ */
+ if (fsconf.vfc_refcount < 1)
+ goto out;
+
+ int numfs = getmntinfo(&fslist, MNT_NOWAIT);
+ if (numfs < 1)
+ goto out;
+
+ QRegExp pendrives_sdcards("^/dev/(da|mmcsd)\\d+");
+
+ for (int i = 0; i < numfs; ++i)
+ {
+ /*
+ * We're interested in MSDOSFS (FAT) filesystems
+ * that are mounted off removable storage (e.g.,
+ * USB memsticks, SD cards). Assume that device
+ * names for those are /dev/da* and /dev/mmcsd*.
+ * (Perhaps not entirely accurate assumption.)
+ */
+ if ((int)fslist[i].f_type == fsconf.vfc_typenum &&
+ QString(fslist[i].f_mntfromname)
+ .contains(pendrives_sdcards))
+ {
+ /*
+ * Unlike other implementations above, we
+ * append tuples of device name *and* the
+ * mount point, so we do not have to find
+ * mount point separately later.
+ */
+ fulldrivelist.append(QString("%1:%2")
+ .arg(fslist[i].f_mntfromname)
+ .arg(fslist[i].f_mntonname));
+ }
+ }
+#endif
#ifdef Q_OS_MAC
QString systemprofilertext = callexternapp("system_profiler", "SPStorageDataType");
QRegExp filesystemregex("File System: (.+)\\n");
@@ -669,6 +725,7 @@ for (int i = 0; i < filesystemlist.size(); ++i)
}
#endif
}
+out:
return fulldrivelist;
}
@@ -1100,7 +1157,12 @@ bool unetbootin::checkifoutofspace(QString destindir)
struct statfs diskstatS;
if (!statfs(QString(destindir+"/.").toAscii(), &diskstatS))
{
- if (diskstatS.f_bavail * diskstatS.f_bfree < 1024)
+ /*
+ * Refuse to work if available disk space is less than 1MB
+ * (1024KB). Even this seems very low, but original value
+ * of 1024 bytes was simply ridiculous.
+ */
+ if (diskstatS.f_bsize / 1024 * diskstatS.f_bavail < 1024)
outofspace = true;
}
#endif
@@ -3412,21 +3474,36 @@ void unetbootin::instIndvfl(QString srcfName, QString
srcF.setFileName(QFile::exists("/usr/share/syslinux/memdisk") ? "/usr/share/syslinux/memdisk" : "/usr/lib/syslinux/memdisk");
else if (srcfName == "menu.c32")
{
+#ifdef Q_OS_LINUX
srcF.setFileName(QFile::exists("/usr/share/syslinux/menu.c32") ? "/usr/share/syslinux/menu.c32" : "/usr/lib/syslinux/menu.c32");
if (QFile::exists("/usr/lib/syslinux/modules/bios/menu.c32"))
srcF.setFileName("/usr/lib/syslinux/modules/bios/menu.c32");
+#endif
+#ifdef Q_OS_FREEBSD
+ srcF.setFileName(LOCALBASE "/share/syslinux/bios/com32/menu/menu.c32");
+#endif
}
else if (srcfName == "libutil.c32")
{
+#ifdef Q_OS_LINUX
srcF.setFileName(QFile::exists("/usr/share/syslinux/libutil.c32") ? "/usr/share/syslinux/libutil.c32" : "/usr/lib/syslinux/libutil.c32");
if (QFile::exists("/usr/lib/syslinux/modules/bios/libutil.c32"))
srcF.setFileName("/usr/lib/syslinux/modules/bios/libutil.c32");
+#endif
+#ifdef Q_OS_FREEBSD
+ srcF.setFileName(LOCALBASE "/share/syslinux/bios/com32/libutil/libutil.c32");
+#endif
}
else if (srcfName == "libcom32.c32")
{
+#ifdef Q_OS_LINUX
srcF.setFileName(QFile::exists("/usr/share/syslinux/libcom32.c32") ? "/usr/share/syslinux/libcom32.c32" : "/usr/lib/syslinux/libcom32.c32");
if (QFile::exists("/usr/lib/syslinux/modules/bios/libcom32.c32"))
srcF.setFileName("/usr/lib/syslinux/modules/bios/libcom32.c32");
+#endif
+#ifdef Q_OS_FREEBSD
+ srcF.setFileName(LOCALBASE "/share/syslinux/bios/com32/lib/libcom32.c32");
+#endif
}
else if (srcfName == "mbr.bin")
{
@@ -3516,11 +3593,19 @@ void unetbootin::runinst()
}
if (installType == tr("USB Drive"))
{
+#ifdef Q_OS_LINUX
targetDev = driveselect->currentText();
devluid = getdevluid(targetDev);
ginstallDir = "";
installDir = ginstallDir;
targetDrive = QString("%1/").arg(locatemountpoint(targetDev));
+#endif
+#ifdef Q_OS_FREEBSD
+ QStringList driveinfo = driveselect->currentText().split(":");
+ targetDev = driveinfo.at(0);
+ installDir = ginstallDir = "";
+ targetDrive = QString("%1/").arg(driveinfo.at(1));
+#endif
}
#ifdef Q_OS_LINUX
if (targetDev.contains(QRegExp("p\\d$")))
@@ -3528,7 +3613,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
@@ -3724,7 +3809,7 @@ void unetbootin::writegrub2cfg()
QString menulstxt = QString(
"%9\n\n"
#ifndef NODEFAULTBOOT
- "\nmenuentry \""UNETBOOTINB"\" {\n"
+ "\nmenuentry \"" UNETBOOTINB "\" {\n"
"\tset root=%8\n"
"\t%1 %2 %3 %4\n"
"\t%5 %6 %7\n"
@@ -3845,7 +3930,7 @@ void unetbootin::runinsthdd()
"timeout 10\n"
#endif
#ifndef NODEFAULTBOOT
- "\ntitle "UNETBOOTINB"\n"
+ "\ntitle " UNETBOOTINB "\n"
#ifdef Q_OS_WIN32
"find --set-root %3\n"
#endif
@@ -4281,21 +4366,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"));
@@ -4334,6 +4445,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();
@@ -4343,7 +4468,7 @@ void unetbootin::fininstall()
sdesc4->setText(QString("<b>%1 %2</b>").arg(sdesc4->text()).arg(trcurrent));
if (installType == tr("Hard Disk"))
{
- rebootmsgtext->setText(tr("After rebooting, select the "UNETBOOTINB" menu entry to boot.%1").arg(postinstmsg));
+ rebootmsgtext->setText(tr("After rebooting, select the " UNETBOOTINB " menu entry to boot.%1").arg(postinstmsg));
}
if (installType == tr("USB Drive"))
{
|