aboutsummaryrefslogtreecommitdiff
path: root/lib/sqfs/write_export_table.c
blob: 2815cc2514d8c36e27dae63d49aec8ed2dd2b98e (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
/* SPDX-License-Identifier: GPL-3.0-or-later */
#include "highlevel.h"

#include <stdlib.h>
#include <stdio.h>

int write_export_table(int outfd, fstree_t *fs, sqfs_super_t *super,
		       compressor_t *cmp)
{
	uint64_t *table, start;
	size_t i;
	int ret;

	table = malloc(sizeof(uint64_t) * (fs->inode_tbl_size - 1));

	if (table == NULL) {
		perror("Allocating NFS export table");
		return -1;
	}

	for (i = 1; i < fs->inode_tbl_size; ++i) {
		if (fs->inode_table[i] == NULL) {
			table[i - 1] = htole64(0xFFFFFFFFFFFFFFFF);
		} else {
			table[i - 1] = htole64(fs->inode_table[i]->inode_ref);
		}
	}

	ret = sqfs_write_table(outfd, super, table, sizeof(table[0]),
			       fs->inode_tbl_size - 1, &start, cmp);

	super->export_table_start = start;
	super->flags |= SQFS_FLAG_EXPORTABLE;
	free(table);
	return ret;
}