linux/samples/kfifo/record-example.c

// SPDX-License-Identifier: GPL-2.0-only
/*
 * Sample dynamic sized record fifo implementation
 *
 * Copyright (C) 2010 Stefani Seibold <[email protected]>
 */

#include <linux/init.h>
#include <linux/module.h>
#include <linux/proc_fs.h>
#include <linux/mutex.h>
#include <linux/kfifo.h>

/*
 * This module shows how to create a variable sized record fifo.
 */

/* fifo size in elements (bytes) */
#define FIFO_SIZE

/* name of the proc entry */
#define PROC_FIFO

/* lock for procfs read access */
static DEFINE_MUTEX(read_access);

/* lock for procfs write access */
static DEFINE_MUTEX(write_access);

/*
 * define DYNAMIC in this example for a dynamically allocated fifo.
 *
 * Otherwise the fifo storage will be a part of the fifo structure.
 */
#if 0
#define DYNAMIC
#endif

/*
 * struct kfifo_rec_ptr_1 and  STRUCT_KFIFO_REC_1 can handle records of a
 * length between 0 and 255 bytes.
 *
 * struct kfifo_rec_ptr_2 and  STRUCT_KFIFO_REC_2 can handle records of a
 * length between 0 and 65535 bytes.
 */

#ifdef DYNAMIC
struct kfifo_rec_ptr_1 test;

#else
mytest;

static mytest test;
#endif

static const char *expected_result[] =;

static int __init testfunc(void)
{}

static ssize_t fifo_write(struct file *file, const char __user *buf,
						size_t count, loff_t *ppos)
{}

static ssize_t fifo_read(struct file *file, char __user *buf,
						size_t count, loff_t *ppos)
{}

static const struct proc_ops fifo_proc_ops =;

static int __init example_init(void)
{}

static void __exit example_exit(void)
{}

module_init(example_init);
module_exit(example_exit);
MODULE_DESCRIPTION();
MODULE_LICENSE();
MODULE_AUTHOR();