/** * trace_seq_putmem_hex - write raw memory into the buffer in ASCII hex * @s: trace sequence descriptor * @mem: The raw memory to write its hex ASCII representation of * @len: The length of the raw memory to copy (in bytes) * * This is similar to trace_seq_putmem() except instead of just copying the * raw memory into the buffer it writes its ASCII representation of it * in hex characters. */ void trace_seq_putmem_hex(struct trace_seq *s, const void *mem, unsigned int len) { unsigned int save_len = s->seq.len; if (s->full) return; __trace_seq_init(s); /* Each byte is represented by two chars */ if (len * 2 > TRACE_SEQ_BUF_LEFT(s)) { s->full = 1; return; } /* The added spaces can still cause an overflow */ seq_buf_putmem_hex(&s->seq, mem, len); if (unlikely(seq_buf_has_overflowed(&s->seq))) { s->seq.len = save_len; s->full = 1; return; } }
/** * trace_seq_vprintf - sequence printing of trace information * @s: trace sequence descriptor * @fmt: printf format string * * The tracer may use either sequence operations or its own * copy to user routines. To simplify formating of a trace * trace_seq_printf is used to store strings into a special * buffer (@s). Then the output may be either used by * the sequencer or pulled into another buffer. */ void trace_seq_vprintf(struct trace_seq *s, const char *fmt, va_list args) { unsigned int save_len = s->seq.len; if (s->full) return; __trace_seq_init(s); seq_buf_vprintf(&s->seq, fmt, args); /* If we can't write it all, don't bother writing anything */ if (unlikely(seq_buf_has_overflowed(&s->seq))) { s->seq.len = save_len; s->full = 1; } }
/** * trace_seq_bitmask - write a bitmask array in its ASCII representation * @s: trace sequence descriptor * @maskp: points to an array of unsigned longs that represent a bitmask * @nmaskbits: The number of bits that are valid in @maskp * * Writes a ASCII representation of a bitmask string into @s. */ void trace_seq_bitmask(struct trace_seq *s, const unsigned long *maskp, int nmaskbits) { unsigned int save_len = s->seq.len; if (s->full) return; __trace_seq_init(s); seq_buf_printf(&s->seq, "%*pb", nmaskbits, maskp); if (unlikely(seq_buf_has_overflowed(&s->seq))) { s->seq.len = save_len; s->full = 1; } }
/** * trace_seq_path - copy a path into the sequence buffer * @s: trace sequence descriptor * @path: path to write into the sequence buffer. * * Write a path name into the sequence buffer. * * Returns 1 if we successfully written all the contents to * the buffer. * Returns 0 if we the length to write is bigger than the * reserved buffer space. In this case, nothing gets written. */ int trace_seq_path(struct trace_seq *s, const struct path *path) { unsigned int save_len = s->seq.len; if (s->full) return 0; __trace_seq_init(s); if (TRACE_SEQ_BUF_LEFT(s) < 1) { s->full = 1; return 0; } seq_buf_path(&s->seq, path, "\n\\"); if (unlikely(seq_buf_has_overflowed(&s->seq))) { s->seq.len = save_len; s->full = 1; return 0; } return 1; }
/** * seq_buf_putmem_hex - write raw memory into the buffer in ASCII hex * @s: seq_buf descriptor * @mem: The raw memory to write its hex ASCII representation of * @len: The length of the raw memory to copy (in bytes) * * This is similar to seq_buf_putmem() except instead of just copying the * raw memory into the buffer it writes its ASCII representation of it * in hex characters. * * Returns zero on success, -1 on overflow */ int seq_buf_putmem_hex(struct seq_buf *s, const void *mem, unsigned int len) { unsigned char hex[HEX_CHARS]; const unsigned char *data = mem; unsigned int start_len; int i, j; WARN_ON(s->size == 0); while (len) { start_len = min(len, HEX_CHARS - 1); #ifdef __BIG_ENDIAN for (i = 0, j = 0; i < start_len; i++) { #else for (i = start_len-1, j = 0; i >= 0; i--) { #endif hex[j++] = hex_asc_hi(data[i]); hex[j++] = hex_asc_lo(data[i]); } if (WARN_ON_ONCE(j == 0 || j/2 > len)) break; /* j increments twice per loop */ len -= j / 2; hex[j++] = ' '; seq_buf_putmem(s, hex, j); if (seq_buf_has_overflowed(s)) return -1; } return 0; } /** * seq_buf_path - copy a path into the sequence buffer * @s: seq_buf descriptor * @path: path to write into the sequence buffer. * @esc: set of characters to escape in the output * * Write a path name into the sequence buffer. * * Returns the number of written bytes on success, -1 on overflow */ int seq_buf_path(struct seq_buf *s, const struct path *path, const char *esc) { char *buf; size_t size = seq_buf_get_buf(s, &buf); int res = -1; WARN_ON(s->size == 0); if (size) { char *p = d_path(path, buf, size); if (!IS_ERR(p)) { char *end = mangle_path(buf, p, esc); if (end) res = end - buf; } } seq_buf_commit(s, res); return res; }