xref: /aosp_15_r20/external/erofs-utils/include/erofs/io.h (revision 33b1fccf6a0fada2c2875d400ed01119b7676ee5)
1 /* SPDX-License-Identifier: GPL-2.0+ OR Apache-2.0 */
2 /*
3  * Copyright (C) 2018-2019 HUAWEI, Inc.
4  *             http://www.huawei.com/
5  * Created by Li Guifu <[email protected]>
6  */
7 #ifndef __EROFS_IO_H
8 #define __EROFS_IO_H
9 
10 #ifdef __cplusplus
11 extern "C"
12 {
13 #endif
14 
15 #ifndef _GNU_SOURCE
16 #define _GNU_SOURCE
17 #endif
18 #include <unistd.h>
19 #include "defs.h"
20 
21 #ifndef O_BINARY
22 #define O_BINARY	0
23 #endif
24 
25 struct erofs_vfile;
26 
27 struct erofs_vfops {
28 	ssize_t (*pread)(struct erofs_vfile *vf, void *buf, u64 offset, size_t len);
29 	ssize_t (*pwrite)(struct erofs_vfile *vf, const void *buf, u64 offset, size_t len);
30 	int (*fsync)(struct erofs_vfile *vf);
31 	int (*fallocate)(struct erofs_vfile *vf, u64 offset, size_t len, bool pad);
32 	int (*ftruncate)(struct erofs_vfile *vf, u64 length);
33 	ssize_t (*read)(struct erofs_vfile *vf, void *buf, size_t len);
34 	off_t (*lseek)(struct erofs_vfile *vf, u64 offset, int whence);
35 	int (*fstat)(struct erofs_vfile *vf, struct stat *buf);
36 	int (*xcopy)(struct erofs_vfile *vout, off_t pos,
37 		     struct erofs_vfile *vin, unsigned int len, bool noseek);
38 };
39 
40 /* don't extend this; instead, use payload for any extra information */
41 struct erofs_vfile {
42 	struct erofs_vfops *ops;
43 	union {
44 		struct {
45 			u64 offset;
46 			int fd;
47 		};
48 		u8 payload[16];
49 	};
50 };
51 
52 int erofs_io_fstat(struct erofs_vfile *vf, struct stat *buf);
53 ssize_t erofs_io_pwrite(struct erofs_vfile *vf, const void *buf, u64 pos, size_t len);
54 int erofs_io_fsync(struct erofs_vfile *vf);
55 ssize_t erofs_io_fallocate(struct erofs_vfile *vf, u64 offset, size_t len, bool pad);
56 int erofs_io_ftruncate(struct erofs_vfile *vf, u64 length);
57 ssize_t erofs_io_pread(struct erofs_vfile *vf, void *buf, u64 offset, size_t len);
58 ssize_t erofs_io_read(struct erofs_vfile *vf, void *buf, size_t len);
59 off_t erofs_io_lseek(struct erofs_vfile *vf, u64 offset, int whence);
60 
61 ssize_t erofs_copy_file_range(int fd_in, u64 *off_in, int fd_out, u64 *off_out,
62 			      size_t length);
63 int erofs_io_xcopy(struct erofs_vfile *vout, off_t pos,
64 		   struct erofs_vfile *vin, unsigned int len, bool noseek);
65 
66 #ifdef __cplusplus
67 }
68 #endif
69 
70 #endif // EROFS_IO_H_
71