102d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe/* 202d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe** 302d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe** Copyright 2008, The Android Open Source Project 402d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe** 502d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe** Licensed under the Apache License, Version 2.0 (the "License"); 602d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe** you may not use this file except in compliance with the License. 702d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe** You may obtain a copy of the License at 802d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe** 902d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe** http://www.apache.org/licenses/LICENSE-2.0 1002d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe** 1102d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe** Unless required by applicable law or agreed to in writing, software 1202d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe** distributed under the License is distributed on an "AS IS" BASIS, 1302d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1402d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe** See the License for the specific language governing permissions and 1502d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe** limitations under the License. 1602d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe*/ 1702d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe 1802d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe#ifndef UTILS_H_ 1902d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe#define UTILS_H_ 2002d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe 2102d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe#include <string> 2202d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe#include <vector> 2302d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe 2402d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe#include <dirent.h> 2502d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe#include <inttypes.h> 2602d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe#include <unistd.h> 2702d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe#include <utime.h> 2802d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe 2902d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe#include <cutils/multiuser.h> 3002d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe 3102d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe#include <installd_constants.h> 3202d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe 3302d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampenamespace android { 3402d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampenamespace installd { 3502d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe 3602d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampestruct dir_rec_t; 3702d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe 3802d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampetypedef struct cache_dir_struct { 3902d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe struct cache_dir_struct* parent; 4002d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe int32_t childCount; 4102d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe int32_t hiddenCount; 4202d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe int32_t deleted; 4302d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe char name[]; 4402d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe} cache_dir_t; 4502d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe 4602d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampetypedef struct { 4702d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe cache_dir_t* dir; 4802d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe time_t modTime; 4902d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe char name[]; 5002d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe} cache_file_t; 5102d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe 5202d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampetypedef struct { 5302d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe size_t numDirs; 5402d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe size_t availDirs; 5502d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe cache_dir_t** dirs; 5602d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe size_t numFiles; 5702d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe size_t availFiles; 5802d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe cache_file_t** files; 5902d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe size_t numCollected; 6002d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe void* memBlocks; 6102d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe int8_t* curMemBlockAvail; 6202d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe int8_t* curMemBlockEnd; 6302d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe} cache_t; 6402d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe 6502d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampeint create_pkg_path(char path[PKG_PATH_MAX], 6602d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe const char *pkgname, 6702d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe const char *postfix, 6802d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe userid_t userid); 6902d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe 7002d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampestd::string create_data_path(const char* volume_uuid); 7102d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe 7202d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampestd::string create_data_app_path(const char* volume_uuid); 7302d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe 7402d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampestd::string create_data_app_package_path(const char* volume_uuid, const char* package_name); 7502d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe 762f720f7ec5c9d0b91defc85878e7330b10f8e89aJeff Sharkeystd::string create_data_user_ce_path(const char* volume_uuid, userid_t userid); 7702d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampestd::string create_data_user_de_path(const char* volume_uuid, userid_t userid); 7802d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe 792f720f7ec5c9d0b91defc85878e7330b10f8e89aJeff Sharkeystd::string create_data_user_ce_package_path(const char* volume_uuid, 8002d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe userid_t user, const char* package_name); 812f720f7ec5c9d0b91defc85878e7330b10f8e89aJeff Sharkeystd::string create_data_user_ce_package_path(const char* volume_uuid, 822f720f7ec5c9d0b91defc85878e7330b10f8e89aJeff Sharkey userid_t user, const char* package_name, ino_t ce_data_inode); 8302d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampestd::string create_data_user_de_package_path(const char* volume_uuid, 8402d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe userid_t user, const char* package_name); 8502d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe 8602d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampestd::string create_data_media_path(const char* volume_uuid, userid_t userid); 8702d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe 88379a12b0072b322c7f86e690a8e8a220e500861cJeff Sharkeystd::string create_data_misc_legacy_path(userid_t userid); 89379a12b0072b322c7f86e690a8e8a220e500861cJeff Sharkey 906a1648e2f161cb1d7c46aa9d27e8062521a9f314Calin Juravlestd::string create_data_user_profiles_path(userid_t userid); 916a1648e2f161cb1d7c46aa9d27e8062521a9f314Calin Juravlestd::string create_data_user_profile_package_path(userid_t user, const char* package_name); 926a1648e2f161cb1d7c46aa9d27e8062521a9f314Calin Juravlestd::string create_data_ref_profile_package_path(const char* package_name); 936a1648e2f161cb1d7c46aa9d27e8062521a9f314Calin Juravle 9402d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampestd::vector<userid_t> get_known_users(const char* volume_uuid); 9502d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe 9602d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampeint create_user_config_path(char path[PKG_PATH_MAX], userid_t userid); 9702d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe 9802d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampeint create_move_path(char path[PKG_PATH_MAX], 9902d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe const char* pkgname, 10002d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe const char* leaf, 10102d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe userid_t userid); 10202d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe 10302d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampeint is_valid_package_name(const char* pkgname); 10402d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe 105b06f98aabc5381fd6366526d9b31b5d0345481b6Calin Juravleint delete_dir_contents(const std::string& pathname, bool ignore_if_missing = false); 106b06f98aabc5381fd6366526d9b31b5d0345481b6Calin Juravleint delete_dir_contents_and_dir(const std::string& pathname, bool ignore_if_missing = false); 10702d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe 10802d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampeint delete_dir_contents(const char *pathname, 10902d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe int also_delete_dir, 110b06f98aabc5381fd6366526d9b31b5d0345481b6Calin Juravle int (*exclusion_predicate)(const char *name, const int is_dir), 111b06f98aabc5381fd6366526d9b31b5d0345481b6Calin Juravle bool ignore_if_missing = false); 11202d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe 11302d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampeint delete_dir_contents_fd(int dfd, const char *name); 11402d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe 11502d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampeint copy_dir_files(const char *srcname, const char *dstname, uid_t owner, gid_t group); 11602d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe 11702d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampeint64_t data_disk_free(const std::string& data_path); 11802d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe 11902d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampecache_t* start_cache_collection(); 12002d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe 12154e292e1ea87b504b552393d2e9bc800458bd0c1Jeff Sharkeyvoid add_cache_files(cache_t* cache, const std::string& data_path); 12202d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe 12302d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampevoid clear_cache_files(const std::string& data_path, cache_t* cache, int64_t free_size); 12402d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe 12502d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampevoid finish_cache_collection(cache_t* cache); 12602d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe 12702d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampeint validate_system_app_path(const char* path); 12802d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe 12902d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampeint get_path_from_env(dir_rec_t* rec, const char* var); 13002d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe 13102d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampeint get_path_from_string(dir_rec_t* rec, const char* path); 13202d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe 13302d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampeint copy_and_append(dir_rec_t* dst, const dir_rec_t* src, const char* suffix); 13402d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe 13502d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampeint validate_apk_path(const char *path); 13602d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampeint validate_apk_path_subdirs(const char *path); 13702d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe 13802d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampeint append_and_increment(char** dst, const char* src, size_t* dst_size); 13902d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe 14002d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampechar *build_string2(const char *s1, const char *s2); 14102d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampechar *build_string3(const char *s1, const char *s2, const char *s3); 14202d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe 14302d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampeint ensure_config_user_dirs(userid_t userid); 14402d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe 14502d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampeint wait_child(pid_t pid); 14602d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe 14702d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe} // namespace installd 14802d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe} // namespace android 14902d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe 15002d0de56c75347a0cb8d5a8565dc8c4ee7616057Andreas Gampe#endif // UTILS_H_ 151