mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 3/8] mtd: ubi: rename cdev.c to barebox.c
Date: Tue, 15 Mar 2016 12:22:27 +0100	[thread overview]
Message-ID: <1458040952-6826-4-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1458040952-6826-1-git-send-email-s.hauer@pengutronix.de>

cdev.c exists in the kernel UBI code, but barebox has completely
different content in this file. rename it to barebox.c to reduce the
number of merge conflicts. Also with the name barebox.c we now have
a place to put other barebox specific UBI code to.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/mtd/ubi/Makefile  |   2 +-
 drivers/mtd/ubi/barebox.c | 262 ++++++++++++++++++++++++++++++++++++++++++++++
 drivers/mtd/ubi/cdev.c    | 262 ----------------------------------------------
 3 files changed, 263 insertions(+), 263 deletions(-)
 create mode 100644 drivers/mtd/ubi/barebox.c
 delete mode 100644 drivers/mtd/ubi/cdev.c

diff --git a/drivers/mtd/ubi/Makefile b/drivers/mtd/ubi/Makefile
index 795b116..33ac390 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/barebox.c b/drivers/mtd/ubi/barebox.c
new file mode 100644
index 0000000..fe71a8d
--- /dev/null
+++ b/drivers/mtd/ubi/barebox.c
@@ -0,0 +1,262 @@
+#include <common.h>
+#include <fcntl.h>
+#include <fs.h>
+#include <ioctl.h>
+#include "ubi-barebox.h"
+#include "ubi.h"
+
+LIST_HEAD(ubi_volumes_list);
+
+struct ubi_volume_cdev_priv {
+	struct ubi_device *ubi;
+	struct ubi_volume *vol;
+	int written;
+};
+
+static ssize_t ubi_volume_cdev_read(struct cdev *cdev, void *buf, size_t size,
+		loff_t offset, unsigned long flags)
+{
+	struct ubi_volume_cdev_priv *priv = cdev->priv;
+	struct ubi_volume *vol = priv->vol;
+	struct ubi_device *ubi = priv->ubi;
+	int err, lnum, off, len;
+	size_t count_save = size;
+	unsigned long long tmp;
+	loff_t offp = offset;
+	int usable_leb_size = vol->usable_leb_size;
+
+	ubi_debug("%s: %zd @ 0x%08llx", __func__, size, offset);
+
+	len = size > usable_leb_size ? usable_leb_size : size;
+
+	tmp = offp;
+	off = do_div(tmp, usable_leb_size);
+	lnum = tmp;
+	do {
+		if (off + len >= usable_leb_size)
+			len = usable_leb_size - off;
+
+		err = ubi_eba_read_leb(ubi, vol, lnum, buf, off, len, 0);
+		if (err) {
+			ubi_err("read error: %s", strerror(-err));
+			break;
+		}
+		off += len;
+		if (off == usable_leb_size) {
+			lnum += 1;
+			off -= usable_leb_size;
+		}
+
+		size -= len;
+		offp += len;
+
+		buf += len;
+		len = size > usable_leb_size ? usable_leb_size : size;
+	} while (size);
+
+	return count_save;
+}
+
+static ssize_t ubi_volume_cdev_write(struct cdev* cdev, const void *buf,
+		size_t size, loff_t offset, unsigned long flags)
+{
+	struct ubi_volume_cdev_priv *priv = cdev->priv;
+	struct ubi_volume *vol = priv->vol;
+	struct ubi_device *ubi = priv->ubi;
+	int err;
+
+	if (!priv->written) {
+		err = ubi_start_update(ubi, vol, vol->used_bytes);
+		if (err < 0) {
+			ubi_err("Cannot start volume update");
+			return err;
+		}
+	}
+
+	err = ubi_more_update_data(ubi, vol, buf, size);
+	if (err < 0) {
+		ubi_err("Couldnt or partially wrote data");
+		return err;
+	}
+
+	priv->written += size;
+
+	return size;
+}
+
+static int ubi_volume_cdev_open(struct cdev *cdev, unsigned long flags)
+{
+	struct ubi_volume_cdev_priv *priv = cdev->priv;
+
+	priv->written = 0;
+
+	return 0;
+}
+
+static int ubi_volume_cdev_close(struct cdev *cdev)
+{
+	struct ubi_volume_cdev_priv *priv = cdev->priv;
+	struct ubi_volume *vol = priv->vol;
+	struct ubi_device *ubi = priv->ubi;
+	int err;
+
+	if (priv->written) {
+		int remaining = vol->usable_leb_size -
+				(priv->written % vol->usable_leb_size);
+
+		if (remaining) {
+			void *buf = kmalloc(remaining, GFP_KERNEL);
+
+			if (!buf)
+				return -ENOMEM;
+
+			memset(buf, 0xff, remaining);
+
+			err = ubi_more_update_data(ubi, vol, buf, remaining);
+
+			kfree(buf);
+
+			if (err < 0) {
+				ubi_err("Couldnt or partially wrote data");
+				return err;
+			}
+		}
+
+		err = ubi_finish_update(ubi, vol);
+		if (err)
+			return err;
+
+		err = ubi_check_volume(ubi, vol->vol_id);
+		if (err < 0) {
+			ubi_err("ubi volume check failed: %s", strerror(err));
+			return err;
+		}
+
+		if (err) {
+			ubi_warn("volume %d on UBI device %d is corrupted",
+					vol->vol_id, ubi->ubi_num);
+			vol->corrupted = 1;
+		}
+
+		vol->checked = 1;
+		ubi_volume_notify(ubi, vol, UBI_VOLUME_UPDATED);
+	}
+
+	return 0;
+}
+
+static loff_t ubi_volume_cdev_lseek(struct cdev *cdev, loff_t ofs)
+{
+	struct ubi_volume_cdev_priv *priv = cdev->priv;
+
+	/* We can only update ubi volumes sequentially */
+	if (priv->written)
+		return -EINVAL;
+
+	return ofs;
+}
+
+static struct file_operations ubi_volume_fops = {
+	.open	= ubi_volume_cdev_open,
+	.close	= ubi_volume_cdev_close,
+	.read   = ubi_volume_cdev_read,
+	.write  = ubi_volume_cdev_write,
+	.lseek	= ubi_volume_cdev_lseek,
+};
+
+int ubi_volume_cdev_add(struct ubi_device *ubi, struct ubi_volume *vol)
+{
+	struct cdev *cdev = &vol->cdev;
+	struct ubi_volume_cdev_priv *priv;
+	int ret;
+
+	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
+
+	priv->vol = vol;
+	priv->ubi = ubi;
+
+	cdev->ops = &ubi_volume_fops;
+	cdev->name = asprintf("%s.%s", ubi->cdev.name, vol->name);
+	cdev->priv = priv;
+	cdev->size = vol->used_bytes;
+	cdev->dev = &vol->dev;
+	ubi_msg("registering %s as /dev/%s", vol->name, cdev->name);
+	ret = devfs_create(cdev);
+	if (ret) {
+		kfree(priv);
+		free(cdev->name);
+	}
+
+	list_add_tail(&vol->list, &ubi_volumes_list);
+
+	return 0;
+}
+
+void ubi_volume_cdev_remove(struct ubi_volume *vol)
+{
+	struct cdev *cdev = &vol->cdev;
+	struct ubi_volume_cdev_priv *priv = cdev->priv;
+
+	list_del(&vol->list);
+
+	devfs_remove(cdev);
+	unregister_device(&vol->dev);
+	kfree(cdev->name);
+	kfree(priv);
+}
+
+static int ubi_cdev_ioctl(struct cdev *cdev, int cmd, void *buf)
+{
+	struct ubi_volume_desc *desc;
+	struct ubi_device *ubi = cdev->priv;
+	struct ubi_mkvol_req *req = buf;
+
+	switch (cmd) {
+	case UBI_IOCRMVOL:
+		desc = ubi_open_volume_nm(ubi->ubi_num, req->name,
+                                           UBI_EXCLUSIVE);
+		if (IS_ERR(desc))
+			return PTR_ERR(desc);
+		ubi_remove_volume(desc, 0);
+		ubi_close_volume(desc);
+		break;
+	case UBI_IOCMKVOL:
+		if (!req->bytes)
+			req->bytes = (__s64)ubi->avail_pebs * ubi->leb_size;
+		return ubi_create_volume(ubi, req);
+	};
+
+	return 0;
+}
+
+static struct file_operations ubi_fops = {
+	.ioctl	= ubi_cdev_ioctl,
+};
+
+int ubi_cdev_add(struct ubi_device *ubi)
+{
+	struct cdev *cdev = &ubi->cdev;
+	int ret;
+
+	cdev->ops = &ubi_fops;
+	cdev->name = asprintf("%s.ubi", ubi->mtd->cdev.name);
+	cdev->priv = ubi;
+	cdev->size = 0;
+
+	ubi_msg("registering /dev/%s", cdev->name);
+	ret = devfs_create(cdev);
+	if (ret)
+		kfree(cdev->name);
+
+	return ret;
+}
+
+void ubi_cdev_remove(struct ubi_device *ubi)
+{
+	struct cdev *cdev = &ubi->cdev;
+
+	ubi_msg("removing %s", cdev->name);
+
+	devfs_remove(cdev);
+	kfree(cdev->name);
+}
diff --git a/drivers/mtd/ubi/cdev.c b/drivers/mtd/ubi/cdev.c
deleted file mode 100644
index fe71a8d..0000000
--- a/drivers/mtd/ubi/cdev.c
+++ /dev/null
@@ -1,262 +0,0 @@
-#include <common.h>
-#include <fcntl.h>
-#include <fs.h>
-#include <ioctl.h>
-#include "ubi-barebox.h"
-#include "ubi.h"
-
-LIST_HEAD(ubi_volumes_list);
-
-struct ubi_volume_cdev_priv {
-	struct ubi_device *ubi;
-	struct ubi_volume *vol;
-	int written;
-};
-
-static ssize_t ubi_volume_cdev_read(struct cdev *cdev, void *buf, size_t size,
-		loff_t offset, unsigned long flags)
-{
-	struct ubi_volume_cdev_priv *priv = cdev->priv;
-	struct ubi_volume *vol = priv->vol;
-	struct ubi_device *ubi = priv->ubi;
-	int err, lnum, off, len;
-	size_t count_save = size;
-	unsigned long long tmp;
-	loff_t offp = offset;
-	int usable_leb_size = vol->usable_leb_size;
-
-	ubi_debug("%s: %zd @ 0x%08llx", __func__, size, offset);
-
-	len = size > usable_leb_size ? usable_leb_size : size;
-
-	tmp = offp;
-	off = do_div(tmp, usable_leb_size);
-	lnum = tmp;
-	do {
-		if (off + len >= usable_leb_size)
-			len = usable_leb_size - off;
-
-		err = ubi_eba_read_leb(ubi, vol, lnum, buf, off, len, 0);
-		if (err) {
-			ubi_err("read error: %s", strerror(-err));
-			break;
-		}
-		off += len;
-		if (off == usable_leb_size) {
-			lnum += 1;
-			off -= usable_leb_size;
-		}
-
-		size -= len;
-		offp += len;
-
-		buf += len;
-		len = size > usable_leb_size ? usable_leb_size : size;
-	} while (size);
-
-	return count_save;
-}
-
-static ssize_t ubi_volume_cdev_write(struct cdev* cdev, const void *buf,
-		size_t size, loff_t offset, unsigned long flags)
-{
-	struct ubi_volume_cdev_priv *priv = cdev->priv;
-	struct ubi_volume *vol = priv->vol;
-	struct ubi_device *ubi = priv->ubi;
-	int err;
-
-	if (!priv->written) {
-		err = ubi_start_update(ubi, vol, vol->used_bytes);
-		if (err < 0) {
-			ubi_err("Cannot start volume update");
-			return err;
-		}
-	}
-
-	err = ubi_more_update_data(ubi, vol, buf, size);
-	if (err < 0) {
-		ubi_err("Couldnt or partially wrote data");
-		return err;
-	}
-
-	priv->written += size;
-
-	return size;
-}
-
-static int ubi_volume_cdev_open(struct cdev *cdev, unsigned long flags)
-{
-	struct ubi_volume_cdev_priv *priv = cdev->priv;
-
-	priv->written = 0;
-
-	return 0;
-}
-
-static int ubi_volume_cdev_close(struct cdev *cdev)
-{
-	struct ubi_volume_cdev_priv *priv = cdev->priv;
-	struct ubi_volume *vol = priv->vol;
-	struct ubi_device *ubi = priv->ubi;
-	int err;
-
-	if (priv->written) {
-		int remaining = vol->usable_leb_size -
-				(priv->written % vol->usable_leb_size);
-
-		if (remaining) {
-			void *buf = kmalloc(remaining, GFP_KERNEL);
-
-			if (!buf)
-				return -ENOMEM;
-
-			memset(buf, 0xff, remaining);
-
-			err = ubi_more_update_data(ubi, vol, buf, remaining);
-
-			kfree(buf);
-
-			if (err < 0) {
-				ubi_err("Couldnt or partially wrote data");
-				return err;
-			}
-		}
-
-		err = ubi_finish_update(ubi, vol);
-		if (err)
-			return err;
-
-		err = ubi_check_volume(ubi, vol->vol_id);
-		if (err < 0) {
-			ubi_err("ubi volume check failed: %s", strerror(err));
-			return err;
-		}
-
-		if (err) {
-			ubi_warn("volume %d on UBI device %d is corrupted",
-					vol->vol_id, ubi->ubi_num);
-			vol->corrupted = 1;
-		}
-
-		vol->checked = 1;
-		ubi_volume_notify(ubi, vol, UBI_VOLUME_UPDATED);
-	}
-
-	return 0;
-}
-
-static loff_t ubi_volume_cdev_lseek(struct cdev *cdev, loff_t ofs)
-{
-	struct ubi_volume_cdev_priv *priv = cdev->priv;
-
-	/* We can only update ubi volumes sequentially */
-	if (priv->written)
-		return -EINVAL;
-
-	return ofs;
-}
-
-static struct file_operations ubi_volume_fops = {
-	.open	= ubi_volume_cdev_open,
-	.close	= ubi_volume_cdev_close,
-	.read   = ubi_volume_cdev_read,
-	.write  = ubi_volume_cdev_write,
-	.lseek	= ubi_volume_cdev_lseek,
-};
-
-int ubi_volume_cdev_add(struct ubi_device *ubi, struct ubi_volume *vol)
-{
-	struct cdev *cdev = &vol->cdev;
-	struct ubi_volume_cdev_priv *priv;
-	int ret;
-
-	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
-
-	priv->vol = vol;
-	priv->ubi = ubi;
-
-	cdev->ops = &ubi_volume_fops;
-	cdev->name = asprintf("%s.%s", ubi->cdev.name, vol->name);
-	cdev->priv = priv;
-	cdev->size = vol->used_bytes;
-	cdev->dev = &vol->dev;
-	ubi_msg("registering %s as /dev/%s", vol->name, cdev->name);
-	ret = devfs_create(cdev);
-	if (ret) {
-		kfree(priv);
-		free(cdev->name);
-	}
-
-	list_add_tail(&vol->list, &ubi_volumes_list);
-
-	return 0;
-}
-
-void ubi_volume_cdev_remove(struct ubi_volume *vol)
-{
-	struct cdev *cdev = &vol->cdev;
-	struct ubi_volume_cdev_priv *priv = cdev->priv;
-
-	list_del(&vol->list);
-
-	devfs_remove(cdev);
-	unregister_device(&vol->dev);
-	kfree(cdev->name);
-	kfree(priv);
-}
-
-static int ubi_cdev_ioctl(struct cdev *cdev, int cmd, void *buf)
-{
-	struct ubi_volume_desc *desc;
-	struct ubi_device *ubi = cdev->priv;
-	struct ubi_mkvol_req *req = buf;
-
-	switch (cmd) {
-	case UBI_IOCRMVOL:
-		desc = ubi_open_volume_nm(ubi->ubi_num, req->name,
-                                           UBI_EXCLUSIVE);
-		if (IS_ERR(desc))
-			return PTR_ERR(desc);
-		ubi_remove_volume(desc, 0);
-		ubi_close_volume(desc);
-		break;
-	case UBI_IOCMKVOL:
-		if (!req->bytes)
-			req->bytes = (__s64)ubi->avail_pebs * ubi->leb_size;
-		return ubi_create_volume(ubi, req);
-	};
-
-	return 0;
-}
-
-static struct file_operations ubi_fops = {
-	.ioctl	= ubi_cdev_ioctl,
-};
-
-int ubi_cdev_add(struct ubi_device *ubi)
-{
-	struct cdev *cdev = &ubi->cdev;
-	int ret;
-
-	cdev->ops = &ubi_fops;
-	cdev->name = asprintf("%s.ubi", ubi->mtd->cdev.name);
-	cdev->priv = ubi;
-	cdev->size = 0;
-
-	ubi_msg("registering /dev/%s", cdev->name);
-	ret = devfs_create(cdev);
-	if (ret)
-		kfree(cdev->name);
-
-	return ret;
-}
-
-void ubi_cdev_remove(struct ubi_device *ubi)
-{
-	struct cdev *cdev = &ubi->cdev;
-
-	ubi_msg("removing %s", cdev->name);
-
-	devfs_remove(cdev);
-	kfree(cdev->name);
-}
-- 
2.7.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2016-03-15 11:22 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-15 11:22 Let ubiformat umount / detach users Sascha Hauer
2016-03-15 11:22 ` [PATCH 1/8] fs: umount based on device path and mount path Sascha Hauer
2016-03-15 11:22 ` [PATCH 2/8] fs: Add for_each_fs_device_safe() Sascha Hauer
2016-03-15 11:22 ` Sascha Hauer [this message]
2016-03-15 11:22 ` [PATCH 4/8] mtd: ubi: make ubi_detach_mtd_dev ubi internal Sascha Hauer
2016-03-15 11:22 ` [PATCH 5/8] mtd: ubi: umount mounted volumes before detaching a ubi device Sascha Hauer
2016-03-15 11:22 ` [PATCH 6/8] mtd: ubi: Add function to get ubi number from mtd device Sascha Hauer
2016-03-15 11:22 ` [PATCH 7/8] commands: ubidetach: Allow mtd devices as argument Sascha Hauer
2016-03-15 11:22 ` [PATCH 8/8] ubiformat: Cleanly umount and detach the ubi before formating Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1458040952-6826-4-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox