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