]> err.no Git - linux-2.6/commitdiff
[CIFS] Various minor bigendian fixes and sparse level 2 warning message fixes
authorSteve French <sfrench@us.ibm.com>
Thu, 22 Sep 2005 23:32:06 +0000 (16:32 -0700)
committerSteve French <sfrench@us.ibm.com>
Thu, 22 Sep 2005 23:32:06 +0000 (16:32 -0700)
Most important of these fixes mapchars on bigendian and a few statfs fields

Signed-off-by: Shaggy (shaggy@austin.ibm.com)
Signed-off-by: Steve French (sfrench@us.ibm.com)
fs/cifs/CHANGES
fs/cifs/cifspdu.h
fs/cifs/cifsproto.h
fs/cifs/cifssmb.c
fs/cifs/connect.c
fs/cifs/misc.c
fs/cifs/netmisc.c
fs/cifs/transport.c

index 661b45906d0980e4669aa31e9dba25b9d55f1167..535177238020e602f098970475801f639b524bd0 100644 (file)
@@ -4,7 +4,8 @@ Fix readdir caching when unlink removes file in current search buffer,
 and this is followed by a rewind search to just before the deleted entry.
 Do not attempt to set ctime unless atime and/or mtime change requested
 (most servers throw it away anyway). Fix length check of received smbs
-to be more accurate.
+to be more accurate. Fix big endian problem with mapchars mount option,
+and with a field returned by statfs.
 
 Version 1.36
 ------------
index 3fa37790bea271bf1f7bc0e9bc1623a78a7962b9..193f06eb43f9e20425eaf6526741d86a1175911e 100644 (file)
@@ -697,7 +697,7 @@ typedef struct smb_com_openx_req {
        __le32 EndOfFile;
        __le32 Timeout;
        __le32 Reserved;
-       __u16  ByteCount;  /* file name follows */
+       __le16  ByteCount;  /* file name follows */
        char   fileName[1];
 } OPENX_REQ;
 
index 0bace385e97a882d3f06a1b88436ebbb2016e516..dc5a6a6ff2f9253b19e7642deb2be2f6831c3dca 100644 (file)
@@ -56,6 +56,7 @@ extern int checkSMB(struct smb_hdr *smb, __u16 mid, int length);
 extern int is_valid_oplock_break(struct smb_hdr *smb);
 extern int is_size_safe_to_change(struct cifsInodeInfo *);
 extern unsigned int smbCalcSize(struct smb_hdr *ptr);
+extern unsigned int smbCalcSize_LE(struct smb_hdr *ptr);
 extern int decode_negTokenInit(unsigned char *security_blob, int length,
                        enum securityEnum *secType);
 extern int cifs_inet_pton(int, char * source, void *dst);
index daf717e6b6eb2426366f03613a12038f74ec16f1..52caac063a7750622050697c81eb06b96e404319 100644 (file)
@@ -779,7 +779,7 @@ OldOpenRetry:
        /* BB FIXME END BB */
 
        pSMB->Sattr = cpu_to_le16(ATTR_HIDDEN | ATTR_SYSTEM | ATTR_DIRECTORY);
-       pSMB->OpenFunction = convert_disposition(openDisposition);
+       pSMB->OpenFunction = cpu_to_le16(convert_disposition(openDisposition));
        count += name_len;
        pSMB->hdr.smb_buf_length += count;
 
@@ -808,10 +808,12 @@ OldOpenRetry:
                        pfile_info->LastAccessTime = 0; /* BB fixme */
                        pfile_info->LastWriteTime = 0; /* BB fixme */
                        pfile_info->ChangeTime = 0;  /* BB fixme */
-                       pfile_info->Attributes = pSMBr->FileAttributes; 
+                       pfile_info->Attributes =
+                               cpu_to_le32(le16_to_cpu(pSMBr->FileAttributes)); 
                        /* the file_info buf is endian converted by caller */
-                       pfile_info->AllocationSize = pSMBr->EndOfFile;
-                       pfile_info->EndOfFile = pSMBr->EndOfFile;
+                       pfile_info->AllocationSize =
+                               cpu_to_le64(le32_to_cpu(pSMBr->EndOfFile));
+                       pfile_info->EndOfFile = pfile_info->AllocationSize;
                        pfile_info->NumberOfLinks = cpu_to_le32(1);
                }
        }
@@ -2390,9 +2392,11 @@ QInfRetry:
                cFYI(1, ("Send error in QueryInfo = %d", rc));
        } else if (pFinfo) {            /* decode response */
                memset(pFinfo, 0, sizeof(FILE_ALL_INFO));
-               pFinfo->AllocationSize = (__le64) pSMBr->size;
-               pFinfo->EndOfFile = (__le64) pSMBr->size;
-               pFinfo->Attributes = (__le32) pSMBr->attr;
+               pFinfo->AllocationSize =
+                       cpu_to_le64(le32_to_cpu(pSMBr->size));
+               pFinfo->EndOfFile = pFinfo->AllocationSize;
+               pFinfo->Attributes =
+                       cpu_to_le32(le16_to_cpu(pSMBr->attr));
        } else
                rc = -EIO; /* bad buffer passed in */
 
@@ -3722,16 +3726,16 @@ QFSPosixRetry:
                                        le64_to_cpu(response_data->TotalBlocks);
                        FSData->f_bfree =
                            le64_to_cpu(response_data->BlocksAvail);
-                       if(response_data->UserBlocksAvail == -1) {
+                       if(response_data->UserBlocksAvail == cpu_to_le64(-1)) {
                                FSData->f_bavail = FSData->f_bfree;
                        } else {
                                FSData->f_bavail =
                                        le64_to_cpu(response_data->UserBlocksAvail);
                        }
-                       if(response_data->TotalFileNodes != -1)
+                       if(response_data->TotalFileNodes != cpu_to_le64(-1))
                                FSData->f_files =
                                        le64_to_cpu(response_data->TotalFileNodes);
-                       if(response_data->FreeFileNodes != -1)
+                       if(response_data->FreeFileNodes != cpu_to_le64(-1))
                                FSData->f_ffree =
                                        le64_to_cpu(response_data->FreeFileNodes);
                }
index 196976049c00e12dce6dda11b8915be2450beaa6..e27e5ad8b5919870c5b2b9c020dcfe8d1627cfbe 100644 (file)
@@ -303,12 +303,12 @@ static int coalesce_t2(struct smb_hdr * psecond, struct smb_hdr *pTargetSMB)
        byte_count += total_in_buf2;
        BCC_LE(pTargetSMB) = cpu_to_le16(byte_count);
 
-       byte_count = be32_to_cpu(pTargetSMB->smb_buf_length);
+       byte_count = pTargetSMB->smb_buf_length;
        byte_count += total_in_buf2;
 
        /* BB also add check that we are not beyond maximum buffer size */
                
-       pTargetSMB->smb_buf_length = cpu_to_be32(byte_count);
+       pTargetSMB->smb_buf_length = byte_count;
 
        if(remaining == total_in_buf2) {
                cFYI(1,("found the last secondary response"));
@@ -333,7 +333,7 @@ cifs_demultiplex_thread(struct TCP_Server_Info *server)
        struct cifsSesInfo *ses;
        struct task_struct *task_to_wake = NULL;
        struct mid_q_entry *mid_entry;
-       char *temp;
+       char temp;
        int isLargeBuf = FALSE;
        int isMultiRsp;
        int reconnect;
@@ -435,22 +435,32 @@ cifs_demultiplex_thread(struct TCP_Server_Info *server)
                        continue;
                }
 
-               /* the right amount was read from socket - 4 bytes */
+               /* The right amount was read from socket - 4 bytes */
+               /* so we can now interpret the length field */
 
+               /* the first byte big endian of the length field,
+               is actually not part of the length but the type
+               with the most common, zero, as regular data */
+               temp = *((char *) smb_buffer);
+
+               /* Note that FC 1001 length is big endian on the wire, 
+               but we convert it here so it is always manipulated
+               as host byte order */
                pdu_length = ntohl(smb_buffer->smb_buf_length);
-               cFYI(1,("rfc1002 length(big endian)0x%x)", pdu_length+4));
+               smb_buffer->smb_buf_length = pdu_length;
+
+               cFYI(1,("rfc1002 length 0x%x)", pdu_length+4));
 
-               temp = (char *) smb_buffer;
-               if (temp[0] == (char) RFC1002_SESSION_KEEP_ALIVE) {
+               if (temp == (char) RFC1002_SESSION_KEEP_ALIVE) {
                        continue; 
-               } else if (temp[0] == (char)RFC1002_POSITIVE_SESSION_RESPONSE) {
+               } else if (temp == (char)RFC1002_POSITIVE_SESSION_RESPONSE) {
                        cFYI(1,("Good RFC 1002 session rsp"));
                        continue;
-               } else if (temp[0] == (char)RFC1002_NEGATIVE_SESSION_RESPONSE) {
+               } else if (temp == (char)RFC1002_NEGATIVE_SESSION_RESPONSE) {
                        /* we get this from Windows 98 instead of 
                           an error on SMB negprot response */
                        cFYI(1,("Negative RFC1002 Session Response Error 0x%x)",
-                               temp[4]));
+                               pdu_length));
                        if(server->tcpStatus == CifsNew) {
                                /* if nack on negprot (rather than 
                                ret of smb negprot error) reconnecting
@@ -472,9 +482,10 @@ cifs_demultiplex_thread(struct TCP_Server_Info *server)
                                wake_up(&server->response_q);
                                continue;
                        }
-               } else if (temp[0] != (char) 0) {
+               } else if (temp != (char) 0) {
                        cERROR(1,("Unknown RFC 1002 frame"));
-                       cifs_dump_mem(" Received Data: ", temp, length);
+                       cifs_dump_mem(" Received Data: ", (char *)smb_buffer,
+                                     length);
                        cifs_reconnect(server);
                        csocket = server->ssocket;
                        continue;
@@ -609,7 +620,8 @@ multi_t2_fnd:
                } else if ((is_valid_oplock_break(smb_buffer) == FALSE)
                    && (isMultiRsp == FALSE)) {                          
                        cERROR(1, ("No task to wake, unknown frame rcvd!"));
-                       cifs_dump_mem("Received Data is: ",temp,sizeof(struct smb_hdr));
+                       cifs_dump_mem("Received Data is: ",(char *)smb_buffer,
+                                     sizeof(struct smb_hdr));
                }
        } /* end while !EXITING */
 
index 26b35b55f31b99b752201e19c31446550ab90c50..8a0edd695f84ba5a29de4c7a1a17045a3d80f892 100644 (file)
@@ -419,7 +419,7 @@ checkSMBhdr(struct smb_hdr *smb, __u16 mid)
 int
 checkSMB(struct smb_hdr *smb, __u16 mid, int length)
 {
-       __u32 len = be32_to_cpu(smb->smb_buf_length);
+       __u32 len = smb->smb_buf_length;
        cFYI(0,
             ("Entering checkSMB with Length: %x, smb_buf_length: %x ",
              length, len));
@@ -448,9 +448,9 @@ checkSMB(struct smb_hdr *smb, __u16 mid, int length)
        if (checkSMBhdr(smb, mid))
                return 1;
 
-       if ((4 + len != smbCalcSize(smb))
+       if ((4 + len != smbCalcSize_LE(smb))
            || (4 + len != (unsigned int)length)) {
-               cERROR(1, ("smbCalcSize %x ", smbCalcSize(smb)));
+               cERROR(1, ("smbCalcSize %x ", smbCalcSize_LE(smb)));
                cERROR(1,
                       ("bad smb size detected. The Mid=%d", smb->Mid));
                return 1;
@@ -672,6 +672,7 @@ cifsConvertToUCS(__le16 * target, const char *source, int maxlen,
        int i,j,charlen;
        int len_remaining = maxlen;
        char src_char;
+       __u16 temp;
 
        if(!mapChars) 
                return cifs_strtoUCS((wchar_t *) target, source, PATH_MAX, cp);
@@ -708,13 +709,14 @@ cifsConvertToUCS(__le16 * target, const char *source, int maxlen,
                                break;*/
                        default:
                                charlen = cp->char2uni(source+i,
-                                       len_remaining, target+j);
+                                       len_remaining, &temp);
                                /* if no match, use question mark, which
                                at least in some cases servers as wild card */
                                if(charlen < 1) {
                                        target[j] = cpu_to_le16(0x003f);
                                        charlen = 1;
-                               }
+                               } else
+                                       target[j] = cpu_to_le16(temp);
                                len_remaining -= charlen;
                                /* character may take more than one byte in the
                                   the source string, but will take exactly two
index 32efa32774d22a73e48dd6c1773322d6caaf0cb9..29e6efc5597c37d9d08e4007eb483d15a0fbdacd 100644 (file)
@@ -868,7 +868,14 @@ unsigned int
 smbCalcSize(struct smb_hdr *ptr)
 {
        return (sizeof (struct smb_hdr) + (2 * ptr->WordCount) +
-               2 /* size of the bcc field itself */ + BCC(ptr));
+               2 /* size of the bcc field */ + BCC(ptr));
+}
+
+unsigned int
+smbCalcSize_LE(struct smb_hdr *ptr)
+{
+       return (sizeof (struct smb_hdr) + (2 * ptr->WordCount) +
+               2 /* size of the bcc field */ + le16_to_cpu(BCC_LE(ptr)));
 }
 
 /* The following are taken from fs/ntfs/util.c */
index d5e0c4018f92e317624fae4afa989b70639068f5..9e8e85a8d186b62a781c49e71d9dfa0c2cb4517c 100644 (file)
@@ -414,7 +414,7 @@ SendReceive2(const unsigned int xid, struct cifsSesInfo *ses,
        spin_lock(&GlobalMid_Lock);
        if (midQ->resp_buf) {
                spin_unlock(&GlobalMid_Lock);
-               receive_len = be32_to_cpu(*(__be32 *)midQ->resp_buf);
+               receive_len = midQ->resp_buf->smb_buf_length;
        } else {
                cERROR(1,("No response buffer"));
                if(midQ->midState == MID_REQUEST_SUBMITTED) {
@@ -665,7 +665,7 @@ SendReceive(const unsigned int xid, struct cifsSesInfo *ses,
        spin_lock(&GlobalMid_Lock);
        if (midQ->resp_buf) {
                spin_unlock(&GlobalMid_Lock);
-               receive_len = be32_to_cpu(*(__be32 *)midQ->resp_buf);
+               receive_len = midQ->resp_buf->smb_buf_length;
        } else {
                cERROR(1,("No response buffer"));
                if(midQ->midState == MID_REQUEST_SUBMITTED) {