From 94457217cb4c718adc3fd66e75ab1b258788d2a6 Mon Sep 17 00:00:00 2001 From: Oli Lan Date: Tue, 19 Nov 2019 18:09:34 +0000 Subject: [PATCH 1/2] Create DE_n and CE_n APEX data directories. This creates an apexdata directory under /data/misc_de/ and /data/misc_ce/, and also creates a directory under that for every APEX that is installed. See go/apex-data-directories. APEXes are discovered by scanning the /apex directory. It may be better to delegate this process to a library, but it is proposed to defer that change to a future CL. Bug: 141148175 Test: Built and flashed, checked directories were created. Change-Id: I95a060b4f42241c91da25a779e61a8f85ca1914c --- vold_prepare_subdirs.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/vold_prepare_subdirs.cpp b/vold_prepare_subdirs.cpp index a620edd..2fb95d2 100644 --- a/vold_prepare_subdirs.cpp +++ b/vold_prepare_subdirs.cpp @@ -120,6 +120,31 @@ static bool rmrf_contents(const std::string& path) { } } +static bool prepare_apex_subdirs(struct selabel_handle* sehandle, const std::string& path) { + if (!prepare_dir(sehandle, 0700, 0, 0, path + "/apexdata")) return false; + + auto dirp = std::unique_ptr(opendir("/apex"), closedir); + if (!dirp) { + PLOG(ERROR) << "Unable to open apex directory"; + return false; + } + struct dirent* entry; + while ((entry = readdir(dirp.get())) != nullptr) { + if (entry->d_type != DT_DIR) continue; + + const char* name = entry->d_name; + // skip any starting with "." + if (name[0] == '.') continue; + + if (strchr(name, '@') != NULL) continue; + + if (!prepare_dir(sehandle, 0700, AID_SYSTEM, AID_SYSTEM, path + "/apexdata/" + name)) { + return false; + } + } + return true; +} + static bool prepare_subdirs(const std::string& volume_uuid, int user_id, int flags) { struct selabel_handle* sehandle = selinux_android_file_context_handle(); @@ -129,6 +154,8 @@ static bool prepare_subdirs(const std::string& volume_uuid, int user_id, int fla if (!prepare_dir(sehandle, 0700, 0, 0, misc_de_path + "/vold")) return false; if (!prepare_dir(sehandle, 0700, 0, 0, misc_de_path + "/storaged")) return false; if (!prepare_dir(sehandle, 0700, 0, 0, misc_de_path + "/rollback")) return false; + // TODO: Return false if this returns false once sure this should succeed. + prepare_apex_subdirs(sehandle, misc_de_path); auto vendor_de_path = android::vold::BuildDataVendorDePath(user_id); if (!prepare_dir(sehandle, 0700, AID_SYSTEM, AID_SYSTEM, vendor_de_path + "/fpdata")) { @@ -144,6 +171,8 @@ static bool prepare_subdirs(const std::string& volume_uuid, int user_id, int fla if (!prepare_dir(sehandle, 0700, 0, 0, misc_ce_path + "/vold")) return false; if (!prepare_dir(sehandle, 0700, 0, 0, misc_ce_path + "/storaged")) return false; if (!prepare_dir(sehandle, 0700, 0, 0, misc_ce_path + "/rollback")) return false; + // TODO: Return false if this returns false once sure this should succeed. + prepare_apex_subdirs(sehandle, misc_ce_path); auto system_ce_path = android::vold::BuildDataSystemCePath(user_id); if (!prepare_dir(sehandle, 0700, AID_SYSTEM, AID_SYSTEM, system_ce_path + "/backup")) { From ac003c49551cdb734ac555e5d10ba78e0a44f757 Mon Sep 17 00:00:00 2001 From: Oli Lan Date: Mon, 2 Dec 2019 18:27:24 +0000 Subject: [PATCH 2/2] Create directories for snapshots of DE_n and CE_n apex data. This creates apexrollback directories under /data/misc_[de|ce]/ which will hold snapshots of DE_n and CE_n apex data directories (i.e. it will hold backups of data from /data/misc_[de|ce]//apexdata for particular apexes). See go/apex-data-directories for details. Bug: 141148175 Test: Built and flashed, checked directory was created. Change-Id: I468060b20dee0c50033b5f014ce8716582d5e6bc --- vold_prepare_subdirs.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/vold_prepare_subdirs.cpp b/vold_prepare_subdirs.cpp index 2fb95d2..3a58b2e 100644 --- a/vold_prepare_subdirs.cpp +++ b/vold_prepare_subdirs.cpp @@ -155,6 +155,7 @@ static bool prepare_subdirs(const std::string& volume_uuid, int user_id, int fla if (!prepare_dir(sehandle, 0700, 0, 0, misc_de_path + "/storaged")) return false; if (!prepare_dir(sehandle, 0700, 0, 0, misc_de_path + "/rollback")) return false; // TODO: Return false if this returns false once sure this should succeed. + prepare_dir(sehandle, 0700, 0, 0, misc_de_path + "/apexrollback"); prepare_apex_subdirs(sehandle, misc_de_path); auto vendor_de_path = android::vold::BuildDataVendorDePath(user_id); @@ -172,6 +173,7 @@ static bool prepare_subdirs(const std::string& volume_uuid, int user_id, int fla if (!prepare_dir(sehandle, 0700, 0, 0, misc_ce_path + "/storaged")) return false; if (!prepare_dir(sehandle, 0700, 0, 0, misc_ce_path + "/rollback")) return false; // TODO: Return false if this returns false once sure this should succeed. + prepare_dir(sehandle, 0700, 0, 0, misc_ce_path + "/apexrollback"); prepare_apex_subdirs(sehandle, misc_ce_path); auto system_ce_path = android::vold::BuildDataSystemCePath(user_id);