#ifndef _FSYS_SERVICE_SYS_RUNTIME_INFO__H_
#define _FSYS_SERVICE_SYS_RUNTIME_INFO__H_
+#include <pthread.h>
+
#include <FApp.h>
#include <FBase.h>
{
public:
static _RuntimeInfo* GetInstance(void);
- static long long GetDirectorySize(const char* path);
+
+public:
+ long long GetDirectorySize(const char* path);
private:
_RuntimeInfo();
virtual ~_RuntimeInfo();
+ bool IsMounted(const char* path);
+ long long GetDirectorySizeIteratively(const char* path);
+
private:
static _RuntimeInfo* __pRuntimeInfo;
+
+ pthread_mutex_t __directory;
};
} } // Tizen::System
#include <stdio.h>
#include <dirent.h>
#include <sys/stat.h>
+#include <mntent.h>
#include <FBaseSysLog.h>
#include "FSys_RuntimeInfo.h"
namespace Tizen { namespace System
{
+_RuntimeInfo* _RuntimeInfo::__pRuntimeInfo = null;
+
_RuntimeInfo::_RuntimeInfo()
{
+ pthread_mutex_init(&__directory, NULL);
}
_RuntimeInfo::~_RuntimeInfo()
{
+ pthread_mutex_destroy(&__directory);
+}
+
+_RuntimeInfo*
+_RuntimeInfo::GetInstance(void)
+{
+ if(__pRuntimeInfo == null)
+ {
+ __pRuntimeInfo = new (std::nothrow) _RuntimeInfo();
+ }
+
+ return __pRuntimeInfo;
}
long long
_RuntimeInfo::GetDirectorySize(const char* path)
{
+ long long size = 0;
+
+ pthread_mutex_lock(&__directory);
+ size = GetDirectorySizeIteratively(path);
+ pthread_mutex_unlock(&__directory);
+
+ return size;
+}
+
+bool
+_RuntimeInfo::IsMounted(const char* path)
+{
+ FILE* fp = null;
+ result r = E_SUCCESS;
+ bool mounted = false;
+ const char* table = "/etc/mtab";
+ struct mntent* mnt = null;
+
+
+ fp = setmntent(table, "r");
+ SysTryCatch(NID_SYS, fp != null, r = E_SYSTEM, r, "It is failed to open mount table.");
+
+ SysLog(NID_SYS, "path: %s", path);
+ while(mnt=getmntent(fp))
+ {
+ SysLog(NID_SYS, "mnt_dir: %s", mnt->mnt_dir);
+ if(strcmp(mnt->mnt_dir, path) == 0)
+ {
+ mounted = true;
+ break;
+ }
+ }
+
+CATCH:
+ if(fp != null)
+ {
+ endmntent(fp);
+ }
+ return mounted;
+}
+
+long long
+_RuntimeInfo::GetDirectorySizeIteratively(const char* path)
+{
struct dirent *de;
struct stat buf;
DIR* d = opendir(path);
sprintf(directoryName, "%s%s/", path, de->d_name);
if(strcmp(de->d_name, ".") != 0 && strcmp(de->d_name, "..") != 0)
{
- total_size += GetDirectorySize(directoryName);
+ if(IsMounted(filePath) == false)
+ {
+ total_size += GetDirectorySizeIteratively(directoryName);
+ }
}
total_size += buf.st_size;