summaryrefslogtreecommitdiff
path: root/include/sqfs/id_table.h
blob: b2097853e0911e506510ad64914f6e0444dd33d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* SPDX-License-Identifier: GPL-3.0-or-later */
/*
 * id_table.h
 *
 * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
 */
#ifndef ID_TABLE_H
#define ID_TABLE_H

#include "config.h"

#include <stdint.h>
#include <stddef.h>

#include "compress.h"

/* Encapsulates the ID table used by SquashFS */
typedef struct {
	/* Array of unique 32 bit IDs */
	uint32_t *ids;

	/* Number of 32 bit IDs stored in the array */
	size_t num_ids;

	/* Actual size of the array, i.e. maximum available */
	size_t max_ids;
} id_table_t;

#ifdef __cplusplus
extern "C" {
#endif

/* Returns 0 on success. Prints error message to stderr on failure. */
int id_table_init(id_table_t *tbl);

void id_table_cleanup(id_table_t *tbl);

/* Resolve a 32 bit to a 16 bit table index.
   Returns 0 on success. Internally prints errors to stderr. */
int id_table_id_to_index(id_table_t *tbl, uint32_t id, uint16_t *out);

/* Write an ID table to a SquashFS image.
   Returns 0 on success. Internally prints error message to stderr. */
int id_table_write(id_table_t *tbl, int outfd, sqfs_super_t *super,
		   compressor_t *cmp);

/* Read an ID table from a SquashFS image.
   Returns 0 on success. Internally prints error messages to stderr. */
int id_table_read(id_table_t *tbl, int fd, sqfs_super_t *super,
		  compressor_t *cmp);

#ifdef __cplusplus
}
#endif

#endif /* ID_TABLE_H */