1/* SPDX-License-Identifier: GPL-2.0-or-later */ 2/* 3 * Copyright (C) 2018-2023 Oracle. All Rights Reserved. 4 * Author: Darrick J. Wong <djwong@kernel.org> 5 */ 6#ifndef __XFS_SCRUB_XFILE_H__ 7#define __XFS_SCRUB_XFILE_H__ 8 9struct xfile_page { 10 struct page *page; 11 void *fsdata; 12 loff_t pos; 13}; 14 15static inline bool xfile_page_cached(const struct xfile_page *xfpage) 16{ 17 return xfpage->page != NULL; 18} 19 20static inline pgoff_t xfile_page_index(const struct xfile_page *xfpage) 21{ 22 return xfpage->page->index; 23} 24 25struct xfile { 26 struct file *file; 27}; 28 29int xfile_create(const char *description, loff_t isize, struct xfile **xfilep); 30void xfile_destroy(struct xfile *xf); 31 32ssize_t xfile_pread(struct xfile *xf, void *buf, size_t count, loff_t pos); 33ssize_t xfile_pwrite(struct xfile *xf, const void *buf, size_t count, 34 loff_t pos); 35 36/* 37 * Load an object. Since we're treating this file as "memory", any error or 38 * short IO is treated as a failure to allocate memory. 39 */ 40static inline int 41xfile_obj_load(struct xfile *xf, void *buf, size_t count, loff_t pos) 42{ 43 ssize_t ret = xfile_pread(xf, buf, count, pos); 44 45 if (ret < 0 || ret != count) 46 return -ENOMEM; 47 return 0; 48} 49 50/* 51 * Store an object. Since we're treating this file as "memory", any error or 52 * short IO is treated as a failure to allocate memory. 53 */ 54static inline int 55xfile_obj_store(struct xfile *xf, const void *buf, size_t count, loff_t pos) 56{ 57 ssize_t ret = xfile_pwrite(xf, buf, count, pos); 58 59 if (ret < 0 || ret != count) 60 return -ENOMEM; 61 return 0; 62} 63 64loff_t xfile_seek_data(struct xfile *xf, loff_t pos); 65 66struct xfile_stat { 67 loff_t size; 68 unsigned long long bytes; 69}; 70 71int xfile_stat(struct xfile *xf, struct xfile_stat *statbuf); 72 73int xfile_get_page(struct xfile *xf, loff_t offset, unsigned int len, 74 struct xfile_page *xbuf); 75int xfile_put_page(struct xfile *xf, struct xfile_page *xbuf); 76 77#endif /* __XFS_SCRUB_XFILE_H__ */ 78