1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*
3 * Copyright (c) 2021-2024 Oracle.  All Rights Reserved.
4 * Author: Darrick J. Wong <djwong@kernel.org>
5 */
6#ifndef __XFS_SCRUB_XFBLOB_H__
7#define __XFS_SCRUB_XFBLOB_H__
8
9struct xfblob {
10	struct xfile	*xfile;
11	loff_t		last_offset;
12};
13
14typedef loff_t		xfblob_cookie;
15
16int xfblob_create(const char *descr, struct xfblob **blobp);
17void xfblob_destroy(struct xfblob *blob);
18int xfblob_load(struct xfblob *blob, xfblob_cookie cookie, void *ptr,
19		uint32_t size);
20int xfblob_store(struct xfblob *blob, xfblob_cookie *cookie, const void *ptr,
21		uint32_t size);
22int xfblob_free(struct xfblob *blob, xfblob_cookie cookie);
23unsigned long long xfblob_bytes(struct xfblob *blob);
24void xfblob_truncate(struct xfblob *blob);
25
26static inline int
27xfblob_storename(
28	struct xfblob		*blob,
29	xfblob_cookie		*cookie,
30	const struct xfs_name	*xname)
31{
32	return xfblob_store(blob, cookie, xname->name, xname->len);
33}
34
35static inline int
36xfblob_loadname(
37	struct xfblob		*blob,
38	xfblob_cookie		cookie,
39	struct xfs_name		*xname,
40	uint32_t		size)
41{
42	int ret = xfblob_load(blob, cookie, (void *)xname->name, size);
43	if (ret)
44		return ret;
45
46	xname->len = size;
47	return 0;
48}
49
50#endif /* __XFS_SCRUB_XFBLOB_H__ */
51