Mark Salyzyn | 8b2c7de | 2015-04-01 07:42:01 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | /* This file is used to define the properties of the filesystem |
| 18 | ** images generated by build tools (mkbootfs and mkyaffs2image) and |
| 19 | ** by the device side of adb. |
| 20 | */ |
| 21 | |
Mark Salyzyn | 6865114 | 2015-04-01 09:24:22 -0700 | [diff] [blame] | 22 | #define LOG_TAG "fs_config" |
Mark Salyzyn | 4e5f71a | 2015-04-01 09:24:22 -0700 | [diff] [blame] | 23 | |
Mark Salyzyn | 6865114 | 2015-04-01 09:24:22 -0700 | [diff] [blame] | 24 | #define _GNU_SOURCE |
| 25 | |
| 26 | #include <errno.h> |
| 27 | #include <fcntl.h> |
| 28 | #include <stdbool.h> |
| 29 | #include <stdint.h> |
| 30 | #include <stdio.h> |
| 31 | #include <stdlib.h> |
| 32 | #include <string.h> |
Mark Salyzyn | 6865114 | 2015-04-01 09:24:22 -0700 | [diff] [blame] | 33 | #include <sys/stat.h> |
| 34 | #include <sys/types.h> |
| 35 | |
Mark Salyzyn | 6865114 | 2015-04-01 09:24:22 -0700 | [diff] [blame] | 36 | #include <log/log.h> |
Mark Salyzyn | 8b2c7de | 2015-04-01 07:42:01 -0700 | [diff] [blame] | 37 | #include <private/android_filesystem_config.h> |
Mark Salyzyn | fd5b425 | 2015-04-16 08:13:32 -0700 | [diff] [blame] | 38 | #include <utils/Compat.h> |
Mark Salyzyn | 8b2c7de | 2015-04-01 07:42:01 -0700 | [diff] [blame] | 39 | |
Mark Salyzyn | 4232b37 | 2015-04-16 08:40:55 -0700 | [diff] [blame] | 40 | #ifndef O_BINARY |
| 41 | #define O_BINARY 0 |
| 42 | #endif |
| 43 | |
Mark Salyzyn | 6865114 | 2015-04-01 09:24:22 -0700 | [diff] [blame] | 44 | /* The following structure is stored little endian */ |
| 45 | struct fs_path_config_from_file { |
| 46 | uint16_t len; |
| 47 | uint16_t mode; |
| 48 | uint16_t uid; |
| 49 | uint16_t gid; |
| 50 | uint64_t capabilities; |
| 51 | char prefix[]; |
| 52 | } __attribute__((__aligned__(sizeof(uint64_t)))); |
| 53 | |
| 54 | /* My kingdom for <endian.h> */ |
| 55 | static inline uint16_t get2LE(const uint8_t* src) |
| 56 | { |
| 57 | return src[0] | (src[1] << 8); |
| 58 | } |
| 59 | |
| 60 | static inline uint64_t get8LE(const uint8_t* src) |
| 61 | { |
| 62 | uint32_t low, high; |
| 63 | |
| 64 | low = src[0] | (src[1] << 8) | (src[2] << 16) | (src[3] << 24); |
| 65 | high = src[4] | (src[5] << 8) | (src[6] << 16) | (src[7] << 24); |
| 66 | return ((uint64_t) high << 32) | (uint64_t) low; |
| 67 | } |
| 68 | |
Mark Salyzyn | 5d9e5ef | 2015-04-01 11:02:00 -0700 | [diff] [blame] | 69 | #define ALIGN(x, alignment) ( ((x) + ((alignment) - 1)) & ~((alignment) - 1) ) |
| 70 | |
Mark Salyzyn | 8b2c7de | 2015-04-01 07:42:01 -0700 | [diff] [blame] | 71 | /* Rules for directories. |
| 72 | ** These rules are applied based on "first match", so they |
| 73 | ** should start with the most specific path and work their |
| 74 | ** way up to the root. |
| 75 | */ |
| 76 | |
| 77 | static const struct fs_path_config android_dirs[] = { |
| 78 | { 00770, AID_SYSTEM, AID_CACHE, 0, "cache" }, |
Daniel Rosenberg | bbe796d | 2015-06-12 15:00:54 -0700 | [diff] [blame] | 79 | { 00500, AID_ROOT, AID_ROOT, 0, "config" }, |
Mark Salyzyn | 8b2c7de | 2015-04-01 07:42:01 -0700 | [diff] [blame] | 80 | { 00771, AID_SYSTEM, AID_SYSTEM, 0, "data/app" }, |
| 81 | { 00771, AID_SYSTEM, AID_SYSTEM, 0, "data/app-private" }, |
Todd Kennedy | 0a27335 | 2015-11-23 15:24:13 -0800 | [diff] [blame] | 82 | { 00771, AID_SYSTEM, AID_SYSTEM, 0, "data/app-ephemeral" }, |
Mark Salyzyn | 8b2c7de | 2015-04-01 07:42:01 -0700 | [diff] [blame] | 83 | { 00771, AID_ROOT, AID_ROOT, 0, "data/dalvik-cache" }, |
| 84 | { 00771, AID_SYSTEM, AID_SYSTEM, 0, "data/data" }, |
| 85 | { 00771, AID_SHELL, AID_SHELL, 0, "data/local/tmp" }, |
| 86 | { 00771, AID_SHELL, AID_SHELL, 0, "data/local" }, |
| 87 | { 01771, AID_SYSTEM, AID_MISC, 0, "data/misc" }, |
| 88 | { 00770, AID_DHCP, AID_DHCP, 0, "data/misc/dhcp" }, |
| 89 | { 00771, AID_SHARED_RELRO, AID_SHARED_RELRO, 0, "data/misc/shared_relro" }, |
| 90 | { 00775, AID_MEDIA_RW, AID_MEDIA_RW, 0, "data/media" }, |
| 91 | { 00775, AID_MEDIA_RW, AID_MEDIA_RW, 0, "data/media/Music" }, |
Gilad Arnold | 47af47f | 2015-11-12 14:34:57 -0800 | [diff] [blame] | 92 | { 00750, AID_ROOT, AID_SHELL, 0, "data/nativetest" }, |
| 93 | { 00750, AID_ROOT, AID_SHELL, 0, "data/nativetest64" }, |
Mark Salyzyn | 8b2c7de | 2015-04-01 07:42:01 -0700 | [diff] [blame] | 94 | { 00771, AID_SYSTEM, AID_SYSTEM, 0, "data" }, |
Daniel Rosenberg | bbe796d | 2015-06-12 15:00:54 -0700 | [diff] [blame] | 95 | { 00755, AID_ROOT, AID_SYSTEM, 0, "mnt" }, |
| 96 | { 00755, AID_ROOT, AID_ROOT, 0, "root" }, |
Mark Salyzyn | 8b2c7de | 2015-04-01 07:42:01 -0700 | [diff] [blame] | 97 | { 00750, AID_ROOT, AID_SHELL, 0, "sbin" }, |
Daniel Rosenberg | bbe796d | 2015-06-12 15:00:54 -0700 | [diff] [blame] | 98 | { 00751, AID_ROOT, AID_SDCARD_R, 0, "storage" }, |
Mark Salyzyn | 8b2c7de | 2015-04-01 07:42:01 -0700 | [diff] [blame] | 99 | { 00755, AID_ROOT, AID_SHELL, 0, "system/bin" }, |
| 100 | { 00755, AID_ROOT, AID_SHELL, 0, "system/vendor" }, |
| 101 | { 00755, AID_ROOT, AID_SHELL, 0, "system/xbin" }, |
| 102 | { 00755, AID_ROOT, AID_ROOT, 0, "system/etc/ppp" }, |
| 103 | { 00755, AID_ROOT, AID_SHELL, 0, "vendor" }, |
| 104 | { 00777, AID_ROOT, AID_ROOT, 0, "sdcard" }, |
| 105 | { 00755, AID_ROOT, AID_ROOT, 0, 0 }, |
| 106 | }; |
| 107 | |
| 108 | /* Rules for files. |
| 109 | ** These rules are applied based on "first match", so they |
| 110 | ** should start with the most specific path and work their |
| 111 | ** way up to the root. Prefixes ending in * denotes wildcard |
| 112 | ** and will allow partial matches. |
| 113 | */ |
Mark Salyzyn | 6865114 | 2015-04-01 09:24:22 -0700 | [diff] [blame] | 114 | static const char conf_dir[] = "/system/etc/fs_config_dirs"; |
| 115 | static const char conf_file[] = "/system/etc/fs_config_files"; |
| 116 | |
Mark Salyzyn | 8b2c7de | 2015-04-01 07:42:01 -0700 | [diff] [blame] | 117 | static const struct fs_path_config android_files[] = { |
| 118 | { 00440, AID_ROOT, AID_SHELL, 0, "system/etc/init.goldfish.rc" }, |
| 119 | { 00550, AID_ROOT, AID_SHELL, 0, "system/etc/init.goldfish.sh" }, |
| 120 | { 00550, AID_ROOT, AID_SHELL, 0, "system/etc/init.ril" }, |
Mark Salyzyn | 8b2c7de | 2015-04-01 07:42:01 -0700 | [diff] [blame] | 121 | { 00555, AID_ROOT, AID_ROOT, 0, "system/etc/ppp/*" }, |
| 122 | { 00555, AID_ROOT, AID_ROOT, 0, "system/etc/rc.*" }, |
Tao Bao | c6e93fe | 2015-07-18 19:46:16 -0700 | [diff] [blame] | 123 | { 00440, AID_ROOT, AID_ROOT, 0, "system/etc/recovery.img" }, |
Mark Salyzyn | 6865114 | 2015-04-01 09:24:22 -0700 | [diff] [blame] | 124 | { 00444, AID_ROOT, AID_ROOT, 0, conf_dir + 1 }, |
| 125 | { 00444, AID_ROOT, AID_ROOT, 0, conf_file + 1 }, |
Mark Salyzyn | 8b2c7de | 2015-04-01 07:42:01 -0700 | [diff] [blame] | 126 | { 00644, AID_SYSTEM, AID_SYSTEM, 0, "data/app/*" }, |
| 127 | { 00644, AID_MEDIA_RW, AID_MEDIA_RW, 0, "data/media/*" }, |
| 128 | { 00644, AID_SYSTEM, AID_SYSTEM, 0, "data/app-private/*" }, |
Todd Kennedy | 0a27335 | 2015-11-23 15:24:13 -0800 | [diff] [blame] | 129 | { 00644, AID_SYSTEM, AID_SYSTEM, 0, "data/app-ephemeral/*" }, |
Mark Salyzyn | 8b2c7de | 2015-04-01 07:42:01 -0700 | [diff] [blame] | 130 | { 00644, AID_APP, AID_APP, 0, "data/data/*" }, |
Gilad Arnold | 1bc7888 | 2015-11-14 18:25:31 -0800 | [diff] [blame] | 131 | { 00640, AID_ROOT, AID_SHELL, 0, "data/nativetest/tests.txt" }, |
| 132 | { 00640, AID_ROOT, AID_SHELL, 0, "data/nativetest64/tests.txt" }, |
Daniel Erat | 5510c13 | 2015-10-28 16:52:37 -0600 | [diff] [blame] | 133 | { 00750, AID_ROOT, AID_SHELL, 0, "data/nativetest/*" }, |
| 134 | { 00750, AID_ROOT, AID_SHELL, 0, "data/nativetest64/*" }, |
Mark Salyzyn | 8b2c7de | 2015-04-01 07:42:01 -0700 | [diff] [blame] | 135 | |
Nick Kralevich | cbbc661 | 2015-11-30 09:17:18 -0800 | [diff] [blame] | 136 | /* the following two files are INTENTIONALLY set-uid, but they |
Mark Salyzyn | 8b2c7de | 2015-04-01 07:42:01 -0700 | [diff] [blame] | 137 | * are NOT included on user builds. */ |
| 138 | { 04750, AID_ROOT, AID_SHELL, 0, "system/xbin/su" }, |
Mark Salyzyn | 8b2c7de | 2015-04-01 07:42:01 -0700 | [diff] [blame] | 139 | { 06755, AID_ROOT, AID_ROOT, 0, "system/xbin/procmem" }, |
Mark Salyzyn | 8b2c7de | 2015-04-01 07:42:01 -0700 | [diff] [blame] | 140 | |
| 141 | /* the following files have enhanced capabilities and ARE included in user builds. */ |
Jorge Lucangeli Obes | e920c46 | 2015-09-02 16:19:59 -0700 | [diff] [blame] | 142 | { 00750, AID_ROOT, AID_SHELL, CAP_MASK_LONG(CAP_SETUID) | CAP_MASK_LONG(CAP_SETGID), "system/bin/run-as" }, |
| 143 | { 00700, AID_SYSTEM, AID_SHELL, CAP_MASK_LONG(CAP_BLOCK_SUSPEND), "system/bin/inputflinger" }, |
Mark Salyzyn | 8b2c7de | 2015-04-01 07:42:01 -0700 | [diff] [blame] | 144 | |
Tim Murray | 3a29e34 | 2016-06-17 14:02:16 -0700 | [diff] [blame] | 145 | /* Support FIFO scheduling mode in SurfaceFlinger. */ |
| 146 | { 00755, AID_SYSTEM, AID_GRAPHICS, CAP_MASK_LONG(CAP_SYS_NICE), "system/bin/surfaceflinger" }, |
| 147 | |
Mark Salyzyn | 8b2c7de | 2015-04-01 07:42:01 -0700 | [diff] [blame] | 148 | { 00750, AID_ROOT, AID_ROOT, 0, "system/bin/uncrypt" }, |
| 149 | { 00750, AID_ROOT, AID_ROOT, 0, "system/bin/install-recovery.sh" }, |
| 150 | { 00755, AID_ROOT, AID_SHELL, 0, "system/bin/*" }, |
| 151 | { 00755, AID_ROOT, AID_ROOT, 0, "system/lib/valgrind/*" }, |
| 152 | { 00755, AID_ROOT, AID_ROOT, 0, "system/lib64/valgrind/*" }, |
| 153 | { 00755, AID_ROOT, AID_SHELL, 0, "system/xbin/*" }, |
| 154 | { 00755, AID_ROOT, AID_SHELL, 0, "system/vendor/bin/*" }, |
Erik Kline | a5a9c74 | 2016-05-27 13:13:07 +0900 | [diff] [blame] | 155 | { 00755, AID_ROOT, AID_SHELL, 0, "system/vendor/xbin/*" }, |
Mark Salyzyn | 8b2c7de | 2015-04-01 07:42:01 -0700 | [diff] [blame] | 156 | { 00755, AID_ROOT, AID_SHELL, 0, "vendor/bin/*" }, |
Erik Kline | a5a9c74 | 2016-05-27 13:13:07 +0900 | [diff] [blame] | 157 | { 00755, AID_ROOT, AID_SHELL, 0, "vendor/xbin/*" }, |
Mark Salyzyn | 8b2c7de | 2015-04-01 07:42:01 -0700 | [diff] [blame] | 158 | { 00750, AID_ROOT, AID_SHELL, 0, "sbin/*" }, |
| 159 | { 00755, AID_ROOT, AID_ROOT, 0, "bin/*" }, |
| 160 | { 00750, AID_ROOT, AID_SHELL, 0, "init*" }, |
| 161 | { 00750, AID_ROOT, AID_SHELL, 0, "sbin/fs_mgr" }, |
| 162 | { 00640, AID_ROOT, AID_SHELL, 0, "fstab.*" }, |
| 163 | { 00644, AID_ROOT, AID_ROOT, 0, 0 }, |
| 164 | }; |
| 165 | |
Thierry Strudel | df33ffa | 2015-07-09 09:50:31 -0700 | [diff] [blame] | 166 | static int fs_config_open(int dir, const char *target_out_path) |
Mark Salyzyn | 6865114 | 2015-04-01 09:24:22 -0700 | [diff] [blame] | 167 | { |
| 168 | int fd = -1; |
| 169 | |
Thierry Strudel | df33ffa | 2015-07-09 09:50:31 -0700 | [diff] [blame] | 170 | if (target_out_path && *target_out_path) { |
| 171 | /* target_out_path is the path to the directory holding content of system partition |
| 172 | but as we cannot guaranty it ends with '/system' we need this below skip_len logic */ |
Mark Salyzyn | 6865114 | 2015-04-01 09:24:22 -0700 | [diff] [blame] | 173 | char *name = NULL; |
Thierry Strudel | df33ffa | 2015-07-09 09:50:31 -0700 | [diff] [blame] | 174 | int target_out_path_len = strlen(target_out_path); |
| 175 | int skip_len = strlen("/system"); |
| 176 | |
| 177 | if (target_out_path[target_out_path_len] == '/') { |
| 178 | skip_len++; |
| 179 | } |
Elliott Hughes | 8b262b9 | 2015-07-24 20:02:31 -0700 | [diff] [blame] | 180 | if (asprintf(&name, "%s%s", target_out_path, (dir ? conf_dir : conf_file) + skip_len) != -1) { |
Mark Salyzyn | 4232b37 | 2015-04-16 08:40:55 -0700 | [diff] [blame] | 181 | fd = TEMP_FAILURE_RETRY(open(name, O_RDONLY | O_BINARY)); |
Mark Salyzyn | 6865114 | 2015-04-01 09:24:22 -0700 | [diff] [blame] | 182 | free(name); |
| 183 | } |
| 184 | } |
| 185 | if (fd < 0) { |
Mark Salyzyn | 4232b37 | 2015-04-16 08:40:55 -0700 | [diff] [blame] | 186 | fd = TEMP_FAILURE_RETRY(open(dir ? conf_dir : conf_file, O_RDONLY | O_BINARY)); |
Mark Salyzyn | 6865114 | 2015-04-01 09:24:22 -0700 | [diff] [blame] | 187 | } |
| 188 | return fd; |
| 189 | } |
| 190 | |
| 191 | static bool fs_config_cmp(bool dir, const char *prefix, size_t len, |
| 192 | const char *path, size_t plen) |
| 193 | { |
| 194 | if (dir) { |
| 195 | if (plen < len) { |
| 196 | return false; |
| 197 | } |
| 198 | } else { |
| 199 | /* If name ends in * then allow partial matches. */ |
| 200 | if (prefix[len - 1] == '*') { |
| 201 | return !strncmp(prefix, path, len - 1); |
| 202 | } |
| 203 | if (plen != len) { |
| 204 | return false; |
| 205 | } |
| 206 | } |
| 207 | return !strncmp(prefix, path, len); |
| 208 | } |
| 209 | |
Thierry Strudel | df33ffa | 2015-07-09 09:50:31 -0700 | [diff] [blame] | 210 | void fs_config(const char *path, int dir, const char *target_out_path, |
Mark Salyzyn | 8b2c7de | 2015-04-01 07:42:01 -0700 | [diff] [blame] | 211 | unsigned *uid, unsigned *gid, unsigned *mode, uint64_t *capabilities) |
| 212 | { |
| 213 | const struct fs_path_config *pc; |
Mark Salyzyn | 7977cc6 | 2015-04-15 19:27:39 -0700 | [diff] [blame] | 214 | int fd, plen; |
Mark Salyzyn | 8b2c7de | 2015-04-01 07:42:01 -0700 | [diff] [blame] | 215 | |
| 216 | if (path[0] == '/') { |
| 217 | path++; |
| 218 | } |
| 219 | |
Mark Salyzyn | 7e82633 | 2015-04-15 22:30:30 +0000 | [diff] [blame] | 220 | plen = strlen(path); |
Mark Salyzyn | 6865114 | 2015-04-01 09:24:22 -0700 | [diff] [blame] | 221 | |
Thierry Strudel | df33ffa | 2015-07-09 09:50:31 -0700 | [diff] [blame] | 222 | fd = fs_config_open(dir, target_out_path); |
Mark Salyzyn | 7977cc6 | 2015-04-15 19:27:39 -0700 | [diff] [blame] | 223 | if (fd >= 0) { |
| 224 | struct fs_path_config_from_file header; |
| 225 | |
| 226 | while (TEMP_FAILURE_RETRY(read(fd, &header, sizeof(header))) == sizeof(header)) { |
| 227 | char *prefix; |
| 228 | uint16_t host_len = get2LE((const uint8_t *)&header.len); |
| 229 | ssize_t len, remainder = host_len - sizeof(header); |
Mark Salyzyn | 6865114 | 2015-04-01 09:24:22 -0700 | [diff] [blame] | 230 | if (remainder <= 0) { |
Mark Salyzyn | 7977cc6 | 2015-04-15 19:27:39 -0700 | [diff] [blame] | 231 | ALOGE("%s len is corrupted", dir ? conf_dir : conf_file); |
Mark Salyzyn | 6865114 | 2015-04-01 09:24:22 -0700 | [diff] [blame] | 232 | break; |
| 233 | } |
Mark Salyzyn | 7977cc6 | 2015-04-15 19:27:39 -0700 | [diff] [blame] | 234 | prefix = calloc(1, remainder); |
| 235 | if (!prefix) { |
| 236 | ALOGE("%s out of memory", dir ? conf_dir : conf_file); |
| 237 | break; |
Mark Salyzyn | 6865114 | 2015-04-01 09:24:22 -0700 | [diff] [blame] | 238 | } |
Mark Salyzyn | 7977cc6 | 2015-04-15 19:27:39 -0700 | [diff] [blame] | 239 | if (TEMP_FAILURE_RETRY(read(fd, prefix, remainder)) != remainder) { |
| 240 | free(prefix); |
| 241 | ALOGE("%s prefix is truncated", dir ? conf_dir : conf_file); |
| 242 | break; |
| 243 | } |
| 244 | len = strnlen(prefix, remainder); |
Mark Salyzyn | 6865114 | 2015-04-01 09:24:22 -0700 | [diff] [blame] | 245 | if (len >= remainder) { /* missing a terminating null */ |
Mark Salyzyn | 7977cc6 | 2015-04-15 19:27:39 -0700 | [diff] [blame] | 246 | free(prefix); |
Mark Salyzyn | 6865114 | 2015-04-01 09:24:22 -0700 | [diff] [blame] | 247 | ALOGE("%s is corrupted", dir ? conf_dir : conf_file); |
Mark Salyzyn | 6865114 | 2015-04-01 09:24:22 -0700 | [diff] [blame] | 248 | break; |
| 249 | } |
Mark Salyzyn | 7977cc6 | 2015-04-15 19:27:39 -0700 | [diff] [blame] | 250 | if (fs_config_cmp(dir, prefix, len, path, plen)) { |
| 251 | free(prefix); |
| 252 | close(fd); |
| 253 | *uid = get2LE((const uint8_t *)&(header.uid)); |
| 254 | *gid = get2LE((const uint8_t *)&(header.gid)); |
| 255 | *mode = (*mode & (~07777)) | get2LE((const uint8_t *)&(header.mode)); |
| 256 | *capabilities = get8LE((const uint8_t *)&(header.capabilities)); |
| 257 | return; |
Mark Salyzyn | 6865114 | 2015-04-01 09:24:22 -0700 | [diff] [blame] | 258 | } |
Mark Salyzyn | 7977cc6 | 2015-04-15 19:27:39 -0700 | [diff] [blame] | 259 | free(prefix); |
Mark Salyzyn | 7e82633 | 2015-04-15 22:30:30 +0000 | [diff] [blame] | 260 | } |
Mark Salyzyn | 6865114 | 2015-04-01 09:24:22 -0700 | [diff] [blame] | 261 | close(fd); |
Mark Salyzyn | 6865114 | 2015-04-01 09:24:22 -0700 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | pc = dir ? android_dirs : android_files; |
| 265 | for(; pc->prefix; pc++){ |
| 266 | if (fs_config_cmp(dir, pc->prefix, strlen(pc->prefix), path, plen)) { |
| 267 | break; |
Mark Salyzyn | 8b2c7de | 2015-04-01 07:42:01 -0700 | [diff] [blame] | 268 | } |
| 269 | } |
| 270 | *uid = pc->uid; |
| 271 | *gid = pc->gid; |
| 272 | *mode = (*mode & (~07777)) | pc->mode; |
| 273 | *capabilities = pc->capabilities; |
| 274 | } |
Mark Salyzyn | 5d9e5ef | 2015-04-01 11:02:00 -0700 | [diff] [blame] | 275 | |
| 276 | ssize_t fs_config_generate(char *buffer, size_t length, const struct fs_path_config *pc) |
| 277 | { |
| 278 | struct fs_path_config_from_file *p = (struct fs_path_config_from_file *)buffer; |
| 279 | size_t len = ALIGN(sizeof(*p) + strlen(pc->prefix) + 1, sizeof(uint64_t)); |
| 280 | |
| 281 | if ((length < len) || (len > UINT16_MAX)) { |
| 282 | return -ENOSPC; |
| 283 | } |
| 284 | memset(p, 0, len); |
| 285 | uint16_t host_len = len; |
| 286 | p->len = get2LE((const uint8_t *)&host_len); |
| 287 | p->mode = get2LE((const uint8_t *)&(pc->mode)); |
| 288 | p->uid = get2LE((const uint8_t *)&(pc->uid)); |
| 289 | p->gid = get2LE((const uint8_t *)&(pc->gid)); |
| 290 | p->capabilities = get8LE((const uint8_t *)&(pc->capabilities)); |
| 291 | strcpy(p->prefix, pc->prefix); |
| 292 | return len; |
| 293 | } |