Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

UBI: Add ro-mode sysfs attribute

On serious situations, UBI may detect serious device corruption,
and switch to read-only mode to protect the data and allow debugging.
This commit exposes this ro-mode on sysfs, so it can be obtained
by userspace tools.

Signed-off-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
Signed-off-by: Richard Weinberger <richard@nod.at>

authored by

Ezequiel Garcia and committed by
Richard Weinberger
525bab71 04974df8

+14
+9
Documentation/ABI/stable/sysfs-class-ubi
··· 107 107 Description: 108 108 Number of physical eraseblocks reserved for bad block handling. 109 109 110 + What: /sys/class/ubi/ubiX/ro_mode 111 + Date: April 2016 112 + KernelVersion: 4.7 113 + Contact: linux-mtd@lists.infradead.org 114 + Description: 115 + Contains ASCII "1\n" if the read-only flag is set on this 116 + device, and "0\n" if it is cleared. UBI devices mark themselves 117 + as read-only when they detect an unrecoverable error. 118 + 110 119 What: /sys/class/ubi/ubiX/total_eraseblocks 111 120 Date: July 2006 112 121 KernelVersion: 2.6.22
+5
drivers/mtd/ubi/build.c
··· 149 149 __ATTR(bgt_enabled, S_IRUGO, dev_attribute_show, NULL); 150 150 static struct device_attribute dev_mtd_num = 151 151 __ATTR(mtd_num, S_IRUGO, dev_attribute_show, NULL); 152 + static struct device_attribute dev_ro_mode = 153 + __ATTR(ro_mode, S_IRUGO, dev_attribute_show, NULL); 152 154 153 155 /** 154 156 * ubi_volume_notify - send a volume change notification. ··· 387 385 ret = sprintf(buf, "%d\n", ubi->thread_enabled); 388 386 else if (attr == &dev_mtd_num) 389 387 ret = sprintf(buf, "%d\n", ubi->mtd->index); 388 + else if (attr == &dev_ro_mode) 389 + ret = sprintf(buf, "%d\n", ubi->ro_mode); 390 390 else 391 391 ret = -EINVAL; 392 392 ··· 408 404 &dev_min_io_size.attr, 409 405 &dev_bgt_enabled.attr, 410 406 &dev_mtd_num.attr, 407 + &dev_ro_mode.attr, 411 408 NULL 412 409 }; 413 410 ATTRIBUTE_GROUPS(ubi_dev);