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