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() )
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) );
346 str <<
"dir:[" << obj.
dir <<
"] [ bs: " << obj.
blockSize()
355 {
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...