14 #include <sys/statvfs.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() )
75 it->pkg_size = it->used_size
76 + duchanges[idx].kbytes
77 + ( duchanges[idx].files * it->block_size / blockAdjust );
97 if ( it->status().isInstalled() != it->status().transacts() )
102 return calcDiskUsage(
_mps, bitmap );
108 bitmap.
set( solv_r.
id() );
114 return calcDiskUsage(
_mps, bitmap );
123 return calcDiskUsage(
_mps, bitmap_r );
130 typedef std::map<std::string, MountPoint> Btrfsfilter;
131 Btrfsfilter btrfsfilter;
133 std::ifstream procmounts(
"/proc/mounts" );
136 WAR <<
"Unable to read /proc/mounts" << std::endl;
140 if ( rootdir !=
"/" )
143 while ( procmounts ) {
145 if ( !(procmounts.fail() || procmounts.bad()) ) {
156 std::vector<std::string> words;
159 if ( words.size() < 3 ) {
160 WAR <<
"Suspicious entry in /proc/mounts: " << l << std::endl;
167 if ( words[0].find(
'/' ) == std::string::npos ) {
168 DBG <<
"Discard mount point : " << l << std::endl;
173 if (words[0] ==
"/proc")
175 DBG <<
"Discard /proc filesystem: " << l << std::endl;
182 std::string mp = words[1];
184 if ( mp.compare( 0, prfx.size(), prfx ) != 0 ) {
186 DBG <<
"Unwanted mount point : " << l << std::endl;
190 mp.erase( 0, prfx.size() );
193 }
else if ( mp[0] !=
'/' ) {
195 DBG <<
"Unwanted mount point : " << l << std::endl;
203 if ( words[2] ==
"iso9660" ) {
204 DBG <<
"Discard cdrom : " << l << std::endl;
208 if ( words[2] ==
"vfat" || words[2] ==
"fat" || words[2] ==
"ntfs" || words[2] ==
"ntfs-3g")
210 MIL << words[1] <<
" contains ignored fs (" << words[2] <<
')' << std::endl;
217 const char * mpunwanted[] = {
218 "/mnt",
"/media",
"/mounts",
"/floppy",
"/cdrom",
219 "/suse",
"/tmp",
"/var/tmp",
"/var/adm/mount",
"/var/adm/YaST",
223 const char ** nomp = mpunwanted;
224 for ( ; *nomp; ++nomp ) {
225 std::string pre( *nomp );
226 if ( mp.compare( 0, pre.size(), pre ) == 0
227 && ( mp.size() == pre.size() || mp[pre.size()] ==
'/' ) ) {
232 DBG <<
"Filter mount point : " << l << std::endl;
239 MountPoint::HintFlags hints;
241 std::vector<std::string> flags;
242 str::split( words[3], std::back_inserter(flags),
"," );
244 for (
unsigned i = 0; i < flags.size(); ++i ) {
245 if ( flags[i] ==
"ro" ) {
251 DBG <<
"Filter ro mount point : " << l << std::endl;
258 bool btrfshack =
false;
259 if ( words[2] ==
"btrfs" )
262 if ( geteuid() != 0 )
264 DBG <<
"Assume snapshots on " << words[1] <<
": non-root user can't check" << std::endl;
272 std::string line( prog.receiveLine() );
273 if ( ! line.empty() )
275 DBG <<
"Found a snapshot on " << words[1] <<
": " << line;
286 if ( statvfs( words[1].c_str(), &sb ) != 0 ) {
287 WAR <<
"Unable to statvfs(" << words[1] <<
"); errno " << errno << std::endl;
295 if ( sb.f_blocks == 0 || sb.f_bsize == 0 )
297 DBG <<
"Filter zero-sized mount point : " << l << std::endl;
312 ((
long long)sb.f_blocks)*sb.f_bsize/1024,
313 ((
long long)(sb.f_blocks - sb.f_bfree))*sb.f_bsize/1024, 0LL, hints );
315 else if ( bmp.
dir > mp )
320 ((
long long)sb.f_blocks)*sb.f_bsize/1024,
321 ((
long long)(sb.f_blocks - sb.f_bfree))*sb.f_bsize/1024, 0LL, hints ) );
328 for (
auto && bmp : btrfsfilter )
329 ret.insert( std::move(bmp.second) );
343 str <<
"dir:[" << obj.
dir <<
"] [ bs: " << obj.
blockSize()
352 {
return dumpRange( str, obj.begin(), obj.end() ); }
ByteCount blockSize() const
Block size of the filesystem as ByteCount for convenience.
A Solvable object within the sat Pool.
const_iterator begin() const
ByteCount commitDiff() const
Size change due to installation as ByteCount for convenience.
growonly partitions (e.g. snapshotting btrfs)
size_type size() const
Size of the Map.
static MountPointSet justRootPartition()
Only one entry for "/" to collect total sizes.
bool readonly
hint for readonly partitions
void set(size_type idx_r)
Set bit idx_r.
detail::CPool * get() const
Expert backdoor.
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
const_iterator end() const
Assign a vaiable a certain value when going out of scope.
std::string fstype
Filesystem type (provided by detectMountPoints)
std::set< MountPoint > MountPointSet
static Pool instance()
Singleton ctor.
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).
unsigned split(const C_Str &line_r, TOutputIterator result_r, const C_Str &sepchars_r=" \t")
Split line_r into words.
std::ostream & operator<<(std::ostream &str, const Exception &obj)
Execute a program and give access to its io An object of this class encapsulates the execution of an ...
Mount point description If block_size is set DiskUsageCoutner will assume half a block_size is wasted...
std::string dir
Directory name.
std::string getline(std::istream &str, const Trim trim_r)
Return stream content up to (but not returning) the next newline.
ByteCount totalSize() const
Total size of the filesystem as ByteCount for convenience.
static constexpr PoolSizeType poolSize
An object indicating the bitmap should match the current pools capacity.
static const Unit K
1024 Byte
IdType id() const
Expert backdoor.
MountPointSet disk_usage(const ResPool &pool) const
Compute disk usage if the current transaction woud be commited.
bool growonly
hint for growonly partitions (e.g. snapshotting btrfs)
Libsolv (bit)Map wrapper.
To Solvable transform functor.
ByteCount usedSize() const
Used size of the filesystem as ByteCount for convenience.
static MountPointSet detectMountPoints(const std::string &rootdir="/")
Get mountpoints of system below rootdir If we happen to detect snapshotting btrfs partitions...