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 | |
| 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 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 37 | typedef struct prop_msg prop_msg; |
| 38 | |
| 39 | #define PROP_AREA_MAGIC 0x504f5250 |
Greg Hackmann | 996cdc4 | 2013-06-20 11:27:56 -0700 | [diff] [blame^] | 40 | #define PROP_AREA_VERSION 0xfc6ed0ab |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 41 | |
| 42 | #define PROP_SERVICE_NAME "property_service" |
Nick Kralevich | 32417fb | 2013-01-23 09:28:35 -0800 | [diff] [blame] | 43 | #define PROP_FILENAME "/dev/__properties__" |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 44 | |
Greg Hackmann | cb215a7 | 2013-02-13 14:41:48 -0800 | [diff] [blame] | 45 | /* (4 header words + 28 toc words) = 128 bytes */ |
| 46 | /* 128 bytes header and toc + 28 prop_infos @ 128 bytes = 3712 bytes */ |
Colin Cross | 5cf32de | 2013-01-23 23:07:06 -0800 | [diff] [blame] | 47 | |
Greg Hackmann | cb215a7 | 2013-02-13 14:41:48 -0800 | [diff] [blame] | 48 | #define PA_REGION_COUNT 128 |
Greg Hackmann | cb215a7 | 2013-02-13 14:41:48 -0800 | [diff] [blame] | 49 | #define PA_SIZE 4096 |
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_VALUE_LEN(serial) ((serial) >> 24) |
| 52 | #define SERIAL_DIRTY(serial) ((serial) & 1) |
| 53 | |
Colin Cross | 5cf32de | 2013-01-23 23:07:06 -0800 | [diff] [blame] | 54 | __BEGIN_DECLS |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 55 | |
| 56 | struct prop_msg |
| 57 | { |
| 58 | unsigned cmd; |
| 59 | char name[PROP_NAME_MAX]; |
| 60 | char value[PROP_VALUE_MAX]; |
| 61 | }; |
| 62 | |
| 63 | #define PROP_MSG_SETPROP 1 |
| 64 | |
| 65 | /* |
| 66 | ** Rules: |
| 67 | ** |
| 68 | ** - there is only one writer, but many readers |
| 69 | ** - prop_area.count will never decrease in value |
| 70 | ** - once allocated, a prop_info's name will not change |
| 71 | ** - once allocated, a prop_info's offset will not change |
| 72 | ** - reading a value requires the following steps |
| 73 | ** 1. serial = pi->serial |
| 74 | ** 2. if SERIAL_DIRTY(serial), wait*, then goto 1 |
| 75 | ** 3. memcpy(local, pi->value, SERIAL_VALUE_LEN(serial) + 1) |
| 76 | ** 4. if pi->serial != serial, goto 2 |
| 77 | ** |
| 78 | ** - writing a value requires the following steps |
| 79 | ** 1. pi->serial = pi->serial | 1 |
| 80 | ** 2. memcpy(pi->value, local_value, value_len) |
| 81 | ** 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] | 82 | */ |
| 83 | |
| 84 | #define PROP_PATH_RAMDISK_DEFAULT "/default.prop" |
| 85 | #define PROP_PATH_SYSTEM_BUILD "/system/build.prop" |
| 86 | #define PROP_PATH_SYSTEM_DEFAULT "/system/default.prop" |
| 87 | #define PROP_PATH_LOCAL_OVERRIDE "/data/local.prop" |
Andrew Boie | 07564f2 | 2013-01-11 12:46:42 -0800 | [diff] [blame] | 88 | #define PROP_PATH_FACTORY "/factory/factory.prop" |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 89 | |
Colin Cross | 5cf32de | 2013-01-23 23:07:06 -0800 | [diff] [blame] | 90 | /* |
Greg Hackmann | cb215a7 | 2013-02-13 14:41:48 -0800 | [diff] [blame] | 91 | ** Map the property area from the specified filename. This |
| 92 | ** method is for testing only. |
| 93 | */ |
| 94 | int __system_property_set_filename(const char *filename); |
| 95 | |
| 96 | /* |
Colin Cross | 5cf32de | 2013-01-23 23:07:06 -0800 | [diff] [blame] | 97 | ** Initialize the area to be used to store properties. Can |
| 98 | ** only be done by a single process that has write access to |
| 99 | ** the property area. |
| 100 | */ |
Greg Hackmann | cb215a7 | 2013-02-13 14:41:48 -0800 | [diff] [blame] | 101 | int __system_property_area_init(); |
Colin Cross | 5cf32de | 2013-01-23 23:07:06 -0800 | [diff] [blame] | 102 | |
| 103 | /* Add a new system property. Can only be done by a single |
| 104 | ** process that has write access to the property area, and |
| 105 | ** that process must handle sequencing to ensure the property |
| 106 | ** does not already exist and that only one property is added |
| 107 | ** or updated at a time. |
| 108 | ** |
| 109 | ** Returns 0 on success, -1 if the property area is full. |
| 110 | */ |
| 111 | int __system_property_add(const char *name, unsigned int namelen, |
| 112 | const char *value, unsigned int valuelen); |
| 113 | |
| 114 | /* Update the value of a system property returned by |
| 115 | ** __system_property_find. Can only be done by a single process |
| 116 | ** that has write access to the property area, and that process |
| 117 | ** must handle sequencing to ensure that only one property is |
| 118 | ** updated at a time. |
| 119 | ** |
| 120 | ** Returns 0 on success, -1 if the parameters are incorrect. |
| 121 | */ |
| 122 | int __system_property_update(prop_info *pi, const char *value, unsigned int len); |
| 123 | |
| 124 | /* Read the serial number of a system property returned by |
| 125 | ** __system_property_find. |
| 126 | ** |
| 127 | ** Returns the serial number on success, -1 on error. |
| 128 | */ |
| 129 | unsigned int __system_property_serial(const prop_info *pi); |
| 130 | |
| 131 | /* Wait for any system property to be updated. Caller must pass |
| 132 | ** in 0 the first time, and the previous return value on each |
| 133 | ** successive call. */ |
| 134 | unsigned int __system_property_wait_any(unsigned int serial); |
| 135 | |
| 136 | __END_DECLS |
| 137 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 138 | #endif |
| 139 | #endif |