hi
i have inode number of file.
but i want to know that can i found file name by using inode number.
chandrakant solanki
Printable View
hi
i have inode number of file.
but i want to know that can i found file name by using inode number.
chandrakant solanki
[email]solanki.chandrakant@gmail.com[/email] wrote:[color=blue]
> hi
>
> i have inode number of file.
> but i want to know that can i found file name by using inode number.[/color]
find <root of fs> -xdev -inum <inode number>
e.g.
find / -xdev -inum 10
--
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
hi
thanks for reply but the command you''ve given me is not work.
And the second thing is to i want to do the same with the help of c
programming... is it possible ? if yes, then how ..?
Chandrakant
[email]solanki.chandrakant@gmail.com[/email] wrote:[color=blue]
> hi
>
> thanks for reply but the command you''ve given me is not work.[/color]
Why not?
Are you sure the file with the given i-number does exist?
# ls -lisa /etc/mgetty+sendfax/login.config
76 [...] /etc/mgetty+sendfax/login.config
# find / -xdev -inum 76
/etc/mgetty+sendfax/login.config
[color=blue]
> And the second thing is to i want to do the same with the help of c
> programming... is it possible ? if yes, then how ..?[/color]
A combination of ftw() and stat() would do the trick.
--
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
hi
can i know that whether the inode number is in hex number or it should
be an integer number..
b'coz i have searched for that but it not works...
i have insert my code over here if any mistake then plz suggest me...
in the following code i have to find the file name for inode number
6216.
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <dirent.h>
int main( void )
{
DIR *dir;
char path[128] = "";
struct stat s;
struct dirent *entry;
int iFD = 0;
char *dPath[24] = { "/usr/bin/" };
int i = 0;
for( i = 0; i < 1; i++ )
{
dir = opendir( dPath[i] );
if( !dir ) {
fprintf( stderr,"error: unable to open dir\n"
);
return 0;
}
else
{
while( ( entry = readdir( dir ) ) )
{
if( entry->d_type == DT_DIR )
continue;
strcpy( path, dPath[i] );
strcat( path, entry->d_name );
iFD = open( path, O_RDONLY );
if( fstat( iFD, &s ) != -1 )
{
if( s.st_ino == 6216 )
printf( "%d\t%s\n",
s.st_ino, entry->d_name );
}
else
;
close( iFD );
}
closedir( dir );
}
}
return 0;
}
[email]solanki.chandrakant@gmail.com[/email] wrote:[color=blue]
> hi
>
> can i know that whether the inode number is in hex number or it should
> be an integer number..[/color]
??? a number is a number is a number
Whether it's hex or decimal or octal or binary or a couple of lumps of
electrons is just a matter of representation!
[color=blue]
> b'coz i have searched for that but it not works...[/color]
Please refrain from kiddie talk. It's "Because" ...
[color=blue]
> i have insert my code over here if any mistake then plz suggest me...[/color]
... and "please".
[color=blue]
> in the following code i have to find the file name for inode number
> 6216.[/color]
Are you sure it exists at all in /usr/bin? Maybe it is in /usr/sbin or
in /usr/lib or ...
What happens if you do "ls -i /usr/bin | fgrep 6216" Does it show any
file with i-number 6216?
Code deleted, sorry, I have no time checking your code and finding bugs
in it. But ... what's so bad about using ftw?
--
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
In article <emb1td$ivd$1@nntp.fujitsu-siemens.com>,
Josef Moellers <josef.moellers@fujitsu-siemens.com> wrote:
[color=blue]
>Are you sure the file with the given i-number does exist?[/color]
And does it have a directory entry somewhere?
--
[url]http://www.spinics.net/lists/[/url]
On 20 Dec 2006 01:59:51 -0800 [email]solanki.chandrakant@gmail.com[/email] <Solanki.Chandrakant@gmail.com> wrote:
| hi
|
| thanks for reply but the command you''ve given me is not work.
|
| And the second thing is to i want to do the same with the help of c
| programming... is it possible ? if yes, then how ..?
|
| Chandrakant
It is also possible the file becomes unlinked to link count zero
somewhere between when you get its inode and when you would have
found a link to it othewise. Even if the file is still open and
exists without a name, this can happen.
Also, the inode is not enough if there is more than one filesystem
mounted. With 2 or more filesystems, each can have a file of the
very same inode number. The distinction is the device number of
the filesystem. A combination of the filesystem device number and
the inode number would uniquely identify a file on a machine if it
still exists.
First, your program has a logic error (just one character) before
statement
close( iFD );
^_^
[email]solanki.chandrakant@gmail.com[/email] wrote:[color=blue]
> hi
>
> can i know that whether the inode number is in hex number or it should
> be an integer number..
> b'coz i have searched for that but it not works...
>
> i have insert my code over here if any mistake then plz suggest me...
> in the following code i have to find the file name for inode number
> 6216.
>
>
> #include <stdio.h>
>
> #include <fcntl.h>
> #include <unistd.h>
> #include <string.h>
> #include <sys/stat.h>
> #include <sys/types.h>
>
> #include <dirent.h>
>
> int main( void )
> {
> DIR *dir;
>
> char path[128] = "";
> struct stat s;
> struct dirent *entry;
>
> int iFD = 0;
>
> char *dPath[24] = { "/usr/bin/" };
>
> int i = 0;
> for( i = 0; i < 1; i++ )
> {
> dir = opendir( dPath[i] );
>
> if( !dir ) {
> fprintf( stderr,"error: unable to open dir\n"
> );
> return 0;
> }
> else
> {
> while( ( entry = readdir( dir ) ) )
> {
> if( entry->d_type == DT_DIR )
> continue;
>
> strcpy( path, dPath[i] );
> strcat( path, entry->d_name );
>
> iFD = open( path, O_RDONLY );
> if( fstat( iFD, &s ) != -1 )
> {
> if( s.st_ino == 6216 )
> printf( "%d\t%s\n",
> s.st_ino, entry->d_name );
> }
> else
> ;
> close( iFD );
> }
> closedir( dir );
> }
> }
> return 0;
> }[/color]