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

📄 cifssmb.c

📁 Linux内核自带的cifs模块
💻 C
📖 第 1 页 / 共 5 页
字号:
	pSMB->DataCount = cpu_to_le16(sizeof(struct unlink_psx_rq));	pSMB->TotalDataCount = cpu_to_le16(sizeof(struct unlink_psx_rq));	pSMB->ParameterCount = cpu_to_le16(params);	pSMB->TotalParameterCount = pSMB->ParameterCount;	pSMB->InformationLevel = cpu_to_le16(SMB_POSIX_UNLINK);	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, ("Posix delete returned %d", rc));	}	cifs_buf_release(pSMB);	cifs_stats_inc(&tcon->num_deletes);	if (rc == -EAGAIN)		goto PsxDelete;	return rc;}intCIFSSMBDelFile(const int xid, struct cifsTconInfo *tcon, const char *fileName,		const struct nls_table *nls_codepage, int remap){	DELETE_FILE_REQ *pSMB = NULL;	DELETE_FILE_RSP *pSMBr = NULL;	int rc = 0;	int bytes_returned;	int name_len;DelFileRetry:	rc = smb_init(SMB_COM_DELETE, 1, tcon, (void **) &pSMB,		      (void **) &pSMBr);	if (rc)		return rc;	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {		name_len =		    cifsConvertToUCS((__le16 *) pSMB->fileName, fileName,				     PATH_MAX, nls_codepage, remap);		name_len++;	/* trailing null */		name_len *= 2;	} else {		/* BB improve check for buffer overruns BB */		name_len = strnlen(fileName, PATH_MAX);		name_len++;	/* trailing null */		strncpy(pSMB->fileName, fileName, name_len);	}	pSMB->SearchAttributes =	    cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM);	pSMB->BufferFormat = 0x04;	pSMB->hdr.smb_buf_length += name_len + 1;	pSMB->ByteCount = cpu_to_le16(name_len + 1);	rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,			 (struct smb_hdr *) pSMBr, &bytes_returned, 0);	cifs_stats_inc(&tcon->num_deletes);	if (rc) {		cFYI(1, ("Error in RMFile = %d", rc));	}	cifs_buf_release(pSMB);	if (rc == -EAGAIN)		goto DelFileRetry;	return rc;}intCIFSSMBRmDir(const int xid, struct cifsTconInfo *tcon, const char *dirName,	     const struct nls_table *nls_codepage, int remap){	DELETE_DIRECTORY_REQ *pSMB = NULL;	DELETE_DIRECTORY_RSP *pSMBr = NULL;	int rc = 0;	int bytes_returned;	int name_len;	cFYI(1, ("In CIFSSMBRmDir"));RmDirRetry:	rc = smb_init(SMB_COM_DELETE_DIRECTORY, 0, tcon, (void **) &pSMB,		      (void **) &pSMBr);	if (rc)		return rc;	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {		name_len = cifsConvertToUCS((__le16 *) pSMB->DirName, dirName,					 PATH_MAX, nls_codepage, remap);		name_len++;	/* trailing null */		name_len *= 2;	} else {		/* BB improve check for buffer overruns BB */		name_len = strnlen(dirName, PATH_MAX);		name_len++;	/* trailing null */		strncpy(pSMB->DirName, dirName, name_len);	}	pSMB->BufferFormat = 0x04;	pSMB->hdr.smb_buf_length += name_len + 1;	pSMB->ByteCount = cpu_to_le16(name_len + 1);	rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,			 (struct smb_hdr *) pSMBr, &bytes_returned, 0);	cifs_stats_inc(&tcon->num_rmdirs);	if (rc) {		cFYI(1, ("Error in RMDir = %d", rc));	}	cifs_buf_release(pSMB);	if (rc == -EAGAIN)		goto RmDirRetry;	return rc;}intCIFSSMBMkDir(const int xid, struct cifsTconInfo *tcon,	     const char *name, const struct nls_table *nls_codepage, int remap){	int rc = 0;	CREATE_DIRECTORY_REQ *pSMB = NULL;	CREATE_DIRECTORY_RSP *pSMBr = NULL;	int bytes_returned;	int name_len;	cFYI(1, ("In CIFSSMBMkDir"));MkDirRetry:	rc = smb_init(SMB_COM_CREATE_DIRECTORY, 0, tcon, (void **) &pSMB,		      (void **) &pSMBr);	if (rc)		return rc;	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {		name_len = cifsConvertToUCS((__le16 *) pSMB->DirName, name,					    PATH_MAX, nls_codepage, remap);		name_len++;	/* trailing null */		name_len *= 2;	} else {		/* BB improve check for buffer overruns BB */		name_len = strnlen(name, PATH_MAX);		name_len++;	/* trailing null */		strncpy(pSMB->DirName, name, name_len);	}	pSMB->BufferFormat = 0x04;	pSMB->hdr.smb_buf_length += name_len + 1;	pSMB->ByteCount = cpu_to_le16(name_len + 1);	rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,			 (struct smb_hdr *) pSMBr, &bytes_returned, 0);	cifs_stats_inc(&tcon->num_mkdirs);	if (rc) {		cFYI(1, ("Error in Mkdir = %d", rc));	}	cifs_buf_release(pSMB);	if (rc == -EAGAIN)		goto MkDirRetry;	return rc;}intCIFSPOSIXCreate(const int xid, struct cifsTconInfo *tcon, __u32 posix_flags,		__u64 mode, __u16 * netfid, FILE_UNIX_BASIC_INFO *pRetData,		__u32 *pOplock, const char *name,		const struct nls_table *nls_codepage, int remap){	TRANSACTION2_SPI_REQ *pSMB = NULL;	TRANSACTION2_SPI_RSP *pSMBr = NULL;	int name_len;	int rc = 0;	int bytes_returned = 0;	__u16 params, param_offset, offset, byte_count, count;	OPEN_PSX_REQ * pdata;	OPEN_PSX_RSP * psx_rsp;	cFYI(1, ("In POSIX Create"));PsxCreat:	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, name,				     PATH_MAX, nls_codepage, remap);		name_len++;	/* trailing null */		name_len *= 2;	} else {	/* BB improve the check for buffer overruns BB */		name_len = strnlen(name, PATH_MAX);		name_len++;	/* trailing null */		strncpy(pSMB->FileName, name, name_len);	}	params = 6 + name_len;	count = sizeof(OPEN_PSX_REQ);	pSMB->MaxParameterCount = cpu_to_le16(2);	pSMB->MaxDataCount = cpu_to_le16(1000);	/* large enough */	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;	pdata = (OPEN_PSX_REQ *)(((char *)&pSMB->hdr.Protocol) + offset);	pdata->Level = SMB_QUERY_FILE_UNIX_BASIC;	pdata->Permissions = cpu_to_le64(mode);	pdata->PosixOpenFlags = cpu_to_le32(posix_flags);	pdata->OpenFlags =  cpu_to_le32(*pOplock);	pSMB->ParameterOffset = cpu_to_le16(param_offset);	pSMB->DataOffset = cpu_to_le16(offset);	pSMB->SetupCount = 1;	pSMB->Reserved3 = 0;	pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_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->InformationLevel = cpu_to_le16(SMB_POSIX_OPEN);	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, ("Posix create returned %d", rc));		goto psx_create_err;	}	cFYI(1, ("copying inode info"));	rc = validate_t2((struct smb_t2_rsp *)pSMBr);	if (rc || (pSMBr->ByteCount < sizeof(OPEN_PSX_RSP))) {		rc = -EIO;	/* bad smb */		goto psx_create_err;	}	/* copy return information to pRetData */	psx_rsp = (OPEN_PSX_RSP *)((char *) &pSMBr->hdr.Protocol			+ le16_to_cpu(pSMBr->t2.DataOffset));	*pOplock = le16_to_cpu(psx_rsp->OplockFlags);	if (netfid)		*netfid = psx_rsp->Fid;   /* cifs fid stays in le */	/* 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) == psx_rsp->CreateAction)		*pOplock |= CIFS_CREATE_ACTION;	/* check to make sure response data is there */	if (psx_rsp->ReturnedLevel != SMB_QUERY_FILE_UNIX_BASIC) {		pRetData->Type = -1; /* unknown */#ifdef CONFIG_CIFS_DEBUG2		cFYI(1, ("unknown type"));#endif	} else {		if (pSMBr->ByteCount < sizeof(OPEN_PSX_RSP)					+ sizeof(FILE_UNIX_BASIC_INFO)) {			cERROR(1, ("Open response data too small"));			pRetData->Type = -1;			goto psx_create_err;		}		memcpy((char *) pRetData,			(char *)psx_rsp + sizeof(OPEN_PSX_RSP),			sizeof(FILE_UNIX_BASIC_INFO));	}psx_create_err:	cifs_buf_release(pSMB);	cifs_stats_inc(&tcon->num_mkdirs);	if (rc == -EAGAIN)		goto PsxCreat;	return rc;}static __u16 convert_disposition(int disposition){	__u16 ofun = 0;	switch (disposition) {		case FILE_SUPERSEDE:			ofun = SMBOPEN_OCREATE | SMBOPEN_OTRUNC;			break;		case FILE_OPEN:			ofun = SMBOPEN_OAPPEND;			break;		case FILE_CREATE:			ofun = SMBOPEN_OCREATE;			break;		case FILE_OPEN_IF:			ofun = SMBOPEN_OCREATE | SMBOPEN_OAPPEND;			break;		case FILE_OVERWRITE:			ofun = SMBOPEN_OTRUNC;			break;		case FILE_OVERWRITE_IF:			ofun = SMBOPEN_OCREATE | SMBOPEN_OTRUNC;			break;		default:			cFYI(1, ("unknown disposition %d", disposition));			ofun =  SMBOPEN_OAPPEND; /* regular open */	}	return ofun;}intSMBLegacyOpen(const int xid, struct cifsTconInfo *tcon,	    const char *fileName, const int openDisposition,	    const int access_flags, const int create_options, __u16 * netfid,	    int *pOplock, FILE_ALL_INFO * pfile_info,	    const struct nls_table *nls_codepage, int remap){	int rc = -EACCES;	OPENX_REQ *pSMB = NULL;	OPENX_RSP *pSMBr = NULL;	int bytes_returned;	int name_len;	__u16 count;OldOpenRetry:	rc = smb_init(SMB_COM_OPEN_ANDX, 15, tcon, (void **) &pSMB,		      (void **) &pSMBr);	if (rc)		return rc;	pSMB->AndXCommand = 0xFF;       /* none */	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {		count = 1;      /* account for one byte pad to word boundary */		name_len =		   cifsConvertToUCS((__le16 *) (pSMB->fileName + 1),				    fileName, PATH_MAX, nls_codepage, remap);		name_len++;     /* trailing null */		name_len *= 2;	} else {                /* BB improve check for buffer overruns BB */		count = 0;      /* no pad */		name_len = strnlen(fileName, PATH_MAX);		name_len++;     /* trailing null */		strncpy(pSMB->fileName, fileName, name_len);	}	if (*pOplock & REQ_OPLOCK)		pSMB->OpenFlags = cpu_to_le16(REQ_OPLOCK);	else if (*pOplock & REQ_BATCHOPLOCK)		pSMB->OpenFlags = cpu_to_le16(REQ_BATCHOPLOCK);	pSMB->OpenFlags |= cpu_to_le16(REQ_MORE_INFO);	/* BB fixme add conversion for access_flags to bits 0 - 2 of mode */	/* 0 = read	   1 = write	   2 = rw	   3 = execute	 */	pSMB->Mode = cpu_to_le16(2);	pSMB->Mode |= cpu_to_le16(0x40); /* deny none */	/* 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)		pSMB->FileAttributes = cpu_to_le16(ATTR_SYSTEM);	else                pSMB->FileAttributes = cpu_to_le16(0/*ATTR_NORMAL*/); /* BB FIXME */	/* if ((omode & S_IWUGO) == 0)		pSMB->FileAttributes |= cpu_to_le32(ATTR_READONLY);*/	/*  Above line causes problems due to vfs splitting create into two	    pieces - need to set mode after file created not while it is	    being created */	/* BB FIXME BB *//*	pSMB->CreateOptions = cpu_to_le32(create_options &						 CREATE_OPTIONS_MASK); */	/* BB FIXME END BB */	pSMB->Sattr = cpu_to_le16(ATTR_HIDDEN | ATTR_SYSTEM | ATTR_DIRECTORY);	pSMB->OpenFunction = cpu_to_le16(convert_disposition(openDisposition));	count += name_len;	pSMB->hdr.smb_buf_length += count;	pSMB->ByteCount = cpu_to_le16(count);	/* long_op set to 1 to allow for oplock break timeouts */	rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,			 (struct smb_hdr *) pSMBr, &bytes_returned, 1);	cifs_stats_inc(&tcon->num_opens);	if (rc) {		cFYI(1, ("Error in Open = %d", rc));	} else {	/* BB verify if wct == 15 *//*		*pOplock = pSMBr->OplockLevel; */  /* BB take from action field BB */		*netfid = pSMBr->Fid;   /* cifs fid stays in le */		/* Let caller know file was created so we can set the mode. */		/* Do we care about the CreateAction in any other cases? */	/* BB FIXME BB *//*		if (cpu_to_le32(FILE_CREATE) == pSMBr->CreateAction)			*pOplock |= CIFS_CREATE_ACTION; */	/* BB FIXME END */		if (pfile_info) {			pfile_info->CreationTime = 0; /* BB convert CreateTime*/			pfile_info->LastAccessTime = 0; /* BB fixme */			pfile_info->LastWriteTime = 0; /* BB fixme */			pfile_info->ChangeTime = 0;  /* BB fixme */			pfile_info->Attributes =				cpu_to_le32(le16_to_cpu(pSMBr->FileAttributes));			/* the file_info buf is endian converted by caller */			pfile_info->AllocationSize =				cpu_to_le64(le32_to_cpu(pSMBr->EndOfFile));			pfile_info->EndOfFile = pfile_info->AllocationSize;			pfile_info->NumberOfLinks = cpu_to_le32(1);		}	}	cifs_buf_release(pSMB);	if (rc == -EAGAIN)		goto OldOpenRetry;	return rc;}intCIFSSMBOpen(const int xid, struct cifsTconInfo *tcon,	    const char *fileName, const int openDisposition,	    const int access_flags, const int create_options, __u16 * netfid,	    int *pOplock, FILE_ALL_INFO * pfile_info,	    const struct nls_table *nls_codepage, int remap){	int rc = -EACCES;	OPEN_REQ *pSMB = NULL;

⌨️ 快捷键说明

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