2 #include <linux/compiler.h> 3 #include <linux/kernel.h> 20 STDIN_FILENO : STDOUT_FILENO;
23 if (!fstat(fd, &st) && S_ISFIFO(st.st_mode))
40 if (!stat(data->
file.
path, &st) && st.st_size) {
43 snprintf(oldname,
sizeof(oldname),
"%s.old",
58 fd = open(data->
file.
path, O_RDONLY);
63 str_error_r(err, sbuf,
sizeof(sbuf)));
64 if (err == ENOENT && !strcmp(data->
file.
path,
"perf.data"))
65 pr_err(
" (try 'perf record' first)");
70 if (fstat(fd, &st) < 0)
73 if (!data->
force && st.st_uid && (st.st_uid != geteuid())) {
74 pr_err(
"File %s not owned by current user or root (use -f to override)\n",
80 pr_info(
"zero-sized data (%s), nothing to do!\n",
85 data->
size = st.st_size;
106 str_error_r(errno, sbuf,
sizeof(sbuf)));
119 return fd < 0 ? -1 : 0;
139 void *buf,
size_t size)
145 void *buf,
size_t size)
152 size_t pos,
bool at_exit)
162 if (asprintf(&new_filepath,
"%s.%s", data->
file.
path, postfix) < 0)
169 if (rename(data->
file.
path, new_filepath))
178 if (lseek(data->
file.
fd, pos, SEEK_SET) == (off_t)-1) {
180 pr_debug(
"Failed to lseek to %zu: %s",
static int open_file_read(struct perf_data *data)
static bool perf_data__is_read(struct perf_data *data)
ssize_t perf_data_file__write(struct perf_data_file *file, void *buf, size_t size)
struct perf_data_file file
#define pr_debug(fmt,...)
int perf_data__open(struct perf_data *data)
static int open_file(struct perf_data *data)
static bool check_pipe(struct perf_data *data)
static int check_backup(struct perf_data *data)
ssize_t perf_data__write(struct perf_data *data, void *buf, size_t size)
ssize_t writen(int fd, const void *buf, size_t n)
#define pr_warning(fmt,...)
int perf_data__switch(struct perf_data *data, const char *postfix, size_t pos, bool at_exit)
void perf_data__close(struct perf_data *data)
static int open_file_write(struct perf_data *data)