]> www.infradead.org Git - mtd-utils.git/commitdiff
mkfs.ubifs: Clear direct_write property when closing target
authorZhihao Cheng <chengzhihao1@huawei.com>
Wed, 7 Feb 2024 01:29:43 +0000 (09:29 +0800)
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>
Wed, 25 Sep 2024 07:08:41 +0000 (09:08 +0200)
Direct writing is not allowd on an UBI volume, unless the volume is set
with direct_write property. The open_target sets direct_write property,
don't forget to clear direct_write property for UBI volume when closing
target.

Fixes: a48340c335dab ("mkfs.ubifs: use libubi to format UBI volume")
Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
ubifs-utils/mkfs.ubifs/mkfs.ubifs.c

index 42a47f839e115567de58e8cdfcc50c4202fc7af1..5ca015128e335996c5f3dbe429e8f19659f378d8 100644 (file)
@@ -2832,7 +2832,7 @@ static int open_target(void)
                        return sys_err_msg("cannot open the UBI volume '%s'",
                                           output);
                if (ubi_set_property(out_fd, UBI_VOL_PROP_DIRECT_WRITE, 1))
-                       return sys_err_msg("ubi_set_property failed");
+                       return sys_err_msg("ubi_set_property(set direct_write) failed");
 
                if (!yes && check_volume_empty()) {
                        if (!prompt("UBI volume is not empty.  Format anyways?", false))
@@ -2859,10 +2859,14 @@ static int open_target(void)
  */
 static int close_target(void)
 {
+       if (out_fd >= 0) {
+               if (ubi && ubi_set_property(out_fd, UBI_VOL_PROP_DIRECT_WRITE, 0))
+                       return sys_err_msg("ubi_set_property(clear direct_write) failed");
+               if (close(out_fd) == -1)
+                       return sys_err_msg("cannot close the target '%s'", output);
+       }
        if (ubi)
                libubi_close(ubi);
-       if (out_fd >= 0 && close(out_fd) == -1)
-               return sys_err_msg("cannot close the target '%s'", output);
        if (output)
                free(output);
        return 0;