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

📄 cifssmb.c

📁 Linux Kernel 2.6.9 for OMAP1710
💻 C
📖 第 1 页 / 共 5 页
字号:
		goto createHardLinkRetry;	return rc;}intCIFSCreateHardLink(const int xid, struct cifsTconInfo *tcon,		   const char *fromName, const char *toName,		   const struct nls_table *nls_codepage){	int rc = 0;	NT_RENAME_REQ *pSMB = NULL;	RENAME_RSP *pSMBr = NULL;	int bytes_returned;	int name_len, name_len2;	__u16 count;	cFYI(1, ("In CIFSCreateHardLink"));winCreateHardLinkRetry:	rc = smb_init(SMB_COM_NT_RENAME, 4, tcon, (void **) &pSMB,		      (void **) &pSMBr);	if (rc)		return rc;	pSMB->SearchAttributes =	    cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM |			ATTR_DIRECTORY);	pSMB->Flags = cpu_to_le16(CREATE_HARD_LINK);	pSMB->ClusterCount = 0;	pSMB->BufferFormat = 0x04;	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] = 0;	/* pad */		pSMB->OldFileName[name_len + 1] = 0x04; 		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 /* string type 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 hard link (NT rename) = %d", rc));	}	if (pSMB)		cifs_buf_release(pSMB);	if (rc == -EAGAIN)		goto winCreateHardLinkRetry;	return rc;}intCIFSSMBUnixQuerySymLink(const int xid, struct cifsTconInfo *tcon,			const unsigned char *searchName,			char *symlinkinfo, const int buflen,			const struct nls_table *nls_codepage){/* SMB_QUERY_FILE_UNIX_LINK */	TRANSACTION2_QPI_REQ *pSMB = NULL;	TRANSACTION2_QPI_RSP *pSMBr = NULL;	int rc = 0;	int bytes_returned;	int name_len;	__u16 params, byte_count;	cFYI(1, ("In QPathSymLinkInfo (Unix) for path %s", searchName));querySymLinkRetry:	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, searchName, 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(searchName, 530);		name_len++;	/* trailing null */		strncpy(pSMB->FileName, searchName, name_len);	}	params = 2 /* level */  + 4 /* rsrvd */  + name_len /* incl null */ ;	pSMB->TotalDataCount = 0;	pSMB->MaxParameterCount = cpu_to_le16(2);	/* BB find exact max data count below 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_QUERY_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 QuerySymLinkInfo = %d", rc));	} else {		/* decode response */		__u16 data_offset = le16_to_cpu(pSMBr->DataOffset);		__u16 count = le16_to_cpu(pSMBr->DataCount);		if ((pSMBr->ByteCount < 2) || (data_offset > 512))		/* BB also check enough total bytes returned */			rc = -EIO;	/* bad smb */		else {			if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) {				name_len = UniStrnlen((wchar_t *) ((char *)					&pSMBr->hdr.Protocol +data_offset),					min_t(const int, buflen,count) / 2);				cifs_strfromUCS_le(symlinkinfo,					(wchar_t *) ((char *)&pSMBr->hdr.Protocol +						data_offset),					name_len, nls_codepage);			} else {				strncpy(symlinkinfo,					(char *) &pSMBr->hdr.Protocol + 						data_offset,					min_t(const int, buflen, count));			}			symlinkinfo[buflen] = 0;	/* just in case so calling code does not go off the end of buffer */		}	}	if (pSMB)		cifs_buf_release(pSMB);	if (rc == -EAGAIN)		goto querySymLinkRetry;	return rc;}intCIFSSMBQueryReparseLinkInfo(const int xid, struct cifsTconInfo *tcon,			const unsigned char *searchName,			char *symlinkinfo, const int buflen,__u16 fid,			const struct nls_table *nls_codepage){	int rc = 0;	int bytes_returned;	int name_len;	struct smb_com_transaction_ioctl_req * pSMB;	struct smb_com_transaction_ioctl_rsp * pSMBr;	cFYI(1, ("In Windows reparse style QueryLink for path %s", searchName));	rc = smb_init(SMB_COM_NT_TRANSACT, 23, tcon, (void **) &pSMB,		      (void **) &pSMBr);	if (rc)		return rc;	pSMB->TotalParameterCount = 0 ;	pSMB->TotalDataCount = 0;	pSMB->MaxParameterCount = cpu_to_le32(2);	/* BB find exact data count max from sess structure BB */	pSMB->MaxDataCount = cpu_to_le32(4000);	pSMB->MaxSetupCount = 4;	pSMB->Reserved = 0;	pSMB->ParameterOffset = 0;	pSMB->DataCount = 0;	pSMB->DataOffset = 0;	pSMB->SetupCount = 4;	pSMB->SubCommand = cpu_to_le16(NT_TRANSACT_IOCTL);	pSMB->ParameterCount = pSMB->TotalParameterCount;	pSMB->FunctionCode = cpu_to_le32(FSCTL_GET_REPARSE_POINT);	pSMB->IsFsctl = 1; /* FSCTL */	pSMB->IsRootFlag = 0;	pSMB->Fid = fid; /* file handle always le */	pSMB->ByteCount = 0;	rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,			 (struct smb_hdr *) pSMBr, &bytes_returned, 0);	if (rc) {		cFYI(1, ("Send error in QueryReparseLinkInfo = %d", rc));	} else {		/* decode response */		__u32 data_offset = le32_to_cpu(pSMBr->DataOffset);		__u32 data_count = le32_to_cpu(pSMBr->DataCount);		if ((pSMBr->ByteCount < 2) || (data_offset > 512))		/* BB also check enough total bytes returned */			rc = -EIO;	/* bad smb */		else {			if(data_count && (data_count < 2048)) {		/* could also validate reparse tag && better check name length */				struct reparse_data * reparse_buf = (struct reparse_data *)					((char *)&pSMBr->hdr.Protocol + data_offset);				if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) {					name_len = UniStrnlen((wchar_t *)							(reparse_buf->LinkNamesBuf + 							reparse_buf->TargetNameOffset),							min(buflen/2, reparse_buf->TargetNameLen / 2)); 					cifs_strfromUCS_le(symlinkinfo,						(wchar_t *) (reparse_buf->LinkNamesBuf + 						reparse_buf->TargetNameOffset),						name_len, nls_codepage);				} else { /* ASCII names */					strncpy(symlinkinfo,reparse_buf->LinkNamesBuf + 						reparse_buf->TargetNameOffset, 						min_t(const int, buflen, reparse_buf->TargetNameLen));				}			} else {				rc = -EIO;				cFYI(1,("Invalid return data count on get reparse info ioctl"));			}			symlinkinfo[buflen] = 0; /* just in case so the caller					does not go off the end of the buffer */			cFYI(1,("readlink result - %s ",symlinkinfo));		}	}	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;}intCIFSSMBQPathInfo(const int xid, struct cifsTconInfo *tcon,		 const unsigned char *searchName,		 FILE_ALL_INFO * pFindData,		 const struct nls_table *nls_codepage){/* level 263 SMB_QUERY_FILE_ALL_INFO */	TRANSACTION2_QPI_REQ *pSMB = NULL;	TRANSACTION2_QPI_RSP *pSMBr = NULL;	int rc = 0;	int bytes_returned;	int name_len;	__u16 params, byte_count;	cFYI(1, ("In QPathInfo path %s", searchName));QPathInfoRetry:	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, searchName, 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(searchName, 530);		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);	pSMB->MaxDataCount = cpu_to_le16(4000);	/* BB find exact max SMB PDU from sess structure BB */	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_QUERY_FILE_ALL_INFO);	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 QPathInfo = %d", rc));	} else {		/* decode response */		__u16 data_offset = le16_to_cpu(pSMBr->DataOffset);		/* BB also check enough total bytes returned */		/* BB we need to improve the validity checking		of these trans2 responses */		if ((pSMBr->ByteCount < 40) || (data_offset > 512)) 			rc = -EIO;	/* bad smb */		else if (pFindData){			memcpy((char *) pFindData,			       (char *) &pSMBr->hdr.Protocol +			       data_offset, sizeof (FILE_ALL_INFO));		} else		    rc = -ENOMEM;	}	if (pSMB)		cifs_buf_release(pSMB);	if (rc == -EAGAIN)		goto QPathInfoRetry;	return rc;}intCIFSSMBUnixQPathInfo(const int xid, struct cifsTconInfo *tcon,		     const unsigned char *searchName,		     FILE_UNIX_BASIC_INFO * pFindData,		     const struct nls_table *nls_codepage){/* SMB_QUERY_FILE_UNIX_BASIC */	TRANSACTION2_QPI_REQ *pSMB = NULL;	TRANSACTION2_QPI_RSP *pSMBr = NULL;	int rc = 0;	int bytes_returned = 0;	int name_len;	__u16 params, byte_count;	cFYI(1, ("In QPathInfo (Unix) the path %s", searchName));UnixQPathInfoRetry:	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, searchName, 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(searchName, 530);		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_QUERY_FILE_UNIX_BASIC);	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 QPathInfo = %d", rc));	} else {		/* decode response */		__u16 data_offset = le16_to_cpu(pSMBr->DataOffset);		/* BB also check if enough total bytes returned */		if ((pSMBr->ByteCount < sizeof(FILE_UNIX_BASIC_INFO)) || 			(data_offset > 512) || 			(data_offset < sizeof(struct smb_hdr))) {			cFYI(1,("UnixQPathinfo invalid data offset %d bytes returned %d",					(int)data_offset,bytes_returned));			rc = -EIO;	/* bad smb */		} else {			memcpy((char *) pFindData,			       (char *) &pSMBr->hdr.Protocol +			       data_offset,			       sizeof (FILE_UNIX_BASIC_INFO));		}	}	if (pSMB)		cifs_buf_release(pSMB);	if (rc == -EAGAIN)		goto UnixQPathInfoRetry;	return rc;}int

⌨️ 快捷键说明

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