linux/fs/tracefs/inode.c

// SPDX-License-Identifier: GPL-2.0-only
/*
 *  inode.c - part of tracefs, a pseudo file system for activating tracing
 *
 * Based on debugfs by: Greg Kroah-Hartman <[email protected]>
 *
 *  Copyright (C) 2014 Red Hat Inc, author: Steven Rostedt <[email protected]>
 *
 * tracefs is the file system that is used by the tracing infrastructure.
 */

#include <linux/module.h>
#include <linux/fs.h>
#include <linux/fs_context.h>
#include <linux/fs_parser.h>
#include <linux/kobject.h>
#include <linux/namei.h>
#include <linux/tracefs.h>
#include <linux/fsnotify.h>
#include <linux/security.h>
#include <linux/seq_file.h>
#include <linux/magic.h>
#include <linux/slab.h>
#include "internal.h"

#define TRACEFS_DEFAULT_MODE
static struct kmem_cache *tracefs_inode_cachep __ro_after_init;

static struct vfsmount *tracefs_mount;
static int tracefs_mount_count;
static bool tracefs_registered;

/*
 * Keep track of all tracefs_inodes in order to update their
 * flags if necessary on a remount.
 */
static DEFINE_SPINLOCK(tracefs_inode_lock);
static LIST_HEAD(tracefs_inodes);

static struct inode *tracefs_alloc_inode(struct super_block *sb)
{}

static void tracefs_free_inode(struct inode *inode)
{}

static void tracefs_destroy_inode(struct inode *inode)
{}

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

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

static const struct file_operations tracefs_file_operations =;

static struct tracefs_dir_ops {} tracefs_ops __ro_after_init;

static char *get_dname(struct dentry *dentry)
{}

static int tracefs_syscall_mkdir(struct mnt_idmap *idmap,
				 struct inode *inode, struct dentry *dentry,
				 umode_t mode)
{}

static int tracefs_syscall_rmdir(struct inode *inode, struct dentry *dentry)
{}

static void set_tracefs_inode_owner(struct inode *inode)
{}

static int tracefs_permission(struct mnt_idmap *idmap,
			      struct inode *inode, int mask)
{}

static int tracefs_getattr(struct mnt_idmap *idmap,
			   const struct path *path, struct kstat *stat,
			   u32 request_mask, unsigned int flags)
{}

static int tracefs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
			   struct iattr *attr)
{}

static const struct inode_operations tracefs_instance_dir_inode_operations =;

static const struct inode_operations tracefs_dir_inode_operations =;

static const struct inode_operations tracefs_file_inode_operations =;

struct inode *tracefs_get_inode(struct super_block *sb)
{}

struct tracefs_fs_info {};

enum {};

static const struct fs_parameter_spec tracefs_param_specs[] =;

static int tracefs_parse_param(struct fs_context *fc, struct fs_parameter *param)
{}

static int tracefs_apply_options(struct super_block *sb, bool remount)
{}

static int tracefs_reconfigure(struct fs_context *fc)
{}

static int tracefs_show_options(struct seq_file *m, struct dentry *root)
{}

static int tracefs_drop_inode(struct inode *inode)
{}

static const struct super_operations tracefs_super_operations =;

/*
 * It would be cleaner if eventfs had its own dentry ops.
 *
 * Note that d_revalidate is called potentially under RCU,
 * so it can't take the eventfs mutex etc. It's fine - if
 * we open a file just as it's marked dead, things will
 * still work just fine, and just see the old stale case.
 */
static void tracefs_d_release(struct dentry *dentry)
{}

static int tracefs_d_revalidate(struct dentry *dentry, unsigned int flags)
{}

static const struct dentry_operations tracefs_dentry_operations =;

static int tracefs_fill_super(struct super_block *sb, struct fs_context *fc)
{}

static int tracefs_get_tree(struct fs_context *fc)
{}

static void tracefs_free_fc(struct fs_context *fc)
{}

static const struct fs_context_operations tracefs_context_ops =;

static int tracefs_init_fs_context(struct fs_context *fc)
{}

static struct file_system_type trace_fs_type =;
MODULE_ALIAS_FS();

struct dentry *tracefs_start_creating(const char *name, struct dentry *parent)
{}

struct dentry *tracefs_failed_creating(struct dentry *dentry)
{}

struct dentry *tracefs_end_creating(struct dentry *dentry)
{}

/* Find the inode that this will use for default */
static struct inode *instance_inode(struct dentry *parent, struct inode *inode)
{}

/**
 * tracefs_create_file - create a file in the tracefs filesystem
 * @name: a pointer to a string containing the name of the file to create.
 * @mode: the permission that the file should have.
 * @parent: a pointer to the parent dentry for this file.  This should be a
 *          directory dentry if set.  If this parameter is NULL, then the
 *          file will be created in the root of the tracefs filesystem.
 * @data: a pointer to something that the caller will want to get to later
 *        on.  The inode.i_private pointer will point to this value on
 *        the open() call.
 * @fops: a pointer to a struct file_operations that should be used for
 *        this file.
 *
 * This is the basic "create a file" function for tracefs.  It allows for a
 * wide range of flexibility in creating a file, or a directory (if you want
 * to create a directory, the tracefs_create_dir() function is
 * recommended to be used instead.)
 *
 * This function will return a pointer to a dentry if it succeeds.  This
 * pointer must be passed to the tracefs_remove() function when the file is
 * to be removed (no automatic cleanup happens if your module is unloaded,
 * you are responsible here.)  If an error occurs, %NULL will be returned.
 *
 * If tracefs is not enabled in the kernel, the value -%ENODEV will be
 * returned.
 */
struct dentry *tracefs_create_file(const char *name, umode_t mode,
				   struct dentry *parent, void *data,
				   const struct file_operations *fops)
{}

static struct dentry *__create_dir(const char *name, struct dentry *parent,
				   const struct inode_operations *ops)
{}

/**
 * tracefs_create_dir - create a directory in the tracefs filesystem
 * @name: a pointer to a string containing the name of the directory to
 *        create.
 * @parent: a pointer to the parent dentry for this file.  This should be a
 *          directory dentry if set.  If this parameter is NULL, then the
 *          directory will be created in the root of the tracefs filesystem.
 *
 * This function creates a directory in tracefs with the given name.
 *
 * This function will return a pointer to a dentry if it succeeds.  This
 * pointer must be passed to the tracefs_remove() function when the file is
 * to be removed. If an error occurs, %NULL will be returned.
 *
 * If tracing is not enabled in the kernel, the value -%ENODEV will be
 * returned.
 */
struct dentry *tracefs_create_dir(const char *name, struct dentry *parent)
{}

/**
 * tracefs_create_instance_dir - create the tracing instances directory
 * @name: The name of the instances directory to create
 * @parent: The parent directory that the instances directory will exist
 * @mkdir: The function to call when a mkdir is performed.
 * @rmdir: The function to call when a rmdir is performed.
 *
 * Only one instances directory is allowed.
 *
 * The instances directory is special as it allows for mkdir and rmdir
 * to be done by userspace. When a mkdir or rmdir is performed, the inode
 * locks are released and the methods passed in (@mkdir and @rmdir) are
 * called without locks and with the name of the directory being created
 * within the instances directory.
 *
 * Returns the dentry of the instances directory.
 */
__init struct dentry *tracefs_create_instance_dir(const char *name,
					  struct dentry *parent,
					  int (*mkdir)(const char *name),
					  int (*rmdir)(const char *name))
{}

static void remove_one(struct dentry *victim)
{}

/**
 * tracefs_remove - recursively removes a directory
 * @dentry: a pointer to a the dentry of the directory to be removed.
 *
 * This function recursively removes a directory tree in tracefs that
 * was previously created with a call to another tracefs function
 * (like tracefs_create_file() or variants thereof.)
 */
void tracefs_remove(struct dentry *dentry)
{}

/**
 * tracefs_initialized - Tells whether tracefs has been registered
 */
bool tracefs_initialized(void)
{}

static void init_once(void *foo)
{}

static int __init tracefs_init(void)
{}
core_initcall(tracefs_init);