kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
From: greg.freemyer@gmail.com (Greg Freemyer)
To: kernelnewbies@lists.kernelnewbies.org
Subject: inode query
Date: Tue, 5 Apr 2011 17:38:12 -0400	[thread overview]
Message-ID: <BANLkTi=aK7W87ONesp04PgsjdLVSrky7uw@mail.gmail.com> (raw)
In-Reply-To: <BANLkTi=+WTH=YxT7Ebm-jtzPop70XX1E3g@mail.gmail.com>

On Tue, Apr 5, 2011 at 4:41 PM, mohit verma <mohit89mlnc@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

  reply	other threads:[~2011-04-05 21:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-05 20:41 inode query mohit verma
2011-04-05 21:38 ` Greg Freemyer [this message]
2011-04-07 21:30   ` Greg Freemyer
2011-04-08  6:54   ` mohit verma
2011-04-08  7:04     ` Manish Katiyar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='BANLkTi=aK7W87ONesp04PgsjdLVSrky7uw@mail.gmail.com' \
    --to=greg.freemyer@gmail.com \
    --cc=kernelnewbies@lists.kernelnewbies.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).