]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commitdiff
Merge git://git.kernel.org/pub/scm/linux/kernel/git/sfrench/cifs-2.6
authorLinus Torvalds <torvalds@woody.linux-foundation.org>
Fri, 19 Oct 2007 19:00:58 +0000 (12:00 -0700)
committerLinus Torvalds <torvalds@woody.linux-foundation.org>
Fri, 19 Oct 2007 19:00:58 +0000 (12:00 -0700)
* git://git.kernel.org/pub/scm/linux/kernel/git/sfrench/cifs-2.6: (51 commits)
  [CIFS] log better errors on failed mounts
  [CIFS] Return better error when server requires signing but client forbids
  [CIFS] fix typo
  [CIFS] acl support part 4
  [CIFS] Fix minor problems noticed by scan
  [CIFS] fix bad handling of EAGAIN error on kernel_recvmsg in cifs_demultiplex_thread
  [CIFS] build break
  [CIFS] endian fixes
  [CIFS] endian fixes in new acl code
  [CIFS] Fix some endianness problems in new acl code
  [CIFS] missing #endif from a previous patch
  [CIFS] formatting fixes
  [CIFS] Break up unicode_sessetup string functions
  [CIFS] parse server_GUID in SPNEGO negProt response
  [CIFS]
  [CIFS] Fix endian conversion problem in posix mkdir
  [CIFS] fix build break when lanman not enabled
  [CIFS] remove two sparse warnings
  [CIFS] remove compile warnings when debug disabled
  [CIFS] CIFS ACL support part 3
  ...

1  2 
fs/cifs/cifsfs.c
fs/cifs/connect.c
fs/cifs/inode.c

diff --combined fs/cifs/cifsfs.c
index ba8f7868cb23c84a5e713910f7b7d5a72bfc6f8a,91ba32861c883cb14d65c082ab4abe7d7d09325a..a6fbea57c4b1e6d895375ed10e8ef636995d763e
  static struct quotactl_ops cifs_quotactl_ops;
  #endif /* QUOTA */
  
- #ifdef CONFIG_CIFS_EXPERIMENTAL
- extern struct export_operations cifs_export_ops;
- #endif /* EXPERIMENTAL */
  int cifsFYI = 0;
  int cifsERROR = 1;
  int traceSMB = 0;
@@@ -240,9 -236,9 +236,9 @@@ static int cifs_permission(struct inod
  
        cifs_sb = CIFS_SB(inode->i_sb);
  
-       if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM) {
+       if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM)
                return 0;
-       else /* file mode might have been restricted at mount time
+       else /* file mode might have been restricted at mount time
                on the client (above and beyond ACL on servers) for
                servers which do not support setting and viewing mode bits,
                so allowing client to check permissions is useful */
@@@ -312,15 -308,15 +308,15 @@@ cifs_show_options(struct seq_file *s, s
                                        seq_printf(s, ",domain=%s",
                                           cifs_sb->tcon->ses->domainName);
                        }
+                       if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_UID) ||
+                          !(cifs_sb->tcon->unix_ext))
+                               seq_printf(s, ",uid=%d", cifs_sb->mnt_uid);
+                       if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_GID) ||
+                          !(cifs_sb->tcon->unix_ext))
+                               seq_printf(s, ",gid=%d", cifs_sb->mnt_gid);
                }
                if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS)
                        seq_printf(s, ",posixpaths");
-               if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_UID) ||
-                  !(cifs_sb->tcon->unix_ext))
-                       seq_printf(s, ",uid=%d", cifs_sb->mnt_uid);
-               if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_GID) ||
-                  !(cifs_sb->tcon->unix_ext))
-                       seq_printf(s, ",gid=%d", cifs_sb->mnt_gid);
                seq_printf(s, ",rsize=%d", cifs_sb->rsize);
                seq_printf(s, ",wsize=%d", cifs_sb->wsize);
        }
@@@ -346,7 -342,7 +342,7 @@@ int cifs_xquota_set(struct super_block 
        if (pTcon) {
                cFYI(1, ("set type: 0x%x id: %d", quota_type, qid));
        } else {
-               return -EIO;
+               rc = -EIO;
        }
  
        FreeXid(xid);
@@@ -704,7 -700,7 +700,7 @@@ const struct file_operations cifs_dir_o
  };
  
  static void
 -cifs_init_once(void *inode, struct kmem_cache *cachep, unsigned long flags)
 +cifs_init_once(struct kmem_cache *cachep, void *inode)
  {
        struct cifsInodeInfo *cifsi = inode;
  
@@@ -716,7 -712,7 +712,7 @@@ static in
  cifs_init_inodecache(void)
  {
        cifs_inode_cachep = kmem_cache_create("cifs_inode_cache",
-                                             sizeof (struct cifsInodeInfo),
+                                             sizeof(struct cifsInodeInfo),
                                              0, (SLAB_RECLAIM_ACCOUNT|
                                                SLAB_MEM_SPREAD),
                                              cifs_init_once);
@@@ -816,8 -812,8 +812,8 @@@ static in
  cifs_init_mids(void)
  {
        cifs_mid_cachep = kmem_cache_create("cifs_mpx_ids",
-                               sizeof (struct mid_q_entry), 0,
-                               SLAB_HWCACHE_ALIGN, NULL);
+                                           sizeof(struct mid_q_entry), 0,
+                                           SLAB_HWCACHE_ALIGN, NULL);
        if (cifs_mid_cachep == NULL)
                return -ENOMEM;
  
        }
  
        cifs_oplock_cachep = kmem_cache_create("cifs_oplock_structs",
-                               sizeof (struct oplock_q_entry), 0,
-                               SLAB_HWCACHE_ALIGN, NULL);
+                                       sizeof(struct oplock_q_entry), 0,
+                                       SLAB_HWCACHE_ALIGN, NULL);
        if (cifs_oplock_cachep == NULL) {
                mempool_destroy(cifs_mid_poolp);
                kmem_cache_destroy(cifs_mid_cachep);
@@@ -882,7 -878,8 +878,8 @@@ static int cifs_oplock_thread(void *dum
                                the call */
                                /* mutex_lock(&inode->i_mutex);*/
                                if (S_ISREG(inode->i_mode)) {
-                                       rc = filemap_fdatawrite(inode->i_mapping);
+                                       rc =
+                                          filemap_fdatawrite(inode->i_mapping);
                                        if (CIFS_I(inode)->clientCanCacheRead
                                                                         == 0) {
                                                filemap_fdatawait(inode->i_mapping);
                                            0 /* len */ , 0 /* offset */, 0,
                                            0, LOCKING_ANDX_OPLOCK_RELEASE,
                                            0 /* wait flag */);
-                                       cFYI(1, 
-                                             ("Oplock release rc = %d ", rc));
+                                       cFYI(1, ("Oplock release rc = %d", rc));
                                }
                        } else
                                spin_unlock(&GlobalMid_Lock);
diff --combined fs/cifs/connect.c
index 370866cb3d482c5d061a065a026a0eb0197173c2,676bbf2bb56d8efc305afd7a1ca139cafcf85f0a..19ee11f7f35ad6188207d25edccb0af3b8cdad11
@@@ -124,7 -124,7 +124,7 @@@ cifs_reconnect(struct TCP_Server_Info *
        struct mid_q_entry *mid_entry;
  
        spin_lock(&GlobalMid_Lock);
-       if ( kthread_should_stop() ) {
+       if (kthread_should_stop()) {
                /* the demux thread will exit normally
                next time through the loop */
                spin_unlock(&GlobalMid_Lock);
        }
        list_for_each(tmp, &GlobalTreeConnectionList) {
                tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList);
-               if ((tcon) && (tcon->ses) && (tcon->ses->server == server)) {
+               if ((tcon) && (tcon->ses) && (tcon->ses->server == server))
                        tcon->tidStatus = CifsNeedReconnect;
-               }
        }
        read_unlock(&GlobalSMBSeslock);
        /* do not want to be sending data on a socket we are freeing */
        spin_unlock(&GlobalMid_Lock);
        up(&server->tcpSem);
  
-       while ( (!kthread_should_stop()) && (server->tcpStatus != CifsGood)) {
+       while ((!kthread_should_stop()) && (server->tcpStatus != CifsGood)) {
                try_to_freeze();
                if (server->protocolType == IPV6) {
                        rc = ipv6_connect(&server->addr.sockAddr6,
                } else {
                        atomic_inc(&tcpSesReconnectCount);
                        spin_lock(&GlobalMid_Lock);
-                       if ( !kthread_should_stop() )
+                       if (!kthread_should_stop())
                                server->tcpStatus = CifsGood;
                        server->sequence_number = 0;
                        spin_unlock(&GlobalMid_Lock);
@@@ -352,17 -351,15 +351,15 @@@ cifs_demultiplex_thread(struct TCP_Serv
  
        current->flags |= PF_MEMALLOC;
        server->tsk = current;  /* save process info to wake at shutdown */
 -      cFYI(1, ("Demultiplex PID: %d", current->pid));
 +      cFYI(1, ("Demultiplex PID: %d", task_pid_nr(current)));
        write_lock(&GlobalSMBSeslock);
        atomic_inc(&tcpSesAllocCount);
        length = tcpSesAllocCount.counter;
        write_unlock(&GlobalSMBSeslock);
        complete(&cifsd_complete);
-       if (length  > 1) {
-               mempool_resize(cifs_req_poolp,
-                       length + cifs_min_rcv,
-                       GFP_KERNEL);
-       }
+       if (length  > 1)
+               mempool_resize(cifs_req_poolp, length + cifs_min_rcv,
+                               GFP_KERNEL);
  
        set_freezable();
        while (!kthread_should_stop()) {
                        }
                } else if (isLargeBuf) {
                        /* we are reusing a dirty large buf, clear its start */
-                       memset(bigbuf, 0, sizeof (struct smb_hdr));
+                       memset(bigbuf, 0, sizeof(struct smb_hdr));
                }
  
                if (smallbuf == NULL) {
                        }
                        /* beginning of smb buffer is cleared in our buf_get */
                } else /* if existing small buf clear beginning */
-                       memset(smallbuf, 0, sizeof (struct smb_hdr));
+                       memset(smallbuf, 0, sizeof(struct smb_hdr));
  
                isLargeBuf = FALSE;
                isMultiRsp = FALSE;
                iov.iov_len = 4;
                smb_msg.msg_control = NULL;
                smb_msg.msg_controllen = 0;
+               pdu_length = 4; /* enough to get RFC1001 header */
+ incomplete_rcv:
                length =
                    kernel_recvmsg(csocket, &smb_msg,
-                                &iov, 1, 4, 0 /* BB see socket.h flags */);
+                               &iov, 1, pdu_length, 0 /* BB other flags? */);
  
-               if ( kthread_should_stop() ) {
+               if (kthread_should_stop()) {
                        break;
                } else if (server->tcpStatus == CifsNeedReconnect) {
                        cFYI(1, ("Reconnect after server stopped responding"));
                        msleep(1); /* minimum sleep to prevent looping
                                allowing socket to clear and app threads to set
                                tcpStatus CifsNeedReconnect if server hung */
-                       continue;
+                       if (pdu_length < 4)
+                               goto incomplete_rcv;
+                       else
+                               continue;
                } else if (length <= 0) {
                        if (server->tcpStatus == CifsNew) {
                                cFYI(1, ("tcp session abend after SMBnegprot"));
                        wake_up(&server->response_q);
                        continue;
                } else if (length < 4) {
-                       cFYI(1,
-                           ("Frame under four bytes received (%d bytes long)",
+                       cFYI(1, ("less than four bytes received (%d bytes)",
                              length));
-                       cifs_reconnect(server);
-                       csocket = server->ssocket;
-                       wake_up(&server->response_q);
-                       continue;
+                       pdu_length -= length;
+                       msleep(1);
+                       goto incomplete_rcv;
                }
  
                /* The right amount was read from socket - 4 bytes */
  
                /* else we have an SMB response */
                if ((pdu_length > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE - 4) ||
-                           (pdu_length < sizeof (struct smb_hdr) - 1 - 4)) {
+                           (pdu_length < sizeof(struct smb_hdr) - 1 - 4)) {
                        cERROR(1, ("Invalid size SMB length %d pdu_length %d",
                                        length, pdu_length+4));
                        cifs_reconnect(server);
                     total_read += length) {
                        length = kernel_recvmsg(csocket, &smb_msg, &iov, 1,
                                                pdu_length - total_read, 0);
-                       if ( kthread_should_stop() ||
+                       if (kthread_should_stop() ||
                            (length == -EINTR)) {
                                /* then will exit */
                                reconnect = 2;
                                              allowing socket to clear and app
                                              threads to set tcpStatus
                                              CifsNeedReconnect if server hung*/
+                               length = 0;
                                continue;
                        } else if (length <= 0) {
                                cERROR(1, ("Received no data, expecting %d",
@@@ -631,9 -632,9 +632,9 @@@ multi_t2_fnd
                        /* Was previous buf put in mpx struct for multi-rsp? */
                        if (!isMultiRsp) {
                                /* smb buffer will be freed by user thread */
-                               if (isLargeBuf) {
+                               if (isLargeBuf)
                                        bigbuf = NULL;
-                               else
+                               else
                                        smallbuf = NULL;
                        }
                        wake_up_process(task_to_wake);
                server->ssocket = NULL;
        }
        /* buffer usuallly freed in free_mid - need to free it here on exit */
-       if (bigbuf != NULL)
-               cifs_buf_release(bigbuf);
-       if (smallbuf != NULL)
+       cifs_buf_release(bigbuf);
+       if (smallbuf) /* no sense logging a debug message if NULL */
                cifs_small_buf_release(smallbuf);
  
        read_lock(&GlobalSMBSeslock);
                list_for_each(tmp, &GlobalSMBSessionList) {
                        ses = list_entry(tmp, struct cifsSesInfo,
                                         cifsSessionList);
-                       if (ses->server == server) {
+                       if (ses->server == server)
                                ses->status = CifsExiting;
-                       }
                }
  
                spin_lock(&GlobalMid_Lock);
                                cFYI(1, ("Clearing Mid 0x%x - waking up ",
                                         mid_entry->mid));
                                task_to_wake = mid_entry->tsk;
-                               if (task_to_wake) {
+                               if (task_to_wake)
                                        wake_up_process(task_to_wake);
-                               }
                        }
                }
                spin_unlock(&GlobalMid_Lock);
        list_for_each(tmp, &GlobalSMBSessionList) {
                ses = list_entry(tmp, struct cifsSesInfo,
                                cifsSessionList);
-               if (ses->server == server) {
+               if (ses->server == server)
                        ses->server = NULL;
-               }
        }
        write_unlock(&GlobalSMBSeslock);
  
        kfree(server);
-       if (length  > 0) {
-               mempool_resize(cifs_req_poolp,
-                       length + cifs_min_rcv,
-                       GFP_KERNEL);
-       }
+       if (length  > 0)
+               mempool_resize(cifs_req_poolp, length + cifs_min_rcv,
+                               GFP_KERNEL);
  
        return 0;
  }
@@@ -1477,7 -1472,7 +1472,7 @@@ ipv4_connect(struct sockaddr_in *psin_s
        if (psin_server->sin_port) { /* user overrode default port */
                rc = (*csocket)->ops->connect(*csocket,
                                (struct sockaddr *) psin_server,
-                               sizeof (struct sockaddr_in), 0);
+                               sizeof(struct sockaddr_in), 0);
                if (rc >= 0)
                        connected = 1;
        }
  
                        rc = (*csocket)->ops->connect(*csocket,
                                        (struct sockaddr *) psin_server,
-                                       sizeof (struct sockaddr_in), 0);
+                                       sizeof(struct sockaddr_in), 0);
                        if (rc >= 0)
                                connected = 1;
                }
                psin_server->sin_port = htons(RFC1001_PORT);
                rc = (*csocket)->ops->connect(*csocket, (struct sockaddr *)
                                              psin_server,
-                                             sizeof (struct sockaddr_in), 0);
+                                             sizeof(struct sockaddr_in), 0);
                if (rc >= 0)
                        connected = 1;
        }
@@@ -1610,7 -1605,7 +1605,7 @@@ ipv6_connect(struct sockaddr_in6 *psin_
        if (psin_server->sin6_port) { /* user overrode default port */
                rc = (*csocket)->ops->connect(*csocket,
                                (struct sockaddr *) psin_server,
-                               sizeof (struct sockaddr_in6), 0);
+                               sizeof(struct sockaddr_in6), 0);
                if (rc >= 0)
                        connected = 1;
        }
  
                        rc = (*csocket)->ops->connect(*csocket,
                                        (struct sockaddr *) psin_server,
-                                       sizeof (struct sockaddr_in6), 0);
+                                       sizeof(struct sockaddr_in6), 0);
                        if (rc >= 0)
                                connected = 1;
                }
        if (!connected) {
                psin_server->sin6_port = htons(RFC1001_PORT);
                rc = (*csocket)->ops->connect(*csocket, (struct sockaddr *)
-                                psin_server, sizeof (struct sockaddr_in6), 0);
+                                psin_server, sizeof(struct sockaddr_in6), 0);
                if (rc >= 0)
                        connected = 1;
        }
@@@ -1750,7 -1745,16 +1745,16 @@@ void reset_cifs_unix_caps(int xid, stru
                        cFYI(1, ("very large write cap"));
  #endif /* CIFS_DEBUG2 */
                if (CIFSSMBSetFSUnixInfo(xid, tcon, cap)) {
-                       cFYI(1, ("setting capabilities failed"));
+                       if (vol_info == NULL) {
+                               cFYI(1, ("resetting capabilities failed"));
+                       } else
+                               cERROR(1, ("Negotiating Unix capabilities "
+                                          "with the server failed.  Consider "
+                                          "mounting with the Unix Extensions\n"
+                                          "disabled, if problems are found, "
+                                          "by specifying the nounix mount "
+                                          "option."));
                }
        }
  }
@@@ -1909,8 -1913,8 +1913,8 @@@ cifs_mount(struct super_block *sb, stru
                        return rc;
                }
  
-               srvTcp = kmalloc(sizeof (struct TCP_Server_Info), GFP_KERNEL);
-               if (srvTcp == NULL) {
+               srvTcp = kzalloc(sizeof(struct TCP_Server_Info), GFP_KERNEL);
+               if (!srvTcp) {
                        rc = -ENOMEM;
                        sock_release(csocket);
                        kfree(volume_info.UNC);
                        FreeXid(xid);
                        return rc;
                } else {
-                       memset(srvTcp, 0, sizeof (struct TCP_Server_Info));
                        memcpy(&srvTcp->addr.sockAddr, &sin_server,
-                               sizeof (struct sockaddr_in));
+                               sizeof(struct sockaddr_in));
                        atomic_set(&srvTcp->inFlight, 0);
                        /* BB Add code for ipv6 case too */
                        srvTcp->ssocket = csocket;
                                                if (tsk)
                                                        kthread_stop(tsk);
                                        }
-                               } else
+                               } else {
                                        cFYI(1, ("No session or bad tcon"));
+                                       if ((pSesInfo->server) &&
+                                           (pSesInfo->server->tsk)) {
+                                               struct task_struct *tsk;
+                                               force_sig(SIGKILL,
+                                                       pSesInfo->server->tsk);
+                                               tsk = pSesInfo->server->tsk;
+                                               if (tsk)
+                                                       kthread_stop(tsk);
+                                       }
+                               }
                                sesInfoFree(pSesInfo);
                                /* pSesInfo = NULL; */
                        }
                tcon->ses = pSesInfo;
  
                /* do not care if following two calls succeed - informational */
-               CIFSSMBQFSDeviceInfo(xid, tcon);
-               CIFSSMBQFSAttributeInfo(xid, tcon);
+               if (!tcon->ipc) {
+                       CIFSSMBQFSDeviceInfo(xid, tcon);
+                       CIFSSMBQFSAttributeInfo(xid, tcon);
+               }
  
                /* tell server which Unix caps we support */
                if (tcon->ses->capabilities & CAP_UNIX)
@@@ -2526,8 -2541,7 +2541,7 @@@ CIFSSessSetup(unsigned int xid, struct 
  sesssetup_nomem:      /* do not return an error on nomem for the info strings,
                           since that could make reconnection harder, and
                           reconnection might be needed to free memory */
-       if (smb_buffer)
-               cifs_buf_release(smb_buffer);
+       cifs_buf_release(smb_buffer);
  
        return rc;
  }
@@@ -2547,7 -2561,7 +2561,7 @@@ CIFSNTLMSSPNegotiateSessSetup(unsigned 
        int remaining_words = 0;
        int bytes_returned = 0;
        int len;
-       int SecurityBlobLength = sizeof (NEGOTIATE_MESSAGE);
+       int SecurityBlobLength = sizeof(NEGOTIATE_MESSAGE);
        PNEGOTIATE_MESSAGE SecurityBlob;
        PCHALLENGE_MESSAGE SecurityBlob2;
        __u32 negotiate_flags, capabilities;
                rc = -EIO;
        }
  
-       if (smb_buffer)
-               cifs_buf_release(smb_buffer);
+       cifs_buf_release(smb_buffer);
  
        return rc;
  }
  static int
  CIFSNTLMSSPAuthSessSetup(unsigned int xid, struct cifsSesInfo *ses,
-               char *ntlm_session_key, int ntlmv2_flag,
-               const struct nls_table *nls_codepage)
+                       char *ntlm_session_key, int ntlmv2_flag,
+                       const struct nls_table *nls_codepage)
  {
        struct smb_hdr *smb_buffer;
        struct smb_hdr *smb_buffer_response;
        int remaining_words = 0;
        int bytes_returned = 0;
        int len;
-       int SecurityBlobLength = sizeof (AUTHENTICATE_MESSAGE);
+       int SecurityBlobLength = sizeof(AUTHENTICATE_MESSAGE);
        PAUTHENTICATE_MESSAGE SecurityBlob;
        __u32 negotiate_flags, capabilities;
        __u16 count;
                return -ENOMEM;
        }
        smb_buffer_response = smb_buffer;
-       pSMB = (SESSION_SETUP_ANDX *) smb_buffer;
-       pSMBr = (SESSION_SETUP_ANDX *) smb_buffer_response;
+       pSMB = (SESSION_SETUP_ANDX *)smb_buffer;
+       pSMBr = (SESSION_SETUP_ANDX *)smb_buffer_response;
  
        /* send SMBsessionSetup here */
        header_assemble(smb_buffer, SMB_COM_SESSION_SETUP_ANDX,
                smb_buffer->Flags2 |= SMBFLG2_SECURITY_SIGNATURE;
  
        capabilities = CAP_LARGE_FILES | CAP_NT_SMBS | CAP_LEVEL_II_OPLOCKS |
-           CAP_EXTENDED_SECURITY;
+                       CAP_EXTENDED_SECURITY;
        if (ses->capabilities & CAP_UNICODE) {
                smb_buffer->Flags2 |= SMBFLG2_UNICODE;
                capabilities |= CAP_UNICODE;
        }
        pSMB->req.Capabilities = cpu_to_le32(capabilities);
  
-       bcc_ptr = (char *) &pSMB->req.SecurityBlob;
-       SecurityBlob = (PAUTHENTICATE_MESSAGE) bcc_ptr;
+       bcc_ptr = (char *)&pSMB->req.SecurityBlob;
+       SecurityBlob = (PAUTHENTICATE_MESSAGE)bcc_ptr;
        strncpy(SecurityBlob->Signature, NTLMSSP_SIGNATURE, 8);
        SecurityBlob->MessageType = NtLmAuthenticate;
        bcc_ptr += SecurityBlobLength;
-       negotiate_flags =
-           NTLMSSP_NEGOTIATE_UNICODE | NTLMSSP_REQUEST_TARGET |
-           NTLMSSP_NEGOTIATE_NTLM | NTLMSSP_NEGOTIATE_TARGET_INFO |
-           0x80000000 | NTLMSSP_NEGOTIATE_128;
+       negotiate_flags = NTLMSSP_NEGOTIATE_UNICODE | NTLMSSP_REQUEST_TARGET |
+                       NTLMSSP_NEGOTIATE_NTLM | NTLMSSP_NEGOTIATE_TARGET_INFO |
+                       0x80000000 | NTLMSSP_NEGOTIATE_128;
        if (sign_CIFS_PDUs)
                negotiate_flags |= /* NTLMSSP_NEGOTIATE_ALWAYS_SIGN |*/ NTLMSSP_NEGOTIATE_SIGN;
        if (ntlmv2_flag)
                        SecurityBlob->DomainName.Length = 0;
                        SecurityBlob->DomainName.MaximumLength = 0;
                } else {
-                       __u16 len =
-                           cifs_strtoUCS((__le16 *) bcc_ptr, domain, 64,
+                       __u16 ln = cifs_strtoUCS((__le16 *) bcc_ptr, domain, 64,
                                          nls_codepage);
-                       len *= 2;
+                       ln *= 2;
                        SecurityBlob->DomainName.MaximumLength =
-                           cpu_to_le16(len);
+                           cpu_to_le16(ln);
                        SecurityBlob->DomainName.Buffer =
                            cpu_to_le32(SecurityBlobLength);
-                       bcc_ptr += len;
-                       SecurityBlobLength += len;
-                       SecurityBlob->DomainName.Length =
-                           cpu_to_le16(len);
+                       bcc_ptr += ln;
+                       SecurityBlobLength += ln;
+                       SecurityBlob->DomainName.Length = cpu_to_le16(ln);
                }
                if (user == NULL) {
                        SecurityBlob->UserName.Buffer = 0;
                        SecurityBlob->UserName.Length = 0;
                        SecurityBlob->UserName.MaximumLength = 0;
                } else {
-                       __u16 len =
-                           cifs_strtoUCS((__le16 *) bcc_ptr, user, 64,
+                       __u16 ln = cifs_strtoUCS((__le16 *) bcc_ptr, user, 64,
                                          nls_codepage);
-                       len *= 2;
+                       ln *= 2;
                        SecurityBlob->UserName.MaximumLength =
-                           cpu_to_le16(len);
+                           cpu_to_le16(ln);
                        SecurityBlob->UserName.Buffer =
                            cpu_to_le32(SecurityBlobLength);
-                       bcc_ptr += len;
-                       SecurityBlobLength += len;
-                       SecurityBlob->UserName.Length =
-                           cpu_to_le16(len);
+                       bcc_ptr += ln;
+                       SecurityBlobLength += ln;
+                       SecurityBlob->UserName.Length = cpu_to_le16(ln);
                }
  
                /* SecurityBlob->WorkstationName.Length =
                        SecurityBlob->DomainName.Length = 0;
                        SecurityBlob->DomainName.MaximumLength = 0;
                } else {
-                       __u16 len;
+                       __u16 ln;
                        negotiate_flags |= NTLMSSP_NEGOTIATE_DOMAIN_SUPPLIED;
                        strncpy(bcc_ptr, domain, 63);
-                       len = strnlen(domain, 64);
+                       ln = strnlen(domain, 64);
                        SecurityBlob->DomainName.MaximumLength =
-                           cpu_to_le16(len);
+                           cpu_to_le16(ln);
                        SecurityBlob->DomainName.Buffer =
                            cpu_to_le32(SecurityBlobLength);
-                       bcc_ptr += len;
-                       SecurityBlobLength += len;
-                       SecurityBlob->DomainName.Length = cpu_to_le16(len);
+                       bcc_ptr += ln;
+                       SecurityBlobLength += ln;
+                       SecurityBlob->DomainName.Length = cpu_to_le16(ln);
                }
                if (user == NULL) {
                        SecurityBlob->UserName.Buffer = 0;
                        SecurityBlob->UserName.Length = 0;
                        SecurityBlob->UserName.MaximumLength = 0;
                } else {
-                       __u16 len;
+                       __u16 ln;
                        strncpy(bcc_ptr, user, 63);
-                       len = strnlen(user, 64);
-                       SecurityBlob->UserName.MaximumLength =
-                           cpu_to_le16(len);
+                       ln = strnlen(user, 64);
+                       SecurityBlob->UserName.MaximumLength = cpu_to_le16(ln);
                        SecurityBlob->UserName.Buffer =
-                           cpu_to_le32(SecurityBlobLength);
-                       bcc_ptr += len;
-                       SecurityBlobLength += len;
-                       SecurityBlob->UserName.Length = cpu_to_le16(len);
+                                               cpu_to_le32(SecurityBlobLength);
+                       bcc_ptr += ln;
+                       SecurityBlobLength += ln;
+                       SecurityBlob->UserName.Length = cpu_to_le16(ln);
                }
                /* BB fill in our workstation name if known BB */
  
        rc = SendReceive(xid, ses, smb_buffer, smb_buffer_response,
                         &bytes_returned, 1);
        if (rc) {
- /*    rc = map_smb_to_linux_error(smb_buffer_response);  *//* done in SendReceive now */
-       } else if ((smb_buffer_response->WordCount == 3)
-                  || (smb_buffer_response->WordCount == 4)) {
+ /*   rc = map_smb_to_linux_error(smb_buffer_response) done in SendReceive now */
+       } else if ((smb_buffer_response->WordCount == 3) ||
+                  (smb_buffer_response->WordCount == 4)) {
                __u16 action = le16_to_cpu(pSMBr->resp.Action);
-               __u16 blob_len =
-                   le16_to_cpu(pSMBr->resp.SecurityBlobLength);
+               __u16 blob_len = le16_to_cpu(pSMBr->resp.SecurityBlobLength);
                if (action & GUEST_LOGIN)
                        cFYI(1, (" Guest login")); /* BB Should we set anything
                                                         in SesInfo struct ? */
                                        } else {
                                                remaining_words = BCC(smb_buffer_response) / 2;
                                        }
-                                       len =
-                                           UniStrnlen((wchar_t *) bcc_ptr,remaining_words - 1);
+                                       len = UniStrnlen((wchar_t *) bcc_ptr,
+                                                       remaining_words - 1);
  /* We look for obvious messed up bcc or strings in response so we do not go off
    the end since (at least) WIN2K and Windows XP have a major bug in not null
    terminating last Unicode string in response  */
                                                <= BCC(smb_buffer_response)) {
                                                if (ses->serverOS)
                                                        kfree(ses->serverOS);
-                                               ses->serverOS = kzalloc(len + 1,GFP_KERNEL);
+                                               ses->serverOS = kzalloc(len + 1, GFP_KERNEL);
                                                strncpy(ses->serverOS,bcc_ptr, len);
  
                                                bcc_ptr += len;
                                                bcc_ptr[0] = 0;
                                                bcc_ptr++;
                                        } else
-                                               cFYI(1,
-                                                    ("field of length %d "
+                                               cFYI(1, ("field of length %d "
                                                   "extends beyond end of smb ",
                                                      len));
                                }
                        } else {
-                               cERROR(1,
-                                      (" Security Blob extends beyond end "
+                               cERROR(1, ("Security Blob extends beyond end "
                                        "of SMB"));
                        }
                } else {
                        cERROR(1, ("No session structure passed in."));
                }
        } else {
-               cERROR(1,
-                      (" Invalid Word count %d: ",
+               cERROR(1, ("Invalid Word count %d: ",
                        smb_buffer_response->WordCount));
                rc = -EIO;
        }
  
-       if (smb_buffer)
-               cifs_buf_release(smb_buffer);
+       cifs_buf_release(smb_buffer);
  
        return rc;
  }
@@@ -3389,6 -3391,18 +3391,18 @@@ CIFSTCon(unsigned int xid, struct cifsS
                bcc_ptr = pByteArea(smb_buffer_response);
                length = strnlen(bcc_ptr, BCC(smb_buffer_response) - 2);
                /* skip service field (NB: this field is always ASCII) */
+               if (length == 3) {
+                       if ((bcc_ptr[0] == 'I') && (bcc_ptr[1] == 'P') &&
+                           (bcc_ptr[2] == 'C')) {
+                               cFYI(1, ("IPC connection"));
+                               tcon->ipc = 1;
+                       }
+               } else if (length == 2) {
+                       if ((bcc_ptr[0] == 'A') && (bcc_ptr[1] == ':')) {
+                               /* the most common case */
+                               cFYI(1, ("disk share connection"));
+                       }
+               }
                bcc_ptr += length + 1;
                strncpy(tcon->treeName, tree, MAX_TREE_SIZE);
                if (smb_buffer->Flags2 & SMBFLG2_UNICODE) {
                                kfree(tcon->nativeFileSystem);
                                tcon->nativeFileSystem =
                                    kzalloc(length + 2, GFP_KERNEL);
-                               cifs_strfromUCS_le(tcon->nativeFileSystem,
-                                                  (__le16 *) bcc_ptr,
-                                                  length, nls_codepage);
+                               if (tcon->nativeFileSystem)
+                                       cifs_strfromUCS_le(
+                                               tcon->nativeFileSystem,
+                                               (__le16 *) bcc_ptr,
+                                               length, nls_codepage);
                                bcc_ptr += 2 * length;
                                bcc_ptr[0] = 0; /* null terminate the string */
                                bcc_ptr[1] = 0;
                                kfree(tcon->nativeFileSystem);
                                tcon->nativeFileSystem =
                                    kzalloc(length + 1, GFP_KERNEL);
-                               strncpy(tcon->nativeFileSystem, bcc_ptr,
-                                       length);
+                               if (tcon->nativeFileSystem)
+                                       strncpy(tcon->nativeFileSystem, bcc_ptr,
+                                               length);
                        }
                        /* else do not bother copying these information fields*/
                }
                ses->ipc_tid = smb_buffer_response->Tid;
        }
  
-       if (smb_buffer)
-               cifs_buf_release(smb_buffer);
+       cifs_buf_release(smb_buffer);
        return rc;
  }
  
diff --combined fs/cifs/inode.c
index 279f3c5e0ce316bf72e9ddb166a50586da206cfb,cc119b278e5be201e555d02c03f577b845762bc7..5e8b388be3b672a7130e9e26f8bb954ed8321534
@@@ -115,7 -115,7 +115,7 @@@ int cifs_get_inode_info_unix(struct ino
                inode->i_mode = le64_to_cpu(findData.Permissions);
                /* since we set the inode type below we need to mask off
                   to avoid strange results if bits set above */
-                       inode->i_mode &= ~S_IFMT;
+               inode->i_mode &= ~S_IFMT;
                if (type == UNIX_FILE) {
                        inode->i_mode |= S_IFREG;
                } else if (type == UNIX_SYMLINK) {
@@@ -575,19 -575,33 +575,33 @@@ int cifs_get_inode_info(struct inode **
        return rc;
  }
  
+ static const struct inode_operations cifs_ipc_inode_ops = {
+       .lookup = cifs_lookup,
+ };
  /* gets root inode */
  void cifs_read_inode(struct inode *inode)
  {
-       int xid;
+       int xid, rc;
        struct cifs_sb_info *cifs_sb;
  
        cifs_sb = CIFS_SB(inode->i_sb);
        xid = GetXid();
  
        if (cifs_sb->tcon->unix_ext)
-               cifs_get_inode_info_unix(&inode, "", inode->i_sb, xid);
+               rc = cifs_get_inode_info_unix(&inode, "", inode->i_sb, xid);
        else
-               cifs_get_inode_info(&inode, "", NULL, inode->i_sb, xid);
+               rc = cifs_get_inode_info(&inode, "", NULL, inode->i_sb, xid);
+       if (rc && cifs_sb->tcon->ipc) {
+               cFYI(1, ("ipc connection - fake read inode"));
+               inode->i_mode |= S_IFDIR;
+               inode->i_nlink = 2;
+               inode->i_op = &cifs_ipc_inode_ops;
+               inode->i_fop = &simple_dir_operations;
+               inode->i_uid = cifs_sb->mnt_uid;
+               inode->i_gid = cifs_sb->mnt_gid;
+       }
        /* can not call macro FreeXid here since in a void func */
        _FreeXid(xid);
  }
@@@ -919,18 -933,25 +933,25 @@@ int cifs_mkdir(struct inode *inode, str
                        goto mkdir_out;
                }
  
+               mode &= ~current->fs->umask;
                rc = CIFSPOSIXCreate(xid, pTcon, SMB_O_DIRECTORY | SMB_O_CREAT,
                                mode, NULL /* netfid */, pInfo, &oplock,
                                full_path, cifs_sb->local_nls,
                                cifs_sb->mnt_cifs_flags &
                                        CIFS_MOUNT_MAP_SPECIAL_CHR);
-               if (rc) {
+               if (rc == -EOPNOTSUPP) {
+                       kfree(pInfo);
+                       goto mkdir_retry_old;
+               } else if (rc) {
                        cFYI(1, ("posix mkdir returned 0x%x", rc));
                        d_drop(direntry);
                } else {
                        int obj_type;
-                       if (pInfo->Type == -1) /* no return info - go query */
+                       if (pInfo->Type == cpu_to_le32(-1)) {
+                               /* no return info, go query for it */
+                               kfree(pInfo);
                                goto mkdir_get_info;
+                       }
  /*BB check (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID ) to see if need
        to set uid/gid */
                        inc_nlink(inode);
                                direntry->d_op = &cifs_dentry_ops;
  
                        newinode = new_inode(inode->i_sb);
-                       if (newinode == NULL)
+                       if (newinode == NULL) {
+                               kfree(pInfo);
                                goto mkdir_get_info;
+                       }
                        /* Is an i_ino of zero legal? */
                        /* Are there sanity checks we can use to ensure that
                           the server is really filling in that field? */
                kfree(pInfo);
                goto mkdir_out;
        }
+ mkdir_retry_old:
        /* BB add setting the equivalent of mode via CreateX w/ACLs */
        rc = CIFSSMBMkDir(xid, pTcon, full_path, cifs_sb->local_nls,
                          cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
@@@ -1377,8 -1400,17 +1400,17 @@@ static int cifs_vmtruncate(struct inod
        }
        i_size_write(inode, offset);
        spin_unlock(&inode->i_lock);
+       /*
+        * unmap_mapping_range is called twice, first simply for efficiency
+        * so that truncate_inode_pages does fewer single-page unmaps. However
+        * after this first call, and before truncate_inode_pages finishes,
+        * it is possible for private pages to be COWed, which remain after
+        * truncate_inode_pages finishes, hence the second unmap_mapping_range
+        * call must be made for correctness.
+        */
        unmap_mapping_range(mapping, offset + PAGE_SIZE - 1, 0, 1);
        truncate_inode_pages(mapping, offset);
+       unmap_mapping_range(mapping, offset + PAGE_SIZE - 1, 0, 1);
        goto out_truncate;
  
  do_expand:
@@@ -1469,7 -1501,7 +1501,7 @@@ int cifs_setattr(struct dentry *direntr
                        atomic_dec(&open_file->wrtPending);
                        cFYI(1, ("SetFSize for attrs rc = %d", rc));
                        if ((rc == -EINVAL) || (rc == -EOPNOTSUPP)) {
-                               int bytes_written;
+                               unsigned int bytes_written;
                                rc = CIFSSMBWrite(xid, pTcon,
                                                  nfid, 0, attrs->ia_size,
                                                  &bytes_written, NULL, NULL,
                                        cifs_sb->mnt_cifs_flags &
                                                CIFS_MOUNT_MAP_SPECIAL_CHR);
                                if (rc == 0) {
-                                       int bytes_written;
+                                       unsigned int bytes_written;
                                        rc = CIFSSMBWrite(xid, pTcon,
                                                        netfid, 0,
                                                        attrs->ia_size,
        }
  
        time_buf.Attributes = 0;
 +
 +      /* skip mode change if it's just for clearing setuid/setgid */
 +      if (attrs->ia_valid & (ATTR_KILL_SUID|ATTR_KILL_SGID))
 +              attrs->ia_valid &= ~ATTR_MODE;
 +
        if (attrs->ia_valid & ATTR_MODE) {
                cFYI(1, ("Mode changed to 0x%x", attrs->ia_mode));
                mode = attrs->ia_mode;