4 * Copyright (C) International Business Machines Corp., 2002,2005
5 * Author(s): Steve French (sfrench@us.ibm.com)
7 * Contains the routines for constructing the SMB PDUs themselves
9 * This library is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as published
11 * by the Free Software Foundation; either version 2.1 of the License, or
12 * (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
17 * the GNU Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 /* SMB/CIFS PDU handling routines here - except for leftovers in connect.c */
25 /* These are mostly routines that operate on a pathname, or on a tree id */
26 /* (mounted volume), but there are eight handle based routines which must be */
27 /* treated slightly different for reconnection purposes since we never want */
28 /* to reuse a stale file handle and the caller knows the file handle */
31 #include <linux/kernel.h>
32 #include <linux/vfs.h>
33 #include <linux/posix_acl_xattr.h>
34 #include <asm/uaccess.h>
37 #include "cifsproto.h"
38 #include "cifs_unicode.h"
39 #include "cifs_debug.h"
41 #ifdef CONFIG_CIFS_POSIX
46 {CIFS_PROT
, "\2NT LM 0.12"},
47 {CIFS_PROT
, "\2POSIX 2"},
55 {CIFS_PROT
, "\2NT LM 0.12"},
61 /* Mark as invalid, all open files on tree connections since they
62 were closed when session to server was lost */
63 static void mark_open_files_invalid(struct cifsTconInfo
* pTcon
)
65 struct cifsFileInfo
*open_file
= NULL
;
66 struct list_head
* tmp
;
67 struct list_head
* tmp1
;
69 /* list all files open on tree connection and mark them invalid */
70 write_lock(&GlobalSMBSeslock
);
71 list_for_each_safe(tmp
, tmp1
, &pTcon
->openFileList
) {
72 open_file
= list_entry(tmp
,struct cifsFileInfo
, tlist
);
74 open_file
->invalidHandle
= TRUE
;
77 write_unlock(&GlobalSMBSeslock
);
78 /* BB Add call to invalidate_inodes(sb) for all superblocks mounted
82 /* If the return code is zero, this function must fill in request_buf pointer */
84 small_smb_init(int smb_command
, int wct
, struct cifsTconInfo
*tcon
,
85 void **request_buf
/* returned */)
89 /* SMBs NegProt, SessSetup, uLogoff do not have tcon yet so
90 check for tcp and smb session status done differently
91 for those three - in the calling routine */
93 if(tcon
->tidStatus
== CifsExiting
) {
94 /* only tree disconnect, open, and write,
95 (and ulogoff which does not have tcon)
96 are allowed as we start force umount */
97 if((smb_command
!= SMB_COM_WRITE_ANDX
) &&
98 (smb_command
!= SMB_COM_OPEN_ANDX
) &&
99 (smb_command
!= SMB_COM_TREE_DISCONNECT
)) {
100 cFYI(1,("can not send cmd %d while umounting",
105 if((tcon
->ses
) && (tcon
->ses
->status
!= CifsExiting
) &&
106 (tcon
->ses
->server
)){
107 struct nls_table
*nls_codepage
;
108 /* Give Demultiplex thread up to 10 seconds to
109 reconnect, should be greater than cifs socket
110 timeout which is 7 seconds */
111 while(tcon
->ses
->server
->tcpStatus
== CifsNeedReconnect
) {
112 wait_event_interruptible_timeout(tcon
->ses
->server
->response_q
,
113 (tcon
->ses
->server
->tcpStatus
== CifsGood
), 10 * HZ
);
114 if(tcon
->ses
->server
->tcpStatus
== CifsNeedReconnect
) {
115 /* on "soft" mounts we wait once */
116 if((tcon
->retry
== FALSE
) ||
117 (tcon
->ses
->status
== CifsExiting
)) {
118 cFYI(1,("gave up waiting on reconnect in smb_init"));
120 } /* else "hard" mount - keep retrying
121 until process is killed or server
122 comes back on-line */
123 } else /* TCP session is reestablished now */
128 nls_codepage
= load_nls_default();
129 /* need to prevent multiple threads trying to
130 simultaneously reconnect the same SMB session */
131 down(&tcon
->ses
->sesSem
);
132 if(tcon
->ses
->status
== CifsNeedReconnect
)
133 rc
= cifs_setup_session(0, tcon
->ses
,
135 if(!rc
&& (tcon
->tidStatus
== CifsNeedReconnect
)) {
136 mark_open_files_invalid(tcon
);
137 rc
= CIFSTCon(0, tcon
->ses
, tcon
->treeName
, tcon
139 up(&tcon
->ses
->sesSem
);
140 /* BB FIXME add code to check if wsize needs
141 update due to negotiated smb buffer size
144 atomic_inc(&tconInfoReconnectCount
);
146 cFYI(1, ("reconnect tcon rc = %d", rc
));
147 /* Removed call to reopen open files here -
148 it is safer (and faster) to reopen files
149 one at a time as needed in read and write */
151 /* Check if handle based operation so we
152 know whether we can continue or not without
153 returning to caller to reset file handle */
154 switch(smb_command
) {
155 case SMB_COM_READ_ANDX
:
156 case SMB_COM_WRITE_ANDX
:
158 case SMB_COM_FIND_CLOSE2
:
159 case SMB_COM_LOCKING_ANDX
: {
160 unload_nls(nls_codepage
);
165 up(&tcon
->ses
->sesSem
);
167 unload_nls(nls_codepage
);
176 *request_buf
= cifs_small_buf_get();
177 if (*request_buf
== NULL
) {
178 /* BB should we add a retry in here if not a writepage? */
182 header_assemble((struct smb_hdr
*) *request_buf
, smb_command
, tcon
,wct
);
185 cifs_stats_inc(&tcon
->num_smbs_sent
);
190 /* If the return code is zero, this function must fill in request_buf pointer */
192 smb_init(int smb_command
, int wct
, struct cifsTconInfo
*tcon
,
193 void **request_buf
/* returned */ ,
194 void **response_buf
/* returned */ )
198 /* SMBs NegProt, SessSetup, uLogoff do not have tcon yet so
199 check for tcp and smb session status done differently
200 for those three - in the calling routine */
202 if(tcon
->tidStatus
== CifsExiting
) {
203 /* only tree disconnect, open, and write,
204 (and ulogoff which does not have tcon)
205 are allowed as we start force umount */
206 if((smb_command
!= SMB_COM_WRITE_ANDX
) &&
207 (smb_command
!= SMB_COM_OPEN_ANDX
) &&
208 (smb_command
!= SMB_COM_TREE_DISCONNECT
)) {
209 cFYI(1,("can not send cmd %d while umounting",
215 if((tcon
->ses
) && (tcon
->ses
->status
!= CifsExiting
) &&
216 (tcon
->ses
->server
)){
217 struct nls_table
*nls_codepage
;
218 /* Give Demultiplex thread up to 10 seconds to
219 reconnect, should be greater than cifs socket
220 timeout which is 7 seconds */
221 while(tcon
->ses
->server
->tcpStatus
== CifsNeedReconnect
) {
222 wait_event_interruptible_timeout(tcon
->ses
->server
->response_q
,
223 (tcon
->ses
->server
->tcpStatus
== CifsGood
), 10 * HZ
);
224 if(tcon
->ses
->server
->tcpStatus
==
226 /* on "soft" mounts we wait once */
227 if((tcon
->retry
== FALSE
) ||
228 (tcon
->ses
->status
== CifsExiting
)) {
229 cFYI(1,("gave up waiting on reconnect in smb_init"));
231 } /* else "hard" mount - keep retrying
232 until process is killed or server
234 } else /* TCP session is reestablished now */
239 nls_codepage
= load_nls_default();
240 /* need to prevent multiple threads trying to
241 simultaneously reconnect the same SMB session */
242 down(&tcon
->ses
->sesSem
);
243 if(tcon
->ses
->status
== CifsNeedReconnect
)
244 rc
= cifs_setup_session(0, tcon
->ses
,
246 if(!rc
&& (tcon
->tidStatus
== CifsNeedReconnect
)) {
247 mark_open_files_invalid(tcon
);
248 rc
= CIFSTCon(0, tcon
->ses
, tcon
->treeName
,
250 up(&tcon
->ses
->sesSem
);
251 /* BB FIXME add code to check if wsize needs
252 update due to negotiated smb buffer size
255 atomic_inc(&tconInfoReconnectCount
);
257 cFYI(1, ("reconnect tcon rc = %d", rc
));
258 /* Removed call to reopen open files here -
259 it is safer (and faster) to reopen files
260 one at a time as needed in read and write */
262 /* Check if handle based operation so we
263 know whether we can continue or not without
264 returning to caller to reset file handle */
265 switch(smb_command
) {
266 case SMB_COM_READ_ANDX
:
267 case SMB_COM_WRITE_ANDX
:
269 case SMB_COM_FIND_CLOSE2
:
270 case SMB_COM_LOCKING_ANDX
: {
271 unload_nls(nls_codepage
);
276 up(&tcon
->ses
->sesSem
);
278 unload_nls(nls_codepage
);
287 *request_buf
= cifs_buf_get();
288 if (*request_buf
== NULL
) {
289 /* BB should we add a retry in here if not a writepage? */
292 /* Although the original thought was we needed the response buf for */
293 /* potential retries of smb operations it turns out we can determine */
294 /* from the mid flags when the request buffer can be resent without */
295 /* having to use a second distinct buffer for the response */
296 *response_buf
= *request_buf
;
298 header_assemble((struct smb_hdr
*) *request_buf
, smb_command
, tcon
,
302 cifs_stats_inc(&tcon
->num_smbs_sent
);
307 static int validate_t2(struct smb_t2_rsp
* pSMB
)
313 /* check for plausible wct, bcc and t2 data and parm sizes */
314 /* check for parm and data offset going beyond end of smb */
315 if(pSMB
->hdr
.WordCount
>= 10) {
316 if((le16_to_cpu(pSMB
->t2_rsp
.ParameterOffset
) <= 1024) &&
317 (le16_to_cpu(pSMB
->t2_rsp
.DataOffset
) <= 1024)) {
318 /* check that bcc is at least as big as parms + data */
319 /* check that bcc is less than negotiated smb buffer */
320 total_size
= le16_to_cpu(pSMB
->t2_rsp
.ParameterCount
);
321 if(total_size
< 512) {
322 total_size
+=le16_to_cpu(pSMB
->t2_rsp
.DataCount
);
323 /* BCC le converted in SendReceive */
324 pBCC
= (pSMB
->hdr
.WordCount
* 2) +
325 sizeof(struct smb_hdr
) +
327 if((total_size
<= (*(u16
*)pBCC
)) &&
329 CIFSMaxBufSize
+MAX_CIFS_HDR_SIZE
)) {
336 cifs_dump_mem("Invalid transact2 SMB: ",(char *)pSMB
,
337 sizeof(struct smb_t2_rsp
) + 16);
341 CIFSSMBNegotiate(unsigned int xid
, struct cifsSesInfo
*ses
)
344 NEGOTIATE_RSP
*pSMBr
;
347 struct TCP_Server_Info
* server
;
351 server
= ses
->server
;
356 rc
= smb_init(SMB_COM_NEGOTIATE
, 0, NULL
/* no tcon yet */ ,
357 (void **) &pSMB
, (void **) &pSMBr
);
360 pSMB
->hdr
.Mid
= GetNextMid(server
);
361 pSMB
->hdr
.Flags2
|= SMBFLG2_UNICODE
;
362 if (extended_security
)
363 pSMB
->hdr
.Flags2
|= SMBFLG2_EXT_SEC
;
365 count
= strlen(protocols
[0].name
) + 1;
366 strncpy(pSMB
->DialectsArray
, protocols
[0].name
, 30);
367 /* null guaranteed to be at end of source and target buffers anyway */
369 pSMB
->hdr
.smb_buf_length
+= count
;
370 pSMB
->ByteCount
= cpu_to_le16(count
);
372 rc
= SendReceive(xid
, ses
, (struct smb_hdr
*) pSMB
,
373 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
375 server
->secMode
= pSMBr
->SecurityMode
;
376 server
->secType
= NTLM
; /* BB override default for
377 NTLMv2 or kerberos v5 */
378 /* one byte - no need to convert this or EncryptionKeyLen
379 from little endian */
380 server
->maxReq
= le16_to_cpu(pSMBr
->MaxMpxCount
);
381 /* probably no need to store and check maxvcs */
383 min(le32_to_cpu(pSMBr
->MaxBufferSize
),
384 (__u32
) CIFSMaxBufSize
+ MAX_CIFS_HDR_SIZE
);
385 server
->maxRw
= le32_to_cpu(pSMBr
->MaxRawSize
);
386 cFYI(0, ("Max buf = %d ", ses
->server
->maxBuf
));
387 GETU32(ses
->server
->sessid
) = le32_to_cpu(pSMBr
->SessionKey
);
388 server
->capabilities
= le32_to_cpu(pSMBr
->Capabilities
);
389 server
->timeZone
= le16_to_cpu(pSMBr
->ServerTimeZone
);
390 /* BB with UTC do we ever need to be using srvr timezone? */
391 if (pSMBr
->EncryptionKeyLength
== CIFS_CRYPTO_KEY_SIZE
) {
392 memcpy(server
->cryptKey
, pSMBr
->u
.EncryptionKey
,
393 CIFS_CRYPTO_KEY_SIZE
);
394 } else if ((pSMBr
->hdr
.Flags2
& SMBFLG2_EXT_SEC
)
395 && (pSMBr
->EncryptionKeyLength
== 0)) {
396 /* decode security blob */
400 /* BB might be helpful to save off the domain of server here */
402 if ((pSMBr
->hdr
.Flags2
& SMBFLG2_EXT_SEC
) &&
403 (server
->capabilities
& CAP_EXTENDED_SECURITY
)) {
404 count
= pSMBr
->ByteCount
;
407 else if (count
== 16) {
408 server
->secType
= RawNTLMSSP
;
409 if (server
->socketUseCount
.counter
> 1) {
411 (server
->server_GUID
,
412 pSMBr
->u
.extended_response
.
415 ("UID of server does not match previous connection to same ip address"));
423 memcpy(server
->server_GUID
,
424 pSMBr
->u
.extended_response
.
427 rc
= decode_negTokenInit(pSMBr
->u
.
433 /* BB Need to fill struct for sessetup here */
440 server
->capabilities
&= ~CAP_EXTENDED_SECURITY
;
441 if(sign_CIFS_PDUs
== FALSE
) {
442 if(server
->secMode
& SECMODE_SIGN_REQUIRED
)
444 ("Server requires /proc/fs/cifs/PacketSigningEnabled"));
445 server
->secMode
&= ~(SECMODE_SIGN_ENABLED
| SECMODE_SIGN_REQUIRED
);
446 } else if(sign_CIFS_PDUs
== 1) {
447 if((server
->secMode
& SECMODE_SIGN_REQUIRED
) == 0)
448 server
->secMode
&= ~(SECMODE_SIGN_ENABLED
| SECMODE_SIGN_REQUIRED
);
453 cifs_buf_release(pSMB
);
458 CIFSSMBTDis(const int xid
, struct cifsTconInfo
*tcon
)
460 struct smb_hdr
*smb_buffer
;
461 struct smb_hdr
*smb_buffer_response
; /* BB removeme BB */
465 cFYI(1, ("In tree disconnect"));
467 * If last user of the connection and
468 * connection alive - disconnect it
469 * If this is the last connection on the server session disconnect it
470 * (and inside session disconnect we should check if tcp socket needs
471 * to be freed and kernel thread woken up).
474 down(&tcon
->tconSem
);
478 atomic_dec(&tcon
->useCount
);
479 if (atomic_read(&tcon
->useCount
) > 0) {
484 /* No need to return error on this operation if tid invalidated and
485 closed on server already e.g. due to tcp session crashing */
486 if(tcon
->tidStatus
== CifsNeedReconnect
) {
491 if((tcon
->ses
== NULL
) || (tcon
->ses
->server
== NULL
)) {
495 rc
= small_smb_init(SMB_COM_TREE_DISCONNECT
, 0, tcon
,
496 (void **)&smb_buffer
);
501 smb_buffer_response
= smb_buffer
; /* BB removeme BB */
503 rc
= SendReceive(xid
, tcon
->ses
, smb_buffer
, smb_buffer_response
,
506 cFYI(1, ("Tree disconnect failed %d", rc
));
509 cifs_small_buf_release(smb_buffer
);
512 /* No need to return error on this operation if tid invalidated and
513 closed on server already e.g. due to tcp session crashing */
521 CIFSSMBLogoff(const int xid
, struct cifsSesInfo
*ses
)
523 struct smb_hdr
*smb_buffer_response
;
524 LOGOFF_ANDX_REQ
*pSMB
;
528 cFYI(1, ("In SMBLogoff for session disconnect"));
534 atomic_dec(&ses
->inUse
);
535 if (atomic_read(&ses
->inUse
) > 0) {
539 rc
= small_smb_init(SMB_COM_LOGOFF_ANDX
, 2, NULL
, (void **)&pSMB
);
545 smb_buffer_response
= (struct smb_hdr
*)pSMB
; /* BB removeme BB */
548 pSMB
->hdr
.Mid
= GetNextMid(ses
->server
);
550 if(ses
->server
->secMode
&
551 (SECMODE_SIGN_REQUIRED
| SECMODE_SIGN_ENABLED
))
552 pSMB
->hdr
.Flags2
|= SMBFLG2_SECURITY_SIGNATURE
;
555 pSMB
->hdr
.Uid
= ses
->Suid
;
557 pSMB
->AndXCommand
= 0xFF;
558 rc
= SendReceive(xid
, ses
, (struct smb_hdr
*) pSMB
,
559 smb_buffer_response
, &length
, 0);
561 atomic_dec(&ses
->server
->socketUseCount
);
562 if (atomic_read(&ses
->server
->socketUseCount
) == 0) {
563 spin_lock(&GlobalMid_Lock
);
564 ses
->server
->tcpStatus
= CifsExiting
;
565 spin_unlock(&GlobalMid_Lock
);
570 cifs_small_buf_release(pSMB
);
572 /* if session dead then we do not need to do ulogoff,
573 since server closed smb session, no sense reporting
581 CIFSSMBDelFile(const int xid
, struct cifsTconInfo
*tcon
, const char *fileName
,
582 const struct nls_table
*nls_codepage
, int remap
)
584 DELETE_FILE_REQ
*pSMB
= NULL
;
585 DELETE_FILE_RSP
*pSMBr
= NULL
;
591 rc
= smb_init(SMB_COM_DELETE
, 1, tcon
, (void **) &pSMB
,
596 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
598 cifsConvertToUCS((__le16
*) pSMB
->fileName
, fileName
,
599 PATH_MAX
, nls_codepage
, remap
);
600 name_len
++; /* trailing null */
602 } else { /* BB improve check for buffer overruns BB */
603 name_len
= strnlen(fileName
, PATH_MAX
);
604 name_len
++; /* trailing null */
605 strncpy(pSMB
->fileName
, fileName
, name_len
);
607 pSMB
->SearchAttributes
=
608 cpu_to_le16(ATTR_READONLY
| ATTR_HIDDEN
| ATTR_SYSTEM
);
609 pSMB
->BufferFormat
= 0x04;
610 pSMB
->hdr
.smb_buf_length
+= name_len
+ 1;
611 pSMB
->ByteCount
= cpu_to_le16(name_len
+ 1);
612 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
613 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
614 cifs_stats_inc(&tcon
->num_deletes
);
616 cFYI(1, ("Error in RMFile = %d", rc
));
619 cifs_buf_release(pSMB
);
627 CIFSSMBRmDir(const int xid
, struct cifsTconInfo
*tcon
, const char *dirName
,
628 const struct nls_table
*nls_codepage
, int remap
)
630 DELETE_DIRECTORY_REQ
*pSMB
= NULL
;
631 DELETE_DIRECTORY_RSP
*pSMBr
= NULL
;
636 cFYI(1, ("In CIFSSMBRmDir"));
638 rc
= smb_init(SMB_COM_DELETE_DIRECTORY
, 0, tcon
, (void **) &pSMB
,
643 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
644 name_len
= cifsConvertToUCS((__le16
*) pSMB
->DirName
, dirName
,
645 PATH_MAX
, nls_codepage
, remap
);
646 name_len
++; /* trailing null */
648 } else { /* BB improve check for buffer overruns BB */
649 name_len
= strnlen(dirName
, PATH_MAX
);
650 name_len
++; /* trailing null */
651 strncpy(pSMB
->DirName
, dirName
, name_len
);
654 pSMB
->BufferFormat
= 0x04;
655 pSMB
->hdr
.smb_buf_length
+= name_len
+ 1;
656 pSMB
->ByteCount
= cpu_to_le16(name_len
+ 1);
657 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
658 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
659 cifs_stats_inc(&tcon
->num_rmdirs
);
661 cFYI(1, ("Error in RMDir = %d", rc
));
664 cifs_buf_release(pSMB
);
671 CIFSSMBMkDir(const int xid
, struct cifsTconInfo
*tcon
,
672 const char *name
, const struct nls_table
*nls_codepage
, int remap
)
675 CREATE_DIRECTORY_REQ
*pSMB
= NULL
;
676 CREATE_DIRECTORY_RSP
*pSMBr
= NULL
;
680 cFYI(1, ("In CIFSSMBMkDir"));
682 rc
= smb_init(SMB_COM_CREATE_DIRECTORY
, 0, tcon
, (void **) &pSMB
,
687 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
688 name_len
= cifsConvertToUCS((__le16
*) pSMB
->DirName
, name
,
689 PATH_MAX
, nls_codepage
, remap
);
690 name_len
++; /* trailing null */
692 } else { /* BB improve check for buffer overruns BB */
693 name_len
= strnlen(name
, PATH_MAX
);
694 name_len
++; /* trailing null */
695 strncpy(pSMB
->DirName
, name
, name_len
);
698 pSMB
->BufferFormat
= 0x04;
699 pSMB
->hdr
.smb_buf_length
+= name_len
+ 1;
700 pSMB
->ByteCount
= cpu_to_le16(name_len
+ 1);
701 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
702 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
703 cifs_stats_inc(&tcon
->num_mkdirs
);
705 cFYI(1, ("Error in Mkdir = %d", rc
));
708 cifs_buf_release(pSMB
);
714 static __u16
convert_disposition(int disposition
)
718 switch (disposition
) {
720 ofun
= SMBOPEN_OCREATE
| SMBOPEN_OTRUNC
;
723 ofun
= SMBOPEN_OAPPEND
;
726 ofun
= SMBOPEN_OCREATE
;
729 ofun
= SMBOPEN_OCREATE
| SMBOPEN_OAPPEND
;
732 ofun
= SMBOPEN_OTRUNC
;
734 case FILE_OVERWRITE_IF
:
735 ofun
= SMBOPEN_OCREATE
| SMBOPEN_OTRUNC
;
738 cFYI(1,("unknown disposition %d",disposition
));
739 ofun
= SMBOPEN_OAPPEND
; /* regular open */
745 SMBLegacyOpen(const int xid
, struct cifsTconInfo
*tcon
,
746 const char *fileName
, const int openDisposition
,
747 const int access_flags
, const int create_options
, __u16
* netfid
,
748 int *pOplock
, FILE_ALL_INFO
* pfile_info
,
749 const struct nls_table
*nls_codepage
, int remap
)
752 OPENX_REQ
*pSMB
= NULL
;
753 OPENX_RSP
*pSMBr
= NULL
;
759 rc
= smb_init(SMB_COM_OPEN_ANDX
, 15, tcon
, (void **) &pSMB
,
764 pSMB
->AndXCommand
= 0xFF; /* none */
766 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
767 count
= 1; /* account for one byte pad to word boundary */
769 cifsConvertToUCS((__le16
*) (pSMB
->fileName
+ 1),
770 fileName
, PATH_MAX
, nls_codepage
, remap
);
771 name_len
++; /* trailing null */
773 } else { /* BB improve check for buffer overruns BB */
774 count
= 0; /* no pad */
775 name_len
= strnlen(fileName
, PATH_MAX
);
776 name_len
++; /* trailing null */
777 strncpy(pSMB
->fileName
, fileName
, name_len
);
779 if (*pOplock
& REQ_OPLOCK
)
780 pSMB
->OpenFlags
= cpu_to_le16(REQ_OPLOCK
);
781 else if (*pOplock
& REQ_BATCHOPLOCK
) {
782 pSMB
->OpenFlags
= cpu_to_le16(REQ_BATCHOPLOCK
);
784 pSMB
->OpenFlags
|= cpu_to_le16(REQ_MORE_INFO
);
785 /* BB fixme add conversion for access_flags to bits 0 - 2 of mode */
791 pSMB
->Mode
= cpu_to_le16(2);
792 pSMB
->Mode
|= cpu_to_le16(0x40); /* deny none */
793 /* set file as system file if special file such
794 as fifo and server expecting SFU style and
795 no Unix extensions */
797 if(create_options
& CREATE_OPTION_SPECIAL
)
798 pSMB
->FileAttributes
= cpu_to_le16(ATTR_SYSTEM
);
800 pSMB
->FileAttributes
= cpu_to_le16(0/*ATTR_NORMAL*/); /* BB FIXME */
802 /* if ((omode & S_IWUGO) == 0)
803 pSMB->FileAttributes |= cpu_to_le32(ATTR_READONLY);*/
804 /* Above line causes problems due to vfs splitting create into two
805 pieces - need to set mode after file created not while it is
809 /* pSMB->CreateOptions = cpu_to_le32(create_options & CREATE_OPTIONS_MASK); */
810 /* BB FIXME END BB */
812 pSMB
->Sattr
= cpu_to_le16(ATTR_HIDDEN
| ATTR_SYSTEM
| ATTR_DIRECTORY
);
813 pSMB
->OpenFunction
= cpu_to_le16(convert_disposition(openDisposition
));
815 pSMB
->hdr
.smb_buf_length
+= count
;
817 pSMB
->ByteCount
= cpu_to_le16(count
);
818 /* long_op set to 1 to allow for oplock break timeouts */
819 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
820 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 1);
821 cifs_stats_inc(&tcon
->num_opens
);
823 cFYI(1, ("Error in Open = %d", rc
));
825 /* BB verify if wct == 15 */
827 /* *pOplock = pSMBr->OplockLevel; */ /* BB take from action field BB */
829 *netfid
= pSMBr
->Fid
; /* cifs fid stays in le */
830 /* Let caller know file was created so we can set the mode. */
831 /* Do we care about the CreateAction in any other cases? */
833 /* if(cpu_to_le32(FILE_CREATE) == pSMBr->CreateAction)
834 *pOplock |= CIFS_CREATE_ACTION; */
838 pfile_info
->CreationTime
= 0; /* BB convert CreateTime*/
839 pfile_info
->LastAccessTime
= 0; /* BB fixme */
840 pfile_info
->LastWriteTime
= 0; /* BB fixme */
841 pfile_info
->ChangeTime
= 0; /* BB fixme */
842 pfile_info
->Attributes
=
843 cpu_to_le32(le16_to_cpu(pSMBr
->FileAttributes
));
844 /* the file_info buf is endian converted by caller */
845 pfile_info
->AllocationSize
=
846 cpu_to_le64(le32_to_cpu(pSMBr
->EndOfFile
));
847 pfile_info
->EndOfFile
= pfile_info
->AllocationSize
;
848 pfile_info
->NumberOfLinks
= cpu_to_le32(1);
852 cifs_buf_release(pSMB
);
859 CIFSSMBOpen(const int xid
, struct cifsTconInfo
*tcon
,
860 const char *fileName
, const int openDisposition
,
861 const int access_flags
, const int create_options
, __u16
* netfid
,
862 int *pOplock
, FILE_ALL_INFO
* pfile_info
,
863 const struct nls_table
*nls_codepage
, int remap
)
866 OPEN_REQ
*pSMB
= NULL
;
867 OPEN_RSP
*pSMBr
= NULL
;
873 rc
= smb_init(SMB_COM_NT_CREATE_ANDX
, 24, tcon
, (void **) &pSMB
,
878 pSMB
->AndXCommand
= 0xFF; /* none */
880 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
881 count
= 1; /* account for one byte pad to word boundary */
883 cifsConvertToUCS((__le16
*) (pSMB
->fileName
+ 1),
884 fileName
, PATH_MAX
, nls_codepage
, remap
);
885 name_len
++; /* trailing null */
887 pSMB
->NameLength
= cpu_to_le16(name_len
);
888 } else { /* BB improve check for buffer overruns BB */
889 count
= 0; /* no pad */
890 name_len
= strnlen(fileName
, PATH_MAX
);
891 name_len
++; /* trailing null */
892 pSMB
->NameLength
= cpu_to_le16(name_len
);
893 strncpy(pSMB
->fileName
, fileName
, name_len
);
895 if (*pOplock
& REQ_OPLOCK
)
896 pSMB
->OpenFlags
= cpu_to_le32(REQ_OPLOCK
);
897 else if (*pOplock
& REQ_BATCHOPLOCK
) {
898 pSMB
->OpenFlags
= cpu_to_le32(REQ_BATCHOPLOCK
);
900 pSMB
->DesiredAccess
= cpu_to_le32(access_flags
);
901 pSMB
->AllocationSize
= 0;
902 /* set file as system file if special file such
903 as fifo and server expecting SFU style and
904 no Unix extensions */
905 if(create_options
& CREATE_OPTION_SPECIAL
)
906 pSMB
->FileAttributes
= cpu_to_le32(ATTR_SYSTEM
);
908 pSMB
->FileAttributes
= cpu_to_le32(ATTR_NORMAL
);
909 /* XP does not handle ATTR_POSIX_SEMANTICS */
910 /* but it helps speed up case sensitive checks for other
911 servers such as Samba */
912 if (tcon
->ses
->capabilities
& CAP_UNIX
)
913 pSMB
->FileAttributes
|= cpu_to_le32(ATTR_POSIX_SEMANTICS
);
915 /* if ((omode & S_IWUGO) == 0)
916 pSMB->FileAttributes |= cpu_to_le32(ATTR_READONLY);*/
917 /* Above line causes problems due to vfs splitting create into two
918 pieces - need to set mode after file created not while it is
920 pSMB
->ShareAccess
= cpu_to_le32(FILE_SHARE_ALL
);
921 pSMB
->CreateDisposition
= cpu_to_le32(openDisposition
);
922 pSMB
->CreateOptions
= cpu_to_le32(create_options
& CREATE_OPTIONS_MASK
);
923 /* BB Expirement with various impersonation levels and verify */
924 pSMB
->ImpersonationLevel
= cpu_to_le32(SECURITY_IMPERSONATION
);
925 pSMB
->SecurityFlags
=
926 SECURITY_CONTEXT_TRACKING
| SECURITY_EFFECTIVE_ONLY
;
929 pSMB
->hdr
.smb_buf_length
+= count
;
931 pSMB
->ByteCount
= cpu_to_le16(count
);
932 /* long_op set to 1 to allow for oplock break timeouts */
933 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
934 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 1);
935 cifs_stats_inc(&tcon
->num_opens
);
937 cFYI(1, ("Error in Open = %d", rc
));
939 *pOplock
= pSMBr
->OplockLevel
; /* 1 byte no need to le_to_cpu */
940 *netfid
= pSMBr
->Fid
; /* cifs fid stays in le */
941 /* Let caller know file was created so we can set the mode. */
942 /* Do we care about the CreateAction in any other cases? */
943 if(cpu_to_le32(FILE_CREATE
) == pSMBr
->CreateAction
)
944 *pOplock
|= CIFS_CREATE_ACTION
;
946 memcpy((char *)pfile_info
,(char *)&pSMBr
->CreationTime
,
947 36 /* CreationTime to Attributes */);
948 /* the file_info buf is endian converted by caller */
949 pfile_info
->AllocationSize
= pSMBr
->AllocationSize
;
950 pfile_info
->EndOfFile
= pSMBr
->EndOfFile
;
951 pfile_info
->NumberOfLinks
= cpu_to_le32(1);
955 cifs_buf_release(pSMB
);
962 CIFSSMBRead(const int xid
, struct cifsTconInfo
*tcon
,
963 const int netfid
, const unsigned int count
,
964 const __u64 lseek
, unsigned int *nbytes
, char **buf
,
968 READ_REQ
*pSMB
= NULL
;
969 READ_RSP
*pSMBr
= NULL
;
970 char *pReadData
= NULL
;
972 int resp_buf_type
= 0;
975 cFYI(1,("Reading %d bytes on fid %d",count
,netfid
));
976 if(tcon
->ses
->capabilities
& CAP_LARGE_FILES
)
979 wct
= 10; /* old style read */
982 rc
= small_smb_init(SMB_COM_READ_ANDX
, wct
, tcon
, (void **) &pSMB
);
986 /* tcon and ses pointer are checked in smb_init */
987 if (tcon
->ses
->server
== NULL
)
988 return -ECONNABORTED
;
990 pSMB
->AndXCommand
= 0xFF; /* none */
992 pSMB
->OffsetLow
= cpu_to_le32(lseek
& 0xFFFFFFFF);
994 pSMB
->OffsetHigh
= cpu_to_le32(lseek
>> 32);
995 else if((lseek
>> 32) > 0) /* can not handle this big offset for old */
999 pSMB
->MaxCount
= cpu_to_le16(count
& 0xFFFF);
1000 pSMB
->MaxCountHigh
= cpu_to_le32(count
>> 16);
1002 pSMB
->ByteCount
= 0; /* no need to do le conversion since 0 */
1004 /* old style read */
1005 struct smb_com_readx_req
* pSMBW
=
1006 (struct smb_com_readx_req
*)pSMB
;
1007 pSMBW
->ByteCount
= 0;
1010 iov
[0].iov_base
= (char *)pSMB
;
1011 iov
[0].iov_len
= pSMB
->hdr
.smb_buf_length
+ 4;
1012 rc
= SendReceive2(xid
, tcon
->ses
, iov
,
1015 cifs_stats_inc(&tcon
->num_reads
);
1016 pSMBr
= (READ_RSP
*)iov
[0].iov_base
;
1018 cERROR(1, ("Send error in read = %d", rc
));
1020 int data_length
= le16_to_cpu(pSMBr
->DataLengthHigh
);
1021 data_length
= data_length
<< 16;
1022 data_length
+= le16_to_cpu(pSMBr
->DataLength
);
1023 *nbytes
= data_length
;
1025 /*check that DataLength would not go beyond end of SMB */
1026 if ((data_length
> CIFSMaxBufSize
)
1027 || (data_length
> count
)) {
1028 cFYI(1,("bad length %d for count %d",data_length
,count
));
1032 pReadData
= (char *) (&pSMBr
->hdr
.Protocol
) +
1033 le16_to_cpu(pSMBr
->DataOffset
);
1034 /* if(rc = copy_to_user(buf, pReadData, data_length)) {
1035 cERROR(1,("Faulting on read rc = %d",rc));
1037 }*/ /* can not use copy_to_user when using page cache*/
1039 memcpy(*buf
,pReadData
,data_length
);
1043 cifs_small_buf_release(pSMB
);
1045 if(resp_buf_type
== CIFS_SMALL_BUFFER
)
1046 cifs_small_buf_release(iov
[0].iov_base
);
1047 else if(resp_buf_type
== CIFS_LARGE_BUFFER
)
1048 cifs_buf_release(iov
[0].iov_base
);
1049 } else /* return buffer to caller to free */ /* BB FIXME how do we tell caller if it is not a large buffer */ {
1050 *buf
= iov
[0].iov_base
;
1051 if(resp_buf_type
== CIFS_SMALL_BUFFER
)
1052 *pbuf_type
= CIFS_SMALL_BUFFER
;
1053 else if(resp_buf_type
== CIFS_LARGE_BUFFER
)
1054 *pbuf_type
= CIFS_LARGE_BUFFER
;
1057 /* Note: On -EAGAIN error only caller can retry on handle based calls
1058 since file handle passed in no longer valid */
1064 CIFSSMBWrite(const int xid
, struct cifsTconInfo
*tcon
,
1065 const int netfid
, const unsigned int count
,
1066 const __u64 offset
, unsigned int *nbytes
, const char *buf
,
1067 const char __user
* ubuf
, const int long_op
)
1070 WRITE_REQ
*pSMB
= NULL
;
1071 WRITE_RSP
*pSMBr
= NULL
;
1072 int bytes_returned
, wct
;
1076 /* cFYI(1,("write at %lld %d bytes",offset,count));*/
1077 if(tcon
->ses
== NULL
)
1078 return -ECONNABORTED
;
1080 if(tcon
->ses
->capabilities
& CAP_LARGE_FILES
)
1085 rc
= smb_init(SMB_COM_WRITE_ANDX
, wct
, tcon
, (void **) &pSMB
,
1089 /* tcon and ses pointer are checked in smb_init */
1090 if (tcon
->ses
->server
== NULL
)
1091 return -ECONNABORTED
;
1093 pSMB
->AndXCommand
= 0xFF; /* none */
1095 pSMB
->OffsetLow
= cpu_to_le32(offset
& 0xFFFFFFFF);
1097 pSMB
->OffsetHigh
= cpu_to_le32(offset
>> 32);
1098 else if((offset
>> 32) > 0) /* can not handle this big offset for old */
1101 pSMB
->Reserved
= 0xFFFFFFFF;
1102 pSMB
->WriteMode
= 0;
1103 pSMB
->Remaining
= 0;
1105 /* Can increase buffer size if buffer is big enough in some cases - ie we
1106 can send more if LARGE_WRITE_X capability returned by the server and if
1107 our buffer is big enough or if we convert to iovecs on socket writes
1108 and eliminate the copy to the CIFS buffer */
1109 if(tcon
->ses
->capabilities
& CAP_LARGE_WRITE_X
) {
1110 bytes_sent
= min_t(const unsigned int, CIFSMaxBufSize
, count
);
1112 bytes_sent
= (tcon
->ses
->server
->maxBuf
- MAX_CIFS_HDR_SIZE
)
1116 if (bytes_sent
> count
)
1119 cpu_to_le16(offsetof(struct smb_com_write_req
,Data
) - 4);
1121 memcpy(pSMB
->Data
,buf
,bytes_sent
);
1123 if(copy_from_user(pSMB
->Data
,ubuf
,bytes_sent
)) {
1124 cifs_buf_release(pSMB
);
1127 } else if (count
!= 0) {
1129 cifs_buf_release(pSMB
);
1131 } /* else setting file size with write of zero bytes */
1133 byte_count
= bytes_sent
+ 1; /* pad */
1134 else /* wct == 12 */ {
1135 byte_count
= bytes_sent
+ 5; /* bigger pad, smaller smb hdr */
1137 pSMB
->DataLengthLow
= cpu_to_le16(bytes_sent
& 0xFFFF);
1138 pSMB
->DataLengthHigh
= cpu_to_le16(bytes_sent
>> 16);
1139 pSMB
->hdr
.smb_buf_length
+= byte_count
;
1142 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
1143 else { /* old style write has byte count 4 bytes earlier so 4 bytes pad */
1144 struct smb_com_writex_req
* pSMBW
=
1145 (struct smb_com_writex_req
*)pSMB
;
1146 pSMBW
->ByteCount
= cpu_to_le16(byte_count
);
1149 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
1150 (struct smb_hdr
*) pSMBr
, &bytes_returned
, long_op
);
1151 cifs_stats_inc(&tcon
->num_writes
);
1153 cFYI(1, ("Send error in write = %d", rc
));
1156 *nbytes
= le16_to_cpu(pSMBr
->CountHigh
);
1157 *nbytes
= (*nbytes
) << 16;
1158 *nbytes
+= le16_to_cpu(pSMBr
->Count
);
1161 cifs_buf_release(pSMB
);
1163 /* Note: On -EAGAIN error only caller can retry on handle based calls
1164 since file handle passed in no longer valid */
1170 CIFSSMBWrite2(const int xid
, struct cifsTconInfo
*tcon
,
1171 const int netfid
, const unsigned int count
,
1172 const __u64 offset
, unsigned int *nbytes
, struct kvec
*iov
,
1173 int n_vec
, const int long_op
)
1176 WRITE_REQ
*pSMB
= NULL
;
1179 int resp_buf_type
= 0;
1181 cFYI(1,("write2 at %lld %d bytes", (long long)offset
, count
));
1183 if(tcon
->ses
->capabilities
& CAP_LARGE_FILES
)
1187 rc
= small_smb_init(SMB_COM_WRITE_ANDX
, wct
, tcon
, (void **) &pSMB
);
1190 /* tcon and ses pointer are checked in smb_init */
1191 if (tcon
->ses
->server
== NULL
)
1192 return -ECONNABORTED
;
1194 pSMB
->AndXCommand
= 0xFF; /* none */
1196 pSMB
->OffsetLow
= cpu_to_le32(offset
& 0xFFFFFFFF);
1198 pSMB
->OffsetHigh
= cpu_to_le32(offset
>> 32);
1199 else if((offset
>> 32) > 0) /* can not handle this big offset for old */
1201 pSMB
->Reserved
= 0xFFFFFFFF;
1202 pSMB
->WriteMode
= 0;
1203 pSMB
->Remaining
= 0;
1206 cpu_to_le16(offsetof(struct smb_com_write_req
,Data
) - 4);
1208 pSMB
->DataLengthLow
= cpu_to_le16(count
& 0xFFFF);
1209 pSMB
->DataLengthHigh
= cpu_to_le16(count
>> 16);
1210 smb_hdr_len
= pSMB
->hdr
.smb_buf_length
+ 1; /* hdr + 1 byte pad */
1212 pSMB
->hdr
.smb_buf_length
+= count
+1;
1213 else /* wct == 12 */
1214 pSMB
->hdr
.smb_buf_length
+= count
+5; /* smb data starts later */
1216 pSMB
->ByteCount
= cpu_to_le16(count
+ 1);
1217 else /* wct == 12 */ /* bigger pad, smaller smb hdr, keep offset ok */ {
1218 struct smb_com_writex_req
* pSMBW
=
1219 (struct smb_com_writex_req
*)pSMB
;
1220 pSMBW
->ByteCount
= cpu_to_le16(count
+ 5);
1222 iov
[0].iov_base
= pSMB
;
1224 iov
[0].iov_len
= smb_hdr_len
+ 4;
1225 else /* wct == 12 pad bigger by four bytes */
1226 iov
[0].iov_len
= smb_hdr_len
+ 8;
1229 rc
= SendReceive2(xid
, tcon
->ses
, iov
, n_vec
+ 1, &resp_buf_type
,
1231 cifs_stats_inc(&tcon
->num_writes
);
1233 cFYI(1, ("Send error Write2 = %d", rc
));
1235 } else if(resp_buf_type
== 0) {
1236 /* presumably this can not happen, but best to be safe */
1240 WRITE_RSP
* pSMBr
= (WRITE_RSP
*)iov
[0].iov_base
;
1241 *nbytes
= le16_to_cpu(pSMBr
->CountHigh
);
1242 *nbytes
= (*nbytes
) << 16;
1243 *nbytes
+= le16_to_cpu(pSMBr
->Count
);
1246 cifs_small_buf_release(pSMB
);
1247 if(resp_buf_type
== CIFS_SMALL_BUFFER
)
1248 cifs_small_buf_release(iov
[0].iov_base
);
1249 else if(resp_buf_type
== CIFS_LARGE_BUFFER
)
1250 cifs_buf_release(iov
[0].iov_base
);
1252 /* Note: On -EAGAIN error only caller can retry on handle based calls
1253 since file handle passed in no longer valid */
1260 CIFSSMBLock(const int xid
, struct cifsTconInfo
*tcon
,
1261 const __u16 smb_file_id
, const __u64 len
,
1262 const __u64 offset
, const __u32 numUnlock
,
1263 const __u32 numLock
, const __u8 lockType
, const int waitFlag
)
1266 LOCK_REQ
*pSMB
= NULL
;
1267 LOCK_RSP
*pSMBr
= NULL
;
1272 cFYI(1, ("In CIFSSMBLock - timeout %d numLock %d",waitFlag
,numLock
));
1273 rc
= small_smb_init(SMB_COM_LOCKING_ANDX
, 8, tcon
, (void **) &pSMB
);
1278 pSMBr
= (LOCK_RSP
*)pSMB
; /* BB removeme BB */
1280 if(lockType
== LOCKING_ANDX_OPLOCK_RELEASE
) {
1281 timeout
= -1; /* no response expected */
1283 } else if (waitFlag
== TRUE
) {
1284 timeout
= 3; /* blocking operation, no timeout */
1285 pSMB
->Timeout
= cpu_to_le32(-1);/* blocking - do not time out */
1290 pSMB
->NumberOfLocks
= cpu_to_le16(numLock
);
1291 pSMB
->NumberOfUnlocks
= cpu_to_le16(numUnlock
);
1292 pSMB
->LockType
= lockType
;
1293 pSMB
->AndXCommand
= 0xFF; /* none */
1294 pSMB
->Fid
= smb_file_id
; /* netfid stays le */
1296 if((numLock
!= 0) || (numUnlock
!= 0)) {
1297 pSMB
->Locks
[0].Pid
= cpu_to_le16(current
->tgid
);
1298 /* BB where to store pid high? */
1299 pSMB
->Locks
[0].LengthLow
= cpu_to_le32((u32
)len
);
1300 pSMB
->Locks
[0].LengthHigh
= cpu_to_le32((u32
)(len
>>32));
1301 pSMB
->Locks
[0].OffsetLow
= cpu_to_le32((u32
)offset
);
1302 pSMB
->Locks
[0].OffsetHigh
= cpu_to_le32((u32
)(offset
>>32));
1303 count
= sizeof(LOCKING_ANDX_RANGE
);
1308 pSMB
->hdr
.smb_buf_length
+= count
;
1309 pSMB
->ByteCount
= cpu_to_le16(count
);
1311 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
1312 (struct smb_hdr
*) pSMBr
, &bytes_returned
, timeout
);
1313 cifs_stats_inc(&tcon
->num_locks
);
1315 cFYI(1, ("Send error in Lock = %d", rc
));
1317 cifs_small_buf_release(pSMB
);
1319 /* Note: On -EAGAIN error only caller can retry on handle based calls
1320 since file handle passed in no longer valid */
1325 CIFSSMBClose(const int xid
, struct cifsTconInfo
*tcon
, int smb_file_id
)
1328 CLOSE_REQ
*pSMB
= NULL
;
1329 CLOSE_RSP
*pSMBr
= NULL
;
1331 cFYI(1, ("In CIFSSMBClose"));
1333 /* do not retry on dead session on close */
1334 rc
= small_smb_init(SMB_COM_CLOSE
, 3, tcon
, (void **) &pSMB
);
1340 pSMBr
= (CLOSE_RSP
*)pSMB
; /* BB removeme BB */
1342 pSMB
->FileID
= (__u16
) smb_file_id
;
1343 pSMB
->LastWriteTime
= 0;
1344 pSMB
->ByteCount
= 0;
1345 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
1346 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
1347 cifs_stats_inc(&tcon
->num_closes
);
1350 /* EINTR is expected when user ctl-c to kill app */
1351 cERROR(1, ("Send error in Close = %d", rc
));
1355 cifs_small_buf_release(pSMB
);
1357 /* Since session is dead, file will be closed on server already */
1365 CIFSSMBRename(const int xid
, struct cifsTconInfo
*tcon
,
1366 const char *fromName
, const char *toName
,
1367 const struct nls_table
*nls_codepage
, int remap
)
1370 RENAME_REQ
*pSMB
= NULL
;
1371 RENAME_RSP
*pSMBr
= NULL
;
1373 int name_len
, name_len2
;
1376 cFYI(1, ("In CIFSSMBRename"));
1378 rc
= smb_init(SMB_COM_RENAME
, 1, tcon
, (void **) &pSMB
,
1383 pSMB
->BufferFormat
= 0x04;
1384 pSMB
->SearchAttributes
=
1385 cpu_to_le16(ATTR_READONLY
| ATTR_HIDDEN
| ATTR_SYSTEM
|
1388 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
1390 cifsConvertToUCS((__le16
*) pSMB
->OldFileName
, fromName
,
1391 PATH_MAX
, nls_codepage
, remap
);
1392 name_len
++; /* trailing null */
1394 pSMB
->OldFileName
[name_len
] = 0x04; /* pad */
1395 /* protocol requires ASCII signature byte on Unicode string */
1396 pSMB
->OldFileName
[name_len
+ 1] = 0x00;
1398 cifsConvertToUCS((__le16
*) &pSMB
->OldFileName
[name_len
+ 2],
1399 toName
, PATH_MAX
, nls_codepage
, remap
);
1400 name_len2
+= 1 /* trailing null */ + 1 /* Signature word */ ;
1401 name_len2
*= 2; /* convert to bytes */
1402 } else { /* BB improve the check for buffer overruns BB */
1403 name_len
= strnlen(fromName
, PATH_MAX
);
1404 name_len
++; /* trailing null */
1405 strncpy(pSMB
->OldFileName
, fromName
, name_len
);
1406 name_len2
= strnlen(toName
, PATH_MAX
);
1407 name_len2
++; /* trailing null */
1408 pSMB
->OldFileName
[name_len
] = 0x04; /* 2nd buffer format */
1409 strncpy(&pSMB
->OldFileName
[name_len
+ 1], toName
, name_len2
);
1410 name_len2
++; /* trailing null */
1411 name_len2
++; /* signature byte */
1414 count
= 1 /* 1st signature byte */ + name_len
+ name_len2
;
1415 pSMB
->hdr
.smb_buf_length
+= count
;
1416 pSMB
->ByteCount
= cpu_to_le16(count
);
1418 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
1419 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
1420 cifs_stats_inc(&tcon
->num_renames
);
1422 cFYI(1, ("Send error in rename = %d", rc
));
1425 cifs_buf_release(pSMB
);
1433 int CIFSSMBRenameOpenFile(const int xid
,struct cifsTconInfo
*pTcon
,
1434 int netfid
, char * target_name
,
1435 const struct nls_table
* nls_codepage
, int remap
)
1437 struct smb_com_transaction2_sfi_req
*pSMB
= NULL
;
1438 struct smb_com_transaction2_sfi_rsp
*pSMBr
= NULL
;
1439 struct set_file_rename
* rename_info
;
1441 char dummy_string
[30];
1443 int bytes_returned
= 0;
1445 __u16 params
, param_offset
, offset
, count
, byte_count
;
1447 cFYI(1, ("Rename to File by handle"));
1448 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, pTcon
, (void **) &pSMB
,
1454 pSMB
->MaxSetupCount
= 0;
1458 pSMB
->Reserved2
= 0;
1459 param_offset
= offsetof(struct smb_com_transaction2_sfi_req
, Fid
) - 4;
1460 offset
= param_offset
+ params
;
1462 data_offset
= (char *) (&pSMB
->hdr
.Protocol
) + offset
;
1463 rename_info
= (struct set_file_rename
*) data_offset
;
1464 pSMB
->MaxParameterCount
= cpu_to_le16(2);
1465 pSMB
->MaxDataCount
= cpu_to_le16(1000); /* BB find max SMB PDU from sess */
1466 pSMB
->SetupCount
= 1;
1467 pSMB
->Reserved3
= 0;
1468 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_FILE_INFORMATION
);
1469 byte_count
= 3 /* pad */ + params
;
1470 pSMB
->ParameterCount
= cpu_to_le16(params
);
1471 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
1472 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
1473 pSMB
->DataOffset
= cpu_to_le16(offset
);
1474 /* construct random name ".cifs_tmp<inodenum><mid>" */
1475 rename_info
->overwrite
= cpu_to_le32(1);
1476 rename_info
->root_fid
= 0;
1477 /* unicode only call */
1478 if(target_name
== NULL
) {
1479 sprintf(dummy_string
,"cifs%x",pSMB
->hdr
.Mid
);
1480 len_of_str
= cifsConvertToUCS((__le16
*)rename_info
->target_name
,
1481 dummy_string
, 24, nls_codepage
, remap
);
1483 len_of_str
= cifsConvertToUCS((__le16
*)rename_info
->target_name
,
1484 target_name
, PATH_MAX
, nls_codepage
, remap
);
1486 rename_info
->target_name_len
= cpu_to_le32(2 * len_of_str
);
1487 count
= 12 /* sizeof(struct set_file_rename) */ + (2 * len_of_str
) + 2;
1488 byte_count
+= count
;
1489 pSMB
->DataCount
= cpu_to_le16(count
);
1490 pSMB
->TotalDataCount
= pSMB
->DataCount
;
1492 pSMB
->InformationLevel
=
1493 cpu_to_le16(SMB_SET_FILE_RENAME_INFORMATION
);
1494 pSMB
->Reserved4
= 0;
1495 pSMB
->hdr
.smb_buf_length
+= byte_count
;
1496 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
1497 rc
= SendReceive(xid
, pTcon
->ses
, (struct smb_hdr
*) pSMB
,
1498 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
1499 cifs_stats_inc(&pTcon
->num_t2renames
);
1501 cFYI(1,("Send error in Rename (by file handle) = %d", rc
));
1504 cifs_buf_release(pSMB
);
1506 /* Note: On -EAGAIN error only caller can retry on handle based calls
1507 since file handle passed in no longer valid */
1513 CIFSSMBCopy(const int xid
, struct cifsTconInfo
*tcon
, const char * fromName
,
1514 const __u16 target_tid
, const char *toName
, const int flags
,
1515 const struct nls_table
*nls_codepage
, int remap
)
1518 COPY_REQ
*pSMB
= NULL
;
1519 COPY_RSP
*pSMBr
= NULL
;
1521 int name_len
, name_len2
;
1524 cFYI(1, ("In CIFSSMBCopy"));
1526 rc
= smb_init(SMB_COM_COPY
, 1, tcon
, (void **) &pSMB
,
1531 pSMB
->BufferFormat
= 0x04;
1532 pSMB
->Tid2
= target_tid
;
1534 pSMB
->Flags
= cpu_to_le16(flags
& COPY_TREE
);
1536 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
1537 name_len
= cifsConvertToUCS((__le16
*) pSMB
->OldFileName
,
1538 fromName
, PATH_MAX
, nls_codepage
,
1540 name_len
++; /* trailing null */
1542 pSMB
->OldFileName
[name_len
] = 0x04; /* pad */
1543 /* protocol requires ASCII signature byte on Unicode string */
1544 pSMB
->OldFileName
[name_len
+ 1] = 0x00;
1545 name_len2
= cifsConvertToUCS((__le16
*)&pSMB
->OldFileName
[name_len
+ 2],
1546 toName
, PATH_MAX
, nls_codepage
, remap
);
1547 name_len2
+= 1 /* trailing null */ + 1 /* Signature word */ ;
1548 name_len2
*= 2; /* convert to bytes */
1549 } else { /* BB improve the check for buffer overruns BB */
1550 name_len
= strnlen(fromName
, PATH_MAX
);
1551 name_len
++; /* trailing null */
1552 strncpy(pSMB
->OldFileName
, fromName
, name_len
);
1553 name_len2
= strnlen(toName
, PATH_MAX
);
1554 name_len2
++; /* trailing null */
1555 pSMB
->OldFileName
[name_len
] = 0x04; /* 2nd buffer format */
1556 strncpy(&pSMB
->OldFileName
[name_len
+ 1], toName
, name_len2
);
1557 name_len2
++; /* trailing null */
1558 name_len2
++; /* signature byte */
1561 count
= 1 /* 1st signature byte */ + name_len
+ name_len2
;
1562 pSMB
->hdr
.smb_buf_length
+= count
;
1563 pSMB
->ByteCount
= cpu_to_le16(count
);
1565 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
1566 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
1568 cFYI(1, ("Send error in copy = %d with %d files copied",
1569 rc
, le16_to_cpu(pSMBr
->CopyCount
)));
1572 cifs_buf_release(pSMB
);
1581 CIFSUnixCreateSymLink(const int xid
, struct cifsTconInfo
*tcon
,
1582 const char *fromName
, const char *toName
,
1583 const struct nls_table
*nls_codepage
)
1585 TRANSACTION2_SPI_REQ
*pSMB
= NULL
;
1586 TRANSACTION2_SPI_RSP
*pSMBr
= NULL
;
1589 int name_len_target
;
1591 int bytes_returned
= 0;
1592 __u16 params
, param_offset
, offset
, byte_count
;
1594 cFYI(1, ("In Symlink Unix style"));
1596 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
1601 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
1603 cifs_strtoUCS((__le16
*) pSMB
->FileName
, fromName
, PATH_MAX
1604 /* find define for this maxpathcomponent */
1606 name_len
++; /* trailing null */
1609 } else { /* BB improve the check for buffer overruns BB */
1610 name_len
= strnlen(fromName
, PATH_MAX
);
1611 name_len
++; /* trailing null */
1612 strncpy(pSMB
->FileName
, fromName
, name_len
);
1614 params
= 6 + name_len
;
1615 pSMB
->MaxSetupCount
= 0;
1619 pSMB
->Reserved2
= 0;
1620 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
1621 InformationLevel
) - 4;
1622 offset
= param_offset
+ params
;
1624 data_offset
= (char *) (&pSMB
->hdr
.Protocol
) + offset
;
1625 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
1627 cifs_strtoUCS((__le16
*) data_offset
, toName
, PATH_MAX
1628 /* find define for this maxpathcomponent */
1630 name_len_target
++; /* trailing null */
1631 name_len_target
*= 2;
1632 } else { /* BB improve the check for buffer overruns BB */
1633 name_len_target
= strnlen(toName
, PATH_MAX
);
1634 name_len_target
++; /* trailing null */
1635 strncpy(data_offset
, toName
, name_len_target
);
1638 pSMB
->MaxParameterCount
= cpu_to_le16(2);
1639 /* BB find exact max on data count below from sess */
1640 pSMB
->MaxDataCount
= cpu_to_le16(1000);
1641 pSMB
->SetupCount
= 1;
1642 pSMB
->Reserved3
= 0;
1643 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
1644 byte_count
= 3 /* pad */ + params
+ name_len_target
;
1645 pSMB
->DataCount
= cpu_to_le16(name_len_target
);
1646 pSMB
->ParameterCount
= cpu_to_le16(params
);
1647 pSMB
->TotalDataCount
= pSMB
->DataCount
;
1648 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
1649 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
1650 pSMB
->DataOffset
= cpu_to_le16(offset
);
1651 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_UNIX_LINK
);
1652 pSMB
->Reserved4
= 0;
1653 pSMB
->hdr
.smb_buf_length
+= byte_count
;
1654 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
1655 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
1656 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
1657 cifs_stats_inc(&tcon
->num_symlinks
);
1660 ("Send error in SetPathInfo (create symlink) = %d",
1665 cifs_buf_release(pSMB
);
1668 goto createSymLinkRetry
;
1674 CIFSUnixCreateHardLink(const int xid
, struct cifsTconInfo
*tcon
,
1675 const char *fromName
, const char *toName
,
1676 const struct nls_table
*nls_codepage
, int remap
)
1678 TRANSACTION2_SPI_REQ
*pSMB
= NULL
;
1679 TRANSACTION2_SPI_RSP
*pSMBr
= NULL
;
1682 int name_len_target
;
1684 int bytes_returned
= 0;
1685 __u16 params
, param_offset
, offset
, byte_count
;
1687 cFYI(1, ("In Create Hard link Unix style"));
1688 createHardLinkRetry
:
1689 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
1694 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
1695 name_len
= cifsConvertToUCS((__le16
*) pSMB
->FileName
, toName
,
1696 PATH_MAX
, nls_codepage
, remap
);
1697 name_len
++; /* trailing null */
1700 } else { /* BB improve the check for buffer overruns BB */
1701 name_len
= strnlen(toName
, PATH_MAX
);
1702 name_len
++; /* trailing null */
1703 strncpy(pSMB
->FileName
, toName
, name_len
);
1705 params
= 6 + name_len
;
1706 pSMB
->MaxSetupCount
= 0;
1710 pSMB
->Reserved2
= 0;
1711 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
1712 InformationLevel
) - 4;
1713 offset
= param_offset
+ params
;
1715 data_offset
= (char *) (&pSMB
->hdr
.Protocol
) + offset
;
1716 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
1718 cifsConvertToUCS((__le16
*) data_offset
, fromName
, PATH_MAX
,
1719 nls_codepage
, remap
);
1720 name_len_target
++; /* trailing null */
1721 name_len_target
*= 2;
1722 } else { /* BB improve the check for buffer overruns BB */
1723 name_len_target
= strnlen(fromName
, PATH_MAX
);
1724 name_len_target
++; /* trailing null */
1725 strncpy(data_offset
, fromName
, name_len_target
);
1728 pSMB
->MaxParameterCount
= cpu_to_le16(2);
1729 /* BB find exact max on data count below from sess*/
1730 pSMB
->MaxDataCount
= cpu_to_le16(1000);
1731 pSMB
->SetupCount
= 1;
1732 pSMB
->Reserved3
= 0;
1733 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
1734 byte_count
= 3 /* pad */ + params
+ name_len_target
;
1735 pSMB
->ParameterCount
= cpu_to_le16(params
);
1736 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
1737 pSMB
->DataCount
= cpu_to_le16(name_len_target
);
1738 pSMB
->TotalDataCount
= pSMB
->DataCount
;
1739 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
1740 pSMB
->DataOffset
= cpu_to_le16(offset
);
1741 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_UNIX_HLINK
);
1742 pSMB
->Reserved4
= 0;
1743 pSMB
->hdr
.smb_buf_length
+= byte_count
;
1744 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
1745 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
1746 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
1747 cifs_stats_inc(&tcon
->num_hardlinks
);
1749 cFYI(1, ("Send error in SetPathInfo (hard link) = %d", rc
));
1752 cifs_buf_release(pSMB
);
1754 goto createHardLinkRetry
;
1760 CIFSCreateHardLink(const int xid
, struct cifsTconInfo
*tcon
,
1761 const char *fromName
, const char *toName
,
1762 const struct nls_table
*nls_codepage
, int remap
)
1765 NT_RENAME_REQ
*pSMB
= NULL
;
1766 RENAME_RSP
*pSMBr
= NULL
;
1768 int name_len
, name_len2
;
1771 cFYI(1, ("In CIFSCreateHardLink"));
1772 winCreateHardLinkRetry
:
1774 rc
= smb_init(SMB_COM_NT_RENAME
, 4, tcon
, (void **) &pSMB
,
1779 pSMB
->SearchAttributes
=
1780 cpu_to_le16(ATTR_READONLY
| ATTR_HIDDEN
| ATTR_SYSTEM
|
1782 pSMB
->Flags
= cpu_to_le16(CREATE_HARD_LINK
);
1783 pSMB
->ClusterCount
= 0;
1785 pSMB
->BufferFormat
= 0x04;
1787 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
1789 cifsConvertToUCS((__le16
*) pSMB
->OldFileName
, fromName
,
1790 PATH_MAX
, nls_codepage
, remap
);
1791 name_len
++; /* trailing null */
1793 pSMB
->OldFileName
[name_len
] = 0; /* pad */
1794 pSMB
->OldFileName
[name_len
+ 1] = 0x04;
1796 cifsConvertToUCS((__le16
*)&pSMB
->OldFileName
[name_len
+ 2],
1797 toName
, PATH_MAX
, nls_codepage
, remap
);
1798 name_len2
+= 1 /* trailing null */ + 1 /* Signature word */ ;
1799 name_len2
*= 2; /* convert to bytes */
1800 } else { /* BB improve the check for buffer overruns BB */
1801 name_len
= strnlen(fromName
, PATH_MAX
);
1802 name_len
++; /* trailing null */
1803 strncpy(pSMB
->OldFileName
, fromName
, name_len
);
1804 name_len2
= strnlen(toName
, PATH_MAX
);
1805 name_len2
++; /* trailing null */
1806 pSMB
->OldFileName
[name_len
] = 0x04; /* 2nd buffer format */
1807 strncpy(&pSMB
->OldFileName
[name_len
+ 1], toName
, name_len2
);
1808 name_len2
++; /* trailing null */
1809 name_len2
++; /* signature byte */
1812 count
= 1 /* string type byte */ + name_len
+ name_len2
;
1813 pSMB
->hdr
.smb_buf_length
+= count
;
1814 pSMB
->ByteCount
= cpu_to_le16(count
);
1816 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
1817 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
1818 cifs_stats_inc(&tcon
->num_hardlinks
);
1820 cFYI(1, ("Send error in hard link (NT rename) = %d", rc
));
1822 cifs_buf_release(pSMB
);
1824 goto winCreateHardLinkRetry
;
1830 CIFSSMBUnixQuerySymLink(const int xid
, struct cifsTconInfo
*tcon
,
1831 const unsigned char *searchName
,
1832 char *symlinkinfo
, const int buflen
,
1833 const struct nls_table
*nls_codepage
)
1835 /* SMB_QUERY_FILE_UNIX_LINK */
1836 TRANSACTION2_QPI_REQ
*pSMB
= NULL
;
1837 TRANSACTION2_QPI_RSP
*pSMBr
= NULL
;
1841 __u16 params
, byte_count
;
1843 cFYI(1, ("In QPathSymLinkInfo (Unix) for path %s", searchName
));
1846 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
1851 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
1853 cifs_strtoUCS((__le16
*) pSMB
->FileName
, searchName
, PATH_MAX
1854 /* find define for this maxpathcomponent */
1856 name_len
++; /* trailing null */
1858 } else { /* BB improve the check for buffer overruns BB */
1859 name_len
= strnlen(searchName
, PATH_MAX
);
1860 name_len
++; /* trailing null */
1861 strncpy(pSMB
->FileName
, searchName
, name_len
);
1864 params
= 2 /* level */ + 4 /* rsrvd */ + name_len
/* incl null */ ;
1865 pSMB
->TotalDataCount
= 0;
1866 pSMB
->MaxParameterCount
= cpu_to_le16(2);
1867 /* BB find exact max data count below from sess structure BB */
1868 pSMB
->MaxDataCount
= cpu_to_le16(4000);
1869 pSMB
->MaxSetupCount
= 0;
1873 pSMB
->Reserved2
= 0;
1874 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
1875 struct smb_com_transaction2_qpi_req
,InformationLevel
) - 4);
1876 pSMB
->DataCount
= 0;
1877 pSMB
->DataOffset
= 0;
1878 pSMB
->SetupCount
= 1;
1879 pSMB
->Reserved3
= 0;
1880 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION
);
1881 byte_count
= params
+ 1 /* pad */ ;
1882 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
1883 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
1884 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FILE_UNIX_LINK
);
1885 pSMB
->Reserved4
= 0;
1886 pSMB
->hdr
.smb_buf_length
+= byte_count
;
1887 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
1889 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
1890 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
1892 cFYI(1, ("Send error in QuerySymLinkInfo = %d", rc
));
1894 /* decode response */
1896 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
1897 if (rc
|| (pSMBr
->ByteCount
< 2))
1898 /* BB also check enough total bytes returned */
1899 rc
= -EIO
; /* bad smb */
1901 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
1902 __u16 count
= le16_to_cpu(pSMBr
->t2
.DataCount
);
1904 if (pSMBr
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
1905 name_len
= UniStrnlen((wchar_t *) ((char *)
1906 &pSMBr
->hdr
.Protocol
+data_offset
),
1907 min_t(const int, buflen
,count
) / 2);
1908 /* BB FIXME investigate remapping reserved chars here */
1909 cifs_strfromUCS_le(symlinkinfo
,
1910 (__le16
*) ((char *)&pSMBr
->hdr
.Protocol
+
1912 name_len
, nls_codepage
);
1914 strncpy(symlinkinfo
,
1915 (char *) &pSMBr
->hdr
.Protocol
+
1917 min_t(const int, buflen
, count
));
1919 symlinkinfo
[buflen
] = 0;
1920 /* just in case so calling code does not go off the end of buffer */
1923 cifs_buf_release(pSMB
);
1925 goto querySymLinkRetry
;
1929 /* Initialize NT TRANSACT SMB into small smb request buffer.
1930 This assumes that all NT TRANSACTS that we init here have
1931 total parm and data under about 400 bytes (to fit in small cifs
1932 buffer size), which is the case so far, it easily fits. NB:
1933 Setup words themselves and ByteCount
1934 MaxSetupCount (size of returned setup area) and
1935 MaxParameterCount (returned parms size) must be set by caller */
1937 smb_init_ntransact(const __u16 sub_command
, const int setup_count
,
1938 const int parm_len
, struct cifsTconInfo
*tcon
,
1943 struct smb_com_ntransact_req
* pSMB
;
1945 rc
= small_smb_init(SMB_COM_NT_TRANSACT
, 19 + setup_count
, tcon
,
1949 *ret_buf
= (void *)pSMB
;
1951 pSMB
->TotalParameterCount
= cpu_to_le32(parm_len
);
1952 pSMB
->TotalDataCount
= 0;
1953 pSMB
->MaxDataCount
= cpu_to_le32((tcon
->ses
->server
->maxBuf
-
1954 MAX_CIFS_HDR_SIZE
) & 0xFFFFFF00);
1955 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
1956 pSMB
->DataCount
= pSMB
->TotalDataCount
;
1957 temp_offset
= offsetof(struct smb_com_ntransact_req
, Parms
) +
1958 (setup_count
* 2) - 4 /* for rfc1001 length itself */;
1959 pSMB
->ParameterOffset
= cpu_to_le32(temp_offset
);
1960 pSMB
->DataOffset
= cpu_to_le32(temp_offset
+ parm_len
);
1961 pSMB
->SetupCount
= setup_count
; /* no need to le convert byte fields */
1962 pSMB
->SubCommand
= cpu_to_le16(sub_command
);
1967 validate_ntransact(char * buf
, char ** ppparm
, char ** ppdata
,
1968 int * pdatalen
, int * pparmlen
)
1971 __u32 data_count
, data_offset
, parm_count
, parm_offset
;
1972 struct smb_com_ntransact_rsp
* pSMBr
;
1977 pSMBr
= (struct smb_com_ntransact_rsp
*)buf
;
1979 /* ByteCount was converted from little endian in SendReceive */
1980 end_of_smb
= 2 /* sizeof byte count */ + pSMBr
->ByteCount
+
1981 (char *)&pSMBr
->ByteCount
;
1984 data_offset
= le32_to_cpu(pSMBr
->DataOffset
);
1985 data_count
= le32_to_cpu(pSMBr
->DataCount
);
1986 parm_offset
= le32_to_cpu(pSMBr
->ParameterOffset
);
1987 parm_count
= le32_to_cpu(pSMBr
->ParameterCount
);
1989 *ppparm
= (char *)&pSMBr
->hdr
.Protocol
+ parm_offset
;
1990 *ppdata
= (char *)&pSMBr
->hdr
.Protocol
+ data_offset
;
1992 /* should we also check that parm and data areas do not overlap? */
1993 if(*ppparm
> end_of_smb
) {
1994 cFYI(1,("parms start after end of smb"));
1996 } else if(parm_count
+ *ppparm
> end_of_smb
) {
1997 cFYI(1,("parm end after end of smb"));
1999 } else if(*ppdata
> end_of_smb
) {
2000 cFYI(1,("data starts after end of smb"));
2002 } else if(data_count
+ *ppdata
> end_of_smb
) {
2003 cFYI(1,("data %p + count %d (%p) ends after end of smb %p start %p",
2004 *ppdata
, data_count
, (data_count
+ *ppdata
), end_of_smb
, pSMBr
)); /* BB FIXME */
2006 } else if(parm_count
+ data_count
> pSMBr
->ByteCount
) {
2007 cFYI(1,("parm count and data count larger than SMB"));
2014 CIFSSMBQueryReparseLinkInfo(const int xid
, struct cifsTconInfo
*tcon
,
2015 const unsigned char *searchName
,
2016 char *symlinkinfo
, const int buflen
,__u16 fid
,
2017 const struct nls_table
*nls_codepage
)
2022 struct smb_com_transaction_ioctl_req
* pSMB
;
2023 struct smb_com_transaction_ioctl_rsp
* pSMBr
;
2025 cFYI(1, ("In Windows reparse style QueryLink for path %s", searchName
));
2026 rc
= smb_init(SMB_COM_NT_TRANSACT
, 23, tcon
, (void **) &pSMB
,
2031 pSMB
->TotalParameterCount
= 0 ;
2032 pSMB
->TotalDataCount
= 0;
2033 pSMB
->MaxParameterCount
= cpu_to_le32(2);
2034 /* BB find exact data count max from sess structure BB */
2035 pSMB
->MaxDataCount
= cpu_to_le32((tcon
->ses
->server
->maxBuf
-
2036 MAX_CIFS_HDR_SIZE
) & 0xFFFFFF00);
2037 pSMB
->MaxSetupCount
= 4;
2039 pSMB
->ParameterOffset
= 0;
2040 pSMB
->DataCount
= 0;
2041 pSMB
->DataOffset
= 0;
2042 pSMB
->SetupCount
= 4;
2043 pSMB
->SubCommand
= cpu_to_le16(NT_TRANSACT_IOCTL
);
2044 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
2045 pSMB
->FunctionCode
= cpu_to_le32(FSCTL_GET_REPARSE_POINT
);
2046 pSMB
->IsFsctl
= 1; /* FSCTL */
2047 pSMB
->IsRootFlag
= 0;
2048 pSMB
->Fid
= fid
; /* file handle always le */
2049 pSMB
->ByteCount
= 0;
2051 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
2052 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
2054 cFYI(1, ("Send error in QueryReparseLinkInfo = %d", rc
));
2055 } else { /* decode response */
2056 __u32 data_offset
= le32_to_cpu(pSMBr
->DataOffset
);
2057 __u32 data_count
= le32_to_cpu(pSMBr
->DataCount
);
2058 if ((pSMBr
->ByteCount
< 2) || (data_offset
> 512))
2059 /* BB also check enough total bytes returned */
2060 rc
= -EIO
; /* bad smb */
2062 if(data_count
&& (data_count
< 2048)) {
2063 char * end_of_smb
= 2 /* sizeof byte count */ +
2065 (char *)&pSMBr
->ByteCount
;
2067 struct reparse_data
* reparse_buf
= (struct reparse_data
*)
2068 ((char *)&pSMBr
->hdr
.Protocol
+ data_offset
);
2069 if((char*)reparse_buf
>= end_of_smb
) {
2073 if((reparse_buf
->LinkNamesBuf
+
2074 reparse_buf
->TargetNameOffset
+
2075 reparse_buf
->TargetNameLen
) >
2077 cFYI(1,("reparse buf extended beyond SMB"));
2082 if (pSMBr
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
2083 name_len
= UniStrnlen((wchar_t *)
2084 (reparse_buf
->LinkNamesBuf
+
2085 reparse_buf
->TargetNameOffset
),
2086 min(buflen
/2, reparse_buf
->TargetNameLen
/ 2));
2087 cifs_strfromUCS_le(symlinkinfo
,
2088 (__le16
*) (reparse_buf
->LinkNamesBuf
+
2089 reparse_buf
->TargetNameOffset
),
2090 name_len
, nls_codepage
);
2091 } else { /* ASCII names */
2092 strncpy(symlinkinfo
,reparse_buf
->LinkNamesBuf
+
2093 reparse_buf
->TargetNameOffset
,
2094 min_t(const int, buflen
, reparse_buf
->TargetNameLen
));
2098 cFYI(1,("Invalid return data count on get reparse info ioctl"));
2100 symlinkinfo
[buflen
] = 0; /* just in case so the caller
2101 does not go off the end of the buffer */
2102 cFYI(1,("readlink result - %s ",symlinkinfo
));
2106 cifs_buf_release(pSMB
);
2108 /* Note: On -EAGAIN error only caller can retry on handle based calls
2109 since file handle passed in no longer valid */
2114 #ifdef CONFIG_CIFS_POSIX
2116 /*Convert an Access Control Entry from wire format to local POSIX xattr format*/
2117 static void cifs_convert_ace(posix_acl_xattr_entry
* ace
, struct cifs_posix_ace
* cifs_ace
)
2119 /* u8 cifs fields do not need le conversion */
2120 ace
->e_perm
= cpu_to_le16(cifs_ace
->cifs_e_perm
);
2121 ace
->e_tag
= cpu_to_le16(cifs_ace
->cifs_e_tag
);
2122 ace
->e_id
= cpu_to_le32(le64_to_cpu(cifs_ace
->cifs_uid
));
2123 /* cFYI(1,("perm %d tag %d id %d",ace->e_perm,ace->e_tag,ace->e_id)); */
2128 /* Convert ACL from CIFS POSIX wire format to local Linux POSIX ACL xattr */
2129 static int cifs_copy_posix_acl(char * trgt
,char * src
, const int buflen
,
2130 const int acl_type
,const int size_of_data_area
)
2135 struct cifs_posix_ace
* pACE
;
2136 struct cifs_posix_acl
* cifs_acl
= (struct cifs_posix_acl
*)src
;
2137 posix_acl_xattr_header
* local_acl
= (posix_acl_xattr_header
*)trgt
;
2139 if (le16_to_cpu(cifs_acl
->version
) != CIFS_ACL_VERSION
)
2142 if(acl_type
& ACL_TYPE_ACCESS
) {
2143 count
= le16_to_cpu(cifs_acl
->access_entry_count
);
2144 pACE
= &cifs_acl
->ace_array
[0];
2145 size
= sizeof(struct cifs_posix_acl
);
2146 size
+= sizeof(struct cifs_posix_ace
) * count
;
2147 /* check if we would go beyond end of SMB */
2148 if(size_of_data_area
< size
) {
2149 cFYI(1,("bad CIFS POSIX ACL size %d vs. %d",size_of_data_area
,size
));
2152 } else if(acl_type
& ACL_TYPE_DEFAULT
) {
2153 count
= le16_to_cpu(cifs_acl
->access_entry_count
);
2154 size
= sizeof(struct cifs_posix_acl
);
2155 size
+= sizeof(struct cifs_posix_ace
) * count
;
2156 /* skip past access ACEs to get to default ACEs */
2157 pACE
= &cifs_acl
->ace_array
[count
];
2158 count
= le16_to_cpu(cifs_acl
->default_entry_count
);
2159 size
+= sizeof(struct cifs_posix_ace
) * count
;
2160 /* check if we would go beyond end of SMB */
2161 if(size_of_data_area
< size
)
2168 size
= posix_acl_xattr_size(count
);
2169 if((buflen
== 0) || (local_acl
== NULL
)) {
2170 /* used to query ACL EA size */
2171 } else if(size
> buflen
) {
2173 } else /* buffer big enough */ {
2174 local_acl
->a_version
= cpu_to_le32(POSIX_ACL_XATTR_VERSION
);
2175 for(i
= 0;i
< count
;i
++) {
2176 cifs_convert_ace(&local_acl
->a_entries
[i
],pACE
);
2183 static __u16
convert_ace_to_cifs_ace(struct cifs_posix_ace
* cifs_ace
,
2184 const posix_acl_xattr_entry
* local_ace
)
2186 __u16 rc
= 0; /* 0 = ACL converted ok */
2188 cifs_ace
->cifs_e_perm
= le16_to_cpu(local_ace
->e_perm
);
2189 cifs_ace
->cifs_e_tag
= le16_to_cpu(local_ace
->e_tag
);
2190 /* BB is there a better way to handle the large uid? */
2191 if(local_ace
->e_id
== cpu_to_le32(-1)) {
2192 /* Probably no need to le convert -1 on any arch but can not hurt */
2193 cifs_ace
->cifs_uid
= cpu_to_le64(-1);
2195 cifs_ace
->cifs_uid
= cpu_to_le64(le32_to_cpu(local_ace
->e_id
));
2196 /*cFYI(1,("perm %d tag %d id %d",ace->e_perm,ace->e_tag,ace->e_id));*/
2200 /* Convert ACL from local Linux POSIX xattr to CIFS POSIX ACL wire format */
2201 static __u16
ACL_to_cifs_posix(char * parm_data
,const char * pACL
,const int buflen
,
2205 struct cifs_posix_acl
* cifs_acl
= (struct cifs_posix_acl
*)parm_data
;
2206 posix_acl_xattr_header
* local_acl
= (posix_acl_xattr_header
*)pACL
;
2210 if((buflen
== 0) || (pACL
== NULL
) || (cifs_acl
== NULL
))
2213 count
= posix_acl_xattr_count((size_t)buflen
);
2214 cFYI(1,("setting acl with %d entries from buf of length %d and version of %d",
2215 count
, buflen
, le32_to_cpu(local_acl
->a_version
)));
2216 if(le32_to_cpu(local_acl
->a_version
) != 2) {
2217 cFYI(1,("unknown POSIX ACL version %d",
2218 le32_to_cpu(local_acl
->a_version
)));
2221 cifs_acl
->version
= cpu_to_le16(1);
2222 if(acl_type
== ACL_TYPE_ACCESS
)
2223 cifs_acl
->access_entry_count
= cpu_to_le16(count
);
2224 else if(acl_type
== ACL_TYPE_DEFAULT
)
2225 cifs_acl
->default_entry_count
= cpu_to_le16(count
);
2227 cFYI(1,("unknown ACL type %d",acl_type
));
2230 for(i
=0;i
<count
;i
++) {
2231 rc
= convert_ace_to_cifs_ace(&cifs_acl
->ace_array
[i
],
2232 &local_acl
->a_entries
[i
]);
2234 /* ACE not converted */
2239 rc
= (__u16
)(count
* sizeof(struct cifs_posix_ace
));
2240 rc
+= sizeof(struct cifs_posix_acl
);
2241 /* BB add check to make sure ACL does not overflow SMB */
2247 CIFSSMBGetPosixACL(const int xid
, struct cifsTconInfo
*tcon
,
2248 const unsigned char *searchName
,
2249 char *acl_inf
, const int buflen
, const int acl_type
,
2250 const struct nls_table
*nls_codepage
, int remap
)
2252 /* SMB_QUERY_POSIX_ACL */
2253 TRANSACTION2_QPI_REQ
*pSMB
= NULL
;
2254 TRANSACTION2_QPI_RSP
*pSMBr
= NULL
;
2258 __u16 params
, byte_count
;
2260 cFYI(1, ("In GetPosixACL (Unix) for path %s", searchName
));
2263 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
2268 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
2270 cifsConvertToUCS((__le16
*) pSMB
->FileName
, searchName
,
2271 PATH_MAX
, nls_codepage
, remap
);
2272 name_len
++; /* trailing null */
2274 pSMB
->FileName
[name_len
] = 0;
2275 pSMB
->FileName
[name_len
+1] = 0;
2276 } else { /* BB improve the check for buffer overruns BB */
2277 name_len
= strnlen(searchName
, PATH_MAX
);
2278 name_len
++; /* trailing null */
2279 strncpy(pSMB
->FileName
, searchName
, name_len
);
2282 params
= 2 /* level */ + 4 /* rsrvd */ + name_len
/* incl null */ ;
2283 pSMB
->TotalDataCount
= 0;
2284 pSMB
->MaxParameterCount
= cpu_to_le16(2);
2285 /* BB find exact max data count below from sess structure BB */
2286 pSMB
->MaxDataCount
= cpu_to_le16(4000);
2287 pSMB
->MaxSetupCount
= 0;
2291 pSMB
->Reserved2
= 0;
2292 pSMB
->ParameterOffset
= cpu_to_le16(
2293 offsetof(struct smb_com_transaction2_qpi_req
,InformationLevel
) - 4);
2294 pSMB
->DataCount
= 0;
2295 pSMB
->DataOffset
= 0;
2296 pSMB
->SetupCount
= 1;
2297 pSMB
->Reserved3
= 0;
2298 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION
);
2299 byte_count
= params
+ 1 /* pad */ ;
2300 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
2301 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
2302 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_POSIX_ACL
);
2303 pSMB
->Reserved4
= 0;
2304 pSMB
->hdr
.smb_buf_length
+= byte_count
;
2305 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
2307 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
2308 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
2309 cifs_stats_inc(&tcon
->num_acl_get
);
2311 cFYI(1, ("Send error in Query POSIX ACL = %d", rc
));
2313 /* decode response */
2315 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
2316 if (rc
|| (pSMBr
->ByteCount
< 2))
2317 /* BB also check enough total bytes returned */
2318 rc
= -EIO
; /* bad smb */
2320 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
2321 __u16 count
= le16_to_cpu(pSMBr
->t2
.DataCount
);
2322 rc
= cifs_copy_posix_acl(acl_inf
,
2323 (char *)&pSMBr
->hdr
.Protocol
+data_offset
,
2324 buflen
,acl_type
,count
);
2327 cifs_buf_release(pSMB
);
2334 CIFSSMBSetPosixACL(const int xid
, struct cifsTconInfo
*tcon
,
2335 const unsigned char *fileName
,
2336 const char *local_acl
, const int buflen
,
2338 const struct nls_table
*nls_codepage
, int remap
)
2340 struct smb_com_transaction2_spi_req
*pSMB
= NULL
;
2341 struct smb_com_transaction2_spi_rsp
*pSMBr
= NULL
;
2345 int bytes_returned
= 0;
2346 __u16 params
, byte_count
, data_count
, param_offset
, offset
;
2348 cFYI(1, ("In SetPosixACL (Unix) for path %s", fileName
));
2350 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
2354 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
2356 cifsConvertToUCS((__le16
*) pSMB
->FileName
, fileName
,
2357 PATH_MAX
, nls_codepage
, remap
);
2358 name_len
++; /* trailing null */
2360 } else { /* BB improve the check for buffer overruns BB */
2361 name_len
= strnlen(fileName
, PATH_MAX
);
2362 name_len
++; /* trailing null */
2363 strncpy(pSMB
->FileName
, fileName
, name_len
);
2365 params
= 6 + name_len
;
2366 pSMB
->MaxParameterCount
= cpu_to_le16(2);
2367 pSMB
->MaxDataCount
= cpu_to_le16(1000); /* BB find max SMB size from sess */
2368 pSMB
->MaxSetupCount
= 0;
2372 pSMB
->Reserved2
= 0;
2373 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
2374 InformationLevel
) - 4;
2375 offset
= param_offset
+ params
;
2376 parm_data
= ((char *) &pSMB
->hdr
.Protocol
) + offset
;
2377 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
2379 /* convert to on the wire format for POSIX ACL */
2380 data_count
= ACL_to_cifs_posix(parm_data
,local_acl
,buflen
,acl_type
);
2382 if(data_count
== 0) {
2384 goto setACLerrorExit
;
2386 pSMB
->DataOffset
= cpu_to_le16(offset
);
2387 pSMB
->SetupCount
= 1;
2388 pSMB
->Reserved3
= 0;
2389 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
2390 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_POSIX_ACL
);
2391 byte_count
= 3 /* pad */ + params
+ data_count
;
2392 pSMB
->DataCount
= cpu_to_le16(data_count
);
2393 pSMB
->TotalDataCount
= pSMB
->DataCount
;
2394 pSMB
->ParameterCount
= cpu_to_le16(params
);
2395 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
2396 pSMB
->Reserved4
= 0;
2397 pSMB
->hdr
.smb_buf_length
+= byte_count
;
2398 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
2399 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
2400 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
2402 cFYI(1, ("Set POSIX ACL returned %d", rc
));
2406 cifs_buf_release(pSMB
);
2412 /* BB fix tabs in this function FIXME BB */
2414 CIFSGetExtAttr(const int xid
, struct cifsTconInfo
*tcon
,
2415 const int netfid
, __u64
* pExtAttrBits
, __u64
*pMask
)
2418 struct smb_t2_qfi_req
*pSMB
= NULL
;
2419 struct smb_t2_qfi_rsp
*pSMBr
= NULL
;
2421 __u16 params
, byte_count
;
2423 cFYI(1,("In GetExtAttr"));
2428 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
2433 params
= 2 /* level */ +2 /* fid */;
2434 pSMB
->t2
.TotalDataCount
= 0;
2435 pSMB
->t2
.MaxParameterCount
= cpu_to_le16(4);
2436 /* BB find exact max data count below from sess structure BB */
2437 pSMB
->t2
.MaxDataCount
= cpu_to_le16(4000);
2438 pSMB
->t2
.MaxSetupCount
= 0;
2439 pSMB
->t2
.Reserved
= 0;
2441 pSMB
->t2
.Timeout
= 0;
2442 pSMB
->t2
.Reserved2
= 0;
2443 pSMB
->t2
.ParameterOffset
= cpu_to_le16(offsetof(struct smb_t2_qfi_req
,
2445 pSMB
->t2
.DataCount
= 0;
2446 pSMB
->t2
.DataOffset
= 0;
2447 pSMB
->t2
.SetupCount
= 1;
2448 pSMB
->t2
.Reserved3
= 0;
2449 pSMB
->t2
.SubCommand
= cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION
);
2450 byte_count
= params
+ 1 /* pad */ ;
2451 pSMB
->t2
.TotalParameterCount
= cpu_to_le16(params
);
2452 pSMB
->t2
.ParameterCount
= pSMB
->t2
.TotalParameterCount
;
2453 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_ATTR_FLAGS
);
2456 pSMB
->hdr
.smb_buf_length
+= byte_count
;
2457 pSMB
->t2
.ByteCount
= cpu_to_le16(byte_count
);
2459 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
2460 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
2462 cFYI(1, ("error %d in GetExtAttr", rc
));
2464 /* decode response */
2465 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
2466 if (rc
|| (pSMBr
->ByteCount
< 2))
2467 /* BB also check enough total bytes returned */
2468 /* If rc should we check for EOPNOSUPP and
2469 disable the srvino flag? or in caller? */
2470 rc
= -EIO
; /* bad smb */
2472 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
2473 __u16 count
= le16_to_cpu(pSMBr
->t2
.DataCount
);
2474 struct file_chattr_info
* pfinfo
;
2475 /* BB Do we need a cast or hash here ? */
2477 cFYI(1, ("Illegal size ret in GetExtAttr"));
2481 pfinfo
= (struct file_chattr_info
*)
2482 (data_offset
+ (char *) &pSMBr
->hdr
.Protocol
);
2483 *pExtAttrBits
= le64_to_cpu(pfinfo
->mode
);
2484 *pMask
= le64_to_cpu(pfinfo
->mask
);
2488 cifs_buf_release(pSMB
);
2490 goto GetExtAttrRetry
;
2495 #endif /* CONFIG_POSIX */
2497 /* Convert CIFS ACL to POSIX form */
2498 static int parse_sec_desc(struct sec_desc
* psec_desc
, int acl_len
)
2500 CHECK ON OTHER COMPUTER TO SEE IF FORMAT ENCODED IN CIFSPDU
.H ALREADY
2504 /* Get Security Descriptor (by handle) from remote server for a file or dir */
2506 CIFSSMBGetCIFSACL(const int xid
, struct cifsTconInfo
*tcon
, __u16 fid
,
2507 /* BB fix up return info */ char *acl_inf
, const int buflen
,
2508 const int acl_type
/* ACCESS/DEFAULT not sure implication */)
2512 QUERY_SEC_DESC_REQ
* pSMB
;
2515 cFYI(1, ("GetCifsACL"));
2517 rc
= smb_init_ntransact(NT_TRANSACT_QUERY_SECURITY_DESC
, 0,
2518 8 /* parm len */, tcon
, (void **) &pSMB
);
2522 pSMB
->MaxParameterCount
= cpu_to_le32(4);
2523 /* BB TEST with big acls that might need to be e.g. larger than 16K */
2524 pSMB
->MaxSetupCount
= 0;
2525 pSMB
->Fid
= fid
; /* file handle always le */
2526 pSMB
->AclFlags
= cpu_to_le32(CIFS_ACL_OWNER
| CIFS_ACL_GROUP
|
2528 pSMB
->ByteCount
= cpu_to_le16(11); /* 3 bytes pad + 8 bytes parm */
2529 pSMB
->hdr
.smb_buf_length
+= 11;
2530 iov
[0].iov_base
= (char *)pSMB
;
2531 iov
[0].iov_len
= pSMB
->hdr
.smb_buf_length
+ 4;
2533 rc
= SendReceive2(xid
, tcon
->ses
, iov
, 1 /* num iovec */, &buf_type
, 0);
2534 cifs_stats_inc(&tcon
->num_acl_get
);
2536 cFYI(1, ("Send error in QuerySecDesc = %d", rc
));
2537 } else { /* decode response */
2538 struct sec_desc
* psec_desc
;
2543 struct smb_com_ntransact_rsp
* pSMBr
;
2545 /* validate_nttransact */
2546 rc
= validate_ntransact(iov
[0].iov_base
, (char **)&parm
,
2547 (char **)&psec_desc
,
2548 &parm_len
, &data_len
);
2552 pSMBr
= (struct smb_com_ntransact_rsp
*)iov
[0].iov_base
;
2554 cERROR(1,("smb %p parm %p data %p",pSMBr
,parm
,psec_desc
)); /* BB removeme BB */
2556 if (le32_to_cpu(pSMBr
->ParameterCount
) != 4) {
2557 rc
= -EIO
; /* bad smb */
2561 /* BB check that data area is minimum length and as big as acl_len */
2563 acl_len
= le32_to_cpu(*(__le32
*)parm
);
2564 /* BB check if(acl_len > bufsize) */
2566 parse_sec_desc(psec_desc
, acl_len
);
2569 if(buf_type
== CIFS_SMALL_BUFFER
)
2570 cifs_small_buf_release(iov
[0].iov_base
);
2571 else if(buf_type
== CIFS_LARGE_BUFFER
)
2572 cifs_buf_release(iov
[0].iov_base
);
2573 cifs_small_buf_release(pSMB
);
2578 /* Legacy Query Path Information call for lookup to old servers such
2580 int SMBQueryInformation(const int xid
, struct cifsTconInfo
*tcon
,
2581 const unsigned char *searchName
,
2582 FILE_ALL_INFO
* pFinfo
,
2583 const struct nls_table
*nls_codepage
, int remap
)
2585 QUERY_INFORMATION_REQ
* pSMB
;
2586 QUERY_INFORMATION_RSP
* pSMBr
;
2591 cFYI(1, ("In SMBQPath path %s", searchName
));
2593 rc
= smb_init(SMB_COM_QUERY_INFORMATION
, 0, tcon
, (void **) &pSMB
,
2598 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
2600 cifsConvertToUCS((__le16
*) pSMB
->FileName
, searchName
,
2601 PATH_MAX
, nls_codepage
, remap
);
2602 name_len
++; /* trailing null */
2605 name_len
= strnlen(searchName
, PATH_MAX
);
2606 name_len
++; /* trailing null */
2607 strncpy(pSMB
->FileName
, searchName
, name_len
);
2609 pSMB
->BufferFormat
= 0x04;
2610 name_len
++; /* account for buffer type byte */
2611 pSMB
->hdr
.smb_buf_length
+= (__u16
) name_len
;
2612 pSMB
->ByteCount
= cpu_to_le16(name_len
);
2614 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
2615 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
2617 cFYI(1, ("Send error in QueryInfo = %d", rc
));
2618 } else if (pFinfo
) { /* decode response */
2619 memset(pFinfo
, 0, sizeof(FILE_ALL_INFO
));
2620 pFinfo
->AllocationSize
=
2621 cpu_to_le64(le32_to_cpu(pSMBr
->size
));
2622 pFinfo
->EndOfFile
= pFinfo
->AllocationSize
;
2623 pFinfo
->Attributes
=
2624 cpu_to_le32(le16_to_cpu(pSMBr
->attr
));
2626 rc
= -EIO
; /* bad buffer passed in */
2628 cifs_buf_release(pSMB
);
2640 CIFSSMBQPathInfo(const int xid
, struct cifsTconInfo
*tcon
,
2641 const unsigned char *searchName
,
2642 FILE_ALL_INFO
* pFindData
,
2643 const struct nls_table
*nls_codepage
, int remap
)
2645 /* level 263 SMB_QUERY_FILE_ALL_INFO */
2646 TRANSACTION2_QPI_REQ
*pSMB
= NULL
;
2647 TRANSACTION2_QPI_RSP
*pSMBr
= NULL
;
2651 __u16 params
, byte_count
;
2653 /* cFYI(1, ("In QPathInfo path %s", searchName)); */
2655 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
2660 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
2662 cifsConvertToUCS((__le16
*) pSMB
->FileName
, searchName
,
2663 PATH_MAX
, nls_codepage
, remap
);
2664 name_len
++; /* trailing null */
2666 } else { /* BB improve the check for buffer overruns BB */
2667 name_len
= strnlen(searchName
, PATH_MAX
);
2668 name_len
++; /* trailing null */
2669 strncpy(pSMB
->FileName
, searchName
, name_len
);
2672 params
= 2 /* level */ + 4 /* reserved */ + name_len
/* includes NUL */ ;
2673 pSMB
->TotalDataCount
= 0;
2674 pSMB
->MaxParameterCount
= cpu_to_le16(2);
2675 pSMB
->MaxDataCount
= cpu_to_le16(4000); /* BB find exact max SMB PDU from sess structure BB */
2676 pSMB
->MaxSetupCount
= 0;
2680 pSMB
->Reserved2
= 0;
2681 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
2682 struct smb_com_transaction2_qpi_req
,InformationLevel
) - 4);
2683 pSMB
->DataCount
= 0;
2684 pSMB
->DataOffset
= 0;
2685 pSMB
->SetupCount
= 1;
2686 pSMB
->Reserved3
= 0;
2687 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION
);
2688 byte_count
= params
+ 1 /* pad */ ;
2689 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
2690 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
2691 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FILE_ALL_INFO
);
2692 pSMB
->Reserved4
= 0;
2693 pSMB
->hdr
.smb_buf_length
+= byte_count
;
2694 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
2696 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
2697 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
2699 cFYI(1, ("Send error in QPathInfo = %d", rc
));
2700 } else { /* decode response */
2701 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
2703 if (rc
|| (pSMBr
->ByteCount
< 40))
2704 rc
= -EIO
; /* bad smb */
2705 else if (pFindData
){
2706 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
2707 memcpy((char *) pFindData
,
2708 (char *) &pSMBr
->hdr
.Protocol
+
2709 data_offset
, sizeof (FILE_ALL_INFO
));
2713 cifs_buf_release(pSMB
);
2715 goto QPathInfoRetry
;
2721 CIFSSMBUnixQPathInfo(const int xid
, struct cifsTconInfo
*tcon
,
2722 const unsigned char *searchName
,
2723 FILE_UNIX_BASIC_INFO
* pFindData
,
2724 const struct nls_table
*nls_codepage
, int remap
)
2726 /* SMB_QUERY_FILE_UNIX_BASIC */
2727 TRANSACTION2_QPI_REQ
*pSMB
= NULL
;
2728 TRANSACTION2_QPI_RSP
*pSMBr
= NULL
;
2730 int bytes_returned
= 0;
2732 __u16 params
, byte_count
;
2734 cFYI(1, ("In QPathInfo (Unix) the path %s", searchName
));
2736 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
2741 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
2743 cifsConvertToUCS((__le16
*) pSMB
->FileName
, searchName
,
2744 PATH_MAX
, nls_codepage
, remap
);
2745 name_len
++; /* trailing null */
2747 } else { /* BB improve the check for buffer overruns BB */
2748 name_len
= strnlen(searchName
, PATH_MAX
);
2749 name_len
++; /* trailing null */
2750 strncpy(pSMB
->FileName
, searchName
, name_len
);
2753 params
= 2 /* level */ + 4 /* reserved */ + name_len
/* includes NUL */ ;
2754 pSMB
->TotalDataCount
= 0;
2755 pSMB
->MaxParameterCount
= cpu_to_le16(2);
2756 /* BB find exact max SMB PDU from sess structure BB */
2757 pSMB
->MaxDataCount
= cpu_to_le16(4000);
2758 pSMB
->MaxSetupCount
= 0;
2762 pSMB
->Reserved2
= 0;
2763 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
2764 struct smb_com_transaction2_qpi_req
,InformationLevel
) - 4);
2765 pSMB
->DataCount
= 0;
2766 pSMB
->DataOffset
= 0;
2767 pSMB
->SetupCount
= 1;
2768 pSMB
->Reserved3
= 0;
2769 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION
);
2770 byte_count
= params
+ 1 /* pad */ ;
2771 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
2772 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
2773 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC
);
2774 pSMB
->Reserved4
= 0;
2775 pSMB
->hdr
.smb_buf_length
+= byte_count
;
2776 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
2778 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
2779 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
2781 cFYI(1, ("Send error in QPathInfo = %d", rc
));
2782 } else { /* decode response */
2783 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
2785 if (rc
|| (pSMBr
->ByteCount
< sizeof(FILE_UNIX_BASIC_INFO
))) {
2786 rc
= -EIO
; /* bad smb */
2788 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
2789 memcpy((char *) pFindData
,
2790 (char *) &pSMBr
->hdr
.Protocol
+
2792 sizeof (FILE_UNIX_BASIC_INFO
));
2795 cifs_buf_release(pSMB
);
2797 goto UnixQPathInfoRetry
;
2802 #if 0 /* function unused at present */
2803 int CIFSFindSingle(const int xid
, struct cifsTconInfo
*tcon
,
2804 const char *searchName
, FILE_ALL_INFO
* findData
,
2805 const struct nls_table
*nls_codepage
)
2807 /* level 257 SMB_ */
2808 TRANSACTION2_FFIRST_REQ
*pSMB
= NULL
;
2809 TRANSACTION2_FFIRST_RSP
*pSMBr
= NULL
;
2813 __u16 params
, byte_count
;
2815 cFYI(1, ("In FindUnique"));
2817 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
2822 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
2824 cifsConvertToUCS((__le16
*) pSMB
->FileName
, searchName
, PATH_MAX
2825 /* find define for this maxpathcomponent */
2827 name_len
++; /* trailing null */
2829 } else { /* BB improve the check for buffer overruns BB */
2830 name_len
= strnlen(searchName
, PATH_MAX
);
2831 name_len
++; /* trailing null */
2832 strncpy(pSMB
->FileName
, searchName
, name_len
);
2835 params
= 12 + name_len
/* includes null */ ;
2836 pSMB
->TotalDataCount
= 0; /* no EAs */
2837 pSMB
->MaxParameterCount
= cpu_to_le16(2);
2838 pSMB
->MaxDataCount
= cpu_to_le16(4000); /* BB find exact max SMB PDU from sess structure BB */
2839 pSMB
->MaxSetupCount
= 0;
2843 pSMB
->Reserved2
= 0;
2844 pSMB
->ParameterOffset
= cpu_to_le16(
2845 offsetof(struct smb_com_transaction2_ffirst_req
,InformationLevel
) - 4);
2846 pSMB
->DataCount
= 0;
2847 pSMB
->DataOffset
= 0;
2848 pSMB
->SetupCount
= 1; /* one byte, no need to le convert */
2849 pSMB
->Reserved3
= 0;
2850 pSMB
->SubCommand
= cpu_to_le16(TRANS2_FIND_FIRST
);
2851 byte_count
= params
+ 1 /* pad */ ;
2852 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
2853 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
2854 pSMB
->SearchAttributes
=
2855 cpu_to_le16(ATTR_READONLY
| ATTR_HIDDEN
| ATTR_SYSTEM
|
2857 pSMB
->SearchCount
= cpu_to_le16(16); /* BB increase */
2858 pSMB
->SearchFlags
= cpu_to_le16(1);
2859 pSMB
->InformationLevel
= cpu_to_le16(SMB_FIND_FILE_DIRECTORY_INFO
);
2860 pSMB
->SearchStorageType
= 0; /* BB what should we set this to? BB */
2861 pSMB
->hdr
.smb_buf_length
+= byte_count
;
2862 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
2864 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
2865 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
2868 cFYI(1, ("Send error in FindFileDirInfo = %d", rc
));
2869 } else { /* decode response */
2870 cifs_stats_inc(&tcon
->num_ffirst
);
2874 cifs_buf_release(pSMB
);
2876 goto findUniqueRetry
;
2880 #endif /* end unused (temporarily) function */
2882 /* xid, tcon, searchName and codepage are input parms, rest are returned */
2884 CIFSFindFirst(const int xid
, struct cifsTconInfo
*tcon
,
2885 const char *searchName
,
2886 const struct nls_table
*nls_codepage
,
2888 struct cifs_search_info
* psrch_inf
, int remap
, const char dirsep
)
2890 /* level 257 SMB_ */
2891 TRANSACTION2_FFIRST_REQ
*pSMB
= NULL
;
2892 TRANSACTION2_FFIRST_RSP
*pSMBr
= NULL
;
2893 T2_FFIRST_RSP_PARMS
* parms
;
2895 int bytes_returned
= 0;
2897 __u16 params
, byte_count
;
2899 cFYI(1, ("In FindFirst for %s",searchName
));
2902 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
2907 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
2909 cifsConvertToUCS((__le16
*) pSMB
->FileName
,searchName
,
2910 PATH_MAX
, nls_codepage
, remap
);
2911 /* We can not add the asterik earlier in case
2912 it got remapped to 0xF03A as if it were part of the
2913 directory name instead of a wildcard */
2915 pSMB
->FileName
[name_len
] = dirsep
;
2916 pSMB
->FileName
[name_len
+1] = 0;
2917 pSMB
->FileName
[name_len
+2] = '*';
2918 pSMB
->FileName
[name_len
+3] = 0;
2919 name_len
+= 4; /* now the trailing null */
2920 pSMB
->FileName
[name_len
] = 0; /* null terminate just in case */
2921 pSMB
->FileName
[name_len
+1] = 0;
2923 } else { /* BB add check for overrun of SMB buf BB */
2924 name_len
= strnlen(searchName
, PATH_MAX
);
2925 /* BB fix here and in unicode clause above ie
2926 if(name_len > buffersize-header)
2927 free buffer exit; BB */
2928 strncpy(pSMB
->FileName
, searchName
, name_len
);
2929 pSMB
->FileName
[name_len
] = dirsep
;
2930 pSMB
->FileName
[name_len
+1] = '*';
2931 pSMB
->FileName
[name_len
+2] = 0;
2935 params
= 12 + name_len
/* includes null */ ;
2936 pSMB
->TotalDataCount
= 0; /* no EAs */
2937 pSMB
->MaxParameterCount
= cpu_to_le16(10);
2938 pSMB
->MaxDataCount
= cpu_to_le16((tcon
->ses
->server
->maxBuf
-
2939 MAX_CIFS_HDR_SIZE
) & 0xFFFFFF00);
2940 pSMB
->MaxSetupCount
= 0;
2944 pSMB
->Reserved2
= 0;
2945 byte_count
= params
+ 1 /* pad */ ;
2946 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
2947 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
2948 pSMB
->ParameterOffset
= cpu_to_le16(
2949 offsetof(struct smb_com_transaction2_ffirst_req
, SearchAttributes
) - 4);
2950 pSMB
->DataCount
= 0;
2951 pSMB
->DataOffset
= 0;
2952 pSMB
->SetupCount
= 1; /* one byte, no need to make endian neutral */
2953 pSMB
->Reserved3
= 0;
2954 pSMB
->SubCommand
= cpu_to_le16(TRANS2_FIND_FIRST
);
2955 pSMB
->SearchAttributes
=
2956 cpu_to_le16(ATTR_READONLY
| ATTR_HIDDEN
| ATTR_SYSTEM
|
2958 pSMB
->SearchCount
= cpu_to_le16(CIFSMaxBufSize
/sizeof(FILE_UNIX_INFO
));
2959 pSMB
->SearchFlags
= cpu_to_le16(CIFS_SEARCH_CLOSE_AT_END
|
2960 CIFS_SEARCH_RETURN_RESUME
);
2961 pSMB
->InformationLevel
= cpu_to_le16(psrch_inf
->info_level
);
2963 /* BB what should we set StorageType to? Does it matter? BB */
2964 pSMB
->SearchStorageType
= 0;
2965 pSMB
->hdr
.smb_buf_length
+= byte_count
;
2966 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
2968 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
2969 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
2970 cifs_stats_inc(&tcon
->num_ffirst
);
2972 if (rc
) {/* BB add logic to retry regular search if Unix search rejected unexpectedly by server */
2973 /* BB Add code to handle unsupported level rc */
2974 cFYI(1, ("Error in FindFirst = %d", rc
));
2977 cifs_buf_release(pSMB
);
2979 /* BB eventually could optimize out free and realloc of buf */
2982 goto findFirstRetry
;
2983 } else { /* decode response */
2984 /* BB remember to free buffer if error BB */
2985 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
2987 if (pSMBr
->hdr
.Flags2
& SMBFLG2_UNICODE
)
2988 psrch_inf
->unicode
= TRUE
;
2990 psrch_inf
->unicode
= FALSE
;
2992 psrch_inf
->ntwrk_buf_start
= (char *)pSMBr
;
2993 psrch_inf
->srch_entries_start
=
2994 (char *) &pSMBr
->hdr
.Protocol
+
2995 le16_to_cpu(pSMBr
->t2
.DataOffset
);
2996 parms
= (T2_FFIRST_RSP_PARMS
*)((char *) &pSMBr
->hdr
.Protocol
+
2997 le16_to_cpu(pSMBr
->t2
.ParameterOffset
));
2999 if(parms
->EndofSearch
)
3000 psrch_inf
->endOfSearch
= TRUE
;
3002 psrch_inf
->endOfSearch
= FALSE
;
3004 psrch_inf
->entries_in_buffer
= le16_to_cpu(parms
->SearchCount
);
3005 psrch_inf
->index_of_last_entry
=
3006 psrch_inf
->entries_in_buffer
;
3007 *pnetfid
= parms
->SearchHandle
;
3009 cifs_buf_release(pSMB
);
3016 int CIFSFindNext(const int xid
, struct cifsTconInfo
*tcon
,
3017 __u16 searchHandle
, struct cifs_search_info
* psrch_inf
)
3019 TRANSACTION2_FNEXT_REQ
*pSMB
= NULL
;
3020 TRANSACTION2_FNEXT_RSP
*pSMBr
= NULL
;
3021 T2_FNEXT_RSP_PARMS
* parms
;
3022 char *response_data
;
3024 int bytes_returned
, name_len
;
3025 __u16 params
, byte_count
;
3027 cFYI(1, ("In FindNext"));
3029 if(psrch_inf
->endOfSearch
== TRUE
)
3032 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
3037 params
= 14; /* includes 2 bytes of null string, converted to LE below */
3039 pSMB
->TotalDataCount
= 0; /* no EAs */
3040 pSMB
->MaxParameterCount
= cpu_to_le16(8);
3041 pSMB
->MaxDataCount
=
3042 cpu_to_le16((tcon
->ses
->server
->maxBuf
- MAX_CIFS_HDR_SIZE
) & 0xFFFFFF00);
3043 pSMB
->MaxSetupCount
= 0;
3047 pSMB
->Reserved2
= 0;
3048 pSMB
->ParameterOffset
= cpu_to_le16(
3049 offsetof(struct smb_com_transaction2_fnext_req
,SearchHandle
) - 4);
3050 pSMB
->DataCount
= 0;
3051 pSMB
->DataOffset
= 0;
3052 pSMB
->SetupCount
= 1;
3053 pSMB
->Reserved3
= 0;
3054 pSMB
->SubCommand
= cpu_to_le16(TRANS2_FIND_NEXT
);
3055 pSMB
->SearchHandle
= searchHandle
; /* always kept as le */
3057 cpu_to_le16(CIFSMaxBufSize
/ sizeof (FILE_UNIX_INFO
));
3058 /* test for Unix extensions */
3059 /* if (tcon->ses->capabilities & CAP_UNIX) {
3060 pSMB->InformationLevel = cpu_to_le16(SMB_FIND_FILE_UNIX);
3061 psrch_inf->info_level = SMB_FIND_FILE_UNIX;
3063 pSMB->InformationLevel =
3064 cpu_to_le16(SMB_FIND_FILE_DIRECTORY_INFO);
3065 psrch_inf->info_level = SMB_FIND_FILE_DIRECTORY_INFO;
3067 pSMB
->InformationLevel
= cpu_to_le16(psrch_inf
->info_level
);
3068 pSMB
->ResumeKey
= psrch_inf
->resume_key
;
3070 cpu_to_le16(CIFS_SEARCH_CLOSE_AT_END
| CIFS_SEARCH_RETURN_RESUME
);
3072 name_len
= psrch_inf
->resume_name_len
;
3074 if(name_len
< PATH_MAX
) {
3075 memcpy(pSMB
->ResumeFileName
, psrch_inf
->presume_name
, name_len
);
3076 byte_count
+= name_len
;
3077 /* 14 byte parm len above enough for 2 byte null terminator */
3078 pSMB
->ResumeFileName
[name_len
] = 0;
3079 pSMB
->ResumeFileName
[name_len
+1] = 0;
3082 goto FNext2_err_exit
;
3084 byte_count
= params
+ 1 /* pad */ ;
3085 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
3086 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
3087 pSMB
->hdr
.smb_buf_length
+= byte_count
;
3088 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
3090 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3091 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3092 cifs_stats_inc(&tcon
->num_fnext
);
3095 psrch_inf
->endOfSearch
= TRUE
;
3096 rc
= 0; /* search probably was closed at end of search above */
3098 cFYI(1, ("FindNext returned = %d", rc
));
3099 } else { /* decode response */
3100 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
3103 /* BB fixme add lock for file (srch_info) struct here */
3104 if (pSMBr
->hdr
.Flags2
& SMBFLG2_UNICODE
)
3105 psrch_inf
->unicode
= TRUE
;
3107 psrch_inf
->unicode
= FALSE
;
3108 response_data
= (char *) &pSMBr
->hdr
.Protocol
+
3109 le16_to_cpu(pSMBr
->t2
.ParameterOffset
);
3110 parms
= (T2_FNEXT_RSP_PARMS
*)response_data
;
3111 response_data
= (char *)&pSMBr
->hdr
.Protocol
+
3112 le16_to_cpu(pSMBr
->t2
.DataOffset
);
3113 cifs_buf_release(psrch_inf
->ntwrk_buf_start
);
3114 psrch_inf
->srch_entries_start
= response_data
;
3115 psrch_inf
->ntwrk_buf_start
= (char *)pSMB
;
3116 if(parms
->EndofSearch
)
3117 psrch_inf
->endOfSearch
= TRUE
;
3119 psrch_inf
->endOfSearch
= FALSE
;
3121 psrch_inf
->entries_in_buffer
= le16_to_cpu(parms
->SearchCount
);
3122 psrch_inf
->index_of_last_entry
+=
3123 psrch_inf
->entries_in_buffer
;
3124 /* cFYI(1,("fnxt2 entries in buf %d index_of_last %d",psrch_inf->entries_in_buffer,psrch_inf->index_of_last_entry)); */
3126 /* BB fixme add unlock here */
3131 /* BB On error, should we leave previous search buf (and count and
3132 last entry fields) intact or free the previous one? */
3134 /* Note: On -EAGAIN error only caller can retry on handle based calls
3135 since file handle passed in no longer valid */
3138 cifs_buf_release(pSMB
);
3144 CIFSFindClose(const int xid
, struct cifsTconInfo
*tcon
, const __u16 searchHandle
)
3147 FINDCLOSE_REQ
*pSMB
= NULL
;
3148 CLOSE_RSP
*pSMBr
= NULL
; /* BB removeme BB */
3151 cFYI(1, ("In CIFSSMBFindClose"));
3152 rc
= small_smb_init(SMB_COM_FIND_CLOSE2
, 1, tcon
, (void **)&pSMB
);
3154 /* no sense returning error if session restarted
3155 as file handle has been closed */
3161 pSMBr
= (CLOSE_RSP
*)pSMB
; /* BB removeme BB */
3162 pSMB
->FileID
= searchHandle
;
3163 pSMB
->ByteCount
= 0;
3164 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3165 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3167 cERROR(1, ("Send error in FindClose = %d", rc
));
3169 cifs_stats_inc(&tcon
->num_fclose
);
3170 cifs_small_buf_release(pSMB
);
3172 /* Since session is dead, search handle closed on server already */
3180 CIFSGetSrvInodeNumber(const int xid
, struct cifsTconInfo
*tcon
,
3181 const unsigned char *searchName
,
3182 __u64
* inode_number
,
3183 const struct nls_table
*nls_codepage
, int remap
)
3186 TRANSACTION2_QPI_REQ
*pSMB
= NULL
;
3187 TRANSACTION2_QPI_RSP
*pSMBr
= NULL
;
3188 int name_len
, bytes_returned
;
3189 __u16 params
, byte_count
;
3191 cFYI(1,("In GetSrvInodeNum for %s",searchName
));
3195 GetInodeNumberRetry
:
3196 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
3202 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
3204 cifsConvertToUCS((__le16
*) pSMB
->FileName
, searchName
,
3205 PATH_MAX
,nls_codepage
, remap
);
3206 name_len
++; /* trailing null */
3208 } else { /* BB improve the check for buffer overruns BB */
3209 name_len
= strnlen(searchName
, PATH_MAX
);
3210 name_len
++; /* trailing null */
3211 strncpy(pSMB
->FileName
, searchName
, name_len
);
3214 params
= 2 /* level */ + 4 /* rsrvd */ + name_len
/* incl null */ ;
3215 pSMB
->TotalDataCount
= 0;
3216 pSMB
->MaxParameterCount
= cpu_to_le16(2);
3217 /* BB find exact max data count below from sess structure BB */
3218 pSMB
->MaxDataCount
= cpu_to_le16(4000);
3219 pSMB
->MaxSetupCount
= 0;
3223 pSMB
->Reserved2
= 0;
3224 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
3225 struct smb_com_transaction2_qpi_req
,InformationLevel
) - 4);
3226 pSMB
->DataCount
= 0;
3227 pSMB
->DataOffset
= 0;
3228 pSMB
->SetupCount
= 1;
3229 pSMB
->Reserved3
= 0;
3230 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION
);
3231 byte_count
= params
+ 1 /* pad */ ;
3232 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
3233 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
3234 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FILE_INTERNAL_INFO
);
3235 pSMB
->Reserved4
= 0;
3236 pSMB
->hdr
.smb_buf_length
+= byte_count
;
3237 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
3239 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3240 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3242 cFYI(1, ("error %d in QueryInternalInfo", rc
));
3244 /* decode response */
3245 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
3246 if (rc
|| (pSMBr
->ByteCount
< 2))
3247 /* BB also check enough total bytes returned */
3248 /* If rc should we check for EOPNOSUPP and
3249 disable the srvino flag? or in caller? */
3250 rc
= -EIO
; /* bad smb */
3252 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
3253 __u16 count
= le16_to_cpu(pSMBr
->t2
.DataCount
);
3254 struct file_internal_info
* pfinfo
;
3255 /* BB Do we need a cast or hash here ? */
3257 cFYI(1, ("Illegal size ret in QryIntrnlInf"));
3259 goto GetInodeNumOut
;
3261 pfinfo
= (struct file_internal_info
*)
3262 (data_offset
+ (char *) &pSMBr
->hdr
.Protocol
);
3263 *inode_number
= pfinfo
->UniqueId
;
3267 cifs_buf_release(pSMB
);
3269 goto GetInodeNumberRetry
;
3274 CIFSGetDFSRefer(const int xid
, struct cifsSesInfo
*ses
,
3275 const unsigned char *searchName
,
3276 unsigned char **targetUNCs
,
3277 unsigned int *number_of_UNC_in_array
,
3278 const struct nls_table
*nls_codepage
, int remap
)
3280 /* TRANS2_GET_DFS_REFERRAL */
3281 TRANSACTION2_GET_DFS_REFER_REQ
*pSMB
= NULL
;
3282 TRANSACTION2_GET_DFS_REFER_RSP
*pSMBr
= NULL
;
3283 struct dfs_referral_level_3
* referrals
= NULL
;
3289 __u16 params
, byte_count
;
3290 *number_of_UNC_in_array
= 0;
3293 cFYI(1, ("In GetDFSRefer the path %s", searchName
));
3297 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, NULL
, (void **) &pSMB
,
3302 /* server pointer checked in called function,
3303 but should never be null here anyway */
3304 pSMB
->hdr
.Mid
= GetNextMid(ses
->server
);
3305 pSMB
->hdr
.Tid
= ses
->ipc_tid
;
3306 pSMB
->hdr
.Uid
= ses
->Suid
;
3307 if (ses
->capabilities
& CAP_STATUS32
) {
3308 pSMB
->hdr
.Flags2
|= SMBFLG2_ERR_STATUS
;
3310 if (ses
->capabilities
& CAP_DFS
) {
3311 pSMB
->hdr
.Flags2
|= SMBFLG2_DFS
;
3314 if (ses
->capabilities
& CAP_UNICODE
) {
3315 pSMB
->hdr
.Flags2
|= SMBFLG2_UNICODE
;
3317 cifsConvertToUCS((__le16
*) pSMB
->RequestFileName
,
3318 searchName
, PATH_MAX
, nls_codepage
, remap
);
3319 name_len
++; /* trailing null */
3321 } else { /* BB improve the check for buffer overruns BB */
3322 name_len
= strnlen(searchName
, PATH_MAX
);
3323 name_len
++; /* trailing null */
3324 strncpy(pSMB
->RequestFileName
, searchName
, name_len
);
3327 params
= 2 /* level */ + name_len
/*includes null */ ;
3328 pSMB
->TotalDataCount
= 0;
3329 pSMB
->DataCount
= 0;
3330 pSMB
->DataOffset
= 0;
3331 pSMB
->MaxParameterCount
= 0;
3332 pSMB
->MaxDataCount
= cpu_to_le16(4000); /* BB find exact max SMB PDU from sess structure BB */
3333 pSMB
->MaxSetupCount
= 0;
3337 pSMB
->Reserved2
= 0;
3338 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
3339 struct smb_com_transaction2_get_dfs_refer_req
, MaxReferralLevel
) - 4);
3340 pSMB
->SetupCount
= 1;
3341 pSMB
->Reserved3
= 0;
3342 pSMB
->SubCommand
= cpu_to_le16(TRANS2_GET_DFS_REFERRAL
);
3343 byte_count
= params
+ 3 /* pad */ ;
3344 pSMB
->ParameterCount
= cpu_to_le16(params
);
3345 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
3346 pSMB
->MaxReferralLevel
= cpu_to_le16(3);
3347 pSMB
->hdr
.smb_buf_length
+= byte_count
;
3348 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
3350 rc
= SendReceive(xid
, ses
, (struct smb_hdr
*) pSMB
,
3351 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3353 cFYI(1, ("Send error in GetDFSRefer = %d", rc
));
3354 } else { /* decode response */
3355 /* BB Add logic to parse referrals here */
3356 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
3358 if (rc
|| (pSMBr
->ByteCount
< 17)) /* BB also check enough total bytes returned */
3359 rc
= -EIO
; /* bad smb */
3361 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
3362 __u16 data_count
= le16_to_cpu(pSMBr
->t2
.DataCount
);
3365 ("Decoding GetDFSRefer response. BCC: %d Offset %d",
3366 pSMBr
->ByteCount
, data_offset
));
3368 (struct dfs_referral_level_3
*)
3369 (8 /* sizeof start of data block */ +
3371 (char *) &pSMBr
->hdr
.Protocol
);
3372 cFYI(1,("num_referrals: %d dfs flags: 0x%x ... \nfor referral one refer size: 0x%x srv type: 0x%x refer flags: 0x%x ttl: 0x%x",
3373 le16_to_cpu(pSMBr
->NumberOfReferrals
),le16_to_cpu(pSMBr
->DFSFlags
), le16_to_cpu(referrals
->ReferralSize
),le16_to_cpu(referrals
->ServerType
),le16_to_cpu(referrals
->ReferralFlags
),le16_to_cpu(referrals
->TimeToLive
)));
3374 /* BB This field is actually two bytes in from start of
3375 data block so we could do safety check that DataBlock
3376 begins at address of pSMBr->NumberOfReferrals */
3377 *number_of_UNC_in_array
= le16_to_cpu(pSMBr
->NumberOfReferrals
);
3379 /* BB Fix below so can return more than one referral */
3380 if(*number_of_UNC_in_array
> 1)
3381 *number_of_UNC_in_array
= 1;
3383 /* get the length of the strings describing refs */
3385 for(i
=0;i
<*number_of_UNC_in_array
;i
++) {
3386 /* make sure that DfsPathOffset not past end */
3387 __u16 offset
= le16_to_cpu(referrals
->DfsPathOffset
);
3388 if (offset
> data_count
) {
3389 /* if invalid referral, stop here and do
3390 not try to copy any more */
3391 *number_of_UNC_in_array
= i
;
3394 temp
= ((char *)referrals
) + offset
;
3396 if (pSMBr
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
3397 name_len
+= UniStrnlen((wchar_t *)temp
,data_count
);
3399 name_len
+= strnlen(temp
,data_count
);
3402 /* BB add check that referral pointer does not fall off end PDU */
3405 /* BB add check for name_len bigger than bcc */
3407 kmalloc(name_len
+1+ (*number_of_UNC_in_array
),GFP_KERNEL
);
3408 if(*targetUNCs
== NULL
) {
3412 /* copy the ref strings */
3414 (struct dfs_referral_level_3
*)
3415 (8 /* sizeof data hdr */ +
3417 (char *) &pSMBr
->hdr
.Protocol
);
3419 for(i
=0;i
<*number_of_UNC_in_array
;i
++) {
3420 temp
= ((char *)referrals
) + le16_to_cpu(referrals
->DfsPathOffset
);
3421 if (pSMBr
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
3422 cifs_strfromUCS_le(*targetUNCs
,
3423 (__le16
*) temp
, name_len
, nls_codepage
);
3425 strncpy(*targetUNCs
,temp
,name_len
);
3427 /* BB update target_uncs pointers */
3437 cifs_buf_release(pSMB
);
3445 /* Query File System Info such as free space to old servers such as Win 9x */
3447 SMBOldQFSInfo(const int xid
, struct cifsTconInfo
*tcon
, struct kstatfs
*FSData
)
3449 /* level 0x01 SMB_QUERY_FILE_SYSTEM_INFO */
3450 TRANSACTION2_QFSI_REQ
*pSMB
= NULL
;
3451 TRANSACTION2_QFSI_RSP
*pSMBr
= NULL
;
3452 FILE_SYSTEM_ALLOC_INFO
*response_data
;
3454 int bytes_returned
= 0;
3455 __u16 params
, byte_count
;
3457 cFYI(1, ("OldQFSInfo"));
3459 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
3463 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
3468 params
= 2; /* level */
3469 pSMB
->TotalDataCount
= 0;
3470 pSMB
->MaxParameterCount
= cpu_to_le16(2);
3471 pSMB
->MaxDataCount
= cpu_to_le16(1000);
3472 pSMB
->MaxSetupCount
= 0;
3476 pSMB
->Reserved2
= 0;
3477 byte_count
= params
+ 1 /* pad */ ;
3478 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
3479 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
3480 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
3481 struct smb_com_transaction2_qfsi_req
, InformationLevel
) - 4);
3482 pSMB
->DataCount
= 0;
3483 pSMB
->DataOffset
= 0;
3484 pSMB
->SetupCount
= 1;
3485 pSMB
->Reserved3
= 0;
3486 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_FS_INFORMATION
);
3487 pSMB
->InformationLevel
= cpu_to_le16(SMB_INFO_ALLOCATION
);
3488 pSMB
->hdr
.smb_buf_length
+= byte_count
;
3489 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
3491 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3492 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3494 cFYI(1, ("Send error in QFSInfo = %d", rc
));
3495 } else { /* decode response */
3496 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
3498 if (rc
|| (pSMBr
->ByteCount
< 18))
3499 rc
= -EIO
; /* bad smb */
3501 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
3502 cFYI(1,("qfsinf resp BCC: %d Offset %d",
3503 pSMBr
->ByteCount
, data_offset
));
3506 (FILE_SYSTEM_ALLOC_INFO
*)
3507 (((char *) &pSMBr
->hdr
.Protocol
) + data_offset
);
3509 le16_to_cpu(response_data
->BytesPerSector
) *
3510 le32_to_cpu(response_data
->
3511 SectorsPerAllocationUnit
);
3513 le32_to_cpu(response_data
->TotalAllocationUnits
);
3514 FSData
->f_bfree
= FSData
->f_bavail
=
3515 le32_to_cpu(response_data
->FreeAllocationUnits
);
3517 ("Blocks: %lld Free: %lld Block size %ld",
3518 (unsigned long long)FSData
->f_blocks
,
3519 (unsigned long long)FSData
->f_bfree
,
3523 cifs_buf_release(pSMB
);
3526 goto oldQFSInfoRetry
;
3532 CIFSSMBQFSInfo(const int xid
, struct cifsTconInfo
*tcon
, struct kstatfs
*FSData
)
3534 /* level 0x103 SMB_QUERY_FILE_SYSTEM_INFO */
3535 TRANSACTION2_QFSI_REQ
*pSMB
= NULL
;
3536 TRANSACTION2_QFSI_RSP
*pSMBr
= NULL
;
3537 FILE_SYSTEM_INFO
*response_data
;
3539 int bytes_returned
= 0;
3540 __u16 params
, byte_count
;
3542 cFYI(1, ("In QFSInfo"));
3544 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
3549 params
= 2; /* level */
3550 pSMB
->TotalDataCount
= 0;
3551 pSMB
->MaxParameterCount
= cpu_to_le16(2);
3552 pSMB
->MaxDataCount
= cpu_to_le16(1000);
3553 pSMB
->MaxSetupCount
= 0;
3557 pSMB
->Reserved2
= 0;
3558 byte_count
= params
+ 1 /* pad */ ;
3559 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
3560 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
3561 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
3562 struct smb_com_transaction2_qfsi_req
, InformationLevel
) - 4);
3563 pSMB
->DataCount
= 0;
3564 pSMB
->DataOffset
= 0;
3565 pSMB
->SetupCount
= 1;
3566 pSMB
->Reserved3
= 0;
3567 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_FS_INFORMATION
);
3568 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FS_SIZE_INFO
);
3569 pSMB
->hdr
.smb_buf_length
+= byte_count
;
3570 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
3572 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3573 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3575 cFYI(1, ("Send error in QFSInfo = %d", rc
));
3576 } else { /* decode response */
3577 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
3579 if (rc
|| (pSMBr
->ByteCount
< 24))
3580 rc
= -EIO
; /* bad smb */
3582 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
3586 *) (((char *) &pSMBr
->hdr
.Protocol
) +
3589 le32_to_cpu(response_data
->BytesPerSector
) *
3590 le32_to_cpu(response_data
->
3591 SectorsPerAllocationUnit
);
3593 le64_to_cpu(response_data
->TotalAllocationUnits
);
3594 FSData
->f_bfree
= FSData
->f_bavail
=
3595 le64_to_cpu(response_data
->FreeAllocationUnits
);
3597 ("Blocks: %lld Free: %lld Block size %ld",
3598 (unsigned long long)FSData
->f_blocks
,
3599 (unsigned long long)FSData
->f_bfree
,
3603 cifs_buf_release(pSMB
);
3612 CIFSSMBQFSAttributeInfo(const int xid
, struct cifsTconInfo
*tcon
)
3614 /* level 0x105 SMB_QUERY_FILE_SYSTEM_INFO */
3615 TRANSACTION2_QFSI_REQ
*pSMB
= NULL
;
3616 TRANSACTION2_QFSI_RSP
*pSMBr
= NULL
;
3617 FILE_SYSTEM_ATTRIBUTE_INFO
*response_data
;
3619 int bytes_returned
= 0;
3620 __u16 params
, byte_count
;
3622 cFYI(1, ("In QFSAttributeInfo"));
3624 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
3629 params
= 2; /* level */
3630 pSMB
->TotalDataCount
= 0;
3631 pSMB
->MaxParameterCount
= cpu_to_le16(2);
3632 pSMB
->MaxDataCount
= cpu_to_le16(1000); /* BB find exact max SMB PDU from sess structure BB */
3633 pSMB
->MaxSetupCount
= 0;
3637 pSMB
->Reserved2
= 0;
3638 byte_count
= params
+ 1 /* pad */ ;
3639 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
3640 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
3641 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
3642 struct smb_com_transaction2_qfsi_req
, InformationLevel
) - 4);
3643 pSMB
->DataCount
= 0;
3644 pSMB
->DataOffset
= 0;
3645 pSMB
->SetupCount
= 1;
3646 pSMB
->Reserved3
= 0;
3647 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_FS_INFORMATION
);
3648 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FS_ATTRIBUTE_INFO
);
3649 pSMB
->hdr
.smb_buf_length
+= byte_count
;
3650 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
3652 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3653 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3655 cERROR(1, ("Send error in QFSAttributeInfo = %d", rc
));
3656 } else { /* decode response */
3657 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
3659 if (rc
|| (pSMBr
->ByteCount
< 13)) { /* BB also check enough bytes returned */
3660 rc
= -EIO
; /* bad smb */
3662 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
3664 (FILE_SYSTEM_ATTRIBUTE_INFO
3665 *) (((char *) &pSMBr
->hdr
.Protocol
) +
3667 memcpy(&tcon
->fsAttrInfo
, response_data
,
3668 sizeof (FILE_SYSTEM_ATTRIBUTE_INFO
));
3671 cifs_buf_release(pSMB
);
3674 goto QFSAttributeRetry
;
3680 CIFSSMBQFSDeviceInfo(const int xid
, struct cifsTconInfo
*tcon
)
3682 /* level 0x104 SMB_QUERY_FILE_SYSTEM_INFO */
3683 TRANSACTION2_QFSI_REQ
*pSMB
= NULL
;
3684 TRANSACTION2_QFSI_RSP
*pSMBr
= NULL
;
3685 FILE_SYSTEM_DEVICE_INFO
*response_data
;
3687 int bytes_returned
= 0;
3688 __u16 params
, byte_count
;
3690 cFYI(1, ("In QFSDeviceInfo"));
3692 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
3697 params
= 2; /* level */
3698 pSMB
->TotalDataCount
= 0;
3699 pSMB
->MaxParameterCount
= cpu_to_le16(2);
3700 pSMB
->MaxDataCount
= cpu_to_le16(1000); /* BB find exact max SMB PDU from sess structure BB */
3701 pSMB
->MaxSetupCount
= 0;
3705 pSMB
->Reserved2
= 0;
3706 byte_count
= params
+ 1 /* pad */ ;
3707 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
3708 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
3709 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
3710 struct smb_com_transaction2_qfsi_req
, InformationLevel
) - 4);
3712 pSMB
->DataCount
= 0;
3713 pSMB
->DataOffset
= 0;
3714 pSMB
->SetupCount
= 1;
3715 pSMB
->Reserved3
= 0;
3716 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_FS_INFORMATION
);
3717 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FS_DEVICE_INFO
);
3718 pSMB
->hdr
.smb_buf_length
+= byte_count
;
3719 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
3721 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3722 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3724 cFYI(1, ("Send error in QFSDeviceInfo = %d", rc
));
3725 } else { /* decode response */
3726 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
3728 if (rc
|| (pSMBr
->ByteCount
< sizeof (FILE_SYSTEM_DEVICE_INFO
)))
3729 rc
= -EIO
; /* bad smb */
3731 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
3733 (FILE_SYSTEM_DEVICE_INFO
*)
3734 (((char *) &pSMBr
->hdr
.Protocol
) +
3736 memcpy(&tcon
->fsDevInfo
, response_data
,
3737 sizeof (FILE_SYSTEM_DEVICE_INFO
));
3740 cifs_buf_release(pSMB
);
3743 goto QFSDeviceRetry
;
3749 CIFSSMBQFSUnixInfo(const int xid
, struct cifsTconInfo
*tcon
)
3751 /* level 0x200 SMB_QUERY_CIFS_UNIX_INFO */
3752 TRANSACTION2_QFSI_REQ
*pSMB
= NULL
;
3753 TRANSACTION2_QFSI_RSP
*pSMBr
= NULL
;
3754 FILE_SYSTEM_UNIX_INFO
*response_data
;
3756 int bytes_returned
= 0;
3757 __u16 params
, byte_count
;
3759 cFYI(1, ("In QFSUnixInfo"));
3761 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
3766 params
= 2; /* level */
3767 pSMB
->TotalDataCount
= 0;
3768 pSMB
->DataCount
= 0;
3769 pSMB
->DataOffset
= 0;
3770 pSMB
->MaxParameterCount
= cpu_to_le16(2);
3771 pSMB
->MaxDataCount
= cpu_to_le16(100); /* BB find exact max SMB PDU from sess structure BB */
3772 pSMB
->MaxSetupCount
= 0;
3776 pSMB
->Reserved2
= 0;
3777 byte_count
= params
+ 1 /* pad */ ;
3778 pSMB
->ParameterCount
= cpu_to_le16(params
);
3779 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
3780 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(struct
3781 smb_com_transaction2_qfsi_req
, InformationLevel
) - 4);
3782 pSMB
->SetupCount
= 1;
3783 pSMB
->Reserved3
= 0;
3784 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_FS_INFORMATION
);
3785 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_CIFS_UNIX_INFO
);
3786 pSMB
->hdr
.smb_buf_length
+= byte_count
;
3787 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
3789 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3790 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3792 cERROR(1, ("Send error in QFSUnixInfo = %d", rc
));
3793 } else { /* decode response */
3794 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
3796 if (rc
|| (pSMBr
->ByteCount
< 13)) {
3797 rc
= -EIO
; /* bad smb */
3799 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
3801 (FILE_SYSTEM_UNIX_INFO
3802 *) (((char *) &pSMBr
->hdr
.Protocol
) +
3804 memcpy(&tcon
->fsUnixInfo
, response_data
,
3805 sizeof (FILE_SYSTEM_UNIX_INFO
));
3808 cifs_buf_release(pSMB
);
3818 CIFSSMBSetFSUnixInfo(const int xid
, struct cifsTconInfo
*tcon
, __u64 cap
)
3820 /* level 0x200 SMB_SET_CIFS_UNIX_INFO */
3821 TRANSACTION2_SETFSI_REQ
*pSMB
= NULL
;
3822 TRANSACTION2_SETFSI_RSP
*pSMBr
= NULL
;
3824 int bytes_returned
= 0;
3825 __u16 params
, param_offset
, offset
, byte_count
;
3827 cFYI(1, ("In SETFSUnixInfo"));
3829 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
3834 params
= 4; /* 2 bytes zero followed by info level. */
3835 pSMB
->MaxSetupCount
= 0;
3839 pSMB
->Reserved2
= 0;
3840 param_offset
= offsetof(struct smb_com_transaction2_setfsi_req
, FileNum
) - 4;
3841 offset
= param_offset
+ params
;
3843 pSMB
->MaxParameterCount
= cpu_to_le16(4);
3844 pSMB
->MaxDataCount
= cpu_to_le16(100); /* BB find exact max SMB PDU from sess structure BB */
3845 pSMB
->SetupCount
= 1;
3846 pSMB
->Reserved3
= 0;
3847 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_FS_INFORMATION
);
3848 byte_count
= 1 /* pad */ + params
+ 12;
3850 pSMB
->DataCount
= cpu_to_le16(12);
3851 pSMB
->ParameterCount
= cpu_to_le16(params
);
3852 pSMB
->TotalDataCount
= pSMB
->DataCount
;
3853 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
3854 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
3855 pSMB
->DataOffset
= cpu_to_le16(offset
);
3859 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_CIFS_UNIX_INFO
);
3862 pSMB
->ClientUnixMajor
= cpu_to_le16(CIFS_UNIX_MAJOR_VERSION
);
3863 pSMB
->ClientUnixMinor
= cpu_to_le16(CIFS_UNIX_MINOR_VERSION
);
3864 pSMB
->ClientUnixCap
= cpu_to_le64(cap
);
3866 pSMB
->hdr
.smb_buf_length
+= byte_count
;
3867 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
3869 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3870 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3872 cERROR(1, ("Send error in SETFSUnixInfo = %d", rc
));
3873 } else { /* decode response */
3874 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
3876 rc
= -EIO
; /* bad smb */
3879 cifs_buf_release(pSMB
);
3882 goto SETFSUnixRetry
;
3890 CIFSSMBQFSPosixInfo(const int xid
, struct cifsTconInfo
*tcon
,
3891 struct kstatfs
*FSData
)
3893 /* level 0x201 SMB_QUERY_CIFS_POSIX_INFO */
3894 TRANSACTION2_QFSI_REQ
*pSMB
= NULL
;
3895 TRANSACTION2_QFSI_RSP
*pSMBr
= NULL
;
3896 FILE_SYSTEM_POSIX_INFO
*response_data
;
3898 int bytes_returned
= 0;
3899 __u16 params
, byte_count
;
3901 cFYI(1, ("In QFSPosixInfo"));
3903 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
3908 params
= 2; /* level */
3909 pSMB
->TotalDataCount
= 0;
3910 pSMB
->DataCount
= 0;
3911 pSMB
->DataOffset
= 0;
3912 pSMB
->MaxParameterCount
= cpu_to_le16(2);
3913 pSMB
->MaxDataCount
= cpu_to_le16(100); /* BB find exact max SMB PDU from sess structure BB */
3914 pSMB
->MaxSetupCount
= 0;
3918 pSMB
->Reserved2
= 0;
3919 byte_count
= params
+ 1 /* pad */ ;
3920 pSMB
->ParameterCount
= cpu_to_le16(params
);
3921 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
3922 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(struct
3923 smb_com_transaction2_qfsi_req
, InformationLevel
) - 4);
3924 pSMB
->SetupCount
= 1;
3925 pSMB
->Reserved3
= 0;
3926 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_FS_INFORMATION
);
3927 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_POSIX_FS_INFO
);
3928 pSMB
->hdr
.smb_buf_length
+= byte_count
;
3929 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
3931 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3932 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3934 cFYI(1, ("Send error in QFSUnixInfo = %d", rc
));
3935 } else { /* decode response */
3936 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
3938 if (rc
|| (pSMBr
->ByteCount
< 13)) {
3939 rc
= -EIO
; /* bad smb */
3941 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
3943 (FILE_SYSTEM_POSIX_INFO
3944 *) (((char *) &pSMBr
->hdr
.Protocol
) +
3947 le32_to_cpu(response_data
->BlockSize
);
3949 le64_to_cpu(response_data
->TotalBlocks
);
3951 le64_to_cpu(response_data
->BlocksAvail
);
3952 if(response_data
->UserBlocksAvail
== cpu_to_le64(-1)) {
3953 FSData
->f_bavail
= FSData
->f_bfree
;
3956 le64_to_cpu(response_data
->UserBlocksAvail
);
3958 if(response_data
->TotalFileNodes
!= cpu_to_le64(-1))
3960 le64_to_cpu(response_data
->TotalFileNodes
);
3961 if(response_data
->FreeFileNodes
!= cpu_to_le64(-1))
3963 le64_to_cpu(response_data
->FreeFileNodes
);
3966 cifs_buf_release(pSMB
);
3975 /* We can not use write of zero bytes trick to
3976 set file size due to need for large file support. Also note that
3977 this SetPathInfo is preferred to SetFileInfo based method in next
3978 routine which is only needed to work around a sharing violation bug
3979 in Samba which this routine can run into */
3982 CIFSSMBSetEOF(const int xid
, struct cifsTconInfo
*tcon
, const char *fileName
,
3983 __u64 size
, int SetAllocation
,
3984 const struct nls_table
*nls_codepage
, int remap
)
3986 struct smb_com_transaction2_spi_req
*pSMB
= NULL
;
3987 struct smb_com_transaction2_spi_rsp
*pSMBr
= NULL
;
3988 struct file_end_of_file_info
*parm_data
;
3991 int bytes_returned
= 0;
3992 __u16 params
, byte_count
, data_count
, param_offset
, offset
;
3994 cFYI(1, ("In SetEOF"));
3996 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4001 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
4003 cifsConvertToUCS((__le16
*) pSMB
->FileName
, fileName
,
4004 PATH_MAX
, nls_codepage
, remap
);
4005 name_len
++; /* trailing null */
4007 } else { /* BB improve the check for buffer overruns BB */
4008 name_len
= strnlen(fileName
, PATH_MAX
);
4009 name_len
++; /* trailing null */
4010 strncpy(pSMB
->FileName
, fileName
, name_len
);
4012 params
= 6 + name_len
;
4013 data_count
= sizeof (struct file_end_of_file_info
);
4014 pSMB
->MaxParameterCount
= cpu_to_le16(2);
4015 pSMB
->MaxDataCount
= cpu_to_le16(4100);
4016 pSMB
->MaxSetupCount
= 0;
4020 pSMB
->Reserved2
= 0;
4021 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
4022 InformationLevel
) - 4;
4023 offset
= param_offset
+ params
;
4025 if (tcon
->ses
->capabilities
& CAP_INFOLEVEL_PASSTHRU
)
4026 pSMB
->InformationLevel
=
4027 cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2
);
4029 pSMB
->InformationLevel
=
4030 cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO
);
4031 } else /* Set File Size */ {
4032 if (tcon
->ses
->capabilities
& CAP_INFOLEVEL_PASSTHRU
)
4033 pSMB
->InformationLevel
=
4034 cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2
);
4036 pSMB
->InformationLevel
=
4037 cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO
);
4041 (struct file_end_of_file_info
*) (((char *) &pSMB
->hdr
.Protocol
) +
4043 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
4044 pSMB
->DataOffset
= cpu_to_le16(offset
);
4045 pSMB
->SetupCount
= 1;
4046 pSMB
->Reserved3
= 0;
4047 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
4048 byte_count
= 3 /* pad */ + params
+ data_count
;
4049 pSMB
->DataCount
= cpu_to_le16(data_count
);
4050 pSMB
->TotalDataCount
= pSMB
->DataCount
;
4051 pSMB
->ParameterCount
= cpu_to_le16(params
);
4052 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
4053 pSMB
->Reserved4
= 0;
4054 pSMB
->hdr
.smb_buf_length
+= byte_count
;
4055 parm_data
->FileSize
= cpu_to_le64(size
);
4056 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4057 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4058 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4060 cFYI(1, ("SetPathInfo (file size) returned %d", rc
));
4063 cifs_buf_release(pSMB
);
4072 CIFSSMBSetFileSize(const int xid
, struct cifsTconInfo
*tcon
, __u64 size
,
4073 __u16 fid
, __u32 pid_of_opener
, int SetAllocation
)
4075 struct smb_com_transaction2_sfi_req
*pSMB
= NULL
;
4076 struct smb_com_transaction2_sfi_rsp
*pSMBr
= NULL
;
4078 struct file_end_of_file_info
*parm_data
;
4080 int bytes_returned
= 0;
4081 __u16 params
, param_offset
, offset
, byte_count
, count
;
4083 cFYI(1, ("SetFileSize (via SetFileInfo) %lld",
4085 rc
= small_smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
);
4090 pSMBr
= (struct smb_com_transaction2_sfi_rsp
*)pSMB
;
4092 pSMB
->hdr
.Pid
= cpu_to_le16((__u16
)pid_of_opener
);
4093 pSMB
->hdr
.PidHigh
= cpu_to_le16((__u16
)(pid_of_opener
>> 16));
4096 pSMB
->MaxSetupCount
= 0;
4100 pSMB
->Reserved2
= 0;
4101 param_offset
= offsetof(struct smb_com_transaction2_sfi_req
, Fid
) - 4;
4102 offset
= param_offset
+ params
;
4104 data_offset
= (char *) (&pSMB
->hdr
.Protocol
) + offset
;
4106 count
= sizeof(struct file_end_of_file_info
);
4107 pSMB
->MaxParameterCount
= cpu_to_le16(2);
4108 pSMB
->MaxDataCount
= cpu_to_le16(1000); /* BB find max SMB PDU from sess */
4109 pSMB
->SetupCount
= 1;
4110 pSMB
->Reserved3
= 0;
4111 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_FILE_INFORMATION
);
4112 byte_count
= 3 /* pad */ + params
+ count
;
4113 pSMB
->DataCount
= cpu_to_le16(count
);
4114 pSMB
->ParameterCount
= cpu_to_le16(params
);
4115 pSMB
->TotalDataCount
= pSMB
->DataCount
;
4116 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
4117 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
4119 (struct file_end_of_file_info
*) (((char *) &pSMB
->hdr
.Protocol
) +
4121 pSMB
->DataOffset
= cpu_to_le16(offset
);
4122 parm_data
->FileSize
= cpu_to_le64(size
);
4125 if (tcon
->ses
->capabilities
& CAP_INFOLEVEL_PASSTHRU
)
4126 pSMB
->InformationLevel
=
4127 cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2
);
4129 pSMB
->InformationLevel
=
4130 cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO
);
4131 } else /* Set File Size */ {
4132 if (tcon
->ses
->capabilities
& CAP_INFOLEVEL_PASSTHRU
)
4133 pSMB
->InformationLevel
=
4134 cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2
);
4136 pSMB
->InformationLevel
=
4137 cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO
);
4139 pSMB
->Reserved4
= 0;
4140 pSMB
->hdr
.smb_buf_length
+= byte_count
;
4141 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4142 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4143 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4146 ("Send error in SetFileInfo (SetFileSize) = %d",
4151 cifs_small_buf_release(pSMB
);
4153 /* Note: On -EAGAIN error only caller can retry on handle based calls
4154 since file handle passed in no longer valid */
4159 /* Some legacy servers such as NT4 require that the file times be set on
4160 an open handle, rather than by pathname - this is awkward due to
4161 potential access conflicts on the open, but it is unavoidable for these
4162 old servers since the only other choice is to go from 100 nanosecond DCE
4163 time and resort to the original setpathinfo level which takes the ancient
4164 DOS time format with 2 second granularity */
4166 CIFSSMBSetFileTimes(const int xid
, struct cifsTconInfo
*tcon
, const FILE_BASIC_INFO
* data
,
4169 struct smb_com_transaction2_sfi_req
*pSMB
= NULL
;
4170 struct smb_com_transaction2_sfi_rsp
*pSMBr
= NULL
;
4173 int bytes_returned
= 0;
4174 __u16 params
, param_offset
, offset
, byte_count
, count
;
4176 cFYI(1, ("Set Times (via SetFileInfo)"));
4177 rc
= small_smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
);
4182 pSMBr
= (struct smb_com_transaction2_sfi_rsp
*)pSMB
;
4184 /* At this point there is no need to override the current pid
4185 with the pid of the opener, but that could change if we someday
4186 use an existing handle (rather than opening one on the fly) */
4187 /* pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener);
4188 pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16));*/
4191 pSMB
->MaxSetupCount
= 0;
4195 pSMB
->Reserved2
= 0;
4196 param_offset
= offsetof(struct smb_com_transaction2_sfi_req
, Fid
) - 4;
4197 offset
= param_offset
+ params
;
4199 data_offset
= (char *) (&pSMB
->hdr
.Protocol
) + offset
;
4201 count
= sizeof (FILE_BASIC_INFO
);
4202 pSMB
->MaxParameterCount
= cpu_to_le16(2);
4203 pSMB
->MaxDataCount
= cpu_to_le16(1000); /* BB find max SMB PDU from sess */
4204 pSMB
->SetupCount
= 1;
4205 pSMB
->Reserved3
= 0;
4206 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_FILE_INFORMATION
);
4207 byte_count
= 3 /* pad */ + params
+ count
;
4208 pSMB
->DataCount
= cpu_to_le16(count
);
4209 pSMB
->ParameterCount
= cpu_to_le16(params
);
4210 pSMB
->TotalDataCount
= pSMB
->DataCount
;
4211 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
4212 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
4213 pSMB
->DataOffset
= cpu_to_le16(offset
);
4215 if (tcon
->ses
->capabilities
& CAP_INFOLEVEL_PASSTHRU
)
4216 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_BASIC_INFO2
);
4218 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_BASIC_INFO
);
4219 pSMB
->Reserved4
= 0;
4220 pSMB
->hdr
.smb_buf_length
+= byte_count
;
4221 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4222 memcpy(data_offset
,data
,sizeof(FILE_BASIC_INFO
));
4223 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4224 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4226 cFYI(1,("Send error in Set Time (SetFileInfo) = %d",rc
));
4229 cifs_small_buf_release(pSMB
);
4231 /* Note: On -EAGAIN error only caller can retry on handle based calls
4232 since file handle passed in no longer valid */
4239 CIFSSMBSetTimes(const int xid
, struct cifsTconInfo
*tcon
, const char *fileName
,
4240 const FILE_BASIC_INFO
* data
,
4241 const struct nls_table
*nls_codepage
, int remap
)
4243 TRANSACTION2_SPI_REQ
*pSMB
= NULL
;
4244 TRANSACTION2_SPI_RSP
*pSMBr
= NULL
;
4247 int bytes_returned
= 0;
4249 __u16 params
, param_offset
, offset
, byte_count
, count
;
4251 cFYI(1, ("In SetTimes"));
4254 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4259 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
4261 cifsConvertToUCS((__le16
*) pSMB
->FileName
, fileName
,
4262 PATH_MAX
, nls_codepage
, remap
);
4263 name_len
++; /* trailing null */
4265 } else { /* BB improve the check for buffer overruns BB */
4266 name_len
= strnlen(fileName
, PATH_MAX
);
4267 name_len
++; /* trailing null */
4268 strncpy(pSMB
->FileName
, fileName
, name_len
);
4271 params
= 6 + name_len
;
4272 count
= sizeof (FILE_BASIC_INFO
);
4273 pSMB
->MaxParameterCount
= cpu_to_le16(2);
4274 pSMB
->MaxDataCount
= cpu_to_le16(1000); /* BB find exact max SMB PDU from sess structure BB */
4275 pSMB
->MaxSetupCount
= 0;
4279 pSMB
->Reserved2
= 0;
4280 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
4281 InformationLevel
) - 4;
4282 offset
= param_offset
+ params
;
4283 data_offset
= (char *) (&pSMB
->hdr
.Protocol
) + offset
;
4284 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
4285 pSMB
->DataOffset
= cpu_to_le16(offset
);
4286 pSMB
->SetupCount
= 1;
4287 pSMB
->Reserved3
= 0;
4288 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
4289 byte_count
= 3 /* pad */ + params
+ count
;
4291 pSMB
->DataCount
= cpu_to_le16(count
);
4292 pSMB
->ParameterCount
= cpu_to_le16(params
);
4293 pSMB
->TotalDataCount
= pSMB
->DataCount
;
4294 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
4295 if (tcon
->ses
->capabilities
& CAP_INFOLEVEL_PASSTHRU
)
4296 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_BASIC_INFO2
);
4298 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_BASIC_INFO
);
4299 pSMB
->Reserved4
= 0;
4300 pSMB
->hdr
.smb_buf_length
+= byte_count
;
4301 memcpy(data_offset
, data
, sizeof (FILE_BASIC_INFO
));
4302 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4303 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4304 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4306 cFYI(1, ("SetPathInfo (times) returned %d", rc
));
4309 cifs_buf_release(pSMB
);
4317 /* Can not be used to set time stamps yet (due to old DOS time format) */
4318 /* Can be used to set attributes */
4319 #if 0 /* Possibly not needed - since it turns out that strangely NT4 has a bug
4320 handling it anyway and NT4 was what we thought it would be needed for
4321 Do not delete it until we prove whether needed for Win9x though */
4323 CIFSSMBSetAttrLegacy(int xid
, struct cifsTconInfo
*tcon
, char *fileName
,
4324 __u16 dos_attrs
, const struct nls_table
*nls_codepage
)
4326 SETATTR_REQ
*pSMB
= NULL
;
4327 SETATTR_RSP
*pSMBr
= NULL
;
4332 cFYI(1, ("In SetAttrLegacy"));
4335 rc
= smb_init(SMB_COM_SETATTR
, 8, tcon
, (void **) &pSMB
,
4340 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
4342 ConvertToUCS((__le16
*) pSMB
->fileName
, fileName
,
4343 PATH_MAX
, nls_codepage
);
4344 name_len
++; /* trailing null */
4346 } else { /* BB improve the check for buffer overruns BB */
4347 name_len
= strnlen(fileName
, PATH_MAX
);
4348 name_len
++; /* trailing null */
4349 strncpy(pSMB
->fileName
, fileName
, name_len
);
4351 pSMB
->attr
= cpu_to_le16(dos_attrs
);
4352 pSMB
->BufferFormat
= 0x04;
4353 pSMB
->hdr
.smb_buf_length
+= name_len
+ 1;
4354 pSMB
->ByteCount
= cpu_to_le16(name_len
+ 1);
4355 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4356 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4358 cFYI(1, ("Error in LegacySetAttr = %d", rc
));
4361 cifs_buf_release(pSMB
);
4364 goto SetAttrLgcyRetry
;
4368 #endif /* temporarily unneeded SetAttr legacy function */
4371 CIFSSMBUnixSetPerms(const int xid
, struct cifsTconInfo
*tcon
,
4372 char *fileName
, __u64 mode
, __u64 uid
, __u64 gid
,
4373 dev_t device
, const struct nls_table
*nls_codepage
,
4376 TRANSACTION2_SPI_REQ
*pSMB
= NULL
;
4377 TRANSACTION2_SPI_RSP
*pSMBr
= NULL
;
4380 int bytes_returned
= 0;
4381 FILE_UNIX_BASIC_INFO
*data_offset
;
4382 __u16 params
, param_offset
, offset
, count
, byte_count
;
4384 cFYI(1, ("In SetUID/GID/Mode"));
4386 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4391 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
4393 cifsConvertToUCS((__le16
*) pSMB
->FileName
, fileName
,
4394 PATH_MAX
, nls_codepage
, remap
);
4395 name_len
++; /* trailing null */
4397 } else { /* BB improve the check for buffer overruns BB */
4398 name_len
= strnlen(fileName
, PATH_MAX
);
4399 name_len
++; /* trailing null */
4400 strncpy(pSMB
->FileName
, fileName
, name_len
);
4403 params
= 6 + name_len
;
4404 count
= sizeof (FILE_UNIX_BASIC_INFO
);
4405 pSMB
->MaxParameterCount
= cpu_to_le16(2);
4406 pSMB
->MaxDataCount
= cpu_to_le16(1000); /* BB find exact max SMB PDU from sess structure BB */
4407 pSMB
->MaxSetupCount
= 0;
4411 pSMB
->Reserved2
= 0;
4412 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
4413 InformationLevel
) - 4;
4414 offset
= param_offset
+ params
;
4416 (FILE_UNIX_BASIC_INFO
*) ((char *) &pSMB
->hdr
.Protocol
+
4418 memset(data_offset
, 0, count
);
4419 pSMB
->DataOffset
= cpu_to_le16(offset
);
4420 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
4421 pSMB
->SetupCount
= 1;
4422 pSMB
->Reserved3
= 0;
4423 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
4424 byte_count
= 3 /* pad */ + params
+ count
;
4425 pSMB
->ParameterCount
= cpu_to_le16(params
);
4426 pSMB
->DataCount
= cpu_to_le16(count
);
4427 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
4428 pSMB
->TotalDataCount
= pSMB
->DataCount
;
4429 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_UNIX_BASIC
);
4430 pSMB
->Reserved4
= 0;
4431 pSMB
->hdr
.smb_buf_length
+= byte_count
;
4432 data_offset
->Uid
= cpu_to_le64(uid
);
4433 data_offset
->Gid
= cpu_to_le64(gid
);
4434 /* better to leave device as zero when it is */
4435 data_offset
->DevMajor
= cpu_to_le64(MAJOR(device
));
4436 data_offset
->DevMinor
= cpu_to_le64(MINOR(device
));
4437 data_offset
->Permissions
= cpu_to_le64(mode
);
4440 data_offset
->Type
= cpu_to_le32(UNIX_FILE
);
4441 else if(S_ISDIR(mode
))
4442 data_offset
->Type
= cpu_to_le32(UNIX_DIR
);
4443 else if(S_ISLNK(mode
))
4444 data_offset
->Type
= cpu_to_le32(UNIX_SYMLINK
);
4445 else if(S_ISCHR(mode
))
4446 data_offset
->Type
= cpu_to_le32(UNIX_CHARDEV
);
4447 else if(S_ISBLK(mode
))
4448 data_offset
->Type
= cpu_to_le32(UNIX_BLOCKDEV
);
4449 else if(S_ISFIFO(mode
))
4450 data_offset
->Type
= cpu_to_le32(UNIX_FIFO
);
4451 else if(S_ISSOCK(mode
))
4452 data_offset
->Type
= cpu_to_le32(UNIX_SOCKET
);
4455 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4456 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4457 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4459 cFYI(1, ("SetPathInfo (perms) returned %d", rc
));
4463 cifs_buf_release(pSMB
);
4469 int CIFSSMBNotify(const int xid
, struct cifsTconInfo
*tcon
,
4470 const int notify_subdirs
, const __u16 netfid
,
4471 __u32 filter
, struct file
* pfile
, int multishot
,
4472 const struct nls_table
*nls_codepage
)
4475 struct smb_com_transaction_change_notify_req
* pSMB
= NULL
;
4476 struct smb_com_ntransaction_change_notify_rsp
* pSMBr
= NULL
;
4477 struct dir_notify_req
*dnotify_req
;
4480 cFYI(1, ("In CIFSSMBNotify for file handle %d",(int)netfid
));
4481 rc
= smb_init(SMB_COM_NT_TRANSACT
, 23, tcon
, (void **) &pSMB
,
4486 pSMB
->TotalParameterCount
= 0 ;
4487 pSMB
->TotalDataCount
= 0;
4488 pSMB
->MaxParameterCount
= cpu_to_le32(2);
4489 /* BB find exact data count max from sess structure BB */
4490 pSMB
->MaxDataCount
= 0; /* same in little endian or be */
4491 /* BB VERIFY verify which is correct for above BB */
4492 pSMB
->MaxDataCount
= cpu_to_le32((tcon
->ses
->server
->maxBuf
-
4493 MAX_CIFS_HDR_SIZE
) & 0xFFFFFF00);
4495 pSMB
->MaxSetupCount
= 4;
4497 pSMB
->ParameterOffset
= 0;
4498 pSMB
->DataCount
= 0;
4499 pSMB
->DataOffset
= 0;
4500 pSMB
->SetupCount
= 4; /* single byte does not need le conversion */
4501 pSMB
->SubCommand
= cpu_to_le16(NT_TRANSACT_NOTIFY_CHANGE
);
4502 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
4504 pSMB
->WatchTree
= 1; /* one byte - no le conversion needed */
4505 pSMB
->Reserved2
= 0;
4506 pSMB
->CompletionFilter
= cpu_to_le32(filter
);
4507 pSMB
->Fid
= netfid
; /* file handle always le */
4508 pSMB
->ByteCount
= 0;
4510 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4511 (struct smb_hdr
*) pSMBr
, &bytes_returned
, -1);
4513 cFYI(1, ("Error in Notify = %d", rc
));
4515 /* Add file to outstanding requests */
4516 /* BB change to kmem cache alloc */
4517 dnotify_req
= (struct dir_notify_req
*) kmalloc(
4518 sizeof(struct dir_notify_req
),
4521 dnotify_req
->Pid
= pSMB
->hdr
.Pid
;
4522 dnotify_req
->PidHigh
= pSMB
->hdr
.PidHigh
;
4523 dnotify_req
->Mid
= pSMB
->hdr
.Mid
;
4524 dnotify_req
->Tid
= pSMB
->hdr
.Tid
;
4525 dnotify_req
->Uid
= pSMB
->hdr
.Uid
;
4526 dnotify_req
->netfid
= netfid
;
4527 dnotify_req
->pfile
= pfile
;
4528 dnotify_req
->filter
= filter
;
4529 dnotify_req
->multishot
= multishot
;
4530 spin_lock(&GlobalMid_Lock
);
4531 list_add_tail(&dnotify_req
->lhead
,
4532 &GlobalDnotifyReqList
);
4533 spin_unlock(&GlobalMid_Lock
);
4537 cifs_buf_release(pSMB
);
4540 #ifdef CONFIG_CIFS_XATTR
4542 CIFSSMBQAllEAs(const int xid
, struct cifsTconInfo
*tcon
,
4543 const unsigned char *searchName
,
4544 char * EAData
, size_t buf_size
,
4545 const struct nls_table
*nls_codepage
, int remap
)
4547 /* BB assumes one setup word */
4548 TRANSACTION2_QPI_REQ
*pSMB
= NULL
;
4549 TRANSACTION2_QPI_RSP
*pSMBr
= NULL
;
4553 struct fea
* temp_fea
;
4555 __u16 params
, byte_count
;
4557 cFYI(1, ("In Query All EAs path %s", searchName
));
4559 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4564 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
4566 cifsConvertToUCS((__le16
*) pSMB
->FileName
, searchName
,
4567 PATH_MAX
, nls_codepage
, remap
);
4568 name_len
++; /* trailing null */
4570 } else { /* BB improve the check for buffer overruns BB */
4571 name_len
= strnlen(searchName
, PATH_MAX
);
4572 name_len
++; /* trailing null */
4573 strncpy(pSMB
->FileName
, searchName
, name_len
);
4576 params
= 2 /* level */ + 4 /* reserved */ + name_len
/* includes NUL */ ;
4577 pSMB
->TotalDataCount
= 0;
4578 pSMB
->MaxParameterCount
= cpu_to_le16(2);
4579 pSMB
->MaxDataCount
= cpu_to_le16(4000); /* BB find exact max SMB PDU from sess structure BB */
4580 pSMB
->MaxSetupCount
= 0;
4584 pSMB
->Reserved2
= 0;
4585 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
4586 struct smb_com_transaction2_qpi_req
,InformationLevel
) - 4);
4587 pSMB
->DataCount
= 0;
4588 pSMB
->DataOffset
= 0;
4589 pSMB
->SetupCount
= 1;
4590 pSMB
->Reserved3
= 0;
4591 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION
);
4592 byte_count
= params
+ 1 /* pad */ ;
4593 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
4594 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
4595 pSMB
->InformationLevel
= cpu_to_le16(SMB_INFO_QUERY_ALL_EAS
);
4596 pSMB
->Reserved4
= 0;
4597 pSMB
->hdr
.smb_buf_length
+= byte_count
;
4598 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4600 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4601 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4603 cFYI(1, ("Send error in QueryAllEAs = %d", rc
));
4604 } else { /* decode response */
4605 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
4607 /* BB also check enough total bytes returned */
4608 /* BB we need to improve the validity checking
4609 of these trans2 responses */
4610 if (rc
|| (pSMBr
->ByteCount
< 4))
4611 rc
= -EIO
; /* bad smb */
4612 /* else if (pFindData){
4613 memcpy((char *) pFindData,
4614 (char *) &pSMBr->hdr.Protocol +
4617 /* check that length of list is not more than bcc */
4618 /* check that each entry does not go beyond length
4620 /* check that each element of each entry does not
4621 go beyond end of list */
4622 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
4623 struct fealist
* ea_response_data
;
4625 /* validate_trans2_offsets() */
4626 /* BB to check if(start of smb + data_offset > &bcc+ bcc)*/
4627 ea_response_data
= (struct fealist
*)
4628 (((char *) &pSMBr
->hdr
.Protocol
) +
4630 name_len
= le32_to_cpu(ea_response_data
->list_len
);
4631 cFYI(1,("ea length %d", name_len
));
4633 /* returned EA size zeroed at top of function */
4634 cFYI(1,("empty EA list returned from server"));
4636 /* account for ea list len */
4638 temp_fea
= ea_response_data
->list
;
4639 temp_ptr
= (char *)temp_fea
;
4640 while(name_len
> 0) {
4644 rc
+= temp_fea
->name_len
;
4645 /* account for prefix user. and trailing null */
4647 if(rc
<(int)buf_size
) {
4648 memcpy(EAData
,"user.",5);
4650 memcpy(EAData
,temp_ptr
,temp_fea
->name_len
);
4651 EAData
+=temp_fea
->name_len
;
4652 /* null terminate name */
4654 EAData
= EAData
+ 1;
4655 } else if(buf_size
== 0) {
4656 /* skip copy - calc size only */
4658 /* stop before overrun buffer */
4662 name_len
-= temp_fea
->name_len
;
4663 temp_ptr
+= temp_fea
->name_len
;
4664 /* account for trailing null */
4667 value_len
= le16_to_cpu(temp_fea
->value_len
);
4668 name_len
-= value_len
;
4669 temp_ptr
+= value_len
;
4670 /* BB check that temp_ptr is still within smb BB*/
4671 /* no trailing null to account for in value len */
4672 /* go on to next EA */
4673 temp_fea
= (struct fea
*)temp_ptr
;
4679 cifs_buf_release(pSMB
);
4686 ssize_t
CIFSSMBQueryEA(const int xid
,struct cifsTconInfo
* tcon
,
4687 const unsigned char * searchName
,const unsigned char * ea_name
,
4688 unsigned char * ea_value
, size_t buf_size
,
4689 const struct nls_table
*nls_codepage
, int remap
)
4691 TRANSACTION2_QPI_REQ
*pSMB
= NULL
;
4692 TRANSACTION2_QPI_RSP
*pSMBr
= NULL
;
4696 struct fea
* temp_fea
;
4698 __u16 params
, byte_count
;
4700 cFYI(1, ("In Query EA path %s", searchName
));
4702 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4707 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
4709 cifsConvertToUCS((__le16
*) pSMB
->FileName
, searchName
,
4710 PATH_MAX
, nls_codepage
, remap
);
4711 name_len
++; /* trailing null */
4713 } else { /* BB improve the check for buffer overruns BB */
4714 name_len
= strnlen(searchName
, PATH_MAX
);
4715 name_len
++; /* trailing null */
4716 strncpy(pSMB
->FileName
, searchName
, name_len
);
4719 params
= 2 /* level */ + 4 /* reserved */ + name_len
/* includes NUL */ ;
4720 pSMB
->TotalDataCount
= 0;
4721 pSMB
->MaxParameterCount
= cpu_to_le16(2);
4722 pSMB
->MaxDataCount
= cpu_to_le16(4000); /* BB find exact max SMB PDU from sess structure BB */
4723 pSMB
->MaxSetupCount
= 0;
4727 pSMB
->Reserved2
= 0;
4728 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
4729 struct smb_com_transaction2_qpi_req
,InformationLevel
) - 4);
4730 pSMB
->DataCount
= 0;
4731 pSMB
->DataOffset
= 0;
4732 pSMB
->SetupCount
= 1;
4733 pSMB
->Reserved3
= 0;
4734 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION
);
4735 byte_count
= params
+ 1 /* pad */ ;
4736 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
4737 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
4738 pSMB
->InformationLevel
= cpu_to_le16(SMB_INFO_QUERY_ALL_EAS
);
4739 pSMB
->Reserved4
= 0;
4740 pSMB
->hdr
.smb_buf_length
+= byte_count
;
4741 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4743 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4744 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4746 cFYI(1, ("Send error in Query EA = %d", rc
));
4747 } else { /* decode response */
4748 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
4750 /* BB also check enough total bytes returned */
4751 /* BB we need to improve the validity checking
4752 of these trans2 responses */
4753 if (rc
|| (pSMBr
->ByteCount
< 4))
4754 rc
= -EIO
; /* bad smb */
4755 /* else if (pFindData){
4756 memcpy((char *) pFindData,
4757 (char *) &pSMBr->hdr.Protocol +
4760 /* check that length of list is not more than bcc */
4761 /* check that each entry does not go beyond length
4763 /* check that each element of each entry does not
4764 go beyond end of list */
4765 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
4766 struct fealist
* ea_response_data
;
4768 /* validate_trans2_offsets() */
4769 /* BB to check if(start of smb + data_offset > &bcc+ bcc)*/
4770 ea_response_data
= (struct fealist
*)
4771 (((char *) &pSMBr
->hdr
.Protocol
) +
4773 name_len
= le32_to_cpu(ea_response_data
->list_len
);
4774 cFYI(1,("ea length %d", name_len
));
4776 /* returned EA size zeroed at top of function */
4777 cFYI(1,("empty EA list returned from server"));
4779 /* account for ea list len */
4781 temp_fea
= ea_response_data
->list
;
4782 temp_ptr
= (char *)temp_fea
;
4783 /* loop through checking if we have a matching
4784 name and then return the associated value */
4785 while(name_len
> 0) {
4789 value_len
= le16_to_cpu(temp_fea
->value_len
);
4790 /* BB validate that value_len falls within SMB,
4791 even though maximum for name_len is 255 */
4792 if(memcmp(temp_fea
->name
,ea_name
,
4793 temp_fea
->name_len
) == 0) {
4796 /* account for prefix user. and trailing null */
4797 if(rc
<=(int)buf_size
) {
4799 temp_fea
->name
+temp_fea
->name_len
+1,
4801 /* ea values, unlike ea names,
4802 are not null terminated */
4803 } else if(buf_size
== 0) {
4804 /* skip copy - calc size only */
4806 /* stop before overrun buffer */
4811 name_len
-= temp_fea
->name_len
;
4812 temp_ptr
+= temp_fea
->name_len
;
4813 /* account for trailing null */
4816 name_len
-= value_len
;
4817 temp_ptr
+= value_len
;
4818 /* no trailing null to account for in value len */
4819 /* go on to next EA */
4820 temp_fea
= (struct fea
*)temp_ptr
;
4826 cifs_buf_release(pSMB
);
4834 CIFSSMBSetEA(const int xid
, struct cifsTconInfo
*tcon
, const char *fileName
,
4835 const char * ea_name
, const void * ea_value
,
4836 const __u16 ea_value_len
, const struct nls_table
*nls_codepage
,
4839 struct smb_com_transaction2_spi_req
*pSMB
= NULL
;
4840 struct smb_com_transaction2_spi_rsp
*pSMBr
= NULL
;
4841 struct fealist
*parm_data
;
4844 int bytes_returned
= 0;
4845 __u16 params
, param_offset
, byte_count
, offset
, count
;
4847 cFYI(1, ("In SetEA"));
4849 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4854 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
4856 cifsConvertToUCS((__le16
*) pSMB
->FileName
, fileName
,
4857 PATH_MAX
, nls_codepage
, remap
);
4858 name_len
++; /* trailing null */
4860 } else { /* BB improve the check for buffer overruns BB */
4861 name_len
= strnlen(fileName
, PATH_MAX
);
4862 name_len
++; /* trailing null */
4863 strncpy(pSMB
->FileName
, fileName
, name_len
);
4866 params
= 6 + name_len
;
4868 /* done calculating parms using name_len of file name,
4869 now use name_len to calculate length of ea name
4870 we are going to create in the inode xattrs */
4874 name_len
= strnlen(ea_name
,255);
4876 count
= sizeof(*parm_data
) + ea_value_len
+ name_len
+ 1;
4877 pSMB
->MaxParameterCount
= cpu_to_le16(2);
4878 pSMB
->MaxDataCount
= cpu_to_le16(1000); /* BB find max SMB size from sess */
4879 pSMB
->MaxSetupCount
= 0;
4883 pSMB
->Reserved2
= 0;
4884 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
4885 InformationLevel
) - 4;
4886 offset
= param_offset
+ params
;
4887 pSMB
->InformationLevel
=
4888 cpu_to_le16(SMB_SET_FILE_EA
);
4891 (struct fealist
*) (((char *) &pSMB
->hdr
.Protocol
) +
4893 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
4894 pSMB
->DataOffset
= cpu_to_le16(offset
);
4895 pSMB
->SetupCount
= 1;
4896 pSMB
->Reserved3
= 0;
4897 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
4898 byte_count
= 3 /* pad */ + params
+ count
;
4899 pSMB
->DataCount
= cpu_to_le16(count
);
4900 parm_data
->list_len
= cpu_to_le32(count
);
4901 parm_data
->list
[0].EA_flags
= 0;
4902 /* we checked above that name len is less than 255 */
4903 parm_data
->list
[0].name_len
= (__u8
)name_len
;;
4904 /* EA names are always ASCII */
4906 strncpy(parm_data
->list
[0].name
,ea_name
,name_len
);
4907 parm_data
->list
[0].name
[name_len
] = 0;
4908 parm_data
->list
[0].value_len
= cpu_to_le16(ea_value_len
);
4909 /* caller ensures that ea_value_len is less than 64K but
4910 we need to ensure that it fits within the smb */
4912 /*BB add length check that it would fit in negotiated SMB buffer size BB */
4913 /* if(ea_value_len > buffer_size - 512 (enough for header)) */
4915 memcpy(parm_data
->list
[0].name
+name_len
+1,ea_value
,ea_value_len
);
4917 pSMB
->TotalDataCount
= pSMB
->DataCount
;
4918 pSMB
->ParameterCount
= cpu_to_le16(params
);
4919 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
4920 pSMB
->Reserved4
= 0;
4921 pSMB
->hdr
.smb_buf_length
+= byte_count
;
4922 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4923 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4924 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4926 cFYI(1, ("SetPathInfo (EA) returned %d", rc
));
4929 cifs_buf_release(pSMB
);