1
0
mirror of https://gitlab.gnome.org/GNOME/gparted synced 2024-07-07 19:39:25 +00:00
gparted/include/BlockSpecial.h
Mike Fleetwood 571304d2c6 Pre-populate BlockSpecial cache while reading /proc/partitions (#767842)
GParted is already reading /proc/partitions to get whole disk device
names.  The file also contains the major, minor device number of every
partition.  Use this information to pre-populate the cache in the
BlockSpecial class.

    # cat /proc/partitions
    major minor  #blocks  name

       8        0   20971520 sda
       8        1     512000 sda1
       8        2   20458496 sda2
    ...
       9        3    1047552 md3
     259        2     262144 md3p1
     259        3     262144 md3p2
    ...
     253        0   18317312 dm-0
     253        1    2097152 dm-1
     253        2    8383872 dm-2
     253        3    1048576 dm-3

Note that for Device-Mapper names (dm-*) the kernel is not using the
canonical user space names (mapper/*).  There is no harm in
pre-populating the cache with these names and will help if tools report
them too.  It is just that for DMRaid, LVM and LUKS, GParted uses the
canonical /dev/mapper/* names so will still have to call stat() once for
each such name.

For plain disks (sd*) and Linux Software RAID arrays (md*) the kernel
name is the common user space name too, therefore matches what GParted
uses and pre-populating does avoid calling stat() at all for these
names.

Bug 767842 - File system usage missing when tools report alternate block
             device names
2016-08-06 09:47:58 -06:00

60 lines
2.0 KiB
C++

/* Copyright (C) 2016 Mike Fleetwood
*
* 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/>.
*/
/* BlockSpecial
*
* Representation of a POSIX block special file, e.g. /dev/sda1. Also
* tracks the major, minor device numbers so that different names for
* the same block device can be compared equal.
* Refs: mknod(1) and mknod(2).
*/
#ifndef GPARTED_BLOCKSPECIAL_H
#define GPARTED_BLOCKSPECIAL_H
#include <glibmm/ustring.h>
namespace GParted
{
class BlockSpecial
{
public:
BlockSpecial();
BlockSpecial( const Glib::ustring & name );
~BlockSpecial();
Glib::ustring m_name; // E.g. Block special file {"/dev/sda1", 8, 1},
unsigned long m_major; // plain file {"FILENAME", 0, 0} and empty object
unsigned long m_minor; // {"", 0, 0}.
static void clear_cache();
static void register_block_special( const Glib::ustring & name,
unsigned long major, unsigned long minor );
};
// Operator overloading > The Decision between Member and Non-member
// http://stackoverflow.com/questions/4421706/operator-overloading/4421729#4421729
// "2. If a binary operator treats both operands equally (it leaves them unchanged),
// implement this operator as a non-member function."
bool operator==( const BlockSpecial & lhs, const BlockSpecial & rhs );
bool operator<( const BlockSpecial & lhs, const BlockSpecial & rhs );
}//GParted
#endif /* GPARTED_BLOCKSPECIAL_H */