Vfs_getattr and apivfs_getattr of Kernel File System APIs
Vfs_getattr for Kernel File System APIs
Int vfs_getattr (const struct path * path, struct kstat * stat, u32 request_mask, unsigned int query_flags) is used to obtain the file's enhanced basic attributes, that is, the basic extended attributes. The source code analysis is shown: int vfs_getattr (const struct path * path, struct kstat * stat, u32 request_mask, unsigned int query_flags) {int retval; # perform security checks on the files indicated by path, for example, selinuxretval = security_inode_getattr (path); if (retval) return retval; # security check has been performed before. Therefore, the basic extension attribute return vfs_getattr_nosec (path, stat, request_mask, query_flags);} int vfs_getattr_nosec (const struct path * path, struct kstat * stat, u32 request_mask, unsigned int query_flags) {# obtain the path that indicates the inodestruct inode * inode = d_backing_inode (path-> dentry) of the file; # Clear stat, because stat will save the extension and return it to the user memset (stat, 0, sizeof (* stat); stat-> result_mask | = STATX_BASIC_STATS; request_mask & = STATX_ALL; query_flags & = KSTAT_QUERY_FLAGS; # The extension attributes of the file can be saved to inode, then, the function provided by inode is returned to the user if (inode-> I _op-> getattr) return inode-> I _op-> getattr (path, stat, request_mask, query_flags ); # If inode is not saved, call the common functions provided by the file system to obtain the extension attribute generic_fillattr (inode, stat); return 0;} of the file ;}