trace_seq.c (8dd06ef34b6e2f41b29fbf5fc1663780f2524285) | trace_seq.c (f2cc020d7876de7583feb52ec939a32419cf9468) |
---|---|
1// SPDX-License-Identifier: GPL-2.0 2/* 3 * trace_seq.c 4 * 5 * Copyright (C) 2008-2014 Red Hat Inc, Steven Rostedt <srostedt@redhat.com> 6 * 7 * The trace_seq is a handy tool that allows you to pass a descriptor around 8 * to a buffer that other functions can write to. It is similar to the 9 * seq_file functionality but has some differences. 10 * 11 * To use it, the trace_seq must be initialized with trace_seq_init(). 12 * This will set up the counters within the descriptor. You can call 13 * trace_seq_init() more than once to reset the trace_seq to start 14 * from scratch. 15 * 16 * The buffer size is currently PAGE_SIZE, although it may become dynamic 17 * in the future. 18 * | 1// SPDX-License-Identifier: GPL-2.0 2/* 3 * trace_seq.c 4 * 5 * Copyright (C) 2008-2014 Red Hat Inc, Steven Rostedt <srostedt@redhat.com> 6 * 7 * The trace_seq is a handy tool that allows you to pass a descriptor around 8 * to a buffer that other functions can write to. It is similar to the 9 * seq_file functionality but has some differences. 10 * 11 * To use it, the trace_seq must be initialized with trace_seq_init(). 12 * This will set up the counters within the descriptor. You can call 13 * trace_seq_init() more than once to reset the trace_seq to start 14 * from scratch. 15 * 16 * The buffer size is currently PAGE_SIZE, although it may become dynamic 17 * in the future. 18 * |
19 * A write to the buffer will either succed or fail. That is, unlike | 19 * A write to the buffer will either succeed or fail. That is, unlike |
20 * sprintf() there will not be a partial write (well it may write into 21 * the buffer but it wont update the pointers). This allows users to 22 * try to write something into the trace_seq buffer and if it fails 23 * they can flush it and try again. 24 * 25 */ 26#include <linux/uaccess.h> 27#include <linux/seq_file.h> --- 40 unchanged lines hidden (view full) --- 68} 69 70/** 71 * trace_seq_printf - sequence printing of trace information 72 * @s: trace sequence descriptor 73 * @fmt: printf format string 74 * 75 * The tracer may use either sequence operations or its own | 20 * sprintf() there will not be a partial write (well it may write into 21 * the buffer but it wont update the pointers). This allows users to 22 * try to write something into the trace_seq buffer and if it fails 23 * they can flush it and try again. 24 * 25 */ 26#include <linux/uaccess.h> 27#include <linux/seq_file.h> --- 40 unchanged lines hidden (view full) --- 68} 69 70/** 71 * trace_seq_printf - sequence printing of trace information 72 * @s: trace sequence descriptor 73 * @fmt: printf format string 74 * 75 * The tracer may use either sequence operations or its own |
76 * copy to user routines. To simplify formating of a trace | 76 * copy to user routines. To simplify formatting of a trace |
77 * trace_seq_printf() is used to store strings into a special 78 * buffer (@s). Then the output may be either used by 79 * the sequencer or pulled into another buffer. 80 */ 81void trace_seq_printf(struct trace_seq *s, const char *fmt, ...) 82{ 83 unsigned int save_len = s->seq.len; 84 va_list ap; --- 43 unchanged lines hidden (view full) --- 128EXPORT_SYMBOL_GPL(trace_seq_bitmask); 129 130/** 131 * trace_seq_vprintf - sequence printing of trace information 132 * @s: trace sequence descriptor 133 * @fmt: printf format string 134 * 135 * The tracer may use either sequence operations or its own | 77 * trace_seq_printf() is used to store strings into a special 78 * buffer (@s). Then the output may be either used by 79 * the sequencer or pulled into another buffer. 80 */ 81void trace_seq_printf(struct trace_seq *s, const char *fmt, ...) 82{ 83 unsigned int save_len = s->seq.len; 84 va_list ap; --- 43 unchanged lines hidden (view full) --- 128EXPORT_SYMBOL_GPL(trace_seq_bitmask); 129 130/** 131 * trace_seq_vprintf - sequence printing of trace information 132 * @s: trace sequence descriptor 133 * @fmt: printf format string 134 * 135 * The tracer may use either sequence operations or its own |
136 * copy to user routines. To simplify formating of a trace | 136 * copy to user routines. To simplify formatting of a trace |
137 * trace_seq_printf is used to store strings into a special 138 * buffer (@s). Then the output may be either used by 139 * the sequencer or pulled into another buffer. 140 */ 141void trace_seq_vprintf(struct trace_seq *s, const char *fmt, va_list args) 142{ 143 unsigned int save_len = s->seq.len; 144 --- 76 unchanged lines hidden (view full) --- 221EXPORT_SYMBOL_GPL(trace_seq_puts); 222 223/** 224 * trace_seq_putc - trace sequence printing of simple character 225 * @s: trace sequence descriptor 226 * @c: simple character to record 227 * 228 * The tracer may use either the sequence operations or its own | 137 * trace_seq_printf is used to store strings into a special 138 * buffer (@s). Then the output may be either used by 139 * the sequencer or pulled into another buffer. 140 */ 141void trace_seq_vprintf(struct trace_seq *s, const char *fmt, va_list args) 142{ 143 unsigned int save_len = s->seq.len; 144 --- 76 unchanged lines hidden (view full) --- 221EXPORT_SYMBOL_GPL(trace_seq_puts); 222 223/** 224 * trace_seq_putc - trace sequence printing of simple character 225 * @s: trace sequence descriptor 226 * @c: simple character to record 227 * 228 * The tracer may use either the sequence operations or its own |
229 * copy to user routines. This function records a simple charater | 229 * copy to user routines. This function records a simple character |
230 * into a special buffer (@s) for later retrieval by a sequencer 231 * or other mechanism. 232 */ 233void trace_seq_putc(struct trace_seq *s, unsigned char c) 234{ 235 if (s->full) 236 return; 237 --- 105 unchanged lines hidden (view full) --- 343 return 0; 344 } 345 346 return 1; 347} 348EXPORT_SYMBOL_GPL(trace_seq_path); 349 350/** | 230 * into a special buffer (@s) for later retrieval by a sequencer 231 * or other mechanism. 232 */ 233void trace_seq_putc(struct trace_seq *s, unsigned char c) 234{ 235 if (s->full) 236 return; 237 --- 105 unchanged lines hidden (view full) --- 343 return 0; 344 } 345 346 return 1; 347} 348EXPORT_SYMBOL_GPL(trace_seq_path); 349 350/** |
351 * trace_seq_to_user - copy the squence buffer to user space | 351 * trace_seq_to_user - copy the sequence buffer to user space |
352 * @s: trace sequence descriptor 353 * @ubuf: The userspace memory location to copy to 354 * @cnt: The amount to copy 355 * 356 * Copies the sequence buffer into the userspace memory pointed to 357 * by @ubuf. It starts from the last read position (@s->readpos) 358 * and writes up to @cnt characters or till it reaches the end of 359 * the content in the buffer (@s->len), which ever comes first. 360 * 361 * On success, it returns a positive number of the number of bytes 362 * it copied. 363 * 364 * On failure it returns -EBUSY if all of the content in the 365 * sequence has been already read, which includes nothing in the | 352 * @s: trace sequence descriptor 353 * @ubuf: The userspace memory location to copy to 354 * @cnt: The amount to copy 355 * 356 * Copies the sequence buffer into the userspace memory pointed to 357 * by @ubuf. It starts from the last read position (@s->readpos) 358 * and writes up to @cnt characters or till it reaches the end of 359 * the content in the buffer (@s->len), which ever comes first. 360 * 361 * On success, it returns a positive number of the number of bytes 362 * it copied. 363 * 364 * On failure it returns -EBUSY if all of the content in the 365 * sequence has been already read, which includes nothing in the |
366 * sequenc (@s->len == @s->readpos). | 366 * sequence (@s->len == @s->readpos). |
367 * 368 * Returns -EFAULT if the copy to userspace fails. 369 */ 370int trace_seq_to_user(struct trace_seq *s, char __user *ubuf, int cnt) 371{ 372 __trace_seq_init(s); 373 return seq_buf_to_user(&s->seq, ubuf, cnt); 374} --- 31 unchanged lines hidden --- | 367 * 368 * Returns -EFAULT if the copy to userspace fails. 369 */ 370int trace_seq_to_user(struct trace_seq *s, char __user *ubuf, int cnt) 371{ 372 __trace_seq_init(s); 373 return seq_buf_to_user(&s->seq, ubuf, cnt); 374} --- 31 unchanged lines hidden --- |