Merge with /pub/scm/linux/kernel/git/torvalds/linux-2.6.git
[sfrench/cifs-2.6.git] / fs / cifs / readdir.c
index a86bd1c076021bb88bec0da95a4d939b0785d69d..2f6e2825571ec22f630f77981d3fe9a174418a2c 100644 (file)
@@ -142,6 +142,11 @@ static void fill_in_inode(struct inode *tmp_inode,
                tmp_inode->i_gid = cifs_sb->mnt_gid;
                /* set default mode. will override for dirs below */
                tmp_inode->i_mode = cifs_sb->mnt_file_mode;
+       } else {
+               /* mask off the type bits since it gets set
+               below and we do not want to get two type
+               bits set */
+               tmp_inode->i_mode &= ~S_IFMT;
        }
 
        if (attr & ATTR_DIRECTORY) {
@@ -152,12 +157,18 @@ static void fill_in_inode(struct inode *tmp_inode,
                }
                tmp_inode->i_mode |= S_IFDIR;
        } else if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL) && 
-                  (attr & ATTR_SYSTEM) && (end_of_file == 0)) {
-               *pobject_type = DT_FIFO;
-               tmp_inode->i_mode |= S_IFIFO;
-/* BB Finish for SFU style symlinks and devies */
-/*     } else if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL) &&
-               (attr & ATTR_SYSTEM) && ) { */
+                  (attr & ATTR_SYSTEM)) {
+               if (end_of_file == 0)  {
+                       *pobject_type = DT_FIFO;
+                       tmp_inode->i_mode |= S_IFIFO;
+               } else {
+                       /* rather than get the type here, we mark the
+                       inode as needing revalidate and get the real type
+                       (blk vs chr vs. symlink) later ie in lookup */
+                       *pobject_type = DT_REG;
+                       tmp_inode->i_mode |= S_IFREG; 
+                       cifsInfo->time = 0;     
+               }
 /* we no longer mark these because we could not follow them */
 /*        } else if (attr & ATTR_REPARSE) {
                 *pobject_type = DT_LNK;
@@ -186,19 +197,24 @@ static void fill_in_inode(struct inode *tmp_inode,
 
        if (allocation_size < end_of_file)
                cFYI(1, ("May be sparse file, allocation less than file size"));
-       cFYI(1,
-            ("File Size %ld and blocks %ld and blocksize %ld",
-             (unsigned long)tmp_inode->i_size, tmp_inode->i_blocks,
-             tmp_inode->i_blksize));
+       cFYI(1, ("File Size %ld and blocks %llu and blocksize %ld",
+               (unsigned long)tmp_inode->i_size,
+               (unsigned long long)tmp_inode->i_blocks,
+               tmp_inode->i_blksize));
        if (S_ISREG(tmp_inode->i_mode)) {
                cFYI(1, ("File inode"));
                tmp_inode->i_op = &cifs_file_inode_ops;
-               if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DIRECT_IO)
-                       tmp_inode->i_fop = &cifs_file_direct_ops;
+               if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DIRECT_IO) {
+                       if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
+                               tmp_inode->i_fop = &cifs_file_direct_nobrl_ops;
+                       else
+                               tmp_inode->i_fop = &cifs_file_direct_ops;
+               
+               } else if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
+                       tmp_inode->i_fop = &cifs_file_nobrl_ops;
                else
                        tmp_inode->i_fop = &cifs_file_ops;
-               if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
-                       tmp_inode->i_fop->lock = NULL;
+
                tmp_inode->i_data.a_ops = &cifs_addr_ops;
                if((cifs_sb->tcon) && (cifs_sb->tcon->ses) &&
                   (cifs_sb->tcon->ses->server->maxBuf <
@@ -258,6 +274,9 @@ static void unix_fill_in_inode(struct inode *tmp_inode,
            cifs_NTtimeToUnix(le64_to_cpu(pfindData->LastStatusChange));
 
        tmp_inode->i_mode = le64_to_cpu(pfindData->Permissions);
+       /* since we set the inode type below we need to mask off type
+           to avoid strange results if bits above were corrupt */
+        tmp_inode->i_mode &= ~S_IFMT;
        if (type == UNIX_FILE) {
                *pobject_type = DT_REG;
                tmp_inode->i_mode |= S_IFREG;
@@ -283,6 +302,11 @@ static void unix_fill_in_inode(struct inode *tmp_inode,
        } else if (type == UNIX_SOCKET) {
                *pobject_type = DT_SOCK;
                tmp_inode->i_mode |= S_IFSOCK;
+       } else {
+               /* safest to just call it a file */
+               *pobject_type = DT_REG;
+               tmp_inode->i_mode |= S_IFREG;
+               cFYI(1,("unknown inode type %d",type)); 
        }
 
        tmp_inode->i_uid = le64_to_cpu(pfindData->Uid);
@@ -302,12 +326,18 @@ static void unix_fill_in_inode(struct inode *tmp_inode,
        if (S_ISREG(tmp_inode->i_mode)) {
                cFYI(1, ("File inode"));
                tmp_inode->i_op = &cifs_file_inode_ops;
-               if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DIRECT_IO)
-                       tmp_inode->i_fop = &cifs_file_direct_ops;
+
+               if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DIRECT_IO) {
+                       if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
+                               tmp_inode->i_fop = &cifs_file_direct_nobrl_ops;
+                       else
+                               tmp_inode->i_fop = &cifs_file_direct_ops;
+               
+               } else if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
+                       tmp_inode->i_fop = &cifs_file_nobrl_ops;
                else
                        tmp_inode->i_fop = &cifs_file_ops;
-               if(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
-                       tmp_inode->i_fop->lock = NULL;
+
                tmp_inode->i_data.a_ops = &cifs_addr_ops;
                if((cifs_sb->tcon) && (cifs_sb->tcon->ses) &&
                   (cifs_sb->tcon->ses->server->maxBuf < 
@@ -374,9 +404,9 @@ static int initiate_cifs_search(const int xid, struct file *file)
        if(pTcon == NULL)
                return -EINVAL;
 
-       down(&file->f_dentry->d_sb->s_vfs_rename_sem);
+       mutex_lock(&file->f_dentry->d_sb->s_vfs_rename_mutex);
        full_path = build_path_from_dentry(file->f_dentry);
-       up(&file->f_dentry->d_sb->s_vfs_rename_sem);
+       mutex_unlock(&file->f_dentry->d_sb->s_vfs_rename_mutex);
 
        if(full_path == NULL) {
                return -ENOMEM;
@@ -574,7 +604,12 @@ static int find_cifs_entry(const int xid, struct cifsTconInfo *pTcon,
                cifsFile->search_resume_name = NULL;
                if(cifsFile->srch_inf.ntwrk_buf_start) {
                        cFYI(1,("freeing SMB ff cache buf on search rewind"));
-                       cifs_buf_release(cifsFile->srch_inf.ntwrk_buf_start);
+                       if(cifsFile->srch_inf.smallBuf)
+                               cifs_small_buf_release(cifsFile->srch_inf.
+                                               ntwrk_buf_start);
+                       else
+                               cifs_buf_release(cifsFile->srch_inf.
+                                               ntwrk_buf_start);
                }
                rc = initiate_cifs_search(xid,file);
                if(rc) {
@@ -699,7 +734,7 @@ static int cifs_get_name_from_search_buf(struct qstr *pqst,
                                        (__le16 *)filename, len/2, nlt);
                else
                        pqst->len = cifs_strfromUCS_le((char *)pqst->name,
-                                       (wchar_t *)filename,len/2,nlt);
+                                       (__le16 *)filename,len/2,nlt);
        } else {
                pqst->name = filename;
                pqst->len = len;