• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #define PROP_FILENAME "/dev/__properties__"
45 
46 /* #define PROP_MAX_ENTRIES 247 */
47 /* 247 -> 32620 bytes (<32768) */
48 
49 #define TOC_NAME_LEN(toc)       ((toc) >> 24)
50 #define TOC_TO_INFO(area, toc)  ((prop_info*) (((char*) area) + ((toc) & 0xFFFFFF)))
51 
52 struct prop_area {
53     unsigned volatile count;
54     unsigned volatile serial;
55     unsigned magic;
56     unsigned version;
57     unsigned reserved[4];
58     unsigned toc[1];
59 };
60 
61 #define SERIAL_VALUE_LEN(serial) ((serial) >> 24)
62 #define SERIAL_DIRTY(serial) ((serial) & 1)
63 
64 struct prop_info {
65     char name[PROP_NAME_MAX];
66     unsigned volatile serial;
67     char value[PROP_VALUE_MAX];
68 };
69 
70 struct prop_msg
71 {
72     unsigned cmd;
73     char name[PROP_NAME_MAX];
74     char value[PROP_VALUE_MAX];
75 };
76 
77 #define PROP_MSG_SETPROP 1
78 
79 /*
80 ** Rules:
81 **
82 ** - there is only one writer, but many readers
83 ** - prop_area.count will never decrease in value
84 ** - once allocated, a prop_info's name will not change
85 ** - once allocated, a prop_info's offset will not change
86 ** - reading a value requires the following steps
87 **   1. serial = pi->serial
88 **   2. if SERIAL_DIRTY(serial), wait*, then goto 1
89 **   3. memcpy(local, pi->value, SERIAL_VALUE_LEN(serial) + 1)
90 **   4. if pi->serial != serial, goto 2
91 **
92 ** - writing a value requires the following steps
93 **   1. pi->serial = pi->serial | 1
94 **   2. memcpy(pi->value, local_value, value_len)
95 **   3. pi->serial = (value_len << 24) | ((pi->serial + 1) & 0xffffff)
96 **
97 ** Improvements:
98 ** - maintain the toc sorted by pi->name to allow lookup
99 **   by binary search
100 **
101 */
102 
103 #define PROP_PATH_RAMDISK_DEFAULT  "/default.prop"
104 #define PROP_PATH_SYSTEM_BUILD     "/system/build.prop"
105 #define PROP_PATH_SYSTEM_DEFAULT   "/system/default.prop"
106 #define PROP_PATH_LOCAL_OVERRIDE   "/data/local.prop"
107 #define PROP_PATH_FACTORY          "/factory/factory.prop"
108 
109 #endif
110 #endif
111