Path Name to kdev_t

Path Name to kdev_t

Post by chandrasekhar.nagara » Fri, 15 Nov 2002 15:50:08



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

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

 
 
 

Path Name to kdev_t

Post by Gianni Tedesc » Fri, 15 Nov 2002 17:30:09



> 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

  signature.asc
< 1K Download

 
 
 

Path Name to kdev_t

Post by Steven Dak » Fri, 15 Nov 2002 17:40:10


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


>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

>More majordomo info at  http://vger.kernel.org/majordomo-info.html
>Please read the FAQ at  http://www.tux.org/lkml/

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
 
 
 

Path Name to kdev_t

Post by Irfan Hami » Fri, 15 Nov 2002 20:00:19


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.


> 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

> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
 
 
 

Path Name to kdev_t

Post by Joe Thornbe » Sat, 16 Nov 2002 18:20:09



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

Quote:}

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
 
 
 

Path Name to kdev_t

Post by Christoph Hellwi » Sat, 16 Nov 2002 18:40:06




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

Quote:

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

Quote:

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

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

 
 
 

Path Name to kdev_t

Post by Alexander Vir » Sat, 16 Nov 2002 20:20:11




> > 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.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

 
 
 

1. Extracting full path name from ~user/path

Environment SunOS 4.1.1 on Sun Sparcstation

Is there a system function from which I can get a full path name from a ~user/pathname ?
  eg.     full_path = some_function("~user/pathname");
           /* returns a pointer to a char string /home/user/pathname */

Please email your responses.  I am not a regular reader of this newsgroup.
Thank you.
--
Rupen Sheth

2550 Beckleymeade Ave. MS 4004                   Phone: (214) 708-3344
Dallas, TX 75237                                   FAX: (214) 708-4827

2. A/D, D/A, I/O Card under $300

3. how to extract path/file name upto the mzximum of two levels from the file name?

4. PCI network card detection/initalization order

5. add in the PATH a path if not present in the PATH

6. Bad Header

7. ksh: add path to $PATH only when ot yet in $PATH

8. mount -dos in vfs?

9. zsh's 'typeset -U path' wipes out path/PATH

10. PATH=$(getconf PATH), but PATH for getconf?

11. set path = "$path" hoses path in tcsh -- why???

12. How to expand paths in $PATH like "~/bin" to full path?

13. empty path name interpreted as current directory