From: Christoph Hellwig <hch@infradead.org>
To: Joe Thornber <joe@fib011235813.fsnet.co.uk>
Cc: "chandrasekhar.nagaraj" <chandrasekhar.nagaraj@patni.com>,
linux-kernel@vger.kernel.org
Subject: Re: Path Name to kdev_t
Date: Fri, 15 Nov 2002 16:28:45 +0000 [thread overview]
Message-ID: <20021115162845.A10146@infradead.org> (raw)
In-Reply-To: <20021115161536.GA6654@reti>; from joe@fib011235813.fsnet.co.uk on Fri, Nov 15, 2002 at 04:15:36PM +0000
On Fri, Nov 15, 2002 at 04:15:36PM +0000, Joe Thornber wrote:
> On Thu, Nov 14, 2002 at 07:19:16PM +0530, chandrasekhar.nagaraj wrote:
> > Hi,
> >
> > In one of the part of my driver module , I have a path name to a device file
> > (for eg:- /dev/hda1) .Now if I want to obtain the associated major number
> > and minor number i.e. device ID(kdev_t) of this file what would be the
> > procedure?
>
> I think this should be standard function, I'm sure lots of people are
> duplicating this code. For 2.4 kernels:
>
> /*
> * Convert a device path to a kdev_t.
> */
> static int lookup_device(const char *path, kdev_t *dev)
> {
> int r;
> struct nameidata nd;
> struct inode *inode;
>
> if (!path_init(path, LOOKUP_FOLLOW, &nd))
> return 0;
missing LOOKUP_POSITIVE
>
> if ((r = path_walk(path, &nd)))
> goto out;
>
> inode = nd.dentry->d_inode;
> if (!inode) {
> r = -ENOENT;
> goto out;
> }
>
> if (!S_ISBLK(inode->i_mode)) {
> r = -EINVAL;
> goto out;
> }
shouldb be -ENOTBLK
new check here:
if (nd.mnt->mnt_flags & MNT_NODEV)
r = -EACCES;
>
> *dev = inode->i_rdev;
>
> out:
> path_release(&nd);
> return r;
I also think that this doesn not make much sense, you really want
name to properly opened struct block_device * instead, i.e. the firsdt halve
of get_sb_bdev()
next prev parent reply other threads:[~2002-11-15 16:21 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-11-14 13:49 Path Name to kdev_t chandrasekhar.nagaraj
2002-11-14 15:20 ` Gianni Tedesco
2002-11-14 15:32 ` Steven Dake
2002-11-14 22:50 ` Irfan Hamid
2002-11-15 16:15 ` Joe Thornber
2002-11-15 16:28 ` Christoph Hellwig [this message]
2002-11-15 18:10 ` Alexander Viro
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=20021115162845.A10146@infradead.org \
--to=hch@infradead.org \
--cc=chandrasekhar.nagaraj@patni.com \
--cc=joe@fib011235813.fsnet.co.uk \
--cc=linux-kernel@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox