Re: [PATCH 2/3] proc: Add a way to make network proc files writable
From: Christoph Hellwig
Date: Tue May 15 2018 - 13:38:50 EST
On Tue, May 01, 2018 at 12:20:33AM +0100, David Howells wrote:
> Provide two extra functions, proc_create_net_data_write() and
> proc_create_net_single_write() that act like their non-write versions but
> also set a write method in the proc_dir_entry struct.
>
> An internal simple write function is provided that will copy its buffer and
> hand it to the pde->write() method if available (or give an error if not).
> The buffer may be modified by the write method.
I thought of doing something like this, aÑ it would remove tons of
boilerplat code from a lot of procfs instances. But I'd also like to
hear what Al and Alexey think of it. We also should offer this for
non-net proc users as well.
> +struct proc_dir_entry *proc_create_net_data_write(const char *name, umode_t mode,
> + struct proc_dir_entry *parent,
> + const struct seq_operations *ops,
> + proc_write_t write,
> + unsigned int state_size, void *data)
> +{
The other option I though about would be to hide a write callback
in struct seq_operations, as that way all the existing helpers would
just work.
Btw one of the lines above is over 80 chars. By using normal two
tab indents for the continuations this would become a lot more readable:
struct proc_dir_entry *proc_create_net_data_write(const char *name,
umode_t mode, struct proc_dir_entry *parent,
const struct seq_operations *ops, proc_write_t write,
unsigned int state_size, void *data)