<br><br><div class="gmail_quote">On Wed, Apr 6, 2011 at 3:08 AM, Greg Freemyer <span dir="ltr">&lt;<a href="mailto:greg.freemyer@gmail.com">greg.freemyer@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div class="im">On Tue, Apr 5, 2011 at 4:41 PM, mohit verma &lt;<a href="mailto:mohit89mlnc@gmail.com">mohit89mlnc@gmail.com</a>&gt; wrote:<br>
&gt;<br>
</div><div class="im">&gt; hi list,<br>
&gt; how can a utility like **find** command  can map an inode number to a<br>
&gt; filename?<br>
&gt;  i mean if we pass **find -inum inode_number  / **   , it will show us the<br>
&gt;  files associated with that &quot;inode_number&quot;. What is the underlying mechanism<br>
&gt; used in all this ?<br>
&gt;  I have peeped into the findutils code but it seems horrible to figure it<br>
&gt; out from that code .:)<br>
<br>
</div>strace is a lot easier than reading code for something like that.<br>
<br>
Looks to me like find is just walking the tree and calling<br>
newfstatat() on every file.<br>
<br>
Here&#39;s a short section from strace.  Notice in the directory walk it<br>
gets to charmaps.  (I think that&#39;s /usr/share/i18n/charmaps).<br>
<br>
I&#39;d guess that based on the return from newfstatat() it decides its a<br>
directory, so it call getdents64()<br>
<br>
It then starts calling newfstatat() for everything in that directory.<br>
(Not as sexy as you hoped I suspect.)<br>
<br>
<br>
newfstatat(AT_FDCWD, &quot;charmaps&quot;, {st_mode=S_IFDIR|0755, st_size=12288,<br>
...}, AT_SYMLINK_NOFOLLOW) = 0<br>
open(&quot;charmaps&quot;, O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 4<br>
getdents64(4, /* 229 entries */, 32768) = 8024<br>
getdents64(4, /* 0 entries */, 32768)   = 0<br>
close(4)                                = 0<br>
open(&quot;charmaps&quot;, O_RDONLY|O_NOFOLLOW)   = 4<br>
fchdir(4)                               = 0<br>
close(4)                                = 0<br>
stat(&quot;.&quot;, {st_mode=S_IFDIR|0755, st_size=12288, ...}) = 0<br>
newfstatat(AT_FDCWD, &quot;CP1257.gz&quot;, {st_mode=S_IFREG|0644, st_size=2813,<br>
...}, AT_SYMLINK_NOFOLLOW) = 0<br>
newfstatat(AT_FDCWD, &quot;EBCDIC-UK.gz&quot;, {st_mode=S_IFREG|0644,<br>
st_size=2129, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
newfstatat(AT_FDCWD, &quot;LATIN-GREEK.gz&quot;, {st_mode=S_IFREG|0644,<br>
st_size=1605, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
newfstatat(AT_FDCWD, &quot;NEXTSTEP.gz&quot;, {st_mode=S_IFREG|0644,<br>
st_size=2972, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
newfstatat(AT_FDCWD, &quot;IBM903.gz&quot;, {st_mode=S_IFREG|0644, st_size=1566,<br>
...}, AT_SYMLINK_NOFOLLOW) = 0<br>
newfstatat(AT_FDCWD, &quot;BIG5-HKSCS.gz&quot;, {st_mode=S_IFREG|0644,<br>
st_size=145960, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
newfstatat(AT_FDCWD, &quot;BRF.gz&quot;, {st_mode=S_IFREG|0644, st_size=1166,<br>
...}, AT_SYMLINK_NOFOLLOW) = 0<br>
newfstatat(AT_FDCWD, &quot;ISO-8859-9E.gz&quot;, {st_mode=S_IFREG|0644,<br>
st_size=3023, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
newfstatat(AT_FDCWD, &quot;MSZ_7795.3.gz&quot;, {st_mode=S_IFREG|0644,<br>
st_size=1559, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
newfstatat(AT_FDCWD, &quot;HP-ROMAN8.gz&quot;, {st_mode=S_IFREG|0644,<br>
st_size=3193, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
newfstatat(AT_FDCWD, &quot;ISO-8859-7.gz&quot;, {st_mode=S_IFREG|0644,<br>
st_size=3074, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
newfstatat(AT_FDCWD, &quot;DEC-MCS.gz&quot;, {st_mode=S_IFREG|0644,<br>
st_size=2948, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
<br></blockquote><div>Hi  , <br> i am using 32 bit intel system with ubuntu10.10.  And what i got after strace find is something like this:<br>fstatat64(AT_FDCWD, &quot;hints&quot;, {st_mode=S_IFDIR|0755, st_size=4096, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
open(&quot;hints&quot;, O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC) = 5<br>fchdir(5)                               = 0<br>getdents64(5, /* 5 entries */, 32768)   = 192<br>getdents64(5, /* 0 entries */, 32768)   = 0<br>
close(5)                                = 0<br>fstatat64(AT_FDCWD, &quot;ttf-droid.hints&quot;, {st_mode=S_IFREG|0644, st_size=2819, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, &quot;ttf-mscorefonts-installer.hints&quot;, {st_mode=S_IFREG|0644, st_size=24745, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, &quot;ttf-unfonts-core.hints&quot;, {st_mode=S_IFREG|0644, st_size=1260, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>open(&quot;..&quot;, O_RDONLY|O_NOCTTY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY|O_NOFOLLOW) = 5<br>fstat64(5, {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0<br>
fchdir(5)                               = 0<br>close(5)                                = 0<br>fstatat64(AT_FDCWD, &quot;ps-cset-enc.data&quot;, {st_mode=S_IFREG|0644, st_size=3983, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, &quot;loc-cset.data&quot;, {st_mode=S_IFREG|0644, st_size=1261, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, &quot;fontconfig.subst-rule&quot;, {st_mode=S_IFREG|0644, st_size=1015, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, &quot;xenc-cset.data&quot;, {st_mode=S_IFREG|0644, st_size=530, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, &quot;csetenc-xenc.data2&quot;, {st_mode=S_IFREG|0644, st_size=580, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>open(&quot;..&quot;, O_RDONLY|O_NOCTTY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY|O_NOFOLLOW) = 5<br>fstat64(5, {st_mode=S_IFDIR|0755, st_size=12288, ...}) = 0<br>
fchdir(5)                               = 0<br>close(5)                                = 0<br>fstatat64(AT_FDCWD, &quot;environment&quot;, {st_mode=S_IFREG|0644, st_size=79, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, &quot;gnome-vfs-2.0&quot;, {st_mode=S_IFDIR|0755, st_size=4096, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
open(&quot;gnome-vfs-2.0&quot;, O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC) = 5<br>fchdir(5)                               = 0<br>getdents64(5, /* 3 entries */, 32768)   = 80<br>getdents64(5, /* 0 entries */, 32768)   = 0<br>
close(5)                                = 0<br>fstatat64(AT_FDCWD, &quot;modules&quot;, {st_mode=S_IFDIR|0755, st_size=4096, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>open(&quot;modules&quot;, O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC) = 5<br>
fchdir(5)                               = 0<br>getdents64(5, /* 4 entries */, 32768)   = 128<br>getdents64(5, /* 0 entries */, 32768)   = 0<br>close(5)                                = 0<br>fstatat64(AT_FDCWD, &quot;extra-modules.conf&quot;, {st_mode=S_IFREG|0644, st_size=225, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, &quot;default-modules.conf&quot;, {st_mode=S_IFREG|0644, st_size=300, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>open(&quot;..&quot;, O_RDONLY|O_NOCTTY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY|O_NOFOLLOW) = 5<br>fstat64(5, {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0<br>
fchdir(5)                               = 0<br>close(5)                                = 0<br>open(&quot;..&quot;, O_RDONLY|O_NOCTTY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY|O_NOFOLLOW) = 5<br>fstat64(5, {st_mode=S_IFDIR|0755, st_size=12288, ...}) = 0<br>
fchdir(5)                               = 0<br>close(5)                                = 0<br>fstatat64(AT_FDCWD, &quot;gshadow&quot;, {st_mode=S_IFREG|0640, st_size=974, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, &quot;manpath.config&quot;, {st_mode=S_IFREG|0644, st_size=5173, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, &quot;brltty&quot;, {st_mode=S_IFDIR|0755, st_size=12288, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>open(&quot;brltty&quot;, O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC) = 5<br>fchdir(5)                               = 0<br>
getdents64(5, /* 265 entries */, 32768) = 9720<br>brk(0x975a000)                          = 0x975a000<br>getdents64(5, /* 0 entries */, 32768)   = 0<br>close(5)                                = 0<br>fstatat64(AT_FDCWD, &quot;kbd-keypad.ktb&quot;, {st_mode=S_IFREG|0644, st_size=2944, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, &quot;letters-latin-dot8.tti&quot;, {st_mode=S_IFREG|0644, st_size=3793, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, &quot;brltty-vr-all.hlp&quot;, {st_mode=S_IFREG|0644, st_size=69, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, &quot;mt.ttb&quot;, {st_mode=S_IFREG|0644, st_size=2203, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, &quot;brl-pm-front9.kti&quot;, {st_mode=S_IFREG|0644, st_size=1777, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, &quot;brl-pm-status4.kti&quot;, {st_mode=S_IFREG|0644, st_size=1160, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, &quot;kbd-braille.kti&quot;, {st_mode=S_IFREG|0644, st_size=1913, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, &quot;sv.ttb&quot;, {st_mode=S_IFREG|0644, st_size=838, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, &quot;gujarati.tti&quot;, {st_mode=S_IFREG|0644, st_size=5279, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, &quot;tamil.tti&quot;, {st_mode=S_IFREG|0644, st_size=4356, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, &quot;brltty-ec-all.hlp&quot;, {st_mode=S_IFREG|0644, st_size=866, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, &quot;sw.ttb&quot;, {st_mode=S_IFREG|0644, st_size=1262, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, &quot;brl-bm-display6.kti&quot;, {st_mode=S_IFREG|0644, st_size=2887, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, &quot;brl-pm-elba_trio_20.ktb&quot;, {st_mode=S_IFREG|0644, st_size=872, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, &quot;sa.ttb&quot;, {st_mode=S_IFREG|0644, st_size=886, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, &quot;brl-pm-el80_ii.ktb&quot;, {st_mode=S_IFREG|0644, st_size=865, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, &quot;brl-pm-routing.kti&quot;, {st_mode=S_IFREG|0644, st_size=969, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, &quot;fr-2007.ttb&quot;, {st_mode=S_IFREG|0644, st_size=12529, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, &quot;ny.ctb&quot;, {st_mode=S_IFREG|0644, st_size=1269, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, &quot;fr-cbifs.ttb&quot;, {st_mode=S_IFREG|0644, st_size=11267, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, &quot;en_CA.ttb&quot;, {st_mode=S_IFREG|0644, st_size=6653, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, &quot;brltty-ts-pb40.hlp&quot;, {st_mode=S_IFREG|0644, st_size=3313, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, &quot;brl-al-abt_small.ktb&quot;, {st_mode=S_IFREG|0644, st_size=880, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, &quot;brl-hm-sync.ktb&quot;, {st_mode=S_IFREG|0644, st_size=1679, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, &quot;bengali.tti&quot;, {st_mode=S_IFREG|0644, st_size=4857, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, &quot;brl-ht-bs80.ktb&quot;, {st_mode=S_IFREG|0644, st_size=868, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, &quot;bo.ttb&quot;, {st_mode=S_IFREG|0644, st_size=4629, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, &quot;fr_CA.ttb&quot;, {st_mode=S_IFREG|0644, st_size=11512, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, &quot;sat.ttb&quot;, {st_mode=S_IFREG|0644, st_size=923, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, &quot;te.ttb&quot;, {st_mode=S_IFREG|0644, st_size=880, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, &quot;brl-pm-bar.kti&quot;, {st_mode=S_IFREG|0644, st_size=1189, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, &quot;brltty-mn-all.hlp&quot;, {st_mode=S_IFREG|0644, st_size=2074, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, &quot;dra.ttb&quot;, {st_mode=S_IFREG|0644, st_size=882, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, &quot;brl-sk-all.ktb&quot;, {st_mode=S_IFREG|0644, st_size=2698, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, &quot;ja.ctb&quot;, {st_mode=S_IFREG|0644, st_size=8450, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, &quot;brl-pm-elba_trio_32.ktb&quot;, {st_mode=S_IFREG|0644, st_size=872, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, &quot;letters-latin.tti&quot;, {st_mode=S_IFREG|0644, st_size=3752, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, &quot;fr.ttb&quot;, {st_mode=S_IFREG|0644, st_size=837, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, &quot;brl-bm-display7.kti&quot;, {st_mode=S_IFREG|0644, st_size=2215, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, &quot;fr-integral.ctb&quot;, {st_mode=S_IFREG|0644, st_size=3843, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, &quot;pl.ttb&quot;, {st_mode=S_IFREG|0644, st_size=11576, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, &quot;sd.ttb&quot;, {st_mode=S_IFREG|0644, st_size=884, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, &quot;de.ttb&quot;, {st_mode=S_IFREG|0644, st_size=11217, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, &quot;kha.ttb&quot;, {st_mode=S_IFREG|0644, st_size=880, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, &quot;brl-ht-me88.ktb&quot;, {st_mode=S_IFREG|0644, st_size=873, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, &quot;de-vollschrift.ctb&quot;, {st_mode=S_IFREG|0644, st_size=3289, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, &quot;zu.ctb&quot;, {st_mode=S_IFREG|0644, st_size=1233, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, &quot;gd.ttb&quot;, {st_mode=S_IFREG|0644, st_size=3435, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, &quot;numbers-nemeth.tti&quot;, {st_mode=S_IFREG|0644, st_size=1486, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, &quot;brl-bm-vertical.kti&quot;, {st_mode=S_IFREG|0644, st_size=916, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, &quot;brl-al-abt_large.ktb&quot;, {st_mode=S_IFREG|0644, st_size=926, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, &quot;brl-pm-status20.kti&quot;, {st_mode=S_IFREG|0644, st_size=2610, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, &quot;brl-pm-status0.kti&quot;, {st_mode=S_IFREG|0644, st_size=862, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
<br><br>My system doesn&#39;t have a system call like newfstatat(). But i suspect (looking at the strace output)  that from the starting search directory find opens the dirent stream and manually check inode number (if option -inum) passed  to it using fstatat() . <br>
</div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<br>
<br>
HTH<br>
<font color="#888888">Greg<br>
</font></blockquote></div><br><br clear="all"><br>-- <br>........................<div><i>MOHIT VERMA</i></div><br>