blob: 60789d41bd08e7505ce121132a8604172f96b73b [file] [log] [blame]
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08001/*
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 Hughes203e13d2016-07-22 14:56:18 -070032#include <sys/cdefs.h>
33
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080034#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 Project1dc9e472009-03-03 19:28:35 -080039typedef struct prop_msg prop_msg;
40
41#define PROP_AREA_MAGIC 0x504f5250
Greg Hackmann996cdc42013-06-20 11:27:56 -070042#define PROP_AREA_VERSION 0xfc6ed0ab
Colin Cross5e9a0862013-06-24 18:36:39 -070043#define PROP_AREA_VERSION_COMPAT 0x45434f76
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080044
45#define PROP_SERVICE_NAME "property_service"
Tom Cherry49a309f2015-09-23 16:09:47 -070046#define PROP_FILENAME_MAX 1024
Nick Kralevich32417fb2013-01-23 09:28:35 -080047#define PROP_FILENAME "/dev/__properties__"
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080048
Greg Hackmann1540f602013-06-19 13:31:21 -070049#define PA_SIZE (128 * 1024)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080050
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080051#define SERIAL_VALUE_LEN(serial) ((serial) >> 24)
52#define SERIAL_DIRTY(serial) ((serial) & 1)
53
Colin Cross5cf32de2013-01-23 23:07:06 -080054__BEGIN_DECLS
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080055
Andres Morales9d9ebc52015-01-13 18:00:56 -080056struct prop_msg
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080057{
58 unsigned cmd;
59 char name[PROP_NAME_MAX];
60 char value[PROP_VALUE_MAX];
61};
62
63#define PROP_MSG_SETPROP 1
Andres Morales9d9ebc52015-01-13 18:00:56 -080064
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080065/*
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 Project1dc9e472009-03-03 19:28:35 -080082*/
83
84#define PROP_PATH_RAMDISK_DEFAULT "/default.prop"
85#define PROP_PATH_SYSTEM_BUILD "/system/build.prop"
Daniel Rosenberg71d220c2014-11-10 16:59:57 -080086#define PROP_PATH_VENDOR_BUILD "/vendor/build.prop"
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080087#define PROP_PATH_LOCAL_OVERRIDE "/data/local.prop"
Andrew Boie07564f22013-01-11 12:46:42 -080088#define PROP_PATH_FACTORY "/factory/factory.prop"
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080089
Colin Cross5cf32de2013-01-23 23:07:06 -080090/*
Greg Hackmanncb215a72013-02-13 14:41:48 -080091** Map the property area from the specified filename. This
92** method is for testing only.
93*/
94int __system_property_set_filename(const char *filename);
95
96/*
Colin Cross5cf32de2013-01-23 23:07:06 -080097** 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 Hackmanncb215a72013-02-13 14:41:48 -0800101int __system_property_area_init();
Colin Cross5cf32de2013-01-23 23:07:06 -0800102
Mark Salyzyn123927d2015-04-24 09:31:32 -0700103/* Read the global serial number of the system properties
104**
105** Called to predict if a series of cached __system_property_find
106** objects will have seen __system_property_serial values change.
107** But also aids the converse, as changes in the global serial can
108** also be used to predict if a failed __system_property_find
Mark Salyzyn62075bc2015-04-29 07:21:36 -0700109** could in-turn now find a new object; thus preventing the
Mark Salyzyn123927d2015-04-24 09:31:32 -0700110** cycles of effort to poll __system_property_find.
111**
Mark Salyzyn62075bc2015-04-29 07:21:36 -0700112** Typically called at beginning of a cache cycle to signal if _any_ possible
113** changes have occurred since last. If there is, one may check each individual
Mark Salyzyn123927d2015-04-24 09:31:32 -0700114** __system_property_serial to confirm dirty, or __system_property_find
Mark Salyzyn62075bc2015-04-29 07:21:36 -0700115** to check if the property now exists. If a call to __system_property_add
116** or __system_property_update has completed between two calls to
117** __system_property_area_serial then the second call will return a larger
118** value than the first call. Beware of race conditions as changes to the
119** properties are not atomic, the main value of this call is to determine
120** whether the expensive __system_property_find is worth retrying to see if
121** a property now exists.
Mark Salyzyn123927d2015-04-24 09:31:32 -0700122**
123** Returns the serial number on success, -1 on error.
124*/
125unsigned int __system_property_area_serial();
126
Colin Cross5cf32de2013-01-23 23:07:06 -0800127/* Add a new system property. Can only be done by a single
128** process that has write access to the property area, and
129** that process must handle sequencing to ensure the property
130** does not already exist and that only one property is added
131** or updated at a time.
132**
133** Returns 0 on success, -1 if the property area is full.
134*/
135int __system_property_add(const char *name, unsigned int namelen,
136 const char *value, unsigned int valuelen);
137
138/* Update the value of a system property returned by
139** __system_property_find. Can only be done by a single process
140** that has write access to the property area, and that process
141** must handle sequencing to ensure that only one property is
142** updated at a time.
143**
144** Returns 0 on success, -1 if the parameters are incorrect.
145*/
146int __system_property_update(prop_info *pi, const char *value, unsigned int len);
147
148/* Read the serial number of a system property returned by
149** __system_property_find.
150**
151** Returns the serial number on success, -1 on error.
152*/
153unsigned int __system_property_serial(const prop_info *pi);
154
155/* Wait for any system property to be updated. Caller must pass
156** in 0 the first time, and the previous return value on each
157** successive call. */
158unsigned int __system_property_wait_any(unsigned int serial);
159
Colin Cross5e9a0862013-06-24 18:36:39 -0700160/* Compatibility functions to support using an old init with a new libc,
161 ** mostly for the OTA updater binary. These can be deleted once OTAs from
162 ** a pre-K release no longer needed to be supported. */
163const prop_info *__system_property_find_compat(const char *name);
164int __system_property_read_compat(const prop_info *pi, char *name, char *value);
165int __system_property_foreach_compat(
166 void (*propfn)(const prop_info *pi, void *cookie),
167 void *cookie);
168
Narayan Kamathc9ae21a2014-02-19 17:59:05 +0000169/* Initialize the system properties area in read only mode.
170 * Should be done by all processes that need to read system
171 * properties.
172 *
173 * Returns 0 on success, -1 otherwise.
174 */
175int __system_properties_init();
176
Colin Cross5cf32de2013-01-23 23:07:06 -0800177__END_DECLS
178
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800179#endif
180#endif