最新消息:热烈庆祝IT小记上线!

/sys/power创建

kernel/power/main.c代码:

power_attr定义:

#define power_attr(_name) \
static struct kobj_attribute _name##_attr = {	\
	.attr	= {				\
		.name = __stringify(_name),	\
		.mode = 0644,			\
	},					\
	.show	= _name##_show,			\
	.store	= _name##_store,		\
}

当定义power_attr(state)时,

.show = state_show,

.store = state_store.

static struct attribute * g[] = {
	&state_attr.attr,
#ifdef CONFIG_PM_TRACE
	&pm_trace_attr.attr,
	&pm_trace_dev_match_attr.attr,
#endif
#ifdef CONFIG_PM_SLEEP
	&pm_async_attr.attr,
	&wakeup_count_attr.attr,
#ifdef CONFIG_PM_DEBUG
	&pm_test_attr.attr,
#endif
#ifdef CONFIG_USER_WAKELOCK
	&wake_lock_attr.attr,
	&wake_unlock_attr.attr,
#endif
#endif
	NULL,
};

static struct attribute_group attr_group = {
	.attrs = g,
};

上面代码定义了attribute_group,在pm_init()函数中创建了/sys/power下的文件:

static int __init pm_init(void)
{
	int error = pm_start_workqueue();
	if (error)
		return error;
	hibernate_image_size_init();
	hibernate_reserved_size_init();
	power_kobj = kobject_create_and_add("power", NULL);
	if (!power_kobj)
		return -ENOMEM;
	return sysfs_create_group(power_kobj, &attr_group);
}

在用户层,使用命令“ls /sys/power”,控制台显示:

pm_async
pm_test
state
wait_for_fb_sleep
wait_for_fb_wake
wake_lock
wake_unlock
wakeup_count

这些文件即是kernel/power/main.c创建的。



上一篇 Linux init系统

猜您喜欢

备案号:苏ICP备12016861号-4