Subject: + seq_file-introduce-seq_setwidth-and-seq_pad.patch added to -mm tree To: penguin-kernel@xxxxxxxxxxxxxxxxxxx,davem@xxxxxxxxxxxxx,joe@xxxxxxxxxxx,keescook@xxxxxxxxxxxx From: akpm@xxxxxxxxxxxxxxxxxxxx Date: Tue, 08 Oct 2013 13:30:38 -0700 The patch titled Subject: seq_file: introduce seq_setwidth() and seq_pad() has been added to the -mm tree. Its filename is seq_file-introduce-seq_setwidth-and-seq_pad.patch This patch should soon appear at http://ozlabs.org/~akpm/mmots/broken-out/seq_file-introduce-seq_setwidth-and-seq_pad.patch and later at http://ozlabs.org/~akpm/mmotm/broken-out/seq_file-introduce-seq_setwidth-and-seq_pad.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/SubmitChecklist when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Tetsuo Handa <penguin-kernel@xxxxxxxxxxxxxxxxxxx> Subject: seq_file: introduce seq_setwidth() and seq_pad() There are several users who want to know bytes written by seq_*() for alignment purpose. Currently they are using %n format for knowing it because seq_*() returns 0 on success. This patch introduces seq_setwidth() and seq_pad() for allowing them to align without using %n format. Signed-off-by: Tetsuo Handa <penguin-kernel@xxxxxxxxxxxxxxxxxxx> Signed-off-by: Kees Cook <keescook@xxxxxxxxxxxx> Cc: Joe Perches <joe@xxxxxxxxxxx> Cc: David Miller <davem@xxxxxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- fs/seq_file.c | 15 +++++++++++++++ include/linux/seq_file.h | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff -puN fs/seq_file.c~seq_file-introduce-seq_setwidth-and-seq_pad fs/seq_file.c --- a/fs/seq_file.c~seq_file-introduce-seq_setwidth-and-seq_pad +++ a/fs/seq_file.c @@ -764,6 +764,21 @@ int seq_write(struct seq_file *seq, cons } EXPORT_SYMBOL(seq_write); +/** + * seq_pad - write padding spaces to buffer + * @m: seq_file identifying the buffer to which data should be written + * @c: the byte to append after padding if non-zero + */ +void seq_pad(struct seq_file *m, char c) +{ + int size = m->pad_until - m->count; + if (size > 0) + seq_printf(m, "%*s", size, ""); + if (c) + seq_putc(m, c); +} +EXPORT_SYMBOL(seq_pad); + struct list_head *seq_list_start(struct list_head *head, loff_t pos) { struct list_head *lh; diff -puN include/linux/seq_file.h~seq_file-introduce-seq_setwidth-and-seq_pad include/linux/seq_file.h --- a/include/linux/seq_file.h~seq_file-introduce-seq_setwidth-and-seq_pad +++ a/include/linux/seq_file.h @@ -20,6 +20,7 @@ struct seq_file { size_t size; size_t from; size_t count; + size_t pad_until; loff_t index; loff_t read_pos; u64 version; @@ -79,6 +80,20 @@ static inline void seq_commit(struct seq } } +/** + * seq_setwidth - set padding width + * @m: the seq_file handle + * @size: the max number of bytes to pad. + * + * Call seq_setwidth() for setting max width, then call seq_printf() etc. and + * finally call seq_pad() to pad the remaining bytes. + */ +static inline void seq_setwidth(struct seq_file *m, size_t size) +{ + m->pad_until = m->count + size; +} +void seq_pad(struct seq_file *m, char c); + char *mangle_path(char *s, const char *p, const char *esc); int seq_open(struct file *, const struct seq_operations *); ssize_t seq_read(struct file *, char __user *, size_t, loff_t *); _ Patches currently in -mm which might be from penguin-kernel@xxxxxxxxxxxxxxxxxxx are kthread-make-kthread_create-killable.patch seq_file-introduce-seq_setwidth-and-seq_pad.patch seq_file-remove-%n-usage-from-seq_file-users.patch vsprintf-ignore-%n-again.patch -- To unsubscribe from this list: send the line "unsubscribe mm-commits" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html