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 <bluce.liguifu@huawei.com>
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 "internal.h"
20
21 #ifndef O_BINARY
22 #define O_BINARY 0
23 #endif
24
25 void blob_closeall(void);
26 int blob_open_ro(const char *dev);
27 int dev_open(const char *devname);
28 int dev_open_ro(const char *dev);
29 void dev_close(void);
30 int dev_write(const void *buf, u64 offset, size_t len);
31 int dev_read(int device_id, void *buf, u64 offset, size_t len);
32 int dev_fillzero(u64 offset, size_t len, bool padding);
33 int dev_fsync(void);
34 int dev_resize(erofs_blk_t nblocks);
35 u64 dev_length(void);
36
37 extern int erofs_devfd;
38
39 ssize_t erofs_copy_file_range(int fd_in, erofs_off_t *off_in,
40 int fd_out, erofs_off_t *off_out,
41 size_t length);
42
blk_write(const void * buf,erofs_blk_t blkaddr,u32 nblocks)43 static inline int blk_write(const void *buf, erofs_blk_t blkaddr,
44 u32 nblocks)
45 {
46 return dev_write(buf, blknr_to_addr(blkaddr),
47 blknr_to_addr(nblocks));
48 }
49
blk_read(int device_id,void * buf,erofs_blk_t start,u32 nblocks)50 static inline int blk_read(int device_id, void *buf,
51 erofs_blk_t start, u32 nblocks)
52 {
53 return dev_read(device_id, buf, blknr_to_addr(start),
54 blknr_to_addr(nblocks));
55 }
56
57 #ifdef __cplusplus
58 }
59 #endif
60
61 #endif // EROFS_IO_H_
62