All of lore.kernel.org
 help / color / mirror / Atom feed
From: Artem Bityutskiy <dedekind1@gmail.com>
To: Corentin Chary <corentin.chary@gmail.com>
Cc: util-linux-ng@vger.kernel.org, Karel Zak <kzak@redhat.com>,
	linux-mtd@lists.infradead.org
Subject: Re: [PATCH 1/3] blkid: add UBI volume support
Date: Fri, 25 Sep 2009 10:19:19 +0300	[thread overview]
Message-ID: <1253863159.3778.38.camel@localhost> (raw)
In-Reply-To: <71cd59b00909241457p3b9247a1q661ea63bde584f26@mail.gmail.com>

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 (Артём Битюцкий)

  reply	other threads:[~2009-09-25  7:22 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   ` [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 [this message]
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=1253863159.3778.38.camel@localhost \
    --to=dedekind1@gmail.com \
    --cc=corentin.chary@gmail.com \
    --cc=kzak@redhat.com \
    --cc=linux-mtd@lists.infradead.org \
    --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.