summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Salyzyn <salyzyn@google.com>2015-04-16 00:32:33 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2015-04-16 00:32:33 +0000
commit233b4974df9333b022c059da48821948617874ae (patch)
treeee68521cb2e6aaa3525c70a62a255ee2c9ec1879
parenteb24a1c288fe94dfc62aa4f74fd8861ad16dabd6 (diff)
parentc130d96e9cf786d17196a400a07fb4e6e221a07c (diff)
downloadsystem_core-233b4974df9333b022c059da48821948617874ae.zip
system_core-233b4974df9333b022c059da48821948617874ae.tar.gz
system_core-233b4974df9333b022c059da48821948617874ae.tar.bz2
am c130d96e: am e1b87e1a: am 48257704: Merge "libcutils: add fs_config_generate"
* commit 'c130d96e9cf786d17196a400a07fb4e6e221a07c': libcutils: add fs_config_generate
-rw-r--r--include/private/android_filesystem_config.h2
-rw-r--r--libcutils/fs_config.c21
2 files changed, 23 insertions, 0 deletions
diff --git a/include/private/android_filesystem_config.h b/include/private/android_filesystem_config.h
index fed81f8..02fe2b5 100644
--- a/include/private/android_filesystem_config.h
+++ b/include/private/android_filesystem_config.h
@@ -215,6 +215,8 @@ __BEGIN_DECLS
void fs_config(const char *path, int dir,
unsigned *uid, unsigned *gid, unsigned *mode, uint64_t *capabilities);
+ssize_t fs_config_generate(char *buffer, size_t length, const struct fs_path_config *pc);
+
__END_DECLS
#endif
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;
+}