public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Path Name to kdev_t
@ 2002-11-14 13:49 chandrasekhar.nagaraj
  2002-11-14 15:20 ` Gianni Tedesco
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: chandrasekhar.nagaraj @ 2002-11-14 13:49 UTC (permalink / raw)
  To: linux-kernel

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?

Thanks and Regards
Chandrasekhar


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

* Re: Path Name to kdev_t
  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
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Gianni Tedesco @ 2002-11-14 15:20 UTC (permalink / raw)
  To: chandrasekhar.nagaraj; +Cc: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 665 bytes --]

On Thu, 2002-11-14 at 13:49, chandrasekhar.nagaraj wrote:
> 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?

You need to lookup the inode from the path using namei() or something
then it's just a field in the inode.

Check out fs/namei.c and related headers for more details.

-- 
// Gianni Tedesco (gianni at ecsc dot co dot uk)
lynx --source www.scaramanga.co.uk/gianni-at-ecsc.asc | gpg --import
8646BE7D: 6D9F 2287 870E A2C9 8F60 3A3C 91B5 7669 8646 BE7D

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 232 bytes --]

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

* Re: Path Name to kdev_t
  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
  3 siblings, 0 replies; 7+ messages in thread
From: Steven Dake @ 2002-11-14 15:32 UTC (permalink / raw)
  To: chandrasekhar.nagaraj, linux-kernel

You would want to find a struct file * that represents the device (look 
at fs/open.c in the sys_open calls, it shows how to convert a filename 
to a file *) then look at file->f_dentry->d_inode->i_bdev->bd_dev.  This 
is the major/minor dev_t for the device.

Hope this helps.
Thanks
-steve
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?
>
>Thanks and Regards
>Chandrasekhar
>
>-
>To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
>the body of a message to majordomo@vger.kernel.org
>More majordomo info at  http://vger.kernel.org/majordomo-info.html
>Please read the FAQ at  http://www.tux.org/lkml/
>
>
>
>  
>


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

* Re: Path Name to kdev_t
  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
  3 siblings, 0 replies; 7+ messages in thread
From: Irfan Hamid @ 2002-11-14 22:50 UTC (permalink / raw)
  To: chandrasekhar.nagaraj, linux-kernel

in all functions of the driver where you will need the kdev_t (e.g.: the VFS 
layer hooks) you will receive either a struct inode* and/or the struct file* 
of the device file. the i_rdev member of struct inode is defined as the 
kdev_t of the particular device.

hope this helps.

regards,
irfan.

On Thursday 14 November 2002 01:49 pm, 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?
>
> Thanks and Regards
> Chandrasekhar
>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/


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

* Re: Path Name to kdev_t
  2002-11-14 13:49 Path Name to kdev_t chandrasekhar.nagaraj
                   ` (2 preceding siblings ...)
  2002-11-14 22:50 ` Irfan Hamid
@ 2002-11-15 16:15 ` Joe Thornber
  2002-11-15 16:28   ` Christoph Hellwig
  2002-11-15 18:10   ` Alexander Viro
  3 siblings, 2 replies; 7+ messages in thread
From: Joe Thornber @ 2002-11-15 16:15 UTC (permalink / raw)
  To: chandrasekhar.nagaraj; +Cc: linux-kernel

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;

	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;
	}

	*dev = inode->i_rdev;

 out:
	path_release(&nd);
	return r;
}

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

* Re: Path Name to kdev_t
  2002-11-15 16:15 ` Joe Thornber
@ 2002-11-15 16:28   ` Christoph Hellwig
  2002-11-15 18:10   ` Alexander Viro
  1 sibling, 0 replies; 7+ messages in thread
From: Christoph Hellwig @ 2002-11-15 16:28 UTC (permalink / raw)
  To: Joe Thornber; +Cc: chandrasekhar.nagaraj, linux-kernel

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()


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

* Re: Path Name to kdev_t
  2002-11-15 16:15 ` Joe Thornber
  2002-11-15 16:28   ` Christoph Hellwig
@ 2002-11-15 18:10   ` Alexander Viro
  1 sibling, 0 replies; 7+ messages in thread
From: Alexander Viro @ 2002-11-15 18:10 UTC (permalink / raw)
  To: Joe Thornber; +Cc: chandrasekhar.nagaraj, linux-kernel



On Fri, 15 Nov 2002, 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:

No, it really shouldn't.  You should _NOT_ mess with kdev_t - use real
objects instead.


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

end of thread, other threads:[~2002-11-15 18:03 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2002-11-15 18:10   ` Alexander Viro

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox