1*e4a36f41SAndroid Build Coastguard Worker // Copyright 2024 The Android Open Source Project 2*e4a36f41SAndroid Build Coastguard Worker // 3*e4a36f41SAndroid Build Coastguard Worker // Licensed under the Apache License, Version 2.0 (the "License"); 4*e4a36f41SAndroid Build Coastguard Worker // you may not use this file except in compliance with the License. 5*e4a36f41SAndroid Build Coastguard Worker // You may obtain a copy of the License at 6*e4a36f41SAndroid Build Coastguard Worker // 7*e4a36f41SAndroid Build Coastguard Worker // http://www.apache.org/licenses/LICENSE-2.0 8*e4a36f41SAndroid Build Coastguard Worker // 9*e4a36f41SAndroid Build Coastguard Worker // Unless required by applicable law or agreed to in writing, software 10*e4a36f41SAndroid Build Coastguard Worker // distributed under the License is distributed on an "AS IS" BASIS, 11*e4a36f41SAndroid Build Coastguard Worker // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12*e4a36f41SAndroid Build Coastguard Worker // See the License for the specific language governing permissions and 13*e4a36f41SAndroid Build Coastguard Worker // limitations under the License. 14*e4a36f41SAndroid Build Coastguard Worker 15*e4a36f41SAndroid Build Coastguard Worker //! Client library to read genfs labels version of the vendor. 16*e4a36f41SAndroid Build Coastguard Worker 17*e4a36f41SAndroid Build Coastguard Worker use std::fs; 18*e4a36f41SAndroid Build Coastguard Worker 19*e4a36f41SAndroid Build Coastguard Worker const GENFS_LABELS_VERSION_TXT_PATH: &str = "/vendor/etc/selinux/genfs_labels_version.txt"; 20*e4a36f41SAndroid Build Coastguard Worker const DEFAULT_GENFS_LABELS_VERSION: i32 = 202404; 21*e4a36f41SAndroid Build Coastguard Worker 22*e4a36f41SAndroid Build Coastguard Worker /// Get genfs labels version from the vendor partition. 23*e4a36f41SAndroid Build Coastguard Worker /// 24*e4a36f41SAndroid Build Coastguard Worker /// This function reads the genfs labels version from the file 25*e4a36f41SAndroid Build Coastguard Worker /// `/vendor/etc/selinux/genfs_labels_version.txt`. If the file does not exist or 26*e4a36f41SAndroid Build Coastguard Worker /// cannot be parsed, it returns a default version of 202404. 27*e4a36f41SAndroid Build Coastguard Worker /// 28*e4a36f41SAndroid Build Coastguard Worker /// # Returns 29*e4a36f41SAndroid Build Coastguard Worker /// 30*e4a36f41SAndroid Build Coastguard Worker /// The genfs labels version as an integer. 31*e4a36f41SAndroid Build Coastguard Worker #[no_mangle] get_genfs_labels_version() -> i3232*e4a36f41SAndroid Build Coastguard Workerpub extern "C" fn get_genfs_labels_version() -> i32 { 33*e4a36f41SAndroid Build Coastguard Worker match fs::read_to_string(GENFS_LABELS_VERSION_TXT_PATH) { 34*e4a36f41SAndroid Build Coastguard Worker Ok(contents) => match contents.trim().parse::<i32>() { 35*e4a36f41SAndroid Build Coastguard Worker Ok(version) => version, 36*e4a36f41SAndroid Build Coastguard Worker Err(_) => DEFAULT_GENFS_LABELS_VERSION, 37*e4a36f41SAndroid Build Coastguard Worker }, 38*e4a36f41SAndroid Build Coastguard Worker Err(_) => DEFAULT_GENFS_LABELS_VERSION, 39*e4a36f41SAndroid Build Coastguard Worker } 40*e4a36f41SAndroid Build Coastguard Worker } 41