Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * linux/fs/seq_file.c |
| 4 | * |
| 5 | * helper functions for making synthetic files from sequences of records. |
| 6 | * initial implementation -- AV, Oct 2001. |
| 7 | */ |
| 8 | |
Joe Perches | a396301 | 2020-06-04 16:51:02 -0700 | [diff] [blame] | 9 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 10 | |
Alexey Dobriyan | 096523203 | 2018-04-10 16:34:45 -0700 | [diff] [blame] | 11 | #include <linux/cache.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/fs.h> |
Paul Gortmaker | 630d9c4 | 2011-11-16 23:57:37 -0500 | [diff] [blame] | 13 | #include <linux/export.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/seq_file.h> |
Heiko Carstens | 058504e | 2014-07-02 15:22:37 -0700 | [diff] [blame] | 15 | #include <linux/vmalloc.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <linux/slab.h> |
Eric W. Biederman | adb37c4 | 2012-05-23 18:01:20 -0600 | [diff] [blame] | 17 | #include <linux/cred.h> |
Heiko Carstens | 058504e | 2014-07-02 15:22:37 -0700 | [diff] [blame] | 18 | #include <linux/mm.h> |
Andy Shevchenko | 3760710 | 2015-09-09 15:38:33 -0700 | [diff] [blame] | 19 | #include <linux/printk.h> |
Andy Shevchenko | 25c6bb7 | 2015-11-06 16:32:40 -0800 | [diff] [blame] | 20 | #include <linux/string_helpers.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 22 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <asm/page.h> |
| 24 | |
Alexey Dobriyan | 096523203 | 2018-04-10 16:34:45 -0700 | [diff] [blame] | 25 | static struct kmem_cache *seq_file_cache __ro_after_init; |
| 26 | |
KAMEZAWA Hiroyuki | e075f59 | 2012-03-23 15:02:55 -0700 | [diff] [blame] | 27 | static void seq_set_overflow(struct seq_file *m) |
| 28 | { |
| 29 | m->count = m->size; |
| 30 | } |
| 31 | |
Heiko Carstens | 058504e | 2014-07-02 15:22:37 -0700 | [diff] [blame] | 32 | static void *seq_buf_alloc(unsigned long size) |
| 33 | { |
Alexey Dobriyan | d64d01a | 2018-04-10 16:34:49 -0700 | [diff] [blame] | 34 | return kvmalloc(size, GFP_KERNEL_ACCOUNT); |
Heiko Carstens | 058504e | 2014-07-02 15:22:37 -0700 | [diff] [blame] | 35 | } |
| 36 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | /** |
| 38 | * seq_open - initialize sequential file |
| 39 | * @file: file we initialize |
| 40 | * @op: method table describing the sequence |
| 41 | * |
| 42 | * seq_open() sets @file, associating it with a sequence described |
| 43 | * by @op. @op->start() sets the iterator up and returns the first |
| 44 | * element of sequence. @op->stop() shuts it down. @op->next() |
| 45 | * returns the next element of sequence. @op->show() prints element |
| 46 | * into the buffer. In case of error ->start() and ->next() return |
| 47 | * ERR_PTR(error). In the end of sequence they return %NULL. ->show() |
| 48 | * returns 0 in case of success and negative number in case of error. |
Al Viro | 521b5d0 | 2008-03-28 00:46:41 -0400 | [diff] [blame] | 49 | * Returning SEQ_SKIP means "discard this element and move on". |
Yann Droneaud | 460b865 | 2015-06-30 14:57:36 -0700 | [diff] [blame] | 50 | * Note: seq_open() will allocate a struct seq_file and store its |
| 51 | * pointer in @file->private_data. This pointer should not be modified. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | */ |
Helge Deller | 15ad7cd | 2006-12-06 20:40:36 -0800 | [diff] [blame] | 53 | int seq_open(struct file *file, const struct seq_operations *op) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | { |
Yann Droneaud | 189f984 | 2015-06-30 14:57:33 -0700 | [diff] [blame] | 55 | struct seq_file *p; |
Al Viro | 1abe77b | 2005-11-07 17:15:34 -0500 | [diff] [blame] | 56 | |
Yann Droneaud | 189f984 | 2015-06-30 14:57:33 -0700 | [diff] [blame] | 57 | WARN_ON(file->private_data); |
| 58 | |
Alexey Dobriyan | 096523203 | 2018-04-10 16:34:45 -0700 | [diff] [blame] | 59 | p = kmem_cache_zalloc(seq_file_cache, GFP_KERNEL); |
Yann Droneaud | 189f984 | 2015-06-30 14:57:33 -0700 | [diff] [blame] | 60 | if (!p) |
| 61 | return -ENOMEM; |
| 62 | |
| 63 | file->private_data = p; |
| 64 | |
Ingo Molnar | 0ac1759 | 2006-03-23 03:00:37 -0800 | [diff] [blame] | 65 | mutex_init(&p->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | p->op = op; |
Linus Torvalds | 34dbbcd | 2016-04-14 11:22:00 -0700 | [diff] [blame] | 67 | |
| 68 | // No refcounting: the lifetime of 'p' is constrained |
| 69 | // to the lifetime of the file. |
| 70 | p->file = file; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
| 72 | /* |
Eric Biederman | 8f19d47 | 2009-02-18 14:48:16 -0800 | [diff] [blame] | 73 | * seq_files support lseek() and pread(). They do not implement |
| 74 | * write() at all, but we clear FMODE_PWRITE here for historical |
| 75 | * reasons. |
| 76 | * |
| 77 | * If a client of seq_files a) implements file.write() and b) wishes to |
| 78 | * support pwrite() then that client will need to implement its own |
| 79 | * file.open() which calls seq_open() and then sets FMODE_PWRITE. |
| 80 | */ |
| 81 | file->f_mode &= ~FMODE_PWRITE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | return 0; |
| 83 | } |
| 84 | EXPORT_SYMBOL(seq_open); |
| 85 | |
Eric Biederman | 33da889 | 2009-02-04 15:12:25 -0800 | [diff] [blame] | 86 | static int traverse(struct seq_file *m, loff_t offset) |
| 87 | { |
NeilBrown | 1f4aace | 2018-08-17 15:44:41 -0700 | [diff] [blame] | 88 | loff_t pos = 0; |
Eric Biederman | 33da889 | 2009-02-04 15:12:25 -0800 | [diff] [blame] | 89 | int error = 0; |
| 90 | void *p; |
| 91 | |
NeilBrown | 1f4aace | 2018-08-17 15:44:41 -0700 | [diff] [blame] | 92 | m->index = 0; |
Eric Biederman | 33da889 | 2009-02-04 15:12:25 -0800 | [diff] [blame] | 93 | m->count = m->from = 0; |
NeilBrown | 1f4aace | 2018-08-17 15:44:41 -0700 | [diff] [blame] | 94 | if (!offset) |
Eric Biederman | 33da889 | 2009-02-04 15:12:25 -0800 | [diff] [blame] | 95 | return 0; |
NeilBrown | 1f4aace | 2018-08-17 15:44:41 -0700 | [diff] [blame] | 96 | |
Eric Biederman | 33da889 | 2009-02-04 15:12:25 -0800 | [diff] [blame] | 97 | if (!m->buf) { |
Heiko Carstens | 058504e | 2014-07-02 15:22:37 -0700 | [diff] [blame] | 98 | m->buf = seq_buf_alloc(m->size = PAGE_SIZE); |
Eric Biederman | 33da889 | 2009-02-04 15:12:25 -0800 | [diff] [blame] | 99 | if (!m->buf) |
| 100 | return -ENOMEM; |
| 101 | } |
NeilBrown | 1f4aace | 2018-08-17 15:44:41 -0700 | [diff] [blame] | 102 | p = m->op->start(m, &m->index); |
Eric Biederman | 33da889 | 2009-02-04 15:12:25 -0800 | [diff] [blame] | 103 | while (p) { |
| 104 | error = PTR_ERR(p); |
| 105 | if (IS_ERR(p)) |
| 106 | break; |
| 107 | error = m->op->show(m, p); |
| 108 | if (error < 0) |
| 109 | break; |
| 110 | if (unlikely(error)) { |
| 111 | error = 0; |
| 112 | m->count = 0; |
| 113 | } |
Joe Perches | 1f33c41 | 2014-09-29 16:08:21 -0700 | [diff] [blame] | 114 | if (seq_has_overflowed(m)) |
Eric Biederman | 33da889 | 2009-02-04 15:12:25 -0800 | [diff] [blame] | 115 | goto Eoverflow; |
NeilBrown | 6a2aeab | 2019-08-13 15:37:44 -0700 | [diff] [blame] | 116 | p = m->op->next(m, p, &m->index); |
Eric Biederman | 33da889 | 2009-02-04 15:12:25 -0800 | [diff] [blame] | 117 | if (pos + m->count > offset) { |
| 118 | m->from = offset - pos; |
| 119 | m->count -= m->from; |
Eric Biederman | 33da889 | 2009-02-04 15:12:25 -0800 | [diff] [blame] | 120 | break; |
| 121 | } |
| 122 | pos += m->count; |
| 123 | m->count = 0; |
NeilBrown | 1f4aace | 2018-08-17 15:44:41 -0700 | [diff] [blame] | 124 | if (pos == offset) |
Eric Biederman | 33da889 | 2009-02-04 15:12:25 -0800 | [diff] [blame] | 125 | break; |
Eric Biederman | 33da889 | 2009-02-04 15:12:25 -0800 | [diff] [blame] | 126 | } |
| 127 | m->op->stop(m, p); |
| 128 | return error; |
| 129 | |
| 130 | Eoverflow: |
| 131 | m->op->stop(m, p); |
Heiko Carstens | 058504e | 2014-07-02 15:22:37 -0700 | [diff] [blame] | 132 | kvfree(m->buf); |
Al Viro | 801a760 | 2013-11-19 01:20:43 +0000 | [diff] [blame] | 133 | m->count = 0; |
Heiko Carstens | 058504e | 2014-07-02 15:22:37 -0700 | [diff] [blame] | 134 | m->buf = seq_buf_alloc(m->size <<= 1); |
Eric Biederman | 33da889 | 2009-02-04 15:12:25 -0800 | [diff] [blame] | 135 | return !m->buf ? -ENOMEM : -EAGAIN; |
| 136 | } |
| 137 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | /** |
| 139 | * seq_read - ->read() method for sequential files. |
Martin Waitz | 67be2dd | 2005-05-01 08:59:26 -0700 | [diff] [blame] | 140 | * @file: the file to read from |
| 141 | * @buf: the buffer to read to |
| 142 | * @size: the maximum number of bytes to read |
| 143 | * @ppos: the current position in the file |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | * |
| 145 | * Ready-made ->f_op->read() |
| 146 | */ |
| 147 | ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos) |
| 148 | { |
Joe Perches | 8209e2f | 2010-09-04 18:52:49 -0700 | [diff] [blame] | 149 | struct seq_file *m = file->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | size_t copied = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | size_t n; |
| 152 | void *p; |
| 153 | int err = 0; |
| 154 | |
Ingo Molnar | 0ac1759 | 2006-03-23 03:00:37 -0800 | [diff] [blame] | 155 | mutex_lock(&m->lock); |
Eric Biederman | 8f19d47 | 2009-02-18 14:48:16 -0800 | [diff] [blame] | 156 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | /* |
Tomasz Majchrzak | e522751 | 2016-11-29 15:18:20 +0100 | [diff] [blame] | 158 | * if request is to read from zero offset, reset iterator to first |
| 159 | * record as it might have been already advanced by previous requests |
| 160 | */ |
Miklos Szeredi | cf5eeba | 2017-11-15 11:34:58 +0100 | [diff] [blame] | 161 | if (*ppos == 0) { |
Tomasz Majchrzak | e522751 | 2016-11-29 15:18:20 +0100 | [diff] [blame] | 162 | m->index = 0; |
Miklos Szeredi | cf5eeba | 2017-11-15 11:34:58 +0100 | [diff] [blame] | 163 | m->count = 0; |
| 164 | } |
Tomasz Majchrzak | e522751 | 2016-11-29 15:18:20 +0100 | [diff] [blame] | 165 | |
Earl Chew | 7904ac8 | 2012-03-21 16:33:43 -0700 | [diff] [blame] | 166 | /* Don't assume *ppos is where we left it */ |
| 167 | if (unlikely(*ppos != m->read_pos)) { |
| 168 | while ((err = traverse(m, *ppos)) == -EAGAIN) |
| 169 | ; |
| 170 | if (err) { |
| 171 | /* With prejudice... */ |
| 172 | m->read_pos = 0; |
Earl Chew | 7904ac8 | 2012-03-21 16:33:43 -0700 | [diff] [blame] | 173 | m->index = 0; |
| 174 | m->count = 0; |
| 175 | goto Done; |
| 176 | } else { |
| 177 | m->read_pos = *ppos; |
| 178 | } |
| 179 | } |
| 180 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | /* grab buffer if we didn't have one */ |
| 182 | if (!m->buf) { |
Heiko Carstens | 058504e | 2014-07-02 15:22:37 -0700 | [diff] [blame] | 183 | m->buf = seq_buf_alloc(m->size = PAGE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | if (!m->buf) |
| 185 | goto Enomem; |
| 186 | } |
| 187 | /* if not empty - flush it first */ |
| 188 | if (m->count) { |
| 189 | n = min(m->count, size); |
| 190 | err = copy_to_user(buf, m->buf + m->from, n); |
| 191 | if (err) |
| 192 | goto Efault; |
| 193 | m->count -= n; |
| 194 | m->from += n; |
| 195 | size -= n; |
| 196 | buf += n; |
| 197 | copied += n; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | if (!size) |
| 199 | goto Done; |
| 200 | } |
| 201 | /* we need at least one record in buffer */ |
NeilBrown | 1f4aace | 2018-08-17 15:44:41 -0700 | [diff] [blame] | 202 | m->from = 0; |
| 203 | p = m->op->start(m, &m->index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | while (1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | err = PTR_ERR(p); |
| 206 | if (!p || IS_ERR(p)) |
| 207 | break; |
| 208 | err = m->op->show(m, p); |
Al Viro | 521b5d0 | 2008-03-28 00:46:41 -0400 | [diff] [blame] | 209 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | break; |
Al Viro | 521b5d0 | 2008-03-28 00:46:41 -0400 | [diff] [blame] | 211 | if (unlikely(err)) |
| 212 | m->count = 0; |
Al Viro | 4cdfe84 | 2008-08-24 07:45:33 -0400 | [diff] [blame] | 213 | if (unlikely(!m->count)) { |
NeilBrown | 1f4aace | 2018-08-17 15:44:41 -0700 | [diff] [blame] | 214 | p = m->op->next(m, p, &m->index); |
Al Viro | 4cdfe84 | 2008-08-24 07:45:33 -0400 | [diff] [blame] | 215 | continue; |
| 216 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | if (m->count < m->size) |
| 218 | goto Fill; |
| 219 | m->op->stop(m, p); |
Heiko Carstens | 058504e | 2014-07-02 15:22:37 -0700 | [diff] [blame] | 220 | kvfree(m->buf); |
Al Viro | 801a760 | 2013-11-19 01:20:43 +0000 | [diff] [blame] | 221 | m->count = 0; |
Heiko Carstens | 058504e | 2014-07-02 15:22:37 -0700 | [diff] [blame] | 222 | m->buf = seq_buf_alloc(m->size <<= 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | if (!m->buf) |
| 224 | goto Enomem; |
NeilBrown | 1f4aace | 2018-08-17 15:44:41 -0700 | [diff] [blame] | 225 | p = m->op->start(m, &m->index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | } |
| 227 | m->op->stop(m, p); |
| 228 | m->count = 0; |
| 229 | goto Done; |
| 230 | Fill: |
| 231 | /* they want more? let's try to get some more */ |
NeilBrown | 1f4aace | 2018-08-17 15:44:41 -0700 | [diff] [blame] | 232 | while (1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | size_t offs = m->count; |
NeilBrown | 1f4aace | 2018-08-17 15:44:41 -0700 | [diff] [blame] | 234 | loff_t pos = m->index; |
| 235 | |
| 236 | p = m->op->next(m, p, &m->index); |
Vasily Averin | 3bfa7e1 | 2020-04-10 14:34:06 -0700 | [diff] [blame] | 237 | if (pos == m->index) { |
Joe Perches | a396301 | 2020-06-04 16:51:02 -0700 | [diff] [blame] | 238 | pr_info_ratelimited("buggy .next function %ps did not update position index\n", |
| 239 | m->op->next); |
NeilBrown | 1f4aace | 2018-08-17 15:44:41 -0700 | [diff] [blame] | 240 | m->index++; |
Vasily Averin | 3bfa7e1 | 2020-04-10 14:34:06 -0700 | [diff] [blame] | 241 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | if (!p || IS_ERR(p)) { |
| 243 | err = PTR_ERR(p); |
| 244 | break; |
| 245 | } |
NeilBrown | 1f4aace | 2018-08-17 15:44:41 -0700 | [diff] [blame] | 246 | if (m->count >= size) |
| 247 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | err = m->op->show(m, p); |
Joe Perches | 1f33c41 | 2014-09-29 16:08:21 -0700 | [diff] [blame] | 249 | if (seq_has_overflowed(m) || err) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | m->count = offs; |
Al Viro | 521b5d0 | 2008-03-28 00:46:41 -0400 | [diff] [blame] | 251 | if (likely(err <= 0)) |
| 252 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | } |
| 255 | m->op->stop(m, p); |
| 256 | n = min(m->count, size); |
| 257 | err = copy_to_user(buf, m->buf, n); |
| 258 | if (err) |
| 259 | goto Efault; |
| 260 | copied += n; |
| 261 | m->count -= n; |
NeilBrown | 1f4aace | 2018-08-17 15:44:41 -0700 | [diff] [blame] | 262 | m->from = n; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | Done: |
| 264 | if (!copied) |
| 265 | copied = err; |
Eric Biederman | 8f19d47 | 2009-02-18 14:48:16 -0800 | [diff] [blame] | 266 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | *ppos += copied; |
Eric Biederman | 8f19d47 | 2009-02-18 14:48:16 -0800 | [diff] [blame] | 268 | m->read_pos += copied; |
| 269 | } |
Ingo Molnar | 0ac1759 | 2006-03-23 03:00:37 -0800 | [diff] [blame] | 270 | mutex_unlock(&m->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | return copied; |
| 272 | Enomem: |
| 273 | err = -ENOMEM; |
| 274 | goto Done; |
| 275 | Efault: |
| 276 | err = -EFAULT; |
| 277 | goto Done; |
| 278 | } |
| 279 | EXPORT_SYMBOL(seq_read); |
| 280 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | /** |
| 282 | * seq_lseek - ->llseek() method for sequential files. |
Martin Waitz | 67be2dd | 2005-05-01 08:59:26 -0700 | [diff] [blame] | 283 | * @file: the file in question |
| 284 | * @offset: new position |
Randy Dunlap | 254adaa | 2013-01-09 17:13:00 -0800 | [diff] [blame] | 285 | * @whence: 0 for absolute, 1 for relative position |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | * |
| 287 | * Ready-made ->f_op->llseek() |
| 288 | */ |
Andrew Morton | 965c8e5 | 2012-12-17 15:59:39 -0800 | [diff] [blame] | 289 | loff_t seq_lseek(struct file *file, loff_t offset, int whence) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | { |
Joe Perches | 8209e2f | 2010-09-04 18:52:49 -0700 | [diff] [blame] | 291 | struct seq_file *m = file->private_data; |
David Sterba | 16abef0 | 2008-04-22 15:09:22 +0200 | [diff] [blame] | 292 | loff_t retval = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | |
Ingo Molnar | 0ac1759 | 2006-03-23 03:00:37 -0800 | [diff] [blame] | 294 | mutex_lock(&m->lock); |
Andrew Morton | 965c8e5 | 2012-12-17 15:59:39 -0800 | [diff] [blame] | 295 | switch (whence) { |
Andrew Morton | 5e62ade | 2013-02-27 17:03:22 -0800 | [diff] [blame] | 296 | case SEEK_CUR: |
| 297 | offset += file->f_pos; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 298 | fallthrough; |
Andrew Morton | 5e62ade | 2013-02-27 17:03:22 -0800 | [diff] [blame] | 299 | case SEEK_SET: |
| 300 | if (offset < 0) |
| 301 | break; |
| 302 | retval = offset; |
| 303 | if (offset != m->read_pos) { |
| 304 | while ((retval = traverse(m, offset)) == -EAGAIN) |
| 305 | ; |
| 306 | if (retval) { |
| 307 | /* with extreme prejudice... */ |
| 308 | file->f_pos = 0; |
| 309 | m->read_pos = 0; |
Andrew Morton | 5e62ade | 2013-02-27 17:03:22 -0800 | [diff] [blame] | 310 | m->index = 0; |
| 311 | m->count = 0; |
| 312 | } else { |
| 313 | m->read_pos = offset; |
| 314 | retval = file->f_pos = offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | } |
Gu Zheng | 05e1674 | 2013-10-25 18:15:06 +0800 | [diff] [blame] | 316 | } else { |
| 317 | file->f_pos = offset; |
Andrew Morton | 5e62ade | 2013-02-27 17:03:22 -0800 | [diff] [blame] | 318 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | } |
Alexey Dobriyan | 00c5746 | 2007-07-15 23:40:22 -0700 | [diff] [blame] | 320 | mutex_unlock(&m->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | return retval; |
| 322 | } |
| 323 | EXPORT_SYMBOL(seq_lseek); |
| 324 | |
| 325 | /** |
| 326 | * seq_release - free the structures associated with sequential file. |
| 327 | * @file: file in question |
Al Viro | 6131ffa | 2013-02-27 16:59:05 -0500 | [diff] [blame] | 328 | * @inode: its inode |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | * |
| 330 | * Frees the structures associated with sequential file; can be used |
| 331 | * as ->f_op->release() if you don't have private data to destroy. |
| 332 | */ |
| 333 | int seq_release(struct inode *inode, struct file *file) |
| 334 | { |
Joe Perches | 8209e2f | 2010-09-04 18:52:49 -0700 | [diff] [blame] | 335 | struct seq_file *m = file->private_data; |
Heiko Carstens | 058504e | 2014-07-02 15:22:37 -0700 | [diff] [blame] | 336 | kvfree(m->buf); |
Alexey Dobriyan | 096523203 | 2018-04-10 16:34:45 -0700 | [diff] [blame] | 337 | kmem_cache_free(seq_file_cache, m); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | return 0; |
| 339 | } |
| 340 | EXPORT_SYMBOL(seq_release); |
| 341 | |
| 342 | /** |
| 343 | * seq_escape - print string into buffer, escaping some characters |
| 344 | * @m: target buffer |
| 345 | * @s: string |
| 346 | * @esc: set of characters that need escaping |
| 347 | * |
| 348 | * Puts string into buffer, replacing each occurrence of character from |
Joe Perches | 6798a8c | 2015-09-11 13:07:48 -0700 | [diff] [blame] | 349 | * @esc with usual octal escape. |
| 350 | * Use seq_has_overflowed() to check for errors. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | */ |
Joe Perches | 6798a8c | 2015-09-11 13:07:48 -0700 | [diff] [blame] | 352 | void seq_escape(struct seq_file *m, const char *s, const char *esc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | { |
Andy Shevchenko | 25c6bb7 | 2015-11-06 16:32:40 -0800 | [diff] [blame] | 354 | char *buf; |
| 355 | size_t size = seq_get_buf(m, &buf); |
| 356 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | |
Andy Shevchenko | 25c6bb7 | 2015-11-06 16:32:40 -0800 | [diff] [blame] | 358 | ret = string_escape_str(s, buf, size, ESCAPE_OCTAL, esc); |
| 359 | seq_commit(m, ret < size ? ret : -1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | } |
| 361 | EXPORT_SYMBOL(seq_escape); |
| 362 | |
J. Bruce Fields | ea053e1 | 2019-06-19 12:30:13 -0400 | [diff] [blame] | 363 | void seq_escape_mem_ascii(struct seq_file *m, const char *src, size_t isz) |
| 364 | { |
| 365 | char *buf; |
| 366 | size_t size = seq_get_buf(m, &buf); |
| 367 | int ret; |
| 368 | |
| 369 | ret = string_escape_mem_ascii(src, isz, buf, size); |
| 370 | seq_commit(m, ret < size ? ret : -1); |
| 371 | } |
| 372 | EXPORT_SYMBOL(seq_escape_mem_ascii); |
| 373 | |
Joe Perches | 6798a8c | 2015-09-11 13:07:48 -0700 | [diff] [blame] | 374 | void seq_vprintf(struct seq_file *m, const char *f, va_list args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | int len; |
| 377 | |
| 378 | if (m->count < m->size) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | len = vsnprintf(m->buf + m->count, m->size - m->count, f, args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | if (m->count + len < m->size) { |
| 381 | m->count += len; |
Joe Perches | 6798a8c | 2015-09-11 13:07:48 -0700 | [diff] [blame] | 382 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | } |
| 384 | } |
KAMEZAWA Hiroyuki | e075f59 | 2012-03-23 15:02:55 -0700 | [diff] [blame] | 385 | seq_set_overflow(m); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | } |
Steven Whitehouse | a480814 | 2012-06-11 13:16:35 +0100 | [diff] [blame] | 387 | EXPORT_SYMBOL(seq_vprintf); |
| 388 | |
Joe Perches | 6798a8c | 2015-09-11 13:07:48 -0700 | [diff] [blame] | 389 | void seq_printf(struct seq_file *m, const char *f, ...) |
Steven Whitehouse | a480814 | 2012-06-11 13:16:35 +0100 | [diff] [blame] | 390 | { |
Steven Whitehouse | a480814 | 2012-06-11 13:16:35 +0100 | [diff] [blame] | 391 | va_list args; |
| 392 | |
| 393 | va_start(args, f); |
Joe Perches | 6798a8c | 2015-09-11 13:07:48 -0700 | [diff] [blame] | 394 | seq_vprintf(m, f, args); |
Steven Whitehouse | a480814 | 2012-06-11 13:16:35 +0100 | [diff] [blame] | 395 | va_end(args); |
Steven Whitehouse | a480814 | 2012-06-11 13:16:35 +0100 | [diff] [blame] | 396 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | EXPORT_SYMBOL(seq_printf); |
| 398 | |
Török Edwin | 74e2f33 | 2008-11-22 13:28:48 +0200 | [diff] [blame] | 399 | /** |
Török Edwin | 958086d | 2008-11-23 23:24:53 +0200 | [diff] [blame] | 400 | * mangle_path - mangle and copy path to buffer beginning |
| 401 | * @s: buffer start |
| 402 | * @p: beginning of path in above buffer |
| 403 | * @esc: set of characters that need escaping |
Török Edwin | 74e2f33 | 2008-11-22 13:28:48 +0200 | [diff] [blame] | 404 | * |
| 405 | * Copy the path from @p to @s, replacing each occurrence of character from |
| 406 | * @esc with usual octal escape. |
| 407 | * Returns pointer past last written character in @s, or NULL in case of |
| 408 | * failure. |
| 409 | */ |
Al Viro | 8c9379e | 2011-12-08 20:18:57 -0500 | [diff] [blame] | 410 | char *mangle_path(char *s, const char *p, const char *esc) |
Ram Pai | 6092d04 | 2008-03-27 13:06:20 +0100 | [diff] [blame] | 411 | { |
| 412 | while (s <= p) { |
| 413 | char c = *p++; |
| 414 | if (!c) { |
| 415 | return s; |
| 416 | } else if (!strchr(esc, c)) { |
| 417 | *s++ = c; |
| 418 | } else if (s + 4 > p) { |
| 419 | break; |
| 420 | } else { |
| 421 | *s++ = '\\'; |
| 422 | *s++ = '0' + ((c & 0300) >> 6); |
| 423 | *s++ = '0' + ((c & 070) >> 3); |
| 424 | *s++ = '0' + (c & 07); |
| 425 | } |
| 426 | } |
| 427 | return NULL; |
| 428 | } |
Ingo Molnar | 604094f | 2008-11-28 18:03:22 +0100 | [diff] [blame] | 429 | EXPORT_SYMBOL(mangle_path); |
Ram Pai | 6092d04 | 2008-03-27 13:06:20 +0100 | [diff] [blame] | 430 | |
Arjan van de Ven | 52afeef | 2008-12-01 14:35:00 -0800 | [diff] [blame] | 431 | /** |
| 432 | * seq_path - seq_file interface to print a pathname |
| 433 | * @m: the seq_file handle |
| 434 | * @path: the struct path to print |
| 435 | * @esc: set of characters to escape in the output |
| 436 | * |
| 437 | * return the absolute path of 'path', as represented by the |
| 438 | * dentry / mnt pair in the path parameter. |
Ram Pai | 6092d04 | 2008-03-27 13:06:20 +0100 | [diff] [blame] | 439 | */ |
Al Viro | 8c9379e | 2011-12-08 20:18:57 -0500 | [diff] [blame] | 440 | int seq_path(struct seq_file *m, const struct path *path, const char *esc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | { |
Miklos Szeredi | f843980 | 2009-09-21 14:48:36 +0200 | [diff] [blame] | 442 | char *buf; |
| 443 | size_t size = seq_get_buf(m, &buf); |
| 444 | int res = -1; |
| 445 | |
| 446 | if (size) { |
| 447 | char *p = d_path(path, buf, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | if (!IS_ERR(p)) { |
Miklos Szeredi | f843980 | 2009-09-21 14:48:36 +0200 | [diff] [blame] | 449 | char *end = mangle_path(buf, p, esc); |
| 450 | if (end) |
| 451 | res = end - buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | } |
| 453 | } |
Miklos Szeredi | f843980 | 2009-09-21 14:48:36 +0200 | [diff] [blame] | 454 | seq_commit(m, res); |
| 455 | |
| 456 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | } |
| 458 | EXPORT_SYMBOL(seq_path); |
| 459 | |
Miklos Szeredi | 2726d56 | 2015-06-19 10:30:28 +0200 | [diff] [blame] | 460 | /** |
| 461 | * seq_file_path - seq_file interface to print a pathname of a file |
| 462 | * @m: the seq_file handle |
| 463 | * @file: the struct file to print |
| 464 | * @esc: set of characters to escape in the output |
| 465 | * |
| 466 | * return the absolute path to the file. |
| 467 | */ |
| 468 | int seq_file_path(struct seq_file *m, struct file *file, const char *esc) |
| 469 | { |
| 470 | return seq_path(m, &file->f_path, esc); |
| 471 | } |
| 472 | EXPORT_SYMBOL(seq_file_path); |
| 473 | |
Ram Pai | 6092d04 | 2008-03-27 13:06:20 +0100 | [diff] [blame] | 474 | /* |
Miklos Szeredi | 9d1bc601 | 2008-03-27 13:06:21 +0100 | [diff] [blame] | 475 | * Same as seq_path, but relative to supplied root. |
Miklos Szeredi | 9d1bc601 | 2008-03-27 13:06:21 +0100 | [diff] [blame] | 476 | */ |
Al Viro | 8c9379e | 2011-12-08 20:18:57 -0500 | [diff] [blame] | 477 | int seq_path_root(struct seq_file *m, const struct path *path, |
| 478 | const struct path *root, const char *esc) |
Miklos Szeredi | 9d1bc601 | 2008-03-27 13:06:21 +0100 | [diff] [blame] | 479 | { |
Miklos Szeredi | f843980 | 2009-09-21 14:48:36 +0200 | [diff] [blame] | 480 | char *buf; |
| 481 | size_t size = seq_get_buf(m, &buf); |
| 482 | int res = -ENAMETOOLONG; |
| 483 | |
| 484 | if (size) { |
Miklos Szeredi | 9d1bc601 | 2008-03-27 13:06:21 +0100 | [diff] [blame] | 485 | char *p; |
| 486 | |
Miklos Szeredi | f843980 | 2009-09-21 14:48:36 +0200 | [diff] [blame] | 487 | p = __d_path(path, root, buf, size); |
Al Viro | 02125a8 | 2011-12-05 08:43:34 -0500 | [diff] [blame] | 488 | if (!p) |
| 489 | return SEQ_SKIP; |
Miklos Szeredi | f843980 | 2009-09-21 14:48:36 +0200 | [diff] [blame] | 490 | res = PTR_ERR(p); |
Miklos Szeredi | 9d1bc601 | 2008-03-27 13:06:21 +0100 | [diff] [blame] | 491 | if (!IS_ERR(p)) { |
Miklos Szeredi | f843980 | 2009-09-21 14:48:36 +0200 | [diff] [blame] | 492 | char *end = mangle_path(buf, p, esc); |
| 493 | if (end) |
| 494 | res = end - buf; |
| 495 | else |
| 496 | res = -ENAMETOOLONG; |
Miklos Szeredi | 9d1bc601 | 2008-03-27 13:06:21 +0100 | [diff] [blame] | 497 | } |
| 498 | } |
Miklos Szeredi | f843980 | 2009-09-21 14:48:36 +0200 | [diff] [blame] | 499 | seq_commit(m, res); |
| 500 | |
Al Viro | 02125a8 | 2011-12-05 08:43:34 -0500 | [diff] [blame] | 501 | return res < 0 && res != -ENAMETOOLONG ? res : 0; |
Miklos Szeredi | 9d1bc601 | 2008-03-27 13:06:21 +0100 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | /* |
Ram Pai | 6092d04 | 2008-03-27 13:06:20 +0100 | [diff] [blame] | 505 | * returns the path of the 'dentry' from the root of its filesystem. |
| 506 | */ |
Al Viro | 8c9379e | 2011-12-08 20:18:57 -0500 | [diff] [blame] | 507 | int seq_dentry(struct seq_file *m, struct dentry *dentry, const char *esc) |
Ram Pai | 6092d04 | 2008-03-27 13:06:20 +0100 | [diff] [blame] | 508 | { |
Miklos Szeredi | f843980 | 2009-09-21 14:48:36 +0200 | [diff] [blame] | 509 | char *buf; |
| 510 | size_t size = seq_get_buf(m, &buf); |
| 511 | int res = -1; |
| 512 | |
| 513 | if (size) { |
| 514 | char *p = dentry_path(dentry, buf, size); |
Ram Pai | 6092d04 | 2008-03-27 13:06:20 +0100 | [diff] [blame] | 515 | if (!IS_ERR(p)) { |
Miklos Szeredi | f843980 | 2009-09-21 14:48:36 +0200 | [diff] [blame] | 516 | char *end = mangle_path(buf, p, esc); |
| 517 | if (end) |
| 518 | res = end - buf; |
Ram Pai | 6092d04 | 2008-03-27 13:06:20 +0100 | [diff] [blame] | 519 | } |
| 520 | } |
Miklos Szeredi | f843980 | 2009-09-21 14:48:36 +0200 | [diff] [blame] | 521 | seq_commit(m, res); |
| 522 | |
| 523 | return res; |
Ram Pai | 6092d04 | 2008-03-27 13:06:20 +0100 | [diff] [blame] | 524 | } |
Omar Sandoval | c8d3fe0 | 2015-05-18 02:16:31 -0700 | [diff] [blame] | 525 | EXPORT_SYMBOL(seq_dentry); |
Ram Pai | 6092d04 | 2008-03-27 13:06:20 +0100 | [diff] [blame] | 526 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | static void *single_start(struct seq_file *p, loff_t *pos) |
| 528 | { |
| 529 | return NULL + (*pos == 0); |
| 530 | } |
| 531 | |
| 532 | static void *single_next(struct seq_file *p, void *v, loff_t *pos) |
| 533 | { |
| 534 | ++*pos; |
| 535 | return NULL; |
| 536 | } |
| 537 | |
| 538 | static void single_stop(struct seq_file *p, void *v) |
| 539 | { |
| 540 | } |
| 541 | |
| 542 | int single_open(struct file *file, int (*show)(struct seq_file *, void *), |
| 543 | void *data) |
| 544 | { |
Alexey Dobriyan | d64d01a | 2018-04-10 16:34:49 -0700 | [diff] [blame] | 545 | struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL_ACCOUNT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | int res = -ENOMEM; |
| 547 | |
| 548 | if (op) { |
| 549 | op->start = single_start; |
| 550 | op->next = single_next; |
| 551 | op->stop = single_stop; |
| 552 | op->show = show; |
| 553 | res = seq_open(file, op); |
| 554 | if (!res) |
| 555 | ((struct seq_file *)file->private_data)->private = data; |
| 556 | else |
| 557 | kfree(op); |
| 558 | } |
| 559 | return res; |
| 560 | } |
| 561 | EXPORT_SYMBOL(single_open); |
| 562 | |
Al Viro | 2043f49 | 2013-03-31 13:43:23 -0400 | [diff] [blame] | 563 | int single_open_size(struct file *file, int (*show)(struct seq_file *, void *), |
| 564 | void *data, size_t size) |
| 565 | { |
Heiko Carstens | 058504e | 2014-07-02 15:22:37 -0700 | [diff] [blame] | 566 | char *buf = seq_buf_alloc(size); |
Al Viro | 2043f49 | 2013-03-31 13:43:23 -0400 | [diff] [blame] | 567 | int ret; |
| 568 | if (!buf) |
| 569 | return -ENOMEM; |
| 570 | ret = single_open(file, show, data); |
| 571 | if (ret) { |
Heiko Carstens | 058504e | 2014-07-02 15:22:37 -0700 | [diff] [blame] | 572 | kvfree(buf); |
Al Viro | 2043f49 | 2013-03-31 13:43:23 -0400 | [diff] [blame] | 573 | return ret; |
| 574 | } |
| 575 | ((struct seq_file *)file->private_data)->buf = buf; |
| 576 | ((struct seq_file *)file->private_data)->size = size; |
| 577 | return 0; |
| 578 | } |
| 579 | EXPORT_SYMBOL(single_open_size); |
| 580 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | int single_release(struct inode *inode, struct file *file) |
| 582 | { |
Helge Deller | 15ad7cd | 2006-12-06 20:40:36 -0800 | [diff] [blame] | 583 | const struct seq_operations *op = ((struct seq_file *)file->private_data)->op; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | int res = seq_release(inode, file); |
| 585 | kfree(op); |
| 586 | return res; |
| 587 | } |
| 588 | EXPORT_SYMBOL(single_release); |
| 589 | |
| 590 | int seq_release_private(struct inode *inode, struct file *file) |
| 591 | { |
| 592 | struct seq_file *seq = file->private_data; |
| 593 | |
| 594 | kfree(seq->private); |
| 595 | seq->private = NULL; |
| 596 | return seq_release(inode, file); |
| 597 | } |
| 598 | EXPORT_SYMBOL(seq_release_private); |
| 599 | |
Pavel Emelyanov | 3969903 | 2007-10-10 02:28:42 -0700 | [diff] [blame] | 600 | void *__seq_open_private(struct file *f, const struct seq_operations *ops, |
| 601 | int psize) |
| 602 | { |
| 603 | int rc; |
| 604 | void *private; |
| 605 | struct seq_file *seq; |
| 606 | |
Alexey Dobriyan | d64d01a | 2018-04-10 16:34:49 -0700 | [diff] [blame] | 607 | private = kzalloc(psize, GFP_KERNEL_ACCOUNT); |
Pavel Emelyanov | 3969903 | 2007-10-10 02:28:42 -0700 | [diff] [blame] | 608 | if (private == NULL) |
| 609 | goto out; |
| 610 | |
| 611 | rc = seq_open(f, ops); |
| 612 | if (rc < 0) |
| 613 | goto out_free; |
| 614 | |
| 615 | seq = f->private_data; |
| 616 | seq->private = private; |
| 617 | return private; |
| 618 | |
| 619 | out_free: |
| 620 | kfree(private); |
| 621 | out: |
| 622 | return NULL; |
| 623 | } |
| 624 | EXPORT_SYMBOL(__seq_open_private); |
| 625 | |
| 626 | int seq_open_private(struct file *filp, const struct seq_operations *ops, |
| 627 | int psize) |
| 628 | { |
| 629 | return __seq_open_private(filp, ops, psize) ? 0 : -ENOMEM; |
| 630 | } |
| 631 | EXPORT_SYMBOL(seq_open_private); |
| 632 | |
Joe Perches | 6798a8c | 2015-09-11 13:07:48 -0700 | [diff] [blame] | 633 | void seq_putc(struct seq_file *m, char c) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | { |
Joe Perches | 6798a8c | 2015-09-11 13:07:48 -0700 | [diff] [blame] | 635 | if (m->count >= m->size) |
| 636 | return; |
| 637 | |
| 638 | m->buf[m->count++] = c; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | } |
| 640 | EXPORT_SYMBOL(seq_putc); |
| 641 | |
Joe Perches | 6798a8c | 2015-09-11 13:07:48 -0700 | [diff] [blame] | 642 | void seq_puts(struct seq_file *m, const char *s) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | { |
| 644 | int len = strlen(s); |
Joe Perches | 6798a8c | 2015-09-11 13:07:48 -0700 | [diff] [blame] | 645 | |
| 646 | if (m->count + len >= m->size) { |
| 647 | seq_set_overflow(m); |
| 648 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | } |
Joe Perches | 6798a8c | 2015-09-11 13:07:48 -0700 | [diff] [blame] | 650 | memcpy(m->buf + m->count, s, len); |
| 651 | m->count += len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | } |
| 653 | EXPORT_SYMBOL(seq_puts); |
Pavel Emelianov | bcf67e1 | 2007-07-10 17:22:26 -0700 | [diff] [blame] | 654 | |
Andrei Vagin | d1be35c | 2018-04-10 16:31:16 -0700 | [diff] [blame] | 655 | /** |
KAMEZAWA Hiroyuki | 1ac101a | 2012-03-23 15:02:54 -0700 | [diff] [blame] | 656 | * A helper routine for putting decimal numbers without rich format of printf(). |
| 657 | * only 'unsigned long long' is supported. |
Andrei Vagin | d1be35c | 2018-04-10 16:31:16 -0700 | [diff] [blame] | 658 | * @m: seq_file identifying the buffer to which data should be written |
| 659 | * @delimiter: a string which is printed before the number |
| 660 | * @num: the number |
| 661 | * @width: a minimum field width |
| 662 | * |
| 663 | * This routine will put strlen(delimiter) + number into seq_filed. |
KAMEZAWA Hiroyuki | 1ac101a | 2012-03-23 15:02:54 -0700 | [diff] [blame] | 664 | * This routine is very quick when you show lots of numbers. |
| 665 | * In usual cases, it will be better to use seq_printf(). It's easier to read. |
| 666 | */ |
Andrei Vagin | d1be35c | 2018-04-10 16:31:16 -0700 | [diff] [blame] | 667 | void seq_put_decimal_ull_width(struct seq_file *m, const char *delimiter, |
| 668 | unsigned long long num, unsigned int width) |
KAMEZAWA Hiroyuki | 1ac101a | 2012-03-23 15:02:54 -0700 | [diff] [blame] | 669 | { |
| 670 | int len; |
| 671 | |
| 672 | if (m->count + 2 >= m->size) /* we'll write 2 bytes at least */ |
| 673 | goto overflow; |
| 674 | |
Andrei Vagin | 48dffbf | 2018-04-10 16:31:23 -0700 | [diff] [blame] | 675 | if (delimiter && delimiter[0]) { |
| 676 | if (delimiter[1] == 0) |
| 677 | seq_putc(m, delimiter[0]); |
| 678 | else |
| 679 | seq_puts(m, delimiter); |
| 680 | } |
Joe Perches | 75ba1d0 | 2016-10-07 17:02:20 -0700 | [diff] [blame] | 681 | |
Andrei Vagin | d1be35c | 2018-04-10 16:31:16 -0700 | [diff] [blame] | 682 | if (!width) |
| 683 | width = 1; |
| 684 | |
| 685 | if (m->count + width >= m->size) |
Joe Perches | 75ba1d0 | 2016-10-07 17:02:20 -0700 | [diff] [blame] | 686 | goto overflow; |
KAMEZAWA Hiroyuki | 1ac101a | 2012-03-23 15:02:54 -0700 | [diff] [blame] | 687 | |
Andrei Vagin | d1be35c | 2018-04-10 16:31:16 -0700 | [diff] [blame] | 688 | len = num_to_str(m->buf + m->count, m->size - m->count, num, width); |
KAMEZAWA Hiroyuki | 1ac101a | 2012-03-23 15:02:54 -0700 | [diff] [blame] | 689 | if (!len) |
| 690 | goto overflow; |
Joe Perches | 75ba1d0 | 2016-10-07 17:02:20 -0700 | [diff] [blame] | 691 | |
KAMEZAWA Hiroyuki | 1ac101a | 2012-03-23 15:02:54 -0700 | [diff] [blame] | 692 | m->count += len; |
Joe Perches | 6798a8c | 2015-09-11 13:07:48 -0700 | [diff] [blame] | 693 | return; |
| 694 | |
KAMEZAWA Hiroyuki | 1ac101a | 2012-03-23 15:02:54 -0700 | [diff] [blame] | 695 | overflow: |
KAMEZAWA Hiroyuki | e075f59 | 2012-03-23 15:02:55 -0700 | [diff] [blame] | 696 | seq_set_overflow(m); |
KAMEZAWA Hiroyuki | 1ac101a | 2012-03-23 15:02:54 -0700 | [diff] [blame] | 697 | } |
Andrei Vagin | d1be35c | 2018-04-10 16:31:16 -0700 | [diff] [blame] | 698 | |
| 699 | void seq_put_decimal_ull(struct seq_file *m, const char *delimiter, |
| 700 | unsigned long long num) |
| 701 | { |
| 702 | return seq_put_decimal_ull_width(m, delimiter, num, 0); |
| 703 | } |
KAMEZAWA Hiroyuki | 1ac101a | 2012-03-23 15:02:54 -0700 | [diff] [blame] | 704 | EXPORT_SYMBOL(seq_put_decimal_ull); |
| 705 | |
Andrei Vagin | 0e3dc01 | 2018-04-10 16:30:44 -0700 | [diff] [blame] | 706 | /** |
| 707 | * seq_put_hex_ll - put a number in hexadecimal notation |
| 708 | * @m: seq_file identifying the buffer to which data should be written |
| 709 | * @delimiter: a string which is printed before the number |
| 710 | * @v: the number |
| 711 | * @width: a minimum field width |
| 712 | * |
| 713 | * seq_put_hex_ll(m, "", v, 8) is equal to seq_printf(m, "%08llx", v) |
| 714 | * |
| 715 | * This routine is very quick when you show lots of numbers. |
| 716 | * In usual cases, it will be better to use seq_printf(). It's easier to read. |
| 717 | */ |
| 718 | void seq_put_hex_ll(struct seq_file *m, const char *delimiter, |
| 719 | unsigned long long v, unsigned int width) |
| 720 | { |
| 721 | unsigned int len; |
| 722 | int i; |
| 723 | |
| 724 | if (delimiter && delimiter[0]) { |
| 725 | if (delimiter[1] == 0) |
| 726 | seq_putc(m, delimiter[0]); |
| 727 | else |
| 728 | seq_puts(m, delimiter); |
| 729 | } |
| 730 | |
| 731 | /* If x is 0, the result of __builtin_clzll is undefined */ |
| 732 | if (v == 0) |
| 733 | len = 1; |
| 734 | else |
| 735 | len = (sizeof(v) * 8 - __builtin_clzll(v) + 3) / 4; |
| 736 | |
| 737 | if (len < width) |
| 738 | len = width; |
| 739 | |
| 740 | if (m->count + len > m->size) { |
| 741 | seq_set_overflow(m); |
| 742 | return; |
| 743 | } |
| 744 | |
| 745 | for (i = len - 1; i >= 0; i--) { |
| 746 | m->buf[m->count + i] = hex_asc[0xf & v]; |
| 747 | v = v >> 4; |
| 748 | } |
| 749 | m->count += len; |
| 750 | } |
| 751 | |
Joe Perches | 75ba1d0 | 2016-10-07 17:02:20 -0700 | [diff] [blame] | 752 | void seq_put_decimal_ll(struct seq_file *m, const char *delimiter, long long num) |
KAMEZAWA Hiroyuki | bda7bad | 2012-03-23 15:02:54 -0700 | [diff] [blame] | 753 | { |
Joe Perches | 75ba1d0 | 2016-10-07 17:02:20 -0700 | [diff] [blame] | 754 | int len; |
| 755 | |
| 756 | if (m->count + 3 >= m->size) /* we'll write 2 bytes at least */ |
| 757 | goto overflow; |
| 758 | |
Andrei Vagin | 48dffbf | 2018-04-10 16:31:23 -0700 | [diff] [blame] | 759 | if (delimiter && delimiter[0]) { |
| 760 | if (delimiter[1] == 0) |
| 761 | seq_putc(m, delimiter[0]); |
| 762 | else |
| 763 | seq_puts(m, delimiter); |
| 764 | } |
Joe Perches | 75ba1d0 | 2016-10-07 17:02:20 -0700 | [diff] [blame] | 765 | |
| 766 | if (m->count + 2 >= m->size) |
| 767 | goto overflow; |
| 768 | |
KAMEZAWA Hiroyuki | bda7bad | 2012-03-23 15:02:54 -0700 | [diff] [blame] | 769 | if (num < 0) { |
Joe Perches | 75ba1d0 | 2016-10-07 17:02:20 -0700 | [diff] [blame] | 770 | m->buf[m->count++] = '-'; |
KAMEZAWA Hiroyuki | bda7bad | 2012-03-23 15:02:54 -0700 | [diff] [blame] | 771 | num = -num; |
KAMEZAWA Hiroyuki | bda7bad | 2012-03-23 15:02:54 -0700 | [diff] [blame] | 772 | } |
Joe Perches | 75ba1d0 | 2016-10-07 17:02:20 -0700 | [diff] [blame] | 773 | |
| 774 | if (num < 10) { |
| 775 | m->buf[m->count++] = num + '0'; |
| 776 | return; |
| 777 | } |
| 778 | |
Andrei Vagin | d1be35c | 2018-04-10 16:31:16 -0700 | [diff] [blame] | 779 | len = num_to_str(m->buf + m->count, m->size - m->count, num, 0); |
Joe Perches | 75ba1d0 | 2016-10-07 17:02:20 -0700 | [diff] [blame] | 780 | if (!len) |
| 781 | goto overflow; |
| 782 | |
| 783 | m->count += len; |
| 784 | return; |
| 785 | |
| 786 | overflow: |
| 787 | seq_set_overflow(m); |
KAMEZAWA Hiroyuki | bda7bad | 2012-03-23 15:02:54 -0700 | [diff] [blame] | 788 | } |
| 789 | EXPORT_SYMBOL(seq_put_decimal_ll); |
| 790 | |
Peter Oberparleiter | 0b92360 | 2009-06-17 16:28:05 -0700 | [diff] [blame] | 791 | /** |
| 792 | * seq_write - write arbitrary data to buffer |
| 793 | * @seq: seq_file identifying the buffer to which data should be written |
| 794 | * @data: data address |
| 795 | * @len: number of bytes |
| 796 | * |
| 797 | * Return 0 on success, non-zero otherwise. |
| 798 | */ |
| 799 | int seq_write(struct seq_file *seq, const void *data, size_t len) |
| 800 | { |
| 801 | if (seq->count + len < seq->size) { |
| 802 | memcpy(seq->buf + seq->count, data, len); |
| 803 | seq->count += len; |
| 804 | return 0; |
| 805 | } |
KAMEZAWA Hiroyuki | e075f59 | 2012-03-23 15:02:55 -0700 | [diff] [blame] | 806 | seq_set_overflow(seq); |
Peter Oberparleiter | 0b92360 | 2009-06-17 16:28:05 -0700 | [diff] [blame] | 807 | return -1; |
| 808 | } |
| 809 | EXPORT_SYMBOL(seq_write); |
| 810 | |
Tetsuo Handa | 839cc2a | 2013-11-14 14:31:56 -0800 | [diff] [blame] | 811 | /** |
| 812 | * seq_pad - write padding spaces to buffer |
| 813 | * @m: seq_file identifying the buffer to which data should be written |
| 814 | * @c: the byte to append after padding if non-zero |
| 815 | */ |
| 816 | void seq_pad(struct seq_file *m, char c) |
| 817 | { |
| 818 | int size = m->pad_until - m->count; |
Andrei Vagin | 8cfa67b4 | 2018-04-10 16:30:47 -0700 | [diff] [blame] | 819 | if (size > 0) { |
| 820 | if (size + m->count > m->size) { |
| 821 | seq_set_overflow(m); |
| 822 | return; |
| 823 | } |
| 824 | memset(m->buf + m->count, ' ', size); |
| 825 | m->count += size; |
| 826 | } |
Tetsuo Handa | 839cc2a | 2013-11-14 14:31:56 -0800 | [diff] [blame] | 827 | if (c) |
| 828 | seq_putc(m, c); |
| 829 | } |
| 830 | EXPORT_SYMBOL(seq_pad); |
| 831 | |
Andy Shevchenko | 3760710 | 2015-09-09 15:38:33 -0700 | [diff] [blame] | 832 | /* A complete analogue of print_hex_dump() */ |
| 833 | void seq_hex_dump(struct seq_file *m, const char *prefix_str, int prefix_type, |
| 834 | int rowsize, int groupsize, const void *buf, size_t len, |
| 835 | bool ascii) |
| 836 | { |
| 837 | const u8 *ptr = buf; |
| 838 | int i, linelen, remaining = len; |
Andy Shevchenko | 8b91a31 | 2015-11-06 16:32:37 -0800 | [diff] [blame] | 839 | char *buffer; |
| 840 | size_t size; |
Andy Shevchenko | 3760710 | 2015-09-09 15:38:33 -0700 | [diff] [blame] | 841 | int ret; |
| 842 | |
| 843 | if (rowsize != 16 && rowsize != 32) |
| 844 | rowsize = 16; |
| 845 | |
| 846 | for (i = 0; i < len && !seq_has_overflowed(m); i += rowsize) { |
| 847 | linelen = min(remaining, rowsize); |
| 848 | remaining -= rowsize; |
| 849 | |
| 850 | switch (prefix_type) { |
| 851 | case DUMP_PREFIX_ADDRESS: |
| 852 | seq_printf(m, "%s%p: ", prefix_str, ptr + i); |
| 853 | break; |
| 854 | case DUMP_PREFIX_OFFSET: |
| 855 | seq_printf(m, "%s%.8x: ", prefix_str, i); |
| 856 | break; |
| 857 | default: |
| 858 | seq_printf(m, "%s", prefix_str); |
| 859 | break; |
| 860 | } |
| 861 | |
Andy Shevchenko | 8b91a31 | 2015-11-06 16:32:37 -0800 | [diff] [blame] | 862 | size = seq_get_buf(m, &buffer); |
Andy Shevchenko | 3760710 | 2015-09-09 15:38:33 -0700 | [diff] [blame] | 863 | ret = hex_dump_to_buffer(ptr + i, linelen, rowsize, groupsize, |
Andy Shevchenko | 8b91a31 | 2015-11-06 16:32:37 -0800 | [diff] [blame] | 864 | buffer, size, ascii); |
| 865 | seq_commit(m, ret < size ? ret : -1); |
| 866 | |
| 867 | seq_putc(m, '\n'); |
Andy Shevchenko | 3760710 | 2015-09-09 15:38:33 -0700 | [diff] [blame] | 868 | } |
| 869 | } |
| 870 | EXPORT_SYMBOL(seq_hex_dump); |
| 871 | |
Pavel Emelianov | bcf67e1 | 2007-07-10 17:22:26 -0700 | [diff] [blame] | 872 | struct list_head *seq_list_start(struct list_head *head, loff_t pos) |
| 873 | { |
| 874 | struct list_head *lh; |
| 875 | |
| 876 | list_for_each(lh, head) |
| 877 | if (pos-- == 0) |
| 878 | return lh; |
| 879 | |
| 880 | return NULL; |
| 881 | } |
Pavel Emelianov | bcf67e1 | 2007-07-10 17:22:26 -0700 | [diff] [blame] | 882 | EXPORT_SYMBOL(seq_list_start); |
| 883 | |
| 884 | struct list_head *seq_list_start_head(struct list_head *head, loff_t pos) |
| 885 | { |
| 886 | if (!pos) |
| 887 | return head; |
| 888 | |
| 889 | return seq_list_start(head, pos - 1); |
| 890 | } |
Pavel Emelianov | bcf67e1 | 2007-07-10 17:22:26 -0700 | [diff] [blame] | 891 | EXPORT_SYMBOL(seq_list_start_head); |
| 892 | |
| 893 | struct list_head *seq_list_next(void *v, struct list_head *head, loff_t *ppos) |
| 894 | { |
| 895 | struct list_head *lh; |
| 896 | |
| 897 | lh = ((struct list_head *)v)->next; |
| 898 | ++*ppos; |
| 899 | return lh == head ? NULL : lh; |
| 900 | } |
Pavel Emelianov | bcf67e1 | 2007-07-10 17:22:26 -0700 | [diff] [blame] | 901 | EXPORT_SYMBOL(seq_list_next); |
Li Zefan | 66655de | 2010-02-08 23:18:22 +0000 | [diff] [blame] | 902 | |
| 903 | /** |
| 904 | * seq_hlist_start - start an iteration of a hlist |
| 905 | * @head: the head of the hlist |
| 906 | * @pos: the start position of the sequence |
| 907 | * |
| 908 | * Called at seq_file->op->start(). |
| 909 | */ |
| 910 | struct hlist_node *seq_hlist_start(struct hlist_head *head, loff_t pos) |
| 911 | { |
| 912 | struct hlist_node *node; |
| 913 | |
| 914 | hlist_for_each(node, head) |
| 915 | if (pos-- == 0) |
| 916 | return node; |
| 917 | return NULL; |
| 918 | } |
| 919 | EXPORT_SYMBOL(seq_hlist_start); |
| 920 | |
| 921 | /** |
| 922 | * seq_hlist_start_head - start an iteration of a hlist |
| 923 | * @head: the head of the hlist |
| 924 | * @pos: the start position of the sequence |
| 925 | * |
| 926 | * Called at seq_file->op->start(). Call this function if you want to |
| 927 | * print a header at the top of the output. |
| 928 | */ |
| 929 | struct hlist_node *seq_hlist_start_head(struct hlist_head *head, loff_t pos) |
| 930 | { |
| 931 | if (!pos) |
| 932 | return SEQ_START_TOKEN; |
| 933 | |
| 934 | return seq_hlist_start(head, pos - 1); |
| 935 | } |
| 936 | EXPORT_SYMBOL(seq_hlist_start_head); |
| 937 | |
| 938 | /** |
| 939 | * seq_hlist_next - move to the next position of the hlist |
| 940 | * @v: the current iterator |
| 941 | * @head: the head of the hlist |
Randy Dunlap | 138860b | 2010-03-04 09:37:12 -0800 | [diff] [blame] | 942 | * @ppos: the current position |
Li Zefan | 66655de | 2010-02-08 23:18:22 +0000 | [diff] [blame] | 943 | * |
| 944 | * Called at seq_file->op->next(). |
| 945 | */ |
| 946 | struct hlist_node *seq_hlist_next(void *v, struct hlist_head *head, |
| 947 | loff_t *ppos) |
| 948 | { |
| 949 | struct hlist_node *node = v; |
| 950 | |
| 951 | ++*ppos; |
| 952 | if (v == SEQ_START_TOKEN) |
| 953 | return head->first; |
| 954 | else |
| 955 | return node->next; |
| 956 | } |
| 957 | EXPORT_SYMBOL(seq_hlist_next); |
stephen hemminger | 1cc5232 | 2010-02-22 07:57:17 +0000 | [diff] [blame] | 958 | |
| 959 | /** |
| 960 | * seq_hlist_start_rcu - start an iteration of a hlist protected by RCU |
| 961 | * @head: the head of the hlist |
| 962 | * @pos: the start position of the sequence |
| 963 | * |
| 964 | * Called at seq_file->op->start(). |
| 965 | * |
| 966 | * This list-traversal primitive may safely run concurrently with |
| 967 | * the _rcu list-mutation primitives such as hlist_add_head_rcu() |
| 968 | * as long as the traversal is guarded by rcu_read_lock(). |
| 969 | */ |
| 970 | struct hlist_node *seq_hlist_start_rcu(struct hlist_head *head, |
| 971 | loff_t pos) |
| 972 | { |
| 973 | struct hlist_node *node; |
| 974 | |
| 975 | __hlist_for_each_rcu(node, head) |
| 976 | if (pos-- == 0) |
| 977 | return node; |
| 978 | return NULL; |
| 979 | } |
| 980 | EXPORT_SYMBOL(seq_hlist_start_rcu); |
| 981 | |
| 982 | /** |
| 983 | * seq_hlist_start_head_rcu - start an iteration of a hlist protected by RCU |
| 984 | * @head: the head of the hlist |
| 985 | * @pos: the start position of the sequence |
| 986 | * |
| 987 | * Called at seq_file->op->start(). Call this function if you want to |
| 988 | * print a header at the top of the output. |
| 989 | * |
| 990 | * This list-traversal primitive may safely run concurrently with |
| 991 | * the _rcu list-mutation primitives such as hlist_add_head_rcu() |
| 992 | * as long as the traversal is guarded by rcu_read_lock(). |
| 993 | */ |
| 994 | struct hlist_node *seq_hlist_start_head_rcu(struct hlist_head *head, |
| 995 | loff_t pos) |
| 996 | { |
| 997 | if (!pos) |
| 998 | return SEQ_START_TOKEN; |
| 999 | |
| 1000 | return seq_hlist_start_rcu(head, pos - 1); |
| 1001 | } |
| 1002 | EXPORT_SYMBOL(seq_hlist_start_head_rcu); |
| 1003 | |
| 1004 | /** |
| 1005 | * seq_hlist_next_rcu - move to the next position of the hlist protected by RCU |
| 1006 | * @v: the current iterator |
| 1007 | * @head: the head of the hlist |
Randy Dunlap | 138860b | 2010-03-04 09:37:12 -0800 | [diff] [blame] | 1008 | * @ppos: the current position |
stephen hemminger | 1cc5232 | 2010-02-22 07:57:17 +0000 | [diff] [blame] | 1009 | * |
| 1010 | * Called at seq_file->op->next(). |
| 1011 | * |
| 1012 | * This list-traversal primitive may safely run concurrently with |
| 1013 | * the _rcu list-mutation primitives such as hlist_add_head_rcu() |
| 1014 | * as long as the traversal is guarded by rcu_read_lock(). |
| 1015 | */ |
| 1016 | struct hlist_node *seq_hlist_next_rcu(void *v, |
| 1017 | struct hlist_head *head, |
| 1018 | loff_t *ppos) |
| 1019 | { |
| 1020 | struct hlist_node *node = v; |
| 1021 | |
| 1022 | ++*ppos; |
| 1023 | if (v == SEQ_START_TOKEN) |
| 1024 | return rcu_dereference(head->first); |
| 1025 | else |
| 1026 | return rcu_dereference(node->next); |
| 1027 | } |
| 1028 | EXPORT_SYMBOL(seq_hlist_next_rcu); |
Jeff Layton | 0bc7738 | 2013-06-21 08:58:21 -0400 | [diff] [blame] | 1029 | |
| 1030 | /** |
| 1031 | * seq_hlist_start_precpu - start an iteration of a percpu hlist array |
| 1032 | * @head: pointer to percpu array of struct hlist_heads |
| 1033 | * @cpu: pointer to cpu "cursor" |
| 1034 | * @pos: start position of sequence |
| 1035 | * |
| 1036 | * Called at seq_file->op->start(). |
| 1037 | */ |
| 1038 | struct hlist_node * |
| 1039 | seq_hlist_start_percpu(struct hlist_head __percpu *head, int *cpu, loff_t pos) |
| 1040 | { |
| 1041 | struct hlist_node *node; |
| 1042 | |
| 1043 | for_each_possible_cpu(*cpu) { |
| 1044 | hlist_for_each(node, per_cpu_ptr(head, *cpu)) { |
| 1045 | if (pos-- == 0) |
| 1046 | return node; |
| 1047 | } |
| 1048 | } |
| 1049 | return NULL; |
| 1050 | } |
| 1051 | EXPORT_SYMBOL(seq_hlist_start_percpu); |
| 1052 | |
| 1053 | /** |
| 1054 | * seq_hlist_next_percpu - move to the next position of the percpu hlist array |
| 1055 | * @v: pointer to current hlist_node |
| 1056 | * @head: pointer to percpu array of struct hlist_heads |
| 1057 | * @cpu: pointer to cpu "cursor" |
| 1058 | * @pos: start position of sequence |
| 1059 | * |
| 1060 | * Called at seq_file->op->next(). |
| 1061 | */ |
| 1062 | struct hlist_node * |
| 1063 | seq_hlist_next_percpu(void *v, struct hlist_head __percpu *head, |
| 1064 | int *cpu, loff_t *pos) |
| 1065 | { |
| 1066 | struct hlist_node *node = v; |
| 1067 | |
| 1068 | ++*pos; |
| 1069 | |
| 1070 | if (node->next) |
| 1071 | return node->next; |
| 1072 | |
| 1073 | for (*cpu = cpumask_next(*cpu, cpu_possible_mask); *cpu < nr_cpu_ids; |
| 1074 | *cpu = cpumask_next(*cpu, cpu_possible_mask)) { |
| 1075 | struct hlist_head *bucket = per_cpu_ptr(head, *cpu); |
| 1076 | |
| 1077 | if (!hlist_empty(bucket)) |
| 1078 | return bucket->first; |
| 1079 | } |
| 1080 | return NULL; |
| 1081 | } |
| 1082 | EXPORT_SYMBOL(seq_hlist_next_percpu); |
Alexey Dobriyan | 096523203 | 2018-04-10 16:34:45 -0700 | [diff] [blame] | 1083 | |
| 1084 | void __init seq_file_init(void) |
| 1085 | { |
Alexey Dobriyan | d64d01a | 2018-04-10 16:34:49 -0700 | [diff] [blame] | 1086 | seq_file_cache = KMEM_CACHE(seq_file, SLAB_ACCOUNT|SLAB_PANIC); |
Alexey Dobriyan | 096523203 | 2018-04-10 16:34:45 -0700 | [diff] [blame] | 1087 | } |