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> |
Elliott Hughes | a0d374d | 2017-02-10 18:13:46 -0800 | [diff] [blame] | 33 | #include <stdint.h> |
Elliott Hughes | 203e13d | 2016-07-22 14:56:18 -0700 | [diff] [blame] | 34 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 35 | #ifndef _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_ |
| 36 | #error you should #include <sys/system_properties.h> instead |
Elliott Hughes | f8562c5 | 2017-01-26 16:48:57 -0800 | [diff] [blame] | 37 | #endif |
| 38 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 39 | #include <sys/system_properties.h> |
| 40 | |
Colin Cross | 5cf32de | 2013-01-23 23:07:06 -0800 | [diff] [blame] | 41 | __BEGIN_DECLS |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 42 | |
Elliott Hughes | f8562c5 | 2017-01-26 16:48:57 -0800 | [diff] [blame] | 43 | #define PROP_SERVICE_NAME "property_service" |
| 44 | #define PROP_FILENAME "/dev/__properties__" |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 45 | |
| 46 | #define PROP_MSG_SETPROP 1 |
Dimitry Ivanov | 16b2a4d | 2017-01-24 20:43:29 +0000 | [diff] [blame] | 47 | #define PROP_MSG_SETPROP2 0x00020001 |
| 48 | |
| 49 | #define PROP_SUCCESS 0 |
| 50 | #define PROP_ERROR_READ_CMD 0x0004 |
| 51 | #define PROP_ERROR_READ_DATA 0x0008 |
| 52 | #define PROP_ERROR_READ_ONLY_PROPERTY 0x000B |
| 53 | #define PROP_ERROR_INVALID_NAME 0x0010 |
| 54 | #define PROP_ERROR_INVALID_VALUE 0x0014 |
| 55 | #define PROP_ERROR_PERMISSION_DENIED 0x0018 |
| 56 | #define PROP_ERROR_INVALID_CMD 0x001B |
| 57 | #define PROP_ERROR_HANDLE_CONTROL_MESSAGE 0x0020 |
| 58 | #define PROP_ERROR_SET_FAILED 0x0024 |
Andres Morales | 9d9ebc5 | 2015-01-13 18:00:56 -0800 | [diff] [blame] | 59 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 60 | /* |
Greg Hackmann | cb215a7 | 2013-02-13 14:41:48 -0800 | [diff] [blame] | 61 | ** Map the property area from the specified filename. This |
| 62 | ** method is for testing only. |
| 63 | */ |
| 64 | int __system_property_set_filename(const char *filename); |
| 65 | |
| 66 | /* |
Colin Cross | 5cf32de | 2013-01-23 23:07:06 -0800 | [diff] [blame] | 67 | ** Initialize the area to be used to store properties. Can |
| 68 | ** only be done by a single process that has write access to |
| 69 | ** the property area. |
| 70 | */ |
Greg Hackmann | cb215a7 | 2013-02-13 14:41:48 -0800 | [diff] [blame] | 71 | int __system_property_area_init(); |
Colin Cross | 5cf32de | 2013-01-23 23:07:06 -0800 | [diff] [blame] | 72 | |
Mark Salyzyn | 123927d | 2015-04-24 09:31:32 -0700 | [diff] [blame] | 73 | /* Read the global serial number of the system properties |
| 74 | ** |
| 75 | ** Called to predict if a series of cached __system_property_find |
| 76 | ** objects will have seen __system_property_serial values change. |
| 77 | ** But also aids the converse, as changes in the global serial can |
| 78 | ** also be used to predict if a failed __system_property_find |
Mark Salyzyn | 62075bc | 2015-04-29 07:21:36 -0700 | [diff] [blame] | 79 | ** could in-turn now find a new object; thus preventing the |
Mark Salyzyn | 123927d | 2015-04-24 09:31:32 -0700 | [diff] [blame] | 80 | ** cycles of effort to poll __system_property_find. |
| 81 | ** |
Mark Salyzyn | 62075bc | 2015-04-29 07:21:36 -0700 | [diff] [blame] | 82 | ** Typically called at beginning of a cache cycle to signal if _any_ possible |
| 83 | ** 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] | 84 | ** __system_property_serial to confirm dirty, or __system_property_find |
Mark Salyzyn | 62075bc | 2015-04-29 07:21:36 -0700 | [diff] [blame] | 85 | ** to check if the property now exists. If a call to __system_property_add |
| 86 | ** or __system_property_update has completed between two calls to |
| 87 | ** __system_property_area_serial then the second call will return a larger |
| 88 | ** value than the first call. Beware of race conditions as changes to the |
| 89 | ** properties are not atomic, the main value of this call is to determine |
| 90 | ** whether the expensive __system_property_find is worth retrying to see if |
| 91 | ** a property now exists. |
Mark Salyzyn | 123927d | 2015-04-24 09:31:32 -0700 | [diff] [blame] | 92 | ** |
| 93 | ** Returns the serial number on success, -1 on error. |
| 94 | */ |
Elliott Hughes | a0d374d | 2017-02-10 18:13:46 -0800 | [diff] [blame] | 95 | uint32_t __system_property_area_serial(); |
Mark Salyzyn | 123927d | 2015-04-24 09:31:32 -0700 | [diff] [blame] | 96 | |
Colin Cross | 5cf32de | 2013-01-23 23:07:06 -0800 | [diff] [blame] | 97 | /* Add a new system property. Can only be done by a single |
| 98 | ** process that has write access to the property area, and |
| 99 | ** that process must handle sequencing to ensure the property |
| 100 | ** does not already exist and that only one property is added |
| 101 | ** or updated at a time. |
| 102 | ** |
| 103 | ** Returns 0 on success, -1 if the property area is full. |
| 104 | */ |
Elliott Hughes | f8562c5 | 2017-01-26 16:48:57 -0800 | [diff] [blame] | 105 | int __system_property_add(const char *name, unsigned int namelen, const char *value, unsigned int valuelen); |
Colin Cross | 5cf32de | 2013-01-23 23:07:06 -0800 | [diff] [blame] | 106 | |
| 107 | /* Update the value of a system property returned by |
| 108 | ** __system_property_find. Can only be done by a single process |
| 109 | ** that has write access to the property area, and that process |
| 110 | ** must handle sequencing to ensure that only one property is |
| 111 | ** updated at a time. |
| 112 | ** |
| 113 | ** Returns 0 on success, -1 if the parameters are incorrect. |
| 114 | */ |
| 115 | int __system_property_update(prop_info *pi, const char *value, unsigned int len); |
| 116 | |
| 117 | /* Read the serial number of a system property returned by |
| 118 | ** __system_property_find. |
| 119 | ** |
| 120 | ** Returns the serial number on success, -1 on error. |
| 121 | */ |
Elliott Hughes | a0d374d | 2017-02-10 18:13:46 -0800 | [diff] [blame] | 122 | uint32_t __system_property_serial(const prop_info* pi); |
Colin Cross | 5cf32de | 2013-01-23 23:07:06 -0800 | [diff] [blame] | 123 | |
Narayan Kamath | c9ae21a | 2014-02-19 17:59:05 +0000 | [diff] [blame] | 124 | /* Initialize the system properties area in read only mode. |
| 125 | * Should be done by all processes that need to read system |
| 126 | * properties. |
| 127 | * |
| 128 | * Returns 0 on success, -1 otherwise. |
| 129 | */ |
| 130 | int __system_properties_init(); |
| 131 | |
Elliott Hughes | 40c885a | 2017-02-16 17:13:04 -0800 | [diff] [blame] | 132 | /* Deprecated: use __system_property_wait instead. */ |
| 133 | uint32_t __system_property_wait_any(uint32_t old_serial); |
| 134 | |
Colin Cross | 5cf32de | 2013-01-23 23:07:06 -0800 | [diff] [blame] | 135 | __END_DECLS |
| 136 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 137 | #endif |