]> Git Repo - linux.git/blob - fs/xfs/scrub/xfile.h
media: ipu-bridge: Fix Kconfig dependencies
[linux.git] / fs / xfs / scrub / xfile.h
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * Copyright (C) 2018-2023 Oracle.  All Rights Reserved.
4  * Author: Darrick J. Wong <[email protected]>
5  */
6 #ifndef __XFS_SCRUB_XFILE_H__
7 #define __XFS_SCRUB_XFILE_H__
8
9 struct xfile_page {
10         struct page             *page;
11         void                    *fsdata;
12         loff_t                  pos;
13 };
14
15 static inline bool xfile_page_cached(const struct xfile_page *xfpage)
16 {
17         return xfpage->page != NULL;
18 }
19
20 static inline pgoff_t xfile_page_index(const struct xfile_page *xfpage)
21 {
22         return xfpage->page->index;
23 }
24
25 struct xfile {
26         struct file             *file;
27 };
28
29 int xfile_create(const char *description, loff_t isize, struct xfile **xfilep);
30 void xfile_destroy(struct xfile *xf);
31
32 ssize_t xfile_pread(struct xfile *xf, void *buf, size_t count, loff_t pos);
33 ssize_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  */
40 static inline int
41 xfile_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  */
54 static inline int
55 xfile_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
64 loff_t xfile_seek_data(struct xfile *xf, loff_t pos);
65
66 struct xfile_stat {
67         loff_t                  size;
68         unsigned long long      bytes;
69 };
70
71 int xfile_stat(struct xfile *xf, struct xfile_stat *statbuf);
72
73 int xfile_get_page(struct xfile *xf, loff_t offset, unsigned int len,
74                 struct xfile_page *xbuf);
75 int xfile_put_page(struct xfile *xf, struct xfile_page *xbuf);
76
77 #endif /* __XFS_SCRUB_XFILE_H__ */
This page took 0.035931 seconds and 4 git commands to generate.