问题
How to check in linux kernel at vfs layer whether the file object is for a directory or a file?
I have found that there is a function called is_dx(dir)
which checks for this but it is present in namei.c
in ext3
or ext4
. I need to do this at vfs layer that is independent of the file system.
回答1:
Having in hand the inode of the initial directory, the code
examines the entry matching the first name to get the
corresponding inode.
q Then the directory file having that node is read from disk and
the entry matching the second name is examined to derive the
corresponding inode.
q This procedure is repeated for each name included in the path.
The dentry cache considerably speeds up the procedure
File system operations are mostly done at the dcache level , so
they are all under kernel lock.
回答2:
How about the S_ISDIR()
macro defined in include/linux/stat.h
? It takesinode->i_mode
field to check if the inode in question belongs to a directory or a file.
来源:https://stackoverflow.com/questions/10168966/how-to-check-in-linux-kernel-at-vfs-layer-whether-the-file-object-is-for-a-direc