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

📄 cifssmb.c

📁 Linux内核自带的cifs模块
💻 C
📖 第 1 页 / 共 5 页
字号:
		pSMB->Locks[0].LengthLow = cpu_to_le32((u32)len);		pSMB->Locks[0].LengthHigh = cpu_to_le32((u32)(len>>32));		pSMB->Locks[0].OffsetLow = cpu_to_le32((u32)offset);		pSMB->Locks[0].OffsetHigh = cpu_to_le32((u32)(offset>>32));		count = sizeof(LOCKING_ANDX_RANGE);	} else {		/* oplock break */		count = 0;	}	pSMB->hdr.smb_buf_length += count;	pSMB->ByteCount = cpu_to_le16(count);	if (waitFlag) {		rc = SendReceiveBlockingLock(xid, tcon, (struct smb_hdr *) pSMB,			(struct smb_hdr *) pSMBr, &bytes_returned);	} else {		rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,			 (struct smb_hdr *) pSMBr, &bytes_returned, timeout);	}	cifs_stats_inc(&tcon->num_locks);	if (rc) {		cFYI(1, ("Send error in Lock = %d", rc));	}	cifs_small_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;}intCIFSSMBPosixLock(const int xid, struct cifsTconInfo *tcon,		const __u16 smb_file_id, const int get_flag, const __u64 len,		struct file_lock *pLockData, const __u16 lock_type,		const int waitFlag){	struct smb_com_transaction2_sfi_req *pSMB  = NULL;	struct smb_com_transaction2_sfi_rsp *pSMBr = NULL;	struct cifs_posix_lock *parm_data;	int rc = 0;	int timeout = 0;	int bytes_returned = 0;	__u16 params, param_offset, offset, byte_count, count;	cFYI(1, ("Posix Lock"));	if (pLockData == NULL)		return EINVAL;	rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB);	if (rc)		return rc;	pSMBr = (struct smb_com_transaction2_sfi_rsp *)pSMB;	params = 6;	pSMB->MaxSetupCount = 0;	pSMB->Reserved = 0;	pSMB->Flags = 0;	pSMB->Reserved2 = 0;	param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4;	offset = param_offset + params;	count = sizeof(struct cifs_posix_lock);	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;	if (get_flag)		pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION);	else		pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION);	byte_count = 3 /* pad */  + params + count;	pSMB->DataCount = cpu_to_le16(count);	pSMB->ParameterCount = cpu_to_le16(params);	pSMB->TotalDataCount = pSMB->DataCount;	pSMB->TotalParameterCount = pSMB->ParameterCount;	pSMB->ParameterOffset = cpu_to_le16(param_offset);	parm_data = (struct cifs_posix_lock *)			(((char *) &pSMB->hdr.Protocol) + offset);	parm_data->lock_type = cpu_to_le16(lock_type);	if (waitFlag) {		timeout = 3;  /* blocking operation, no timeout */		parm_data->lock_flags = cpu_to_le16(1);		pSMB->Timeout = cpu_to_le32(-1);	} else		pSMB->Timeout = 0;	parm_data->pid = cpu_to_le32(current->tgid);	parm_data->start = cpu_to_le64(pLockData->fl_start);	parm_data->length = cpu_to_le64(len);  /* normalize negative numbers */	pSMB->DataOffset = cpu_to_le16(offset);	pSMB->Fid = smb_file_id;	pSMB->InformationLevel = cpu_to_le16(SMB_SET_POSIX_LOCK);	pSMB->Reserved4 = 0;	pSMB->hdr.smb_buf_length += byte_count;	pSMB->ByteCount = cpu_to_le16(byte_count);	if (waitFlag) {		rc = SendReceiveBlockingLock(xid, tcon, (struct smb_hdr *) pSMB,			(struct smb_hdr *) pSMBr, &bytes_returned);	} else {		rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,			(struct smb_hdr *) pSMBr, &bytes_returned, timeout);	}	if (rc) {		cFYI(1, ("Send error in Posix Lock = %d", rc));	} else if (get_flag) {		/* lock structure can be returned on get */		__u16 data_offset;		__u16 data_count;		rc = validate_t2((struct smb_t2_rsp *)pSMBr);		if (rc || (pSMBr->ByteCount < sizeof(struct cifs_posix_lock))) {			rc = -EIO;      /* bad smb */			goto plk_err_exit;		}		if (pLockData == NULL) {			rc = -EINVAL;			goto plk_err_exit;		}		data_offset = le16_to_cpu(pSMBr->t2.DataOffset);		data_count  = le16_to_cpu(pSMBr->t2.DataCount);		if (data_count < sizeof(struct cifs_posix_lock)) {			rc = -EIO;			goto plk_err_exit;		}		parm_data = (struct cifs_posix_lock *)			((char *)&pSMBr->hdr.Protocol + data_offset);		if (parm_data->lock_type == cpu_to_le16(CIFS_UNLCK))			pLockData->fl_type = F_UNLCK;	}plk_err_exit:	if (pSMB)		cifs_small_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;}intCIFSSMBClose(const int xid, struct cifsTconInfo *tcon, int smb_file_id){	int rc = 0;	CLOSE_REQ *pSMB = NULL;	CLOSE_RSP *pSMBr = NULL;	int bytes_returned;	cFYI(1, ("In CIFSSMBClose"));/* do not retry on dead session on close */	rc = small_smb_init(SMB_COM_CLOSE, 3, tcon, (void **) &pSMB);	if (rc == -EAGAIN)		return 0;	if (rc)		return rc;	pSMBr = (CLOSE_RSP *)pSMB; /* BB removeme BB */	pSMB->FileID = (__u16) smb_file_id;	pSMB->LastWriteTime = 0xFFFFFFFF;	pSMB->ByteCount = 0;	rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,			 (struct smb_hdr *) pSMBr, &bytes_returned, 0);	cifs_stats_inc(&tcon->num_closes);	if (rc) {		if (rc != -EINTR) {			/* EINTR is expected when user ctl-c to kill app */			cERROR(1, ("Send error in Close = %d", rc));		}	}	cifs_small_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 remap){	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 =		    cifsConvertToUCS((__le16 *) pSMB->OldFileName, fromName,				     PATH_MAX, nls_codepage, remap);		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 =		    cifsConvertToUCS((__le16 *) &pSMB->OldFileName[name_len + 2],				     toName, PATH_MAX, nls_codepage, remap);		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, PATH_MAX);		name_len++;	/* trailing null */		strncpy(pSMB->OldFileName, fromName, name_len);		name_len2 = strnlen(toName, PATH_MAX);		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);	cifs_stats_inc(&tcon->num_renames);	if (rc) {		cFYI(1, ("Send error in rename = %d", rc));	}	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, int remap){	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 = cifsConvertToUCS((__le16 *)rename_info->target_name,					dummy_string, 24, nls_codepage, remap);	} else {		len_of_str = cifsConvertToUCS((__le16 *)rename_info->target_name,					target_name, PATH_MAX, nls_codepage,					remap);	}	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);	cifs_stats_inc(&pTcon->num_t2renames);	if (rc) {		cFYI(1, ("Send error in Rename (by file handle) = %d", rc));	}	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 remap){	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 = cifsConvertToUCS((__le16 *) pSMB->OldFileName,					    fromName, PATH_MAX, nls_codepage,					    remap);		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 =		    cifsConvertToUCS((__le16 *)&pSMB->OldFileName[name_len + 2],				toName, PATH_MAX, nls_codepage, remap);		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, PATH_MAX);		name_len++;     /* trailing null */		strncpy(pSMB->OldFileName, fromName, name_len);		name_len2 = strnlen(toName, PATH_MAX);		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((__le16 *) pSMB->FileName, fromName, PATH_MAX				  /* find define for

⌨️ 快捷键说明

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