blob: c5bc2235b110c1b46fd2bf11a2dfa53be0984866 [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
40#define PROP_AREA_VERSION 0x45434f76
41
42#define PROP_SERVICE_NAME "property_service"
Nick Kralevich32417fb2013-01-23 09:28:35 -080043#define PROP_FILENAME "/dev/__properties__"
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080044
Colin Cross5cf32de2013-01-23 23:07:06 -080045/* (8 header words + 247 toc words) = 1020 bytes */
46/* 1024 bytes header and toc + 247 prop_infos @ 128 bytes = 32640 bytes */
47
48#define PA_COUNT_MAX 247
49#define PA_INFO_START 1024
50#define PA_SIZE 32768
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080051
52#define TOC_NAME_LEN(toc) ((toc) >> 24)
53#define TOC_TO_INFO(area, toc) ((prop_info*) (((char*) area) + ((toc) & 0xFFFFFF)))
54
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080055#define SERIAL_VALUE_LEN(serial) ((serial) >> 24)
56#define SERIAL_DIRTY(serial) ((serial) & 1)
57
Colin Cross5cf32de2013-01-23 23:07:06 -080058__BEGIN_DECLS
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080059
60struct prop_msg
61{
62 unsigned cmd;
63 char name[PROP_NAME_MAX];
64 char value[PROP_VALUE_MAX];
65};
66
67#define PROP_MSG_SETPROP 1
68
69/*
70** Rules:
71**
72** - there is only one writer, but many readers
73** - prop_area.count will never decrease in value
74** - once allocated, a prop_info's name will not change
75** - once allocated, a prop_info's offset will not change
76** - reading a value requires the following steps
77** 1. serial = pi->serial
78** 2. if SERIAL_DIRTY(serial), wait*, then goto 1
79** 3. memcpy(local, pi->value, SERIAL_VALUE_LEN(serial) + 1)
80** 4. if pi->serial != serial, goto 2
81**
82** - writing a value requires the following steps
83** 1. pi->serial = pi->serial | 1
84** 2. memcpy(pi->value, local_value, value_len)
85** 3. pi->serial = (value_len << 24) | ((pi->serial + 1) & 0xffffff)
86**
87** Improvements:
88** - maintain the toc sorted by pi->name to allow lookup
89** by binary search
90**
91*/
92
93#define PROP_PATH_RAMDISK_DEFAULT "/default.prop"
94#define PROP_PATH_SYSTEM_BUILD "/system/build.prop"
95#define PROP_PATH_SYSTEM_DEFAULT "/system/default.prop"
96#define PROP_PATH_LOCAL_OVERRIDE "/data/local.prop"
Andrew Boie07564f22013-01-11 12:46:42 -080097#define PROP_PATH_FACTORY "/factory/factory.prop"
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080098
Colin Cross5cf32de2013-01-23 23:07:06 -080099/*
100** Initialize the area to be used to store properties. Can
101** only be done by a single process that has write access to
102** the property area.
103*/
104void __system_property_area_init(void *data);
105
106/* Add a new system property. Can only be done by a single
107** process that has write access to the property area, and
108** that process must handle sequencing to ensure the property
109** does not already exist and that only one property is added
110** or updated at a time.
111**
112** Returns 0 on success, -1 if the property area is full.
113*/
114int __system_property_add(const char *name, unsigned int namelen,
115 const char *value, unsigned int valuelen);
116
117/* Update the value of a system property returned by
118** __system_property_find. Can only be done by a single process
119** that has write access to the property area, and that process
120** must handle sequencing to ensure that only one property is
121** updated at a time.
122**
123** Returns 0 on success, -1 if the parameters are incorrect.
124*/
125int __system_property_update(prop_info *pi, const char *value, unsigned int len);
126
127/* Read the serial number of a system property returned by
128** __system_property_find.
129**
130** Returns the serial number on success, -1 on error.
131*/
132unsigned int __system_property_serial(const prop_info *pi);
133
134/* Wait for any system property to be updated. Caller must pass
135** in 0 the first time, and the previous return value on each
136** successive call. */
137unsigned int __system_property_wait_any(unsigned int serial);
138
139__END_DECLS
140
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800141#endif
142#endif