Download presentation
Presentation is loading. Please wait.
Published byEileen Lang Modified over 8 years ago
1
© 2009 IBM Corporation Tianhong Wang 2012/06/28 Android’s udev —— Vold
2
© 2009 IBM Corporation Agenda Linux Udev Introduction Udev Usage Example Android Vold Introduction
3
© 2009 IBM Corporation Linux Udev Introduction U U Udev is the device manager for the linux kernel. Primarily, it manages device nodes in /dev. It is the successor of devfs and hotplug, which means that it handles the /dev directory and all user space actions when adding/removing devices, including firmware load.
4
© 2009 IBM Corporation Linux Udev Architecture U T The system is divided into three parts: 1 1. namedev —— parse the naming rule config file /etc/udev/rules.d 2 2. libsysfs —— read the hardware information under /sys/class 3 3. udev —— get the libsysfs info and the namedev info to create the device file under /dev U udev toolsets: udevadm 、 udevcontrol 、 udevinfo 、 udevmonitor 、 udevsettle 、 udevtest 、 udevtrigger
5
© 2009 IBM Corporation Linux Udev Architecture U
6
© 2009 IBM Corporation Udev Usage Example U
7
© 2009 IBM Corporation Udev Usage Example U
8
© 2009 IBM Corporation Android Vold Introduction Vold has two function: 1) send the kernel message to user space 2) accpet the user space command to do the device mount operation
9
© 2009 IBM Corporation Android Vold Basic Structure Vold(Volume Daemon) is a new mechanism that can dynamically create the device file according to listen the kernel uevent.
10
© 2009 IBM Corporation Android Vold Structure in Framework Layer NativeDaemonConnector SocketListener NetlinkListenerCommandListener AutoVolume DirectVolume VolumeManager NetlinkManagerVolume read vold.fstab, create DirectVolume Kernel Mount Command execute JNI
11
© 2009 IBM Corporation Vold Running Function Step 1: vold init startup Step 2: setup the connection Step 3: load the rule file Step 4: event handler
12
© 2009 IBM Corporation Step 1: Vold init startup
13
© 2009 IBM Corporation Step 1: Vold init startup void main(){ VolumeManager *vm; CommandListener *cl; NetlinkManager *nm; mkdir("/dev/block/vold", 0755); /* Create our singleton managers */ if (!(vm = VolumeManager::Instance())) { SLOGE("Unable to create VolumeManager"); exit(1); }; if (!(nm = NetlinkManager::Instance())) { SLOGE("Unable to create NetlinkManager"); exit(1); }; cl = new CommandListener(); vm->setBroadcaster((SocketListener *) cl); nm->setBroadcaster((SocketListener *) cl); if (vm->start()) { SLOGE("Unable to start VolumeManager (%s)", strerror(errno)); exit(1); } if (process_config(vm)) { SLOGE("Error reading configuration (%s)... continuing anyways", strerror(errno)); } if (nm->start()) { SLOGE("Unable to start NetlinkManager (%s)", strerror(errno)); exit(1); } … }
14
© 2009 IBM Corporation Step 2: setup the connection Two communication socket: 1)Vold socket: communction with vold and framework(FrameworkListener) 2)Sysfs uevent socket: communication with kernel(NetlinkListener)
15
© 2009 IBM Corporation Step 3: Load Rules file —— vold.fstab
16
© 2009 IBM Corporation Step 4: Event Handler 1) kernel trigger uevent: call NetlinkHandler::onEvent() after parsing uevent information
17
© 2009 IBM Corporation Step 4: Event Handler 2) Command Sent from Framework Layer: call VolumeManger function
18
© 2009 IBM Corporation Netlink Mechanism Kernel SpaceUser Space netlink_proto_init netlink_kernel_create sock_register(&netlink_family_ops) syscall: socket sys_sock netlink_create netlink_rcv_skb netlink_create send_to
19
© 2009 IBM Corporation static int __inti netlink_proto_init(void) { …… sock_register(&netlink_family_ops); …… } static const struct net_proto_family netlink_family_ops = {.family = PF_NETLINK,.create = netlink_create,.owner= THIS_MODULE,/* for consistency 8) */ }; static int netlink_create(struct net *net, struct socket *sock, int protocol, int kern) { struct module *module = NULL; struct mutex *cb_mutex; struct netlink_sock *nlk; int err = 0; sock->state = SS_UNCONNECTED; if (sock->type != SOCK_RAW && sock->type != SOCK_DGRAM) return -ESOCKTNOSUPPORT; if (protocol = MAX_LINKS) return -EPROTONOSUPPORT; netlink_lock_table(); …… } Client Netlink Socket
20
© 2009 IBM Corporation struct sock * netlink_kernel_create(struct net *net, int unit, unsigned int groups, void (*input)(struct sk_buff *skb), struct mutex *cb_mutex, struct module *module) { struct socket *sock; struct sock *sk; struct netlink_sock *nlk; struct listeners *listeners = NULL; BUG_ON(!nl_table); if (unit = MAX_LINKS) return NULL; if (sock_create_lite(PF_NETLINK, SOCK_DGRAM, unit, &sock)) return NULL; …… } Server Netlink Socket
21
© 2009 IBM Corporation
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.