Home | History | Annotate | Download | only in init
      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 
     20 #include <functional>
     21 #include <sys/stat.h>
     22 
     23 enum coldboot_action_t {
     24     // coldboot continues without creating the device for the uevent
     25     COLDBOOT_CONTINUE = 0,
     26     // coldboot continues after creating the device for the uevent
     27     COLDBOOT_CREATE,
     28     // coldboot stops after creating the device for uevent but doesn't
     29     // create the COLDBOOT_DONE file
     30     COLDBOOT_STOP,
     31     // same as COLDBOOT_STOP, but creates the COLDBOOT_DONE file
     32     COLDBOOT_FINISH
     33 };
     34 
     35 struct uevent {
     36     const char* action;
     37     const char* path;
     38     const char* subsystem;
     39     const char* firmware;
     40     const char* partition_name;
     41     const char* device_name;
     42     int partition_num;
     43     int major;
     44     int minor;
     45 };
     46 
     47 typedef std::function<coldboot_action_t(struct uevent* uevent)> coldboot_callback;
     48 extern coldboot_action_t handle_device_fd(coldboot_callback fn = nullptr);
     49 extern void device_init(const char* path = nullptr, coldboot_callback fn = nullptr);
     50 extern void device_close();
     51 
     52 extern int add_dev_perms(const char *name, const char *attr,
     53                          mode_t perm, unsigned int uid,
     54                          unsigned int gid, unsigned short prefix,
     55                          unsigned short wildcard);
     56 int get_device_fd();
     57 
     58 char** get_block_device_symlinks(struct uevent* uevent);
     59 
     60 #endif	/* _INIT_DEVICES_H */
     61