inode query
Manish Katiyar
mkatiyar at gmail.com
Fri Apr 8 03:04:36 EDT 2011
On Thu, Apr 7, 2011 at 11:54 PM, mohit verma <mohit89mlnc at gmail.com> wrote:
>
>
> On Wed, Apr 6, 2011 at 3:08 AM, Greg Freemyer <greg.freemyer at gmail.com>
> wrote:
>>
>> 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
>>
> Hi ,
> i am using 32 bit intel system with ubuntu10.10. And what i got after
> strace find is something like this:
> fstatat64(AT_FDCWD, "hints", {st_mode=S_IFDIR|0755, st_size=4096, ...},
> AT_SYMLINK_NOFOLLOW) = 0
> open("hints", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC) = 5
> fchdir(5) = 0
> getdents64(5, /* 5 entries */, 32768) = 192
> getdents64(5, /* 0 entries */, 32768) = 0
> close(5) = 0
> fstatat64(AT_FDCWD, "ttf-droid.hints", {st_mode=S_IFREG|0644, st_size=2819,
> ...}, AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "ttf-mscorefonts-installer.hints",
> {st_mode=S_IFREG|0644, st_size=24745, ...}, AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "ttf-unfonts-core.hints", {st_mode=S_IFREG|0644,
> st_size=1260, ...}, AT_SYMLINK_NOFOLLOW) = 0
> open("..", O_RDONLY|O_NOCTTY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY|O_NOFOLLOW)
> = 5
> fstat64(5, {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
> fchdir(5) = 0
> close(5) = 0
> fstatat64(AT_FDCWD, "ps-cset-enc.data", {st_mode=S_IFREG|0644, st_size=3983,
> ...}, AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "loc-cset.data", {st_mode=S_IFREG|0644, st_size=1261,
> ...}, AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "fontconfig.subst-rule", {st_mode=S_IFREG|0644,
> st_size=1015, ...}, AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "xenc-cset.data", {st_mode=S_IFREG|0644, st_size=530,
> ...}, AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "csetenc-xenc.data2", {st_mode=S_IFREG|0644,
> st_size=580, ...}, AT_SYMLINK_NOFOLLOW) = 0
> open("..", O_RDONLY|O_NOCTTY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY|O_NOFOLLOW)
> = 5
> fstat64(5, {st_mode=S_IFDIR|0755, st_size=12288, ...}) = 0
> fchdir(5) = 0
> close(5) = 0
> fstatat64(AT_FDCWD, "environment", {st_mode=S_IFREG|0644, st_size=79, ...},
> AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "gnome-vfs-2.0", {st_mode=S_IFDIR|0755, st_size=4096,
> ...}, AT_SYMLINK_NOFOLLOW) = 0
> open("gnome-vfs-2.0", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC)
> = 5
> fchdir(5) = 0
> getdents64(5, /* 3 entries */, 32768) = 80
> getdents64(5, /* 0 entries */, 32768) = 0
> close(5) = 0
> fstatat64(AT_FDCWD, "modules", {st_mode=S_IFDIR|0755, st_size=4096, ...},
> AT_SYMLINK_NOFOLLOW) = 0
> open("modules", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC) = 5
> fchdir(5) = 0
> getdents64(5, /* 4 entries */, 32768) = 128
> getdents64(5, /* 0 entries */, 32768) = 0
> close(5) = 0
> fstatat64(AT_FDCWD, "extra-modules.conf", {st_mode=S_IFREG|0644,
> st_size=225, ...}, AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "default-modules.conf", {st_mode=S_IFREG|0644,
> st_size=300, ...}, AT_SYMLINK_NOFOLLOW) = 0
> open("..", O_RDONLY|O_NOCTTY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY|O_NOFOLLOW)
> = 5
> fstat64(5, {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
> fchdir(5) = 0
> close(5) = 0
> open("..", O_RDONLY|O_NOCTTY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY|O_NOFOLLOW)
> = 5
> fstat64(5, {st_mode=S_IFDIR|0755, st_size=12288, ...}) = 0
> fchdir(5) = 0
> close(5) = 0
> fstatat64(AT_FDCWD, "gshadow", {st_mode=S_IFREG|0640, st_size=974, ...},
> AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "manpath.config", {st_mode=S_IFREG|0644, st_size=5173,
> ...}, AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "brltty", {st_mode=S_IFDIR|0755, st_size=12288, ...},
> AT_SYMLINK_NOFOLLOW) = 0
> open("brltty", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC) = 5
> fchdir(5) = 0
> getdents64(5, /* 265 entries */, 32768) = 9720
> brk(0x975a000) = 0x975a000
> getdents64(5, /* 0 entries */, 32768) = 0
> close(5) = 0
> fstatat64(AT_FDCWD, "kbd-keypad.ktb", {st_mode=S_IFREG|0644, st_size=2944,
> ...}, AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "letters-latin-dot8.tti", {st_mode=S_IFREG|0644,
> st_size=3793, ...}, AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "brltty-vr-all.hlp", {st_mode=S_IFREG|0644, st_size=69,
> ...}, AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "mt.ttb", {st_mode=S_IFREG|0644, st_size=2203, ...},
> AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "brl-pm-front9.kti", {st_mode=S_IFREG|0644,
> st_size=1777, ...}, AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "brl-pm-status4.kti", {st_mode=S_IFREG|0644,
> st_size=1160, ...}, AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "kbd-braille.kti", {st_mode=S_IFREG|0644, st_size=1913,
> ...}, AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "sv.ttb", {st_mode=S_IFREG|0644, st_size=838, ...},
> AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "gujarati.tti", {st_mode=S_IFREG|0644, st_size=5279,
> ...}, AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "tamil.tti", {st_mode=S_IFREG|0644, st_size=4356, ...},
> AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "brltty-ec-all.hlp", {st_mode=S_IFREG|0644, st_size=866,
> ...}, AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "sw.ttb", {st_mode=S_IFREG|0644, st_size=1262, ...},
> AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "brl-bm-display6.kti", {st_mode=S_IFREG|0644,
> st_size=2887, ...}, AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "brl-pm-elba_trio_20.ktb", {st_mode=S_IFREG|0644,
> st_size=872, ...}, AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "sa.ttb", {st_mode=S_IFREG|0644, st_size=886, ...},
> AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "brl-pm-el80_ii.ktb", {st_mode=S_IFREG|0644,
> st_size=865, ...}, AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "brl-pm-routing.kti", {st_mode=S_IFREG|0644,
> st_size=969, ...}, AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "fr-2007.ttb", {st_mode=S_IFREG|0644, st_size=12529,
> ...}, AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "ny.ctb", {st_mode=S_IFREG|0644, st_size=1269, ...},
> AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "fr-cbifs.ttb", {st_mode=S_IFREG|0644, st_size=11267,
> ...}, AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "en_CA.ttb", {st_mode=S_IFREG|0644, st_size=6653, ...},
> AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "brltty-ts-pb40.hlp", {st_mode=S_IFREG|0644,
> st_size=3313, ...}, AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "brl-al-abt_small.ktb", {st_mode=S_IFREG|0644,
> st_size=880, ...}, AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "brl-hm-sync.ktb", {st_mode=S_IFREG|0644, st_size=1679,
> ...}, AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "bengali.tti", {st_mode=S_IFREG|0644, st_size=4857,
> ...}, AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "brl-ht-bs80.ktb", {st_mode=S_IFREG|0644, st_size=868,
> ...}, AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "bo.ttb", {st_mode=S_IFREG|0644, st_size=4629, ...},
> AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "fr_CA.ttb", {st_mode=S_IFREG|0644, st_size=11512, ...},
> AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "sat.ttb", {st_mode=S_IFREG|0644, st_size=923, ...},
> AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "te.ttb", {st_mode=S_IFREG|0644, st_size=880, ...},
> AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "brl-pm-bar.kti", {st_mode=S_IFREG|0644, st_size=1189,
> ...}, AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "brltty-mn-all.hlp", {st_mode=S_IFREG|0644,
> st_size=2074, ...}, AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "dra.ttb", {st_mode=S_IFREG|0644, st_size=882, ...},
> AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "brl-sk-all.ktb", {st_mode=S_IFREG|0644, st_size=2698,
> ...}, AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "ja.ctb", {st_mode=S_IFREG|0644, st_size=8450, ...},
> AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "brl-pm-elba_trio_32.ktb", {st_mode=S_IFREG|0644,
> st_size=872, ...}, AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "letters-latin.tti", {st_mode=S_IFREG|0644,
> st_size=3752, ...}, AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "fr.ttb", {st_mode=S_IFREG|0644, st_size=837, ...},
> AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "brl-bm-display7.kti", {st_mode=S_IFREG|0644,
> st_size=2215, ...}, AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "fr-integral.ctb", {st_mode=S_IFREG|0644, st_size=3843,
> ...}, AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "pl.ttb", {st_mode=S_IFREG|0644, st_size=11576, ...},
> AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "sd.ttb", {st_mode=S_IFREG|0644, st_size=884, ...},
> AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "de.ttb", {st_mode=S_IFREG|0644, st_size=11217, ...},
> AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "kha.ttb", {st_mode=S_IFREG|0644, st_size=880, ...},
> AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "brl-ht-me88.ktb", {st_mode=S_IFREG|0644, st_size=873,
> ...}, AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "de-vollschrift.ctb", {st_mode=S_IFREG|0644,
> st_size=3289, ...}, AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "zu.ctb", {st_mode=S_IFREG|0644, st_size=1233, ...},
> AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "gd.ttb", {st_mode=S_IFREG|0644, st_size=3435, ...},
> AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "numbers-nemeth.tti", {st_mode=S_IFREG|0644,
> st_size=1486, ...}, AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "brl-bm-vertical.kti", {st_mode=S_IFREG|0644,
> st_size=916, ...}, AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "brl-al-abt_large.ktb", {st_mode=S_IFREG|0644,
> st_size=926, ...}, AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "brl-pm-status20.kti", {st_mode=S_IFREG|0644,
> st_size=2610, ...}, AT_SYMLINK_NOFOLLOW) = 0
> fstatat64(AT_FDCWD, "brl-pm-status0.kti", {st_mode=S_IFREG|0644,
> st_size=862, ...}, AT_SYMLINK_NOFOLLOW) = 0
>
>
> 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() .
Hmm...actually I think it shouldn't need to do a if all you are trying
to do is to find a file by inode number. It can be done just by using
directory entries and doing a match of the name. The only reason I can
think of doing a stat is to check if some entry is of directory type
so that it can descend down.
but then I tried "strace find . -maxdepth 1 -inum 5" to limit the
descend only to current directory, but unfortunately find still calls
stat :-(, don't know why.
--
Thanks -
Manish
More information about the Kernelnewbies
mailing list