summaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2016-04-08 13:37:28 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2016-04-08 13:37:28 +0200
commit5a4379527259d426c2ac8f5f06c358c175a33237 (patch)
tree2589a5cc2e223ae7706efb7035ebc729be2738fa /drivers
parent11b2257f4b2c7440925f1c0772905f3c4eea2def (diff)
parentd43c5b45ab24b9639a103b2ff9d829962c0e472b (diff)
downloadbarebox-5a4379527259d426c2ac8f5f06c358c175a33237.tar.gz
barebox-5a4379527259d426c2ac8f5f06c358c175a33237.tar.xz
Merge branch 'for-next/ubiformat'
Diffstat (limited to 'drivers')
-rw-r--r--drivers/mtd/ubi/Makefile2
-rw-r--r--drivers/mtd/ubi/barebox.c (renamed from drivers/mtd/ubi/cdev.c)57
-rw-r--r--drivers/mtd/ubi/ubi.h1
3 files changed, 59 insertions, 1 deletions
diff --git a/drivers/mtd/ubi/Makefile b/drivers/mtd/ubi/Makefile
index 795b116ecc..33ac39026c 100644
--- a/drivers/mtd/ubi/Makefile
+++ b/drivers/mtd/ubi/Makefile
@@ -1,5 +1,5 @@
obj-$(CONFIG_MTD_UBI) += ubi.o
-ubi-y += vtbl.o vmt.o upd.o build.o cdev.o kapi.o eba.o io.o wl.o attach.o
+ubi-y += vtbl.o vmt.o upd.o build.o barebox.o kapi.o eba.o io.o wl.o attach.o
ubi-y += misc.o debug.o
ubi-$(CONFIG_MTD_UBI_FASTMAP) += fastmap.o
diff --git a/drivers/mtd/ubi/cdev.c b/drivers/mtd/ubi/barebox.c
index fe71a8d609..c26a2455b2 100644
--- a/drivers/mtd/ubi/cdev.c
+++ b/drivers/mtd/ubi/barebox.c
@@ -260,3 +260,60 @@ void ubi_cdev_remove(struct ubi_device *ubi)
devfs_remove(cdev);
kfree(cdev->name);
}
+
+static void ubi_umount_volumes(struct ubi_device *ubi)
+{
+ int i;
+
+ for (i = 0; i < ubi->vtbl_slots; i++) {
+ struct ubi_volume *vol = ubi->volumes[i];
+ if (!vol)
+ continue;
+ umount_by_cdev(&vol->cdev);
+ }
+}
+
+/**
+ * ubi_detach - detach an UBI device
+ * @ubi_num: The UBI device number
+ *
+ * UBI volumes used by UBIFS will be unmounted before detaching the
+ * UBI device.
+ *
+ * @return: 0 for success, negative error code otherwise
+ */
+int ubi_detach(int ubi_num)
+{
+ struct ubi_device *ubi;
+
+ if (ubi_num < 0 || ubi_num >= UBI_MAX_DEVICES)
+ return -EINVAL;
+
+ ubi = ubi_devices[ubi_num];
+ if (!ubi)
+ return -ENOENT;
+
+ ubi_umount_volumes(ubi);
+
+ return ubi_detach_mtd_dev(ubi_num, 1);
+}
+
+/**
+ * ubi_num_get_by_mtd - find the ubi number to the given mtd
+ * @mtd: the mtd device
+ *
+ * @return: positive or zero for a UBI number, negative error code otherwise
+ */
+int ubi_num_get_by_mtd(struct mtd_info *mtd)
+{
+ int i;
+ struct ubi_device *ubi;
+
+ for (i = 0; i < UBI_MAX_DEVICES; i++) {
+ ubi = ubi_devices[i];
+ if (ubi && mtd == ubi->mtd)
+ return ubi->ubi_num;
+ }
+
+ return -ENOENT;
+}
diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h
index 03a36d2e76..a8ed0d7710 100644
--- a/drivers/mtd/ubi/ubi.h
+++ b/drivers/mtd/ubi/ubi.h
@@ -809,6 +809,7 @@ int ubi_io_write_vid_hdr(struct ubi_device *ubi, int pnum,
struct ubi_vid_hdr *vid_hdr);
/* build.c */
+int ubi_detach_mtd_dev(int ubi_num, int anyway);
struct ubi_device *ubi_get_device(int ubi_num);
void ubi_put_device(struct ubi_device *ubi);
struct ubi_device *ubi_get_by_major(int major);