162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci *  internal.h - declarations internal to debugfs
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci *  Copyright (C) 2016 Nicolai Stange <nicstange@gmail.com>
662306a36Sopenharmony_ci */
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci#ifndef _DEBUGFS_INTERNAL_H_
962306a36Sopenharmony_ci#define _DEBUGFS_INTERNAL_H_
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_cistruct file_operations;
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci/* declared over in file.c */
1462306a36Sopenharmony_ciextern const struct file_operations debugfs_noop_file_operations;
1562306a36Sopenharmony_ciextern const struct file_operations debugfs_open_proxy_file_operations;
1662306a36Sopenharmony_ciextern const struct file_operations debugfs_full_proxy_file_operations;
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_cistruct debugfs_fsdata {
1962306a36Sopenharmony_ci	const struct file_operations *real_fops;
2062306a36Sopenharmony_ci	union {
2162306a36Sopenharmony_ci		/* automount_fn is used when real_fops is NULL */
2262306a36Sopenharmony_ci		debugfs_automount_t automount;
2362306a36Sopenharmony_ci		struct {
2462306a36Sopenharmony_ci			refcount_t active_users;
2562306a36Sopenharmony_ci			struct completion active_users_drained;
2662306a36Sopenharmony_ci		};
2762306a36Sopenharmony_ci	};
2862306a36Sopenharmony_ci};
2962306a36Sopenharmony_ci
3062306a36Sopenharmony_ci/*
3162306a36Sopenharmony_ci * A dentry's ->d_fsdata either points to the real fops or to a
3262306a36Sopenharmony_ci * dynamically allocated debugfs_fsdata instance.
3362306a36Sopenharmony_ci * In order to distinguish between these two cases, a real fops
3462306a36Sopenharmony_ci * pointer gets its lowest bit set.
3562306a36Sopenharmony_ci */
3662306a36Sopenharmony_ci#define DEBUGFS_FSDATA_IS_REAL_FOPS_BIT BIT(0)
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci/* Access BITS */
3962306a36Sopenharmony_ci#define DEBUGFS_ALLOW_API	BIT(0)
4062306a36Sopenharmony_ci#define DEBUGFS_ALLOW_MOUNT	BIT(1)
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci#ifdef CONFIG_DEBUG_FS_ALLOW_ALL
4362306a36Sopenharmony_ci#define DEFAULT_DEBUGFS_ALLOW_BITS (DEBUGFS_ALLOW_MOUNT | DEBUGFS_ALLOW_API)
4462306a36Sopenharmony_ci#endif
4562306a36Sopenharmony_ci#ifdef CONFIG_DEBUG_FS_DISALLOW_MOUNT
4662306a36Sopenharmony_ci#define DEFAULT_DEBUGFS_ALLOW_BITS (DEBUGFS_ALLOW_API)
4762306a36Sopenharmony_ci#endif
4862306a36Sopenharmony_ci#ifdef CONFIG_DEBUG_FS_ALLOW_NONE
4962306a36Sopenharmony_ci#define DEFAULT_DEBUGFS_ALLOW_BITS (0)
5062306a36Sopenharmony_ci#endif
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ci#endif /* _DEBUGFS_INTERNAL_H_ */
53