blob: 44cdd958d9cb222468c84602766c01082381c1cc [file] [log] [blame]
that7e303cf2014-03-06 07:57:43 +01001/*
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_LEGACY_PROPERTIES_H
30#define _INCLUDE_LEGACY_PROPERTIES_H
31
32#include <sys/system_properties.h>
33
34typedef struct prop_area prop_area;
35typedef struct prop_msg prop_msg;
36
37#define PROP_AREA_MAGIC 0x504f5250
38#define PROP_AREA_VERSION 0x45434f76
39
40#define PROP_SERVICE_NAME "property_service"
41
42/* #define PROP_MAX_ENTRIES 247 */
43/* 247 -> 32620 bytes (<32768) */
44
45#define TOC_NAME_LEN(toc) ((toc) >> 24)
46#define TOC_TO_INFO(area, toc) ((prop_info*) (((char*) area) + ((toc) & 0xFFFFFF)))
47
48struct prop_area {
49 unsigned volatile count;
50 unsigned volatile serial;
51 unsigned magic;
52 unsigned version;
53 unsigned reserved[4];
54 unsigned toc[1];
55};
56
57#define SERIAL_VALUE_LEN(serial) ((serial) >> 24)
58#define SERIAL_DIRTY(serial) ((serial) & 1)
59
60struct prop_info {
61 char name[PROP_NAME_MAX];
62 unsigned volatile serial;
63 char value[PROP_VALUE_MAX];
64};
65
Matt Mowercdd3b332014-03-27 14:38:48 -050066struct prop_msg
that7e303cf2014-03-06 07:57:43 +010067{
68 unsigned cmd;
69 char name[PROP_NAME_MAX];
70 char value[PROP_VALUE_MAX];
71};
72
73#define PROP_MSG_SETPROP 1
Matt Mowercdd3b332014-03-27 14:38:48 -050074
that7e303cf2014-03-06 07:57:43 +010075/*
76** Rules:
77**
78** - there is only one writer, but many readers
79** - prop_area.count will never decrease in value
80** - once allocated, a prop_info's name will not change
81** - once allocated, a prop_info's offset will not change
82** - reading a value requires the following steps
83** 1. serial = pi->serial
84** 2. if SERIAL_DIRTY(serial), wait*, then goto 1
85** 3. memcpy(local, pi->value, SERIAL_VALUE_LEN(serial) + 1)
86** 4. if pi->serial != serial, goto 2
87**
88** - writing a value requires the following steps
89** 1. pi->serial = pi->serial | 1
90** 2. memcpy(pi->value, local_value, value_len)
91** 3. pi->serial = (value_len << 24) | ((pi->serial + 1) & 0xffffff)
92**
93** Improvements:
94** - maintain the toc sorted by pi->name to allow lookup
95** by binary search
96**
97*/
98
99#define PROP_PATH_RAMDISK_DEFAULT "/default.prop"
100#define PROP_PATH_SYSTEM_BUILD "/system/build.prop"
101#define PROP_PATH_SYSTEM_DEFAULT "/system/default.prop"
102#define PROP_PATH_LOCAL_OVERRIDE "/data/local.prop"
103
104#endif