int main(int argc, char *argv[]) { int fuseargcount=1; char *fuseargv[6]; struct fuse_operations capfs_oper; capfs_oper.init = capfs_init, capfs_oper.destroy = capfs_destroy, capfs_oper.getattr = capfs_getattr, capfs_oper.fgetattr = capfs_fgetattr, capfs_oper.access = capfs_access, capfs_oper.readlink = capfs_readlink, capfs_oper.readdir = capfs_readdir, capfs_oper.mknod = capfs_mknod, capfs_oper.mkdir = capfs_mkdir, capfs_oper.symlink = capfs_symlink, capfs_oper.unlink = capfs_unlink, capfs_oper.rmdir = capfs_rmdir, capfs_oper.rename = capfs_rename, capfs_oper.link = capfs_link, capfs_oper.chmod = capfs_chmod, capfs_oper.chown = capfs_chown, capfs_oper.truncate = capfs_truncate, capfs_oper.ftruncate = capfs_ftruncate, capfs_oper.utimens = capfs_utimens, capfs_oper.create = capfs_create, capfs_oper.open = capfs_open, capfs_oper.read = capfs_read, capfs_oper.write = capfs_write, capfs_oper.statfs = capfs_statfs, capfs_oper.release = capfs_release, capfs_oper.opendir = capfs_opendir, capfs_oper.releasedir = capfs_releasedir, capfs_oper.fsync = capfs_fsync, capfs_oper.flush = capfs_flush, capfs_oper.fsyncdir = capfs_fsyncdir, capfs_oper.lock = capfs_lock, capfs_oper.bmap = capfs_bmap, capfs_oper.ioctl = capfs_ioctl, capfs_oper.poll = capfs_poll, capfs_oper.setxattr = capfs_setxattr, capfs_oper.getxattr = capfs_getxattr, capfs_oper.listxattr = capfs_listxattr, capfs_oper.removexattr = capfs_removexattr, capfs_oper.flag_nullpath_ok = 0; fuseargv[0]=argv[0]; if ((argc > 1) && (argv[1][0] == '-')) { fuseargv[1]=argv[1]; fuseargcount=2; } string_literal_wrapper mino("-o"); fuseargv[fuseargcount]=mino; //After the argv[0] and optionaly a -d argument set some options: string_literal_wrapper allow_other("allow_other"); fuseargv[fuseargcount+1]=allow_other; //* allow all users to access the filesystem. string_literal_wrapper mins("-s"); fuseargv[fuseargcount+2]=mins; //Run the filesystem as single threaded. string_literal_wrapper mountpoint("/minorfs/cap"); fuseargv[fuseargcount+3]=mountpoint; return fuse_main(4+fuseargcount, fuseargv, &capfs_oper,NULL); }
void DeviceWidget::runButtonClicked(){ //Run the device (audio/video CD, browse filesystem) if(isMounted){ //Open the mountpoint directory QProcess::startDetached("xdg-open \""+mountpoint()+"\""); }else if(type()=="CD-AUDIO"){ if(QFile::exists("/usr/local/bin/vlc")){ QProcess::startDetached("vlc cdda://1");} else if(QFile::exists("/usr/local/bin/smplayer")){ QProcess::startDetached("smplayer cdda://1"); } else{ QProcess::startDetached("xdg-open cdda://1"); } }else if(type()=="CD-VIDEO"){ if(QFile::exists("/usr/local/bin/vlc")){ QProcess::startDetached("vlc dvd://1");} else if(QFile::exists("/usr/local/bin/smplayer")){ QProcess::startDetached("smplayer dvd://1"); } else{ QProcess::startDetached("xdg-open dvd://1"); } } emit CloseMenu(); }
int DialogClone::do_image_partition() { MWindow window; QString befehl; QString _Datum_clone = window.Zeit_auslesen(); Qt::CheckState state; lbl_save->setText (tr("already saved", "bereits gesichert")); state = chk_zip->checkState(); flag_clone =3; if (img_partition_clone == "" ){ QMessageBox::about(this, tr("Note", "Hinweis"), tr("You must select a partition.", "Sie müssen eine Partition auswählen.\n")); return 0; } if (folder_clone == "" ){ QMessageBox::about(this, tr("Note", "Hinweis"), tr("You must select a folder.", "Sie müssen ein Verzeichnis auswählen.\n")); return 0; } partition_exist_size_int = img_partition_size.toInt(); // Überprüfen, ob System oder Home-Partition auf der Festplatte vorhanden ist int part_art_clone = mountpoint(img_partition_clone); if (part_art_clone == 1){ QMessageBox::about(this, tr("Note", "Hinweis"), tr("On the hard drive exist a root or a home partition. You must need a live-CD.", "Auf der Festplatte ist eine root- oder home Partition. Sie müssen eine Live-CD benutzen.\n")); return 0; } if (state == Qt::Checked) befehl = "dd if=/dev/" + img_partition_clone + " | gzip --best > " + folder_clone + "/" + img_partition_clone + "-" + _Datum_clone + "-gz.part.fsa"; else befehl = "dd if=/dev/" + img_partition_clone + " of=" + folder_clone + "/" + img_partition_clone + "-" + _Datum_clone + "-part.fsa bs=1M 2>" + homepath + "/.config/qt5-fsarchiver/disk.txt"; thread1.setValues( 0,befehl); int ret = questionMessage(tr(" Do you want really built a image from a partition? ", " Wollen Sie wirklich ein Abbild einer Partition erstellen? ") ); if (ret == 2) return 0; if (ret == 1){ bt_end->setEnabled(false); bt_save->setEnabled(false); ViewProzent(); this->setCursor(Qt::WaitCursor); if (state == Qt::Checked){ read_write_hd(); startThread1(1); } else startThread1(0); qDebug() << "The image is created"; } return 0; }
int DialogClone::restore_image() { QString befehl; int row; int pos; QString partition_exist; QString partition_exist_size; Qt::CheckState state; lbl_save->setText (tr("already restored", "bereits zurückgeschrieben")); state = chk_zip->checkState(); flag_clone =2; row = listWidget_exist->currentRow(); if (row > -1){ partition_exist = part_clone[row][0] ; partition_exist_size = part_clone[row][1]; pos = partition_exist_size.indexOf("."); if (pos > 0) partition_exist_size = partition_exist_size.left(partition_exist_size.size() -2); partition_exist_size_int = partition_exist_size.toInt(); } partition_exist = partition_exist.left(partition_exist.size() -1); if (partition_exist == "" ){ QMessageBox::about(this, tr("Note", "Hinweis"), tr("You must select a hard drive.", "Sie müssen eine Festplatte auswählen.\n")); return 0; } if (folder_clone == "" ){ QMessageBox::about(this, tr("Note", "Hinweis"), tr("You must select a gz.fsa file or an img.fsa file.", "Sie müssen eine gz.fsa- oder eine img.fsa-Datei auswählen.\n")); return 0; } if (file_check() == 1) return 0; // Prüfen, ob gesicherte und wiederherzustellende Partition übereinstimmt. // Festplatte aus folder_clone extrahieren QString disk_name; pos = folder_clone.indexOf(".gz.fsa"); if (pos > -1) disk_name = folder_clone.mid(pos-14,3); pos = folder_clone.indexOf(".img.fsa"); if (pos > -1) disk_name = folder_clone.mid(pos-14,3); disk_name = partition_exist.right(partition_exist.size() -4); if (folder_clone.indexOf(disk_name) == -1) pos = questionMessage(tr("Partition to restore ", "Die wiederherzustellende Partition ") + disk_name + tr(" does not coincide with the saved ", " stimmt nicht mit der gesicherten ") + img_partition_clone + tr(" Do you want to continue restore?", " überein. Wollen Sie trotzdem die Wiederherstellung durchführen?")); if (pos == 2) //nicht wiederherstellen return 0; // Überprüfen, ob System oder Home-Partition auf der Festplatte vorhanden ist int part_art_clone = mountpoint(partition_exist); if (part_art_clone == 1){ QMessageBox::about(this, tr("Note", "Hinweis"), tr("On the hard drive exist a root or a home partition. You must need a live-CD.", "Auf der Festplatte ist eine root- oder home Partition. Sie müssen eine Live-CD benutzen.\n")); return 0; } partition_name = partition_exist.right(partition_exist.size() -4); //Prüfen ob img.fsa oder gz.fsa Datei if (folder_clone.indexOf("gz.fsa") > 0) befehl = "gunzip -c " + folder_clone + " | sudo dd of=" + partition_exist; if (folder_clone.indexOf("img.fsa") > 0) befehl = "dd if=" + folder_clone + " of=" + partition_exist + " bs=1M 2>" + homepath + "/.config/qt5-fsarchiver/disk.txt"; int ret = questionMessage(tr(" Do you want really restore the image of the hard drive? ", " Wollen Sie wirklich ein Abbild der Festplatte zurückschreiben? ") ); if (ret == 2) return 0; if (ret == 1){ bt_end->setEnabled(false); bt_save->setEnabled(false); thread2.setValues( 0,befehl); ViewProzent(); this->setCursor(Qt::WaitCursor); pos = folder_clone.indexOf("gz.fsa"); if (pos > 0){ read_write_hd(); startThread2(1); } else startThread2(0); qDebug() << "The image is written back"; } return 0; }
int DialogClone::do_image() { MWindow window; QString _Datum_clone = window.Zeit_auslesen(); QString befehl; int row; int pos; QString partition_exist; QString partition_exist_size; Qt::CheckState state; lbl_save->setText (tr("already saved", "bereits gesichert")); state = chk_zip->checkState(); flag_clone =2; row = listWidget_exist->currentRow(); if (row > -1){ partition_exist = part_clone[row][0] ; partition_exist_size = part_clone[row][1]; pos = partition_exist_size.indexOf("."); if (pos > 0) partition_exist_size = partition_exist_size.left(partition_exist_size.size() -2); partition_exist_size_int = partition_exist_size.toInt(); } partition_exist = partition_exist.left(partition_exist.size() -1); //qDebug() << "partition_exist_size_int" << partition_exist_size_int; //return 0; if (partition_exist == "" ){ QMessageBox::about(this, tr("Note", "Hinweis"), tr("You must select a partition.", "Sie müssen eine Partition auswählen.\n")); return 0; } if (folder_clone == "" ){ QMessageBox::about(this, tr("Note", "Hinweis"), tr("You must select a folder.", "Sie müssen ein Verzeichnis auswählen.\n")); return 0; } // Überprüfen, ob System oder Home-Partition auf der Festplatte vorhanden ist int part_art_clone = mountpoint(partition_exist); if (part_art_clone == 1){ QMessageBox::about(this, tr("Note", "Hinweis"), tr("On the hard drive exist a root or a home partition. You must need a live-CD.", "Auf der Festplatte ist eine root- oder home Partition. Sie müssen eine Live-CD benutzen.\n")); return 0; } partition_name = partition_exist.right(partition_exist.size() -4); if (state == Qt::Checked) befehl = "dd if=" + partition_exist + " | gzip --best > " + folder_clone + partition_name + "-" + _Datum_clone + ".gz.fsa"; else befehl = "dd if=" + partition_exist + " of=" + folder_clone + partition_name + "-" + _Datum_clone + ".img.fsa bs=1M 2>" + homepath + "/.config/qt5-fsarchiver/disk.txt"; thread1.setValues( 0,befehl); int ret = questionMessage(tr(" Do you want really built a image from the hard drive? ", " Wollen Sie wirklich ein Abbild der Festplatte erstellen? ") ); if (ret == 2) return 0; if (ret == 1){ bt_end->setEnabled(false); bt_save->setEnabled(false); ViewProzent(); this->setCursor(Qt::WaitCursor); if (state == Qt::Checked){ read_write_hd(); startThread1(1);} else startThread1(0); qDebug() << "The image is created"; } return 0; }
int DialogClone::do_clone() { QString befehl; int row; int pos; QString partition_exist; QString partition_exist_size; QString partition_clone; QString partition_clone_size; int partition_clone_size_int; lbl_save->setText (tr("already saved", "bereits gesichert")); QFile file(homepath + "/.config/qt5-fsarchiver/disk.txt"); befehl = "rm " + homepath + "/.config/qt5-fsarchiver/disk.txt"; if (file.exists()) system (befehl.toAscii().data()); flag_clone =1; row = listWidget_exist->currentRow(); if (row > -1){ partition_exist = part_clone[row][0] ; partition_exist_size = part_clone[row][1]; pos = partition_exist_size.indexOf("."); if (pos > 0) partition_exist_size = partition_exist_size.left(partition_exist_size.size() -2); partition_exist_size_int = partition_exist_size.toInt(); } row = listWidget_clone->currentRow(); if (row > -1){ partition_clone = part_clone[row][0] ; partition_clone_size = part_clone[row][1]; pos = partition_clone_size.indexOf("."); if (pos > 0) partition_clone_size = partition_clone_size.left(partition_clone_size.size() -2); partition_clone_size_int = partition_clone_size.toInt(); } partition_exist = partition_exist.left(partition_exist.size() -1); partition_clone = partition_clone.left(partition_clone.size() -1); if (partition_exist == "" or partition_clone == ""){ QMessageBox::about(this, tr("Note", "Hinweis"), tr("You must select a hard drive.", "Sie müssen eine Festplatte auswählen.\n")); return 0; } // Überprüfen, ob Festplatte groß genug ist if (partition_exist_size_int > partition_clone_size_int){ QMessageBox::about(this, tr("Note", "Hinweis"), tr("The selected hard drive is too small.", "Die gewählte Festplatte ist zu klein.\n")); return 0; } // Überprüfen, ob System oder Home-Partition auf der Festplatte vorhanden ist int part_art_clone = mountpoint(partition_exist); if (part_art_clone == 1){ QMessageBox::about(this, tr("Note", "Hinweis"), tr("On the hard drive exist a root or a home partition. You must need a live-CD.", "Auf der Festplatte ist eine root- oder home Partition. Sie müssen eine Live-CD benutzen.\n")); return 0; } befehl = "dd if=" + partition_exist + " of=" + partition_clone + " bs=1M 2>" + homepath + "/.config/qt5-fsarchiver/disk.txt"; int ret = questionMessage(tr(" Do you want really clone the hard drive? All dates on ", " Wollen Sie wirklich die Festplatte klonen? Alle Daten auf der Festplatte ") + partition_clone + tr(" are deleted!", " werden gelöscht!") ); if (ret == 2) return 0; thread1.setValues( 0,befehl); ViewProzent(); this->setCursor(Qt::WaitCursor); startThread1(0); return 0; }
// == PRIVATE FUNCTIONS == void DeviceWidget::doUpdate(){ bool firstrun = type().isEmpty(); //qDebug() << "Update Item:" << firstrun << quickupdates << node(); if(firstrun || !quickupdates){ QStringList info = pcbsd::Utils::runShellCommand("pc-sysconfig \"devinfo "+node()+"\"").join("").split(", "); if(info.length() < 3){ emit RefreshDeviceList(); return; } //invalid device - will probably get removed here in a moment //Info Output: <filesystem>, <label>, <type> //qDebug() << " - info:" << info; //Save this into the internal variables ui->label_icon->setWhatsThis(info[2]); //type ui->label_dev->setText(info[1]); //label ui->tool_mount->setWhatsThis(info[0]); //filesystem if(info[0].toLower()=="zfs"){ ui->label_icon->setToolTip(node()+" ("+info[0]+")"); } else{ ui->label_icon->setToolTip("/dev/"+node()+" ("+info[0]+")"); } //Now go through and set all the various icons and such QString icon = ":icons/%1.png"; if(type()=="SATA"){ icon = icon.arg("harddrive"); } else if(type()=="USB"){ icon = icon.arg("usb"); } else if(type()=="SD"){ icon = icon.arg("sdcard"); } else if(type()=="CD-AUDIO"){ icon = icon.arg("musiccd"); } else if(type()=="CD-VIDEO"){ icon = icon.arg("cd-video"); } else if(type().startsWith("CD")){ icon = icon.arg("cd-generic"); } else if(type()=="ISO"){ icon = icon.arg("dvd"); } else{ icon = icon.arg("CDdevices"); } if(filesystem()=="NONE" && !type().startsWith("CD")){ //Add the question-mark overlay to the icon, signifying that it is an unknown filesystem QPixmap tmp(icon); QPixmap overlay(":icons/question-overlay.png"); QPainter paint(&tmp); paint.drawPixmap(ui->label_icon->width()-20, ui->label_icon->height()-20, overlay ); //put it in the bottom-right corner ui->label_icon->setPixmap(tmp); }else{ //Just the normal icon ui->label_icon->setPixmap(QPixmap(icon)); } if(type()=="CD-AUDIO" || type()=="CD-VIDEO"){ ui->tool_run->setIcon(QIcon(":icons/play.png")); ui->tool_run->setText(tr("Play")); }else{ ui->tool_run->setIcon(QIcon(":icons/folder.png") ); ui->tool_run->setText(tr("Browse")); } ui->tool_tray->setVisible(type().startsWith("CD")); //This is a CD tray canmount = filesystem()!="NONE" || !type().startsWith("CD"); //has a detected filesystem or is not a CD ui->tool_mount->setVisible(canmount); ui->check_auto->setVisible(canmount && !type().startsWith("CD")); } //Update the status of the mount button (TO DO - special ISO handling) if(isMounted){ ui->tool_mount->setText(tr("Unmount")); ui->tool_mount->setIcon(QIcon(":icons/eject.png")); QString devsize = pcbsd::Utils::runShellCommand("pc-sysconfig \"devsize "+node()+"\"").join(""); if(devsize.contains("??")){ ui->progressBar->setRange(0,0); }else{ ui->progressBar->setRange(0,100); ui->progressBar->setValue(devsize.section("(",1,1).section("%",0,0).toInt()); ui->progressBar->setToolTip(devsize); } }else{ ui->tool_mount->setText(tr("Mount")); ui->tool_mount->setIcon(QIcon(":icons/mount.png")); } ui->label_icon->setEnabled(isMounted || !canmount); ui->tool_run->setVisible( (isMounted && !mountpoint().isEmpty()) || type()=="CD-AUDIO" || type()=="CD-VIDEO" ); //if it is mounted, it can also be run ui->progressBar->setVisible(isMounted && ui->progressBar->maximum()==100); if(firstrun){ if(canmount && !type().startsWith("CD") ){ //Load auto-mount database and act appropriately QString AMFILE = QDir::homePath() + "/.pc-automounttray"; if(QFile::exists(AMFILE)){ QString cmd = "cat "+AMFILE; QString search = label() +" "+ type()+" "+ filesystem(); bool amount = !pcbsd::Utils::runShellCommandSearch(cmd, search).isEmpty(); ui->check_auto->setChecked(amount); if(amount){ mountButtonClicked(); if(isMounted){ emit ShowMessage(tr("Device Mounted"), QString(tr("%1 has been automatically mounted on %2")).arg(label(), mountpoint()) ); runButtonClicked(); //also open the directory } } } }else if(canmount){ //This is some kind of optical disk that can also be mounted (Blueray/DVD, or data disk for instance) if(type()!="CD-DATA"){ runButtonClicked(); } //not a pure data disk - go ahead and prompt to run it }else if(autoplay){ //Always try to "play" a non-mountable device when it is first connected (AUDIO/VIDEO CD usually) runButtonClicked(); } } }