interface file list
-
- 1. android_filesystem_config.h
- 2. android_get_control_file.h
- 3. android_reboot.h
- 4. ashmem.h
- 5. atomic.h
- 6. bitops.h
- 7. compiler.h
- 8. config_utils.h
- 9.fs.h
- 10. hashmap.h
- 11. iosched_policy.h
- 12. wise.h
- 13. list.h
- 14. log.h
- 15. memory.h
- 16. misc.h
- 17. multiuser.h
- 18. native_handle.h
- 19. partition_utils.h
- 20. properties.h
- 21. qtaguid.h
- 22. record_stream.h
- 23. sched_policy.h
- 24. sockets.h
- 25. str_parms.h
- 26. threads.h
- 27. trace.h
- 28. uevent.h
1. android_filesystem_config.h
Many AID_xxx macros are defined, and build/tools/fs_config is used to generate Android files.
#define AID_ROOT 0
#define AID_DAEMON
#define AID_BIN 2
#define AID_SYSTEM 1000
2. android_get_control_file.h
Get the file managed by init, path is the file path in init.rc, return fd. See klog.cpp
int android_get_control_file(const char* path);
3. android_reboot.h
By setting the property, request the init process to restart and shut down the system.
int android_reboot(unsigned cmd, int flags, const char* arg);
4. ashmem.h
Encapsulate shared memory related functions.
int ashmem_valid(int fd);
int ashmem_create_region(const char *name, size_t size);
int ashmem_set_prot_region(int fd, int prot);
int ashmem_pin_region(int fd, size_t offset, size_t len);
int ashmem_unpin_region(int fd, size_t offset, size_t len);
int ashmem_get_size_region(int fd);
5. atomic.h
Some functions related to atomic are legacy codes and are not recommended.
6. bitops.h
Encapsulation of __builtin_popcount to count the number of 1s in binary.
static inline int popcount(unsigned int x);
7. compiler.h
Define CC_LIKELY/CC_UNLIKELY macros and encapsulate __builtin_expect.
#define ANDROID_API __attribute__((visibility("default")))
8. config_utils.h
Analysis and processing of configuration files.
void config_load(cnode *root, char *data);
void config_load_file(cnode *root, const char *fn);
cnode* config_node(const char *name, const char *value);
cnode* config_find(cnode *root, const char *name);
int config_bool(cnode *root, const char *name, int _default);
const char* config_str(cnode *root, const char *name, const char *_default);
void config_set(cnode *root, const char *name, const char *value);
void config_free(cnode *root);
9.fs.h
File and directory related methods
如果path不存在,则创建。
如果path存在,加查mode和owners,如果不符合,则修改。
extern int fs_prepare_dir(const char* path, mode_t mode, uid_t uid, gid_t gid);
同上,如果不符合,不修改参,返回-1。
extern int fs_prepare_dir_strict(const char* path, mode_t mode, uid_t uid, gid_t gid);
extern int fs_prepare_file_strict(const char* path, mode_t mode, uid_t uid, gid_t gid);
从文件中读写一个整数。
extern int fs_read_atomic_int(const char* path, int* value);
extern int fs_write_atomic_int(const char* path, int value);
创建path指定的各级目录。
如果最后不是'/'结尾,最后一级会被当做文件名,忽略。
extern int fs_mkdirs(const char* path, mode_t mode);
10. hashmap.h
Customize Hashmap and related operation functions.
11. iosched_policy.h
设置/获取io schedule policy。
extern int android_set_ioprio(int pid, IoSchedClass clazz, int ioprio);
extern int android_get_ioprio(int pid, IoSchedClass *clazz, int *ioprio);
12. wise.h
提供/dev/kmsg的写log方法。
void klog_set_level(int level);
void klog_write(int level, const char fmt, …) attribute ((format(printf, 2, 3)));
void klog_writev(int level, const struct iovec iov, int iov_count);
13. list.h
Customize list and related operation functions.
14. log.h
#include <log/log.h>
15. memory.h
Declare method for GLIBC and WIN32:
size_t strlcpy(char *dst, const char *src, size_t size);
16. misc.h
Load the file fn into the memory, the size is file-size + 1, and return the memory size through sz.
extern void *load_file(const char *fn, unsigned *sz);
UID范围。
#define FIRST_APPLICATION_UID 10000
#define LAST_APPLICATION_UID 99999
17. multiuser.h
It encapsulates user id, app id, uid, cache_gid, ext gid, ext cache gid, shared gid, share app gid acquisition and conversion functions.
18. native_handle.h
Define the native_handle structure, and related operation functions such as creation and deletion.
The native_handle definition uses the C99 extension, variable-length array (0-length array zero-length-array). According to the actual values of numFds and numInts, save the corresponding number of data arrays.
typedef struct native_handle
{
int version; /* sizeof(native_handle_t) */
int numFds; /* number of file-descriptors at &data[0] */
int numInts; /* number of ints at &data[numFds] */
int data[0]; /* numFds + numInts ints */
} native_handle_t;
int native_handle_close(const native_handle_t* h);
native_handle_t* native_handle_init(char* storage, int numFds, int numInts);
native_handle_t* native_handle_create(int numFds, int numInts);
native_handle_t* native_handle_clone(const native_handle_t* handle);
int native_handle_delete(native_handle_t* h);
19. partition_utils.h
Check whether the device specified by source is all 0 or all 0xff in the first 4096 bytes.
int partition_wiped(const char* source);
20. properties.h
Manipulate property functions.
intproperty_get(const char* key, char* value, const char* default_value);
int8_t property_get_bool(const char *key, int8_t default_value);
int64_t property_get_int64(const char *key, int64_t default_value);
int32_t property_get_int32(const char *key, int32_t default_value);
int property_set(const char *key, const char *value);
int property_list(void (*propfn)(const char *key, const char *value, void *cookie), void *cookie);
21. qtaguid.h
Encapsulation of several methods of libnetd_client.so library.
extern int qtaguid_tagSocket(int sockfd, int tag, uid_t uid);
extern int qtaguid_untagSocket(int sockfd);
extern int qtaguid_setCounterSet(int counterSetNum, uid_t uid);
extern int qtaguid_deleteTagData(int tag, uid_t uid);
extern int qtaguid_setPacifier(int on);
22. record_stream.h
Several helper functions provide the ability to read fixed-size records from streams.
struct RecordStream {
int fd;
size_t maxRecordLen;
unsigned char *buffer;
unsigned char *unconsumed;
unsigned char *read_end;
unsigned char *buffer_end;
};
extern RecordStream *record_stream_new(int fd, size_t maxRecordLen);
extern void record_stream_free(RecordStream *p_rs);
extern int record_stream_get_next (RecordStream *p_rs, void ** p_outRecord,
size_t *p_outRecordLen);
23. sched_policy.h
Kernel CPUSETS/SCHEDTUNE function settings.
#include <processgroup/sched_policy.h>
24. sockets.h
Get the socket named name in init.rc and return fd.
int android_get_control_socket(const char* name);
Encapsulate common socket functions.
cutils_socket_t socket_network_client(const char* host, int port, int type);
int socket_network_client_timeout(const char* host, int port, int type,
int timeout, int* getaddrinfo_error);
int socket_local_server(const char* name, int namespaceId, int type);
int socket_local_server_bind(int s, const char* name, int namespaceId);
int socket_local_client_connect(int fd, const char *name, int namespaceId, int type);
int socket_local_client(const char* name, int namespaceId, int type);
cutils_socket_t socket_inaddr_any_server(int port, int type);
int socket_close(cutils_socket_t sock);
int socket_get_local_port(cutils_socket_t sock);
ssize_t socket_send_buffers(cutils_socket_t sock,
const cutils_socket_buffer_t* buffers,
size_t num_buffers);
25. str_parms.h
Use custom Hashmap to implement str_parms and related operations. I don't know what it is for.
26. threads.h
废弃:
1)gettid -> android::base::GetThreadId
2)thread_store -> _Thread_local © or thread_local (C++)
// syscall(__NR_gettid);
extern pid_t gettid();
extern void* thread_store_get(thread_store_t* store);
extern void thread_store_set(thread_store_t* store,
void* value,
thread_store_destruct_t destroy);
27. trace.h
atrace related functions, and ATRACE_TAG_xxx series macro definitions.
void atrace_setup();
void atrace_update_tags();
void atrace_set_debuggable(bool debuggable);
void atrace_set_tracing_enabled(bool enabled);
#define ATRACE_INIT() atrace_init()
#define ATRACE_GET_ENABLED_TAGS() atrace_get_enabled_tags()
void atrace_init();
uint64_t atrace_get_enabled_tags();
#define ATRACE_ENABLED() atrace_is_tag_enabled(ATRACE_TAG)
static inline uint64_t atrace_is_tag_enabled(uint64_t tag)
#define ATRACE_BEGIN(name) atrace_begin(ATRACE_TAG, name)
static inline void atrace_begin(uint64_t tag, const char* name)
#define ATRACE_END() atrace_end(ATRACE_TAG)
static inline void atrace_end(uint64_t tag)
#define ATRACE_ASYNC_BEGIN(name, cookie) atrace_async_begin(ATRACE_TAG, name, cookie)
static inline void atrace_async_begin(uint64_t tag, const char* name, int32_t cookie)
#define ATRACE_ASYNC_END(name, cookie) atrace_async_end(ATRACE_TAG, name, cookie)
static inline void atrace_async_end(uint64_t tag, const char* name, int32_t cookie)
#define ATRACE_INT(name, value) atrace_int(ATRACE_TAG, name, value)
static inline void atrace_int(uint64_t tag, const char* name, int32_t value)
#define ATRACE_INT64(name, value) atrace_int64(ATRACE_TAG, name, value)
static inline void atrace_int64(uint64_t tag, const char* name, int64_t value)
28. uevent.h
Encapsulate netlink ipc function.
int uevent_open_socket(int buf_sz, bool passcred);
ssize_t uevent_kernel_multicast_recv(int socket, void *buffer, size_t length);
ssize_t uevent_kernel_multicast_uid_recv(int socket, void *buffer, size_t length, uid_t *uid);
ssize_t uevent_kernel_recv(int socket, void *buffer, size_t length, bool require_group, uid_t *uid);