14#include <sys/statvfs.h>
20#include <zypp/base/Easy.h>
21#include <zypp/base/LogTools.h>
22#include <zypp-core/base/DtorReset>
23#include <zypp/base/String.h>
26#include <zypp/ExternalProgram.h>
28#include <zypp/sat/detail/PoolImpl.h>
51 static const ::DUChanges _initdu = { 0, 0, 0, 0 };
52 std::vector< ::DUChanges> duchanges( result.size(), _initdu );
55 for_( it, result.begin(), result.end() )
57 duchanges[idx].path = it->dir.c_str();
59 duchanges[idx].flags |= DUCHANGES_ONLYADD;
64 ::pool_calc_duchanges( satpool.get(),
65 const_cast<Bitmap &
>(installedmap_r),
72 for_( it, result.begin(), result.end() )
78 it->pkg_size = it->used_size
79 + duchanges[idx].kbytes
80 + ( duchanges[idx].files * ( it->fstype ==
"btrfs" ? 4096 : it->block_size ) / blockAdjust );
100 if ( it->status().isInstalled() != it->status().transacts() )
105 return calcDiskUsage(
_mps, bitmap );
111 bitmap.
set( solv_r.
id() );
117 return calcDiskUsage(
_mps, bitmap );
126 return calcDiskUsage(
_mps, bitmap_r );
133 typedef std::map<std::string, MountPoint> Btrfsfilter;
134 Btrfsfilter btrfsfilter;
136 std::ifstream procmounts(
"/proc/mounts" );
139 WAR <<
"Unable to read /proc/mounts" << std::endl;
143 if ( rootdir !=
"/" )
146 while ( procmounts ) {
148 if ( !(procmounts.fail() || procmounts.bad()) ) {
159 std::vector<std::string> words;
162 if ( words.size() < 3 ) {
163 WAR <<
"Suspicious entry in /proc/mounts: " << l << std::endl;
170 if ( words[0].find(
'/' ) == std::string::npos ) {
171 DBG <<
"Discard mount point : " << l << std::endl;
176 if (words[0] ==
"/proc")
178 DBG <<
"Discard /proc filesystem: " << l << std::endl;
185 std::string mp = words[1];
187 if ( mp.compare( 0, prfx.size(), prfx ) != 0 ) {
189 DBG <<
"Unwanted mount point : " << l << std::endl;
193 mp.erase( 0, prfx.size() );
196 }
else if ( mp[0] !=
'/' ) {
198 DBG <<
"Unwanted mount point : " << l << std::endl;
206 if ( words[2] ==
"iso9660" ) {
207 DBG <<
"Discard cdrom : " << l << std::endl;
211 if ( words[2] ==
"vfat" || words[2] ==
"fat" || words[2] ==
"ntfs" || words[2] ==
"ntfs-3g")
213 MIL << words[1] <<
" contains ignored fs (" << words[2] <<
')' << std::endl;
220 const char * mpunwanted[] = {
221 "/mnt",
"/media",
"/mounts",
"/floppy",
"/cdrom",
222 "/suse",
"/tmp",
"/var/tmp",
"/var/adm/mount",
"/var/adm/YaST",
226 const char ** nomp = mpunwanted;
227 for ( ; *nomp; ++nomp ) {
228 std::string pre( *nomp );
229 if ( mp.compare( 0, pre.size(), pre ) == 0
230 && ( mp.size() == pre.size() || mp[pre.size()] ==
'/' ) ) {
235 DBG <<
"Filter mount point : " << l << std::endl;
242 MountPoint::HintFlags hints;
244 std::vector<std::string> flags;
245 str::split( words[3], std::back_inserter(flags),
"," );
247 for (
unsigned i = 0; i < flags.size(); ++i ) {
248 if ( flags[i] ==
"ro" ) {
254 DBG <<
"Filter ro mount point : " << l << std::endl;
261 bool btrfshack =
false;
262 if ( words[2] ==
"btrfs" )
265 if ( geteuid() != 0 )
267 DBG <<
"Assume snapshots on " << words[1] <<
": non-root user can't check" << std::endl;
275 std::string line( prog.receiveLine() );
276 if ( ! line.empty() )
278 DBG <<
"Found a snapshot on " << words[1] <<
": " << line;
289 if ( statvfs( words[1].c_str(), &sb ) != 0 ) {
290 WAR <<
"Unable to statvfs(" << words[1] <<
"); errno " << errno << std::endl;
298 if ( sb.f_blocks == 0 || sb.f_bsize == 0 )
300 DBG <<
"Filter zero-sized mount point : " << l << std::endl;
315 ((
long long)sb.f_blocks)*sb.f_bsize/1024,
316 ((
long long)(sb.f_blocks - sb.f_bfree))*sb.f_bsize/1024, 0LL, hints );
318 else if ( bmp.
dir > mp )
323 ((
long long)sb.f_blocks)*sb.f_bsize/1024,
324 ((
long long)(sb.f_blocks - sb.f_bfree))*sb.f_bsize/1024, 0LL, hints ) );
331 for (
auto && bmp : btrfsfilter )
332 ret.insert( std::move(bmp.second) );
static const Unit K
1024 Byte
static MountPointSet justRootPartition()
Only one entry for "/" to collect total sizes.
MountPointSet disk_usage(const ResPool &pool) const
Compute disk usage if the current transaction woud be commited.
std::set< MountPoint > MountPointSet
static MountPointSet detectMountPoints(const std::string &rootdir="/")
Get mountpoints of system below rootdir If we happen to detect snapshotting btrfs partitions,...
Assign a vaiable a certain value when going out of scope.
Execute a program and give access to its io An object of this class encapsulates the execution of an ...
const_iterator end() const
const_iterator begin() const
Libsolv (bit)Map wrapper.
size_type size() const
Size of the Map.
static constexpr PoolSizeType poolSize
An object indicating the bitmap should match the current pools capacity.
void set(size_type idx_r)
Set bit idx_r.
static Pool instance()
Singleton ctor.
detail::CPool * get() const
Expert backdoor.
A Solvable object within the sat Pool.
IdType id() const
Expert backdoor.
String related utilities and Regular expression matching.
std::string getline(std::istream &str, const Trim trim_r)
Return stream content up to (but not returning) the next newline.
unsigned split(const C_Str &line_r, TOutputIterator result_r, const C_Str &sepchars_r=" \t", const Trim trim_r=NO_TRIM)
Split line_r into words.
Easy-to use interface to the ZYPP dependency resolver.
std::ostream & dumpRange(std::ostream &str, TIterator begin, TIterator end, const std::string &intro="{", const std::string &pfx="\n ", const std::string &sep="\n ", const std::string &sfx="\n", const std::string &extro="}")
Print range defined by iterators (multiline style).
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
Mount point description If block_size is set DiskUsageCoutner will assume half a block_size is wasted...
ByteCount commitDiff() const
Size change due to installation as ByteCount for convenience.
ByteCount usedSize() const
Used size of the filesystem as ByteCount for convenience.
@ Hint_readonly
readonly partitions
@ Hint_growonly
growonly partitions (e.g. snapshotting btrfs)
bool readonly
hint for readonly partitions
std::string dir
Directory name.
ByteCount blockSize() const
Block size of the filesystem as ByteCount for convenience.
bool growonly
hint for growonly partitions (e.g. snapshotting btrfs)
std::string fstype
Filesystem type (provided by detectMountPoints)
ByteCount totalSize() const
Total size of the filesystem as ByteCount for convenience.
To Solvable transform functor.
#define for_(IT, BEG, END)
Convenient for-loops using iterator.