Static int init_hotplug_sock (void)
183 {
184
185 struct sockaddr_nl SNL;
186 const int buffersize = 16*1024*1024;
187 int retval;
188
189 memset (& SNL, 0x00, sizeof (struct sockaddr_nl ));
190 SNL. nl_family = af_netlink;
191 SNL. nl_pid = getpid ();
192 SNL. nl_groups = 1;
193
194 int hotplug_sock = socket (pf_netlink, sock_dgram, netlink_kobject_uevent );
195 If (hotplug_sock =-1)
196 {
197 printf ("error getting socket: % s", strerror (errno ));
198 return-1;
199}
200
201/* set receive buffersize */
202
203 // setsockopt (hotplug_sock, sol_socket, so_rcvbufforce, & buffersize, sizeof (buffersize ));
204 retval = BIND (hotplug_sock, (struct sockaddr *) & SNL, sizeof (struct sockaddr_nl ));
205 If (retval <0 ){
206 printf ("bind failed: % s", strerror (errno ));
207 close (hotplug_sock );
208 hotplug_sock =-1;
209 return-1;
210}
211 pthread_mutex_init (& mount_mutex, null );
212 return hotplug_sock;
213
214}
If (hotplug_sock> = 0) & fd_isset (hotplug_sock, & FD ))
{
Char Buf [4096] = {0 };
Recv (hotplug_sock, & Buf, sizeof (BUF), 0 );
}
The plugging status is obtained by judging "add" and "Remove" in the Buf.
Hotplug: Add @/devices/platform/brcm-ehci.0/usb1/1-1
Hotplug: Add @/devices/platform/brcm-ehci.0/usb1/1-1/usbdev1.4 _ ep00
Hotplug: Add @/devices/platform/brcm-ehci.0/usb1/1-1/1-. 0
Hotplug: Add @/class/scsi_host/host1
Hotplug: Add @/devices/platform/brcm-ehci.0/usb1/1-1/1-. 0/usbdev1.4 _ ep81
Hotplug: Add @/devices/platform/brcm-ehci.0/usb1/1-1/1-. 0/usbdev1.4 _ ep02
Hotplug: Add @/class/usb_device/usbdev1.4
[Cascade_ui.c: 372] Message: pd900 code = 20f key_eventkind = 0
199997: browsersendcustominput (527)
Hotplug: Add @/devices/platform/brcm-ehci.0/usb1/1-1/1-. 0/host1/target1: 0: 0/1: 0: 0: 0: 0
Hotplug: Add @/class/scsi_disk/1: 0: 0: 0
Hotplug: Add @/block/SDB
Hotplug: Add @/block/sdb/sdb1
Hotplug: Add @/class/scsi_device/1: 0: 0: 0
Hotplug: Add @/class/scsi_generic/sg0
Hotplug: Mount @/block/sdb/sdb1