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 std::ifstream procmounts(
"/proc/mounts" );
133 WAR <<
"Unable to read /proc/mounts" << std::endl;
137 if ( rootdir !=
"/" )
140 while ( procmounts ) {
142 if ( !(procmounts.fail() || procmounts.bad()) ) {
153 std::vector<std::string> words;
156 if ( words.size() < 3 ) {
157 WAR <<
"Suspicious entry in /proc/mounts: " << l << std::endl;
164 if ( words[0].find(
'/' ) == std::string::npos ) {
165 DBG <<
"Discard mount point : " << l << std::endl;
170 if (words[0] ==
"/proc")
172 DBG <<
"Discard /proc filesystem: " << l << std::endl;
179 std::string mp = words[1];
181 if ( mp.compare( 0, prfx.size(), prfx ) != 0 ) {
183 DBG <<
"Unwanted mount point : " << l << std::endl;
187 mp.erase( 0, prfx.size() );
190 }
else if ( mp[0] !=
'/' ) {
192 DBG <<
"Unwanted mount point : " << l << std::endl;
200 if ( words[2] ==
"iso9660" ) {
201 DBG <<
"Discard cdrom : " << l << std::endl;
205 if ( words[2] ==
"vfat" || words[2] ==
"fat" || words[2] ==
"ntfs" || words[2] ==
"ntfs-3g")
207 MIL << words[1] <<
" contains ignored fs (" << words[2] <<
')' << std::endl;
214 const char * mpunwanted[] = {
215 "/mnt",
"/media",
"/mounts",
"/floppy",
"/cdrom",
216 "/suse",
"/var/tmp",
"/var/adm/mount",
"/var/adm/YaST",
220 const char ** nomp = mpunwanted;
221 for ( ; *nomp; ++nomp ) {
222 std::string pre( *nomp );
223 if ( mp.compare( 0, pre.size(), pre ) == 0
224 && ( mp.size() == pre.size() || mp[pre.size()] ==
'/' ) ) {
229 DBG <<
"Filter mount point : " << l << std::endl;
236 MountPoint::HintFlags hints;
238 std::vector<std::string> flags;
239 str::split( words[3], std::back_inserter(flags),
"," );
241 for (
unsigned i = 0; i < flags.size(); ++i ) {
242 if ( flags[i] ==
"ro" ) {
248 DBG <<
"Filter ro mount point : " << l << std::endl;
255 if ( words[2] ==
"btrfs" )
257 if ( geteuid() != 0 )
259 DBG <<
"Assume snapshots on " << words[1] <<
": non-root user can't check" << std::endl;
267 std::string line( prog.receiveLine() );
268 if ( ! line.empty() )
270 DBG <<
"Found a snapshot on " << words[1] <<
": " << line;
281 if ( statvfs( words[1].c_str(), &sb ) != 0 ) {
282 WAR <<
"Unable to statvfs(" << words[1] <<
"); errno " << errno << std::endl;
290 if ( sb.f_blocks == 0 || sb.f_bsize == 0 )
292 DBG <<
"Filter zero-sized mount point : " << l << std::endl;
296 ((
long long)sb.f_blocks)*sb.f_bsize/1024,
297 ((
long long)(sb.f_blocks - sb.f_bfree))*sb.f_bsize/1024, 0LL, hints ) );
315 str <<
"dir:[" << obj.
dir <<
"] [ bs: " << obj.
blockSize()
324 {
return dumpRange( str, obj.begin(), obj.end() ); }
::_Pool * get() const
Expert backdoor.
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.
unsigned split(const C_Str &line_r, _OutputIterator result_r, const C_Str &sepchars_r=" \t")
Split line_r into words.
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.
String related utilities and Regular expression matching.
#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, _Iterator begin, _Iterator 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 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.
Easy-to use interface to the ZYPP dependency resolver.
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...