The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 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 | |
Elliott Hughes | 203e13d | 2016-07-22 14:56:18 -0700 | [diff] [blame] | 32 | #include <sys/cdefs.h> |
| 33 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 34 | #ifndef _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_ |
| 35 | #error you should #include <sys/system_properties.h> instead |
| 36 | #else |
| 37 | #include <sys/system_properties.h> |
| 38 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 39 | typedef struct prop_msg prop_msg; |
| 40 | |
| 41 | #define PROP_AREA_MAGIC 0x504f5250 |
Greg Hackmann | 996cdc4 | 2013-06-20 11:27:56 -0700 | [diff] [blame] | 42 | #define PROP_AREA_VERSION 0xfc6ed0ab |
Colin Cross | 5e9a086 | 2013-06-24 18:36:39 -0700 | [diff] [blame] | 43 | #define PROP_AREA_VERSION_COMPAT 0x45434f76 |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 44 | |
| 45 | #define PROP_SERVICE_NAME "property_service" |
Tom Cherry | 49a309f | 2015-09-23 16:09:47 -0700 | [diff] [blame] | 46 | #define PROP_FILENAME_MAX 1024 |
Nick Kralevich | 32417fb | 2013-01-23 09:28:35 -0800 | [diff] [blame] | 47 | #define PROP_FILENAME "/dev/__properties__" |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 48 | |
Greg Hackmann | 1540f60 | 2013-06-19 13:31:21 -0700 | [diff] [blame] | 49 | #define PA_SIZE (128 * 1024) |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 50 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 51 | #define SERIAL_DIRTY(serial) ((serial) & 1) |
| 52 | |
Colin Cross | 5cf32de | 2013-01-23 23:07:06 -0800 | [diff] [blame] | 53 | __BEGIN_DECLS |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 54 | |
Andres Morales | 9d9ebc5 | 2015-01-13 18:00:56 -0800 | [diff] [blame] | 55 | struct prop_msg |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 56 | { |
| 57 | unsigned cmd; |
| 58 | char name[PROP_NAME_MAX]; |
| 59 | char value[PROP_VALUE_MAX]; |
| 60 | }; |
| 61 | |
| 62 | #define PROP_MSG_SETPROP 1 |
Dimitry Ivanov | 16b2a4d | 2017-01-24 20:43:29 +0000 | [diff] [blame] | 63 | #define PROP_MSG_SETPROP2 0x00020001 |
| 64 | |
| 65 | #define PROP_SUCCESS 0 |
| 66 | #define PROP_ERROR_READ_CMD 0x0004 |
| 67 | #define PROP_ERROR_READ_DATA 0x0008 |
| 68 | #define PROP_ERROR_READ_ONLY_PROPERTY 0x000B |
| 69 | #define PROP_ERROR_INVALID_NAME 0x0010 |
| 70 | #define PROP_ERROR_INVALID_VALUE 0x0014 |
| 71 | #define PROP_ERROR_PERMISSION_DENIED 0x0018 |
| 72 | #define PROP_ERROR_INVALID_CMD 0x001B |
| 73 | #define PROP_ERROR_HANDLE_CONTROL_MESSAGE 0x0020 |
| 74 | #define PROP_ERROR_SET_FAILED 0x0024 |
Andres Morales | 9d9ebc5 | 2015-01-13 18:00:56 -0800 | [diff] [blame] | 75 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 76 | /* |
| 77 | ** Rules: |
| 78 | ** |
| 79 | ** - there is only one writer, but many readers |
| 80 | ** - prop_area.count will never decrease in value |
| 81 | ** - once allocated, a prop_info's name will not change |
| 82 | ** - once allocated, a prop_info's offset will not change |
| 83 | ** - reading a value requires the following steps |
| 84 | ** 1. serial = pi->serial |
| 85 | ** 2. if SERIAL_DIRTY(serial), wait*, then goto 1 |
| 86 | ** 3. memcpy(local, pi->value, SERIAL_VALUE_LEN(serial) + 1) |
| 87 | ** 4. if pi->serial != serial, goto 2 |
| 88 | ** |
| 89 | ** - writing a value requires the following steps |
| 90 | ** 1. pi->serial = pi->serial | 1 |
| 91 | ** 2. memcpy(pi->value, local_value, value_len) |
| 92 | ** 3. pi->serial = (value_len << 24) | ((pi->serial + 1) & 0xffffff) |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 93 | */ |
| 94 | |
| 95 | #define PROP_PATH_RAMDISK_DEFAULT "/default.prop" |
Jaekyun Seok | dc94cf5 | 2017-01-17 14:44:31 +0900 | [diff] [blame] | 96 | #define PROP_PATH_VENDOR_DEFAULT "/vendor/default.prop" |
| 97 | #define PROP_PATH_ODM_DEFAULT "/odm/default.prop" |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 98 | #define PROP_PATH_SYSTEM_BUILD "/system/build.prop" |
Daniel Rosenberg | 71d220c | 2014-11-10 16:59:57 -0800 | [diff] [blame] | 99 | #define PROP_PATH_VENDOR_BUILD "/vendor/build.prop" |
Jaekyun Seok | dc94cf5 | 2017-01-17 14:44:31 +0900 | [diff] [blame] | 100 | #define PROP_PATH_ODM_BUILD "/odm/build.prop" |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 101 | #define PROP_PATH_LOCAL_OVERRIDE "/data/local.prop" |
Andrew Boie | 07564f2 | 2013-01-11 12:46:42 -0800 | [diff] [blame] | 102 | #define PROP_PATH_FACTORY "/factory/factory.prop" |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 103 | |
Colin Cross | 5cf32de | 2013-01-23 23:07:06 -0800 | [diff] [blame] | 104 | /* |
Greg Hackmann | cb215a7 | 2013-02-13 14:41:48 -0800 | [diff] [blame] | 105 | ** Map the property area from the specified filename. This |
| 106 | ** method is for testing only. |
| 107 | */ |
| 108 | int __system_property_set_filename(const char *filename); |
| 109 | |
| 110 | /* |
Colin Cross | 5cf32de | 2013-01-23 23:07:06 -0800 | [diff] [blame] | 111 | ** Initialize the area to be used to store properties. Can |
| 112 | ** only be done by a single process that has write access to |
| 113 | ** the property area. |
| 114 | */ |
Greg Hackmann | cb215a7 | 2013-02-13 14:41:48 -0800 | [diff] [blame] | 115 | int __system_property_area_init(); |
Colin Cross | 5cf32de | 2013-01-23 23:07:06 -0800 | [diff] [blame] | 116 | |
Mark Salyzyn | 123927d | 2015-04-24 09:31:32 -0700 | [diff] [blame] | 117 | /* Read the global serial number of the system properties |
| 118 | ** |
| 119 | ** Called to predict if a series of cached __system_property_find |
| 120 | ** objects will have seen __system_property_serial values change. |
| 121 | ** But also aids the converse, as changes in the global serial can |
| 122 | ** also be used to predict if a failed __system_property_find |
Mark Salyzyn | 62075bc | 2015-04-29 07:21:36 -0700 | [diff] [blame] | 123 | ** could in-turn now find a new object; thus preventing the |
Mark Salyzyn | 123927d | 2015-04-24 09:31:32 -0700 | [diff] [blame] | 124 | ** cycles of effort to poll __system_property_find. |
| 125 | ** |
Mark Salyzyn | 62075bc | 2015-04-29 07:21:36 -0700 | [diff] [blame] | 126 | ** Typically called at beginning of a cache cycle to signal if _any_ possible |
| 127 | ** changes have occurred since last. If there is, one may check each individual |
Mark Salyzyn | 123927d | 2015-04-24 09:31:32 -0700 | [diff] [blame] | 128 | ** __system_property_serial to confirm dirty, or __system_property_find |
Mark Salyzyn | 62075bc | 2015-04-29 07:21:36 -0700 | [diff] [blame] | 129 | ** to check if the property now exists. If a call to __system_property_add |
| 130 | ** or __system_property_update has completed between two calls to |
| 131 | ** __system_property_area_serial then the second call will return a larger |
| 132 | ** value than the first call. Beware of race conditions as changes to the |
| 133 | ** properties are not atomic, the main value of this call is to determine |
| 134 | ** whether the expensive __system_property_find is worth retrying to see if |
| 135 | ** a property now exists. |
Mark Salyzyn | 123927d | 2015-04-24 09:31:32 -0700 | [diff] [blame] | 136 | ** |
| 137 | ** Returns the serial number on success, -1 on error. |
| 138 | */ |
| 139 | unsigned int __system_property_area_serial(); |
| 140 | |
Colin Cross | 5cf32de | 2013-01-23 23:07:06 -0800 | [diff] [blame] | 141 | /* Add a new system property. Can only be done by a single |
| 142 | ** process that has write access to the property area, and |
| 143 | ** that process must handle sequencing to ensure the property |
| 144 | ** does not already exist and that only one property is added |
| 145 | ** or updated at a time. |
| 146 | ** |
| 147 | ** Returns 0 on success, -1 if the property area is full. |
| 148 | */ |
| 149 | int __system_property_add(const char *name, unsigned int namelen, |
| 150 | const char *value, unsigned int valuelen); |
| 151 | |
| 152 | /* Update the value of a system property returned by |
| 153 | ** __system_property_find. Can only be done by a single process |
| 154 | ** that has write access to the property area, and that process |
| 155 | ** must handle sequencing to ensure that only one property is |
| 156 | ** updated at a time. |
| 157 | ** |
| 158 | ** Returns 0 on success, -1 if the parameters are incorrect. |
| 159 | */ |
| 160 | int __system_property_update(prop_info *pi, const char *value, unsigned int len); |
| 161 | |
| 162 | /* Read the serial number of a system property returned by |
| 163 | ** __system_property_find. |
| 164 | ** |
| 165 | ** Returns the serial number on success, -1 on error. |
| 166 | */ |
| 167 | unsigned int __system_property_serial(const prop_info *pi); |
| 168 | |
| 169 | /* Wait for any system property to be updated. Caller must pass |
| 170 | ** in 0 the first time, and the previous return value on each |
| 171 | ** successive call. */ |
| 172 | unsigned int __system_property_wait_any(unsigned int serial); |
| 173 | |
Colin Cross | 5e9a086 | 2013-06-24 18:36:39 -0700 | [diff] [blame] | 174 | /* Compatibility functions to support using an old init with a new libc, |
| 175 | ** mostly for the OTA updater binary. These can be deleted once OTAs from |
| 176 | ** a pre-K release no longer needed to be supported. */ |
| 177 | const prop_info *__system_property_find_compat(const char *name); |
| 178 | int __system_property_read_compat(const prop_info *pi, char *name, char *value); |
| 179 | int __system_property_foreach_compat( |
| 180 | void (*propfn)(const prop_info *pi, void *cookie), |
| 181 | void *cookie); |
| 182 | |
Narayan Kamath | c9ae21a | 2014-02-19 17:59:05 +0000 | [diff] [blame] | 183 | /* Initialize the system properties area in read only mode. |
| 184 | * Should be done by all processes that need to read system |
| 185 | * properties. |
| 186 | * |
| 187 | * Returns 0 on success, -1 otherwise. |
| 188 | */ |
| 189 | int __system_properties_init(); |
| 190 | |
Colin Cross | 5cf32de | 2013-01-23 23:07:06 -0800 | [diff] [blame] | 191 | __END_DECLS |
| 192 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 193 | #endif |
| 194 | #endif |