9cff7a9a1cd272a7f3f31dacbfe9baf4b0f390fd
[platform/core/security/vasum.git] / common / utils / fs.hpp
1 /*
2  *  Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *  Contact: Lukasz Pawelczyk <l.pawelczyk@partner.samsung.com>
5  *
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
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
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
17  */
18
19 /**
20  * @file
21  * @author  Lukasz Pawelczyk (l.pawelczyk@partner.samsung.com)
22  * @brief   File utility functions declaration
23  */
24
25 #ifndef COMMON_UTILS_FS_HPP
26 #define COMMON_UTILS_FS_HPP
27
28 #include <string>
29 #include <sys/types.h>
30 #include <vector>
31 #include <boost/filesystem.hpp>
32
33
34 namespace security_containers {
35 namespace utils {
36
37 /**
38  * Reads the content of a file; Throws exception on error
39  */
40 std::string readFileContent(const std::string& path);
41
42 /**
43  * Reads the content of a file
44  */
45 bool readFileContent(const std::string& path, std::string& content);
46
47 /**
48  * Save the content to the file
49  */
50 bool saveFileContent(const std::string& path, const std::string& content);
51
52 /**
53  * Checks if a char device exists
54  */
55 bool isCharDevice(const std::string& path);
56
57 /**
58  * List all (including '.' and '..' entries) dir entries
59  */
60 bool listDir(const std::string& path, std::vector<std::string>& files);
61
62 /**
63  * Mounts run as a tmpfs on a given path
64  */
65 bool mountRun(const std::string& path);
66
67 /**
68  * Umounts a filesystem
69  */
70 bool umount(const std::string& path);
71
72 /**
73  * Check if given path is a mount point
74  */
75 bool isMountPoint(const std::string& path, bool& result);
76
77 /**
78  * Checks whether the given paths are under the same mount point
79  */
80 bool hasSameMountPoint(const std::string& path1, const std::string& path2, bool& result);
81
82 /**
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.
86  */
87 bool moveFile(const std::string& src, const std::string& dst);
88
89 /**
90  * Creates a directory with specific UID, GID and permissions set.
91  */
92 bool createDir(const std::string& path, uid_t uid, uid_t gid, boost::filesystem::perms mode);
93
94
95 } // namespace utils
96 } // namespace security_containers
97
98
99 #endif // COMMON_UTILS_FS_HPP