2010-12-09 14:06:38 -07:00
|
|
|
/* Copyright (C) 2008, 2009, 2010 Curtis Gedak
|
2008-11-11 10:19:46 -07:00
|
|
|
*
|
|
|
|
* 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
|
2014-01-23 03:59:48 -07:00
|
|
|
* GNU General Public License for more details.
|
2008-11-11 10:19:46 -07:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2014-01-23 03:59:48 -07:00
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2008-11-11 10:19:46 -07:00
|
|
|
*/
|
|
|
|
|
2013-05-27 05:20:16 -06:00
|
|
|
#ifndef GPARTED_FS_INFO_H
|
|
|
|
#define GPARTED_FS_INFO_H
|
2008-11-11 10:19:46 -07:00
|
|
|
|
2016-10-18 16:45:28 -06:00
|
|
|
#include "BlockSpecial.h"
|
2016-07-07 08:34:57 -06:00
|
|
|
|
2016-07-07 06:11:44 -06:00
|
|
|
#include <glibmm/ustring.h>
|
|
|
|
#include <vector>
|
2008-11-11 10:19:46 -07:00
|
|
|
|
|
|
|
namespace GParted
|
|
|
|
{
|
|
|
|
|
2016-07-07 06:11:44 -06:00
|
|
|
struct FS_Entry
|
|
|
|
{
|
2016-07-07 08:34:57 -06:00
|
|
|
BlockSpecial path;
|
2016-07-07 06:11:44 -06:00
|
|
|
Glib::ustring type;
|
|
|
|
Glib::ustring sec_type;
|
|
|
|
Glib::ustring uuid;
|
|
|
|
bool have_label;
|
|
|
|
Glib::ustring label;
|
|
|
|
};
|
|
|
|
|
2008-11-11 10:19:46 -07:00
|
|
|
class FS_Info
|
|
|
|
{
|
|
|
|
public:
|
2021-03-29 13:31:48 -06:00
|
|
|
static void clear_cache();
|
Pass device and partition names to blkid (#131)
A user reported that GParted would hang at "scanning all devices...",
when a fully working disk was named on the command line, but another
device on the machine was hung.
This can be replicated like this:
(on Ubuntu 20.04 LTS for it's NBD support)
1. Export and import NBD:
# truncate -s 1G /tmp/disk-1G.img
# nbd-server -C /dev/null 9000 /tmp/disk-1G.img
# nbd-client localhost 9000 /dev/nbd0
2. Hang the NBD server and therefore /dev/nbd0:
# killall -STOP nbd-server
3. Run GParted:
$ gparted /dev/sda
Tracing GParted shows that execution of blkid never returns.
# strace -f -tt -q -bexecve -eexecve ./gpartedbin 2>&1 1> /dev/null | fgrep -v ENOENT
...
[pid 37823] 13:56:24.814139 execve("/usr/sbin/mkudffs", ["mkudffs", "--help"], 0x55e2a3f2d230 /* 20 vars */ <detached ...>
[pid 37814] 13:56:24.829246 --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=37823, si_uid=0, si_status=1, si_utime=0, si_stime=0} ---
[pid 37825] 13:56:25.376796 execve("/usr/sbin/blkid", ["blkid", "-v"], 0x55e2a3f2d230 /* 20 vars */ <detached ...>
[pid 37824] 13:56:25.380824 --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=37825, si_uid=0, si_status=0, si_utime=0, si_stime=0} ---
[pid 37826] 13:56:25.402512 execve("/usr/sbin/blkid", ["blkid"], 0x55e2a3f2d230 /* 20 vars */ <detached ...>
Tracking of blkid shows that it hangs on either the open of or first
read from /dev/nbd0.
# strace blkid
...
lstat("/dev", {st_mode=S_IFDIR|0755, st_size=4560, ...}) = 0
lstat("/dev/nbd0", {st_mode=S_IFBLK|0660, st_rdev=makedev(0x2b, 0), ...}) = 0
stat("/dev/nbd0", {st_mode=S_IFBLK|0660, st_rdev=makedev(0x2b, 0), ...}) = 0
lstat("/dev", {st_mode=S_IFDIR|0755, st_size=4560, ...}) = 0
lstat("/dev/nbd0", {st_mode=S_IFBLK|0660, st_rdev=makedev(0x2b, 0), ...}) = 0
access("/dev/nbd0", F_OK) = 0
stat("/dev/nbd0", {st_mode=S_IFBLK|0660, st_rdev=makedev(0x2b, 0), ...}) = 0
openat(AT_FDCWD, "/sys/dev/block/43:0", O_RDONLY|O_CLOEXEC) = 4
openat(4, "dm/uuid", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
close(4) = 0
openat(AT_FDCWD, "/dev/nbd0", O_RDONLY|O_CLOEXEC
Clean up:
1. Resume NBD server:
# killall -CONT nbd-server
2. Delete NBD setup:
# nbd-client -d /dev/nbd0
# killall nbd-server
# rm /tmp/disk-1G.img
Fix this by making GParted specify the whole disk device and partition
names that it is interested in to blkid, rather than letting blkid scan
and report all block devices. Do this both when GParted determines the
devices for itself and when they are named on the command line.
Also update example blkid command output being parsed and cache value
with this change to how blkid is executed.
Closes #131 - GParted hangs when non-named device is hung
2021-01-24 07:33:04 -07:00
|
|
|
static void load_cache_for_paths(const std::vector<Glib::ustring>& paths);
|
2016-07-08 09:26:32 -06:00
|
|
|
static Glib::ustring get_fs_type( const Glib::ustring & path );
|
|
|
|
static Glib::ustring get_label( const Glib::ustring & path, bool & found );
|
|
|
|
static Glib::ustring get_uuid( const Glib::ustring & path );
|
|
|
|
static Glib::ustring get_path_by_uuid( const Glib::ustring & uuid );
|
|
|
|
static Glib::ustring get_path_by_label( const Glib::ustring & label );
|
2016-07-07 06:11:44 -06:00
|
|
|
|
2008-11-11 10:19:46 -07:00
|
|
|
private:
|
2021-01-31 05:51:13 -07:00
|
|
|
static bool not_initialised_then_error();
|
2016-07-07 06:11:44 -06:00
|
|
|
static void set_commands_found();
|
|
|
|
static const FS_Entry & get_cache_entry_by_path( const Glib::ustring & path );
|
2021-01-31 06:16:22 -07:00
|
|
|
static void run_blkid_load_cache(const std::vector<Glib::ustring>& paths);
|
2017-08-28 03:52:44 -06:00
|
|
|
static void update_fs_info_cache_all_labels();
|
2017-08-27 07:31:38 -06:00
|
|
|
static bool run_blkid_update_cache_one_label( FS_Entry & fs_entry );
|
2016-07-07 06:11:44 -06:00
|
|
|
|
2009-04-24 17:18:36 -06:00
|
|
|
static bool fs_info_cache_initialized ;
|
|
|
|
static bool blkid_found ;
|
2015-03-08 05:13:20 -06:00
|
|
|
static bool need_blkid_vfat_cache_update_workaround;
|
2016-07-07 06:11:44 -06:00
|
|
|
static std::vector<FS_Entry> fs_info_cache;
|
2008-11-11 10:19:46 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
}//GParted
|
|
|
|
|
2013-05-27 05:20:16 -06:00
|
|
|
#endif /* GPARTED_FS_INFO_H */
|