* Getting file type from inode of fd
@ 2016-07-25 3:19 Peter Chen
2016-08-05 11:19 ` Jan Kara
0 siblings, 1 reply; 2+ messages in thread
From: Peter Chen @ 2016-07-25 3:19 UTC (permalink / raw)
To: linux-fsdevel
Hi,
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?
Peter
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Getting file type from inode of fd
2016-07-25 3:19 Getting file type from inode of fd Peter Chen
@ 2016-08-05 11:19 ` Jan Kara
0 siblings, 0 replies; 2+ messages in thread
From: Jan Kara @ 2016-08-05 11:19 UTC (permalink / raw)
To: Peter Chen; +Cc: linux-fsdevel
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-08-05 11:33 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-25 3:19 Getting file type from inode of fd Peter Chen
2016-08-05 11:19 ` Jan Kara
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).