2 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Contact: Lukasz Pawelczyk <l.pawelczyk@partner.samsung.com>
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License
21 * @author Lukasz Pawelczyk (l.pawelczyk@partner.samsung.com)
22 * @brief File utility functions declaration
25 #ifndef COMMON_UTILS_FS_HPP
26 #define COMMON_UTILS_FS_HPP
29 #include <sys/types.h>
31 #include <boost/filesystem.hpp>
34 namespace security_containers {
38 * Reads the content of a file; Throws exception on error
40 std::string readFileContent(const std::string& path);
43 * Reads the content of a file
45 bool readFileContent(const std::string& path, std::string& content);
48 * Save the content to the file
50 bool saveFileContent(const std::string& path, const std::string& content);
53 * Checks if a char device exists
55 bool isCharDevice(const std::string& path);
58 * List all (including '.' and '..' entries) dir entries
60 bool listDir(const std::string& path, std::vector<std::string>& files);
63 * Mounts run as a tmpfs on a given path
65 bool mountRun(const std::string& path);
68 * Umounts a filesystem
70 bool umount(const std::string& path);
73 * Check if given path is a mount point
75 bool isMountPoint(const std::string& path, bool& result);
78 * Checks whether the given paths are under the same mount point
80 bool hasSameMountPoint(const std::string& path1, const std::string& path2, bool& result);
83 * Moves the file either by rename if under the same mount point
84 * or by copy&delete if under a different one.
85 * The destination has to be a full path including file name.
87 bool moveFile(const std::string& src, const std::string& dst);
90 * Recursively copy contents of src dir to dst dir.
92 bool copyDirContents(const std::string& src, const std::string& dst);
95 * Creates a directory with specific UID, GID and permissions set.
97 bool createDir(const std::string& path, uid_t uid, uid_t gid, boost::filesystem::perms mode);
100 * Creates an empty directory, ready to serve as mount point.
101 * Succeeds either if path did not exist and was created successfully, or if already existing dir
102 * under the same path is empty and is not a mount point.
104 bool createEmptyDir(const std::string& path);
108 } // namespace security_containers
111 #endif // COMMON_UTILS_FS_HPP