Lines Matching +full:buffer +full:- +full:size
1 // SPDX-License-Identifier: GPL-2.0
8 * to a buffer that other functions can write to. It is similar to the
31 * seq_buf_can_fit - can the new data fit in the current buffer?
33 * @len: The length to see if it can fit in the current buffer
35 * Returns: true if there's enough unused space in the seq_buf buffer
40 return s->len + len <= s->size; in seq_buf_can_fit()
44 * seq_buf_print_seq - move the contents of seq_buf into a seq_file
48 * Returns: zero on success, non-zero otherwise.
54 return seq_write(m, s->buffer, len); in seq_buf_print_seq()
58 * seq_buf_vprintf - sequence printing of information.
63 * Writes a vnprintf() format into the sequence buffer.
65 * Returns: zero on success, -1 on overflow.
71 WARN_ON(s->size == 0); in seq_buf_vprintf()
73 if (s->len < s->size) { in seq_buf_vprintf()
74 len = vsnprintf(s->buffer + s->len, s->size - s->len, fmt, args); in seq_buf_vprintf()
75 if (s->len + len < s->size) { in seq_buf_vprintf()
76 s->len += len; in seq_buf_vprintf()
81 return -1; in seq_buf_vprintf()
85 * seq_buf_printf - sequence printing of information
89 * Writes a printf() format into the sequence buffer.
91 * Returns: zero on success, -1 on overflow.
107 * seq_buf_do_printk - printk() seq_buf line by line
111 * printk()-s a multi-line sequential buffer line by line. The function
112 * makes sure that the buffer in @s is NUL-terminated and safe to read
119 if (s->size == 0 || s->len == 0) in seq_buf_do_printk()
124 int len = lf - start + 1; in seq_buf_do_printk()
131 if (start < s->buffer + s->len) in seq_buf_do_printk()
138 * seq_buf_bprintf - Write the printf string from binary arguments
150 * the conversion into the ASCII string within the buffer.
152 * Returns: zero on success, -1 on overflow.
159 WARN_ON(s->size == 0); in seq_buf_bprintf()
161 if (s->len < s->size) { in seq_buf_bprintf()
162 ret = bstr_printf(s->buffer + s->len, len, fmt, binary); in seq_buf_bprintf()
163 if (s->len + ret < s->size) { in seq_buf_bprintf()
164 s->len += ret; in seq_buf_bprintf()
169 return -1; in seq_buf_bprintf()
174 * seq_buf_puts - sequence printing of simple string
178 * Copy a simple string into the sequence buffer.
180 * Returns: zero on success, -1 on overflow.
186 WARN_ON(s->size == 0); in seq_buf_puts()
192 memcpy(s->buffer + s->len, str, len); in seq_buf_puts()
194 s->len += len - 1; in seq_buf_puts()
198 return -1; in seq_buf_puts()
203 * seq_buf_putc - sequence printing of simple character
207 * Copy a single character into the sequence buffer.
209 * Returns: zero on success, -1 on overflow.
213 WARN_ON(s->size == 0); in seq_buf_putc()
216 s->buffer[s->len++] = c; in seq_buf_putc()
220 return -1; in seq_buf_putc()
225 * seq_buf_putmem - write raw data into the sequence buffer
227 * @mem: The raw memory to copy into the buffer
231 * buffer and a strcpy() would not work. Using this function allows
234 * Returns: zero on success, -1 on overflow.
238 WARN_ON(s->size == 0); in seq_buf_putmem()
241 memcpy(s->buffer + s->len, mem, len); in seq_buf_putmem()
242 s->len += len; in seq_buf_putmem()
246 return -1; in seq_buf_putmem()
253 * seq_buf_putmem_hex - write raw memory into the buffer in ASCII hex
259 * raw memory into the buffer it writes its ASCII representation of it
262 * Returns: zero on success, -1 on overflow.
272 WARN_ON(s->size == 0);
281 for (i = start_len-1, j = 0; i >= 0; i--) {
294 return -1;
296 len -= start_len;
303 * seq_buf_path - copy a path into the sequence buffer
305 * @path: path to write into the sequence buffer.
308 * Write a path name into the sequence buffer.
310 * Returns: the number of written bytes on success, -1 on overflow.
315 size_t size = seq_buf_get_buf(s, &buf); local
316 int res = -1;
318 WARN_ON(s->size == 0);
320 if (size) {
321 char *p = d_path(path, buf, size);
325 res = end - buf;
334 * seq_buf_to_user - copy the sequence buffer to user space
337 * @start: The first byte in the buffer to copy
340 * Copies the sequence buffer into the userspace memory pointed to
342 * or until it reaches the end of the content in the buffer (@s->len),
349 * On failure it returns -EBUSY if all of the content in the
351 * sequence (@s->len == @start).
353 * Returns -EFAULT if the copy to userspace fails.
366 return -EBUSY;
368 len -= start;
371 ret = copy_to_user(ubuf, s->buffer + start, cnt);
373 return -EFAULT;
375 return cnt - ret;
379 * seq_buf_hex_dump - print formatted hex dump into the sequence buffer
393 * linebuf size is maximal length for one line.
394 * 32 * 3 - maximum bytes per line, each printed into 2 chars + 1 for
396 * 2 - spaces separating hex dump and ASCII representation
397 * 32 - ASCII representation
398 * 1 - terminating '\0'
400 * Returns: zero on success, -1 on overflow.
416 remaining -= rowsize;