From a3b18ab3b4ef306b7ca924d7553ad4d95b43ee0b Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Wed, 28 Feb 2018 00:52:31 +0100 Subject: [PATCH] Implement userfs move --- addon/lib/rmupdate.tcl | 15 ++++++-------- addon/www/index.html | 46 +++++++++++++++++++++++++++++++++--------- 2 files changed, 42 insertions(+), 19 deletions(-) diff --git a/addon/lib/rmupdate.tcl b/addon/lib/rmupdate.tcl index e706119..7ece4d2 100644 --- a/addon/lib/rmupdate.tcl +++ b/addon/lib/rmupdate.tcl @@ -710,19 +710,15 @@ proc ::rmupdate::move_userfs_to_device {target_device {sync_data 0} {repartition } set source_partition_device [get_mounted_device "/usr/local"] - set source_device [string range $source_partition_device 0 end-1] - if { [regexp {mmcblk} $source_partition_device match] } { - set source_device [string range $source_partition_device 0 end-2] - } + set source_device [get_disk_device $source_partition_device] - if { $source_device == ""} { + if {$source_partition_device == "" || $source_device == ""} { error [i18n "Failed to find source device for /usr/local."] } - if { $source_device == $target_device} { + if {$source_device == $target_device} { error [i18n "Source and target are the same device."] } - if {$target_partition_device == ""} { set partition_number 0 if {$repartition == 1} { @@ -774,8 +770,8 @@ proc ::rmupdate::move_userfs_to_device {target_device {sync_data 0} {repartition } } - catch { exec tune2fs -L 0userfs $source_partition_device } - catch { exec tune2fs -L userfs $target_partition_device } + catch { exec /sbin/tune2fs -L 0userfs $source_partition_device } + catch { exec /sbin/tune2fs -L userfs $target_partition_device } } proc ::rmupdate::clone_system {target_device {activate_clone 0}} { @@ -1533,3 +1529,4 @@ proc ::rmupdate::wlan_disconnect {} { #puts [rmupdate::get_partitions] #puts [array_to_json [rmupdate::get_partitions]] #rmupdate::move_userfs_to_device /dev/sda1 1 0 +#puts [rmupdate::get_mounted_device "/usr/local"] diff --git a/addon/www/index.html b/addon/www/index.html index 15e0565..1a0e990 100644 --- a/addon/www/index.html +++ b/addon/www/index.html @@ -38,6 +38,7 @@ along with this program. If not, see . var current_firmware = '?'; var latest_firmware = '?'; var wlanScanTimer; + var moving_userfs_to_device = false; function display_message(type, text, millis) { clear_message(); @@ -326,14 +327,18 @@ along with this program. If not, see . data.forEach(function(partition) { if (partition.partition == 0) { disks[partition.disk_device] = partition; - disks[partition.disk_device].usr_local_on_disk = false; + disks[partition.disk_device].userfs_on_disk = false; + disks[partition.disk_device].bootfs_on_disk = false; disks[partition.disk_device].partitions = {}; } }); data.forEach(function(partition) { disks[partition.disk_device].partitions[partition.partition] = partition; if (partition.mountpoint == '/usr/local') { - disks[partition.disk_device].usr_local_on_disk = true; + disks[partition.disk_device].userfs_on_disk = true; + } + else if (partition.mountpoint == '/boot') { + disks[partition.disk_device].bootfs_on_disk = true; } }); $('#volume-info tbody').empty(); @@ -345,7 +350,18 @@ along with this program. If not, see . var partition = disks[disk_device].partitions[part]; var menu_items = []; - if (! disks[disk_device].usr_local_on_disk) { + var skip_dev = false; + if (disks[disk_device].userfs_on_disk) { + skip_dev = true; + } + else if (disks[disk_device].bootfs_on_disk && (partition.partition == 0)) { + skip_dev = true; + } + else if ((partition.partition > 0) && (partition.filesystem_label == 'bootfs' || partition.filesystem_label == 'rootfs' || partition.filesystem_label == 'rootfs1' || partition.filesystem_label == 'rootfs2')) { + skip_dev = true; + } + + if (! skip_dev) { var device = partition.disk_device; var label = i18next.t('use_disk_for_userfs'); if (partition.partition > 0) { @@ -355,15 +371,23 @@ along with this program. If not, see . menu_items.push($('').append(label).attr('data-device', device).click(function() { var target_device = this.getAttribute('data-device'); $('#modal-move-userfs').modal({ - onDeny: function(){ + onDeny: function() { return true; }, onApprove: function() { - rest('POST', '/move_userfs_to_device', JSON.stringify({"target_device":target_device}), function(data) { - display_message('success', i18next.t('userfs_moved'), 120000); - rest('POST', '/system_reboot'); - }); - return true; + moving_userfs_to_device = true; + display_message('warning', i18next.t('moving_userfs'), 300000); + rest('POST', '/move_userfs_to_device', JSON.stringify({"target_device":target_device}), + function(data) { + moving_userfs_to_device = false; + display_message('success', i18next.t('userfs_moved'), 120000); + rest('POST', '/system_reboot'); + }, + function(xhr, ajaxOptions, thrownError) { + moving_userfs_to_device = false; + default_error_callback(xhr, ajaxOptions, thrownError); + } + ); } }) .modal('show'); @@ -371,7 +395,7 @@ along with this program. If not, see . } var menu = null; if (menu_items.length > 0) { - menu = $('