linux/samples/configfs/configfs_sample.c

// 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.
 */

#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/configfs.h>

/*
 * 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 {};

static inline struct childless *to_childless(struct config_item *item)
{}

static ssize_t childless_showme_show(struct config_item *item, char *page)
{}

static ssize_t childless_storeme_show(struct config_item *item, char *page)
{}

static ssize_t childless_storeme_store(struct config_item *item,
		const char *page, size_t count)
{}

static ssize_t childless_description_show(struct config_item *item, char *page)
{}

CONFIGFS_ATTR_RO();
CONFIGFS_ATTR();
CONFIGFS_ATTR_RO();

static struct configfs_attribute *childless_attrs[] =;

static const struct config_item_type childless_type =;

static struct childless childless_subsys =;

/* ----------------------------------------------------------------- */

/*
 * 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 {};

static inline struct simple_child *to_simple_child(struct config_item *item)
{}

static ssize_t simple_child_storeme_show(struct config_item *item, char *page)
{}

static ssize_t simple_child_storeme_store(struct config_item *item,
		const char *page, size_t count)
{}

CONFIGFS_ATTR();

static struct configfs_attribute *simple_child_attrs[] =;

static void simple_child_release(struct config_item *item)
{}

static struct configfs_item_operations simple_child_item_ops =;

static const struct config_item_type simple_child_type =;

struct simple_children {};

static inline struct simple_children *to_simple_children(struct config_item *item)
{}

static struct config_item *simple_children_make_item(struct config_group *group,
		const char *name)
{}

static ssize_t simple_children_description_show(struct config_item *item,
		char *page)
{}

CONFIGFS_ATTR_RO();

static struct configfs_attribute *simple_children_attrs[] =;

static void simple_children_release(struct config_item *item)
{}

static struct configfs_item_operations simple_children_item_ops =;

/*
 * Note that, since no extra work is required on ->drop_item(),
 * no ->drop_item() is provided.
 */
static struct configfs_group_operations simple_children_group_ops =;

static const struct config_item_type simple_children_type =;

static struct configfs_subsystem simple_children_subsys =;

/* ----------------------------------------------------------------- */

/*
 * 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.
 */

static struct config_group *group_children_make_group(
		struct config_group *group, const char *name)
{}

static ssize_t group_children_description_show(struct config_item *item,
		char *page)
{}

CONFIGFS_ATTR_RO();

static struct configfs_attribute *group_children_attrs[] =;

/*
 * Note that, since no extra work is required on ->drop_item(),
 * no ->drop_item() is provided.
 */
static struct configfs_group_operations group_children_group_ops =;

static const struct config_item_type group_children_type =;

static struct configfs_subsystem group_children_subsys =;

/* ----------------------------------------------------------------- */

/*
 * 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.
 */
static struct configfs_subsystem *example_subsys[] =;

static int __init configfs_example_init(void)
{}

static void __exit configfs_example_exit(void)
{}

module_init(configfs_example_init);
module_exit(configfs_example_exit);
MODULE_DESCRIPTION();
MODULE_LICENSE();