2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file FSys_RuntimeInfo.cpp
19 * @brief This is the implementation file for _RuntimeInfo class.
30 #include <FBaseSysLog.h>
31 #include "FSys_RuntimeInfo.h"
33 using namespace Tizen::Base;
35 namespace Tizen { namespace System
38 _RuntimeInfo* _RuntimeInfo::__pRuntimeInfo = null;
40 _RuntimeInfo::_RuntimeInfo()
42 pthread_mutex_init(&__directory, NULL);
45 _RuntimeInfo::~_RuntimeInfo()
47 pthread_mutex_destroy(&__directory);
51 _RuntimeInfo::GetInstance(void)
53 if(__pRuntimeInfo == null)
55 __pRuntimeInfo = new (std::nothrow) _RuntimeInfo();
58 return __pRuntimeInfo;
62 _RuntimeInfo::GetDirectorySize(const char* path)
66 pthread_mutex_lock(&__directory);
67 size = GetDirectorySizeIteratively(path);
68 pthread_mutex_unlock(&__directory);
74 _RuntimeInfo::IsMounted(const char* path)
79 const char* table = "/etc/mtab";
80 struct mntent* mnt = null;
82 fp = setmntent(table, "r");
83 SysTryCatch(NID_SYS, fp != null, r = E_SYSTEM, r, "It is failed to open mount table.");
85 SysLog(NID_SYS, "path: %s", path);
86 while(mnt=getmntent(fp))
88 SysLog(NID_SYS, "mnt_dir: %s", mnt->mnt_dir);
89 if(strcmp(mnt->mnt_dir, path) == 0)
105 _RuntimeInfo::GetDirectorySizeIteratively(const char* path)
109 DIR* d = opendir(path);
110 long long total_size = 0;
116 for (de = readdir(d); de != null; de = readdir(d))
118 char filePath[1024] = {0,};
119 sprintf(filePath, "%s%s", path, de->d_name);
121 if (lstat(filePath, &buf) == 0)
123 if (S_ISLNK(buf.st_mode) == true)
125 total_size += buf.st_size;
129 if(stat(filePath, &buf) == 0)
131 if(S_ISDIR(buf.st_mode) == true)
133 char directoryName[1024] = {0,};
134 sprintf(directoryName, "%s%s/", path, de->d_name);
135 if(strcmp(de->d_name, ".") != 0 && strcmp(de->d_name, "..") != 0)
137 if(IsMounted(filePath) == false)
139 total_size += GetDirectorySizeIteratively(directoryName);
142 total_size += buf.st_size;
147 total_size += buf.st_size;