This repository has been archived by the owner on Dec 4, 2020. It is now read-only.
/
wizardDisk.cpp
1101 lines (932 loc) · 32.6 KB
/
wizardDisk.cpp
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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/****************************************************************************
** ui.h extension file, included from the uic-generated form implementation.
**
** If you want to add, delete, or rename functions or slots, use
** Qt Designer to update this file, preserving your code.
**
** You should not define a constructor or destructor in this file.
** Instead, write your code in functions called init() and destroy().
** These will automatically be called by the form's constructor and
** destructor.
*****************************************************************************/
#include <QDebug>
#include <QInputDialog>
#include <QMessageBox>
#include "wizardDisk.h"
#include "ui_wizardDisk.h"
void wizardDisk::programInit()
{
prevID = 0;
restoreMode=false;
populateDiskInfo();
//connect(pushClose, SIGNAL(clicked()), this, SLOT(slotClose()));
connect(checkGPT, SIGNAL(clicked()), this, SLOT(slotGPTClicked()));
connect(pushSwapSize, SIGNAL(clicked()), this, SLOT(slotSwapSize()));
connect(pushRemoveMount, SIGNAL(clicked()), this, SLOT(slotRemoveFS()));
connect(pushAddMount, SIGNAL(clicked()), this, SLOT(slotAddFS()));
connect(this,SIGNAL(currentIdChanged(int)),this,SLOT(slotCheckComplete()));
connect(lineZpoolName,SIGNAL(textChanged ( const QString & )),this,SLOT(slotCheckComplete()));
connect(groupZFSPool,SIGNAL( clicked(bool)),this,SLOT(slotCheckComplete()));
connect(comboDisk,SIGNAL(currentIndexChanged(int)),this,SLOT(slotCheckComplete()));
connect(comboDisk,SIGNAL(currentIndexChanged(int)),this,SLOT(slotChangedDisk()));
connect(comboPartition,SIGNAL(currentIndexChanged(int)),this,SLOT(slotCheckComplete()));
connect(treeMounts,SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),this,SLOT(slotTreeDiskChanged()));
treeMounts->setContextMenuPolicy(Qt::CustomContextMenu);
connect(treeMounts,SIGNAL(customContextMenuRequested(const QPoint &)),this,SLOT(slotTreeMountsRightClick()));
connect(pushTerminal, SIGNAL(clicked()), this, SLOT(slotTerminal()));
// ZFS Mode Page
connect(comboZFSMode,SIGNAL(currentIndexChanged(int)),this,SLOT(slotCheckComplete()));
connect(groupZFSOpts,SIGNAL(clicked(bool)),this,SLOT(slotCheckComplete()));
connect(listZFSDisks,SIGNAL(itemClicked(QListWidgetItem *)),this,SLOT(slotCheckComplete()));
connect(listZFSDisks,SIGNAL(itemActivated(QListWidgetItem *)),this,SLOT(slotCheckComplete()));
connect(listZFSDisks,SIGNAL(itemChanged(QListWidgetItem *)),this,SLOT(slotCheckComplete()));
}
void wizardDisk::populateDiskInfo()
{
qDebug() << "Loading Disk Info";
sysDisks = Scripts::Backend::hardDrives();
// load drives
comboDisk->clear();
for (int i=0; i < sysDisks.count(); ++i) {
// Make sure to only add the drives to the comboDisk
if ( sysDisks.at(i).at(0) == "DRIVE" )
comboDisk->addItem(sysDisks.at(i).at(1) + " - " + sysDisks.at(i).at(2) + "MB " + sysDisks.at(i).at(3));
}
// Reload the slice list box
slotChangedDisk();
}
void wizardDisk::slotChangedDisk()
{
QString ptag;
if ( comboDisk->currentText().isEmpty())
return;
comboPartition->clear();
comboPartition->addItem(tr("Use entire disk"));
QString disk = comboDisk->currentText();
disk.truncate(disk.indexOf(" -"));
for (int i=0; i < sysDisks.count(); ++i) {
// Make sure to only add the slices to the listDiskSlices
if ( sysDisks.at(i).at(0) == "SLICE" && disk == sysDisks.at(i).at(1) && sysDisks.at(i).at(4) != "Unused Space") {
ptag = sysDisks.at(i).at(4).section(",", 0, 0);
ptag = ptag.section("/", 0, 0);
ptag.truncate(15);
if ( ptag.indexOf(")") == -1 )
ptag += ")";
comboPartition->addItem(sysDisks.at(i).at(2) + ": " + sysDisks.at(i).at(3) + "MB " + ptag );
}
}
}
void wizardDisk::slotClose()
{
close();
}
void wizardDisk::accept()
{
bool useGRUB = true;
bool useGPT = false;
bool force4K = false;
QString zpoolName;
if (comboPartition->currentIndex() == 0 )
useGPT = checkGPT->isChecked();
// Are we installing GRUB?
useGRUB = checkGRUB->isChecked();
if ( comboPartition->currentIndex() != 0 && ! useGRUB ) {
QMessageBox::warning(this, tr("No boot-loader!"),
tr("You have chosen not to install GRUB on your MBR. You will need to manually setup your own MBR loader."),
QMessageBox::Ok,
QMessageBox::Ok);
}
// When doing advanced ZFS setups, make sure to use GPT
if ( radioAdvanced->isChecked() && groupZFSOpts->isChecked() )
useGPT = true;
// When doing advanced ZFS setups, check if 4K is enabled
if ( radioAdvanced->isChecked() && checkForce4K->isChecked() )
force4K = true;
if ( radioAdvanced->isChecked() && groupZFSPool->isChecked() )
zpoolName = lineZpoolName->text();
if ( radioExpert->isChecked() )
emit saved(sysFinalDiskLayout, false, false, zpoolName, force4K);
else
emit saved(sysFinalDiskLayout, useGRUB, useGPT, zpoolName, force4K);
close();
}
int wizardDisk::nextId() const
{
switch (currentId()) {
case Page_Intro:
if (radioExpert->isChecked())
return Page_Expert;
if (radioBasic->isChecked()) {
checkGPT->setVisible(false);
checkGRUB->setVisible(false);
checkForce4K->setVisible(false);
groupZFSPool->setVisible(false);
}
if (radioAdvanced->isChecked()) {
checkGPT->setVisible(true);
checkGRUB->setVisible(true);
checkForce4K->setVisible(true);
groupZFSPool->setVisible(true);
}
break;
case Page_BasicDisk:
if (radioBasic->isChecked())
return Page_Confirmation;
if (comboPartition->currentIndex() != 0 ) {
groupZFSOpts->setEnabled(false);
return Page_Mounts;
} else {
groupZFSOpts->setEnabled(true);
return Page_ZFS;
}
break;
case Page_ZFS:
return Page_Mounts;
break;
case Page_Mounts:
return Page_Confirmation;
break;
case Page_Confirmation:
return -1;
break;
default:
return currentId() + 1;
}
return currentId() + 1;
}
// Logic checks to see if we are ready to move onto next page
bool wizardDisk::validatePage()
{
// Generate suggested disk layout and show disk tree
if ( prevID == Page_BasicDisk && currentId() == Page_Mounts) {
generateDiskLayout();
populateDiskTree();
}
// Generate suggested disk layout and show disk tree
if ( prevID == Page_ZFS && currentId() == Page_Mounts) {
generateDiskLayout();
populateDiskTree();
}
// Show the other disks available
if ( prevID == Page_BasicDisk && currentId() == Page_ZFS)
populateZFSDisks();
// Basic mode, generate a disk layout and show summary
if ( prevID == Page_BasicDisk && currentId() == Page_Confirmation) {
generateDiskLayout();
generateConfirmationText();
}
// Create the final disk layout from user options
if ( prevID == Page_Mounts && currentId() == Page_Confirmation) {
generateCustomDiskLayout();
generateConfirmationText();
}
// Create the final disk layout from user options
if ( prevID == Page_Expert && currentId() == Page_Confirmation) {
generateConfirmationText();
}
// Reset the prevID
prevID = currentId();
switch (currentId()) {
case Page_Intro:
button(QWizard::NextButton)->setEnabled(true);
return true;
case Page_BasicDisk:
if ( ! radioAdvanced->isChecked() ) {
checkGPT->setChecked(false);
checkGPT->setVisible(false);
checkForce4K->setVisible(false);
checkForce4K->setChecked(false);
} else {
checkGPT->setVisible(true);
checkForce4K->setVisible(true);
if ( comboPartition->currentIndex() == 0)
checkGRUB->setText(tr("Install GRUB (Required for Boot-Environment support)"));
else
checkGRUB->setText(tr("Stamp GRUB on MBR"));
}
// Doing a Advanced install
if ( radioAdvanced->isChecked() && groupZFSPool->isChecked() )
{
if ( lineZpoolName->text().isEmpty() ) {
button(QWizard::NextButton)->setEnabled(false);
return false;
}
if ( lineZpoolName->text() == "root" ) {
button(QWizard::NextButton)->setEnabled(false);
return false;
}
if ( lineZpoolName->text().contains(" ") ) {
button(QWizard::NextButton)->setEnabled(false);
return false;
}
QRegExp *re = new QRegExp("^[-'a-zA-Z]*$");
if (! re->exactMatch(lineZpoolName->text()) ) {
button(QWizard::NextButton)->setEnabled(false);
return false;
}
}
// If the select partition is just too small, we can stop here
if ( ! checkDiskSpace() ) {
button(QWizard::NextButton)->setEnabled(false);
return false;
}
// if we get this far, all the fields are filled in
button(QWizard::NextButton)->setEnabled(true);
return true;
case Page_ZFS:
// Check if we have valid ZFS disk options specified
if ( ! groupZFSOpts->isChecked() ) {
button(QWizard::NextButton)->setEnabled(true);
return true;
}
// Need at least one other disk for mirroring
if ( comboZFSMode->currentText() == "mirror" ) {
labelZFSMsg->setText(tr("Please select at least 1 other drive for mirroring"));
for ( int i = 0; i < listZFSDisks->count(); ++i )
{
if ( listZFSDisks->item(i)->checkState() == Qt::Checked ) {
button(QWizard::NextButton)->setEnabled(true);
return true;
}
}
}
if ( comboZFSMode->currentText() == "raidz1" ) {
labelZFSMsg->setText(tr("Please select 2 or 4 additional drives for raidz1"));
int numChecked = 0;
for ( int i = 0; i < listZFSDisks->count(); ++i )
if ( listZFSDisks->item(i)->checkState() == Qt::Checked )
numChecked++;
if ( numChecked == 2 || numChecked == 4 ) {
button(QWizard::NextButton)->setEnabled(true);
return true;
}
}
if ( comboZFSMode->currentText() == "raidz2" ) {
labelZFSMsg->setText(tr("Please select 3, 5, or 9 additional drives for raidz2"));
int numChecked = 0;
for ( int i = 0; i < listZFSDisks->count(); ++i )
if ( listZFSDisks->item(i)->checkState() == Qt::Checked )
numChecked++;
if ( numChecked == 3 || numChecked == 5 || numChecked == 9 ) {
button(QWizard::NextButton)->setEnabled(true);
return true;
}
}
if ( comboZFSMode->currentText() == "raidz3" ) {
labelZFSMsg->setText(tr("Please select 4, 6, or 10 additional drives for raidz3"));
int numChecked = 0;
for ( int i = 0; i < listZFSDisks->count(); ++i )
if ( listZFSDisks->item(i)->checkState() == Qt::Checked )
numChecked++;
if ( numChecked == 4 || numChecked == 6 || numChecked == 10 ) {
button(QWizard::NextButton)->setEnabled(true);
return true;
}
}
// Disable the next button until we get a working config
button(QWizard::NextButton)->setEnabled(false);
return false;
case Page_Confirmation:
button(QWizard::FinishButton)->setEnabled(true);
return true;
default:
button(QWizard::NextButton)->setEnabled(true);
return true;
}
return true;
}
void wizardDisk::populateZFSDisks()
{
qDebug() << "Adding ZFS disks...";
listZFSDisks->clear();
QString curDisk = comboDisk->currentText();
curDisk.truncate(curDisk.indexOf(" -"));
for (int z=0; z < sysDisks.count(); ++z)
if ( sysDisks.at(z).at(0) == "DRIVE" && sysDisks.at(z).at(1) != curDisk )
{
QListWidgetItem *dItem = new QListWidgetItem(sysDisks.at(z).at(1) + " - " + sysDisks.at(z).at(2) + "MB " + sysDisks.at(z).at(3));
dItem->setCheckState(Qt::Unchecked);
listZFSDisks->addItem(dItem);
}
}
bool wizardDisk::checkDiskSpace()
{
if ( getDiskSliceSize() < 4000 )
return false;
return true;
}
void wizardDisk::slotCheckComplete()
{
// Validate this page
validatePage();
}
void wizardDisk::generateDiskLayout()
{
QString targetType, tmp;
int targetLoc, totalSize = 0;
QString targetDisk, targetSlice, tmpPass, fsType, target;
// Clear out the original disk layout
sysFinalDiskLayout.clear();
QStringList fileSystem;
qDebug() << "Generating disk layout";
if ( comboPartition->currentIndex() == 0) {
targetType = "DRIVE";
targetSlice = "ALL";
targetDisk = comboDisk->currentText();
targetDisk.truncate(targetDisk.indexOf(" -"));
target = targetDisk;
targetLoc = 1;
} else {
targetType = "SLICE";
targetDisk = comboDisk->currentText();
targetDisk.truncate(targetDisk.indexOf(" -"));
targetSlice = comboPartition->currentText();
targetSlice.truncate(targetSlice.indexOf(":"));
targetSlice = targetSlice.remove(0, targetSlice.size() -2);
target = targetDisk + targetSlice;
targetLoc = 2;
}
// Get the size of the slice we are working on
totalSize = getDiskSliceSize();
// Setup some swap space
if ( totalSize > 30000 ) {
// 2GB if over 30GB of disk space, 512MB otherwise
swapsize = 2000;
} else {
swapsize = 512;
}
totalSize = totalSize - swapsize;
if ( totalSize != -1 )
{
fsType= "ZFS";
// This lets the user do nifty stuff like a mirror/raid post-install with a single zpool command
fileSystem << targetDisk << targetSlice << "/,/tmp(compress=lzjb),/usr(canmount=off),/usr/home,/usr/jails,/usr/obj(compress=lzjb),/usr/pbi,/usr/ports(compress=gzip),/usr/ports/distfiles(compress=off),/usr/src(compress=gzip),/var(canmount=off),/var/audit(compress=lzjb),/var/log(compress=gzip),/var/tmp(compress=lzjb)" << fsType << tmp.setNum(totalSize) << "" << tmpPass;
sysFinalDiskLayout << fileSystem;
fileSystem.clear();
// Now add swap space
fileSystem << targetDisk << targetSlice << "SWAP" << "SWAP" << tmp.setNum(swapsize) << "" << "";
sysFinalDiskLayout << fileSystem;
fileSystem.clear();
//qDebug() << "Auto-Gen FS:" << fileSystem;
}
qDebug() << "AutoLayout:" << sysFinalDiskLayout;
}
void wizardDisk::populateDiskTree()
{
QStringList tmpList, zMnts;
QString tmp, opts;
treeMounts->clear();
treeMounts->setHeaderLabels(QStringList() << "ID" << tr("ZFS Mounts") << tr("ZFS Options") );
treeMounts->setColumnCount(3);
labelFreeSpace->setVisible(false);
lineFreeMB->setVisible(false);
treeMounts->header()->setSectionHidden(0, true);
treeMounts->header()->setDefaultSectionSize(150);
zMnts = sysFinalDiskLayout.at(0).at(2).split(",");
// Now loop through ZFS mounts
for (int i=0; i < zMnts.count(); ++i) {
tmpList.clear();
opts = zMnts.at(i).section("(", 1, 1).section(")", 0, 0);
tmpList << tmp.setNum(i+1) << zMnts.at(i).split("(").at(0) << opts ;
QTreeWidgetItem *mItem = new QTreeWidgetItem(treeMounts, tmpList);
mItem->setToolTip(2, opts);
}
treeMounts->setCurrentItem(treeMounts->findItems("0", Qt::MatchFixedString).at(0));
slotTreeDiskChanged();
if ( restoreMode ) {
treeMounts->setEnabled(false);
pushRemoveMount->setEnabled(false);
pushAddMount->setEnabled(false);
labelMounts->setText(tr("The original system datasets / mount-points will be automatically restored."));
}
}
int wizardDisk::getDiskSliceSize()
{
bool ok;
QString disk = comboDisk->currentText();
disk.truncate(disk.indexOf(" -"));
int safeBuf = 10;
// Check the full disk
if ( comboPartition->currentIndex() == 0) {
for (int i=0; i < sysDisks.count(); ++i) {
// Make sure to only add the drives to the comboDiskList
if ( sysDisks.at(i).at(0) == "DRIVE" && sysDisks.at(i).at(1) == disk ) {
//qDebug() << "Selected Disk Size: " + sysDisks.at(i).at(2);
sysDisks.at(i).at(2).toInt(&ok);
if( ok )
return sysDisks.at(i).at(2).toInt(&ok) - safeBuf;
else
return -1;
}
}
} else {
// Check the selected partition
QString slice = comboPartition->currentText();
slice.truncate(slice.indexOf(":"));
for (int i=0; i < sysDisks.count(); ++i) {
// Make sure to only add the slices to the listDiskSlices
if ( sysDisks.at(i).at(0) == "SLICE" && slice == sysDisks.at(i).at(2)) {
//qDebug() << "Selected Slice Size: " + sysDisks.at(i).at(3);
sysDisks.at(i).at(3).toInt(&ok);
if( ok )
return sysDisks.at(i).at(3).toInt(&ok) - safeBuf;
else
return -1;
}
}
}
return -1;
}
void wizardDisk::slotTreeDiskChanged()
{
if ( ! treeMounts->currentItem() )
return;
pushRemoveMount->setEnabled(true);
pushAddMount->setEnabled(true);
if ( treeMounts->currentItem()->text(1) == "/boot" || treeMounts->currentItem()->text(1) == "/")
pushRemoveMount->setEnabled(false);
if ( lineFreeMB->text() == "0" )
pushAddMount->setEnabled(false);
}
void wizardDisk::slotResizeFS()
{
if ( ! treeMounts->currentItem() )
return;
QString mnt = treeMounts->currentItem()->text(1);
bool ok;
int curSize, availSize, minSize;
curSize = treeMounts->currentItem()->text(2).toInt(&ok);
availSize = curSize + lineFreeMB->text().toInt(&ok);
minSize = 100;
// See if we need some other sanity check on sizes
if ( mnt == "SWAP" )
minSize = 256;
if ( mnt == "/" )
minSize = 2000;
if ( mnt == "/boot" )
minSize = 1000;
addingMount="";
rFS = new dialogFSSize();
rFS->programInit(QString(tr("Resizing") + " " + mnt), curSize, availSize, minSize);
rFS->setWindowModality(Qt::ApplicationModal);
connect(rFS, SIGNAL(saved(int)), this, SLOT(slotSaveFSResize(int)));
rFS->show();
rFS->raise();
}
void wizardDisk::slotRemoveFS()
{
if ( ! treeMounts->currentItem() )
return;
int ret = QMessageBox::question(this, tr("Remove mount-point"),
tr("Are you sure you want to remove this mount point?"),
QMessageBox::Yes | QMessageBox::No,
QMessageBox::No);
if ( ret != QMessageBox::Yes )
return;
QTreeWidgetItem *rmItem = treeMounts->currentItem();
treeMounts->setCurrentItem(treeMounts->findItems("0", Qt::MatchFixedString).at(0));
delete rmItem;
}
void wizardDisk::slotAddFS()
{
bool ok;
QString tmp;
QString nMount = QInputDialog::getText(this, tr("Enter mount-point"),
tr("Please enter the new mount-point:"), QLineEdit::Normal,
"/", &ok);
if (!ok || nMount.isEmpty())
return;
// Sanity checks
////////////////////////////////////////
if ( nMount.indexOf("/") != 0 ) {
QMessageBox::critical(this, tr("Invalid Mount"),
tr("Mount point should start with '/'"),
QMessageBox::Ok,
QMessageBox::Ok);
return;
}
// End sanity checks
////////////////////////////////////////
// Make sure this mount doesn't already exist
QList<QTreeWidgetItem *> mItems = treeMounts->findItems("*", Qt::MatchWildcard);
for ( int i = 0; i < mItems.size(); ++i) {
if ( mItems.at(i)->text(1) == nMount )
return;
}
new QTreeWidgetItem(treeMounts, QStringList() << tmp.setNum(mItems.size() + 1) << nMount );
}
void wizardDisk::slotSaveFSResize(int newSize)
{
QString tmp, tmp2;
bool ok;
int oSize, availSize, tSize, newAvailSize;
// If adding a new mount point
if ( ! addingMount.isEmpty() ) {
QList<QTreeWidgetItem *> mItems = treeMounts->findItems("*", Qt::MatchWildcard);
new QTreeWidgetItem(treeMounts, QStringList() << tmp.setNum(mItems.size() + 1) << addingMount << tmp2.setNum(newSize) << "UFS+SUJ" );
addingMount="";
availSize = lineFreeMB->text().toInt(&ok);
newAvailSize = availSize - newSize;
lineFreeMB->setText(tmp.setNum(newAvailSize));
return;
}
if ( ! treeMounts->currentItem() )
return;
// Just resizing an existing partition
oSize = treeMounts->currentItem()->text(2).toInt(&ok);
treeMounts->currentItem()->setText(2, tmp.setNum(newSize));
// Set the available size
if ( oSize > newSize ) {
tSize = oSize - newSize;
availSize = lineFreeMB->text().toInt(&ok);
newAvailSize = availSize + tSize;
} else {
tSize = newSize - oSize;
availSize = lineFreeMB->text().toInt(&ok);
newAvailSize = availSize - tSize;
}
lineFreeMB->setText(tmp.setNum(newAvailSize));
// Check if we need to enable the add button
if ( newAvailSize >= 100 )
pushAddMount->setEnabled(true);
else
pushAddMount->setEnabled(false);
}
void wizardDisk::slotTreeMountsRightClick()
{
if ( ! treeMounts->currentItem() )
return;
popup = new QMenu();
popup->setTitle(tr("Editing:") + " " + treeMounts->currentItem()->text(1));
popup->addSeparator();
// Create atime sub-menu
popupAT = popup->addMenu("atime");
popupAT->addAction( "on", this, SLOT(slotZATON()));
popupAT->addAction( "off", this, SLOT(slotZATOFF()));
// Create canmount sub-menu
popupCM = popup->addMenu("canmount");
popupCM->addAction( "on", this, SLOT(slotZCMON()));
popupCM->addAction( "off", this, SLOT(slotZCMOFF()));
popupCM->addAction( "noauto", this, SLOT(slotZCMNOAUTO()));
// Create Checksum sub-menu
popupCH = popup->addMenu("checksum");
popupCH->addAction( "on", this, SLOT(slotZChkON()));
popupCH->addAction( "off", this, SLOT(slotZChkOFF()));
// Create compression sub-menu
popupCmp = popup->addMenu("compression");
popupCmp->addAction( "off", this, SLOT(slotZCmpOFF()));
popupCmp->addAction( "on", this, SLOT(slotZCmpON()));
popupCmp->addAction( "lz4", this, SLOT(slotZCmpLZ4()));
popupCmp->addAction( "lzjb", this, SLOT(slotZCmpLZJB()));
popupCmp->addAction( "gzip", this, SLOT(slotZCmpGZIP()));
popupCmp->addAction( "zle", this, SLOT(slotZCmpZLE()));
// Create dedup sub-menu
// dedup is disabled for now, until such time as it is safe in all cases
//popupDD = popup->addMenu("dedup");
//popupDD->addAction( "off", this, SLOT(slotZDDOFF()));
//popupDD->addAction( "on", this, SLOT(slotZDDON()));
//popupDD->addAction( "verify", this, SLOT(slotZDDVERIFY()));
// Create exec sub-menu
popupNE = popup->addMenu("exec");
popupNE->addAction( "on", this, SLOT(slotZEXON()));
popupNE->addAction( "off", this, SLOT(slotZEXOFF()));
popup->exec( QCursor::pos() );
}
void wizardDisk::slotZCMNOAUTO()
{
toggleZFSOpt(QString("canmount=noauto"));
}
void wizardDisk::slotZCMOFF()
{
toggleZFSOpt(QString("canmount=off"));
}
void wizardDisk::slotZCMON()
{
toggleZFSOpt(QString("canmount=on"));
}
void wizardDisk::slotZDDVERIFY()
{
toggleZFSOpt(QString("dedup=verify"));
}
void wizardDisk::slotZDDON()
{
toggleZFSOpt(QString("dedup=on"));
}
void wizardDisk::slotZDDOFF()
{
toggleZFSOpt(QString("dedup=off"));
}
void wizardDisk::slotZCmpZLE()
{
toggleZFSOpt(QString("compress=zle"));
}
void wizardDisk::slotZCmpGZIP()
{
toggleZFSOpt(QString("compress=gzip"));
}
void wizardDisk::slotZCmpLZ4()
{
toggleZFSOpt(QString("compress=lz4"));
}
void wizardDisk::slotZCmpLZJB()
{
toggleZFSOpt(QString("compress=lzjb"));
}
void wizardDisk::slotZCmpOFF()
{
toggleZFSOpt(QString("compress=off"));
}
void wizardDisk::slotZCmpON()
{
toggleZFSOpt(QString("compress=on"));
}
void wizardDisk::slotZChkOFF()
{
toggleZFSOpt(QString("checksum=off"));
}
void wizardDisk::slotZChkON()
{
toggleZFSOpt(QString("checksum=on"));
}
void wizardDisk::slotZATON()
{
toggleZFSOpt(QString("atime=on"));
}
void wizardDisk::slotSwapSize()
{
bool ok;
QString tmp;
int size = QInputDialog::getInt(this, tr("Enter SWAP size"),
tr("Size (MB)"), swapsize, 0, 1000000, 1, &ok);
if ( ok )
swapsize = size;
}
void wizardDisk::slotZATOFF()
{
toggleZFSOpt(QString("atime=off"));
}
void wizardDisk::slotZEXOFF()
{
toggleZFSOpt(QString("exec=off"));
}
void wizardDisk::slotZEXON()
{
toggleZFSOpt(QString("exec=on"));
}
// Toggle an option being on / off for ZFS
void wizardDisk::toggleZFSOpt(QString option)
{
if ( ! treeMounts->currentItem() )
return;
bool found = false;
QString optTag = option.section("=", 0, 0);
QString tmpTag;
QStringList newOpts;
QStringList curOpts = treeMounts->currentItem()->text(2).split("|");
for (int i=0; i < curOpts.count(); ++i) {
tmpTag=curOpts.at(i).section("=", 0, 0);
if ( optTag == tmpTag ) {
found = true;
// Only save option if setting to new value
if ( option != curOpts.at(i) )
newOpts << option;
} else {
if ( !curOpts.at(i).isEmpty() )
newOpts << curOpts.at(i);
}
}
if ( ! found )
newOpts << option;
QString optString;
if ( newOpts.count() <= 1)
optString = newOpts.join("");
else
optString = newOpts.join("|");
treeMounts->currentItem()->setText(2, optString);
treeMounts->currentItem()->setToolTip(2, optString);
}
void wizardDisk::generateCustomDiskLayout()
{
QString targetType, tmp;
int targetLoc;
QString targetDisk, targetSlice, tmpPass, fsType, target;
// Clear out the original disk layout
sysFinalDiskLayout.clear();
QStringList fileSystem;
qDebug() << "Generating custom disk layout";
if ( comboPartition->currentIndex() == 0) {
targetType = "DRIVE";
targetSlice = "ALL";
targetDisk = comboDisk->currentText();
targetDisk.truncate(targetDisk.indexOf(" -"));
target = targetDisk;
targetLoc = 1;
} else {
targetType = "SLICE";
targetDisk = comboDisk->currentText();
targetDisk.truncate(targetDisk.indexOf(" -"));
targetSlice = comboPartition->currentText();
targetSlice.truncate(targetSlice.indexOf(":"));
targetSlice = targetSlice.remove(0, targetSlice.size() -2);
target = targetDisk + targetSlice;
targetLoc = 2;
}
// Start building the ZFS file-systems
QStringList zMnts;
fsType = "ZFS";
int zpoolSize = getDiskSliceSize();
// Deduct any swap space
zpoolSize = zpoolSize - swapsize;
// Get the zfs mounts
QList<QTreeWidgetItem *> mItems = treeMounts->findItems("*", Qt::MatchWildcard);
for ( int i = 0; i < mItems.size(); ++i) {
if ( mItems.at(i)->text(2).isEmpty() )
zMnts << mItems.at(i)->text(1);
else
zMnts << mItems.at(i)->text(1) + "(" + mItems.at(i)->text(2) + ")";
}
// If we have any additional ZFS mirror / raidz devices set it up now
QString zOpts, zDisk;
if ( groupZFSOpts->isChecked() && comboPartition->currentIndex() == 0 ) {
zOpts = comboZFSMode->currentText() + ":";
for ( int i = 0; i < listZFSDisks->count(); ++i )
if ( listZFSDisks->item(i)->checkState() == Qt::Checked ) {
zDisk = listZFSDisks->item(i)->text();
zDisk.truncate(zDisk.indexOf(" -"));
zOpts = zOpts + " " + zDisk;
}
}
// Save the final disk layout
fileSystem.clear();
fileSystem << targetDisk << targetSlice << zMnts.join(",") << fsType << tmp.setNum(zpoolSize) << zOpts << tmpPass;
sysFinalDiskLayout << fileSystem;
fileSystem.clear();
fileSystem << targetDisk << targetSlice << "SWAP" << "SWAP" << tmp.setNum(swapsize) << "" << "";
sysFinalDiskLayout << fileSystem;
qDebug() <<"AutoLayout:" << sysFinalDiskLayout;
}
void wizardDisk::generateConfirmationText()
{
// If running in expert mode, we just create a simple config / confirmation
if ( radioExpert->isChecked() ) {
QStringList filesystem;
filesystem << "MANUAL" << "/mnt" ;
sysFinalDiskLayout << filesystem;
textConfirmation->setText(tr("Installing to file-system mounted at /mnt"));
return;
}
QList<QStringList> copyList;
QStringList summaryList;
QString tmp, workingDisk, workingSlice, tmpSlice, XtraTmp, startPart, sliceSize;
int disk = 0;
// Copy over the list to a new variable we can mangle without modifying the original
copyList = sysFinalDiskLayout;
// Start our summary
summaryList << "";
summaryList << "<b>" + tr("The disk will be setup with the following configuration:") + "</b>";
while ( ! copyList.empty() )
{
workingDisk = copyList.at(0).at(0);
workingSlice = copyList.at(0).at(1);
tmpSlice = workingSlice;
// Check if this is an install to "Unused Space"
for (int z=0; z < sysDisks.count(); ++z)
if ( sysDisks.at(z).at(0) == "SLICE" \
&& sysDisks.at(z).at(2) == workingDisk + workingSlice \
&& sysDisks.at(z).at(4) == "Unused Space" )
tmpSlice = "free";
// Check for any mirror for this device
for (int i=0; i < copyList.count(); ++i) {
if ( copyList.at(i).at(2).indexOf("MIRROR(" + workingDisk + ")") != -1 )
{
summaryList << tr("Disk:") + copyList.at(i).at(0) + " " + tr("Mirroring:") + workingDisk;
copyList.removeAt(i);
break;
}
}
// If after doing the mirror, our list is empty, break out
if ( copyList.empty() )
break;
// If there is a dedicated /boot partition, need to list that first, see what is found
for (int i=0; i < copyList.count(); ++i) {
QStringList mounts = copyList.at(i).at(2).split(",");
for (int z = 0; z < mounts.size(); ++z) {
if ( copyList.at(i).at(0) == workingDisk \
&& copyList.at(i).at(1) == workingSlice \
&& mounts.at(z) == "/boot" )
startPart="/boot";
}
}
// If no dedicated /boot partition, then lets list "/" first
if(startPart.isEmpty())
startPart="/";
// Start by looking for the root partition
for (int i=0; i < copyList.count(); ++i) {
QStringList mounts = copyList.at(i).at(2).split(",");
for (int z = 0; z < mounts.size(); ++z) {
if ( copyList.at(i).at(0) == workingDisk \
&& copyList.at(i).at(1) == workingSlice \
&& mounts.at(z) == startPart ) {
// Check if we have any extra arguments to throw on the end
XtraTmp="";
if ( ! copyList.at(i).at(5).isEmpty() )
XtraTmp=" (" + copyList.at(i).at(5) + ")" ;
// Write the user summary
summaryList << "";
summaryList << tr("Partition:") + " " + workingDisk + "(" + workingSlice + "):";
summaryList << tr("FileSystem:") + " " + copyList.at(i).at(3);
summaryList << tr("Size:") + " " + copyList.at(i).at(4) + "MB ";
if ( copyList.at(i).at(3) == "ZFS" ) {
QStringList zDS = copyList.at(i).at(2).split(",/");
QString zTMP;
for (int ds = 0; ds < zDS.size(); ++ds) {
if ( zDS.at(ds) != "/" )
zDS.replace(ds, "/" + zDS.at(ds));
if ( zDS.at(ds).indexOf("(") != -1 ) {
zTMP = zDS.at(ds);
zTMP.replace("(", " (");