blob: f6183c94513d6678cd2d2058ac4e16349be2760d [file] [log] [blame]
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001/*
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 Crossf83d0b92010-04-21 12:04:20 -070020#include <sys/stat.h>
21
Tom Cherry3f5eaae52017-04-06 16:30:22 -070022#include <functional>
Tom Cherry2e344f92017-04-04 17:53:45 -070023#include <string>
24#include <vector>
Tom Cherry3f5eaae52017-04-06 16:30:22 -070025
Sandeep Patil957e4ab2017-02-07 18:11:37 -080026enum coldboot_action_t {
27 // coldboot continues without creating the device for the uevent
28 COLDBOOT_CONTINUE = 0,
29 // coldboot continues after creating the device for the uevent
30 COLDBOOT_CREATE,
31 // coldboot stops after creating the device for uevent but doesn't
32 // create the COLDBOOT_DONE file
33 COLDBOOT_STOP,
34 // same as COLDBOOT_STOP, but creates the COLDBOOT_DONE file
35 COLDBOOT_FINISH
36};
37
38struct uevent {
39 const char* action;
40 const char* path;
41 const char* subsystem;
42 const char* firmware;
43 const char* partition_name;
44 const char* device_name;
45 int partition_num;
46 int major;
47 int minor;
48};
49
50typedef std::function<coldboot_action_t(struct uevent* uevent)> coldboot_callback;
51extern coldboot_action_t handle_device_fd(coldboot_callback fn = nullptr);
52extern void device_init(const char* path = nullptr, coldboot_callback fn = nullptr);
Sandeep Patil35403eb2017-02-08 20:27:12 -080053extern void device_close();
Hung-ying Tyan99c4a8a2016-02-01 15:07:40 +080054
Brian Swetlandbc57d4c2010-10-26 15:09:43 -070055extern int add_dev_perms(const char *name, const char *attr,
56 mode_t perm, unsigned int uid,
Daniel Leungc0c1ffe2012-07-02 11:32:30 -070057 unsigned int gid, unsigned short prefix,
58 unsigned short wildcard);
Colin Cross0dd7ca62010-04-13 19:25:51 -070059int get_device_fd();
Elliott Hughesf3cf4382015-02-03 17:12:07 -080060
Tom Cherryc44f6a42017-04-05 15:58:31 -070061// Exposed for testing
62void add_platform_device(const char* path);
63void remove_platform_device(const char* path);
Tom Cherry2e344f92017-04-04 17:53:45 -070064std::vector<std::string> get_character_device_symlinks(uevent* uevent);
65std::vector<std::string> get_block_device_symlinks(uevent* uevent);
66void sanitize_partition_name(std::string* string);
Tom Cherryc44f6a42017-04-05 15:58:31 -070067
68#endif /* _INIT_DEVICES_H */