From: Karel Zak <kzak@redhat.com>
To: Corentin Chary <corentincj@iksaif.net>
Cc: Theodore Ts'o <tytso@mit.edu>,
util-linux-ng@vger.kernel.org, linux-mtd@lists.infradead.org,
dedekind1@gmail.com
Subject: Re: [PATCH 1/3] blkid: add UBI volume support
Date: Wed, 2 Sep 2009 11:24:02 +0200 [thread overview]
Message-ID: <20090902092402.GI1466@nb.net.home> (raw)
In-Reply-To: <1251112316-18971-2-git-send-email-corentincj@iksaif.net>
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>
next prev parent reply other threads:[~2009-09-02 9:24 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Karel Zak [this message]
2009-09-02 10:10 ` [PATCH 1/3] blkid: add UBI volume support 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
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=20090902092402.GI1466@nb.net.home \
--to=kzak@redhat.com \
--cc=corentincj@iksaif.net \
--cc=dedekind1@gmail.com \
--cc=linux-mtd@lists.infradead.org \
--cc=tytso@mit.edu \
--cc=util-linux-ng@vger.kernel.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 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.