14 #include <sys/statvfs.h>
46 void add( sat::Solvable solv_r )
51 void add(
const PoolItem & pi_r )
52 { add( pi_r->satSolvable() ); }
55 { add( obj_r->satSolvable() ); }
71 static const ::DUChanges _initdu = { 0, 0, 0 };
72 std::vector< ::DUChanges> duchanges( result.size(), _initdu );
75 for_( it, result.begin(), result.end() )
77 duchanges[idx].path = it->dir.c_str();
83 ::pool_calc_duchanges( satpool.get(),
84 &installedmap_r._installedmap,
91 for_( it, result.begin(), result.end() )
94 it->pkg_size = it->used_size
95 + duchanges[idx].kbytes
96 + ( duchanges[idx].files * it->block_size / blockAdjust );
115 if ( it->status().isInstalled() != it->status().transacts() )
117 installedmap.add( *it );
120 return calcDiskUsage(
mps, installedmap );
126 installedmap.add( solv_r );
132 return calcDiskUsage(
mps, installedmap );
139 std::ifstream procmounts(
"/proc/mounts" );
142 WAR <<
"Unable to read /proc/mounts" << std::endl;
146 if ( rootdir !=
"/" )
149 while ( procmounts ) {
151 if ( !(procmounts.fail() || procmounts.bad()) ) {
162 std::vector<std::string> words;
165 if ( words.size() < 3 ) {
166 WAR <<
"Suspicious entry in /proc/mounts: " << l << std::endl;
173 if ( words[0].find(
'/' ) == std::string::npos ) {
174 DBG <<
"Discard mount point : " << l << std::endl;
179 if (words[0] ==
"/proc")
181 DBG <<
"Discard /proc filesystem: " << l << std::endl;
188 std::string mp = words[1];
190 if ( mp.compare( 0, prfx.size(), prfx ) != 0 ) {
192 DBG <<
"Unwanted mount point : " << l << std::endl;
196 mp.erase( 0, prfx.size() );
199 }
else if ( mp[0] !=
'/' ) {
201 DBG <<
"Unwanted mount point : " << l << std::endl;
209 if ( words[2] ==
"iso9660" ) {
210 DBG <<
"Discard cdrom : " << l << std::endl;
214 if ( words[2] ==
"vfat" || words[2] ==
"fat" || words[2] ==
"ntfs" || words[2] ==
"ntfs-3g")
216 MIL << words[1] <<
" contains ignored fs (" << words[2] <<
')' << std::endl;
223 const char * mpunwanted[] = {
224 "/mnt",
"/media",
"/mounts",
"/floppy",
"/cdrom",
225 "/suse",
"/var/tmp",
"/var/adm/mount",
"/var/adm/YaST",
229 const char ** nomp = mpunwanted;
230 for ( ; *nomp; ++nomp ) {
231 std::string pre( *nomp );
232 if ( mp.compare( 0, pre.size(), pre ) == 0
233 && ( mp.size() == pre.size() || mp[pre.size()] ==
'/' ) ) {
238 DBG <<
"Filter mount point : " << l << std::endl;
246 std::vector<std::string> flags;
247 str::split( words[3], std::back_inserter(flags),
"," );
249 for (
unsigned i = 0; i < flags.size(); ++i ) {
250 if ( flags[i] ==
"ro" ) {
256 DBG <<
"Filter ro mount point : " << l << std::endl;
264 if ( statvfs( words[1].c_str(), &sb ) != 0 ) {
265 WAR <<
"Unable to statvfs(" << words[1] <<
"); errno " << errno << std::endl;
273 if ( sb.f_blocks == 0 || sb.f_bsize == 0 )
275 DBG <<
"Filter zero-sized mount point : " << l << std::endl;
279 ((
long long)sb.f_blocks)*sb.f_bsize/1024,
280 ((
long long)(sb.f_blocks - sb.f_bfree))*sb.f_bsize/1024, 0LL, ro ) );
298 str <<
"dir:[" << obj.
dir <<
"] [ bs: " << obj.
blockSize()
::_Pool * get() const
Expert backdoor.
ByteCount blockSize() const
MountPointSet disk_usage(const ResPool &pool)
Compute disk usage of the pool.
A Solvable object within the sat Pool.
const_iterator begin() const
ByteCount commitDiff() const
unsigned split(const C_Str &line_r, _OutputIterator result_r, const C_Str &sepchars_r=" \t")
Split line_r into words.
static MountPointSet justRootPartition()
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
const_iterator end() const
TraitsType::constPtrType constPtr
Assign a vaiable a certain value when going out of scope.
std::set< MountPoint > MountPointSet
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
static Pool instance()
Singleton ctor.
std::ostream & operator<<(std::ostream &str, const Exception &obj)
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
mutable::Map _installedmap
static const Unit K
1024 Byte
ByteCount usedSize() const
static MountPointSet detectMountPoints(const std::string &rootdir="/")