]> www.infradead.org Git - mtd-utils.git/commitdiff
libubi: Add new interface ubi_leb_map()
authorZhihao Cheng <chengzhihao1@huawei.com>
Mon, 11 Nov 2024 08:36:53 +0000 (16:36 +0800)
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>
Mon, 11 Nov 2024 09:32:45 +0000 (10:32 +0100)
Add ubi_leb_map() implementation, it is used in UBIFS linux kernel libs.

This is a preparation for replacing implementation of UBIFS utils with
linux kernel libs.

Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
include/libubi.h
lib/libubi.c

index 9cb5037bb92a590c325a3ae8541c2821bfee5825..b5b3d8f3d327b189100737801aafcc2ae42eb2fb 100644 (file)
@@ -487,6 +487,21 @@ int ubi_leb_unmap(int fd, int lnum);
  */
 int ubi_is_mapped(int fd, int lnum);
 
+/**
+ * ubi_leb_map - map logical eraseblock to a physical eraseblock.
+ * @fd: volume character device file descriptor
+ * @lnum: logical eraseblock number
+ *
+ * This function maps an un-mapped logical eraseblock @lnum to a physical
+ * eraseblock. This means, that after a successful invocation of this
+ * function the logical eraseblock @lnum will be empty (contain only %0xFF
+ * bytes) and be mapped to a physical eraseblock, even if an unclean reboot
+ * happens.
+ *
+ * This function returns zero in case of success, %-1 in case of failures.
+ */
+int ubi_leb_map(int fd, int lnum);
+
 #ifdef __cplusplus
 }
 #endif
index 6b57e50d6bcf2cd09dbc23b3cf5003166b709d99..86736dd533546cffa2e097a78b91e62e9ff810e3 100644 (file)
@@ -1364,3 +1364,13 @@ int ubi_is_mapped(int fd, int lnum)
 {
        return ioctl(fd, UBI_IOCEBISMAP, &lnum);
 }
+
+int ubi_leb_map(int fd, int lnum)
+{
+       struct ubi_map_req r;
+
+       memset(&r, 0, sizeof(struct ubi_map_req));
+       r.lnum = lnum;
+
+       return ioctl(fd, UBI_IOCEBMAP, &r);
+}