linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Peter Chen <peter.feifan.chen@gmail.com>
Cc: linux-fsdevel@vger.kernel.org
Subject: Re: Getting file type from inode of fd
Date: Fri, 5 Aug 2016 13:19:12 +0200	[thread overview]
Message-ID: <20160805111912.GB18566@quack2.suse.cz> (raw)
In-Reply-To: <CAMGYKAd3+cNbF66zjwUWRMzVSDNBP83H7wgsBMMJf3KoZmX5vg@mail.gmail.com>

Hi,

On Sun 24-07-16 20:19:59, Peter Chen wrote:
>   I was wondering, how I can tell a file is a regular file ("-" when
> you run ls -l) or a socket ("s" when you run ls -l). I think I can use
> sockfd_lookup on the fd to check if a fd points to a socket (NULL if
> it doesn't).
> 
>    But I see these macros in stat.h (S_ISREG, S_ISSOCK) that takes an
> inode's umode and returns true if the inode is a specific file type.
> But I was wondering, if I use fget() to get the file of a fd, can I
> get the inode from the file from f_inode? I see the comment says it is
> a cached value. So what would go wrong if I went something like
> S_ISREG(file->f_inode) or is this the correct way to do this?

You can use file_inode() helper and then S_ISREG() function to test file
type. That is certainly going to work.

								Honza
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

      reply	other threads:[~2016-08-05 11:33 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-25  3:19 Getting file type from inode of fd Peter Chen
2016-08-05 11:19 ` Jan Kara [this message]

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=20160805111912.GB18566@quack2.suse.cz \
    --to=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=peter.feifan.chen@gmail.com \
    /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).