2 * Copyright (C) 2013 - Julien Desfossez <jdesfossez@efficios.com>
3 * David Goulet <dgoulet@efficios.com>
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License, version 2 only, as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc., 51
16 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include <common/common.h>
24 #include <common/defaults.h>
25 #include <common/utils.h>
30 * Create the index file associated with a trace file.
32 * Return fd on success, a negative value on error.
34 int index_create_file(char *path_name
, char *stream_name
, int uid
, int gid
,
35 uint64_t size
, uint64_t count
)
39 struct lttng_packet_index_file_hdr hdr
;
40 char fullpath
[PATH_MAX
];
42 ret
= snprintf(fullpath
, sizeof(fullpath
), "%s/" DEFAULT_INDEX_DIR
,
45 PERROR("snprintf index path");
49 /* Create index directory if necessary. */
50 ret
= run_as_mkdir(fullpath
, S_IRWXU
| S_IRWXG
, uid
, gid
);
53 ERR("Index trace directory creation error");
58 ret
= utils_create_stream_file(fullpath
, stream_name
, size
, count
, uid
,
59 gid
, DEFAULT_INDEX_FILE_SUFFIX
);
65 memcpy(hdr
.magic
, INDEX_MAGIC
, sizeof(hdr
.magic
));
66 hdr
.index_major
= htobe32(INDEX_MAJOR
);
67 hdr
.index_minor
= htobe32(INDEX_MINOR
);
69 size_ret
= lttng_write(fd
, &hdr
, sizeof(hdr
));
70 if (size_ret
< sizeof(hdr
)) {
71 PERROR("write index header");
82 close_ret
= close(fd
);
84 PERROR("close index fd");
91 * Write index values to the given fd of size len.
93 * Return "len" on success or else < len on error. errno contains error
96 ssize_t
index_write(int fd
, struct lttng_packet_index
*index
, size_t len
)
103 ret
= lttng_write(fd
, index
, len
);
105 PERROR("writing index file");