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 17 #include "file_operator_wrapper.h" 18 #include <sys/statfs.h> 19 #include <cstring> 20 #include <dirent.h> 21 22 #include "directory_ex.h" 23 #include "asset_log.h" 24 #include "asset_type.h" 25 26 using namespace OHOS; 27 GetRemainPartitionSize(const char * partitionName,double * partitionSize)28int32_t GetRemainPartitionSize(const char *partitionName, double *partitionSize) 29 { 30 if (partitionName == nullptr) { 31 LOGE("Fail to get partition name"); 32 return ASSET_INVALID_ARGUMENT; 33 } 34 struct statfs stat; 35 if (statfs(partitionName, &stat) != 0) { 36 LOGE("Failed to get partition information for %{public}s", partitionName); 37 return ASSET_FILE_OPERATION_ERROR; 38 } 39 /* Calculate free space in megabytes */ 40 constexpr double units = 1024.0; 41 *partitionSize = (static_cast<double>(stat.f_bfree) / units) * (static_cast<double>(stat.f_bsize) / units); 42 return ASSET_SUCCESS; 43 } 44 GetDirSize(const char * dir)45uint64_t GetDirSize(const char *dir) 46 { 47 return GetFolderSize(dir); 48 } 49