1 /* 2 * Copyright (C) 2008 The Android Open Source Project 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * * Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * * Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in 12 * the documentation and/or other materials provided with the 13 * distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29 #ifndef _INCLUDE_SYS__SYSTEM_PROPERTIES_H 30 #define _INCLUDE_SYS__SYSTEM_PROPERTIES_H 31 32 #ifndef _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_ 33 #error you should #include <sys/system_properties.h> instead 34 #else 35 #include <sys/system_properties.h> 36 37 typedef struct prop_msg prop_msg; 38 39 #define PROP_AREA_MAGIC 0x504f5250 40 #define PROP_AREA_VERSION 0xfc6ed0ab 41 #define PROP_AREA_VERSION_COMPAT 0x45434f76 42 43 #define PROP_SERVICE_NAME "property_service" 44 #define PROP_FILENAME_MAX 1024 45 #define PROP_FILENAME "/dev/__properties__" 46 47 #define PA_SIZE (128 * 1024) 48 49 #define SERIAL_VALUE_LEN(serial) ((serial) >> 24) 50 #define SERIAL_DIRTY(serial) ((serial) & 1) 51 52 __BEGIN_DECLS 53 54 struct prop_msg 55 { 56 unsigned cmd; 57 char name[PROP_NAME_MAX]; 58 char value[PROP_VALUE_MAX]; 59 }; 60 61 #define PROP_MSG_SETPROP 1 62 63 /* 64 ** Rules: 65 ** 66 ** - there is only one writer, but many readers 67 ** - prop_area.count will never decrease in value 68 ** - once allocated, a prop_info's name will not change 69 ** - once allocated, a prop_info's offset will not change 70 ** - reading a value requires the following steps 71 ** 1. serial = pi->serial 72 ** 2. if SERIAL_DIRTY(serial), wait*, then goto 1 73 ** 3. memcpy(local, pi->value, SERIAL_VALUE_LEN(serial) + 1) 74 ** 4. if pi->serial != serial, goto 2 75 ** 76 ** - writing a value requires the following steps 77 ** 1. pi->serial = pi->serial | 1 78 ** 2. memcpy(pi->value, local_value, value_len) 79 ** 3. pi->serial = (value_len << 24) | ((pi->serial + 1) & 0xffffff) 80 */ 81 82 #define PROP_PATH_RAMDISK_DEFAULT "/default.prop" 83 #define PROP_PATH_SYSTEM_BUILD "/system/build.prop" 84 #define PROP_PATH_VENDOR_BUILD "/vendor/build.prop" 85 #define PROP_PATH_LOCAL_OVERRIDE "/data/local.prop" 86 #define PROP_PATH_FACTORY "/factory/factory.prop" 87 88 /* 89 ** Map the property area from the specified filename. This 90 ** method is for testing only. 91 */ 92 int __system_property_set_filename(const char *filename); 93 94 /* 95 ** Initialize the area to be used to store properties. Can 96 ** only be done by a single process that has write access to 97 ** the property area. 98 */ 99 int __system_property_area_init(); 100 101 /* Read the global serial number of the system properties 102 ** 103 ** Called to predict if a series of cached __system_property_find 104 ** objects will have seen __system_property_serial values change. 105 ** But also aids the converse, as changes in the global serial can 106 ** also be used to predict if a failed __system_property_find 107 ** could in-turn now find a new object; thus preventing the 108 ** cycles of effort to poll __system_property_find. 109 ** 110 ** Typically called at beginning of a cache cycle to signal if _any_ possible 111 ** changes have occurred since last. If there is, one may check each individual 112 ** __system_property_serial to confirm dirty, or __system_property_find 113 ** to check if the property now exists. If a call to __system_property_add 114 ** or __system_property_update has completed between two calls to 115 ** __system_property_area_serial then the second call will return a larger 116 ** value than the first call. Beware of race conditions as changes to the 117 ** properties are not atomic, the main value of this call is to determine 118 ** whether the expensive __system_property_find is worth retrying to see if 119 ** a property now exists. 120 ** 121 ** Returns the serial number on success, -1 on error. 122 */ 123 unsigned int __system_property_area_serial(); 124 125 /* Add a new system property. Can only be done by a single 126 ** process that has write access to the property area, and 127 ** that process must handle sequencing to ensure the property 128 ** does not already exist and that only one property is added 129 ** or updated at a time. 130 ** 131 ** Returns 0 on success, -1 if the property area is full. 132 */ 133 int __system_property_add(const char *name, unsigned int namelen, 134 const char *value, unsigned int valuelen); 135 136 /* Update the value of a system property returned by 137 ** __system_property_find. Can only be done by a single process 138 ** that has write access to the property area, and that process 139 ** must handle sequencing to ensure that only one property is 140 ** updated at a time. 141 ** 142 ** Returns 0 on success, -1 if the parameters are incorrect. 143 */ 144 int __system_property_update(prop_info *pi, const char *value, unsigned int len); 145 146 /* Read the serial number of a system property returned by 147 ** __system_property_find. 148 ** 149 ** Returns the serial number on success, -1 on error. 150 */ 151 unsigned int __system_property_serial(const prop_info *pi); 152 153 /* Wait for any system property to be updated. Caller must pass 154 ** in 0 the first time, and the previous return value on each 155 ** successive call. */ 156 unsigned int __system_property_wait_any(unsigned int serial); 157 158 /* Compatibility functions to support using an old init with a new libc, 159 ** mostly for the OTA updater binary. These can be deleted once OTAs from 160 ** a pre-K release no longer needed to be supported. */ 161 const prop_info *__system_property_find_compat(const char *name); 162 int __system_property_read_compat(const prop_info *pi, char *name, char *value); 163 int __system_property_foreach_compat( 164 void (*propfn)(const prop_info *pi, void *cookie), 165 void *cookie); 166 167 /* Initialize the system properties area in read only mode. 168 * Should be done by all processes that need to read system 169 * properties. 170 * 171 * Returns 0 on success, -1 otherwise. 172 */ 173 int __system_properties_init(); 174 175 __END_DECLS 176 177 #endif 178 #endif 179