@@ -16,4 +16,6 @@ int write_leb(struct ubifs_info *c, int lnum, int len, void *buf);
int close_target(void);
int open_target(struct ubifs_info *c, int yes);
int open_ubi(struct ubifs_info *c, const char *node);
+
+int ubifs_read(loff_t offset, int len, void *buf);
#endif
@@ -132,3 +132,21 @@ int write_leb(struct ubifs_info *c, int lnum, int len, void *buf)
return 0;
}
+
+/**
+ * ubifs_read - read data from ubi volume.
+ * @offset: offset of data in volume
+ * @len: length of data in the buffer
+ * @buf: buffer (must be at least c->leb_size bytes)
+ */
+int ubifs_read(loff_t offset, int len, void *buf)
+{
+ if (lseek(out_fd, offset, SEEK_SET) != offset)
+ return sys_err_msg("lseek failed seeking %"PRIdoff_t, offset);
+
+ if (read(out_fd, buf, len) != len)
+ return sys_err_msg("write failed writing %d bytes at pos %"PRIdoff_t,
+ len, offset);
+
+ return 0;
+}
Implement a ubifs_read function in io lib. This function will read the data at offset in length of len from ubi volume to buf. Signed-off-by: Dongsheng Yang <yangds.fnst@cn.fujitsu.com> --- ubifs-utils/include/io.h | 2 ++ ubifs-utils/lib/io.c | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+)