Andreas Gampe | 02d0de5 | 2015-11-11 20:43:16 -0800 | [diff] [blame] | 1 | /* |
| 2 | ** |
| 3 | ** Copyright 2008, The Android Open Source Project |
| 4 | ** |
| 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | ** you may not use this file except in compliance with the License. |
| 7 | ** You may obtain a copy of the License at |
| 8 | ** |
| 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | ** |
| 11 | ** Unless required by applicable law or agreed to in writing, software |
| 12 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | ** See the License for the specific language governing permissions and |
| 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #ifndef UTILS_H_ |
| 19 | #define UTILS_H_ |
| 20 | |
| 21 | #include <string> |
| 22 | #include <vector> |
| 23 | |
| 24 | #include <dirent.h> |
| 25 | #include <inttypes.h> |
| 26 | #include <unistd.h> |
| 27 | #include <utime.h> |
| 28 | |
| 29 | #include <cutils/multiuser.h> |
| 30 | |
| 31 | #include <installd_constants.h> |
| 32 | |
| 33 | namespace android { |
| 34 | namespace installd { |
| 35 | |
| 36 | struct dir_rec_t; |
| 37 | |
| 38 | typedef struct cache_dir_struct { |
| 39 | struct cache_dir_struct* parent; |
| 40 | int32_t childCount; |
| 41 | int32_t hiddenCount; |
| 42 | int32_t deleted; |
| 43 | char name[]; |
| 44 | } cache_dir_t; |
| 45 | |
| 46 | typedef struct { |
| 47 | cache_dir_t* dir; |
| 48 | time_t modTime; |
| 49 | char name[]; |
| 50 | } cache_file_t; |
| 51 | |
| 52 | typedef struct { |
| 53 | size_t numDirs; |
| 54 | size_t availDirs; |
| 55 | cache_dir_t** dirs; |
| 56 | size_t numFiles; |
| 57 | size_t availFiles; |
| 58 | cache_file_t** files; |
| 59 | size_t numCollected; |
| 60 | void* memBlocks; |
| 61 | int8_t* curMemBlockAvail; |
| 62 | int8_t* curMemBlockEnd; |
| 63 | } cache_t; |
| 64 | |
| 65 | int create_pkg_path(char path[PKG_PATH_MAX], |
| 66 | const char *pkgname, |
| 67 | const char *postfix, |
| 68 | userid_t userid); |
| 69 | |
| 70 | std::string create_data_path(const char* volume_uuid); |
| 71 | |
| 72 | std::string create_data_app_path(const char* volume_uuid); |
| 73 | |
| 74 | std::string create_data_app_package_path(const char* volume_uuid, const char* package_name); |
| 75 | |
Jeff Sharkey | 2f720f7 | 2016-04-10 20:51:40 -0600 | [diff] [blame] | 76 | std::string create_data_user_ce_path(const char* volume_uuid, userid_t userid); |
Andreas Gampe | 02d0de5 | 2015-11-11 20:43:16 -0800 | [diff] [blame] | 77 | std::string create_data_user_de_path(const char* volume_uuid, userid_t userid); |
| 78 | |
Jeff Sharkey | 2f720f7 | 2016-04-10 20:51:40 -0600 | [diff] [blame] | 79 | std::string create_data_user_ce_package_path(const char* volume_uuid, |
Andreas Gampe | 02d0de5 | 2015-11-11 20:43:16 -0800 | [diff] [blame] | 80 | userid_t user, const char* package_name); |
Jeff Sharkey | 2f720f7 | 2016-04-10 20:51:40 -0600 | [diff] [blame] | 81 | std::string create_data_user_ce_package_path(const char* volume_uuid, |
| 82 | userid_t user, const char* package_name, ino_t ce_data_inode); |
Andreas Gampe | 02d0de5 | 2015-11-11 20:43:16 -0800 | [diff] [blame] | 83 | std::string create_data_user_de_package_path(const char* volume_uuid, |
| 84 | userid_t user, const char* package_name); |
| 85 | |
| 86 | std::string create_data_media_path(const char* volume_uuid, userid_t userid); |
| 87 | |
Jeff Sharkey | 379a12b | 2016-04-14 20:45:06 -0600 | [diff] [blame^] | 88 | std::string create_data_misc_legacy_path(userid_t userid); |
| 89 | |
Calin Juravle | 6a1648e | 2016-02-01 12:12:16 +0000 | [diff] [blame] | 90 | std::string create_data_user_profiles_path(userid_t userid); |
| 91 | std::string create_data_user_profile_package_path(userid_t user, const char* package_name); |
| 92 | std::string create_data_ref_profile_package_path(const char* package_name); |
| 93 | |
Andreas Gampe | 02d0de5 | 2015-11-11 20:43:16 -0800 | [diff] [blame] | 94 | std::vector<userid_t> get_known_users(const char* volume_uuid); |
| 95 | |
| 96 | int create_user_config_path(char path[PKG_PATH_MAX], userid_t userid); |
| 97 | |
| 98 | int create_move_path(char path[PKG_PATH_MAX], |
| 99 | const char* pkgname, |
| 100 | const char* leaf, |
| 101 | userid_t userid); |
| 102 | |
| 103 | int is_valid_package_name(const char* pkgname); |
| 104 | |
Calin Juravle | b06f98a | 2016-03-28 15:11:01 +0100 | [diff] [blame] | 105 | int delete_dir_contents(const std::string& pathname, bool ignore_if_missing = false); |
| 106 | int delete_dir_contents_and_dir(const std::string& pathname, bool ignore_if_missing = false); |
Andreas Gampe | 02d0de5 | 2015-11-11 20:43:16 -0800 | [diff] [blame] | 107 | |
| 108 | int delete_dir_contents(const char *pathname, |
| 109 | int also_delete_dir, |
Calin Juravle | b06f98a | 2016-03-28 15:11:01 +0100 | [diff] [blame] | 110 | int (*exclusion_predicate)(const char *name, const int is_dir), |
| 111 | bool ignore_if_missing = false); |
Andreas Gampe | 02d0de5 | 2015-11-11 20:43:16 -0800 | [diff] [blame] | 112 | |
| 113 | int delete_dir_contents_fd(int dfd, const char *name); |
| 114 | |
| 115 | int copy_dir_files(const char *srcname, const char *dstname, uid_t owner, gid_t group); |
| 116 | |
| 117 | int lookup_media_dir(char basepath[PATH_MAX], const char *dir); |
| 118 | |
| 119 | int64_t data_disk_free(const std::string& data_path); |
| 120 | |
| 121 | cache_t* start_cache_collection(); |
| 122 | |
| 123 | void add_cache_files(cache_t* cache, const char *basepath, const char *cachedir); |
| 124 | |
| 125 | void clear_cache_files(const std::string& data_path, cache_t* cache, int64_t free_size); |
| 126 | |
| 127 | void finish_cache_collection(cache_t* cache); |
| 128 | |
| 129 | int validate_system_app_path(const char* path); |
| 130 | |
| 131 | int get_path_from_env(dir_rec_t* rec, const char* var); |
| 132 | |
| 133 | int get_path_from_string(dir_rec_t* rec, const char* path); |
| 134 | |
| 135 | int copy_and_append(dir_rec_t* dst, const dir_rec_t* src, const char* suffix); |
| 136 | |
| 137 | int validate_apk_path(const char *path); |
| 138 | int validate_apk_path_subdirs(const char *path); |
| 139 | |
| 140 | int append_and_increment(char** dst, const char* src, size_t* dst_size); |
| 141 | |
| 142 | char *build_string2(const char *s1, const char *s2); |
| 143 | char *build_string3(const char *s1, const char *s2, const char *s3); |
| 144 | |
Andreas Gampe | 02d0de5 | 2015-11-11 20:43:16 -0800 | [diff] [blame] | 145 | int ensure_config_user_dirs(userid_t userid); |
| 146 | |
| 147 | int wait_child(pid_t pid); |
| 148 | |
| 149 | } // namespace installd |
| 150 | } // namespace android |
| 151 | |
| 152 | #endif // UTILS_H_ |