int mdev_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int mdev_main(int argc UNUSED_PARAM, char **argv) { RESERVE_CONFIG_BUFFER(temp, PATH_MAX + SCRATCH_SIZE);
INIT_G();
G.filename = "/etc/mdev.conf";
bb_sanitize_stdio();
umask(0);
xchdir("/dev");--------------------------------------------------?????????/dev??
if (argv[1] && strcmp(argv[1], "-s") == 0) {---------------------mdev -s?????/sys/dev???????
/*
* Scan: mdev -s
*/
struct stat st;
/* Same as xrealloc_vector(NULL, 4, 0): */
G.rule_vec = xzalloc((1 << 4) * sizeof(*G.rule_vec));
xstat("/", &st);
G.root_major = major(st.st_dev);
G.root_minor = minor(st.st_dev);
putenv((char*)"ACTION=add");
/* Create all devices from /sys/dev hierarchy */
recursive_action("/sys/dev",
ACTION_RECURSE | ACTION_FOLLOWLINKS,
fileAction, dirAction, temp, 0);----------------????????????/sys/dev??????????dev??????/etc/mdev.con??????????
} else {
char *fw;
char *seq;
char *action;
char *env_devname;
char *env_devpath;
unsigned my_pid;
unsigned seqnum = seqnum; /* for compiler */
int seq_fd;
smalluint op;
/* Hotplug:
* env ACTION=... DEVPATH=... SUBSYSTEM=... [SEQNUM=...] mdev
* ACTION can be "add", "remove", "change"
* DEVPATH is like "/block/sda" or "/class/input/mice"
*/
env_devname = getenv("DEVNAME"); /* can be NULL */----------????kobject_uevent_env()?????????????????do_execve()????mdev????getenv????
G.subsystem = getenv("SUBSYSTEM");
action = getenv("ACTION");
env_devpath = getenv("DEVPATH");
if (!action || !env_devpath /*|| !G.subsystem*/)
bb_show_usage();
fw = getenv("FIRMWARE");
seq = getenv("SEQNUM");
op = index_in_strings(keywords, action);--------------------keywords???add?remove???op???OP_add?OP_remove?
... snprintf(temp, PATH_MAX, "/sys%s", env_devpath); if (op == OP_remove) { /* Ignoring "remove firmware". It was reported * to happen and to cause erroneous deletion * of device nodes. */ if (!fw) make_device(env_devname, temp, op);-----------------?temp????????env_devnam?????? } else { make_device(env_devname, temp, op);---------------------??temp??????env_devname???? if (ENABLE_FEATURE_MDEV_LOAD_FIRMWARE) { if (op == OP_add && fw) load_firmware(fw, temp);------------------------?fw?????temp???? } } ... }
if (ENABLE_FEATURE_CLEAN_UP)
RELEASE_CONFIG_BUFFER(temp);
return EXIT_SUCCESS;
}