<br><br><div class="gmail_quote">On Wed, Apr 6, 2011 at 3:08 AM, Greg Freemyer <span dir="ltr"><<a href="mailto:greg.freemyer@gmail.com">greg.freemyer@gmail.com</a>></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 <<a href="mailto:mohit89mlnc@gmail.com">mohit89mlnc@gmail.com</a>> wrote:<br>
><br>
</div><div class="im">> hi list,<br>
> how can a utility like **find** command can map an inode number to a<br>
> filename?<br>
> i mean if we pass **find -inum inode_number / ** , it will show us the<br>
> files associated with that "inode_number". What is the underlying mechanism<br>
> used in all this ?<br>
> I have peeped into the findutils code but it seems horrible to figure it<br>
> 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's a short section from strace. Notice in the directory walk it<br>
gets to charmaps. (I think that's /usr/share/i18n/charmaps).<br>
<br>
I'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, "charmaps", {st_mode=S_IFDIR|0755, st_size=12288,<br>
...}, AT_SYMLINK_NOFOLLOW) = 0<br>
open("charmaps", 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("charmaps", O_RDONLY|O_NOFOLLOW) = 4<br>
fchdir(4) = 0<br>
close(4) = 0<br>
stat(".", {st_mode=S_IFDIR|0755, st_size=12288, ...}) = 0<br>
newfstatat(AT_FDCWD, "CP1257.gz", {st_mode=S_IFREG|0644, st_size=2813,<br>
...}, AT_SYMLINK_NOFOLLOW) = 0<br>
newfstatat(AT_FDCWD, "EBCDIC-UK.gz", {st_mode=S_IFREG|0644,<br>
st_size=2129, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
newfstatat(AT_FDCWD, "LATIN-GREEK.gz", {st_mode=S_IFREG|0644,<br>
st_size=1605, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
newfstatat(AT_FDCWD, "NEXTSTEP.gz", {st_mode=S_IFREG|0644,<br>
st_size=2972, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
newfstatat(AT_FDCWD, "IBM903.gz", {st_mode=S_IFREG|0644, st_size=1566,<br>
...}, AT_SYMLINK_NOFOLLOW) = 0<br>
newfstatat(AT_FDCWD, "BIG5-HKSCS.gz", {st_mode=S_IFREG|0644,<br>
st_size=145960, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
newfstatat(AT_FDCWD, "BRF.gz", {st_mode=S_IFREG|0644, st_size=1166,<br>
...}, AT_SYMLINK_NOFOLLOW) = 0<br>
newfstatat(AT_FDCWD, "ISO-8859-9E.gz", {st_mode=S_IFREG|0644,<br>
st_size=3023, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
newfstatat(AT_FDCWD, "MSZ_7795.3.gz", {st_mode=S_IFREG|0644,<br>
st_size=1559, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
newfstatat(AT_FDCWD, "HP-ROMAN8.gz", {st_mode=S_IFREG|0644,<br>
st_size=3193, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
newfstatat(AT_FDCWD, "ISO-8859-7.gz", {st_mode=S_IFREG|0644,<br>
st_size=3074, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
newfstatat(AT_FDCWD, "DEC-MCS.gz", {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, "hints", {st_mode=S_IFDIR|0755, st_size=4096, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
open("hints", 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, "ttf-droid.hints", {st_mode=S_IFREG|0644, st_size=2819, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, "ttf-mscorefonts-installer.hints", {st_mode=S_IFREG|0644, st_size=24745, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, "ttf-unfonts-core.hints", {st_mode=S_IFREG|0644, st_size=1260, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>open("..", 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, "ps-cset-enc.data", {st_mode=S_IFREG|0644, st_size=3983, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, "loc-cset.data", {st_mode=S_IFREG|0644, st_size=1261, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, "fontconfig.subst-rule", {st_mode=S_IFREG|0644, st_size=1015, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, "xenc-cset.data", {st_mode=S_IFREG|0644, st_size=530, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, "csetenc-xenc.data2", {st_mode=S_IFREG|0644, st_size=580, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>open("..", 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, "environment", {st_mode=S_IFREG|0644, st_size=79, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, "gnome-vfs-2.0", {st_mode=S_IFDIR|0755, st_size=4096, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
open("gnome-vfs-2.0", 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, "modules", {st_mode=S_IFDIR|0755, st_size=4096, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>open("modules", 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, "extra-modules.conf", {st_mode=S_IFREG|0644, st_size=225, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, "default-modules.conf", {st_mode=S_IFREG|0644, st_size=300, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>open("..", 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("..", 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, "gshadow", {st_mode=S_IFREG|0640, st_size=974, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, "manpath.config", {st_mode=S_IFREG|0644, st_size=5173, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, "brltty", {st_mode=S_IFDIR|0755, st_size=12288, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>open("brltty", 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, "kbd-keypad.ktb", {st_mode=S_IFREG|0644, st_size=2944, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, "letters-latin-dot8.tti", {st_mode=S_IFREG|0644, st_size=3793, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, "brltty-vr-all.hlp", {st_mode=S_IFREG|0644, st_size=69, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, "mt.ttb", {st_mode=S_IFREG|0644, st_size=2203, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, "brl-pm-front9.kti", {st_mode=S_IFREG|0644, st_size=1777, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, "brl-pm-status4.kti", {st_mode=S_IFREG|0644, st_size=1160, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, "kbd-braille.kti", {st_mode=S_IFREG|0644, st_size=1913, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, "sv.ttb", {st_mode=S_IFREG|0644, st_size=838, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, "gujarati.tti", {st_mode=S_IFREG|0644, st_size=5279, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, "tamil.tti", {st_mode=S_IFREG|0644, st_size=4356, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, "brltty-ec-all.hlp", {st_mode=S_IFREG|0644, st_size=866, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, "sw.ttb", {st_mode=S_IFREG|0644, st_size=1262, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, "brl-bm-display6.kti", {st_mode=S_IFREG|0644, st_size=2887, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, "brl-pm-elba_trio_20.ktb", {st_mode=S_IFREG|0644, st_size=872, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, "sa.ttb", {st_mode=S_IFREG|0644, st_size=886, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, "brl-pm-el80_ii.ktb", {st_mode=S_IFREG|0644, st_size=865, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, "brl-pm-routing.kti", {st_mode=S_IFREG|0644, st_size=969, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, "fr-2007.ttb", {st_mode=S_IFREG|0644, st_size=12529, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, "ny.ctb", {st_mode=S_IFREG|0644, st_size=1269, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, "fr-cbifs.ttb", {st_mode=S_IFREG|0644, st_size=11267, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, "en_CA.ttb", {st_mode=S_IFREG|0644, st_size=6653, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, "brltty-ts-pb40.hlp", {st_mode=S_IFREG|0644, st_size=3313, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, "brl-al-abt_small.ktb", {st_mode=S_IFREG|0644, st_size=880, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, "brl-hm-sync.ktb", {st_mode=S_IFREG|0644, st_size=1679, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, "bengali.tti", {st_mode=S_IFREG|0644, st_size=4857, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, "brl-ht-bs80.ktb", {st_mode=S_IFREG|0644, st_size=868, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, "bo.ttb", {st_mode=S_IFREG|0644, st_size=4629, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, "fr_CA.ttb", {st_mode=S_IFREG|0644, st_size=11512, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, "sat.ttb", {st_mode=S_IFREG|0644, st_size=923, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, "te.ttb", {st_mode=S_IFREG|0644, st_size=880, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, "brl-pm-bar.kti", {st_mode=S_IFREG|0644, st_size=1189, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, "brltty-mn-all.hlp", {st_mode=S_IFREG|0644, st_size=2074, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, "dra.ttb", {st_mode=S_IFREG|0644, st_size=882, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, "brl-sk-all.ktb", {st_mode=S_IFREG|0644, st_size=2698, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, "ja.ctb", {st_mode=S_IFREG|0644, st_size=8450, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, "brl-pm-elba_trio_32.ktb", {st_mode=S_IFREG|0644, st_size=872, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, "letters-latin.tti", {st_mode=S_IFREG|0644, st_size=3752, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, "fr.ttb", {st_mode=S_IFREG|0644, st_size=837, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, "brl-bm-display7.kti", {st_mode=S_IFREG|0644, st_size=2215, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, "fr-integral.ctb", {st_mode=S_IFREG|0644, st_size=3843, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, "pl.ttb", {st_mode=S_IFREG|0644, st_size=11576, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, "sd.ttb", {st_mode=S_IFREG|0644, st_size=884, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, "de.ttb", {st_mode=S_IFREG|0644, st_size=11217, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, "kha.ttb", {st_mode=S_IFREG|0644, st_size=880, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, "brl-ht-me88.ktb", {st_mode=S_IFREG|0644, st_size=873, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, "de-vollschrift.ctb", {st_mode=S_IFREG|0644, st_size=3289, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, "zu.ctb", {st_mode=S_IFREG|0644, st_size=1233, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, "gd.ttb", {st_mode=S_IFREG|0644, st_size=3435, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, "numbers-nemeth.tti", {st_mode=S_IFREG|0644, st_size=1486, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, "brl-bm-vertical.kti", {st_mode=S_IFREG|0644, st_size=916, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, "brl-al-abt_large.ktb", {st_mode=S_IFREG|0644, st_size=926, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
fstatat64(AT_FDCWD, "brl-pm-status20.kti", {st_mode=S_IFREG|0644, st_size=2610, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>fstatat64(AT_FDCWD, "brl-pm-status0.kti", {st_mode=S_IFREG|0644, st_size=862, ...}, AT_SYMLINK_NOFOLLOW) = 0<br>
<br><br>My system doesn'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>