All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] Add support for UBI and UBIFS
@ 2009-08-24 11:11 Corentin Chary
  2009-08-24 11:11 ` [PATCH 1/3] blkid: add UBI volume support Corentin Chary
                   ` (2 more replies)
  0 siblings, 3 replies; 22+ messages in thread
From: Corentin Chary @ 2009-08-24 11:11 UTC (permalink / raw)
  To: util-linux-ng; +Cc: Corentin Chary, linux-mtd, dedekind1

Hi,
Here is some patchs to add support for UBI and UBIFS in libblkid.

UBIFS works on top of UBI volumes, there are 3 subsystems involved:
  * MTD subsystem, which provides uniform interface to access flash chips.
    MTD provides an notion of MTD devices (e.g., /dev/mtd0) which basically represents raw flash;
  * UBI subsystem, which is a wear-leveling and volume management system for flash devices;
    UBI works on top of MTD devices and provides a notion of UBI volumes (e.g.m /dev/ubi0_0);
  * UBIFS file system, which works on top of UBI volumes.

The first patch add support for UBI volumes, which are represented as char devices in /dev/.
This allow to probe for UBIFS filesystem on UBI volumes.

Thanks,

Corentin Chary (3):
  blkid: add UBI volume support
  blkid: add ubifs support
  blkid: add UBIFS test image to blkid test suite

 shlibs/blkid/src/blkidP.h            |    1 +
 shlibs/blkid/src/devname.c           |   56 +++++++++++++++-
 shlibs/blkid/src/probe.c             |    5 +-
 shlibs/blkid/src/probers/Makefile.am |    3 +-
 shlibs/blkid/src/probers/probers.h   |    1 +
 shlibs/blkid/src/probers/ubifs.c     |  122 ++++++++++++++++++++++++++++++++++
 tests/expected/blkid/low-probe-ubifs |    5 ++
 tests/ts/blkid/images/ubifs.img.bz2  |  Bin 0 -> 937 bytes
 8 files changed, 190 insertions(+), 3 deletions(-)
 create mode 100644 shlibs/blkid/src/probers/ubifs.c
 create mode 100644 tests/expected/blkid/low-probe-ubifs
 create mode 100644 tests/ts/blkid/images/ubifs.img.bz2

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [PATCH 1/3] blkid: add UBI volume support
  2009-08-24 11:11 [PATCH 0/3] Add support for UBI and UBIFS Corentin Chary
@ 2009-08-24 11:11 ` Corentin Chary
  2009-08-24 11:11   ` [PATCH 2/3] blkid: add ubifs support Corentin Chary
                     ` (2 more replies)
  2009-08-31 19:03 ` [PATCH 0/3] Add support for UBI and UBIFS Corentin Chary
  2009-09-24 14:06 ` Karel Zak
  2 siblings, 3 replies; 22+ messages in thread
From: Corentin Chary @ 2009-08-24 11:11 UTC (permalink / raw)
  To: util-linux-ng; +Cc: Corentin Chary, linux-mtd, dedekind1

Probe UBI volume under /dev (or /devfs, /devices).
ubi_ctrl skip is hardcoded, maybe we should find a
cleaner way to do that. Also change probe.c to handle
char devices.

Signed-off-by: Corentin Chary <corentincj@iksaif.net>
---
 shlibs/blkid/src/blkidP.h  |    1 +
 shlibs/blkid/src/devname.c |   56 +++++++++++++++++++++++++++++++++++++++++++-
 shlibs/blkid/src/probe.c   |    2 +
 3 files changed, 58 insertions(+), 1 deletions(-)

diff --git a/shlibs/blkid/src/blkidP.h b/shlibs/blkid/src/blkidP.h
index e0e5cb8..8db6599 100644
--- a/shlibs/blkid/src/blkidP.h
+++ b/shlibs/blkid/src/blkidP.h
@@ -237,6 +237,7 @@ extern char *blkid_strndup(const char *s, const int length);
 /*
  * Priority settings for different types of devices
  */
+#define BLKID_PRI_UBI	50
 #define BLKID_PRI_DM	40
 #define BLKID_PRI_EVMS	30
 #define BLKID_PRI_LVM	20
diff --git a/shlibs/blkid/src/devname.c b/shlibs/blkid/src/devname.c
index ef686f4..cac13c5 100644
--- a/shlibs/blkid/src/devname.c
+++ b/shlibs/blkid/src/devname.c
@@ -229,7 +229,9 @@ static void probe_one(blkid_cache cache, const char *ptname,
 		    dev->bid_devno == devno)
 			goto set_pri;
 
-		if (stat(device, &st) == 0 && S_ISBLK(st.st_mode) &&
+		if (stat(device, &st) == 0 &&
+		    (S_ISBLK(st.st_mode) ||
+		     (S_ISCHR(st.st_mode) && !strncmp(ptname, "ubi", 3))) &&
 		    st.st_rdev == devno) {
 			devname = blkid_strdup(device);
 			goto get_dev;
@@ -388,6 +390,57 @@ evms_probe_all(blkid_cache cache, int only_if_new)
 	return num;
 }
 
+static void
+ubi_probe_all(blkid_cache cache, int only_if_new)
+{
+	const char **dirname;
+
+	for (dirname = dirlist; *dirname; dirname++) {
+		DBG(DEBUG_DEVNAME, printf("probing UBI volumes under %s\n",
+					  *dirname));
+
+		DIR		*dir;
+		struct dirent	*iter;
+
+		dir = opendir(*dirname);
+		if (dir == NULL)
+			continue ;
+
+		while ((iter = readdir(dir)) != NULL) {
+			char		*name, *device;
+			struct stat	st;
+			dev_t		dev;
+
+			name = iter->d_name;
+
+			if (!strcmp(name, ".") || !strcmp(name, "..") ||
+			    !strstr(name, "ubi"))
+				continue;
+			if (!strcmp(name, "ubi_ctrl"))
+				continue;
+			device = malloc(strlen(*dirname) + strlen(name) + 2);
+			if (!device)
+				break ;
+			sprintf(device, "%s/%s", *dirname, name);
+			if (stat(device, &st))
+				break ;
+
+			if (!(st.st_rdev & 0xFF)) { // It's an UBI Device
+				free(device);
+				continue ;
+			}
+			dev = st.st_rdev;
+			DBG(DEBUG_DEVNAME, printf("UBI vol %s: devno 0x%04X\n",
+						  device,
+						  (int) dev));
+			probe_one(cache, name, dev, BLKID_PRI_UBI,
+				  only_if_new);
+			free(device);
+		}
+		closedir(dir);
+	}
+}
+
 /*
  * Read the device data for all available block devices in the system.
  */
@@ -419,6 +472,7 @@ static int probe_all(blkid_cache cache, int only_if_new)
 #ifdef VG_DIR
 	lvm_probe_all(cache, only_if_new);
 #endif
+	ubi_probe_all(cache, only_if_new);
 
 	proc = fopen(PROC_PARTITIONS, "r");
 	if (!proc)
diff --git a/shlibs/blkid/src/probe.c b/shlibs/blkid/src/probe.c
index 10fcb00..fc293fc 100644
--- a/shlibs/blkid/src/probe.c
+++ b/shlibs/blkid/src/probe.c
@@ -284,6 +284,8 @@ int blkid_probe_set_device(blkid_probe pr, int fd,
 
 		if (S_ISBLK(sb.st_mode))
 			blkdev_get_size(fd, (unsigned long long *) &pr->size);
+		else if (S_ISCHR(sb.st_mode))
+			pr->size = 1;
 		else
 			pr->size = sb.st_size;
 	}
-- 
1.6.4

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 2/3] blkid: add ubifs support
  2009-08-24 11:11 ` [PATCH 1/3] blkid: add UBI volume support Corentin Chary
@ 2009-08-24 11:11   ` Corentin Chary
  2009-08-24 11:11     ` [PATCH 3/3] blkid: add UBIFS test image to blkid test suite Corentin Chary
  2009-09-02  9:24   ` [PATCH 1/3] blkid: add UBI volume support Karel Zak
  2009-09-24 14:14   ` Karel Zak
  2 siblings, 1 reply; 22+ messages in thread
From: Corentin Chary @ 2009-08-24 11:11 UTC (permalink / raw)
  To: util-linux-ng; +Cc: Corentin Chary, linux-mtd, dedekind1

Signed-off-by: Corentin Chary <corentincj@iksaif.net>
---
 shlibs/blkid/src/probe.c             |    3 +-
 shlibs/blkid/src/probers/Makefile.am |    3 +-
 shlibs/blkid/src/probers/probers.h   |    1 +
 shlibs/blkid/src/probers/ubifs.c     |  122 ++++++++++++++++++++++++++++++++++
 4 files changed, 127 insertions(+), 2 deletions(-)
 create mode 100644 shlibs/blkid/src/probers/ubifs.c

diff --git a/shlibs/blkid/src/probe.c b/shlibs/blkid/src/probe.c
index fc293fc..51793e8 100644
--- a/shlibs/blkid/src/probe.c
+++ b/shlibs/blkid/src/probe.c
@@ -92,7 +92,8 @@ static const struct blkid_idinfo *idinfos[] =
 	&vxfs_idinfo,
 	&squashfs_idinfo,
 	&netware_idinfo,
-	&btrfs_idinfo
+	&btrfs_idinfo,
+	&ubifs_idinfo
 };
 
 #ifndef ARRAY_SIZE
diff --git a/shlibs/blkid/src/probers/Makefile.am b/shlibs/blkid/src/probers/Makefile.am
index 4591db6..5a5d8b6 100644
--- a/shlibs/blkid/src/probers/Makefile.am
+++ b/shlibs/blkid/src/probers/Makefile.am
@@ -40,4 +40,5 @@ libblkid_probers_la_SOURCES = \
 			sysv.c \
 			btrfs.c \
 			lvm.c \
-			zfs.c
+			zfs.c \
+			ubifs.c
diff --git a/shlibs/blkid/src/probers/probers.h b/shlibs/blkid/src/probers/probers.h
index 78dbd40..93be79f 100644
--- a/shlibs/blkid/src/probers/probers.h
+++ b/shlibs/blkid/src/probers/probers.h
@@ -56,6 +56,7 @@ extern const struct blkid_idinfo netware_idinfo;
 extern const struct blkid_idinfo sysv_idinfo;
 extern const struct blkid_idinfo xenix_idinfo;
 extern const struct blkid_idinfo btrfs_idinfo;
+extern const struct blkid_idinfo ubifs_idinfo;
 extern const struct blkid_idinfo zfs_idinfo;
 
 #endif /* _BLKID_PROBE_H */
diff --git a/shlibs/blkid/src/probers/ubifs.c b/shlibs/blkid/src/probers/ubifs.c
new file mode 100644
index 0000000..45157ae
--- /dev/null
+++ b/shlibs/blkid/src/probers/ubifs.c
@@ -0,0 +1,122 @@
+/*
+ * Copyright (C) 2009 Corentin Chary <corentincj@iksaif.net>
+ *
+ * This file may be redistributed under the terms of the
+ * GNU Lesser General Public License.
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdint.h>
+
+#include "blkidP.h"
+
+/**
+ * struct ubifs_ch - common header node.
+ * @magic: UBIFS node magic number (%UBIFS_NODE_MAGIC)
+ * @crc: CRC-32 checksum of the node header
+ * @sqnum: sequence number
+ * @len: full node length
+ * @node_type: node type
+ * @group_type: node group type
+ * @padding: reserved for future, zeroes
+ *
+ * Every UBIFS node starts with this common part. If the node has a key, the
+ * key always goes next.
+ */
+struct ubifs_ch {
+	uint32_t magic;
+	uint32_t crc;
+	uint64_t sqnum;
+	uint32_t len;
+	uint8_t node_type;
+	uint8_t group_type;
+	uint8_t padding[2];
+} __attribute__ ((packed));
+
+/**
+ * struct ubifs_sb_node - superblock node.
+ * @ch: common header
+ * @padding: reserved for future, zeroes
+ * @key_hash: type of hash function used in keys
+ * @key_fmt: format of the key
+ * @flags: file-system flags (%UBIFS_FLG_BIGLPT, etc)
+ * @min_io_size: minimal input/output unit size
+ * @leb_size: logical eraseblock size in bytes
+ * @leb_cnt: count of LEBs used by file-system
+ * @max_leb_cnt: maximum count of LEBs used by file-system
+ * @max_bud_bytes: maximum amount of data stored in buds
+ * @log_lebs: log size in logical eraseblocks
+ * @lpt_lebs: number of LEBs used for lprops table
+ * @orph_lebs: number of LEBs used for recording orphans
+ * @jhead_cnt: count of journal heads
+ * @fanout: tree fanout (max. number of links per indexing node)
+ * @lsave_cnt: number of LEB numbers in LPT's save table
+ * @fmt_version: UBIFS on-flash format version
+ * @default_compr: default compression algorithm (%UBIFS_COMPR_LZO, etc)
+ * @padding1: reserved for future, zeroes
+ * @rp_uid: reserve pool UID
+ * @rp_gid: reserve pool GID
+ * @rp_size: size of the reserved pool in bytes
+ * @padding2: reserved for future, zeroes
+ * @time_gran: time granularity in nanoseconds
+ * @uuid: UUID generated when the file system image was created
+ * @ro_compat_version: UBIFS R/O compatibility version
+ */
+struct ubifs_sb_node {
+	struct ubifs_ch ch;
+	uint8_t padding[2];
+	uint8_t key_hash;
+	uint8_t key_fmt;
+	uint32_t flags;
+	uint32_t min_io_size;
+	uint32_t leb_size;
+	uint32_t leb_cnt;
+	uint32_t max_leb_cnt;
+	uint64_t max_bud_bytes;
+	uint32_t log_lebs;
+	uint32_t lpt_lebs;
+	uint32_t orph_lebs;
+	uint32_t jhead_cnt;
+	uint32_t fanout;
+	uint32_t lsave_cnt;
+	uint32_t fmt_version;
+	uint16_t default_compr;
+	uint8_t padding1[2];
+	uint32_t rp_uid;
+	uint32_t rp_gid;
+	uint64_t rp_size;
+	uint32_t time_gran;
+	uint8_t uuid[16];
+	uint32_t ro_compat_version;
+	uint8_t padding2[3968];
+} __attribute__ ((packed));
+
+
+static int probe_ubifs(blkid_probe pr, const struct blkid_idmag *mag)
+{
+	struct ubifs_sb_node *sb;
+
+	sb = blkid_probe_get_sb(pr, mag, struct ubifs_sb_node);
+	if (!sb)
+		return -1;
+
+	blkid_probe_set_uuid(pr, sb->uuid);
+	blkid_probe_sprintf_version(pr, "w%dr%d",
+				    sb->fmt_version, sb->ro_compat_version);
+
+	return 0;
+}
+
+const struct blkid_idinfo ubifs_idinfo =
+{
+	.name		= "ubifs",
+	.usage		= BLKID_USAGE_FILESYSTEM,
+	.probefunc	= probe_ubifs,
+	.magics		=
+	{
+		{ .magic = "\x31\x18\x10\x06", .len = 4 },
+		{ NULL }
+	}
+};
-- 
1.6.4

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 3/3] blkid: add UBIFS test image to blkid test suite
  2009-08-24 11:11   ` [PATCH 2/3] blkid: add ubifs support Corentin Chary
@ 2009-08-24 11:11     ` Corentin Chary
  0 siblings, 0 replies; 22+ messages in thread
From: Corentin Chary @ 2009-08-24 11:11 UTC (permalink / raw)
  To: util-linux-ng; +Cc: Corentin Chary, linux-mtd, dedekind1

Signed-off-by: Corentin Chary <corentincj@iksaif.net>
---
 tests/expected/blkid/low-probe-ubifs |    5 +++++
 tests/ts/blkid/images/ubifs.img.bz2  |  Bin 0 -> 937 bytes
 2 files changed, 5 insertions(+), 0 deletions(-)
 create mode 100644 tests/expected/blkid/low-probe-ubifs
 create mode 100644 tests/ts/blkid/images/ubifs.img.bz2

diff --git a/tests/expected/blkid/low-probe-ubifs b/tests/expected/blkid/low-probe-ubifs
new file mode 100644
index 0000000..4164db4
--- /dev/null
+++ b/tests/expected/blkid/low-probe-ubifs
@@ -0,0 +1,5 @@
+ID_FS_TYPE=ubifs
+ID_FS_USAGE=filesystem
+ID_FS_UUID=bafe46c2-5ed9-4405-8e81-7fc317fab8f0
+ID_FS_UUID_ENC=bafe46c2-5ed9-4405-8e81-7fc317fab8f0
+ID_FS_VERSION=w4r0
diff --git a/tests/ts/blkid/images/ubifs.img.bz2 b/tests/ts/blkid/images/ubifs.img.bz2
new file mode 100644
index 0000000000000000000000000000000000000000..efba8f75efa32954d50ab70d6db74c4b9f24de44
GIT binary patch
literal 937
zcmV;a16KS(T4*^jL0KkKSsMma+5iICfB*mg|LyitdfxwWMS1t{-sJOVjvV#GK>U9D
zaUfKCSNXsL6pTYCSq%{ZC+e9;wMJyhdTMN-G|&JIsCh@I8Z-cDkjMr=dYWh&Jx@>u
zntGaJDd_bzGgI`SN+yaE&`lbfO;1syOrD_79;Sz+XaHyc13(P{pfqS200EHD4FC-q
z2$Ygd0000000000000000000000000L6ZnF0ilR8X`?0rFe4_JG&EuiMoa=|&>AuZ
zA*K^djWlQ(GGxFKBoc^Qf<hJ%6;Vluj)jqIOAE<vsQQ-L2v^xnp^L^>PNRERQO%`C
zwTlWhtVpR|JOwF2&d}sYiK>%7dn)8hnADj&F=b~7##s(H+GGoRa8TO-wV~n8ImVDe
zC_?5yosB`gev~p(6EM(m6d@iEd8&YTI5U|7s8m4+naGJz6wited#G1UrB1R0WI~x@
zI7o#=N*RF5ovh^<)$3l>t0se@D9aRFeWY^CfdUvzkS4+kMj$vvfiAVr6jTtq$s)Ng
zl@P5FLPShlE5ZV`_bFXfXoU!k2!(1=s@B+4FAfb-q9kDm30+A=O9Z4tF%<^9f|3bT
z6#s1Z6bgp$Km^!COZ<%IN-k{JvgMOlO$r)cGXi5#OLe^17z~sZRRVOk0*Xjc<<pBr
z22m%eg+`Qzi@cdH<{<$I%77Ux8SF_}vvMqmm}KdLAx=ZukQ@a-xl|aLO8rI>*G}Y$
z?ZG8es$FK9)Sq!^;Z^D`0-`0tqbQd&nUbztO@A9^2!d&1VWfv%t9N+=8T<-ug2?E0
zK@gy@f<|3EJ7Ra8GPf`72Ph%g>J=yi3&?1Eb!nyMI3#8m3mGVQox5uj@WU{HnVHqY
zKevy7sZe|TZ?VCTT#kF*;T-GcW*k;3GL74ri2Q*Ev2nox`l8-Q)rZ0Kx$gX5)ZL7)
z1~hM)M=;h~SqDTu<i^-hSU*1H64G~?&(6zXY;l(YqT@{AJqD1&mfL}AYyH83BRmTV
zSHl+CwSWpRa<vG*TR3JzqAT~<4{AXmgxvHbQ$R?uL2;0P>Oa-}8>e^7D0bgXtzP<K
z;gbc0p*qVl#_-vC4u$HMADYcGfVd7A1vR7>6?`@^I$s%2uu_>3eTYvom#T7wSG}tD
z_-5Krfb;}KP;78%2thyqNBK$us-Vq1n>qL4AfTiDh>7Z`q6(^iqNo5^U;qKr|BJaI
LoG3^QgDPzRZM~1E

literal 0
HcmV?d00001

-- 
1.6.4

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* Re: [PATCH 0/3] Add support for UBI and UBIFS
  2009-08-24 11:11 [PATCH 0/3] Add support for UBI and UBIFS Corentin Chary
  2009-08-24 11:11 ` [PATCH 1/3] blkid: add UBI volume support Corentin Chary
@ 2009-08-31 19:03 ` Corentin Chary
  2009-08-31 21:25   ` Karel Zak
  2009-09-24 14:06 ` Karel Zak
  2 siblings, 1 reply; 22+ messages in thread
From: Corentin Chary @ 2009-08-31 19:03 UTC (permalink / raw)
  To: linux-mtd; +Cc: util-linux-ng, Theodore Ts'o, Karel Zak, dedekind1

On Monday 24 August 2009 13:11:53 Corentin Chary wrote:
> Hi,
> Here is some patchs to add support for UBI and UBIFS in libblkid.
>
> UBIFS works on top of UBI volumes, there are 3 subsystems involved:
>   * MTD subsystem, which provides uniform interface to access flash chips.
>     MTD provides an notion of MTD devices (e.g., /dev/mtd0) which basically
> represents raw flash; * UBI subsystem, which is a wear-leveling and volume
> management system for flash devices; UBI works on top of MTD devices and
> provides a notion of UBI volumes (e.g.m /dev/ubi0_0); * UBIFS file system,
> which works on top of UBI volumes.
>
> The first patch add support for UBI volumes, which are represented as char
> devices in /dev/. This allow to probe for UBIFS filesystem on UBI volumes.
>
> Thanks,

Hi,
No feedback, but I forgot to CC Karel and Theodore.
I've got another series of patch for the old e2fsprogs, do you want me to send 
it ?

Thanks,

-- 
Corentin Chary
http://xf.iksaif.net

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 0/3] Add support for UBI and UBIFS
  2009-08-31 19:03 ` [PATCH 0/3] Add support for UBI and UBIFS Corentin Chary
@ 2009-08-31 21:25   ` Karel Zak
  0 siblings, 0 replies; 22+ messages in thread
From: Karel Zak @ 2009-08-31 21:25 UTC (permalink / raw)
  To: Corentin Chary; +Cc: Theodore Ts'o, util-linux-ng, linux-mtd, dedekind1

On Mon, Aug 31, 2009 at 09:03:59PM +0200, Corentin Chary wrote:
> On Monday 24 August 2009 13:11:53 Corentin Chary wrote:
> > Hi,
> > Here is some patchs to add support for UBI and UBIFS in libblkid.
> >
> > UBIFS works on top of UBI volumes, there are 3 subsystems involved:
> >   * MTD subsystem, which provides uniform interface to access flash chips.
> >     MTD provides an notion of MTD devices (e.g., /dev/mtd0) which basically
> > represents raw flash; * UBI subsystem, which is a wear-leveling and volume
> > management system for flash devices; UBI works on top of MTD devices and
> > provides a notion of UBI volumes (e.g.m /dev/ubi0_0); * UBIFS file system,
> > which works on top of UBI volumes.
> >
> > The first patch add support for UBI volumes, which are represented as char
> > devices in /dev/. This allow to probe for UBIFS filesystem on UBI volumes.
> >
> > Thanks,
> 
> Hi,
> No feedback, but I forgot to CC Karel and Theodore.

 Sorry, I had vacation last week. I'll review your patches this week.

    Karel

-- 
 Karel Zak  <kzak@redhat.com>

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 1/3] blkid: add UBI volume support
  2009-08-24 11:11 ` [PATCH 1/3] blkid: add UBI volume support Corentin Chary
  2009-08-24 11:11   ` [PATCH 2/3] blkid: add ubifs support Corentin Chary
@ 2009-09-02  9:24   ` Karel Zak
  2009-09-02 10:10     ` Artem Bityutskiy
  2009-09-18 10:52     ` Corentin Chary
  2009-09-24 14:14   ` Karel Zak
  2 siblings, 2 replies; 22+ messages in thread
From: Karel Zak @ 2009-09-02  9:24 UTC (permalink / raw)
  To: Corentin Chary; +Cc: Theodore Ts'o, util-linux-ng, linux-mtd, dedekind1


 Hi Corentin,

On Mon, Aug 24, 2009 at 01:11:54PM +0200, Corentin Chary wrote:
> Probe UBI volume under /dev (or /devfs, /devices).

 that's not elegant. Does it mean that UBI volumes are not in
 /proc/partitions?
 
 Ted, any comment?

> ubi_ctrl skip is hardcoded, maybe we should find a
> cleaner way to do that. Also change probe.c to handle
> char devices.
> 
> Signed-off-by: Corentin Chary <corentincj@iksaif.net>
> ---
>  shlibs/blkid/src/blkidP.h  |    1 +
>  shlibs/blkid/src/devname.c |   56 +++++++++++++++++++++++++++++++++++++++++++-
>  shlibs/blkid/src/probe.c   |    2 +
>  3 files changed, 58 insertions(+), 1 deletions(-)
> 
> diff --git a/shlibs/blkid/src/blkidP.h b/shlibs/blkid/src/blkidP.h
> index e0e5cb8..8db6599 100644
> --- a/shlibs/blkid/src/blkidP.h
> +++ b/shlibs/blkid/src/blkidP.h
> @@ -237,6 +237,7 @@ extern char *blkid_strndup(const char *s, const int length);
>  /*
>   * Priority settings for different types of devices
>   */
> +#define BLKID_PRI_UBI	50
>  #define BLKID_PRI_DM	40
>  #define BLKID_PRI_EVMS	30
>  #define BLKID_PRI_LVM	20
> diff --git a/shlibs/blkid/src/devname.c b/shlibs/blkid/src/devname.c
> index ef686f4..cac13c5 100644
> --- a/shlibs/blkid/src/devname.c
> +++ b/shlibs/blkid/src/devname.c
> @@ -229,7 +229,9 @@ static void probe_one(blkid_cache cache, const char *ptname,
>  		    dev->bid_devno == devno)
>  			goto set_pri;
>  
> -		if (stat(device, &st) == 0 && S_ISBLK(st.st_mode) &&
> +		if (stat(device, &st) == 0 &&
> +		    (S_ISBLK(st.st_mode) ||
> +		     (S_ISCHR(st.st_mode) && !strncmp(ptname, "ubi", 3))) &&
>  		    st.st_rdev == devno) {
>  			devname = blkid_strdup(device);
>  			goto get_dev;
> @@ -388,6 +390,57 @@ evms_probe_all(blkid_cache cache, int only_if_new)
>  	return num;
>  }
>  
> +static void
> +ubi_probe_all(blkid_cache cache, int only_if_new)
> +{
> +	const char **dirname;
> +
> +	for (dirname = dirlist; *dirname; dirname++) {
> +		DBG(DEBUG_DEVNAME, printf("probing UBI volumes under %s\n",
> +					  *dirname));
> +
> +		DIR		*dir;
> +		struct dirent	*iter;
> +
> +		dir = opendir(*dirname);
> +		if (dir == NULL)
> +			continue ;
> +
> +		while ((iter = readdir(dir)) != NULL) {
> +			char		*name, *device;
> +			struct stat	st;
> +			dev_t		dev;
> +
> +			name = iter->d_name;
> +
> +			if (!strcmp(name, ".") || !strcmp(name, "..") ||
> +			    !strstr(name, "ubi"))
> +				continue;
> +			if (!strcmp(name, "ubi_ctrl"))
> +				continue;
> +			device = malloc(strlen(*dirname) + strlen(name) + 2);
> +			if (!device)
> +				break ;
> +			sprintf(device, "%s/%s", *dirname, name);
> +			if (stat(device, &st))
             
 leak:          free(device);

> +				break ;

 I hope one day we will convert whole libblkid to use openat(),
 statat(), ... functions to avoid malloc() and sprintf() for paths :-)

> +			if (!(st.st_rdev & 0xFF)) { // It's an UBI Device
> +				free(device);
> +				continue ;
> +			}
> +			dev = st.st_rdev;
> +			DBG(DEBUG_DEVNAME, printf("UBI vol %s: devno 0x%04X\n",
> +						  device,
> +						  (int) dev));
> +			probe_one(cache, name, dev, BLKID_PRI_UBI,
> +				  only_if_new);
> +			free(device);
> +		}
> +		closedir(dir);
> +	}
> +}

    Karel

-- 
 Karel Zak  <kzak@redhat.com>

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 1/3] blkid: add UBI volume support
  2009-09-02  9:24   ` [PATCH 1/3] blkid: add UBI volume support Karel Zak
@ 2009-09-02 10:10     ` Artem Bityutskiy
  2009-09-18 10:52     ` Corentin Chary
  1 sibling, 0 replies; 22+ messages in thread
From: Artem Bityutskiy @ 2009-09-02 10:10 UTC (permalink / raw)
  To: Karel Zak; +Cc: Corentin Chary, Theodore Ts'o, util-linux-ng, linux-mtd

On Wed, 2009-09-02 at 11:24 +0200, Karel Zak wrote:
> Hi Corentin,
> 
> On Mon, Aug 24, 2009 at 01:11:54PM +0200, Corentin Chary wrote:
> > Probe UBI volume under /dev (or /devfs, /devices).
> 
>  that's not elegant. Does it mean that UBI volumes are not in
>  /proc/partitions?

Yeah, the thing is that neither UBI volumes nor MTD devices are in
/proc/partitions, just because they are not block devices and they
are not members of the blkock device infrastructure. They form a
completely separate subsystem.

Here are some more data:
http://www.linux-mtd.infradead.org/faq/general.html#L_mtd_what
http://www.linux-mtd.infradead.org/doc/ubifs.html#L_raw_vs_ftl

There are already 3 FSes which work with MTD: JFFS2, UBIFS and
(out-of-tree)YAFFS2.

-- 
Best Regards,
Artem Bityutskiy (Артём Битюцкий)

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 1/3] blkid: add UBI volume support
  2009-09-02  9:24   ` [PATCH 1/3] blkid: add UBI volume support Karel Zak
  2009-09-02 10:10     ` Artem Bityutskiy
@ 2009-09-18 10:52     ` Corentin Chary
  2009-09-19  1:23       ` Theodore Tso
  1 sibling, 1 reply; 22+ messages in thread
From: Corentin Chary @ 2009-09-18 10:52 UTC (permalink / raw)
  To: Karel Zak; +Cc: Theodore Ts'o, util-linux-ng, linux-mtd, dedekind1

On Wednesday 02 September 2009 11:24:02 Karel Zak wrote:
>  Hi Corentin,
> 
> On Mon, Aug 24, 2009 at 01:11:54PM +0200, Corentin Chary wrote:
> > Probe UBI volume under /dev (or /devfs, /devices).
> 
>  that's not elegant. Does it mean that UBI volumes are not in
>  /proc/partitions?
> 
>  Ted, any comment?

Any news for this patch ?
Thanks,
-- 
Corentin Chary
http://xf.iksaif.net

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 1/3] blkid: add UBI volume support
  2009-09-18 10:52     ` Corentin Chary
@ 2009-09-19  1:23       ` Theodore Tso
  0 siblings, 0 replies; 22+ messages in thread
From: Theodore Tso @ 2009-09-19  1:23 UTC (permalink / raw)
  To: Corentin Chary; +Cc: util-linux-ng, Karel Zak, linux-mtd, dedekind1

On Fri, Sep 18, 2009 at 12:52:09PM +0200, Corentin Chary wrote:
> On Wednesday 02 September 2009 11:24:02 Karel Zak wrote:
> >  Hi Corentin,
> > 
> > On Mon, Aug 24, 2009 at 01:11:54PM +0200, Corentin Chary wrote:
> > > Probe UBI volume under /dev (or /devfs, /devices).
> > 
> >  that's not elegant. Does it mean that UBI volumes are not in
> >  /proc/partitions?
> > 
> >  Ted, any comment?
> 
> Any news for this patch ?
> Thanks,

Sorry, I've been travelling and it's the merge window and I have
slides for a Usenix tutorial due soon, so my userspace-related pages
have been swapped out.  And next week is LinuxCon/Plumber's...  

I'll try to look at this either next week if I can find some airplane
hacking time or when I get back from Plumber's Conference.

	     	       	   	     	       - Ted

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 0/3] Add support for UBI and UBIFS
  2009-08-24 11:11 [PATCH 0/3] Add support for UBI and UBIFS Corentin Chary
  2009-08-24 11:11 ` [PATCH 1/3] blkid: add UBI volume support Corentin Chary
  2009-08-31 19:03 ` [PATCH 0/3] Add support for UBI and UBIFS Corentin Chary
@ 2009-09-24 14:06 ` Karel Zak
  2009-09-24 22:41   ` Corentin Chary
  2 siblings, 1 reply; 22+ messages in thread
From: Karel Zak @ 2009-09-24 14:06 UTC (permalink / raw)
  To: Corentin Chary; +Cc: util-linux-ng, linux-mtd, dedekind1

On Mon, Aug 24, 2009 at 01:11:53PM +0200, Corentin Chary wrote:
> Hi,
> Here is some patchs to add support for UBI and UBIFS in libblkid.
> 
> UBIFS works on top of UBI volumes, there are 3 subsystems involved:
>   * MTD subsystem, which provides uniform interface to access flash chips.
>     MTD provides an notion of MTD devices (e.g., /dev/mtd0) which basically represents raw flash;
>   * UBI subsystem, which is a wear-leveling and volume management system for flash devices;
>     UBI works on top of MTD devices and provides a notion of UBI volumes (e.g.m /dev/ubi0_0);
>   * UBIFS file system, which works on top of UBI volumes.

 Applied. 
 
 Please, "git pull" and test "mics-utils/blkid -p" against a real UBI
 device. I did some minor changes to the code (it was necessary to
 rebase your patches to the current HEAD).

 Thanks for your patience :-)

    Karel

-- 
 Karel Zak  <kzak@redhat.com>

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 1/3] blkid: add UBI volume support
  2009-08-24 11:11 ` [PATCH 1/3] blkid: add UBI volume support Corentin Chary
  2009-08-24 11:11   ` [PATCH 2/3] blkid: add ubifs support Corentin Chary
  2009-09-02  9:24   ` [PATCH 1/3] blkid: add UBI volume support Karel Zak
@ 2009-09-24 14:14   ` Karel Zak
  2009-09-24 21:57     ` Corentin Chary
  2 siblings, 1 reply; 22+ messages in thread
From: Karel Zak @ 2009-09-24 14:14 UTC (permalink / raw)
  To: Corentin Chary; +Cc: util-linux-ng, linux-mtd, dedekind1

On Mon, Aug 24, 2009 at 01:11:54PM +0200, Corentin Chary wrote:
> --- a/shlibs/blkid/src/devname.c
> +static void
> +ubi_probe_all(blkid_cache cache, int only_if_new)
> +{
> +	const char **dirname;
> +
> +	for (dirname = dirlist; *dirname; dirname++) {
> +		DBG(DEBUG_DEVNAME, printf("probing UBI volumes under %s\n",
> +					  *dirname));
> +
> +		DIR		*dir;
> +		struct dirent	*iter;
> +
> +		dir = opendir(*dirname);
> +		if (dir == NULL)
> +			continue ;
> +
> +		while ((iter = readdir(dir)) != NULL) {
> +			char		*name, *device;
> +			struct stat	st;
> +			dev_t		dev;
> +
> +			name = iter->d_name;
> +
> +			if (!strcmp(name, ".") || !strcmp(name, "..") ||
> +			    !strstr(name, "ubi"))
> +				continue;
> +			if (!strcmp(name, "ubi_ctrl"))
> +				continue;
> +			device = malloc(strlen(*dirname) + strlen(name) + 2);
> +			if (!device)
> +				break ;
> +			sprintf(device, "%s/%s", *dirname, name);
> +			if (stat(device, &st))
> +				break ;
> +
> +			if (!(st.st_rdev & 0xFF)) { // It's an UBI Device
> +				free(device);
> +				continue ;
> +			}

Wouldn't be better to 

  #define is_ubi_device(s)    (S_ISCHR(s->st_mode) && (s->st_rdev & 0xFF))

(or major() instead magic 0xFF constant?) and use it everywhere in
code? I guess UBI is always a char device.

> +++ b/shlibs/blkid/src/probe.c
> @@ -284,6 +284,8 @@ int blkid_probe_set_device(blkid_probe pr, int fd,
>  
>  		if (S_ISBLK(sb.st_mode))
>  			blkdev_get_size(fd, (unsigned long long *) &pr->size);
> +		else if (S_ISCHR(sb.st_mode))
> +			pr->size = 1;
>  		else
>  			pr->size = sb.st_size;
>  	}

this is the same situation, this code will for all char devices, but we
want to support UBI only.

    Karel

-- 
 Karel Zak  <kzak@redhat.com>

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 1/3] blkid: add UBI volume support
  2009-09-24 14:14   ` Karel Zak
@ 2009-09-24 21:57     ` Corentin Chary
  2009-09-25  7:19       ` Artem Bityutskiy
  0 siblings, 1 reply; 22+ messages in thread
From: Corentin Chary @ 2009-09-24 21:57 UTC (permalink / raw)
  To: dedekind1, Karel Zak; +Cc: util-linux-ng, linux-mtd

On Thu, Sep 24, 2009 at 4:14 PM, Karel Zak <kzak@redhat.com> wrote:
> On Mon, Aug 24, 2009 at 01:11:54PM +0200, Corentin Chary wrote:
>> --- a/shlibs/blkid/src/devname.c
>> +static void
>> +ubi_probe_all(blkid_cache cache, int only_if_new)
>> +{
>> +     const char **dirname;
>> +
>> +     for (dirname = dirlist; *dirname; dirname++) {
>> +             DBG(DEBUG_DEVNAME, printf("probing UBI volumes under %s\n",
>> +                                       *dirname));
>> +
>> +             DIR             *dir;
>> +             struct dirent   *iter;
>> +
>> +             dir = opendir(*dirname);
>> +             if (dir == NULL)
>> +                     continue ;
>> +
>> +             while ((iter = readdir(dir)) != NULL) {
>> +                     char            *name, *device;
>> +                     struct stat     st;
>> +                     dev_t           dev;
>> +
>> +                     name = iter->d_name;
>> +
>> +                     if (!strcmp(name, ".") || !strcmp(name, "..") ||
>> +                         !strstr(name, "ubi"))
>> +                             continue;
>> +                     if (!strcmp(name, "ubi_ctrl"))
>> +                             continue;
>> +                     device = malloc(strlen(*dirname) + strlen(name) + 2);
>> +                     if (!device)
>> +                             break ;
>> +                     sprintf(device, "%s/%s", *dirname, name);
>> +                     if (stat(device, &st))
>> +                             break ;
>> +
>> +                     if (!(st.st_rdev & 0xFF)) { // It's an UBI Device
>> +                             free(device);
>> +                             continue ;
>> +                     }
>
> Wouldn't be better to
>
>  #define is_ubi_device(s)    (S_ISCHR(s->st_mode) && (s->st_rdev & 0xFF))
>
> (or major() instead magic 0xFF constant?) and use it everywhere in
> code? I guess UBI is always a char device.

Maybe something like that:
#define is_ubi_device(s)    (S_ISCHR(s->st_mode) && !minor(s->st_rdev))

>> +++ b/shlibs/blkid/src/probe.c
>> @@ -284,6 +284,8 @@ int blkid_probe_set_device(blkid_probe pr, int fd,
>>
>>               if (S_ISBLK(sb.st_mode))
>>                       blkdev_get_size(fd, (unsigned long long *) &pr->size);
>> +             else if (S_ISCHR(sb.st_mode))
>> +                     pr->size = 1;
>>               else
>>                       pr->size = sb.st_size;
>>       }
>
> this is the same situation, this code will for all char devices, but we
> want to support UBI only.

I don't know if there is a "good" way to detect an ubi device using
only struct stat.

Artem, any idea ?

-- 
Corentin Chary
http://xf.iksaif.net

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 0/3] Add support for UBI and UBIFS
  2009-09-24 14:06 ` Karel Zak
@ 2009-09-24 22:41   ` Corentin Chary
  2009-09-24 22:47     ` [PATCH] UBIFS: Add /dev/ubiX_Y naming scheme in open_ubi Corentin Chary
  0 siblings, 1 reply; 22+ messages in thread
From: Corentin Chary @ 2009-09-24 22:41 UTC (permalink / raw)
  To: Karel Zak; +Cc: util-linux-ng, linux-mtd, dedekind1

On Thu, Sep 24, 2009 at 4:06 PM, Karel Zak <kzak@redhat.com> wrote:
> On Mon, Aug 24, 2009 at 01:11:53PM +0200, Corentin Chary wrote:
>> Hi,
>> Here is some patchs to add support for UBI and UBIFS in libblkid.
>>
>> UBIFS works on top of UBI volumes, there are 3 subsystems involved:
>>   * MTD subsystem, which provides uniform interface to access flash chips.
>>     MTD provides an notion of MTD devices (e.g., /dev/mtd0) which basically represents raw flash;
>>   * UBI subsystem, which is a wear-leveling and volume management system for flash devices;
>>     UBI works on top of MTD devices and provides a notion of UBI volumes (e.g.m /dev/ubi0_0);
>>   * UBIFS file system, which works on top of UBI volumes.
>
>  Applied.
>
>  Please, "git pull" and test "mics-utils/blkid -p" against a real UBI
>  device. I did some minor changes to the code (it was necessary to
>  rebase your patches to the current HEAD).
>
>  Thanks for your patience :-)
>
>    Karel
>

$ ../../misc-utils/blkid /dev/ubi0_0
/dev/ubi0_0: UUID="6358dcea-6e46-40c9-8d76-072eac24d909" TYPE="ubifs"

Working

$ ../../mount/mount /dev/ubi0_0 /mnt/key
UBIFS error (pid 28250): ubifs_get_sb: cannot open "/dev/ubi0_0", error -22

*patching UBIFS*

$ sudo ../../mount/mount /dev/ubi0_0 /mnt/key/
Yeah, working !

-- 
Corentin Chary
http://xf.iksaif.net

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [PATCH] UBIFS: Add /dev/ubiX_Y naming scheme in open_ubi
  2009-09-24 22:41   ` Corentin Chary
@ 2009-09-24 22:47     ` Corentin Chary
  2009-09-25 11:37       ` Adrian Hunter
  2009-09-28 11:39       ` Artem Bityutskiy
  0 siblings, 2 replies; 22+ messages in thread
From: Corentin Chary @ 2009-09-24 22:47 UTC (permalink / raw)
  To: dedekind1; +Cc: Corentin Chary, util-linux-ng, linux-mtd

This is needed to use $ mount /dev/ubi0_0 /mnt/nand
You'll also need a recent libblkid with UBI and UBIFS
support.

Signed-off-by: Corentin Chary <corentincj@iksaif.net>
---
 fs/ubifs/super.c |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/fs/ubifs/super.c b/fs/ubifs/super.c
index 7e2b3d4..38320ad 100644
--- a/fs/ubifs/super.c
+++ b/fs/ubifs/super.c
@@ -1843,10 +1843,11 @@ const struct super_operations ubifs_super_operations = {
  * @mode: UBI volume open mode
  *
  * There are several ways to specify UBI volumes when mounting UBIFS:
- * o ubiX_Y    - UBI device number X, volume Y;
- * o ubiY      - UBI device number 0, volume Y;
- * o ubiX:NAME - mount UBI device X, volume with name NAME;
- * o ubi:NAME  - mount UBI device 0, volume with name NAME.
+ * o /dev/ubiX_Y - UBI device number X, volume Y;
+ * o ubiX_Y      - UBI device number X, volume Y;
+ * o ubiY        - UBI device number 0, volume Y;
+ * o ubiX:NAME   - mount UBI device X, volume with name NAME;
+ * o ubi:NAME    - mount UBI device 0, volume with name NAME.
  *
  * Alternative '!' separator may be used instead of ':' (because some shells
  * like busybox may interpret ':' as an NFS host name separator). This function
@@ -1858,6 +1859,9 @@ static struct ubi_volume_desc *open_ubi(const char *name, int mode)
 	int dev, vol;
 	char *endptr;
 
+	if (!strncmp("/dev/", name, 5))
+		name = name + 5;
+
 	if (name[0] != 'u' || name[1] != 'b' || name[2] != 'i')
 		return ERR_PTR(-EINVAL);
 
-- 
1.6.5.rc1

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* Re: [PATCH 1/3] blkid: add UBI volume support
  2009-09-24 21:57     ` Corentin Chary
@ 2009-09-25  7:19       ` Artem Bityutskiy
  2009-09-25  7:56         ` Karel Zak
  0 siblings, 1 reply; 22+ messages in thread
From: Artem Bityutskiy @ 2009-09-25  7:19 UTC (permalink / raw)
  To: Corentin Chary; +Cc: util-linux-ng, Karel Zak, linux-mtd

On Thu, 2009-09-24 at 23:57 +0200, Corentin Chary wrote:
> >> +                     if (!(st.st_rdev & 0xFF)) { // It's an UBI Device
> >> +                             free(device);
> >> +                             continue ;
> >> +                     }
> >
> > Wouldn't be better to
> >
> >  #define is_ubi_device(s)    (S_ISCHR(s->st_mode) && (s->st_rdev & 0xFF))
> >
> > (or major() instead magic 0xFF constant?) and use it everywhere in
> > code? I guess UBI is always a char device.
> 
> Maybe something like that:
> #define is_ubi_device(s)    (S_ISCHR(s->st_mode) && !minor(s->st_rdev))

Well, if you want to be really nice, you may implement this as a
function which scans sysfs or looks at /proc/devices and makes sure the
device really belongs to UBI. See below.

> 
> >> +++ b/shlibs/blkid/src/probe.c
> >> @@ -284,6 +284,8 @@ int blkid_probe_set_device(blkid_probe pr, int fd,
> >>
> >>               if (S_ISBLK(sb.st_mode))
> >>                       blkdev_get_size(fd, (unsigned long long *) &pr->size);
> >> +             else if (S_ISCHR(sb.st_mode))
> >> +                     pr->size = 1;
> >>               else
> >>                       pr->size = sb.st_size;
> >>       }
> >
> > this is the same situation, this code will for all char devices, but we
> > want to support UBI only.
> 
> I don't know if there is a "good" way to detect an ubi device using
> only struct stat.
> 
> Artem, any idea ?

UBI char devices' major:minor numbers are allocated dynamically, so they
cannot be used.

To check whether this char. device node is an UBI volume and not
something else, you should scan all /sys/class/ubi/ubiX/Y/dev files, and
see if there is a device with the same major:minor.

The other possibility would be to look at /proc/devices, and make sure
there is an ubiX device with the same major number as your /dev/ubiX_Y
device.

-- 
Best Regards,
Artem Bityutskiy (Артём Битюцкий)

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 1/3] blkid: add UBI volume support
  2009-09-25  7:19       ` Artem Bityutskiy
@ 2009-09-25  7:56         ` Karel Zak
  0 siblings, 0 replies; 22+ messages in thread
From: Karel Zak @ 2009-09-25  7:56 UTC (permalink / raw)
  To: Artem Bityutskiy; +Cc: util-linux-ng, linux-mtd, Corentin Chary

On Fri, Sep 25, 2009 at 10:19:19AM +0300, Artem Bityutskiy wrote:
> To check whether this char. device node is an UBI volume and not
> something else, you should scan all /sys/class/ubi/ubiX/Y/dev files, and
> see if there is a device with the same major:minor.
> 
> The other possibility would be to look at /proc/devices, and make sure
> there is an ubiX device with the same major number as your /dev/ubiX_Y
> device.

 Yes, we have such function (blkid_driver_has_major()), but I think
 it's overkill in this context. It seems that check for the "ubi" 
 device name in ubi_probe_all() is enough.

 Thanks.

    Karel

-- 
 Karel Zak  <kzak@redhat.com>

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH] UBIFS: Add /dev/ubiX_Y naming scheme in open_ubi
  2009-09-24 22:47     ` [PATCH] UBIFS: Add /dev/ubiX_Y naming scheme in open_ubi Corentin Chary
@ 2009-09-25 11:37       ` Adrian Hunter
  2009-09-25 12:27         ` Corentin Chary
  2009-09-28 11:39       ` Artem Bityutskiy
  1 sibling, 1 reply; 22+ messages in thread
From: Adrian Hunter @ 2009-09-25 11:37 UTC (permalink / raw)
  To: Corentin Chary; +Cc: util-linux-ng, linux-mtd, dedekind1

Corentin Chary wrote:
> This is needed to use $ mount /dev/ubi0_0 /mnt/nand
> You'll also need a recent libblkid with UBI and UBIFS
> support.
> 
> Signed-off-by: Corentin Chary <corentincj@iksaif.net>
> ---
>  fs/ubifs/super.c |   12 ++++++++----
>  1 files changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/ubifs/super.c b/fs/ubifs/super.c
> index 7e2b3d4..38320ad 100644
> --- a/fs/ubifs/super.c
> +++ b/fs/ubifs/super.c
> @@ -1843,10 +1843,11 @@ const struct super_operations ubifs_super_operations = {
>   * @mode: UBI volume open mode
>   *
>   * There are several ways to specify UBI volumes when mounting UBIFS:
> - * o ubiX_Y    - UBI device number X, volume Y;
> - * o ubiY      - UBI device number 0, volume Y;
> - * o ubiX:NAME - mount UBI device X, volume with name NAME;
> - * o ubi:NAME  - mount UBI device 0, volume with name NAME.
> + * o /dev/ubiX_Y - UBI device number X, volume Y;
> + * o ubiX_Y      - UBI device number X, volume Y;
> + * o ubiY        - UBI device number 0, volume Y;
> + * o ubiX:NAME   - mount UBI device X, volume with name NAME;
> + * o ubi:NAME    - mount UBI device 0, volume with name NAME.
>   *
>   * Alternative '!' separator may be used instead of ':' (because some shells
>   * like busybox may interpret ':' as an NFS host name separator). This function
> @@ -1858,6 +1859,9 @@ static struct ubi_volume_desc *open_ubi(const char *name, int mode)
>  	int dev, vol;
>  	char *endptr;
>  
> +	if (!strncmp("/dev/", name, 5))
> +		name = name + 5;
> +
>  	if (name[0] != 'u' || name[1] != 'b' || name[2] != 'i')
>  		return ERR_PTR(-EINVAL);

Is this for the kernel?

I do not think UBIFS should interpret the file name.  It should
work off the major and minor numbers from the device node
irrespective of what its path name or file name is.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH] UBIFS: Add /dev/ubiX_Y naming scheme in open_ubi
  2009-09-25 11:37       ` Adrian Hunter
@ 2009-09-25 12:27         ` Corentin Chary
  0 siblings, 0 replies; 22+ messages in thread
From: Corentin Chary @ 2009-09-25 12:27 UTC (permalink / raw)
  To: Adrian Hunter; +Cc: util-linux-ng, linux-mtd, dedekind1

On Fri, Sep 25, 2009 at 1:37 PM, Adrian Hunter <adrian.hunter@nokia.com> wrote:
> Corentin Chary wrote:
>>
>> This is needed to use $ mount /dev/ubi0_0 /mnt/nand
>> You'll also need a recent libblkid with UBI and UBIFS
>> support.
>>
>> Signed-off-by: Corentin Chary <corentincj@iksaif.net>
>> ---
>>  fs/ubifs/super.c |   12 ++++++++----
>>  1 files changed, 8 insertions(+), 4 deletions(-)
>>
>> diff --git a/fs/ubifs/super.c b/fs/ubifs/super.c
>> index 7e2b3d4..38320ad 100644
>> --- a/fs/ubifs/super.c
>> +++ b/fs/ubifs/super.c
>> @@ -1843,10 +1843,11 @@ const struct super_operations
>> ubifs_super_operations = {
>>  * @mode: UBI volume open mode
>>  *
>>  * There are several ways to specify UBI volumes when mounting UBIFS:
>> - * o ubiX_Y    - UBI device number X, volume Y;
>> - * o ubiY      - UBI device number 0, volume Y;
>> - * o ubiX:NAME - mount UBI device X, volume with name NAME;
>> - * o ubi:NAME  - mount UBI device 0, volume with name NAME.
>> + * o /dev/ubiX_Y - UBI device number X, volume Y;
>> + * o ubiX_Y      - UBI device number X, volume Y;
>> + * o ubiY        - UBI device number 0, volume Y;
>> + * o ubiX:NAME   - mount UBI device X, volume with name NAME;
>> + * o ubi:NAME    - mount UBI device 0, volume with name NAME.
>>  *
>>  * Alternative '!' separator may be used instead of ':' (because some
>> shells
>>  * like busybox may interpret ':' as an NFS host name separator). This
>> function
>> @@ -1858,6 +1859,9 @@ static struct ubi_volume_desc *open_ubi(const char
>> *name, int mode)
>>        int dev, vol;
>>        char *endptr;
>>  +       if (!strncmp("/dev/", name, 5))
>> +               name = name + 5;
>> +
>>        if (name[0] != 'u' || name[1] != 'b' || name[2] != 'i')
>>                return ERR_PTR(-EINVAL);
>
> Is this for the kernel?
Yes

> I do not think UBIFS should interpret the file name.  It should
> work off the major and minor numbers from the device node
> irrespective of what its path name or file name is.

UBIFS is currently a "nodev" filesystem, it's why I did it that way.

Using name and kern_path we can find the corresponding inode (and
major/minor informations).
But I don't see a way to open the corresponding UBI volume with only
major/minor.
ubi_open_volume use ubi_num and vol_id.
vol_id is minor()-1, but major is not related to ubi_num.

UBI have a "ubi_major2num" internally, is it ok to export this symbol ?

Thanks

-- 
Corentin Chary
http://xf.iksaif.net

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH] UBIFS: Add /dev/ubiX_Y naming scheme in open_ubi
  2009-09-24 22:47     ` [PATCH] UBIFS: Add /dev/ubiX_Y naming scheme in open_ubi Corentin Chary
  2009-09-25 11:37       ` Adrian Hunter
@ 2009-09-28 11:39       ` Artem Bityutskiy
  2009-09-28 11:53         ` Corentin Chary
  1 sibling, 1 reply; 22+ messages in thread
From: Artem Bityutskiy @ 2009-09-28 11:39 UTC (permalink / raw)
  To: Corentin Chary; +Cc: util-linux-ng, linux-mtd

On Fri, 2009-09-25 at 00:47 +0200, Corentin Chary wrote:
> This is needed to use $ mount /dev/ubi0_0 /mnt/nand
> You'll also need a recent libblkid with UBI and UBIFS
> support.
> 
> Signed-off-by: Corentin Chary <corentincj@iksaif.net>
> ---
>  fs/ubifs/super.c |   12 ++++++++----
>  1 files changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/ubifs/super.c b/fs/ubifs/super.c
> index 7e2b3d4..38320ad 100644
> --- a/fs/ubifs/super.c
> +++ b/fs/ubifs/super.c
> @@ -1843,10 +1843,11 @@ const struct super_operations ubifs_super_operations = {
>   * @mode: UBI volume open mode
>   *
>   * There are several ways to specify UBI volumes when mounting UBIFS:
> - * o ubiX_Y    - UBI device number X, volume Y;
> - * o ubiY      - UBI device number 0, volume Y;
> - * o ubiX:NAME - mount UBI device X, volume with name NAME;
> - * o ubi:NAME  - mount UBI device 0, volume with name NAME.
> + * o /dev/ubiX_Y - UBI device number X, volume Y;
> + * o ubiX_Y      - UBI device number X, volume Y;
> + * o ubiY        - UBI device number 0, volume Y;
> + * o ubiX:NAME   - mount UBI device X, volume with name NAME;
> + * o ubi:NAME    - mount UBI device 0, volume with name NAME.
>   *
>   * Alternative '!' separator may be used instead of ':' (because some shells
>   * like busybox may interpret ':' as an NFS host name separator). This function
> @@ -1858,6 +1859,9 @@ static struct ubi_volume_desc *open_ubi(const char *name, int mode)
>  	int dev, vol;
>  	char *endptr;
>  
> +	if (!strncmp("/dev/", name, 5))
> +		name = name + 5;
> +
>  	if (name[0] != 'u' || name[1] != 'b' || name[2] != 'i')
>  		return ERR_PTR(-EINVAL);

But UBI volume may have arbitrary names. Could we invent something
better?

-- 
Best Regards,
Artem Bityutskiy (Артём Битюцкий)

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH] UBIFS: Add /dev/ubiX_Y naming scheme in open_ubi
  2009-09-28 11:39       ` Artem Bityutskiy
@ 2009-09-28 11:53         ` Corentin Chary
  2009-09-28 12:02           ` Artem Bityutskiy
  0 siblings, 1 reply; 22+ messages in thread
From: Corentin Chary @ 2009-09-28 11:53 UTC (permalink / raw)
  To: dedekind1; +Cc: util-linux-ng, linux-mtd

On Mon, Sep 28, 2009 at 1:39 PM, Artem Bityutskiy <dedekind1@gmail.com> wrote:
> On Fri, 2009-09-25 at 00:47 +0200, Corentin Chary wrote:
>> This is needed to use $ mount /dev/ubi0_0 /mnt/nand
>> You'll also need a recent libblkid with UBI and UBIFS
>> support.
>>
>> Signed-off-by: Corentin Chary <corentincj@iksaif.net>
>> ---
>>  fs/ubifs/super.c |   12 ++++++++----
>>  1 files changed, 8 insertions(+), 4 deletions(-)
>>
>> diff --git a/fs/ubifs/super.c b/fs/ubifs/super.c
>> index 7e2b3d4..38320ad 100644
>> --- a/fs/ubifs/super.c
>> +++ b/fs/ubifs/super.c
>> @@ -1843,10 +1843,11 @@ const struct super_operations ubifs_super_operations = {
>>   * @mode: UBI volume open mode
>>   *
>>   * There are several ways to specify UBI volumes when mounting UBIFS:
>> - * o ubiX_Y    - UBI device number X, volume Y;
>> - * o ubiY      - UBI device number 0, volume Y;
>> - * o ubiX:NAME - mount UBI device X, volume with name NAME;
>> - * o ubi:NAME  - mount UBI device 0, volume with name NAME.
>> + * o /dev/ubiX_Y - UBI device number X, volume Y;
>> + * o ubiX_Y      - UBI device number X, volume Y;
>> + * o ubiY        - UBI device number 0, volume Y;
>> + * o ubiX:NAME   - mount UBI device X, volume with name NAME;
>> + * o ubi:NAME    - mount UBI device 0, volume with name NAME.
>>   *
>>   * Alternative '!' separator may be used instead of ':' (because some shells
>>   * like busybox may interpret ':' as an NFS host name separator). This function
>> @@ -1858,6 +1859,9 @@ static struct ubi_volume_desc *open_ubi(const char *name, int mode)
>>       int dev, vol;
>>       char *endptr;
>>
>> +     if (!strncmp("/dev/", name, 5))
>> +             name = name + 5;
>> +
>>       if (name[0] != 'u' || name[1] != 'b' || name[2] != 'i')
>>               return ERR_PTR(-EINVAL);
>
> But UBI volume may have arbitrary names. Could we invent something
> better?


Using name and kern_path we can find the corresponding inode (and
major/minor informations).
ubi_open_volume use ubi_num and vol_id.
vol_id is minor()-1, but major is not related to ubi_num.

UBI have a "ubi_major2num" internally, is it ok to export this symbol ?

Then we could do something like
ubi_open_volume(ubi_major2num(major()), minor()-1)

-- 
Corentin Chary
http://xf.iksaif.net

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH] UBIFS: Add /dev/ubiX_Y naming scheme in open_ubi
  2009-09-28 11:53         ` Corentin Chary
@ 2009-09-28 12:02           ` Artem Bityutskiy
  0 siblings, 0 replies; 22+ messages in thread
From: Artem Bityutskiy @ 2009-09-28 12:02 UTC (permalink / raw)
  To: Corentin Chary; +Cc: util-linux-ng, linux-mtd

On 09/28/2009 02:53 PM, Corentin Chary wrote:
>>> +     if (!strncmp("/dev/", name, 5))
>>> +             name = name + 5;
>>> +
>>>        if (name[0] != 'u' || name[1] != 'b' || name[2] != 'i')
>>>                return ERR_PTR(-EINVAL);
>>
>> But UBI volume may have arbitrary names. Could we invent something
>> better?
>
>
> Using name and kern_path we can find the corresponding inode (and
> major/minor informations).
> ubi_open_volume use ubi_num and vol_id.
> vol_id is minor()-1, but major is not related to ubi_num.
>
> UBI have a "ubi_major2num" internally, is it ok to export this symbol ?
>
> Then we could do something like
> ubi_open_volume(ubi_major2num(major()), minor()-1)

Sounds good.

-- 
Best Regards,
Artem Bityutskiy (Артём Битюцкий)

^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2009-09-28 12:06 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-24 11:11 [PATCH 0/3] Add support for UBI and UBIFS Corentin Chary
2009-08-24 11:11 ` [PATCH 1/3] blkid: add UBI volume support Corentin Chary
2009-08-24 11:11   ` [PATCH 2/3] blkid: add ubifs support Corentin Chary
2009-08-24 11:11     ` [PATCH 3/3] blkid: add UBIFS test image to blkid test suite Corentin Chary
2009-09-02  9:24   ` [PATCH 1/3] blkid: add UBI volume support Karel Zak
2009-09-02 10:10     ` Artem Bityutskiy
2009-09-18 10:52     ` Corentin Chary
2009-09-19  1:23       ` Theodore Tso
2009-09-24 14:14   ` Karel Zak
2009-09-24 21:57     ` Corentin Chary
2009-09-25  7:19       ` Artem Bityutskiy
2009-09-25  7:56         ` Karel Zak
2009-08-31 19:03 ` [PATCH 0/3] Add support for UBI and UBIFS Corentin Chary
2009-08-31 21:25   ` Karel Zak
2009-09-24 14:06 ` Karel Zak
2009-09-24 22:41   ` Corentin Chary
2009-09-24 22:47     ` [PATCH] UBIFS: Add /dev/ubiX_Y naming scheme in open_ubi Corentin Chary
2009-09-25 11:37       ` Adrian Hunter
2009-09-25 12:27         ` Corentin Chary
2009-09-28 11:39       ` Artem Bityutskiy
2009-09-28 11:53         ` Corentin Chary
2009-09-28 12:02           ` Artem Bityutskiy

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.