提交 9bf4fa01 编写于 作者: P Pavel Shilovsky 提交者: Steve French

CIFS: Cleanup CIFSSMBOpen

Remove indentation, fix comment style, rename camel case
variables in preparation to make it work with cifs_open_parms
structure as a parm.
Signed-off-by: NPavel Shilovsky <piastry@etersoft.ru>
Signed-off-by: NSteve French <smfrench@gmail.com>
上级 924e3fa4
...@@ -363,10 +363,10 @@ extern int CIFSSMBQuerySymLink(const unsigned int xid, struct cifs_tcon *tcon, ...@@ -363,10 +363,10 @@ extern int CIFSSMBQuerySymLink(const unsigned int xid, struct cifs_tcon *tcon,
extern int CIFSSMB_set_compression(const unsigned int xid, extern int CIFSSMB_set_compression(const unsigned int xid,
struct cifs_tcon *tcon, __u16 fid); struct cifs_tcon *tcon, __u16 fid);
extern int CIFSSMBOpen(const unsigned int xid, struct cifs_tcon *tcon, extern int CIFSSMBOpen(const unsigned int xid, struct cifs_tcon *tcon,
const char *fileName, const int disposition, const char *path, const int disposition,
const int access_flags, const int omode, const int desired_access, const int create_options,
__u16 *netfid, int *pOplock, FILE_ALL_INFO *, __u16 *netfid, int *oplock, FILE_ALL_INFO *buf,
const struct nls_table *nls_codepage, int remap); const struct nls_table *nls, int remap);
extern int SMBLegacyOpen(const unsigned int xid, struct cifs_tcon *tcon, extern int SMBLegacyOpen(const unsigned int xid, struct cifs_tcon *tcon,
const char *fileName, const int disposition, const char *fileName, const int disposition,
const int access_flags, const int omode, const int access_flags, const int omode,
......
...@@ -1274,103 +1274,117 @@ SMBLegacyOpen(const unsigned int xid, struct cifs_tcon *tcon, ...@@ -1274,103 +1274,117 @@ SMBLegacyOpen(const unsigned int xid, struct cifs_tcon *tcon,
int int
CIFSSMBOpen(const unsigned int xid, struct cifs_tcon *tcon, CIFSSMBOpen(const unsigned int xid, struct cifs_tcon *tcon,
const char *fileName, const int openDisposition, const char *path, const int disposition, const int desired_access,
const int access_flags, const int create_options, __u16 *netfid, const int create_options, __u16 *netfid, int *oplock,
int *pOplock, FILE_ALL_INFO *pfile_info, FILE_ALL_INFO *buf, const struct nls_table *nls, int remap)
const struct nls_table *nls_codepage, int remap)
{ {
int rc = -EACCES; int rc = -EACCES;
OPEN_REQ *pSMB = NULL; OPEN_REQ *req = NULL;
OPEN_RSP *pSMBr = NULL; OPEN_RSP *rsp = NULL;
int bytes_returned; int bytes_returned;
int name_len; int name_len;
__u16 count; __u16 count;
openRetry: openRetry:
rc = smb_init(SMB_COM_NT_CREATE_ANDX, 24, tcon, (void **) &pSMB, rc = smb_init(SMB_COM_NT_CREATE_ANDX, 24, tcon, (void **)&req,
(void **) &pSMBr); (void **)&rsp);
if (rc) if (rc)
return rc; return rc;
pSMB->AndXCommand = 0xFF; /* none */ /* no commands go after this */
req->AndXCommand = 0xFF;
if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { if (req->hdr.Flags2 & SMBFLG2_UNICODE) {
count = 1; /* account for one byte pad to word boundary */ /* account for one byte pad to word boundary */
name_len = count = 1;
cifsConvertToUTF16((__le16 *) (pSMB->fileName + 1), name_len = cifsConvertToUTF16((__le16 *)(req->fileName + 1),
fileName, PATH_MAX, nls_codepage, remap); path, PATH_MAX, nls, remap);
name_len++; /* trailing null */ /* trailing null */
name_len++;
name_len *= 2; name_len *= 2;
pSMB->NameLength = cpu_to_le16(name_len); req->NameLength = cpu_to_le16(name_len);
} else { /* BB improve check for buffer overruns BB */ } else {
count = 0; /* no pad */ /* BB improve check for buffer overruns BB */
name_len = strnlen(fileName, PATH_MAX); /* no pad */
name_len++; /* trailing null */ count = 0;
pSMB->NameLength = cpu_to_le16(name_len); name_len = strnlen(path, PATH_MAX);
strncpy(pSMB->fileName, fileName, name_len); /* trailing null */
name_len++;
req->NameLength = cpu_to_le16(name_len);
strncpy(req->fileName, path, name_len);
} }
if (*pOplock & REQ_OPLOCK)
pSMB->OpenFlags = cpu_to_le32(REQ_OPLOCK); if (*oplock & REQ_OPLOCK)
else if (*pOplock & REQ_BATCHOPLOCK) req->OpenFlags = cpu_to_le32(REQ_OPLOCK);
pSMB->OpenFlags = cpu_to_le32(REQ_BATCHOPLOCK); else if (*oplock & REQ_BATCHOPLOCK)
pSMB->DesiredAccess = cpu_to_le32(access_flags); req->OpenFlags = cpu_to_le32(REQ_BATCHOPLOCK);
pSMB->AllocationSize = 0;
/* set file as system file if special file such req->DesiredAccess = cpu_to_le32(desired_access);
as fifo and server expecting SFU style and req->AllocationSize = 0;
no Unix extensions */
/*
* Set file as system file if special file such as fifo and server
* expecting SFU style and no Unix extensions.
*/
if (create_options & CREATE_OPTION_SPECIAL) if (create_options & CREATE_OPTION_SPECIAL)
pSMB->FileAttributes = cpu_to_le32(ATTR_SYSTEM); req->FileAttributes = cpu_to_le32(ATTR_SYSTEM);
else else
pSMB->FileAttributes = cpu_to_le32(ATTR_NORMAL); req->FileAttributes = cpu_to_le32(ATTR_NORMAL);
/* XP does not handle ATTR_POSIX_SEMANTICS */ /*
/* but it helps speed up case sensitive checks for other * XP does not handle ATTR_POSIX_SEMANTICS but it helps speed up case
servers such as Samba */ * sensitive checks for other servers such as Samba.
*/
if (tcon->ses->capabilities & CAP_UNIX) if (tcon->ses->capabilities & CAP_UNIX)
pSMB->FileAttributes |= cpu_to_le32(ATTR_POSIX_SEMANTICS); req->FileAttributes |= cpu_to_le32(ATTR_POSIX_SEMANTICS);
if (create_options & CREATE_OPTION_READONLY) if (create_options & CREATE_OPTION_READONLY)
pSMB->FileAttributes |= cpu_to_le32(ATTR_READONLY); req->FileAttributes |= cpu_to_le32(ATTR_READONLY);
req->ShareAccess = cpu_to_le32(FILE_SHARE_ALL);
req->CreateDisposition = cpu_to_le32(disposition);
req->CreateOptions = cpu_to_le32(create_options & CREATE_OPTIONS_MASK);
pSMB->ShareAccess = cpu_to_le32(FILE_SHARE_ALL);
pSMB->CreateDisposition = cpu_to_le32(openDisposition);
pSMB->CreateOptions = cpu_to_le32(create_options & CREATE_OPTIONS_MASK);
/* BB Expirement with various impersonation levels and verify */ /* BB Expirement with various impersonation levels and verify */
pSMB->ImpersonationLevel = cpu_to_le32(SECURITY_IMPERSONATION); req->ImpersonationLevel = cpu_to_le32(SECURITY_IMPERSONATION);
pSMB->SecurityFlags = req->SecurityFlags = SECURITY_CONTEXT_TRACKING|SECURITY_EFFECTIVE_ONLY;
SECURITY_CONTEXT_TRACKING | SECURITY_EFFECTIVE_ONLY;
count += name_len; count += name_len;
inc_rfc1001_len(pSMB, count); inc_rfc1001_len(req, count);
pSMB->ByteCount = cpu_to_le16(count); req->ByteCount = cpu_to_le16(count);
/* long_op set to 1 to allow for oplock break timeouts */ rc = SendReceive(xid, tcon->ses, (struct smb_hdr *)req,
rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, (struct smb_hdr *)rsp, &bytes_returned, 0);
(struct smb_hdr *)pSMBr, &bytes_returned, 0);
cifs_stats_inc(&tcon->stats.cifs_stats.num_opens); cifs_stats_inc(&tcon->stats.cifs_stats.num_opens);
if (rc) { if (rc) {
cifs_dbg(FYI, "Error in Open = %d\n", rc); cifs_dbg(FYI, "Error in Open = %d\n", rc);
} else { cifs_buf_release(req);
*pOplock = pSMBr->OplockLevel; /* 1 byte no need to le_to_cpu */ if (rc == -EAGAIN)
*netfid = pSMBr->Fid; /* cifs fid stays in le */ goto openRetry;
/* Let caller know file was created so we can set the mode. */ return rc;
/* Do we care about the CreateAction in any other cases? */
if (cpu_to_le32(FILE_CREATE) == pSMBr->CreateAction)
*pOplock |= CIFS_CREATE_ACTION;
if (pfile_info) {
memcpy((char *)pfile_info, (char *)&pSMBr->CreationTime,
36 /* CreationTime to Attributes */);
/* the file_info buf is endian converted by caller */
pfile_info->AllocationSize = pSMBr->AllocationSize;
pfile_info->EndOfFile = pSMBr->EndOfFile;
pfile_info->NumberOfLinks = cpu_to_le32(1);
pfile_info->DeletePending = 0;
}
} }
cifs_buf_release(pSMB); /* 1 byte no need to le_to_cpu */
if (rc == -EAGAIN) *oplock = rsp->OplockLevel;
goto openRetry; /* cifs fid stays in le */
*netfid = rsp->Fid;
/* Let caller know file was created so we can set the mode. */
/* Do we care about the CreateAction in any other cases? */
if (cpu_to_le32(FILE_CREATE) == rsp->CreateAction)
*oplock |= CIFS_CREATE_ACTION;
if (buf) {
/* copy from CreationTime to Attributes */
memcpy((char *)buf, (char *)&rsp->CreationTime, 36);
/* the file_info buf is endian converted by caller */
buf->AllocationSize = rsp->AllocationSize;
buf->EndOfFile = rsp->EndOfFile;
buf->NumberOfLinks = cpu_to_le32(1);
buf->DeletePending = 0;
}
cifs_buf_release(req);
return rc; return rc;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册