mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-04-13 09:59:31 +00:00
debugfs: allow to store an additional opaque pointer at file creation
Set by debugfs_create_file_aux(name, mode, parent, data, aux, fops). Plain debugfs_create_file() has it set to NULL. Accessed by debugfs_get_aux(file). Convenience macros for numeric opaque data - debugfs_create_file_aux_num and debugfs_get_aux_num, resp. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> Reviewed-by: Christian Brauner <brauner@kernel.org> Link: https://lore.kernel.org/r/20250112080705.141166-5-viro@zeniv.linux.org.uk Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
95688800ee
commit
12c9209893
4 changed files with 42 additions and 6 deletions
|
@ -47,6 +47,12 @@ const struct file_operations debugfs_noop_file_operations = {
|
||||||
|
|
||||||
#define F_DENTRY(filp) ((filp)->f_path.dentry)
|
#define F_DENTRY(filp) ((filp)->f_path.dentry)
|
||||||
|
|
||||||
|
const void *debugfs_get_aux(const struct file *file)
|
||||||
|
{
|
||||||
|
return DEBUGFS_I(file_inode(file))->aux;
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL_GPL(debugfs_get_aux);
|
||||||
|
|
||||||
const struct file_operations *debugfs_real_fops(const struct file *filp)
|
const struct file_operations *debugfs_real_fops(const struct file *filp)
|
||||||
{
|
{
|
||||||
struct debugfs_fsdata *fsd = F_DENTRY(filp)->d_fsdata;
|
struct debugfs_fsdata *fsd = F_DENTRY(filp)->d_fsdata;
|
||||||
|
|
|
@ -424,6 +424,7 @@ static struct dentry *end_creating(struct dentry *dentry)
|
||||||
|
|
||||||
static struct dentry *__debugfs_create_file(const char *name, umode_t mode,
|
static struct dentry *__debugfs_create_file(const char *name, umode_t mode,
|
||||||
struct dentry *parent, void *data,
|
struct dentry *parent, void *data,
|
||||||
|
const void *aux,
|
||||||
const struct file_operations *proxy_fops,
|
const struct file_operations *proxy_fops,
|
||||||
const void *real_fops)
|
const void *real_fops)
|
||||||
{
|
{
|
||||||
|
@ -458,6 +459,7 @@ static struct dentry *__debugfs_create_file(const char *name, umode_t mode,
|
||||||
proxy_fops = &debugfs_noop_file_operations;
|
proxy_fops = &debugfs_noop_file_operations;
|
||||||
inode->i_fop = proxy_fops;
|
inode->i_fop = proxy_fops;
|
||||||
DEBUGFS_I(inode)->raw = real_fops;
|
DEBUGFS_I(inode)->raw = real_fops;
|
||||||
|
DEBUGFS_I(inode)->aux = aux;
|
||||||
|
|
||||||
d_instantiate(dentry, inode);
|
d_instantiate(dentry, inode);
|
||||||
fsnotify_create(d_inode(dentry->d_parent), dentry);
|
fsnotify_create(d_inode(dentry->d_parent), dentry);
|
||||||
|
@ -466,19 +468,21 @@ static struct dentry *__debugfs_create_file(const char *name, umode_t mode,
|
||||||
|
|
||||||
struct dentry *debugfs_create_file_full(const char *name, umode_t mode,
|
struct dentry *debugfs_create_file_full(const char *name, umode_t mode,
|
||||||
struct dentry *parent, void *data,
|
struct dentry *parent, void *data,
|
||||||
|
const void *aux,
|
||||||
const struct file_operations *fops)
|
const struct file_operations *fops)
|
||||||
{
|
{
|
||||||
return __debugfs_create_file(name, mode, parent, data,
|
return __debugfs_create_file(name, mode, parent, data, aux,
|
||||||
&debugfs_full_proxy_file_operations,
|
&debugfs_full_proxy_file_operations,
|
||||||
fops);
|
fops);
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(debugfs_create_file_full);
|
EXPORT_SYMBOL_GPL(debugfs_create_file_full);
|
||||||
|
|
||||||
struct dentry *debugfs_create_file_short(const char *name, umode_t mode,
|
struct dentry *debugfs_create_file_short(const char *name, umode_t mode,
|
||||||
struct dentry *parent, void *data,
|
struct dentry *parent, void *data,
|
||||||
const struct debugfs_short_fops *fops)
|
const void *aux,
|
||||||
|
const struct debugfs_short_fops *fops)
|
||||||
{
|
{
|
||||||
return __debugfs_create_file(name, mode, parent, data,
|
return __debugfs_create_file(name, mode, parent, data, aux,
|
||||||
&debugfs_full_short_proxy_file_operations,
|
&debugfs_full_short_proxy_file_operations,
|
||||||
fops);
|
fops);
|
||||||
}
|
}
|
||||||
|
@ -516,7 +520,7 @@ struct dentry *debugfs_create_file_unsafe(const char *name, umode_t mode,
|
||||||
const struct file_operations *fops)
|
const struct file_operations *fops)
|
||||||
{
|
{
|
||||||
|
|
||||||
return __debugfs_create_file(name, mode, parent, data,
|
return __debugfs_create_file(name, mode, parent, data, NULL,
|
||||||
&debugfs_open_proxy_file_operations,
|
&debugfs_open_proxy_file_operations,
|
||||||
fops);
|
fops);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ struct debugfs_inode_info {
|
||||||
const struct debugfs_short_fops *short_fops;
|
const struct debugfs_short_fops *short_fops;
|
||||||
debugfs_automount_t automount;
|
debugfs_automount_t automount;
|
||||||
};
|
};
|
||||||
|
const void *aux;
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline struct debugfs_inode_info *DEBUGFS_I(struct inode *inode)
|
static inline struct debugfs_inode_info *DEBUGFS_I(struct inode *inode)
|
||||||
|
|
|
@ -79,9 +79,11 @@ struct debugfs_short_fops {
|
||||||
|
|
||||||
struct dentry *debugfs_create_file_full(const char *name, umode_t mode,
|
struct dentry *debugfs_create_file_full(const char *name, umode_t mode,
|
||||||
struct dentry *parent, void *data,
|
struct dentry *parent, void *data,
|
||||||
|
const void *aux,
|
||||||
const struct file_operations *fops);
|
const struct file_operations *fops);
|
||||||
struct dentry *debugfs_create_file_short(const char *name, umode_t mode,
|
struct dentry *debugfs_create_file_short(const char *name, umode_t mode,
|
||||||
struct dentry *parent, void *data,
|
struct dentry *parent, void *data,
|
||||||
|
const void *aux,
|
||||||
const struct debugfs_short_fops *fops);
|
const struct debugfs_short_fops *fops);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -126,7 +128,15 @@ struct dentry *debugfs_create_file_short(const char *name, umode_t mode,
|
||||||
const struct debugfs_short_fops *: debugfs_create_file_short, \
|
const struct debugfs_short_fops *: debugfs_create_file_short, \
|
||||||
struct file_operations *: debugfs_create_file_full, \
|
struct file_operations *: debugfs_create_file_full, \
|
||||||
struct debugfs_short_fops *: debugfs_create_file_short) \
|
struct debugfs_short_fops *: debugfs_create_file_short) \
|
||||||
(name, mode, parent, data, fops)
|
(name, mode, parent, data, NULL, fops)
|
||||||
|
|
||||||
|
#define debugfs_create_file_aux(name, mode, parent, data, aux, fops) \
|
||||||
|
_Generic(fops, \
|
||||||
|
const struct file_operations *: debugfs_create_file_full, \
|
||||||
|
const struct debugfs_short_fops *: debugfs_create_file_short, \
|
||||||
|
struct file_operations *: debugfs_create_file_full, \
|
||||||
|
struct debugfs_short_fops *: debugfs_create_file_short) \
|
||||||
|
(name, mode, parent, data, aux, fops)
|
||||||
|
|
||||||
struct dentry *debugfs_create_file_unsafe(const char *name, umode_t mode,
|
struct dentry *debugfs_create_file_unsafe(const char *name, umode_t mode,
|
||||||
struct dentry *parent, void *data,
|
struct dentry *parent, void *data,
|
||||||
|
@ -153,6 +163,7 @@ void debugfs_remove(struct dentry *dentry);
|
||||||
void debugfs_lookup_and_remove(const char *name, struct dentry *parent);
|
void debugfs_lookup_and_remove(const char *name, struct dentry *parent);
|
||||||
|
|
||||||
const struct file_operations *debugfs_real_fops(const struct file *filp);
|
const struct file_operations *debugfs_real_fops(const struct file *filp);
|
||||||
|
const void *debugfs_get_aux(const struct file *file);
|
||||||
|
|
||||||
int debugfs_file_get(struct dentry *dentry);
|
int debugfs_file_get(struct dentry *dentry);
|
||||||
void debugfs_file_put(struct dentry *dentry);
|
void debugfs_file_put(struct dentry *dentry);
|
||||||
|
@ -259,6 +270,14 @@ static inline struct dentry *debugfs_lookup(const char *name,
|
||||||
return ERR_PTR(-ENODEV);
|
return ERR_PTR(-ENODEV);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline struct dentry *debugfs_create_file_aux(const char *name,
|
||||||
|
umode_t mode, struct dentry *parent,
|
||||||
|
void *data, void *aux,
|
||||||
|
const void *fops)
|
||||||
|
{
|
||||||
|
return ERR_PTR(-ENODEV);
|
||||||
|
}
|
||||||
|
|
||||||
static inline struct dentry *debugfs_create_file(const char *name, umode_t mode,
|
static inline struct dentry *debugfs_create_file(const char *name, umode_t mode,
|
||||||
struct dentry *parent, void *data,
|
struct dentry *parent, void *data,
|
||||||
const void *fops)
|
const void *fops)
|
||||||
|
@ -312,6 +331,7 @@ static inline void debugfs_lookup_and_remove(const char *name,
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
const struct file_operations *debugfs_real_fops(const struct file *filp);
|
const struct file_operations *debugfs_real_fops(const struct file *filp);
|
||||||
|
void *debugfs_get_aux(const struct file *file);
|
||||||
|
|
||||||
static inline int debugfs_file_get(struct dentry *dentry)
|
static inline int debugfs_file_get(struct dentry *dentry)
|
||||||
{
|
{
|
||||||
|
@ -452,6 +472,11 @@ static inline ssize_t debugfs_read_file_str(struct file *file,
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define debugfs_create_file_aux_num(name, mode, parent, data, n, fops) \
|
||||||
|
debugfs_create_file_aux(name, mode, parent, data, \
|
||||||
|
(void *)(unsigned long)n, fops)
|
||||||
|
#define debugfs_get_aux_num(f) (unsigned long)debugfs_get_aux(f)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* debugfs_create_xul - create a debugfs file that is used to read and write an
|
* debugfs_create_xul - create a debugfs file that is used to read and write an
|
||||||
* unsigned long value, formatted in hexadecimal
|
* unsigned long value, formatted in hexadecimal
|
||||||
|
|
Loading…
Add table
Reference in a new issue