Add labelling of mounted ext2/3/4 (#163)(#600496)

E2label works the same way whether an ext2/3/4 file system is mounted or
not, by directly reading and writing the superblock from the partition
block device.  (Technically the superblock will already be in the kernel
device buffer cache because the kernel has the ext2/3/4 file system
mounted and a reference to the superblock in the device buffer cache).
This is safe and supported as confirmed here [1].  As this method has
always worked, even on the oldest distributions, unconditionally enable
this feature.

    # mkfs.ext4 -L label_1 /dev/sdb3
    # mount /dev/sdb3 /mnt/3
    # e2label /dev/sdb3 label_2
    # blkid /dev/sdb3
    /dev/sdb3: LABEL="label_2" ...

[1] Is labelling a mounted ext2/3/4 file system safe and supported?
    https://lore.kernel.org/linux-ext4/CAMU1PDgNvW_3Jr91iii-Nh=DCuRytVG8ka3-J+a43gKwigx8Yg@mail.gmail.com/T/#u

Bug 600496 - Allow changing ext2/3 label without unmounting
Closes #163 - Feature request: set label on a mounted btrfs
This commit is contained in:
Mike Fleetwood 2021-07-27 11:52:09 +01:00 committed by Curtis Gedak
parent 0c13855d52
commit e4427b0333
1 changed files with 2 additions and 0 deletions

View File

@ -98,6 +98,7 @@ FS ext2::get_filesystem_support()
{ {
fs.read_label = FS::EXTERNAL; fs.read_label = FS::EXTERNAL;
fs.write_label = FS::EXTERNAL; fs.write_label = FS::EXTERNAL;
fs.online_write_label = FS::EXTERNAL;
} }
if ( ! Glib::find_program_in_path( "e2fsck" ).empty() ) if ( ! Glib::find_program_in_path( "e2fsck" ).empty() )
@ -247,6 +248,7 @@ void ext2::read_label( Partition & partition )
bool ext2::write_label( const Partition & partition, OperationDetail & operationdetail ) bool ext2::write_label( const Partition & partition, OperationDetail & operationdetail )
{ {
// Called when file system is unmounted *and* when mounted.
return ! execute_command( "e2label " + Glib::shell_quote( partition.get_path() ) + return ! execute_command( "e2label " + Glib::shell_quote( partition.get_path() ) +
" " + Glib::shell_quote( partition.get_filesystem_label() ), " " + Glib::shell_quote( partition.get_filesystem_label() ),
operationdetail, EXEC_CHECK_STATUS ); operationdetail, EXEC_CHECK_STATUS );