T-Box Basic dev
Loading...
Searching...
No Matches
_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/* clang-format off */
29#ifndef _INCLUDE_SYS__SYSTEM_PROPERTIES_H
30#define _INCLUDE_SYS__SYSTEM_PROPERTIES_H
31
32#include "system_properties.h"
33#include "internal/fs_paths.h"
34
35#define __predict_true(exp) (exp)
36#define __predict_false(exp) (exp)
37#define PATH_MAX 4096
38
39typedef struct prop_msg1 prop_msg;
40
41#define PROP_AREA_MAGIC 0x504f5250
42#define PROP_AREA_VERSION 0xfc6ed0ab
43#define PROP_AREA_VERSION_COMPAT 0x45434f76
44
45#define PROP_SERVICE_NAME "/tmp/tbox_propertyd.sock"
46#define PROP_FILENAME "/var/run/__tbox_property__"
47#define PROP_PID_FILE "/var/run/tbox_propertyd.pid"
48
49#define PA_SIZE (256 * 1024)
50
51#define SERIAL_VALUE_LEN(serial) ((serial) >> 24)
52#define SERIAL_DIRTY(serial) ((serial) & 1)
53
54__BEGIN_DECLS
55
56struct prop_msg1
57{
58 unsigned cmd;
59 char name[PROP_NAME_MAX];
60 char value[PROP_VALUE_MAX];
61};
62
63#define PROP_MSG_SETPROP 1
64#define PROP_MSG_ARRAY 2
65
66/*
67** Rules:
68**
69** - there is only one writer, but many readers
70** - prop_area.count will never decrease in value
71** - once allocated, a prop_info's name will not change
72** - once allocated, a prop_info's offset will not change
73** - reading a value requires the following steps
74** 1. serial = pi->serial
75** 2. if SERIAL_DIRTY(serial), wait*, then goto 1
76** 3. memcpy(local, pi->value, SERIAL_VALUE_LEN(serial) + 1)
77** 4. if pi->serial != serial, goto 2
78**
79** - writing a value requires the following steps
80** 1. pi->serial = pi->serial | 1
81** 2. memcpy(pi->value, local_value, value_len)
82** 3. pi->serial = (value_len << 24) | ((pi->serial + 1) & 0xffffff)
83*/
84
85#define PROP_PATH_RAMDISK_DEFAULT "/default.prop"
86#define PROP_PATH_SYSTEM_BUILD "/system/build.prop"
87#define PROP_PATH_SYSTEM_DEFAULT "/system/default.prop"
88#define PROP_PATH_LOCAL_OVERRIDE "/data/local.prop"
89#define PROP_PATH_FACTORY "/factory/factory.prop"
90#define PROP_PATH_TBOX_DEFAULT TBOX_ETC_RO_PATH"/default.prop"
91#define PROP_PATH_TBOX_PROJECT TBOX_ETC_RO_PATH"/project.prop"
92#define PERSISTENT_PROPERTY_DIR TBOX_ETC_RW_PATH
93
94/*
95** Map the property area from the specified filename. This
96** method is for testing only.
97*/
98int __system_property_set_filename(const char *filename);
99
100int __system_property_area_init_mm();
101
102/*
103** Initialize the area to be used to store properties. Can
104** only be done by a single process that has write access to
105** the property area.
106*/
107int __system_property_area_init();
108
109/* Add a new system property. Can only be done by a single
110** process that has write access to the property area, and
111** that process must handle sequencing to ensure the property
112** does not already exist and that only one property is added
113** or updated at a time.
114**
115** Returns 0 on success, -1 if the property area is full.
116*/
117int __system_property_add(const char *name, unsigned int namelen,
118 const char *value, unsigned int valuelen);
119
120/* Update the value of a system property returned by
121** __system_property_find. Can only be done by a single process
122** that has write access to the property area, and that process
123** must handle sequencing to ensure that only one property is
124** updated at a time.
125**
126** Returns 0 on success, -1 if the parameters are incorrect.
127*/
128int __system_property_update(prop_info *pi, const char *value, unsigned int len);
129
130/* Read the serial number of a system property returned by
131** __system_property_find.
132**
133** Returns the serial number on success, -1 on error.
134*/
135unsigned int __system_property_serial(const prop_info *pi);
136
137/* Wait for any system property to be updated. Caller must pass
138** in 0 the first time, and the previous return value on each
139** successive call. */
140unsigned int __system_property_wait_any(unsigned int serial);
141
142/* Compatibility functions to support using an old init with a new libc,
143 ** mostly for the OTA updater binary. These can be deleted once OTAs from
144 ** a pre-K release no longer needed to be supported. */
145const prop_info *__system_property_find_compat(const char *name);
146
147int __system_property_read_compat(const prop_info *pi, char *name, char *value);
148
149int __system_property_foreach_compat(
150 void (*propfn)(const prop_info *pi, void *cookie),
151 void *cookie);
152
153__END_DECLS
154
155#endif
156/* clang-format on */
T-Box 文件系统相关宏
Definition _system_properties.h:57