The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1 | /* |
Mark Salyzyn | 154f460 | 2014-02-20 14:59:07 -0800 | [diff] [blame] | 2 | * Copyright (C) 2007-2014 The Android Open Source Project |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 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 | #include <errno.h> |
Daniel Leung | c0c1ffe | 2012-07-02 11:32:30 -0700 | [diff] [blame] | 18 | #include <fnmatch.h> |
Olivier Bailly | b93e581 | 2010-11-17 11:47:23 -0800 | [diff] [blame] | 19 | #include <stddef.h> |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 20 | #include <stdio.h> |
| 21 | #include <stdlib.h> |
| 22 | #include <sys/stat.h> |
| 23 | #include <sys/types.h> |
| 24 | |
| 25 | #include <fcntl.h> |
| 26 | #include <dirent.h> |
| 27 | #include <unistd.h> |
| 28 | #include <string.h> |
| 29 | |
| 30 | #include <sys/socket.h> |
| 31 | #include <sys/un.h> |
| 32 | #include <linux/netlink.h> |
Stephen Smalley | e46f9d5 | 2012-01-13 08:48:47 -0500 | [diff] [blame] | 33 | |
James Hawkins | 588a2ca | 2016-02-18 14:52:46 -0800 | [diff] [blame] | 34 | #include <memory> |
| 35 | |
Stephen Smalley | e46f9d5 | 2012-01-13 08:48:47 -0500 | [diff] [blame] | 36 | #include <selinux/selinux.h> |
| 37 | #include <selinux/label.h> |
Stephen Smalley | ae6f3d7 | 2012-05-01 15:02:53 -0400 | [diff] [blame] | 38 | #include <selinux/android.h> |
Stephen Smalley | e2eb69d | 2013-04-16 09:30:30 -0400 | [diff] [blame] | 39 | #include <selinux/avc.h> |
Stephen Smalley | e46f9d5 | 2012-01-13 08:48:47 -0500 | [diff] [blame] | 40 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 41 | #include <private/android_filesystem_config.h> |
| 42 | #include <sys/time.h> |
Colin Cross | 982a815 | 2010-06-03 12:21:01 -0700 | [diff] [blame] | 43 | #include <sys/wait.h> |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 44 | |
Biao Lu | dc84856 | 2016-01-28 16:10:54 +0800 | [diff] [blame] | 45 | #include <android-base/file.h> |
Dima Zavin | da04c52 | 2011-09-01 17:09:44 -0700 | [diff] [blame] | 46 | #include <cutils/list.h> |
Vernon Tang | 3f582e9 | 2011-04-25 13:08:17 +1000 | [diff] [blame] | 47 | #include <cutils/uevent.h> |
| 48 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 49 | #include "devices.h" |
Greg Hackmann | 3312aa8 | 2013-11-18 15:24:40 -0800 | [diff] [blame] | 50 | #include "ueventd_parser.h" |
Colin Cross | b0ab94b | 2010-04-08 16:16:20 -0700 | [diff] [blame] | 51 | #include "util.h" |
Colin Cross | ed8a7d8 | 2010-04-19 17:05:34 -0700 | [diff] [blame] | 52 | #include "log.h" |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 53 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 54 | #define SYSFS_PREFIX "/sys" |
Daniel Rosenberg | d1d9602 | 2015-03-20 15:10:29 -0700 | [diff] [blame] | 55 | static const char *firmware_dirs[] = { "/etc/firmware", |
| 56 | "/vendor/firmware", |
| 57 | "/firmware/image" }; |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 58 | |
Stephen Smalley | e096e36 | 2012-06-11 13:37:39 -0400 | [diff] [blame] | 59 | extern struct selabel_handle *sehandle; |
Stephen Smalley | e46f9d5 | 2012-01-13 08:48:47 -0500 | [diff] [blame] | 60 | |
Colin Cross | 0dd7ca6 | 2010-04-13 19:25:51 -0700 | [diff] [blame] | 61 | static int device_fd = -1; |
| 62 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 63 | struct uevent { |
| 64 | const char *action; |
| 65 | const char *path; |
| 66 | const char *subsystem; |
| 67 | const char *firmware; |
Colin Cross | b0ab94b | 2010-04-08 16:16:20 -0700 | [diff] [blame] | 68 | const char *partition_name; |
Wei Zhong | f97b887 | 2012-03-23 14:15:34 -0700 | [diff] [blame] | 69 | const char *device_name; |
Colin Cross | b0ab94b | 2010-04-08 16:16:20 -0700 | [diff] [blame] | 70 | int partition_num; |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 71 | int major; |
| 72 | int minor; |
| 73 | }; |
| 74 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 75 | struct perms_ { |
| 76 | char *name; |
Brian Swetland | bc57d4c | 2010-10-26 15:09:43 -0700 | [diff] [blame] | 77 | char *attr; |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 78 | mode_t perm; |
| 79 | unsigned int uid; |
| 80 | unsigned int gid; |
| 81 | unsigned short prefix; |
Daniel Leung | c0c1ffe | 2012-07-02 11:32:30 -0700 | [diff] [blame] | 82 | unsigned short wildcard; |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 83 | }; |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 84 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 85 | struct perm_node { |
| 86 | struct perms_ dp; |
| 87 | struct listnode plist; |
| 88 | }; |
Brian Swetland | bc57d4c | 2010-10-26 15:09:43 -0700 | [diff] [blame] | 89 | |
Colin Cross | fadb85e | 2011-03-30 18:32:12 -0700 | [diff] [blame] | 90 | struct platform_node { |
| 91 | char *name; |
Dima Zavin | f395c92 | 2013-03-06 16:23:57 -0800 | [diff] [blame] | 92 | char *path; |
| 93 | int path_len; |
Colin Cross | fadb85e | 2011-03-30 18:32:12 -0700 | [diff] [blame] | 94 | struct listnode list; |
| 95 | }; |
| 96 | |
Brian Swetland | bc57d4c | 2010-10-26 15:09:43 -0700 | [diff] [blame] | 97 | static list_declare(sys_perms); |
Colin Cross | 44b65d0 | 2010-04-20 14:32:50 -0700 | [diff] [blame] | 98 | static list_declare(dev_perms); |
Colin Cross | fadb85e | 2011-03-30 18:32:12 -0700 | [diff] [blame] | 99 | static list_declare(platform_names); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 100 | |
Brian Swetland | bc57d4c | 2010-10-26 15:09:43 -0700 | [diff] [blame] | 101 | int add_dev_perms(const char *name, const char *attr, |
| 102 | mode_t perm, unsigned int uid, unsigned int gid, |
Daniel Leung | c0c1ffe | 2012-07-02 11:32:30 -0700 | [diff] [blame] | 103 | unsigned short prefix, |
| 104 | unsigned short wildcard) { |
Elliott Hughes | f3cf438 | 2015-02-03 17:12:07 -0800 | [diff] [blame] | 105 | struct perm_node *node = (perm_node*) calloc(1, sizeof(*node)); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 106 | if (!node) |
| 107 | return -ENOMEM; |
| 108 | |
Brian Swetland | bc57d4c | 2010-10-26 15:09:43 -0700 | [diff] [blame] | 109 | node->dp.name = strdup(name); |
| 110 | if (!node->dp.name) |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 111 | return -ENOMEM; |
| 112 | |
Brian Swetland | bc57d4c | 2010-10-26 15:09:43 -0700 | [diff] [blame] | 113 | if (attr) { |
| 114 | node->dp.attr = strdup(attr); |
| 115 | if (!node->dp.attr) |
| 116 | return -ENOMEM; |
| 117 | } |
| 118 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 119 | node->dp.perm = perm; |
| 120 | node->dp.uid = uid; |
| 121 | node->dp.gid = gid; |
| 122 | node->dp.prefix = prefix; |
Daniel Leung | c0c1ffe | 2012-07-02 11:32:30 -0700 | [diff] [blame] | 123 | node->dp.wildcard = wildcard; |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 124 | |
Brian Swetland | bc57d4c | 2010-10-26 15:09:43 -0700 | [diff] [blame] | 125 | if (attr) |
| 126 | list_add_tail(&sys_perms, &node->plist); |
| 127 | else |
| 128 | list_add_tail(&dev_perms, &node->plist); |
| 129 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 130 | return 0; |
| 131 | } |
| 132 | |
Brian Swetland | bc57d4c | 2010-10-26 15:09:43 -0700 | [diff] [blame] | 133 | void fixup_sys_perms(const char *upath) |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 134 | { |
Brian Swetland | bc57d4c | 2010-10-26 15:09:43 -0700 | [diff] [blame] | 135 | char buf[512]; |
| 136 | struct listnode *node; |
| 137 | struct perms_ *dp; |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 138 | |
Nick Kralevich | 3b4c0bd | 2014-07-03 16:04:34 -0700 | [diff] [blame] | 139 | /* upaths omit the "/sys" that paths in this list |
| 140 | * contain, so we add 4 when comparing... |
| 141 | */ |
Brian Swetland | bc57d4c | 2010-10-26 15:09:43 -0700 | [diff] [blame] | 142 | list_for_each(node, &sys_perms) { |
| 143 | dp = &(node_to_item(node, struct perm_node, plist))->dp; |
| 144 | if (dp->prefix) { |
| 145 | if (strncmp(upath, dp->name + 4, strlen(dp->name + 4))) |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 146 | continue; |
Daniel Leung | c0c1ffe | 2012-07-02 11:32:30 -0700 | [diff] [blame] | 147 | } else if (dp->wildcard) { |
| 148 | if (fnmatch(dp->name + 4, upath, FNM_PATHNAME) != 0) |
| 149 | continue; |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 150 | } else { |
Brian Swetland | bc57d4c | 2010-10-26 15:09:43 -0700 | [diff] [blame] | 151 | if (strcmp(upath, dp->name + 4)) |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 152 | continue; |
| 153 | } |
Brian Swetland | bc57d4c | 2010-10-26 15:09:43 -0700 | [diff] [blame] | 154 | |
| 155 | if ((strlen(upath) + strlen(dp->attr) + 6) > sizeof(buf)) |
Nick Kralevich | 3b4c0bd | 2014-07-03 16:04:34 -0700 | [diff] [blame] | 156 | break; |
Brian Swetland | bc57d4c | 2010-10-26 15:09:43 -0700 | [diff] [blame] | 157 | |
Yabin Cui | e2d63af | 2015-02-17 19:27:51 -0800 | [diff] [blame] | 158 | snprintf(buf, sizeof(buf), "/sys%s/%s", upath, dp->attr); |
Brian Swetland | bc57d4c | 2010-10-26 15:09:43 -0700 | [diff] [blame] | 159 | INFO("fixup %s %d %d 0%o\n", buf, dp->uid, dp->gid, dp->perm); |
| 160 | chown(buf, dp->uid, dp->gid); |
| 161 | chmod(buf, dp->perm); |
Nick Kralevich | 3b4c0bd | 2014-07-03 16:04:34 -0700 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | // Now fixup SELinux file labels |
| 165 | int len = snprintf(buf, sizeof(buf), "/sys%s", upath); |
| 166 | if ((len < 0) || ((size_t) len >= sizeof(buf))) { |
| 167 | // Overflow |
| 168 | return; |
| 169 | } |
| 170 | if (access(buf, F_OK) == 0) { |
| 171 | INFO("restorecon_recursive: %s\n", buf); |
| 172 | restorecon_recursive(buf); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 173 | } |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 174 | } |
| 175 | |
Colin Cross | 43d537e | 2014-07-02 13:08:13 -0700 | [diff] [blame] | 176 | static bool perm_path_matches(const char *path, struct perms_ *dp) |
| 177 | { |
| 178 | if (dp->prefix) { |
| 179 | if (strncmp(path, dp->name, strlen(dp->name)) == 0) |
| 180 | return true; |
| 181 | } else if (dp->wildcard) { |
| 182 | if (fnmatch(dp->name, path, FNM_PATHNAME) == 0) |
| 183 | return true; |
| 184 | } else { |
| 185 | if (strcmp(path, dp->name) == 0) |
| 186 | return true; |
| 187 | } |
| 188 | |
| 189 | return false; |
| 190 | } |
| 191 | |
| 192 | static mode_t get_device_perm(const char *path, const char **links, |
| 193 | unsigned *uid, unsigned *gid) |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 194 | { |
Colin Cross | 44b65d0 | 2010-04-20 14:32:50 -0700 | [diff] [blame] | 195 | struct listnode *node; |
| 196 | struct perm_node *perm_node; |
| 197 | struct perms_ *dp; |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 198 | |
Colin Cross | 44b65d0 | 2010-04-20 14:32:50 -0700 | [diff] [blame] | 199 | /* search the perms list in reverse so that ueventd.$hardware can |
| 200 | * override ueventd.rc |
| 201 | */ |
| 202 | list_for_each_reverse(node, &dev_perms) { |
Colin Cross | 43d537e | 2014-07-02 13:08:13 -0700 | [diff] [blame] | 203 | bool match = false; |
| 204 | |
Colin Cross | 44b65d0 | 2010-04-20 14:32:50 -0700 | [diff] [blame] | 205 | perm_node = node_to_item(node, struct perm_node, plist); |
| 206 | dp = &perm_node->dp; |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 207 | |
Colin Cross | 43d537e | 2014-07-02 13:08:13 -0700 | [diff] [blame] | 208 | if (perm_path_matches(path, dp)) { |
| 209 | match = true; |
Colin Cross | 44b65d0 | 2010-04-20 14:32:50 -0700 | [diff] [blame] | 210 | } else { |
Colin Cross | 43d537e | 2014-07-02 13:08:13 -0700 | [diff] [blame] | 211 | if (links) { |
| 212 | int i; |
| 213 | for (i = 0; links[i]; i++) { |
| 214 | if (perm_path_matches(links[i], dp)) { |
| 215 | match = true; |
| 216 | break; |
| 217 | } |
| 218 | } |
| 219 | } |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 220 | } |
Colin Cross | 43d537e | 2014-07-02 13:08:13 -0700 | [diff] [blame] | 221 | |
| 222 | if (match) { |
| 223 | *uid = dp->uid; |
| 224 | *gid = dp->gid; |
| 225 | return dp->perm; |
| 226 | } |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 227 | } |
Colin Cross | 44b65d0 | 2010-04-20 14:32:50 -0700 | [diff] [blame] | 228 | /* Default if nothing found. */ |
| 229 | *uid = 0; |
| 230 | *gid = 0; |
| 231 | return 0600; |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 232 | } |
| 233 | |
Brian Swetland | bc57d4c | 2010-10-26 15:09:43 -0700 | [diff] [blame] | 234 | static void make_device(const char *path, |
Elliott Hughes | f682b47 | 2015-02-06 12:19:48 -0800 | [diff] [blame] | 235 | const char */*upath*/, |
Stephen Smalley | b4c5200 | 2014-06-12 12:29:14 -0400 | [diff] [blame] | 236 | int block, int major, int minor, |
| 237 | const char **links) |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 238 | { |
| 239 | unsigned uid; |
| 240 | unsigned gid; |
| 241 | mode_t mode; |
| 242 | dev_t dev; |
Stephen Smalley | e46f9d5 | 2012-01-13 08:48:47 -0500 | [diff] [blame] | 243 | char *secontext = NULL; |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 244 | |
Colin Cross | 43d537e | 2014-07-02 13:08:13 -0700 | [diff] [blame] | 245 | mode = get_device_perm(path, links, &uid, &gid) | (block ? S_IFBLK : S_IFCHR); |
Kenny Root | b5982bf | 2012-10-16 23:07:05 -0700 | [diff] [blame] | 246 | |
Nick Kralevich | 4d87095 | 2015-06-12 22:03:50 -0700 | [diff] [blame] | 247 | selabel_lookup_best_match(sehandle, &secontext, path, links, mode); |
| 248 | setfscreatecon(secontext); |
Kenny Root | b5982bf | 2012-10-16 23:07:05 -0700 | [diff] [blame] | 249 | |
Colin Cross | 17dcc5c | 2010-09-03 12:25:34 -0700 | [diff] [blame] | 250 | dev = makedev(major, minor); |
Nick Pelly | 6405c69 | 2010-01-21 18:13:39 -0800 | [diff] [blame] | 251 | /* Temporarily change egid to avoid race condition setting the gid of the |
| 252 | * device node. Unforunately changing the euid would prevent creation of |
| 253 | * some device nodes, so the uid has to be set with chown() and is still |
| 254 | * racy. Fixing the gid race at least fixed the issue with system_server |
| 255 | * opening dynamic input devices under the AID_INPUT gid. */ |
| 256 | setegid(gid); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 257 | mknod(path, mode, dev); |
Nick Pelly | 6405c69 | 2010-01-21 18:13:39 -0800 | [diff] [blame] | 258 | chown(path, uid, -1); |
| 259 | setegid(AID_ROOT); |
Kenny Root | b5982bf | 2012-10-16 23:07:05 -0700 | [diff] [blame] | 260 | |
Stephen Smalley | e46f9d5 | 2012-01-13 08:48:47 -0500 | [diff] [blame] | 261 | if (secontext) { |
| 262 | freecon(secontext); |
| 263 | setfscreatecon(NULL); |
| 264 | } |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 265 | } |
| 266 | |
Dima Zavin | f395c92 | 2013-03-06 16:23:57 -0800 | [diff] [blame] | 267 | static void add_platform_device(const char *path) |
Colin Cross | fadb85e | 2011-03-30 18:32:12 -0700 | [diff] [blame] | 268 | { |
Dima Zavin | f395c92 | 2013-03-06 16:23:57 -0800 | [diff] [blame] | 269 | int path_len = strlen(path); |
Colin Cross | fadb85e | 2011-03-30 18:32:12 -0700 | [diff] [blame] | 270 | struct platform_node *bus; |
Dima Zavin | f395c92 | 2013-03-06 16:23:57 -0800 | [diff] [blame] | 271 | const char *name = path; |
| 272 | |
| 273 | if (!strncmp(path, "/devices/", 9)) { |
| 274 | name += 9; |
| 275 | if (!strncmp(name, "platform/", 9)) |
| 276 | name += 9; |
| 277 | } |
Colin Cross | fadb85e | 2011-03-30 18:32:12 -0700 | [diff] [blame] | 278 | |
Dima Zavin | f395c92 | 2013-03-06 16:23:57 -0800 | [diff] [blame] | 279 | INFO("adding platform device %s (%s)\n", name, path); |
Colin Cross | fadb85e | 2011-03-30 18:32:12 -0700 | [diff] [blame] | 280 | |
Elliott Hughes | f3cf438 | 2015-02-03 17:12:07 -0800 | [diff] [blame] | 281 | bus = (platform_node*) calloc(1, sizeof(struct platform_node)); |
Dima Zavin | f395c92 | 2013-03-06 16:23:57 -0800 | [diff] [blame] | 282 | bus->path = strdup(path); |
| 283 | bus->path_len = path_len; |
| 284 | bus->name = bus->path + (name - path); |
Colin Cross | fadb85e | 2011-03-30 18:32:12 -0700 | [diff] [blame] | 285 | list_add_tail(&platform_names, &bus->list); |
| 286 | } |
| 287 | |
| 288 | /* |
Dima Zavin | f395c92 | 2013-03-06 16:23:57 -0800 | [diff] [blame] | 289 | * given a path that may start with a platform device, find the length of the |
Colin Cross | fadb85e | 2011-03-30 18:32:12 -0700 | [diff] [blame] | 290 | * platform device prefix. If it doesn't start with a platform device, return |
| 291 | * 0. |
| 292 | */ |
Dima Zavin | f395c92 | 2013-03-06 16:23:57 -0800 | [diff] [blame] | 293 | static struct platform_node *find_platform_device(const char *path) |
Colin Cross | fadb85e | 2011-03-30 18:32:12 -0700 | [diff] [blame] | 294 | { |
Dima Zavin | f395c92 | 2013-03-06 16:23:57 -0800 | [diff] [blame] | 295 | int path_len = strlen(path); |
Colin Cross | fadb85e | 2011-03-30 18:32:12 -0700 | [diff] [blame] | 296 | struct listnode *node; |
| 297 | struct platform_node *bus; |
| 298 | |
| 299 | list_for_each_reverse(node, &platform_names) { |
| 300 | bus = node_to_item(node, struct platform_node, list); |
Dima Zavin | f395c92 | 2013-03-06 16:23:57 -0800 | [diff] [blame] | 301 | if ((bus->path_len < path_len) && |
| 302 | (path[bus->path_len] == '/') && |
| 303 | !strncmp(path, bus->path, bus->path_len)) |
| 304 | return bus; |
Colin Cross | fadb85e | 2011-03-30 18:32:12 -0700 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | return NULL; |
| 308 | } |
| 309 | |
Dima Zavin | f395c92 | 2013-03-06 16:23:57 -0800 | [diff] [blame] | 310 | static void remove_platform_device(const char *path) |
Colin Cross | fadb85e | 2011-03-30 18:32:12 -0700 | [diff] [blame] | 311 | { |
| 312 | struct listnode *node; |
| 313 | struct platform_node *bus; |
| 314 | |
| 315 | list_for_each_reverse(node, &platform_names) { |
| 316 | bus = node_to_item(node, struct platform_node, list); |
Dima Zavin | f395c92 | 2013-03-06 16:23:57 -0800 | [diff] [blame] | 317 | if (!strcmp(path, bus->path)) { |
| 318 | INFO("removing platform device %s\n", bus->name); |
| 319 | free(bus->path); |
Colin Cross | fadb85e | 2011-03-30 18:32:12 -0700 | [diff] [blame] | 320 | list_remove(node); |
| 321 | free(bus); |
| 322 | return; |
| 323 | } |
| 324 | } |
| 325 | } |
| 326 | |
Andrew Boie | a885d04 | 2013-09-13 17:41:20 -0700 | [diff] [blame] | 327 | /* Given a path that may start with a PCI device, populate the supplied buffer |
| 328 | * with the PCI domain/bus number and the peripheral ID and return 0. |
| 329 | * If it doesn't start with a PCI device, or there is some error, return -1 */ |
| 330 | static int find_pci_device_prefix(const char *path, char *buf, ssize_t buf_sz) |
| 331 | { |
| 332 | const char *start, *end; |
| 333 | |
| 334 | if (strncmp(path, "/devices/pci", 12)) |
| 335 | return -1; |
| 336 | |
| 337 | /* Beginning of the prefix is the initial "pci" after "/devices/" */ |
| 338 | start = path + 9; |
| 339 | |
| 340 | /* End of the prefix is two path '/' later, capturing the domain/bus number |
| 341 | * and the peripheral ID. Example: pci0000:00/0000:00:1f.2 */ |
| 342 | end = strchr(start, '/'); |
| 343 | if (!end) |
| 344 | return -1; |
| 345 | end = strchr(end + 1, '/'); |
| 346 | if (!end) |
| 347 | return -1; |
| 348 | |
| 349 | /* Make sure we have enough room for the string plus null terminator */ |
| 350 | if (end - start + 1 > buf_sz) |
| 351 | return -1; |
| 352 | |
| 353 | strncpy(buf, start, end - start); |
| 354 | buf[end - start] = '\0'; |
| 355 | return 0; |
| 356 | } |
| 357 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 358 | static void parse_event(const char *msg, struct uevent *uevent) |
| 359 | { |
| 360 | uevent->action = ""; |
| 361 | uevent->path = ""; |
| 362 | uevent->subsystem = ""; |
| 363 | uevent->firmware = ""; |
| 364 | uevent->major = -1; |
| 365 | uevent->minor = -1; |
Colin Cross | b0ab94b | 2010-04-08 16:16:20 -0700 | [diff] [blame] | 366 | uevent->partition_name = NULL; |
| 367 | uevent->partition_num = -1; |
Wei Zhong | f97b887 | 2012-03-23 14:15:34 -0700 | [diff] [blame] | 368 | uevent->device_name = NULL; |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 369 | |
| 370 | /* currently ignoring SEQNUM */ |
| 371 | while(*msg) { |
| 372 | if(!strncmp(msg, "ACTION=", 7)) { |
| 373 | msg += 7; |
| 374 | uevent->action = msg; |
| 375 | } else if(!strncmp(msg, "DEVPATH=", 8)) { |
| 376 | msg += 8; |
| 377 | uevent->path = msg; |
| 378 | } else if(!strncmp(msg, "SUBSYSTEM=", 10)) { |
| 379 | msg += 10; |
| 380 | uevent->subsystem = msg; |
| 381 | } else if(!strncmp(msg, "FIRMWARE=", 9)) { |
| 382 | msg += 9; |
| 383 | uevent->firmware = msg; |
| 384 | } else if(!strncmp(msg, "MAJOR=", 6)) { |
| 385 | msg += 6; |
| 386 | uevent->major = atoi(msg); |
| 387 | } else if(!strncmp(msg, "MINOR=", 6)) { |
| 388 | msg += 6; |
| 389 | uevent->minor = atoi(msg); |
Colin Cross | b0ab94b | 2010-04-08 16:16:20 -0700 | [diff] [blame] | 390 | } else if(!strncmp(msg, "PARTN=", 6)) { |
| 391 | msg += 6; |
| 392 | uevent->partition_num = atoi(msg); |
| 393 | } else if(!strncmp(msg, "PARTNAME=", 9)) { |
| 394 | msg += 9; |
| 395 | uevent->partition_name = msg; |
Wei Zhong | f97b887 | 2012-03-23 14:15:34 -0700 | [diff] [blame] | 396 | } else if(!strncmp(msg, "DEVNAME=", 8)) { |
| 397 | msg += 8; |
| 398 | uevent->device_name = msg; |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 399 | } |
| 400 | |
Wei Zhong | f97b887 | 2012-03-23 14:15:34 -0700 | [diff] [blame] | 401 | /* advance to after the next \0 */ |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 402 | while(*msg++) |
| 403 | ; |
| 404 | } |
| 405 | |
Elliott Hughes | c0e919c | 2015-02-04 14:46:36 -0800 | [diff] [blame] | 406 | if (LOG_UEVENTS) { |
| 407 | INFO("event { '%s', '%s', '%s', '%s', %d, %d }\n", |
| 408 | uevent->action, uevent->path, uevent->subsystem, |
| 409 | uevent->firmware, uevent->major, uevent->minor); |
| 410 | } |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 411 | } |
| 412 | |
Benoit Goby | d227863 | 2010-08-03 14:36:02 -0700 | [diff] [blame] | 413 | static char **get_character_device_symlinks(struct uevent *uevent) |
| 414 | { |
| 415 | const char *parent; |
Dan Austin | 60b976d | 2016-03-28 14:22:12 -0700 | [diff] [blame^] | 416 | const char *slash; |
Benoit Goby | d227863 | 2010-08-03 14:36:02 -0700 | [diff] [blame] | 417 | char **links; |
| 418 | int link_num = 0; |
| 419 | int width; |
Dima Zavin | f395c92 | 2013-03-06 16:23:57 -0800 | [diff] [blame] | 420 | struct platform_node *pdev; |
Benoit Goby | d227863 | 2010-08-03 14:36:02 -0700 | [diff] [blame] | 421 | |
Dima Zavin | f395c92 | 2013-03-06 16:23:57 -0800 | [diff] [blame] | 422 | pdev = find_platform_device(uevent->path); |
| 423 | if (!pdev) |
Benoit Goby | d227863 | 2010-08-03 14:36:02 -0700 | [diff] [blame] | 424 | return NULL; |
| 425 | |
Elliott Hughes | f3cf438 | 2015-02-03 17:12:07 -0800 | [diff] [blame] | 426 | links = (char**) malloc(sizeof(char *) * 2); |
Benoit Goby | d227863 | 2010-08-03 14:36:02 -0700 | [diff] [blame] | 427 | if (!links) |
| 428 | return NULL; |
| 429 | memset(links, 0, sizeof(char *) * 2); |
| 430 | |
| 431 | /* skip "/devices/platform/<driver>" */ |
Dima Zavin | f395c92 | 2013-03-06 16:23:57 -0800 | [diff] [blame] | 432 | parent = strchr(uevent->path + pdev->path_len, '/'); |
Tomasz Kondel | fca58f4 | 2013-11-05 13:17:45 +0100 | [diff] [blame] | 433 | if (!parent) |
Benoit Goby | d227863 | 2010-08-03 14:36:02 -0700 | [diff] [blame] | 434 | goto err; |
| 435 | |
| 436 | if (!strncmp(parent, "/usb", 4)) { |
| 437 | /* skip root hub name and device. use device interface */ |
| 438 | while (*++parent && *parent != '/'); |
| 439 | if (*parent) |
| 440 | while (*++parent && *parent != '/'); |
| 441 | if (!*parent) |
| 442 | goto err; |
| 443 | slash = strchr(++parent, '/'); |
| 444 | if (!slash) |
| 445 | goto err; |
| 446 | width = slash - parent; |
| 447 | if (width <= 0) |
| 448 | goto err; |
| 449 | |
| 450 | if (asprintf(&links[link_num], "/dev/usb/%s%.*s", uevent->subsystem, width, parent) > 0) |
| 451 | link_num++; |
| 452 | else |
| 453 | links[link_num] = NULL; |
| 454 | mkdir("/dev/usb", 0755); |
| 455 | } |
| 456 | else { |
| 457 | goto err; |
| 458 | } |
| 459 | |
| 460 | return links; |
| 461 | err: |
| 462 | free(links); |
| 463 | return NULL; |
| 464 | } |
| 465 | |
Andrew Boie | a885d04 | 2013-09-13 17:41:20 -0700 | [diff] [blame] | 466 | static char **get_block_device_symlinks(struct uevent *uevent) |
Colin Cross | b0ab94b | 2010-04-08 16:16:20 -0700 | [diff] [blame] | 467 | { |
Colin Cross | fadb85e | 2011-03-30 18:32:12 -0700 | [diff] [blame] | 468 | const char *device; |
Dima Zavin | f395c92 | 2013-03-06 16:23:57 -0800 | [diff] [blame] | 469 | struct platform_node *pdev; |
Dan Austin | 60b976d | 2016-03-28 14:22:12 -0700 | [diff] [blame^] | 470 | const char *slash; |
Andrew Boie | a885d04 | 2013-09-13 17:41:20 -0700 | [diff] [blame] | 471 | const char *type; |
Colin Cross | b0ab94b | 2010-04-08 16:16:20 -0700 | [diff] [blame] | 472 | char buf[256]; |
| 473 | char link_path[256]; |
Colin Cross | b0ab94b | 2010-04-08 16:16:20 -0700 | [diff] [blame] | 474 | int link_num = 0; |
Colin Cross | b0ab94b | 2010-04-08 16:16:20 -0700 | [diff] [blame] | 475 | char *p; |
Colin Cross | b0ab94b | 2010-04-08 16:16:20 -0700 | [diff] [blame] | 476 | |
Dima Zavin | f395c92 | 2013-03-06 16:23:57 -0800 | [diff] [blame] | 477 | pdev = find_platform_device(uevent->path); |
Andrew Boie | a885d04 | 2013-09-13 17:41:20 -0700 | [diff] [blame] | 478 | if (pdev) { |
| 479 | device = pdev->name; |
| 480 | type = "platform"; |
| 481 | } else if (!find_pci_device_prefix(uevent->path, buf, sizeof(buf))) { |
| 482 | device = buf; |
| 483 | type = "pci"; |
| 484 | } else { |
Dima Zavin | f395c92 | 2013-03-06 16:23:57 -0800 | [diff] [blame] | 485 | return NULL; |
Andrew Boie | a885d04 | 2013-09-13 17:41:20 -0700 | [diff] [blame] | 486 | } |
Dima Zavin | f395c92 | 2013-03-06 16:23:57 -0800 | [diff] [blame] | 487 | |
Elliott Hughes | f3cf438 | 2015-02-03 17:12:07 -0800 | [diff] [blame] | 488 | char **links = (char**) malloc(sizeof(char *) * 4); |
Colin Cross | b0ab94b | 2010-04-08 16:16:20 -0700 | [diff] [blame] | 489 | if (!links) |
| 490 | return NULL; |
| 491 | memset(links, 0, sizeof(char *) * 4); |
| 492 | |
Andrew Boie | a885d04 | 2013-09-13 17:41:20 -0700 | [diff] [blame] | 493 | INFO("found %s device %s\n", type, device); |
Colin Cross | fadb85e | 2011-03-30 18:32:12 -0700 | [diff] [blame] | 494 | |
Andrew Boie | a885d04 | 2013-09-13 17:41:20 -0700 | [diff] [blame] | 495 | snprintf(link_path, sizeof(link_path), "/dev/block/%s/%s", type, device); |
Colin Cross | b0ab94b | 2010-04-08 16:16:20 -0700 | [diff] [blame] | 496 | |
| 497 | if (uevent->partition_name) { |
| 498 | p = strdup(uevent->partition_name); |
| 499 | sanitize(p); |
Johan Redestig | 93ca79b | 2012-04-18 16:41:19 +0200 | [diff] [blame] | 500 | if (strcmp(uevent->partition_name, p)) |
| 501 | NOTICE("Linking partition '%s' as '%s'\n", uevent->partition_name, p); |
Colin Cross | b0ab94b | 2010-04-08 16:16:20 -0700 | [diff] [blame] | 502 | if (asprintf(&links[link_num], "%s/by-name/%s", link_path, p) > 0) |
| 503 | link_num++; |
| 504 | else |
| 505 | links[link_num] = NULL; |
| 506 | free(p); |
| 507 | } |
| 508 | |
| 509 | if (uevent->partition_num >= 0) { |
| 510 | if (asprintf(&links[link_num], "%s/by-num/p%d", link_path, uevent->partition_num) > 0) |
| 511 | link_num++; |
| 512 | else |
| 513 | links[link_num] = NULL; |
| 514 | } |
| 515 | |
Dima Zavin | f395c92 | 2013-03-06 16:23:57 -0800 | [diff] [blame] | 516 | slash = strrchr(uevent->path, '/'); |
Colin Cross | b0ab94b | 2010-04-08 16:16:20 -0700 | [diff] [blame] | 517 | if (asprintf(&links[link_num], "%s/%s", link_path, slash + 1) > 0) |
| 518 | link_num++; |
| 519 | else |
| 520 | links[link_num] = NULL; |
| 521 | |
| 522 | return links; |
Colin Cross | b0ab94b | 2010-04-08 16:16:20 -0700 | [diff] [blame] | 523 | } |
| 524 | |
Colin Cross | eb5ba83 | 2011-03-30 17:37:17 -0700 | [diff] [blame] | 525 | static void handle_device(const char *action, const char *devpath, |
| 526 | const char *path, int block, int major, int minor, char **links) |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 527 | { |
Colin Cross | b0ab94b | 2010-04-08 16:16:20 -0700 | [diff] [blame] | 528 | int i; |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 529 | |
Colin Cross | eb5ba83 | 2011-03-30 17:37:17 -0700 | [diff] [blame] | 530 | if(!strcmp(action, "add")) { |
Stephen Smalley | b4c5200 | 2014-06-12 12:29:14 -0400 | [diff] [blame] | 531 | make_device(devpath, path, block, major, minor, (const char **)links); |
Colin Cross | b0ab94b | 2010-04-08 16:16:20 -0700 | [diff] [blame] | 532 | if (links) { |
| 533 | for (i = 0; links[i]; i++) |
Chris Fries | 79f3384 | 2013-09-05 13:19:21 -0500 | [diff] [blame] | 534 | make_link_init(devpath, links[i]); |
Colin Cross | b0ab94b | 2010-04-08 16:16:20 -0700 | [diff] [blame] | 535 | } |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 536 | } |
| 537 | |
Colin Cross | eb5ba83 | 2011-03-30 17:37:17 -0700 | [diff] [blame] | 538 | if(!strcmp(action, "remove")) { |
Colin Cross | b0ab94b | 2010-04-08 16:16:20 -0700 | [diff] [blame] | 539 | if (links) { |
| 540 | for (i = 0; links[i]; i++) |
| 541 | remove_link(devpath, links[i]); |
| 542 | } |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 543 | unlink(devpath); |
Colin Cross | b0ab94b | 2010-04-08 16:16:20 -0700 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | if (links) { |
| 547 | for (i = 0; links[i]; i++) |
| 548 | free(links[i]); |
| 549 | free(links); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 550 | } |
| 551 | } |
| 552 | |
Colin Cross | fadb85e | 2011-03-30 18:32:12 -0700 | [diff] [blame] | 553 | static void handle_platform_device_event(struct uevent *uevent) |
| 554 | { |
Dima Zavin | f395c92 | 2013-03-06 16:23:57 -0800 | [diff] [blame] | 555 | const char *path = uevent->path; |
Colin Cross | fadb85e | 2011-03-30 18:32:12 -0700 | [diff] [blame] | 556 | |
| 557 | if (!strcmp(uevent->action, "add")) |
Dima Zavin | f395c92 | 2013-03-06 16:23:57 -0800 | [diff] [blame] | 558 | add_platform_device(path); |
Colin Cross | fadb85e | 2011-03-30 18:32:12 -0700 | [diff] [blame] | 559 | else if (!strcmp(uevent->action, "remove")) |
Dima Zavin | f395c92 | 2013-03-06 16:23:57 -0800 | [diff] [blame] | 560 | remove_platform_device(path); |
Colin Cross | fadb85e | 2011-03-30 18:32:12 -0700 | [diff] [blame] | 561 | } |
| 562 | |
Colin Cross | eb5ba83 | 2011-03-30 17:37:17 -0700 | [diff] [blame] | 563 | static const char *parse_device_name(struct uevent *uevent, unsigned int len) |
| 564 | { |
| 565 | const char *name; |
| 566 | |
| 567 | /* if it's not a /dev device, nothing else to do */ |
| 568 | if((uevent->major < 0) || (uevent->minor < 0)) |
| 569 | return NULL; |
| 570 | |
| 571 | /* do we have a name? */ |
| 572 | name = strrchr(uevent->path, '/'); |
| 573 | if(!name) |
| 574 | return NULL; |
| 575 | name++; |
| 576 | |
| 577 | /* too-long names would overrun our buffer */ |
Greg Hackmann | f6e009e | 2013-11-21 13:26:48 -0800 | [diff] [blame] | 578 | if(strlen(name) > len) { |
| 579 | ERROR("DEVPATH=%s exceeds %u-character limit on filename; ignoring event\n", |
| 580 | name, len); |
Colin Cross | eb5ba83 | 2011-03-30 17:37:17 -0700 | [diff] [blame] | 581 | return NULL; |
Greg Hackmann | f6e009e | 2013-11-21 13:26:48 -0800 | [diff] [blame] | 582 | } |
Colin Cross | eb5ba83 | 2011-03-30 17:37:17 -0700 | [diff] [blame] | 583 | |
| 584 | return name; |
| 585 | } |
| 586 | |
| 587 | static void handle_block_device_event(struct uevent *uevent) |
| 588 | { |
| 589 | const char *base = "/dev/block/"; |
| 590 | const char *name; |
| 591 | char devpath[96]; |
| 592 | char **links = NULL; |
| 593 | |
| 594 | name = parse_device_name(uevent, 64); |
| 595 | if (!name) |
| 596 | return; |
| 597 | |
| 598 | snprintf(devpath, sizeof(devpath), "%s%s", base, name); |
Stephen Smalley | e46f9d5 | 2012-01-13 08:48:47 -0500 | [diff] [blame] | 599 | make_dir(base, 0755); |
Colin Cross | eb5ba83 | 2011-03-30 17:37:17 -0700 | [diff] [blame] | 600 | |
Dima Zavin | f395c92 | 2013-03-06 16:23:57 -0800 | [diff] [blame] | 601 | if (!strncmp(uevent->path, "/devices/", 9)) |
Andrew Boie | a885d04 | 2013-09-13 17:41:20 -0700 | [diff] [blame] | 602 | links = get_block_device_symlinks(uevent); |
Colin Cross | eb5ba83 | 2011-03-30 17:37:17 -0700 | [diff] [blame] | 603 | |
| 604 | handle_device(uevent->action, devpath, uevent->path, 1, |
| 605 | uevent->major, uevent->minor, links); |
Colin Cross | eb5ba83 | 2011-03-30 17:37:17 -0700 | [diff] [blame] | 606 | } |
| 607 | |
Greg Hackmann | 3312aa8 | 2013-11-18 15:24:40 -0800 | [diff] [blame] | 608 | #define DEVPATH_LEN 96 |
| 609 | |
| 610 | static bool assemble_devpath(char *devpath, const char *dirname, |
| 611 | const char *devname) |
| 612 | { |
| 613 | int s = snprintf(devpath, DEVPATH_LEN, "%s/%s", dirname, devname); |
| 614 | if (s < 0) { |
| 615 | ERROR("failed to assemble device path (%s); ignoring event\n", |
| 616 | strerror(errno)); |
| 617 | return false; |
| 618 | } else if (s >= DEVPATH_LEN) { |
| 619 | ERROR("%s/%s exceeds %u-character limit on path; ignoring event\n", |
| 620 | dirname, devname, DEVPATH_LEN); |
| 621 | return false; |
| 622 | } |
| 623 | return true; |
| 624 | } |
| 625 | |
| 626 | static void mkdir_recursive_for_devpath(const char *devpath) |
| 627 | { |
| 628 | char dir[DEVPATH_LEN]; |
| 629 | char *slash; |
| 630 | |
| 631 | strcpy(dir, devpath); |
| 632 | slash = strrchr(dir, '/'); |
| 633 | *slash = '\0'; |
| 634 | mkdir_recursive(dir, 0755); |
| 635 | } |
| 636 | |
Colin Cross | eb5ba83 | 2011-03-30 17:37:17 -0700 | [diff] [blame] | 637 | static void handle_generic_device_event(struct uevent *uevent) |
| 638 | { |
Elliott Hughes | f3cf438 | 2015-02-03 17:12:07 -0800 | [diff] [blame] | 639 | const char *base; |
Colin Cross | eb5ba83 | 2011-03-30 17:37:17 -0700 | [diff] [blame] | 640 | const char *name; |
Greg Hackmann | 3312aa8 | 2013-11-18 15:24:40 -0800 | [diff] [blame] | 641 | char devpath[DEVPATH_LEN] = {0}; |
Colin Cross | eb5ba83 | 2011-03-30 17:37:17 -0700 | [diff] [blame] | 642 | char **links = NULL; |
| 643 | |
| 644 | name = parse_device_name(uevent, 64); |
| 645 | if (!name) |
| 646 | return; |
| 647 | |
Greg Hackmann | 3312aa8 | 2013-11-18 15:24:40 -0800 | [diff] [blame] | 648 | struct ueventd_subsystem *subsystem = |
| 649 | ueventd_subsystem_find_by_name(uevent->subsystem); |
| 650 | |
| 651 | if (subsystem) { |
| 652 | const char *devname; |
| 653 | |
| 654 | switch (subsystem->devname_src) { |
| 655 | case DEVNAME_UEVENT_DEVNAME: |
| 656 | devname = uevent->device_name; |
| 657 | break; |
| 658 | |
| 659 | case DEVNAME_UEVENT_DEVPATH: |
| 660 | devname = name; |
| 661 | break; |
| 662 | |
| 663 | default: |
| 664 | ERROR("%s subsystem's devpath option is not set; ignoring event\n", |
| 665 | uevent->subsystem); |
| 666 | return; |
| 667 | } |
| 668 | |
| 669 | if (!assemble_devpath(devpath, subsystem->dirname, devname)) |
| 670 | return; |
| 671 | mkdir_recursive_for_devpath(devpath); |
| 672 | } else if (!strncmp(uevent->subsystem, "usb", 3)) { |
Colin Cross | eb5ba83 | 2011-03-30 17:37:17 -0700 | [diff] [blame] | 673 | if (!strcmp(uevent->subsystem, "usb")) { |
Wei Zhong | f97b887 | 2012-03-23 14:15:34 -0700 | [diff] [blame] | 674 | if (uevent->device_name) { |
Greg Hackmann | 3312aa8 | 2013-11-18 15:24:40 -0800 | [diff] [blame] | 675 | if (!assemble_devpath(devpath, "/dev", uevent->device_name)) |
Greg Hackmann | f6e009e | 2013-11-21 13:26:48 -0800 | [diff] [blame] | 676 | return; |
Greg Hackmann | 3312aa8 | 2013-11-18 15:24:40 -0800 | [diff] [blame] | 677 | mkdir_recursive_for_devpath(devpath); |
Wei Zhong | f97b887 | 2012-03-23 14:15:34 -0700 | [diff] [blame] | 678 | } |
| 679 | else { |
| 680 | /* This imitates the file system that would be created |
| 681 | * if we were using devfs instead. |
| 682 | * Minors are broken up into groups of 128, starting at "001" |
| 683 | */ |
| 684 | int bus_id = uevent->minor / 128 + 1; |
| 685 | int device_id = uevent->minor % 128 + 1; |
| 686 | /* build directories */ |
| 687 | make_dir("/dev/bus", 0755); |
| 688 | make_dir("/dev/bus/usb", 0755); |
| 689 | snprintf(devpath, sizeof(devpath), "/dev/bus/usb/%03d", bus_id); |
| 690 | make_dir(devpath, 0755); |
| 691 | snprintf(devpath, sizeof(devpath), "/dev/bus/usb/%03d/%03d", bus_id, device_id); |
| 692 | } |
Colin Cross | eb5ba83 | 2011-03-30 17:37:17 -0700 | [diff] [blame] | 693 | } else { |
| 694 | /* ignore other USB events */ |
| 695 | return; |
| 696 | } |
| 697 | } else if (!strncmp(uevent->subsystem, "graphics", 8)) { |
| 698 | base = "/dev/graphics/"; |
Stephen Smalley | e46f9d5 | 2012-01-13 08:48:47 -0500 | [diff] [blame] | 699 | make_dir(base, 0755); |
Lukasz Anaczkowski | e6f8d45 | 2011-09-28 15:30:07 +0200 | [diff] [blame] | 700 | } else if (!strncmp(uevent->subsystem, "drm", 3)) { |
| 701 | base = "/dev/dri/"; |
| 702 | make_dir(base, 0755); |
Colin Cross | eb5ba83 | 2011-03-30 17:37:17 -0700 | [diff] [blame] | 703 | } else if (!strncmp(uevent->subsystem, "oncrpc", 6)) { |
| 704 | base = "/dev/oncrpc/"; |
Stephen Smalley | e46f9d5 | 2012-01-13 08:48:47 -0500 | [diff] [blame] | 705 | make_dir(base, 0755); |
Colin Cross | eb5ba83 | 2011-03-30 17:37:17 -0700 | [diff] [blame] | 706 | } else if (!strncmp(uevent->subsystem, "adsp", 4)) { |
| 707 | base = "/dev/adsp/"; |
Stephen Smalley | e46f9d5 | 2012-01-13 08:48:47 -0500 | [diff] [blame] | 708 | make_dir(base, 0755); |
Colin Cross | eb5ba83 | 2011-03-30 17:37:17 -0700 | [diff] [blame] | 709 | } else if (!strncmp(uevent->subsystem, "msm_camera", 10)) { |
| 710 | base = "/dev/msm_camera/"; |
Stephen Smalley | e46f9d5 | 2012-01-13 08:48:47 -0500 | [diff] [blame] | 711 | make_dir(base, 0755); |
Colin Cross | eb5ba83 | 2011-03-30 17:37:17 -0700 | [diff] [blame] | 712 | } else if(!strncmp(uevent->subsystem, "input", 5)) { |
| 713 | base = "/dev/input/"; |
Stephen Smalley | e46f9d5 | 2012-01-13 08:48:47 -0500 | [diff] [blame] | 714 | make_dir(base, 0755); |
Colin Cross | eb5ba83 | 2011-03-30 17:37:17 -0700 | [diff] [blame] | 715 | } else if(!strncmp(uevent->subsystem, "mtd", 3)) { |
| 716 | base = "/dev/mtd/"; |
Stephen Smalley | e46f9d5 | 2012-01-13 08:48:47 -0500 | [diff] [blame] | 717 | make_dir(base, 0755); |
Colin Cross | eb5ba83 | 2011-03-30 17:37:17 -0700 | [diff] [blame] | 718 | } else if(!strncmp(uevent->subsystem, "sound", 5)) { |
| 719 | base = "/dev/snd/"; |
Stephen Smalley | e46f9d5 | 2012-01-13 08:48:47 -0500 | [diff] [blame] | 720 | make_dir(base, 0755); |
Colin Cross | eb5ba83 | 2011-03-30 17:37:17 -0700 | [diff] [blame] | 721 | } else if(!strncmp(uevent->subsystem, "misc", 4) && |
| 722 | !strncmp(name, "log_", 4)) { |
Elliott Hughes | f682b47 | 2015-02-06 12:19:48 -0800 | [diff] [blame] | 723 | INFO("kernel logger is deprecated\n"); |
Colin Cross | eb5ba83 | 2011-03-30 17:37:17 -0700 | [diff] [blame] | 724 | base = "/dev/log/"; |
Stephen Smalley | e46f9d5 | 2012-01-13 08:48:47 -0500 | [diff] [blame] | 725 | make_dir(base, 0755); |
Colin Cross | eb5ba83 | 2011-03-30 17:37:17 -0700 | [diff] [blame] | 726 | name += 4; |
| 727 | } else |
| 728 | base = "/dev/"; |
| 729 | links = get_character_device_symlinks(uevent); |
| 730 | |
| 731 | if (!devpath[0]) |
| 732 | snprintf(devpath, sizeof(devpath), "%s%s", base, name); |
| 733 | |
| 734 | handle_device(uevent->action, devpath, uevent->path, 0, |
| 735 | uevent->major, uevent->minor, links); |
| 736 | } |
| 737 | |
| 738 | static void handle_device_event(struct uevent *uevent) |
| 739 | { |
Ruchi Kandoi | 75b287b | 2014-04-29 19:14:37 -0700 | [diff] [blame] | 740 | if (!strcmp(uevent->action,"add") || !strcmp(uevent->action, "change") || !strcmp(uevent->action, "online")) |
Colin Cross | eb5ba83 | 2011-03-30 17:37:17 -0700 | [diff] [blame] | 741 | fixup_sys_perms(uevent->path); |
| 742 | |
| 743 | if (!strncmp(uevent->subsystem, "block", 5)) { |
| 744 | handle_block_device_event(uevent); |
Colin Cross | fadb85e | 2011-03-30 18:32:12 -0700 | [diff] [blame] | 745 | } else if (!strncmp(uevent->subsystem, "platform", 8)) { |
| 746 | handle_platform_device_event(uevent); |
Colin Cross | eb5ba83 | 2011-03-30 17:37:17 -0700 | [diff] [blame] | 747 | } else { |
| 748 | handle_generic_device_event(uevent); |
| 749 | } |
| 750 | } |
| 751 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 752 | static int load_firmware(int fw_fd, int loading_fd, int data_fd) |
| 753 | { |
| 754 | struct stat st; |
| 755 | long len_to_copy; |
| 756 | int ret = 0; |
| 757 | |
| 758 | if(fstat(fw_fd, &st) < 0) |
| 759 | return -1; |
| 760 | len_to_copy = st.st_size; |
| 761 | |
| 762 | write(loading_fd, "1", 1); /* start transfer */ |
| 763 | |
| 764 | while (len_to_copy > 0) { |
| 765 | char buf[PAGE_SIZE]; |
| 766 | ssize_t nr; |
| 767 | |
| 768 | nr = read(fw_fd, buf, sizeof(buf)); |
| 769 | if(!nr) |
| 770 | break; |
| 771 | if(nr < 0) { |
| 772 | ret = -1; |
| 773 | break; |
| 774 | } |
Biao Lu | dc84856 | 2016-01-28 16:10:54 +0800 | [diff] [blame] | 775 | if (!android::base::WriteFully(data_fd, buf, nr)) { |
| 776 | ret = -1; |
| 777 | break; |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 778 | } |
Biao Lu | dc84856 | 2016-01-28 16:10:54 +0800 | [diff] [blame] | 779 | len_to_copy -= nr; |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 780 | } |
| 781 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 782 | if(!ret) |
| 783 | write(loading_fd, "0", 1); /* successful end of transfer */ |
| 784 | else |
| 785 | write(loading_fd, "-1", 2); /* abort transfer */ |
| 786 | |
| 787 | return ret; |
| 788 | } |
| 789 | |
Brian Swetland | 8d48c8e | 2011-03-24 15:45:30 -0700 | [diff] [blame] | 790 | static int is_booting(void) |
| 791 | { |
| 792 | return access("/dev/.booting", F_OK) == 0; |
| 793 | } |
| 794 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 795 | static void process_firmware_event(struct uevent *uevent) |
| 796 | { |
Daniel Rosenberg | d1d9602 | 2015-03-20 15:10:29 -0700 | [diff] [blame] | 797 | char *root, *loading, *data; |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 798 | int l, loading_fd, data_fd, fw_fd; |
Daniel Rosenberg | d1d9602 | 2015-03-20 15:10:29 -0700 | [diff] [blame] | 799 | size_t i; |
Brian Swetland | 8d48c8e | 2011-03-24 15:45:30 -0700 | [diff] [blame] | 800 | int booting = is_booting(); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 801 | |
Brian Swetland | 8d48c8e | 2011-03-24 15:45:30 -0700 | [diff] [blame] | 802 | INFO("firmware: loading '%s' for '%s'\n", |
| 803 | uevent->firmware, uevent->path); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 804 | |
| 805 | l = asprintf(&root, SYSFS_PREFIX"%s/", uevent->path); |
| 806 | if (l == -1) |
| 807 | return; |
| 808 | |
| 809 | l = asprintf(&loading, "%sloading", root); |
| 810 | if (l == -1) |
| 811 | goto root_free_out; |
| 812 | |
| 813 | l = asprintf(&data, "%sdata", root); |
| 814 | if (l == -1) |
| 815 | goto loading_free_out; |
| 816 | |
Nick Kralevich | 45a884f | 2015-02-02 14:37:22 -0800 | [diff] [blame] | 817 | loading_fd = open(loading, O_WRONLY|O_CLOEXEC); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 818 | if(loading_fd < 0) |
Daniel Rosenberg | d1d9602 | 2015-03-20 15:10:29 -0700 | [diff] [blame] | 819 | goto data_free_out; |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 820 | |
Nick Kralevich | 45a884f | 2015-02-02 14:37:22 -0800 | [diff] [blame] | 821 | data_fd = open(data, O_WRONLY|O_CLOEXEC); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 822 | if(data_fd < 0) |
| 823 | goto loading_close_out; |
| 824 | |
Brian Swetland | 8d48c8e | 2011-03-24 15:45:30 -0700 | [diff] [blame] | 825 | try_loading_again: |
Daniel Rosenberg | d1d9602 | 2015-03-20 15:10:29 -0700 | [diff] [blame] | 826 | for (i = 0; i < ARRAY_SIZE(firmware_dirs); i++) { |
| 827 | char *file = NULL; |
| 828 | l = asprintf(&file, "%s/%s", firmware_dirs[i], uevent->firmware); |
| 829 | if (l == -1) |
| 830 | goto data_free_out; |
| 831 | fw_fd = open(file, O_RDONLY|O_CLOEXEC); |
| 832 | free(file); |
| 833 | if (fw_fd >= 0) { |
| 834 | if(!load_firmware(fw_fd, loading_fd, data_fd)) |
| 835 | INFO("firmware: copy success { '%s', '%s' }\n", root, uevent->firmware); |
| 836 | else |
| 837 | INFO("firmware: copy failure { '%s', '%s' }\n", root, uevent->firmware); |
| 838 | break; |
Benoit Goby | 609d882 | 2010-11-09 18:10:24 -0800 | [diff] [blame] | 839 | } |
Brian Swetland | 02863b9 | 2010-09-19 03:36:39 -0700 | [diff] [blame] | 840 | } |
Daniel Rosenberg | d1d9602 | 2015-03-20 15:10:29 -0700 | [diff] [blame] | 841 | if (fw_fd < 0) { |
| 842 | if (booting) { |
| 843 | /* If we're not fully booted, we may be missing |
| 844 | * filesystems needed for firmware, wait and retry. |
| 845 | */ |
| 846 | usleep(100000); |
| 847 | booting = is_booting(); |
| 848 | goto try_loading_again; |
| 849 | } |
Elliott Hughes | cd67f00 | 2015-03-20 17:05:56 -0700 | [diff] [blame] | 850 | INFO("firmware: could not open '%s': %s\n", uevent->firmware, strerror(errno)); |
Daniel Rosenberg | d1d9602 | 2015-03-20 15:10:29 -0700 | [diff] [blame] | 851 | write(loading_fd, "-1", 2); |
| 852 | goto data_close_out; |
| 853 | } |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 854 | |
| 855 | close(fw_fd); |
| 856 | data_close_out: |
| 857 | close(data_fd); |
| 858 | loading_close_out: |
| 859 | close(loading_fd); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 860 | data_free_out: |
| 861 | free(data); |
| 862 | loading_free_out: |
| 863 | free(loading); |
| 864 | root_free_out: |
| 865 | free(root); |
| 866 | } |
| 867 | |
| 868 | static void handle_firmware_event(struct uevent *uevent) |
| 869 | { |
| 870 | pid_t pid; |
| 871 | |
| 872 | if(strcmp(uevent->subsystem, "firmware")) |
| 873 | return; |
| 874 | |
| 875 | if(strcmp(uevent->action, "add")) |
| 876 | return; |
| 877 | |
| 878 | /* we fork, to avoid making large memory allocations in init proper */ |
| 879 | pid = fork(); |
| 880 | if (!pid) { |
| 881 | process_firmware_event(uevent); |
Kenny Root | 17baff4 | 2014-08-20 16:16:44 -0700 | [diff] [blame] | 882 | _exit(EXIT_SUCCESS); |
| 883 | } else if (pid < 0) { |
Elliott Hughes | c0e919c | 2015-02-04 14:46:36 -0800 | [diff] [blame] | 884 | ERROR("could not fork to process firmware event: %s\n", strerror(errno)); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 885 | } |
| 886 | } |
| 887 | |
Ruchi Kandoi | c603720 | 2014-06-23 11:22:09 -0700 | [diff] [blame] | 888 | #define UEVENT_MSG_LEN 2048 |
Colin Cross | 0dd7ca6 | 2010-04-13 19:25:51 -0700 | [diff] [blame] | 889 | void handle_device_fd() |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 890 | { |
Vernon Tang | 3f582e9 | 2011-04-25 13:08:17 +1000 | [diff] [blame] | 891 | char msg[UEVENT_MSG_LEN+2]; |
| 892 | int n; |
Nick Kralevich | 57de8b8 | 2011-05-11 14:58:24 -0700 | [diff] [blame] | 893 | while ((n = uevent_kernel_multicast_recv(device_fd, msg, UEVENT_MSG_LEN)) > 0) { |
Nick Kralevich | 5f5d5c8 | 2010-07-19 14:31:20 -0700 | [diff] [blame] | 894 | if(n >= UEVENT_MSG_LEN) /* overflow -- discard */ |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 895 | continue; |
| 896 | |
| 897 | msg[n] = '\0'; |
| 898 | msg[n+1] = '\0'; |
| 899 | |
Nick Kralevich | 5f5d5c8 | 2010-07-19 14:31:20 -0700 | [diff] [blame] | 900 | struct uevent uevent; |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 901 | parse_event(msg, &uevent); |
| 902 | |
Nick Kralevich | 4d87095 | 2015-06-12 22:03:50 -0700 | [diff] [blame] | 903 | if (selinux_status_updated() > 0) { |
Stephen Smalley | e2eb69d | 2013-04-16 09:30:30 -0400 | [diff] [blame] | 904 | struct selabel_handle *sehandle2; |
| 905 | sehandle2 = selinux_android_file_context_handle(); |
| 906 | if (sehandle2) { |
| 907 | selabel_close(sehandle); |
| 908 | sehandle = sehandle2; |
| 909 | } |
| 910 | } |
| 911 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 912 | handle_device_event(&uevent); |
| 913 | handle_firmware_event(&uevent); |
| 914 | } |
| 915 | } |
| 916 | |
| 917 | /* Coldboot walks parts of the /sys tree and pokes the uevent files |
| 918 | ** to cause the kernel to regenerate device add events that happened |
| 919 | ** before init's device manager was started |
| 920 | ** |
| 921 | ** We drain any pending events from the netlink socket every time |
| 922 | ** we poke another uevent file to make sure we don't overrun the |
Elliott Hughes | c0e919c | 2015-02-04 14:46:36 -0800 | [diff] [blame] | 923 | ** socket's buffer. |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 924 | */ |
| 925 | |
Colin Cross | 0dd7ca6 | 2010-04-13 19:25:51 -0700 | [diff] [blame] | 926 | static void do_coldboot(DIR *d) |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 927 | { |
| 928 | struct dirent *de; |
| 929 | int dfd, fd; |
| 930 | |
| 931 | dfd = dirfd(d); |
| 932 | |
| 933 | fd = openat(dfd, "uevent", O_WRONLY); |
| 934 | if(fd >= 0) { |
| 935 | write(fd, "add\n", 4); |
| 936 | close(fd); |
Colin Cross | 0dd7ca6 | 2010-04-13 19:25:51 -0700 | [diff] [blame] | 937 | handle_device_fd(); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 938 | } |
| 939 | |
| 940 | while((de = readdir(d))) { |
| 941 | DIR *d2; |
| 942 | |
| 943 | if(de->d_type != DT_DIR || de->d_name[0] == '.') |
| 944 | continue; |
| 945 | |
| 946 | fd = openat(dfd, de->d_name, O_RDONLY | O_DIRECTORY); |
| 947 | if(fd < 0) |
| 948 | continue; |
| 949 | |
| 950 | d2 = fdopendir(fd); |
| 951 | if(d2 == 0) |
| 952 | close(fd); |
| 953 | else { |
Colin Cross | 0dd7ca6 | 2010-04-13 19:25:51 -0700 | [diff] [blame] | 954 | do_coldboot(d2); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 955 | closedir(d2); |
| 956 | } |
| 957 | } |
| 958 | } |
| 959 | |
Colin Cross | 0dd7ca6 | 2010-04-13 19:25:51 -0700 | [diff] [blame] | 960 | static void coldboot(const char *path) |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 961 | { |
James Hawkins | 588a2ca | 2016-02-18 14:52:46 -0800 | [diff] [blame] | 962 | std::unique_ptr<DIR, decltype(&closedir)> d(opendir(path), closedir); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 963 | if(d) { |
James Hawkins | 588a2ca | 2016-02-18 14:52:46 -0800 | [diff] [blame] | 964 | do_coldboot(d.get()); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 965 | } |
| 966 | } |
| 967 | |
Elliott Hughes | 7473836 | 2015-03-28 10:51:23 -0700 | [diff] [blame] | 968 | void device_init() { |
Nick Kralevich | 4d87095 | 2015-06-12 22:03:50 -0700 | [diff] [blame] | 969 | sehandle = selinux_android_file_context_handle(); |
| 970 | selinux_status_open(true); |
Kenny Root | b5982bf | 2012-10-16 23:07:05 -0700 | [diff] [blame] | 971 | |
Andrew Boie | d562ca7 | 2012-12-04 15:47:20 -0800 | [diff] [blame] | 972 | /* is 256K enough? udev uses 16MB! */ |
| 973 | device_fd = uevent_open_socket(256*1024, true); |
Elliott Hughes | 56a0656 | 2015-03-28 11:23:32 -0700 | [diff] [blame] | 974 | if (device_fd == -1) { |
Colin Cross | 0dd7ca6 | 2010-04-13 19:25:51 -0700 | [diff] [blame] | 975 | return; |
Elliott Hughes | 56a0656 | 2015-03-28 11:23:32 -0700 | [diff] [blame] | 976 | } |
Colin Cross | 0dd7ca6 | 2010-04-13 19:25:51 -0700 | [diff] [blame] | 977 | fcntl(device_fd, F_SETFL, O_NONBLOCK); |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 978 | |
Elliott Hughes | 56a0656 | 2015-03-28 11:23:32 -0700 | [diff] [blame] | 979 | if (access(COLDBOOT_DONE, F_OK) == 0) { |
Elliott Hughes | da40c00 | 2015-03-27 23:20:44 -0700 | [diff] [blame] | 980 | NOTICE("Skipping coldboot, already done!\n"); |
Elliott Hughes | 56a0656 | 2015-03-28 11:23:32 -0700 | [diff] [blame] | 981 | return; |
Colin Cross | f83d0b9 | 2010-04-21 12:04:20 -0700 | [diff] [blame] | 982 | } |
Elliott Hughes | 56a0656 | 2015-03-28 11:23:32 -0700 | [diff] [blame] | 983 | |
| 984 | Timer t; |
| 985 | coldboot("/sys/class"); |
| 986 | coldboot("/sys/block"); |
| 987 | coldboot("/sys/devices"); |
| 988 | close(open(COLDBOOT_DONE, O_WRONLY|O_CREAT|O_CLOEXEC, 0000)); |
| 989 | NOTICE("Coldboot took %.2fs.\n", t.duration()); |
Colin Cross | 0dd7ca6 | 2010-04-13 19:25:51 -0700 | [diff] [blame] | 990 | } |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 991 | |
Colin Cross | 0dd7ca6 | 2010-04-13 19:25:51 -0700 | [diff] [blame] | 992 | int get_device_fd() |
| 993 | { |
| 994 | return device_fd; |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 995 | } |