Other Parts Discussed in Thread: TPS65950, WL1271
Hi,
I'm considering "SD card automount" at run-time. As far as I know, there are three ways to automount SD card.
Is there possible way to automount SD card from the below methods?
1. Polling : after checking SD card /sys/* entry, if exsits, mount -t vfat /dev/mmcblk1 /sdcard
2. Using hotplug : replace automount script with /proc/sys/kernel/hotplug
3. Using uevent :
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <asm/types.h>
#include <sys/socket.h>
#include <linux/rtnetlink.h>
#include <linux/netlink.h>
#define NETLINK_KOBJECT_UEVENT (15)
int main(int argc, char **argv)
{
int ret = EXIT_FAILURE;
int ns = -1;
struct sockaddr_nl sa;
char buf[4096];
struct iovec iov = { buf, sizeof(buf) };
struct msghdr msg = { &sa, sizeof(sa), &iov, 1, NULL, 0, 0 };
int len;
memset (&sa, 0, sizeof(sa));
sa.nl_family = AF_NETLINK;
sa.nl_groups = RTMGRP_LINK | RTMGRP_IPV4_IFADDR;
ns = socket(AF_NETLINK, SOCK_RAW, NETLINK_KOBJECT_UEVENT);
if (ns < 0) {
perror("socket()");
goto sock_err;
}
if (bind(ns, (struct sockaddr*)&sa, sizeof(sa))) {
perror("bind()");
goto bind_err;
}
while (1) {
len = recvmsg (ns, &msg, 0);
if (len < 0) {
perror("recvmsg()");
break;
}
buf[4095] = 0;
printf("%s\n", &buf[0]);
fflush(stdout);
#if 0
/* ... refer to 'man 7 netlink' */
struct nlmsghdr *h;
for (h = (struct nlmsghdr*)buf; NLMSG_OK(h, len);) {
printf("nlmsg_len: %d\n", h->nlmsg_len);
h = NLMSG_NEXT(h, len);
}
#endif
}
bind_err:
close(ns);
sock_err:
return ret;
}