// SPDX-License-Identifier: GPL-2.0-or-later /* * configfs_example_macros.c - This file is a demonstration module * containing a number of configfs subsystems. It uses the helper * macros defined by configfs.h * * Based on sysfs: * sysfs is Copyright (C) 2001, 2002, 2003 Patrick Mochel * * configfs Copyright (C) 2005 Oracle. All rights reserved.
*/
/* * 01-childless * * This first example is a childless subsystem. It cannot create * any config_items. It just has attributes. * * Note that we are enclosing the configfs_subsystem inside a container. * This is not necessary if a subsystem has no attributes directly * on the subsystem. See the next example, 02-simple-children, for * such a subsystem.
*/
struct childless { struct configfs_subsystem subsys; int showme; int storeme;
};
ret = kstrtoint(page, 10, &childless->storeme); if (ret) return ret;
return count;
}
static ssize_t childless_description_show(struct config_item *item, char *page)
{ return sprintf(page, "[01-childless]\n" "\n" "The childless subsystem is the simplest possible subsystem in\n" "configfs. It does not support the creation of child config_items.\n" "It only has a few attributes. In fact, it isn't much different\n" "than a directory in /proc.\n");
}
/* * 02-simple-children * * This example merely has a simple one-attribute child. Note that * there is no extra attribute structure, as the child's attribute is * known from the get-go. Also, there is no container for the * subsystem, as it has no attributes of its own.
*/
struct simple_child { struct config_item item; int storeme;
};
static ssize_t simple_children_description_show(struct config_item *item, char *page)
{ return sprintf(page, "[02-simple-children]\n" "\n" "This subsystem allows the creation of child config_items. These\n" "items have only one attribute that is readable and writeable.\n");
}
/* * Note that, since no extra work is required on ->drop_item(), * no ->drop_item() is provided.
*/ staticstruct configfs_group_operations simple_children_group_ops = {
.make_item = simple_children_make_item,
};
/* * 03-group-children * * This example reuses the simple_children group from above. However, * the simple_children group is not the subsystem itself, it is a * child of the subsystem. Creation of a group in the subsystem creates * a new simple_children group. That group can then have simple_child * children of its own.
*/
/* * Note that, since no extra work is required on ->drop_item(), * no ->drop_item() is provided.
*/ staticstruct configfs_group_operations group_children_group_ops = {
.make_group = group_children_make_group,
};
/* * We're now done with our subsystem definitions. * For convenience in this module, here's a list of them all. It * allows the init function to easily register them. Most modules * will only have one subsystem, and will only call register_subsystem * on it directly.
*/ staticstruct configfs_subsystem *example_subsys[] = {
&childless_subsys.subsys,
&simple_children_subsys,
&group_children_subsys,
NULL,
};
staticint __init configfs_example_init(void)
{ struct configfs_subsystem *subsys; int ret, i;
for (i = 0; example_subsys[i]; i++) {
subsys = example_subsys[i];
config_group_init(&subsys->su_group);
mutex_init(&subsys->su_mutex);
ret = configfs_register_subsystem(subsys); if (ret) {
pr_err("Error %d while registering subsystem %s\n",
ret, subsys->su_group.cg_item.ci_namebuf); goto out_unregister;
}
}
return 0;
out_unregister: for (i--; i >= 0; i--)
configfs_unregister_subsystem(example_subsys[i]);
return ret;
}
staticvoid __exit configfs_example_exit(void)
{ int i;
for (i = 0; example_subsys[i]; i++)
configfs_unregister_subsystem(example_subsys[i]);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.