[gparted] Add labelling of mounted btrfs (#163)



commit eb034b17597713bbc08dd3ab90444eaa2c0e7ff5
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Thu Jul 22 08:04:12 2021 +0100

    Add labelling of mounted btrfs (#163)
    
    Btrfs supports labelling of the file system while it is mounted.  This
    was added into Linux kernel 3.10 [1] and btrfs-progs 3.12 [2].  As the
    oldest supported distributions have the needed versions or newer,
    unconditionally enable without any checking for availability.
    
        Distro             EOL        Linux kernel   btrfs-progs
        Debian 9           2022-Jun   4.19           4.7.3
        RHEL / CentOS 7    2024-Jun   3.10.0         4.9.1
        Ubuntu 18.04 LTS   2023-Apr   4.15.0         4.15.1
    
    Unmounted btrfs is labelled via the block device containing it, where as
    a mounted btrfs is labelled via it's mount point.
    
        # mkfs.btrfs -L initial_label /dev/sdb1
        # blkid /dev/sdb1
        /dev/sdb1: LABEL="initial_label" ...
    
        # btrfs filesystem label /dev/sdb1 unmounted_label_2
        # blkid /dev/sdb1
        /dev/sdb1: LABEL="unmounted_label_2" ...
    
        # mount /dev/sdb1 /mnt/1
        # btrfs filesystem label /dev/sdb1 mounted_label_3
        # blkid /dev/sdb1
        /dev/sdb1: LABEL="mounted_label_3" ...
    
    [1] 
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=a8bfd4abea3da0e28f215e2a2b8c2f1ca27ebe80
        Btrfs: set/change the label of a mounted file system
    [2] 
https://git.kernel.org/pub/scm/linux/kernel/git/kdave/btrfs-progs.git/commit/?id=619dc61cae1420da2dec48f689d49b9b346abc15
        Btrfs-progs: Change the label of a mounted file system
    
    Closes #163 - Feature request: set label on a mounted btrfs

 include/FileSystem.h |  3 ++-
 src/GParted_Core.cc  |  4 +++-
 src/Win_GParted.cc   |  8 ++++++++
 src/btrfs.cc         | 19 ++++++++++++++++---
 4 files changed, 29 insertions(+), 5 deletions(-)
---
diff --git a/include/FileSystem.h b/include/FileSystem.h
index bbad470e..df3991d4 100644
--- a/include/FileSystem.h
+++ b/include/FileSystem.h
@@ -79,12 +79,13 @@ struct FS
        Support online_read;        // Can and how to read sector usage while active
        Support online_grow;
        Support online_shrink;
+       Support online_write_label;
 
        FS(FSType fstype_ = FS_UNSUPPORTED) : fstype(fstype_)
        {
                busy = read = read_label = write_label = read_uuid = write_uuid = create =
                create_with_label = grow = shrink = move = check = copy = remove = online_read =
-               online_grow = online_shrink = NONE;
+               online_grow = online_shrink = online_write_label = NONE;
        }
 };
 
diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc
index f7ac970c..27eb6a1d 100644
--- a/src/GParted_Core.cc
+++ b/src/GParted_Core.cc
@@ -2053,7 +2053,9 @@ bool GParted_Core::label_filesystem( const Partition & partition, OperationDetai
 
        bool succes = false ;
        FileSystem* p_filesystem = NULL ;
-       switch (get_fs(partition.fstype).write_label)
+       const FS& fs_cap = get_fs(partition.fstype);
+       FS::Support support = (partition.busy) ? fs_cap.online_write_label : fs_cap.write_label;
+       switch (support)
        {
                case FS::EXTERNAL:
                        succes =    (p_filesystem = get_filesystem_object(partition.fstype))
diff --git a/src/Win_GParted.cc b/src/Win_GParted.cc
index f2d1975a..75ea445e 100644
--- a/src/Win_GParted.cc
+++ b/src/Win_GParted.cc
@@ -1299,6 +1299,14 @@ void Win_GParted::set_valid_operations()
        }
 #endif
 
+       // Allow labelling of mounted file systems that support it.
+       if (selected_filesystem.busy                    &&
+           selected_partition_ptr->status == STAT_REAL &&
+           fs_cap.online_write_label                     )
+       {
+               allow_label_filesystem(true);
+       }
+
        // Only unmount/swapoff/VG deactivate or online actions allowed if busy
        if ( selected_filesystem.busy )
                return ;
diff --git a/src/btrfs.cc b/src/btrfs.cc
index f3b7bce3..b8c72086 100644
--- a/src/btrfs.cc
+++ b/src/btrfs.cc
@@ -66,6 +66,7 @@ FS btrfs::get_filesystem_support()
                fs .read_uuid = FS::EXTERNAL ;
                fs.check = FS::EXTERNAL;
                fs.write_label = FS::EXTERNAL;
+               fs.online_write_label = FS::EXTERNAL;
 
                //Resizing of btrfs requires mount, umount and kernel
                //  support as well as btrfs filesystem resize
@@ -261,13 +262,25 @@ void btrfs::set_used_sectors( Partition & partition )
        }
 }
 
+
 bool btrfs::write_label( const Partition & partition, OperationDetail & operationdetail )
 {
-       return ! execute_command( "btrfs filesystem label " + Glib::shell_quote( partition.get_path() ) +
-                                 " " + Glib::shell_quote( partition.get_filesystem_label() ),
-                                 operationdetail, EXEC_CHECK_STATUS );
+       // Use the mount point when labelling a mounted btrfs, or block device containing
+       // the unmounted btrfs.
+       //     btrfs filesystem label '/dev/PTN' 'NEWLABEL'
+       //     btrfs filesystem label '/MNTPNT' 'NEWLABEL'
+       Glib::ustring path;
+       if (partition.busy)
+               path = partition.get_mountpoint();
+       else
+               path = partition.get_path();
+
+       return ! execute_command("btrfs filesystem label " + Glib::shell_quote(path) +
+                                " " + Glib::shell_quote(partition.get_filesystem_label()),
+                                operationdetail, EXEC_CHECK_STATUS);
 }
 
+
 bool btrfs::resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition )
 {
        bool success = true ;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]