mesa/src/intel/mda/tar.h
Caio Oliveira bccc0fa984 intel/mda: Add code to produce mesa debug archives
Uses the tar format to collect multiple output files.  It can
be inspected using the regular UNIX tools, but a later commit
will add a specialized tool to perform common tasks.

The tar implementation is enough to fulfill the current needs
without adding a dependency.  There's also a small test mostly
to ensure scaffolding is there in case we need to expand the
implementation.

Acked-by: Kenneth Graunke <kenneth@whitecape.org>
Acked-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29146>
2025-09-24 23:08:45 -07:00

70 lines
1.3 KiB
C

/*
* Copyright 2023 Intel Corporation
* SPDX-License-Identifier: MIT
*/
#ifndef MDA_TAR_H
#define MDA_TAR_H
/* Subset of the tar archive format. The writer produces a fully valid tar file,
* and the reader is capable to read files procuded by that writer.
*/
#include <assert.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <time.h>
#include "slice.h"
#ifdef __cplusplus
extern "C" {
#endif
enum {
RECORD_SIZE = 512,
};
typedef long archive_pos;
typedef struct tar_writer {
FILE *file;
archive_pos header_pos;
char header[RECORD_SIZE];
bool error;
const char *prefix;
time_t timestamp;
} tar_writer;
void tar_writer_init(tar_writer *tw, FILE *f);
void tar_writer_start_file(tar_writer *tw, const char *filename);
void tar_writer_finish_file(tar_writer *tw);
void tar_writer_file_from_bytes(tar_writer *tw, const char *filename,
const char *contents, unsigned contents_size);
typedef struct {
slice contents;
bool error;
archive_pos pos;
} tar_reader;
void tar_reader_init_from_bytes(tar_reader *tr, const char *contents, unsigned contents_size);
typedef struct {
slice prefix;
slice name;
slice contents;
time_t mtime;
} tar_reader_entry;
bool tar_reader_next(tar_reader *tr, tar_reader_entry *entry);
#ifdef __cplusplus
}
#endif
#endif /* MDA_TAR_H */