diff options
author | Mark Salyzyn <salyzyn@google.com> | 2015-04-01 11:02:00 -0700 |
---|---|---|
committer | Mark Salyzyn <salyzyn@google.com> | 2015-04-15 16:43:07 -0700 |
commit | 5d9e5efbcdab4a5442e332944765f67eb7005be5 (patch) | |
tree | 1133e734a780e94b79d00bdd150f6196ff817c7e /libcutils | |
parent | 68651148dd06da576068749d33a82b5105d67091 (diff) | |
download | system_core-5d9e5efbcdab4a5442e332944765f67eb7005be5.zip system_core-5d9e5efbcdab4a5442e332944765f67eb7005be5.tar.gz system_core-5d9e5efbcdab4a5442e332944765f67eb7005be5.tar.bz2 |
libcutils: add fs_config_generate
Bug: 19908228
Change-Id: Icb0e189a86758bb779b9bdf7c0d92216d297869f
Diffstat (limited to 'libcutils')
-rw-r--r-- | libcutils/fs_config.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/libcutils/fs_config.c b/libcutils/fs_config.c index bdb24dc..7fd66cd 100644 --- a/libcutils/fs_config.c +++ b/libcutils/fs_config.c @@ -63,6 +63,8 @@ static inline uint64_t get8LE(const uint8_t* src) return ((uint64_t) high << 32) | (uint64_t) low; } +#define ALIGN(x, alignment) ( ((x) + ((alignment) - 1)) & ~((alignment) - 1) ) + /* Rules for directories. ** These rules are applied based on "first match", so they ** should start with the most specific path and work their @@ -261,3 +263,22 @@ void fs_config(const char *path, int dir, *mode = (*mode & (~07777)) | pc->mode; *capabilities = pc->capabilities; } + +ssize_t fs_config_generate(char *buffer, size_t length, const struct fs_path_config *pc) +{ + struct fs_path_config_from_file *p = (struct fs_path_config_from_file *)buffer; + size_t len = ALIGN(sizeof(*p) + strlen(pc->prefix) + 1, sizeof(uint64_t)); + + if ((length < len) || (len > UINT16_MAX)) { + return -ENOSPC; + } + memset(p, 0, len); + uint16_t host_len = len; + p->len = get2LE((const uint8_t *)&host_len); + p->mode = get2LE((const uint8_t *)&(pc->mode)); + p->uid = get2LE((const uint8_t *)&(pc->uid)); + p->gid = get2LE((const uint8_t *)&(pc->gid)); + p->capabilities = get8LE((const uint8_t *)&(pc->capabilities)); + strcpy(p->prefix, pc->prefix); + return len; +} |