162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci#ifndef _TRACEFS_INTERNAL_H
362306a36Sopenharmony_ci#define _TRACEFS_INTERNAL_H
462306a36Sopenharmony_ci
562306a36Sopenharmony_cienum {
662306a36Sopenharmony_ci	TRACEFS_EVENT_INODE		= BIT(1),
762306a36Sopenharmony_ci	TRACEFS_EVENT_TOP_INODE		= BIT(2),
862306a36Sopenharmony_ci	TRACEFS_GID_PERM_SET		= BIT(3),
962306a36Sopenharmony_ci	TRACEFS_UID_PERM_SET		= BIT(4),
1062306a36Sopenharmony_ci	TRACEFS_INSTANCE_INODE		= BIT(5),
1162306a36Sopenharmony_ci};
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_cistruct tracefs_inode {
1462306a36Sopenharmony_ci	struct inode            vfs_inode;
1562306a36Sopenharmony_ci	/* The below gets initialized with memset_after(ti, 0, vfs_inode) */
1662306a36Sopenharmony_ci	unsigned long           flags;
1762306a36Sopenharmony_ci	void                    *private;
1862306a36Sopenharmony_ci};
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci/*
2162306a36Sopenharmony_ci * struct eventfs_attr - cache the mode and ownership of a eventfs entry
2262306a36Sopenharmony_ci * @mode:	saved mode plus flags of what is saved
2362306a36Sopenharmony_ci * @uid:	saved uid if changed
2462306a36Sopenharmony_ci * @gid:	saved gid if changed
2562306a36Sopenharmony_ci */
2662306a36Sopenharmony_cistruct eventfs_attr {
2762306a36Sopenharmony_ci	int				mode;
2862306a36Sopenharmony_ci	kuid_t				uid;
2962306a36Sopenharmony_ci	kgid_t				gid;
3062306a36Sopenharmony_ci};
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ci/*
3362306a36Sopenharmony_ci * struct eventfs_inode - hold the properties of the eventfs directories.
3462306a36Sopenharmony_ci * @list:	link list into the parent directory
3562306a36Sopenharmony_ci * @rcu:	Union with @list for freeing
3662306a36Sopenharmony_ci * @children:	link list into the child eventfs_inode
3762306a36Sopenharmony_ci * @entries:	the array of entries representing the files in the directory
3862306a36Sopenharmony_ci * @name:	the name of the directory to create
3962306a36Sopenharmony_ci * @events_dir: the dentry of the events directory
4062306a36Sopenharmony_ci * @entry_attrs: Saved mode and ownership of the @d_children
4162306a36Sopenharmony_ci * @data:	The private data to pass to the callbacks
4262306a36Sopenharmony_ci * @attr:	Saved mode and ownership of eventfs_inode itself
4362306a36Sopenharmony_ci * @is_freed:	Flag set if the eventfs is on its way to be freed
4462306a36Sopenharmony_ci *                Note if is_freed is set, then dentry is corrupted.
4562306a36Sopenharmony_ci * @is_events:	Flag set for only the top level "events" directory
4662306a36Sopenharmony_ci * @nr_entries: The number of items in @entries
4762306a36Sopenharmony_ci * @ino:	The saved inode number
4862306a36Sopenharmony_ci */
4962306a36Sopenharmony_cistruct eventfs_inode {
5062306a36Sopenharmony_ci	union {
5162306a36Sopenharmony_ci		struct list_head	list;
5262306a36Sopenharmony_ci		struct rcu_head		rcu;
5362306a36Sopenharmony_ci	};
5462306a36Sopenharmony_ci	struct list_head		children;
5562306a36Sopenharmony_ci	const struct eventfs_entry	*entries;
5662306a36Sopenharmony_ci	const char			*name;
5762306a36Sopenharmony_ci	struct dentry			*events_dir;
5862306a36Sopenharmony_ci	struct eventfs_attr		*entry_attrs;
5962306a36Sopenharmony_ci	void				*data;
6062306a36Sopenharmony_ci	struct eventfs_attr		attr;
6162306a36Sopenharmony_ci	struct kref			kref;
6262306a36Sopenharmony_ci	unsigned int			is_freed:1;
6362306a36Sopenharmony_ci	unsigned int			is_events:1;
6462306a36Sopenharmony_ci	unsigned int			nr_entries:30;
6562306a36Sopenharmony_ci	unsigned int			ino;
6662306a36Sopenharmony_ci};
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_cistatic inline struct tracefs_inode *get_tracefs(const struct inode *inode)
6962306a36Sopenharmony_ci{
7062306a36Sopenharmony_ci	return container_of(inode, struct tracefs_inode, vfs_inode);
7162306a36Sopenharmony_ci}
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_cistruct dentry *tracefs_start_creating(const char *name, struct dentry *parent);
7462306a36Sopenharmony_cistruct dentry *tracefs_end_creating(struct dentry *dentry);
7562306a36Sopenharmony_cistruct dentry *tracefs_failed_creating(struct dentry *dentry);
7662306a36Sopenharmony_cistruct inode *tracefs_get_inode(struct super_block *sb);
7762306a36Sopenharmony_ci
7862306a36Sopenharmony_civoid eventfs_d_release(struct dentry *dentry);
7962306a36Sopenharmony_ci
8062306a36Sopenharmony_ci#endif /* _TRACEFS_INTERNAL_H */
81