• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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(struct erofs_sb_info *sbi);
26 int blob_open_ro(struct erofs_sb_info *sbi, const char *dev);
27 int dev_open(struct erofs_sb_info *sbi, const char *devname);
28 int dev_open_ro(struct erofs_sb_info *sbi, const char *dev);
29 void dev_close(struct erofs_sb_info *sbi);
30 int dev_write(struct erofs_sb_info *sbi, const void *buf,
31 	      u64 offset, size_t len);
32 int dev_read(struct erofs_sb_info *sbi, int device_id,
33 	     void *buf, u64 offset, size_t len);
34 int dev_fillzero(struct erofs_sb_info *sbi, u64 offset,
35 		 size_t len, bool padding);
36 int dev_fsync(struct erofs_sb_info *sbi);
37 int dev_resize(struct erofs_sb_info *sbi, erofs_blk_t nblocks);
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(struct erofs_sb_info * sbi,const void * buf,erofs_blk_t blkaddr,u32 nblocks)43 static inline int blk_write(struct erofs_sb_info *sbi, const void *buf,
44 			    erofs_blk_t blkaddr, u32 nblocks)
45 {
46 	return dev_write(sbi, buf, erofs_pos(sbi, blkaddr),
47 			 erofs_pos(sbi, nblocks));
48 }
49 
blk_read(struct erofs_sb_info * sbi,int device_id,void * buf,erofs_blk_t start,u32 nblocks)50 static inline int blk_read(struct erofs_sb_info *sbi, int device_id, void *buf,
51 			   erofs_blk_t start, u32 nblocks)
52 {
53 	return dev_read(sbi, device_id, buf, erofs_pos(sbi, start),
54 			erofs_pos(sbi, nblocks));
55 }
56 
57 #ifdef __cplusplus
58 }
59 #endif
60 
61 #endif // EROFS_IO_H_
62