Path Name to kdev_t
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
Quoted 4 lines · chandrasekhar.nagaraj
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. deviceID(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.
Signature · 3 lines
// 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
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
Quoted 20 lines · chandrasekhar.nagaraj
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. deviceID(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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
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.
Quoted 15 lines · chandrasekhar.nagaraj
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. deviceID(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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Quoted 6 lines · chandrasekhar.nagaraj
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. deviceID(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; }
Quoted 15 lines · Joe Thornber
Quoted 6 lines · chandrasekhar.nagaraj
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. deviceID(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 akdev_t.
*/
static intlookup_device(const char *path, kdev_t *dev)
Quoted 7 lines
{
int r;
struct nameidata nd;
struct inode *inode;
if (!path_init(path, LOOKUP_FOLLOW, &nd))
return 0;missing LOOKUP_POSITIVE
Quoted 14 lines
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;
Quoted 6 lines
*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()
Quoted 10 lines · Joe Thornber
Quoted 6 lines · chandrasekhar.nagaraj
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. deviceID(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.