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.
22 #include <common/common.h>
23 #include <common/defaults.h>
24 #include <common/utils.h>
29 * Create the index file associated with a trace file.
31 * Return fd on success, a negative value on error.
33 int index_create_file(char *path_name
, char *stream_name
, int uid
, int gid
,
34 uint64_t size
, uint64_t count
)
37 struct lttng_packet_index_file_hdr hdr
;
39 ret
= utils_create_stream_file(path_name
, stream_name
, size
, count
, uid
,
40 gid
, DEFAULT_INDEX_FILE_SUFFIX
);
46 memcpy(hdr
.magic
, INDEX_MAGIC
, sizeof(hdr
.magic
));
47 hdr
.index_major
= htobe32(INDEX_MAJOR
);
48 hdr
.index_minor
= htobe32(INDEX_MINOR
);
51 ret
= write(fd
, &hdr
, sizeof(hdr
));
52 } while (ret
< 0 && errno
== EINTR
);
54 PERROR("write index header");
64 close_ret
= close(fd
);
66 PERROR("close index fd");
73 * Write index values to the given fd of size len.
75 * Return 0 on success or else a negative value on error.
77 int index_write(int fd
, struct lttng_packet_index
*index
, size_t len
)
85 ret
= write(fd
, index
, len
);
86 } while (ret
< 0 && errno
== EINTR
);
88 PERROR("writing index file");