⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cifssmb.c

📁 Linux Kernel 2.6.9 for OMAP1710
💻 C
📖 第 1 页 / 共 5 页
字号:
/* do not retry on dead session on close */	rc = smb_init(SMB_COM_CLOSE, 3, tcon, (void **) &pSMB,		      (void **) &pSMBr);	if(rc == -EAGAIN)		return 0;	if (rc)		return rc;	pSMB->FileID = (__u16) smb_file_id;	pSMB->LastWriteTime = 0;	pSMB->ByteCount = 0;	rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,			 (struct smb_hdr *) pSMBr, &bytes_returned, 0);	if (rc) {		if(rc!=-EINTR) {			/* EINTR is expected when user ctl-c to kill app */			cERROR(1, ("Send error in Close = %d", rc));		}	}	if (pSMB)		cifs_buf_release(pSMB);	/* Since session is dead, file will be closed on server already */	if(rc == -EAGAIN)		rc = 0;	return rc;}intCIFSSMBRename(const int xid, struct cifsTconInfo *tcon,	      const char *fromName, const char *toName,	      const struct nls_table *nls_codepage){	int rc = 0;	RENAME_REQ *pSMB = NULL;	RENAME_RSP *pSMBr = NULL;	int bytes_returned;	int name_len, name_len2;	__u16 count;	cFYI(1, ("In CIFSSMBRename"));renameRetry:	rc = smb_init(SMB_COM_RENAME, 1, tcon, (void **) &pSMB,		      (void **) &pSMBr);	if (rc)		return rc;	pSMB->BufferFormat = 0x04;	pSMB->SearchAttributes =	    cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM |			ATTR_DIRECTORY);	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {		name_len =		    cifs_strtoUCS((wchar_t *) pSMB->OldFileName, fromName, 530				  /* find define for this maxpathcomponent */				  , nls_codepage);		name_len++;	/* trailing null */		name_len *= 2;		pSMB->OldFileName[name_len] = 0x04;	/* pad */	/* protocol requires ASCII signature byte on Unicode string */		pSMB->OldFileName[name_len + 1] = 0x00;		name_len2 =		    cifs_strtoUCS((wchar_t *) & pSMB->				  OldFileName[name_len + 2], toName, 530,				  nls_codepage);		name_len2 += 1 /* trailing null */  + 1 /* Signature word */ ;		name_len2 *= 2;	/* convert to bytes */	} else {		/* BB improve the check for buffer overruns BB */		name_len = strnlen(fromName, 530);		name_len++;	/* trailing null */		strncpy(pSMB->OldFileName, fromName, name_len);		name_len2 = strnlen(toName, 530);		name_len2++;	/* trailing null */		pSMB->OldFileName[name_len] = 0x04;  /* 2nd buffer format */		strncpy(&pSMB->OldFileName[name_len + 1], toName, name_len2);		name_len2++;	/* trailing null */		name_len2++;	/* signature byte */	}	count = 1 /* 1st signature byte */  + name_len + name_len2;	pSMB->hdr.smb_buf_length += count;	pSMB->ByteCount = cpu_to_le16(count);	rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,			 (struct smb_hdr *) pSMBr, &bytes_returned, 0);	if (rc) {		cFYI(1, ("Send error in rename = %d", rc));	} #ifdef CONFIG_CIFS_STATS	  else {		atomic_inc(&tcon->num_renames);	}#endif	if (pSMB)		cifs_buf_release(pSMB);	if (rc == -EAGAIN)		goto renameRetry;	return rc;}int CIFSSMBRenameOpenFile(const int xid,struct cifsTconInfo *pTcon, 		int netfid, char * target_name, const struct nls_table * nls_codepage) {	struct smb_com_transaction2_sfi_req *pSMB  = NULL;	struct smb_com_transaction2_sfi_rsp *pSMBr = NULL;	struct set_file_rename * rename_info;	char *data_offset;	char dummy_string[30];	int rc = 0;	int bytes_returned = 0;	int len_of_str;	__u16 params, param_offset, offset, count, byte_count;	cFYI(1, ("Rename to File by handle"));	rc = smb_init(SMB_COM_TRANSACTION2, 15, pTcon, (void **) &pSMB,			(void **) &pSMBr);	if (rc)		return rc;	params = 6;	pSMB->MaxSetupCount = 0;	pSMB->Reserved = 0;	pSMB->Flags = 0;	pSMB->Timeout = 0;	pSMB->Reserved2 = 0;	param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4;	offset = param_offset + params;	data_offset = (char *) (&pSMB->hdr.Protocol) + offset;	rename_info = (struct set_file_rename *) data_offset;	pSMB->MaxParameterCount = cpu_to_le16(2);	pSMB->MaxDataCount = cpu_to_le16(1000); /* BB find max SMB PDU from sess */	pSMB->SetupCount = 1;	pSMB->Reserved3 = 0;	pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION);	byte_count = 3 /* pad */  + params;	pSMB->ParameterCount = cpu_to_le16(params);	pSMB->TotalParameterCount = pSMB->ParameterCount;	pSMB->ParameterOffset = cpu_to_le16(param_offset);	pSMB->DataOffset = cpu_to_le16(offset);	/* construct random name ".cifs_tmp<inodenum><mid>" */	rename_info->overwrite = cpu_to_le32(1);	rename_info->root_fid  = 0;	/* unicode only call */	if(target_name == NULL) {		sprintf(dummy_string,"cifs%x",pSMB->hdr.Mid);	        len_of_str = cifs_strtoUCS((wchar_t *) rename_info->target_name, dummy_string, 24, nls_codepage);	} else {		len_of_str = cifs_strtoUCS((wchar_t *) rename_info->target_name, target_name, 530, nls_codepage);	}	rename_info->target_name_len = cpu_to_le32(2 * len_of_str);	count = 12 /* sizeof(struct set_file_rename) */ + (2 * len_of_str) + 2;	byte_count += count;	pSMB->DataCount = cpu_to_le16(count);	pSMB->TotalDataCount = pSMB->DataCount;	pSMB->Fid = netfid;	pSMB->InformationLevel =		cpu_to_le16(SMB_SET_FILE_RENAME_INFORMATION);	pSMB->Reserved4 = 0;	pSMB->hdr.smb_buf_length += byte_count;	pSMB->ByteCount = cpu_to_le16(byte_count);	rc = SendReceive(xid, pTcon->ses, (struct smb_hdr *) pSMB,                         (struct smb_hdr *) pSMBr, &bytes_returned, 0);	if (rc) {		cFYI(1,("Send error in Rename (by file handle) = %d", rc));	}#ifdef CONFIG_CIFS_STATS	  else {		atomic_inc(&pTcon->num_t2renames);	}#endif	if (pSMB)		cifs_buf_release(pSMB);	/* Note: On -EAGAIN error only caller can retry on handle based calls		since file handle passed in no longer valid */	return rc;}intCIFSSMBCopy(const int xid, struct cifsTconInfo *tcon, const char * fromName,             const __u16 target_tid, const char *toName, const int flags,            const struct nls_table *nls_codepage){	int rc = 0;	COPY_REQ *pSMB = NULL;	COPY_RSP *pSMBr = NULL;	int bytes_returned;	int name_len, name_len2;	__u16 count;	cFYI(1, ("In CIFSSMBCopy"));copyRetry:	rc = smb_init(SMB_COM_COPY, 1, tcon, (void **) &pSMB,			(void **) &pSMBr);	if (rc)		return rc;	pSMB->BufferFormat = 0x04;	pSMB->Tid2 = target_tid;	pSMB->Flags = cpu_to_le16(flags & COPY_TREE);	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {		name_len = cifs_strtoUCS((wchar_t *) pSMB->OldFileName, 				fromName, 				530 /* find define for this maxpathcomponent */,				nls_codepage);		name_len++;     /* trailing null */		name_len *= 2;		pSMB->OldFileName[name_len] = 0x04;     /* pad */		/* protocol requires ASCII signature byte on Unicode string */		pSMB->OldFileName[name_len + 1] = 0x00;		name_len2 = cifs_strtoUCS((wchar_t *) & pSMB->				OldFileName[name_len + 2], toName, 530,				nls_codepage);		name_len2 += 1 /* trailing null */  + 1 /* Signature word */ ;		name_len2 *= 2; /* convert to bytes */	} else {                /* BB improve the check for buffer overruns BB */		name_len = strnlen(fromName, 530);		name_len++;     /* trailing null */		strncpy(pSMB->OldFileName, fromName, name_len);		name_len2 = strnlen(toName, 530);		name_len2++;    /* trailing null */		pSMB->OldFileName[name_len] = 0x04;  /* 2nd buffer format */		strncpy(&pSMB->OldFileName[name_len + 1], toName, name_len2);		name_len2++;    /* trailing null */		name_len2++;    /* signature byte */	}	count = 1 /* 1st signature byte */  + name_len + name_len2;	pSMB->hdr.smb_buf_length += count;	pSMB->ByteCount = cpu_to_le16(count);	rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,		(struct smb_hdr *) pSMBr, &bytes_returned, 0);	if (rc) {		cFYI(1, ("Send error in copy = %d with %d files copied",			rc, le16_to_cpu(pSMBr->CopyCount)));	}	if (pSMB)		cifs_buf_release(pSMB);	if (rc == -EAGAIN)		goto copyRetry;	return rc;}intCIFSUnixCreateSymLink(const int xid, struct cifsTconInfo *tcon,		      const char *fromName, const char *toName,		      const struct nls_table *nls_codepage){	TRANSACTION2_SPI_REQ *pSMB = NULL;	TRANSACTION2_SPI_RSP *pSMBr = NULL;	char *data_offset;	int name_len;	int name_len_target;	int rc = 0;	int bytes_returned = 0;	__u16 params, param_offset, offset, byte_count;	cFYI(1, ("In Symlink Unix style"));createSymLinkRetry:	rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB,		      (void **) &pSMBr);	if (rc)		return rc;	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {		name_len =		    cifs_strtoUCS((wchar_t *) pSMB->FileName, fromName, 530				  /* find define for this maxpathcomponent */				  , nls_codepage);		name_len++;	/* trailing null */		name_len *= 2;	} else {		/* BB improve the check for buffer overruns BB */		name_len = strnlen(fromName, 530);		name_len++;	/* trailing null */		strncpy(pSMB->FileName, fromName, name_len);	}	params = 6 + name_len;	pSMB->MaxSetupCount = 0;	pSMB->Reserved = 0;	pSMB->Flags = 0;	pSMB->Timeout = 0;	pSMB->Reserved2 = 0;	param_offset = offsetof(struct smb_com_transaction2_spi_req,                                     InformationLevel) - 4;	offset = param_offset + params;	data_offset = (char *) (&pSMB->hdr.Protocol) + offset;	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {		name_len_target =		    cifs_strtoUCS((wchar_t *) data_offset, toName, 530				  /* find define for this maxpathcomponent */				  , nls_codepage);		name_len_target++;	/* trailing null */		name_len_target *= 2;	} else {		/* BB improve the check for buffer overruns BB */		name_len_target = strnlen(toName, 530);		name_len_target++;	/* trailing null */		strncpy(data_offset, toName, name_len_target);	}	pSMB->MaxParameterCount = cpu_to_le16(2);	/* BB find exact max on data count below from sess */	pSMB->MaxDataCount = cpu_to_le16(1000);	pSMB->SetupCount = 1;	pSMB->Reserved3 = 0;	pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION);	byte_count = 3 /* pad */  + params + name_len_target;	pSMB->DataCount = cpu_to_le16(name_len_target);	pSMB->ParameterCount = cpu_to_le16(params);	pSMB->TotalDataCount = pSMB->DataCount;	pSMB->TotalParameterCount = pSMB->ParameterCount;	pSMB->ParameterOffset = cpu_to_le16(param_offset);	pSMB->DataOffset = cpu_to_le16(offset);	pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_LINK);	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 SetPathInfo (create symlink) = %d",		      rc));	}	if (pSMB)		cifs_buf_release(pSMB);	if (rc == -EAGAIN)		goto createSymLinkRetry;	return rc;}intCIFSUnixCreateHardLink(const int xid, struct cifsTconInfo *tcon,		       const char *fromName, const char *toName,		       const struct nls_table *nls_codepage){	TRANSACTION2_SPI_REQ *pSMB = NULL;	TRANSACTION2_SPI_RSP *pSMBr = NULL;	char *data_offset;	int name_len;	int name_len_target;	int rc = 0;	int bytes_returned = 0;	__u16 params, param_offset, offset, byte_count;	cFYI(1, ("In Create Hard link Unix style"));createHardLinkRetry:	rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB,		      (void **) &pSMBr);	if (rc)		return rc;	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {		name_len = cifs_strtoUCS((wchar_t *) pSMB->FileName, toName, 530					 /* find define for this maxpathcomponent */					 , nls_codepage);		name_len++;	/* trailing null */		name_len *= 2;	} else {		/* BB improve the check for buffer overruns BB */		name_len = strnlen(toName, 530);		name_len++;	/* trailing null */		strncpy(pSMB->FileName, toName, name_len);	}	params = 6 + name_len;	pSMB->MaxSetupCount = 0;	pSMB->Reserved = 0;	pSMB->Flags = 0;	pSMB->Timeout = 0;	pSMB->Reserved2 = 0;	param_offset = offsetof(struct smb_com_transaction2_spi_req,                                     InformationLevel) - 4;	offset = param_offset + params;	data_offset = (char *) (&pSMB->hdr.Protocol) + offset;	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {		name_len_target =		    cifs_strtoUCS((wchar_t *) data_offset, fromName, 530				  /* find define for this maxpathcomponent */				  , nls_codepage);		name_len_target++;	/* trailing null */		name_len_target *= 2;	} else {		/* BB improve the check for buffer overruns BB */		name_len_target = strnlen(fromName, 530);		name_len_target++;	/* trailing null */		strncpy(data_offset, fromName, name_len_target);	}	pSMB->MaxParameterCount = cpu_to_le16(2);	/* BB find exact max on data count below from sess*/	pSMB->MaxDataCount = cpu_to_le16(1000);	pSMB->SetupCount = 1;	pSMB->Reserved3 = 0;	pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION);	byte_count = 3 /* pad */  + params + name_len_target;	pSMB->ParameterCount = cpu_to_le16(params);	pSMB->TotalParameterCount = pSMB->ParameterCount;	pSMB->DataCount = cpu_to_le16(name_len_target);	pSMB->TotalDataCount = pSMB->DataCount;	pSMB->ParameterOffset = cpu_to_le16(param_offset);	pSMB->DataOffset = cpu_to_le16(offset);	pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_HLINK);	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 SetPathInfo (hard link) = %d", rc));	}	if (pSMB)		cifs_buf_release(pSMB);	if (rc == -EAGAIN)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -