]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
cifs: merge CIFSSMBQueryEA with CIFSSMBQAllEAs
authorJeff Layton <jlayton@redhat.com>
Wed, 10 Feb 2010 21:18:26 +0000 (16:18 -0500)
committerSteve French <sfrench@us.ibm.com>
Tue, 23 Feb 2010 20:47:32 +0000 (20:47 +0000)
Add an "ea_name" parameter to CIFSSMBQAllEAs. When it's set make it
behave like CIFSSMBQueryEA does now. The current callers of
CIFSSMBQueryEA are converted to use CIFSSMBQAllEAs, and the old
CIFSSMBQueryEA function is removed.

Signed-off-by: Jeff Layton <jlayton@redhat.com>
Signed-off-by: Steve French <sfrench@us.ibm.com>
fs/cifs/cifsproto.h
fs/cifs/cifssmb.c
fs/cifs/inode.c
fs/cifs/xattr.c

index 5646727e33f543f70ec449b390d8955b66852dc9..88e2bc44ac583860e15391041e4c0659e885094f 100644 (file)
@@ -363,13 +363,10 @@ extern int CIFSSMBNotify(const int xid, struct cifsTconInfo *tcon,
                        __u32 filter, struct file *file, int multishot,
                        const struct nls_table *nls_codepage);
 extern ssize_t CIFSSMBQAllEAs(const int xid, struct cifsTconInfo *tcon,
-                       const unsigned char *searchName, char *EAData,
+                       const unsigned char *searchName,
+                       const unsigned char *ea_name, char *EAData,
                        size_t bufsize, const struct nls_table *nls_codepage,
                        int remap_special_chars);
-extern ssize_t CIFSSMBQueryEA(const int xid, struct cifsTconInfo *tcon,
-               const unsigned char *searchName, const unsigned char *ea_name,
-               unsigned char *ea_value, size_t buf_size,
-               const struct nls_table *nls_codepage, int remap_special_chars);
 extern int CIFSSMBSetEA(const int xid, struct cifsTconInfo *tcon,
                const char *fileName, const char *ea_name,
                const void *ea_value, const __u16 ea_value_len,
index e197e1647d5d4c34ccdb16cfe4e6653cf56cfe3c..d6d40b883abc3511f299acee5e9662e774f50fc1 100644 (file)
@@ -5269,12 +5269,22 @@ int CIFSSMBNotify(const int xid, struct cifsTconInfo *tcon,
        cifs_buf_release(pSMB);
        return rc;
 }
+
 #ifdef CONFIG_CIFS_XATTR
+/*
+ * Do a path-based QUERY_ALL_EAS call and parse the result. This is a common
+ * function used by listxattr and getxattr type calls. When ea_name is set,
+ * it looks for that attribute name and stuffs that value into the EAData
+ * buffer. When ea_name is NULL, it stuffs a list of attribute names into the
+ * buffer. In both cases, the return value is either the length of the
+ * resulting data or a negative error code. If EAData is a NULL pointer then
+ * the data isn't copied to it, but the length is returned.
+ */
 ssize_t
 CIFSSMBQAllEAs(const int xid, struct cifsTconInfo *tcon,
-                const unsigned char *searchName,
-                char *EAData, size_t buf_size,
-                const struct nls_table *nls_codepage, int remap)
+               const unsigned char *searchName, const unsigned char *ea_name,
+               char *EAData, size_t buf_size,
+               const struct nls_table *nls_codepage, int remap)
 {
                /* BB assumes one setup word */
        TRANSACTION2_QPI_REQ *pSMB = NULL;
@@ -5403,27 +5413,46 @@ QAllEAsRetry:
                        goto QAllEAsOut;
                }
 
-               /* account for prefix user. and trailing null */
-               rc += (5 + 1 + name_len);
-               if (rc < (int) buf_size) {
-                       memcpy(EAData, "user.", 5);
-                       EAData += 5;
-                       memcpy(EAData, temp_ptr, name_len);
-                       EAData += name_len;
-                       /* null terminate name */
-                       *EAData = 0;
-                       ++EAData;
-               } else if (buf_size == 0) {
-                       /* skip copy - calc size only */
+               if (ea_name) {
+                       if (strncmp(ea_name, temp_ptr, name_len) == 0) {
+                               temp_ptr += name_len + 1;
+                               rc = value_len;
+                               if (buf_size == 0)
+                                       goto QAllEAsOut;
+                               if ((size_t)value_len > buf_size) {
+                                       rc = -ERANGE;
+                                       goto QAllEAsOut;
+                               }
+                               memcpy(EAData, temp_ptr, value_len);
+                               goto QAllEAsOut;
+                       }
                } else {
-                       /* stop before overrun buffer */
-                       rc = -ERANGE;
-                       break;
+                       /* account for prefix user. and trailing null */
+                       rc += (5 + 1 + name_len);
+                       if (rc < (int) buf_size) {
+                               memcpy(EAData, "user.", 5);
+                               EAData += 5;
+                               memcpy(EAData, temp_ptr, name_len);
+                               EAData += name_len;
+                               /* null terminate name */
+                               *EAData = 0;
+                               ++EAData;
+                       } else if (buf_size == 0) {
+                               /* skip copy - calc size only */
+                       } else {
+                               /* stop before overrun buffer */
+                               rc = -ERANGE;
+                               break;
+                       }
                }
                temp_ptr += name_len + 1 + value_len;
                temp_fea = (struct fea *)temp_ptr;
        }
 
+       /* didn't find the named attribute */
+       if (ea_name)
+               rc = -ENODATA;
+
 QAllEAsOut:
        cifs_buf_release(pSMB);
        if (rc == -EAGAIN)
@@ -5432,155 +5461,6 @@ QAllEAsOut:
        return (ssize_t)rc;
 }
 
-ssize_t CIFSSMBQueryEA(const int xid, struct cifsTconInfo *tcon,
-               const unsigned char *searchName, const unsigned char *ea_name,
-               unsigned char *ea_value, size_t buf_size,
-               const struct nls_table *nls_codepage, int remap)
-{
-       TRANSACTION2_QPI_REQ *pSMB = NULL;
-       TRANSACTION2_QPI_RSP *pSMBr = NULL;
-       int rc = 0;
-       int bytes_returned;
-       int name_len;
-       struct fea *temp_fea;
-       char *temp_ptr;
-       __u16 params, byte_count;
-
-       cFYI(1, ("In Query EA path %s", searchName));
-QEARetry:
-       rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB,
-                     (void **) &pSMBr);
-       if (rc)
-               return rc;
-
-       if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
-               name_len =
-                   cifsConvertToUCS((__le16 *) pSMB->FileName, searchName,
-                                    PATH_MAX, nls_codepage, remap);
-               name_len++;     /* trailing null */
-               name_len *= 2;
-       } else {        /* BB improve the check for buffer overruns BB */
-               name_len = strnlen(searchName, PATH_MAX);
-               name_len++;     /* trailing null */
-               strncpy(pSMB->FileName, searchName, name_len);
-       }
-
-       params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */;
-       pSMB->TotalDataCount = 0;
-       pSMB->MaxParameterCount = cpu_to_le16(2);
-       /* BB find exact max SMB PDU from sess structure BB */
-       pSMB->MaxDataCount = cpu_to_le16(4000);
-       pSMB->MaxSetupCount = 0;
-       pSMB->Reserved = 0;
-       pSMB->Flags = 0;
-       pSMB->Timeout = 0;
-       pSMB->Reserved2 = 0;
-       pSMB->ParameterOffset = cpu_to_le16(offsetof(
-               struct smb_com_transaction2_qpi_req, InformationLevel) - 4);
-       pSMB->DataCount = 0;
-       pSMB->DataOffset = 0;
-       pSMB->SetupCount = 1;
-       pSMB->Reserved3 = 0;
-       pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION);
-       byte_count = params + 1 /* pad */ ;
-       pSMB->TotalParameterCount = cpu_to_le16(params);
-       pSMB->ParameterCount = pSMB->TotalParameterCount;
-       pSMB->InformationLevel = cpu_to_le16(SMB_INFO_QUERY_ALL_EAS);
-       pSMB->Reserved4 = 0;
-       pSMB->hdr.smb_buf_length += byte_count;
-       pSMB->ByteCount = cpu_to_le16(byte_count);
-
-       rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
-                        (struct smb_hdr *) pSMBr, &bytes_returned, 0);
-       if (rc) {
-               cFYI(1, ("Send error in Query EA = %d", rc));
-       } else {                /* decode response */
-               rc = validate_t2((struct smb_t2_rsp *)pSMBr);
-
-               /* BB also check enough total bytes returned */
-               /* BB we need to improve the validity checking
-               of these trans2 responses */
-               if (rc || (pSMBr->ByteCount < 4))
-                       rc = -EIO;      /* bad smb */
-          /* else if (pFindData){
-                       memcpy((char *) pFindData,
-                              (char *) &pSMBr->hdr.Protocol +
-                              data_offset, kl);
-               }*/ else {
-                       /* check that length of list is not more than bcc */
-                       /* check that each entry does not go beyond length
-                          of list */
-                       /* check that each element of each entry does not
-                          go beyond end of list */
-                       __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset);
-                       struct fealist *ea_response_data;
-                       rc = -ENODATA;
-                       /* validate_trans2_offsets() */
-                       /* BB check if start of smb + data_offset > &bcc+ bcc*/
-                       ea_response_data = (struct fealist *)
-                               (((char *) &pSMBr->hdr.Protocol) +
-                               data_offset);
-                       name_len = le32_to_cpu(ea_response_data->list_len);
-                       cFYI(1, ("ea length %d", name_len));
-                       if (name_len <= 8) {
-                       /* returned EA size zeroed at top of function */
-                               cFYI(1, ("empty EA list returned from server"));
-                       } else {
-                               /* account for ea list len */
-                               name_len -= 4;
-                               temp_fea = ea_response_data->list;
-                               temp_ptr = (char *)temp_fea;
-                               /* loop through checking if we have a matching
-                               name and then return the associated value */
-                               while (name_len > 0) {
-                                       __u16 value_len;
-                                       name_len -= 4;
-                                       temp_ptr += 4;
-                                       value_len =
-                                             le16_to_cpu(temp_fea->value_len);
-                               /* BB validate that value_len falls within SMB,
-                               even though maximum for name_len is 255 */
-                                       if (memcmp(temp_fea->name, ea_name,
-                                                 temp_fea->name_len) == 0) {
-                                               /* found a match */
-                                               rc = value_len;
-                               /* account for prefix user. and trailing null */
-                                               if (rc <= (int)buf_size) {
-                                                       memcpy(ea_value,
-                                                               temp_fea->name+temp_fea->name_len+1,
-                                                               rc);
-                                                       /* ea values, unlike ea
-                                                          names, are not null
-                                                          terminated */
-                                               } else if (buf_size == 0) {
-                                               /* skip copy - calc size only */
-                                               } else {
-                                               /* stop before overrun buffer */
-                                                       rc = -ERANGE;
-                                               }
-                                               break;
-                                       }
-                                       name_len -= temp_fea->name_len;
-                                       temp_ptr += temp_fea->name_len;
-                                       /* account for trailing null */
-                                       name_len--;
-                                       temp_ptr++;
-                                       name_len -= value_len;
-                                       temp_ptr += value_len;
-                                       /* No trailing null to account for in
-                                          value_len.  Go on to next EA */
-                                       temp_fea = (struct fea *)temp_ptr;
-                               }
-                       }
-               }
-       }
-       cifs_buf_release(pSMB);
-       if (rc == -EAGAIN)
-               goto QEARetry;
-
-       return (ssize_t)rc;
-}
-
 int
 CIFSSMBSetEA(const int xid, struct cifsTconInfo *tcon, const char *fileName,
             const char *ea_name, const void *ea_value,
index e3fda978f4816eca17b9f5e4194fd161a224c5fe..5e9cc9c2fc7da02991b6ccdd8929ed8dfe6a6b40 100644 (file)
@@ -366,7 +366,7 @@ static int cifs_sfu_mode(struct cifs_fattr *fattr, const unsigned char *path,
        char ea_value[4];
        __u32 mode;
 
-       rc = CIFSSMBQueryEA(xid, cifs_sb->tcon, path, "SETFILEBITS",
+       rc = CIFSSMBQAllEAs(xid, cifs_sb->tcon, path, "SETFILEBITS",
                            ea_value, 4 /* size of buf */, cifs_sb->local_nls,
                            cifs_sb->mnt_cifs_flags &
                                CIFS_MOUNT_MAP_SPECIAL_CHR);
index a75afa3dd9e18c9c606fe3f0c9ece44d343c47a0..3e2ef0de120968e8e8012486f188e2b537590950 100644 (file)
@@ -244,7 +244,7 @@ ssize_t cifs_getxattr(struct dentry *direntry, const char *ea_name,
                        /* revalidate/getattr then populate from inode */
                } /* BB add else when above is implemented */
                ea_name += 5; /* skip past user. prefix */
-               rc = CIFSSMBQueryEA(xid, pTcon, full_path, ea_name, ea_value,
+               rc = CIFSSMBQAllEAs(xid, pTcon, full_path, ea_name, ea_value,
                        buf_size, cifs_sb->local_nls,
                        cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
        } else if (strncmp(ea_name, CIFS_XATTR_OS2_PREFIX, 4) == 0) {
@@ -252,7 +252,7 @@ ssize_t cifs_getxattr(struct dentry *direntry, const char *ea_name,
                        goto get_ea_exit;
 
                ea_name += 4; /* skip past os2. prefix */
-               rc = CIFSSMBQueryEA(xid, pTcon, full_path, ea_name, ea_value,
+               rc = CIFSSMBQAllEAs(xid, pTcon, full_path, ea_name, ea_value,
                        buf_size, cifs_sb->local_nls,
                        cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
        } else if (strncmp(ea_name, POSIX_ACL_XATTR_ACCESS,
@@ -364,8 +364,8 @@ ssize_t cifs_listxattr(struct dentry *direntry, char *data, size_t buf_size)
        /* if proc/fs/cifs/streamstoxattr is set then
                search server for EAs or streams to
                returns as xattrs */
-       rc = CIFSSMBQAllEAs(xid, pTcon, full_path, data, buf_size,
-                               cifs_sb->local_nls,
+       rc = CIFSSMBQAllEAs(xid, pTcon, full_path, NULL, data,
+                               buf_size, cifs_sb->local_nls,
                                cifs_sb->mnt_cifs_flags &
                                        CIFS_MOUNT_MAP_SPECIAL_CHR);