| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2007 The Android Open Source Project | 
|  | 3 | * | 
|  | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | * you may not use this file except in compliance with the License. | 
|  | 6 | * You may obtain a copy of the License at | 
|  | 7 | * | 
|  | 8 | *      http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | * | 
|  | 10 | * Unless required by applicable law or agreed to in writing, software | 
|  | 11 | * distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | * See the License for the specific language governing permissions and | 
|  | 14 | * limitations under the License. | 
|  | 15 | */ | 
|  | 16 |  | 
|  | 17 | #ifndef _INIT_DEVICES_H | 
|  | 18 | #define _INIT_DEVICES_H | 
|  | 19 |  | 
| Colin Cross | f83d0b9 | 2010-04-21 12:04:20 -0700 | [diff] [blame] | 20 | #include <sys/stat.h> | 
|  | 21 |  | 
| Tom Cherry | 3f5eaae5 | 2017-04-06 16:30:22 -0700 | [diff] [blame] | 22 | #include <functional> | 
|  | 23 |  | 
| Sandeep Patil | 957e4ab | 2017-02-07 18:11:37 -0800 | [diff] [blame] | 24 | enum coldboot_action_t { | 
|  | 25 | // coldboot continues without creating the device for the uevent | 
|  | 26 | COLDBOOT_CONTINUE = 0, | 
|  | 27 | // coldboot continues after creating the device for the uevent | 
|  | 28 | COLDBOOT_CREATE, | 
|  | 29 | // coldboot stops after creating the device for uevent but doesn't | 
|  | 30 | // create the COLDBOOT_DONE file | 
|  | 31 | COLDBOOT_STOP, | 
|  | 32 | // same as COLDBOOT_STOP, but creates the COLDBOOT_DONE file | 
|  | 33 | COLDBOOT_FINISH | 
|  | 34 | }; | 
|  | 35 |  | 
|  | 36 | struct uevent { | 
|  | 37 | const char* action; | 
|  | 38 | const char* path; | 
|  | 39 | const char* subsystem; | 
|  | 40 | const char* firmware; | 
|  | 41 | const char* partition_name; | 
|  | 42 | const char* device_name; | 
|  | 43 | int partition_num; | 
|  | 44 | int major; | 
|  | 45 | int minor; | 
|  | 46 | }; | 
|  | 47 |  | 
|  | 48 | typedef std::function<coldboot_action_t(struct uevent* uevent)> coldboot_callback; | 
|  | 49 | extern coldboot_action_t handle_device_fd(coldboot_callback fn = nullptr); | 
|  | 50 | extern void device_init(const char* path = nullptr, coldboot_callback fn = nullptr); | 
| Sandeep Patil | 35403eb | 2017-02-08 20:27:12 -0800 | [diff] [blame] | 51 | extern void device_close(); | 
| Hung-ying Tyan | 99c4a8a | 2016-02-01 15:07:40 +0800 | [diff] [blame] | 52 |  | 
| Brian Swetland | bc57d4c | 2010-10-26 15:09:43 -0700 | [diff] [blame] | 53 | extern int add_dev_perms(const char *name, const char *attr, | 
|  | 54 | mode_t perm, unsigned int uid, | 
| Daniel Leung | c0c1ffe | 2012-07-02 11:32:30 -0700 | [diff] [blame] | 55 | unsigned int gid, unsigned short prefix, | 
|  | 56 | unsigned short wildcard); | 
| Colin Cross | 0dd7ca6 | 2010-04-13 19:25:51 -0700 | [diff] [blame] | 57 | int get_device_fd(); | 
| Elliott Hughes | f3cf438 | 2015-02-03 17:12:07 -0800 | [diff] [blame] | 58 |  | 
| Tom Cherry | c44f6a4 | 2017-04-05 15:58:31 -0700 | [diff] [blame] | 59 | // Exposed for testing | 
|  | 60 | void add_platform_device(const char* path); | 
|  | 61 | void remove_platform_device(const char* path); | 
|  | 62 | char** get_character_device_symlinks(uevent* uevent); | 
|  | 63 | char** get_block_device_symlinks(struct uevent* uevent); | 
|  | 64 | void sanitize_partition_name(char* s); | 
|  | 65 |  | 
|  | 66 | #endif /* _INIT_DEVICES_H */ |