gparted/include/btrfs.h

61 lines
2.0 KiB
C
Raw Permalink Normal View History

/* Copyright (C) 2009,2010 Luca Bruno <lucab@debian.org>
* Copyright (C) 2010 Curtis Gedak
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GPARTED_BTRFS_H
#define GPARTED_BTRFS_H
#include "FileSystem.h"
#include "BlockSpecial.h"
#include "Partition.h"
namespace GParted
{
struct BTRFS_Device
{
int devid;
std::vector<BlockSpecial> members;
} ;
class btrfs : public FileSystem
{
public:
FS get_filesystem_support() ;
void set_used_sectors( Partition & partition ) ;
Detect busy status of multi-device btrfs file systems (#723842) Busy detection of file systems works by checking if the device is mounted (appears in the mount_info map). For a multi-device btrfs file system this will only report one of the devices as busy, not all of them. # btrfs filesystem show /dev/sdb1 Label: none uuid: 36eb51a2-2927-4c92-820f-b2f0b5cdae50 Total devices 2 FS bytes used 156.00KB devid 2 size 2.00GB used 512.00MB path /dev/sdb2 devid 1 size 2.00GB used 240.75MB path /dev/sdb1 # mount /dev/sdb1 /mnt/1 # grep btrfs /proc/mounts /dev/sdb1 /mnt/1 btrfs rw,seclabel,relatime,ssd,space_cache 0 0 GParted will only report /dev/sdb1 as busy, but not /dev/sdb2. Add btrfs specific is_busy() method which reports the device as busy if any of the devices in the btrfs file system are mounted. This uses a cache which maps device membership in all btrfs file systems. The cache is cleared on GParted refresh and incrementally populated as each btrfs partition is checked for busy status. WARNING: Removal of the mounting device from a btrfs file system makes it impossible to determine whether the file system is mounted or not for linux <= 3.4. This is because /proc/mounts continues to show the old device which is no longer a member of the file system. # btrfs device delete /dev/sdb1 /mnt/1 # sync # grep btrfs /proc/mounts /dev/sdb1 /mnt/1 btrfs rw,seclabel,relatime,ssd,space_cache 0 0 # btrfs filesystem show /dev/sdb1 # btrfs filesystem show /dev/sdb2 Label: none uuid: 36eb51a2-2927-4c92-820f-b2f0b5cdae50 Total devices 1 FS bytes used 28.00KB devid 2 size 2.00GB used 1.02GB path /dev/sdb2 Fixed in linux 3.5 by commit: Btrfs: implement ->show_devname https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=9c5085c147989d48dfe74194b48affc23f376650 Bug #723842 - GParted resizes the wrong filesystem (does not pass the devid to btrfs filesystem resize)
2014-02-17 15:39:34 -07:00
bool is_busy( const Glib::ustring & path ) ;
void read_label( Partition & partition ) ;
bool write_label( const Partition & partition, OperationDetail & operationdetail ) ;
void read_uuid( Partition & partition ) ;
bool write_uuid( const Partition & partition, OperationDetail & operationdetail );
bool create( const Partition & new_partition, OperationDetail & operationdetail ) ;
bool resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition );
bool check_repair( const Partition & partition, OperationDetail & operationdetail ) ;
Detect busy status of multi-device btrfs file systems (#723842) Busy detection of file systems works by checking if the device is mounted (appears in the mount_info map). For a multi-device btrfs file system this will only report one of the devices as busy, not all of them. # btrfs filesystem show /dev/sdb1 Label: none uuid: 36eb51a2-2927-4c92-820f-b2f0b5cdae50 Total devices 2 FS bytes used 156.00KB devid 2 size 2.00GB used 512.00MB path /dev/sdb2 devid 1 size 2.00GB used 240.75MB path /dev/sdb1 # mount /dev/sdb1 /mnt/1 # grep btrfs /proc/mounts /dev/sdb1 /mnt/1 btrfs rw,seclabel,relatime,ssd,space_cache 0 0 GParted will only report /dev/sdb1 as busy, but not /dev/sdb2. Add btrfs specific is_busy() method which reports the device as busy if any of the devices in the btrfs file system are mounted. This uses a cache which maps device membership in all btrfs file systems. The cache is cleared on GParted refresh and incrementally populated as each btrfs partition is checked for busy status. WARNING: Removal of the mounting device from a btrfs file system makes it impossible to determine whether the file system is mounted or not for linux <= 3.4. This is because /proc/mounts continues to show the old device which is no longer a member of the file system. # btrfs device delete /dev/sdb1 /mnt/1 # sync # grep btrfs /proc/mounts /dev/sdb1 /mnt/1 btrfs rw,seclabel,relatime,ssd,space_cache 0 0 # btrfs filesystem show /dev/sdb1 # btrfs filesystem show /dev/sdb2 Label: none uuid: 36eb51a2-2927-4c92-820f-b2f0b5cdae50 Total devices 1 FS bytes used 28.00KB devid 2 size 2.00GB used 1.02GB path /dev/sdb2 Fixed in linux 3.5 by commit: Btrfs: implement ->show_devname https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=9c5085c147989d48dfe74194b48affc23f376650 Bug #723842 - GParted resizes the wrong filesystem (does not pass the devid to btrfs filesystem resize)
2014-02-17 15:39:34 -07:00
static void clear_cache() ;
static Glib::ustring get_mount_device( const Glib::ustring & path ) ;
static std::vector<Glib::ustring> get_members( const Glib::ustring & path ) ;
Detect busy status of multi-device btrfs file systems (#723842) Busy detection of file systems works by checking if the device is mounted (appears in the mount_info map). For a multi-device btrfs file system this will only report one of the devices as busy, not all of them. # btrfs filesystem show /dev/sdb1 Label: none uuid: 36eb51a2-2927-4c92-820f-b2f0b5cdae50 Total devices 2 FS bytes used 156.00KB devid 2 size 2.00GB used 512.00MB path /dev/sdb2 devid 1 size 2.00GB used 240.75MB path /dev/sdb1 # mount /dev/sdb1 /mnt/1 # grep btrfs /proc/mounts /dev/sdb1 /mnt/1 btrfs rw,seclabel,relatime,ssd,space_cache 0 0 GParted will only report /dev/sdb1 as busy, but not /dev/sdb2. Add btrfs specific is_busy() method which reports the device as busy if any of the devices in the btrfs file system are mounted. This uses a cache which maps device membership in all btrfs file systems. The cache is cleared on GParted refresh and incrementally populated as each btrfs partition is checked for busy status. WARNING: Removal of the mounting device from a btrfs file system makes it impossible to determine whether the file system is mounted or not for linux <= 3.4. This is because /proc/mounts continues to show the old device which is no longer a member of the file system. # btrfs device delete /dev/sdb1 /mnt/1 # sync # grep btrfs /proc/mounts /dev/sdb1 /mnt/1 btrfs rw,seclabel,relatime,ssd,space_cache 0 0 # btrfs filesystem show /dev/sdb1 # btrfs filesystem show /dev/sdb2 Label: none uuid: 36eb51a2-2927-4c92-820f-b2f0b5cdae50 Total devices 1 FS bytes used 28.00KB devid 2 size 2.00GB used 1.02GB path /dev/sdb2 Fixed in linux 3.5 by commit: Btrfs: implement ->show_devname https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=9c5085c147989d48dfe74194b48affc23f376650 Bug #723842 - GParted resizes the wrong filesystem (does not pass the devid to btrfs filesystem resize)
2014-02-17 15:39:34 -07:00
private:
static const BTRFS_Device & get_cache_entry( const Glib::ustring & path ) ;
};
Use btrfs filesystem show --raw to read usage (!105) 'btrfs filesystem show' only used to report rounded human readable size figures. Therefore the actual figure could have been anywhere within the rounding limit. GParted also applied a heuristic to snap the file system size figure to the partition size if the partition size was within the rounding limit of the reported file system size [1]. btrfs-progs v4.1 added the --raw option to print the figures in bytes [2][3][4]. # btrfs filesystem show --raw /dev/sdb1 Label: none uuid: 003a619e-856f-4b9c-bd29-4d0ae0296d66 Total devices 2 FS bytes used 178765824 devid 1 size 2147483648 used 239861760 path /dev/sdb1 devid 2 size 2147483648 used 436207616 path /dev/sdc1 Since the oldest supported distributions now use btrfs-progs v4.5.3 and later (see the distribution End-of-Life table in the previous commit message), unconditionally use this to get accurate figures. [1] 7fc16a1b6905f7f2d6876d317c4757ff09cdd57c Handle btrfs tools rounding of figures (#499202) [2] btrfs-progs: Allow "filesystem show" command to handle different units https://git.kernel.org/pub/scm/linux/kernel/git/kdave/btrfs-progs.git/commit/?id=15379fa2257bf937cf7830c0b1b79f2daf5df72c [3] btrfs-progs: docs: new size options for fi show https://git.kernel.org/pub/scm/linux/kernel/git/kdave/btrfs-progs.git/commit/?id=81225f11d9ea58590476612e69211113ddb9b943 [4] Btrfs progs release 4.1 https://lore.kernel.org/linux-btrfs/20150622150023.GX6761@twin.jikos.cz/ Closes !105 - Update used btrfs file system commands, new minimum is btrfs-progs 4.5
2022-07-25 13:26:37 -06:00
} //GParted
#endif /* GPARTED_BTRFS_H */