blob: 0349e4c3d055d5f43cdda9981d19a6579d444966 [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
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 Project1dc9e472009-03-03 19:28:35 -080037typedef struct prop_msg prop_msg;
38
39#define PROP_AREA_MAGIC 0x504f5250
Greg Hackmann996cdc42013-06-20 11:27:56 -070040#define PROP_AREA_VERSION 0xfc6ed0ab
Colin Cross5e9a0862013-06-24 18:36:39 -070041#define PROP_AREA_VERSION_COMPAT 0x45434f76
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080042
43#define PROP_SERVICE_NAME "property_service"
Nick Kralevich32417fb2013-01-23 09:28:35 -080044#define PROP_FILENAME "/dev/__properties__"
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080045
Greg Hackmann1540f602013-06-19 13:31:21 -070046#define PA_SIZE (128 * 1024)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080047
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080048#define SERIAL_VALUE_LEN(serial) ((serial) >> 24)
49#define SERIAL_DIRTY(serial) ((serial) & 1)
50
Colin Cross5cf32de2013-01-23 23:07:06 -080051__BEGIN_DECLS
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080052
53struct prop_msg
54{
55 unsigned cmd;
56 char name[PROP_NAME_MAX];
57 char value[PROP_VALUE_MAX];
58};
59
60#define PROP_MSG_SETPROP 1
61
62/*
63** Rules:
64**
65** - there is only one writer, but many readers
66** - prop_area.count will never decrease in value
67** - once allocated, a prop_info's name will not change
68** - once allocated, a prop_info's offset will not change
69** - reading a value requires the following steps
70** 1. serial = pi->serial
71** 2. if SERIAL_DIRTY(serial), wait*, then goto 1
72** 3. memcpy(local, pi->value, SERIAL_VALUE_LEN(serial) + 1)
73** 4. if pi->serial != serial, goto 2
74**
75** - writing a value requires the following steps
76** 1. pi->serial = pi->serial | 1
77** 2. memcpy(pi->value, local_value, value_len)
78** 3. pi->serial = (value_len << 24) | ((pi->serial + 1) & 0xffffff)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080079*/
80
81#define PROP_PATH_RAMDISK_DEFAULT "/default.prop"
82#define PROP_PATH_SYSTEM_BUILD "/system/build.prop"
83#define PROP_PATH_SYSTEM_DEFAULT "/system/default.prop"
Daniel Rosenberg4a50d8e2014-11-10 16:59:57 -080084#define PROP_PATH_VENDOR_BUILD "/vendor/build.prop"
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080085#define PROP_PATH_LOCAL_OVERRIDE "/data/local.prop"
Andrew Boie07564f22013-01-11 12:46:42 -080086#define PROP_PATH_FACTORY "/factory/factory.prop"
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080087
Colin Cross5cf32de2013-01-23 23:07:06 -080088/*
Greg Hackmanncb215a72013-02-13 14:41:48 -080089** Map the property area from the specified filename. This
90** method is for testing only.
91*/
92int __system_property_set_filename(const char *filename);
93
94/*
Colin Cross5cf32de2013-01-23 23:07:06 -080095** 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*/
Greg Hackmanncb215a72013-02-13 14:41:48 -080099int __system_property_area_init();
Colin Cross5cf32de2013-01-23 23:07:06 -0800100
101/* Add a new system property. Can only be done by a single
102** process that has write access to the property area, and
103** that process must handle sequencing to ensure the property
104** does not already exist and that only one property is added
105** or updated at a time.
106**
107** Returns 0 on success, -1 if the property area is full.
108*/
109int __system_property_add(const char *name, unsigned int namelen,
110 const char *value, unsigned int valuelen);
111
112/* Update the value of a system property returned by
113** __system_property_find. Can only be done by a single process
114** that has write access to the property area, and that process
115** must handle sequencing to ensure that only one property is
116** updated at a time.
117**
118** Returns 0 on success, -1 if the parameters are incorrect.
119*/
120int __system_property_update(prop_info *pi, const char *value, unsigned int len);
121
122/* Read the serial number of a system property returned by
123** __system_property_find.
124**
125** Returns the serial number on success, -1 on error.
126*/
127unsigned int __system_property_serial(const prop_info *pi);
128
129/* Wait for any system property to be updated. Caller must pass
130** in 0 the first time, and the previous return value on each
131** successive call. */
132unsigned int __system_property_wait_any(unsigned int serial);
133
Colin Cross5e9a0862013-06-24 18:36:39 -0700134/* Compatibility functions to support using an old init with a new libc,
135 ** mostly for the OTA updater binary. These can be deleted once OTAs from
136 ** a pre-K release no longer needed to be supported. */
137const prop_info *__system_property_find_compat(const char *name);
138int __system_property_read_compat(const prop_info *pi, char *name, char *value);
139int __system_property_foreach_compat(
140 void (*propfn)(const prop_info *pi, void *cookie),
141 void *cookie);
142
Narayan Kamathc9ae21a2014-02-19 17:59:05 +0000143/* Initialize the system properties area in read only mode.
144 * Should be done by all processes that need to read system
145 * properties.
146 *
147 * Returns 0 on success, -1 otherwise.
148 */
149int __system_properties_init();
150
Colin Cross5cf32de2013-01-23 23:07:06 -0800151__END_DECLS
152
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800153#endif
154#endif