1 /* 2 * Copyright (c) 2023-2024 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 #ifndef OHOS_STORAGE_DAEMON_QUOTA_MANAGER_H 17 #define OHOS_STORAGE_DAEMON_QUOTA_MANAGER_H 18 19 #include <nocopyable.h> 20 #include <set> 21 #include <sys/types.h> 22 #include <string> 23 #include <vector> 24 25 namespace OHOS { 26 namespace StorageDaemon { 27 struct FileStat { 28 std::string filePath; 29 int64_t fileSize; 30 int64_t lastUpdateTime; 31 int32_t mode; 32 bool isDir; 33 bool isIncre; 34 }; 35 struct BundleStatsParas { 36 uint32_t userId; 37 std::string &bundleName; 38 int64_t lastBackupTime; 39 int64_t fileSizeSum; 40 int64_t incFileSizeSum; 41 }; 42 uint32_t CheckOverLongPath(const std::string &path); 43 class QuotaManager final { 44 public: 45 virtual ~QuotaManager() = default; 46 static QuotaManager* GetInstance(); 47 48 int32_t SetBundleQuota(const std::string &bundleName, int32_t uid, 49 const std::string &bundleDataDirPath, int32_t limitSizeMb); 50 int32_t GetOccupiedSpace(int32_t idType, int32_t id, int64_t &size); 51 int32_t SetQuotaPrjId(const std::string &path, int32_t prjId, bool inherit); 52 int32_t GetBundleStatsForIncrease(uint32_t userId, const std::vector<std::string> &bundleNames, 53 const std::vector<int64_t> &incrementalBackTimes, std::vector<int64_t> &pkgFileSizes, 54 std::vector<int64_t> &incPkgFileSizes); 55 private: 56 QuotaManager() = default; 57 DISALLOW_COPY_AND_MOVE(QuotaManager); 58 59 static QuotaManager* instance_; 60 }; 61 } // STORAGE_DAEMON 62 } // OHOS 63 64 #endif // OHOS_STORAGE_DAEMON_QUOTA_MANAGER_H