NTFS_LOOKUP

Section: (9)
Updated: 09 October 2005
Index Return to Main Contents

 

NAME

ntfs_lookup - find the inode represented by a dentry in a directory inode  

SYNOPSIS

"SYNOPSIS"

struct dentry * ntfs_lookup (struct inode * dir_ino, struct dentry * dent, struct nameidata * nd);  

ARGUMENTS

dir_ino
directory inode in which to look for the inode
dent
dentry representing the inode to look for
nd
lookup nameidata
 

DESCRIPTION

In short, ntfs_lookup looks for the inode represented by the dentry dent in the directory inode dir_ino and if found attaches the inode to the dentry dent.

In more detail, the dentry dent specifies which inode to look for by supplying the name of the inode in dent->d_name.name. ntfs_lookup converts the name to Unicode and walks the contents of the directory inode dir_ino looking for the converted Unicode name. If the name is found in the directory, the corresponding inode is loaded by calling ntfs_iget on its inode number and the inode is associated with the dentry dent via a call to d_splice_alias.

If the name is not found in the directory, a NULL inode is inserted into the dentry dent via a call to d_add. The dentry is then termed a negative dentry.

Only if an actual error occurs, do we return an error via ERR_PTR.

In order to handle the case insensitivity issues of NTFS with regards to the dcache and the dcache requiring only one dentry per directory, we deal with dentry aliases that only differ in case in ->ntfs_lookup while maintaining a case sensitive dcache. This means that we get the full benefit of dcache speed when the file/directory is looked up with the same case as returned by ->ntfs_readdir but that a lookup for any other case (or for the short file name) will not find anything in dcache and will enter ->ntfs_lookup instead, where we search the directory for a fully matching file name (including case) and if that is not found, we search for a file name that matches with different case and if that has non-POSIX semantics we return that. We actually do only one search (case sensitive) and keep tabs on whether we have found a case insensitive match in the process.

To simplify matters for us, we do not treat the short vs long filenames as two hard links but instead if the lookup matches a short filename, we return the dentry for the corresponding long filename instead.  

THERE ARE THREE CASES WE NEED TO DISTINGUISH HERE

1) dent perfectly matches (i.e. including case) a directory entry with a file name in the WIN32 or POSIX namespaces. In this case ntfs_lookup_inode_by_name will return with name set to NULL and we just d_splice_alias dent. 2) dent matches (not including case) a directory entry with a file name in the WIN32 namespace. In this case ntfs_lookup_inode_by_name will return with name set to point to a kmalloced ntfs_name structure containing the properly cased little endian Unicode name. We convert the name to the current NLS code page, search if a dentry with this name already exists and if so return that instead of dent. At this point things are complicated by the possibility of 'disconnected' dentries due to NFS which we deal with appropriately (see the code comments). The VFS will then destroy the old dent and use the one we returned. If a dentry is not found, we allocate a new one, d_splice_alias it, and return it as above. 3) dent matches either perfectly or not (i.e. we don't care about case) a directory entry with a file name in the DOS namespace. In this case ntfs_lookup_inode_by_name will return with name set to point to a kmalloced ntfs_name structure containing the mft reference (cpu endian) of the inode. We use the mft reference to read the inode and to find the file name in the WIN32 namespace corresponding to the matched short file name. We then convert the name to the current NLS code page, and proceed searching for a dentry with this name, etc, as in case 2), above.  

LOCKING

Caller must hold i_sem on the directory.


 

Index

NAME
SYNOPSIS
ARGUMENTS
DESCRIPTION
THERE ARE THREE CASES WE NEED TO DISTINGUISH HERE
LOCKING

This document was created by man2html, using the manual pages.
Time: 00:02:34 GMT, October 09, 2005