1 /* 2 * Copyright (c) 2021 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 #ifndef STORAGE_DAEMON_UTILS_FILE_UTILS_H 16 #define STORAGE_DAEMON_UTILS_FILE_UTILS_H 17 18 #include <stdint.h> 19 #include <string> 20 #include <vector> 21 #include <iostream> 22 #include <sstream> 23 #include <sys/types.h> 24 #include <sys/mount.h> 25 26 namespace OHOS { 27 namespace StorageDaemon { 28 struct FileList { 29 uint32_t userId; 30 std::string path; 31 }; 32 33 int32_t ChMod(const std::string &path, mode_t mode); 34 int32_t MkDir(const std::string &path, mode_t mode); 35 bool IsDir(const std::string &path); 36 bool PrepareDir(const std::string &path, mode_t mode, uid_t uid, gid_t gid); 37 bool DestroyDir(const std::string &path); 38 bool MkDirRecurse(const std::string& path, mode_t mode); 39 bool RmDirRecurse(const std::string &path); 40 void TravelChmod(std::string path, mode_t mode); 41 int32_t Mount(const std::string &source, const std::string &target, const char *type, 42 unsigned long flags, const void *data); 43 int32_t UMount(const std::string &path); 44 int32_t UMount2(const std::string &path, int flag); 45 void GetSubDirs(const std::string &path, std::vector<std::string> &dirList); 46 void ReadDigitDir(const std::string &path, std::vector<FileList> &dirInfo); 47 bool StringToUint32(const std::string &str, uint32_t &num); 48 bool ReadFile(std::string path, std::string *str); 49 int ForkExec(std::vector<std::string> &cmd, std::vector<std::string> *output = nullptr); 50 void TraverseDirUevent(const std::string &path, bool flag); 51 } 52 } 53 54 #endif // STORAGE_DAEMON_UTILS_FILE_UTILS_H 55