diff options
-rwxr-xr-x | backend/magiback | 5 | ||||
-rwxr-xr-x | backend/raw_write.py | 43 | ||||
-rwxr-xr-x | lib/isodumper.py | 36 |
3 files changed, 65 insertions, 19 deletions
diff --git a/backend/magiback b/backend/magiback index 108618a..5c55307 100755 --- a/backend/magiback +++ b/backend/magiback @@ -43,6 +43,7 @@ class Isodumper(raw_write.Dumper): <arg type='s' name='target' direction='in'/> <arg type='s' name='label' direction='in'/> <arg type='s' name='key' direction='in'/> + <arg type='s' name='fs_type' direction='in'/> </method> <method name='set_backup_mode'> <arg type='x' name='uid' direction='in'/> @@ -102,10 +103,10 @@ class Isodumper(raw_write.Dumper): logging.debug(self.return_message) self.finished.set() - def do_persistence(self, target, label, key): + def do_persistence(self, target, label, key, fs_type): self.finished.clear() if self.writing_perm and self.writing_target == target: - self.thread = threading.Thread(target=self._do_persistence, args=(target, label, key)) + self.thread = threading.Thread(target=self._do_persistence, args=(target, label, key, fs_type)) self.thread.start() logging.info("Persistence thread started") else: diff --git a/backend/raw_write.py b/backend/raw_write.py index d46fe1e..fe21046 100755 --- a/backend/raw_write.py +++ b/backend/raw_write.py @@ -198,9 +198,16 @@ class Dumper(object): return False return True - def _do_persistence(self, target, label, key): + def _do_persistence(self, target, label, key, fs_type): logging.debug("Start doing persistence partition") p = Popen(["fdisk", target], stdin=PIPE, stderr=PIPE) + # commands: + # n : new + # p : primary partition + # 3 : partition number (1-4) + # default first sector + # default last sector + # w : write and quit outs, errs = p.communicate(input=b"n\np\n3\n\n\nw\n") working = True while working: @@ -250,15 +257,35 @@ class Dumper(object): logging.debug("New partition created") self._progress = 25 - # Wait for propagation of the info of new partition table - if not self.udev_wait("creating a new partition table"): - return + ## Wait for propagation of the info of new partition table + #if not self.udev_wait("creating a new partition table"): + #logging.error("Timeout") + #self.return_state = False + #self.finished.set() + #return if key == "": # example mkfs.ext4 -L mgalive-persist /dev/sdf3 - self.return_message = _("Persistent partition added. Formatting...") - process = Popen( - ["mkfs.ext4", "-q", "-F", "-L", label, target + "3"], stderr=PIPE - ) + self.return_message = _("Additional partition added. Formatting...") + path = target + "3" + # Format partition according to the fs_type specified + fs_type = fs_type.lower() + if fs_type == "fat32": + cmd = ["mkdosfs", "-F", "32", "-n", label.upper()[:11], path] + elif fs_type == "exfat": + cmd = ["mkfs.exfat", "-n", label.upper()[:11], path] + elif fs_type == "ntfs": + cmd = ["mkntfs", "-f", "-L", label, path] + elif fs_type == "ext4": + cmd = [ + "mkfs.ext4", + "-q", + "-F", + "-L", + label, + path, + ] + logging.info(f"Executing {' '.join(cmd)}") + process = Popen(cmd, stderr=PIPE) outs, errs = process.communicate() working = True while working: diff --git a/lib/isodumper.py b/lib/isodumper.py index 94f0484..48353be 100755 --- a/lib/isodumper.py +++ b/lib/isodumper.py @@ -6,7 +6,7 @@ # # Author: Oliver Grawert <ogra@ubuntu.com> # -# Modifications 2013 from papoteur <papoteur@mageialinux-online.org> +# Modifications 2013-2023 from papoteur <papoteur@mageialinux-online.org> # and Geiger David <david.david@mageialinux-online.org> # # This program is free software; you can redistribute it and/or @@ -260,6 +260,12 @@ class Logging(): class IsoDumper(basedialog.BaseDialog): + # Maximal length for partition label + label_length = { "fat32": 11, + "ext4": 16, + "ntfs": 32, + "exfat": 11 + } def get_devices(self, selected=None): self.list = self.u.find_devices() while len(self.list) == 0: @@ -467,9 +473,9 @@ class IsoDumper(basedialog.BaseDialog): ) if self.ask_YesOrNo(info): name = self.partition_label.value() - if format_type == "fat32": + if format_type == "fat32" or format_type == "exfat": name = name.upper()[:11] - elif format_type == "exfat" or format_type == "ntfs": + elif format_type == "ntfs": name = name[:32] rc = self.raw_format(target, format_type, name) self.operation = False @@ -675,13 +681,10 @@ class IsoDumper(basedialog.BaseDialog): nowarning, message = self.iface.end() self.progress.setEnabled() # Add persistent partition if asked, persistent or not - if ( - self.partition_cbox.isChecked() - and self.partition_cb.value() == "ext4" - ): + if (self.partition_cbox.isChecked()): self.progress.setLabel(_("Adding partition")) self.progress.setValue(0) - if self.cryptcb.isChecked(): + if self.cryptcb.isChecked() and (self.partition_cb.value() == "ext4"): if self.cryptkey.value() == "": message = _( "No key for encrypted partition provided. Adding the partition aborted." @@ -692,6 +695,7 @@ class IsoDumper(basedialog.BaseDialog): target, self.partition_label.value(), self.cryptkey.value(), + self.partition_cb.value() ) while not self.iface.done: progress = self.iface.progress @@ -714,7 +718,7 @@ class IsoDumper(basedialog.BaseDialog): nowarning = False else: self.iface.do_persistence( - target, self.partition_label.value(), "" + target, self.partition_label.value(), "", self.partition_cb.value() ) while not self.iface.done: progress = self.iface.progress @@ -1281,6 +1285,20 @@ exFAT, NTFS or ext. You can specify a volume name and the format in a new dialog info = Info(_("Error"), True, _("No image to write is selected.")) self.ask_OK(info) return + if self.partition_cbox.isChecked(): + format_type = list(self.format_type.keys())[ + list(self.format_type.values()).index(self.partition_cb.value()) + ] + if len(self.partition_label.value()) > self.label_length[format_type]: + info = Info( + _("Warning"), + True, + _( + "Label length will be shorten to {} characters. Do you want to continue?".format(self.label_length[format_type]) + ), + ) + if not self.ask_YesOrNo(info): + return if self.backup_cbox.isChecked() and self.backup_is_selected: backup_success, message = self.backup_go() if not backup_success: |