mdev : bug corrected (patch attached) - recursive_action version

souf souf_oued at yahoo.fr
Wed Jun 13 21:01:56 UTC 2007


Hi all,
waow! there was change, it is well even if my patch was not chosen to
improve mdev !?

in mdev.c (svn):
>#define MAX_SYSFS_DEPTH 3 /* prevent infinite loops in /sys symlinks */
>...
>static int fileAction(const char *fileName, struct stat *statbuf, void *userData, int depth)
>...
>static int dirAction(const char *fileName, struct stat *statbuf, void *userData, int depth)
>...
>		root_minor = minor(st.st_dev);
>
>		recursive_action("/sys/block",
>			ACTION_RECURSE | ACTION_FOLLOWLINKS,
>			fileAction, dirAction, temp, 0);
>
>		recursive_action("/sys/class",
>			ACTION_RECURSE | ACTION_FOLLOWLINKS,
>			fileAction, dirAction, temp, 0);
>
>	/* Hotplug */

if I understands well, mdev must make 3 recursions in each first
sysmlink !!!
I had chosen this solution: NO ACTION_FOLLOWLINKS, NO SUBSYSTEM

>static int fileAction(const char *fileName, struct stat *statbuf, void *userData, int depth)
>{
>	char *last;
>
>	last = bb_get_last_path_component((char *)fileName);
>
>	if (S_ISLNK(statbuf->st_mode) && strcmp(last, "subsystem")) {
>		RESERVE_CONFIG_BUFFER(device_path, PATH_MAX);
>
>		realpath(fileName, device_path);
>		make_device(device_path, 0);
>		free(device_path);
>		return TRUE;
>	}
>
>	if (!strcmp(last, "dev")) {
>		char *tmp_name;
>
>		tmp_name = strndupa(fileName, strlen(fileName) - 4);
>		make_device(tmp_name, 0);
>		return TRUE;
>	}
>
>	return FALSE;
>}
>...
>int mdev_main(int argc, char **argv)
>...
>		root_major = major(st.st_dev);
>		root_minor = minor(st.st_dev);
>		strcpy(temp, "/sys/block");
>		recursive_action(temp, ACTION_RECURSE, fileAction, 0, NULL, 0);
>		strcpy(temp, "/sys/class");
>		recursive_action(temp, ACTION_RECURSE, fileAction, 0, NULL, 0);

example (kernel >= 2.6.20 without CONFIG_SYSFS_DEPRECATED [= n]):
/sys/class/sound/timer : timer is a symlink towards ../../devices/virtual/sound/timer
realpath(symlink, device_path);
device_path = /sys/devices/virtual/sound/timer
make_device(/sys/devices/virtual/sound/timer, 0);

I believe that this is quicker than to do 3 recursions.

mdev (svn) cannot create devices in directories, neither subdirs  nor symlinks



>void load_firmware(const char * const firmware, const char * const sysfs_path)

Really great work for load_firmware function.

Thanks

Malek (Souf)





More information about the busybox mailing list