1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * erofs-utils/include/erofs/io.h
4  *
5  * Copyright (C) 2018-2019 HUAWEI, Inc.
6  *             http://www.huawei.com/
7  * Created by Li Guifu <bluce.liguifu@huawei.com>
8  */
9 #ifndef __EROFS_IO_H
10 #define __EROFS_IO_H
11 
12 #include <unistd.h>
13 #include "internal.h"
14 
15 #ifndef O_BINARY
16 #define O_BINARY	0
17 #endif
18 
19 int dev_open(const char *devname);
20 int dev_open_ro(const char *dev);
21 void dev_close(void);
22 int dev_write(const void *buf, u64 offset, size_t len);
23 int dev_read(void *buf, u64 offset, size_t len);
24 int dev_fillzero(u64 offset, size_t len, bool padding);
25 int dev_fsync(void);
26 int dev_resize(erofs_blk_t nblocks);
27 u64 dev_length(void);
28 
blk_write(const void * buf,erofs_blk_t blkaddr,u32 nblocks)29 static inline int blk_write(const void *buf, erofs_blk_t blkaddr,
30 			    u32 nblocks)
31 {
32 	return dev_write(buf, blknr_to_addr(blkaddr),
33 			 blknr_to_addr(nblocks));
34 }
35 
blk_read(void * buf,erofs_blk_t start,u32 nblocks)36 static inline int blk_read(void *buf, erofs_blk_t start,
37 			    u32 nblocks)
38 {
39 	return dev_read(buf, blknr_to_addr(start),
40 			 blknr_to_addr(nblocks));
41 }
42 
43 #endif
44 
45