OSDN Git Service

original
[gb-231r1-is01/Gingerbread_2.3.3_r1_IS01.git] / prebuilt / ndk / android-ndk-r4 / platforms / android-5 / arch-x86 / usr / include / sys / _system_properties.h
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
37 typedef struct prop_area prop_area;
38 typedef struct prop_msg prop_msg;
39
40 #define PROP_AREA_MAGIC   0x504f5250
41 #define PROP_AREA_VERSION 0x45434f76
42
43 #define PROP_SERVICE_NAME "property_service"
44
45 /* #define PROP_MAX_ENTRIES 247 */
46 /* 247 -> 32620 bytes (<32768) */
47
48 #define TOC_NAME_LEN(toc)       ((toc) >> 24)
49 #define TOC_TO_INFO(area, toc)  ((prop_info*) (((char*) area) + ((toc) & 0xFFFFFF)))
50
51 struct prop_area {
52     unsigned volatile count;
53     unsigned volatile serial;
54     unsigned magic;
55     unsigned version;
56     unsigned reserved[4];
57     unsigned toc[1];
58 };
59
60 #define SERIAL_VALUE_LEN(serial) ((serial) >> 24)
61 #define SERIAL_DIRTY(serial) ((serial) & 1)
62
63 struct prop_info {
64     char name[PROP_NAME_MAX];
65     unsigned volatile serial;
66     char value[PROP_VALUE_MAX];
67 };
68
69 struct prop_msg 
70 {
71     unsigned cmd;
72     char name[PROP_NAME_MAX];
73     char value[PROP_VALUE_MAX];
74 };
75
76 #define PROP_MSG_SETPROP 1
77     
78 /*
79 ** Rules:
80 **
81 ** - there is only one writer, but many readers
82 ** - prop_area.count will never decrease in value
83 ** - once allocated, a prop_info's name will not change
84 ** - once allocated, a prop_info's offset will not change
85 ** - reading a value requires the following steps
86 **   1. serial = pi->serial
87 **   2. if SERIAL_DIRTY(serial), wait*, then goto 1
88 **   3. memcpy(local, pi->value, SERIAL_VALUE_LEN(serial) + 1)
89 **   4. if pi->serial != serial, goto 2
90 **
91 ** - writing a value requires the following steps
92 **   1. pi->serial = pi->serial | 1
93 **   2. memcpy(pi->value, local_value, value_len)
94 **   3. pi->serial = (value_len << 24) | ((pi->serial + 1) & 0xffffff)
95 **
96 ** Improvements:
97 ** - maintain the toc sorted by pi->name to allow lookup
98 **   by binary search
99 **
100 */
101
102 #define PROP_PATH_RAMDISK_DEFAULT  "/default.prop"
103 #define PROP_PATH_SYSTEM_BUILD     "/system/build.prop"
104 #define PROP_PATH_SYSTEM_DEFAULT   "/system/default.prop"
105 #define PROP_PATH_LOCAL_OVERRIDE   "/data/local.prop"
106
107 #endif
108 #endif