<pre>Hey, <br><br>I just ran through this post, and since no solution was posted, here's a piece of code that i had written <br>Infact when i wrote this i wanted both the device name and also the file system on that partition. <br>
But for this, one needs the root privileges. <br><br>#include<stdio.h><br>#include<stdlib.h><br>#include <sys/types.h><br>#include <sys/stat.h><br>#include <unistd.h><br>#include<assert.h><br>
#include<blkid/blkid.h><br><br>int main(int argc,char *argv[])<br>{<br> struct blkid_struct_dev *dev;<br> struct blkid_struct_cache *cache;<br> char *type,*dev_name;<br> struct stat buf;<br>
assert(argc == 2);<br> assert(argv[1]);<br> assert(lstat(argv[1],&buf) == 0);<br> dev_name=blkid_devno_to_devname(buf.st_dev);<br> assert(dev_name);<br> printf("Device name :%s\n",dev_name);<br>
assert(blkid_get_cache(&cache,"/dev/null") == 0);<br> dev = (struct blkid_struct_dev *)blkid_get_dev(cache,dev_name, BLKID_DEV_NORMAL);<br> assert(dev);<br> type = blkid_get_tag_value(cache,"TYPE",dev_name);<br>
printf("File System type is : %s\n",type);<br> blkid_free_dev(dev);<br> return (0);<br>}<br><br>You have to compile it with the libblkid. <br>Do man for libblkid, that should be really helpful. <br>
<br>-Smit Shah.<br><br><br>--- On Thu, 20/3/08, liuyue <liuyue ncic ac cn> wrote:<br><br>> From: liuyue <liuyue ncic ac cn><br>> Subject: Re: How to get device name with device id?<br>> To: "ashitpro yahoo co in" <ashitpro yahoo co in>, "ext3-users redhat com" <ext3-users redhat com><br>
> Date: Thursday, 20 March, 2008, 4:34 PM<br>> ashish mahamuni,<br>> <br>> I guess maybe the following function does what you want.<br>> But it is a kernel function, sorry :(<br>> <br>> int __file_to_disk (char * file_name, char *disk_name) {<br>
> int err = 0;<br>> struct nameidata nd;<br>> struct super_block * sb;<br>> struct vfsmount *mnt;<br>> err = path_lookup(file_name, LOOKUP_FOLLOW,<br>> &nd);<br>
> if(err){<br>> DCFS3_ERROR("error to parse the file<br>> name, %s\n", file_name);<br>> goto exit;<br>> }<br>> mnt = nd.mnt;<br>> sb = mnt->mnt_sb;<br>
> strcpy (disk_name,<br>> sb->s_bdev->bd_disk->disk_name);<br>> path_release(&nd);<br>> exit:<br>> return err;<br>> }<br>> <br>> ======= 2008-03-20 19:21:04<br>
> ÄúÔÚÀ´ÐÅÖÐдµÀ£º=======<br>> <br>> >Hi all,<br>> ><br>> >I want to open a device(/dev/sda1, /dev/hda2 etc) in<br>> which my file exists.<br>> >I've used 'stat' system call to get the<br>
> device id.<br>> ><br>> >But now I want the device name from this id(st_dev).<br>> >How to get that one?<br>> >Or <br>> >Do you have any other method to know the device name<br>> where my file resides?<br>
> ><br>> >Thanks <br>> ><br>> ><br>> > Bollywood, fun, friendship, sports and more. You<br>> name it, we have it on <a rel="nofollow" href="http://in.promos.yahoo.com/groups">http://in.promos.yahoo.com/groups</a> <br>
> ><br>> ><br>> >_______________________________________________<br>> >Ext3-users mailing list<br>> >Ext3-users redhat com<br>> ><a rel="nofollow" href="https://www.redhat.com/mailman/listinfo/ext3-users">https://www.redhat.com/mailman/listinfo/ext3-users</a><br>
> ><br>> ><br>> <br>> = = = = = = = = = = = = = = = = = = = =<br>> <br>> <br>> ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ÖÂ<br>> Àñ£¡<br>> <br>> <br>> ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡liuyue<br>> ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡liuyue ncic ac cn<br>> ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡2008-03-20<br>
</pre>