inode query

Greg Freemyer greg.freemyer at gmail.com
Tue Apr 5 17:38:12 EDT 2011


On Tue, Apr 5, 2011 at 4:41 PM, mohit verma <mohit89mlnc at gmail.com> wrote:
>
> hi list,
> how can a utility like **find** command  can map an inode number to a
> filename?
>  i mean if we pass **find -inum inode_number  / **   , it will show us the
>  files associated with that "inode_number". What is the underlying mechanism
> used in all this ?
>  I have peeped into the findutils code but it seems horrible to figure it
> out from that code .:)

strace is a lot easier than reading code for something like that.

Looks to me like find is just walking the tree and calling
newfstatat() on every file.

Here's a short section from strace.  Notice in the directory walk it
gets to charmaps.  (I think that's /usr/share/i18n/charmaps).

I'd guess that based on the return from newfstatat() it decides its a
directory, so it call getdents64()

It then starts calling newfstatat() for everything in that directory.
(Not as sexy as you hoped I suspect.)


newfstatat(AT_FDCWD, "charmaps", {st_mode=S_IFDIR|0755, st_size=12288,
...}, AT_SYMLINK_NOFOLLOW) = 0
open("charmaps", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 4
getdents64(4, /* 229 entries */, 32768) = 8024
getdents64(4, /* 0 entries */, 32768)   = 0
close(4)                                = 0
open("charmaps", O_RDONLY|O_NOFOLLOW)   = 4
fchdir(4)                               = 0
close(4)                                = 0
stat(".", {st_mode=S_IFDIR|0755, st_size=12288, ...}) = 0
newfstatat(AT_FDCWD, "CP1257.gz", {st_mode=S_IFREG|0644, st_size=2813,
...}, AT_SYMLINK_NOFOLLOW) = 0
newfstatat(AT_FDCWD, "EBCDIC-UK.gz", {st_mode=S_IFREG|0644,
st_size=2129, ...}, AT_SYMLINK_NOFOLLOW) = 0
newfstatat(AT_FDCWD, "LATIN-GREEK.gz", {st_mode=S_IFREG|0644,
st_size=1605, ...}, AT_SYMLINK_NOFOLLOW) = 0
newfstatat(AT_FDCWD, "NEXTSTEP.gz", {st_mode=S_IFREG|0644,
st_size=2972, ...}, AT_SYMLINK_NOFOLLOW) = 0
newfstatat(AT_FDCWD, "IBM903.gz", {st_mode=S_IFREG|0644, st_size=1566,
...}, AT_SYMLINK_NOFOLLOW) = 0
newfstatat(AT_FDCWD, "BIG5-HKSCS.gz", {st_mode=S_IFREG|0644,
st_size=145960, ...}, AT_SYMLINK_NOFOLLOW) = 0
newfstatat(AT_FDCWD, "BRF.gz", {st_mode=S_IFREG|0644, st_size=1166,
...}, AT_SYMLINK_NOFOLLOW) = 0
newfstatat(AT_FDCWD, "ISO-8859-9E.gz", {st_mode=S_IFREG|0644,
st_size=3023, ...}, AT_SYMLINK_NOFOLLOW) = 0
newfstatat(AT_FDCWD, "MSZ_7795.3.gz", {st_mode=S_IFREG|0644,
st_size=1559, ...}, AT_SYMLINK_NOFOLLOW) = 0
newfstatat(AT_FDCWD, "HP-ROMAN8.gz", {st_mode=S_IFREG|0644,
st_size=3193, ...}, AT_SYMLINK_NOFOLLOW) = 0
newfstatat(AT_FDCWD, "ISO-8859-7.gz", {st_mode=S_IFREG|0644,
st_size=3074, ...}, AT_SYMLINK_NOFOLLOW) = 0
newfstatat(AT_FDCWD, "DEC-MCS.gz", {st_mode=S_IFREG|0644,
st_size=2948, ...}, AT_SYMLINK_NOFOLLOW) = 0



HTH
Greg



More information about the Kernelnewbies mailing list