13f6cab07SMatt Macy /*- 24d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 33f6cab07SMatt Macy * 43f6cab07SMatt Macy * Copyright (c) 2016-2018, Matthew Macy <mmacy@freebsd.org> 53f6cab07SMatt Macy * 63f6cab07SMatt Macy * Redistribution and use in source and binary forms, with or without 73f6cab07SMatt Macy * modification, are permitted provided that the following conditions 83f6cab07SMatt Macy * are met: 93f6cab07SMatt Macy * 1. Redistributions of source code must retain the above copyright 103f6cab07SMatt Macy * notice, this list of conditions and the following disclaimer. 113f6cab07SMatt Macy * 2. Redistributions in binary form must reproduce the above copyright 123f6cab07SMatt Macy * notice, this list of conditions and the following disclaimer in the 133f6cab07SMatt Macy * documentation and/or other materials provided with the distribution. 143f6cab07SMatt Macy * 153f6cab07SMatt Macy * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 163f6cab07SMatt Macy * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 173f6cab07SMatt Macy * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 183f6cab07SMatt Macy * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 193f6cab07SMatt Macy * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 203f6cab07SMatt Macy * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 213f6cab07SMatt Macy * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 223f6cab07SMatt Macy * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 233f6cab07SMatt Macy * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 243f6cab07SMatt Macy * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 253f6cab07SMatt Macy * SUCH DAMAGE. 263f6cab07SMatt Macy */ 273f6cab07SMatt Macy 28307f78f3SVladimir Kondratyev #ifndef _LINUXKPI_LINUX_SEQ_FILE_H_ 29307f78f3SVladimir Kondratyev #define _LINUXKPI_LINUX_SEQ_FILE_H_ 303f6cab07SMatt Macy 316a65ca35SJohannes Lundberg #include <linux/types.h> 326a65ca35SJohannes Lundberg #include <linux/fs.h> 33*d6d1e73eSJean-Sébastien Pédron #include <linux/string_helpers.h> 343f6cab07SMatt Macy 356a65ca35SJohannes Lundberg #undef file 363f6cab07SMatt Macy #define inode vnode 373f6cab07SMatt Macy 38f697b943SJake Freeland MALLOC_DECLARE(M_LSEQ); 39f697b943SJake Freeland 406a65ca35SJohannes Lundberg #define DEFINE_SHOW_ATTRIBUTE(__name) \ 416a65ca35SJohannes Lundberg static int __name ## _open(struct inode *inode, struct linux_file *file) \ 426a65ca35SJohannes Lundberg { \ 436a65ca35SJohannes Lundberg return single_open(file, __name ## _show, inode->i_private); \ 446a65ca35SJohannes Lundberg } \ 456a65ca35SJohannes Lundberg \ 466a65ca35SJohannes Lundberg static const struct file_operations __name ## _fops = { \ 476a65ca35SJohannes Lundberg .owner = THIS_MODULE, \ 486a65ca35SJohannes Lundberg .open = __name ## _open, \ 496a65ca35SJohannes Lundberg .read = seq_read, \ 506a65ca35SJohannes Lundberg .llseek = seq_lseek, \ 516a65ca35SJohannes Lundberg .release = single_release, \ 526a65ca35SJohannes Lundberg } 536a65ca35SJohannes Lundberg 543f6cab07SMatt Macy struct seq_file { 553f6cab07SMatt Macy struct sbuf *buf; 565fbfe951SJean-Sébastien Pédron size_t size; 573f6cab07SMatt Macy const struct seq_operations *op; 583f6cab07SMatt Macy const struct linux_file *file; 593f6cab07SMatt Macy void *private; 603f6cab07SMatt Macy }; 613f6cab07SMatt Macy 623f6cab07SMatt Macy struct seq_operations { 633f6cab07SMatt Macy void * (*start) (struct seq_file *m, off_t *pos); 643f6cab07SMatt Macy void (*stop) (struct seq_file *m, void *v); 653f6cab07SMatt Macy void * (*next) (struct seq_file *m, void *v, off_t *pos); 663f6cab07SMatt Macy int (*show) (struct seq_file *m, void *v); 673f6cab07SMatt Macy }; 683f6cab07SMatt Macy 693f6cab07SMatt Macy ssize_t seq_read(struct linux_file *, char *, size_t, off_t *); 703f6cab07SMatt Macy int seq_write(struct seq_file *seq, const void *data, size_t len); 715fbfe951SJean-Sébastien Pédron void seq_putc(struct seq_file *m, char c); 725fbfe951SJean-Sébastien Pédron void seq_puts(struct seq_file *m, const char *str); 735fbfe951SJean-Sébastien Pédron bool seq_has_overflowed(struct seq_file *m); 743f6cab07SMatt Macy 75b5a81075SBjoern A. Zeeb void *__seq_open_private(struct linux_file *, const struct seq_operations *, int); 76b5a81075SBjoern A. Zeeb int seq_release_private(struct inode *, struct linux_file *); 77b5a81075SBjoern A. Zeeb 783f6cab07SMatt Macy int seq_open(struct linux_file *f, const struct seq_operations *op); 793f6cab07SMatt Macy int seq_release(struct inode *inode, struct linux_file *file); 803f6cab07SMatt Macy 813f6cab07SMatt Macy off_t seq_lseek(struct linux_file *file, off_t offset, int whence); 823f6cab07SMatt Macy int single_open(struct linux_file *, int (*)(struct seq_file *, void *), void *); 835fbfe951SJean-Sébastien Pédron int single_open_size(struct linux_file *, int (*)(struct seq_file *, void *), void *, size_t); 843f6cab07SMatt Macy int single_release(struct inode *, struct linux_file *); 853f6cab07SMatt Macy 86cbda8bedSHans Petter Selasky void lkpi_seq_vprintf(struct seq_file *m, const char *fmt, va_list args); 87cbda8bedSHans Petter Selasky void lkpi_seq_printf(struct seq_file *m, const char *fmt, ...); 88cbda8bedSHans Petter Selasky 89cbda8bedSHans Petter Selasky #define seq_vprintf(...) lkpi_seq_vprintf(__VA_ARGS__) 90cbda8bedSHans Petter Selasky #define seq_printf(...) lkpi_seq_printf(__VA_ARGS__) 913f6cab07SMatt Macy 926a65ca35SJohannes Lundberg #define file linux_file 933f6cab07SMatt Macy 94307f78f3SVladimir Kondratyev #endif /* _LINUXKPI_LINUX_SEQ_FILE_H_ */ 95