Re: Getting file type from inode of fd

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxx>
SUSE Labs, CR
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [Samba]     [Device Mapper]     [CEPH Development]
  Powered by Linux