How to check in linux kernel at vfs layer whether the file object is for a directory or a file

烂漫一生 提交于 2019-12-12 04:05:14

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!