1 /* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "statvfs_impl.h" 17 #include <cinttypes> 18 #include <sys/statvfs.h> 19 #include "uni_error.h" 20 21 namespace OHOS { 22 namespace CJSystemapi { 23 namespace Statvfs { GetFreeSize(const char * path)24 std::tuple<int32_t, int64_t> StatvfsImpl::GetFreeSize(const char* path) 25 { 26 struct statvfs diskInfo; 27 int ret = statvfs(path, &diskInfo); 28 if (ret != 0) { 29 return {FileFs::GetErrorCode(errno), 0}; 30 } 31 unsigned long long freeSize = static_cast<unsigned long long>(diskInfo.f_bsize) * 32 static_cast<unsigned long long>(diskInfo.f_bfree); 33 return {SUCCESS_CODE, static_cast<int64_t>(freeSize)}; 34 } 35 GetTotalSize(const char * path)36 std::tuple<int32_t, int64_t> StatvfsImpl::GetTotalSize(const char* path) 37 { 38 struct statvfs diskInfo; 39 int ret = statvfs(path, &diskInfo); 40 if (ret != 0) { 41 return {FileFs::GetErrorCode(errno), 0}; 42 } 43 unsigned long long totalSize = static_cast<unsigned long long>(diskInfo.f_bsize) * 44 static_cast<unsigned long long>(diskInfo.f_blocks); 45 return {SUCCESS_CODE, static_cast<int64_t>(totalSize)}; 46 } 47 } // Statvfs 48 } // CJSystemapi 49 } // namespace OHOS