4 * Copyright (C) International Business Machines Corp., 2002,2008
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 differently for reconnection purposes since we never */
28 /* want to reuse a stale file handle and only the caller knows the file info */
31 #include <linux/kernel.h>
32 #include <linux/vfs.h>
33 #include <linux/posix_acl_xattr.h>
34 #include <asm/uaccess.h>
38 #include "cifsproto.h"
39 #include "cifs_unicode.h"
40 #include "cifs_debug.h"
42 #ifdef CONFIG_CIFS_POSIX
47 #ifdef CONFIG_CIFS_WEAK_PW_HASH
48 {LANMAN_PROT
, "\2LM1.2X002"},
49 {LANMAN2_PROT
, "\2LANMAN2.1"},
50 #endif /* weak password hashing for legacy clients */
51 {CIFS_PROT
, "\2NT LM 0.12"},
52 {POSIX_PROT
, "\2POSIX 2"},
60 #ifdef CONFIG_CIFS_WEAK_PW_HASH
61 {LANMAN_PROT
, "\2LM1.2X002"},
62 {LANMAN2_PROT
, "\2LANMAN2.1"},
63 #endif /* weak password hashing for legacy clients */
64 {CIFS_PROT
, "\2NT LM 0.12"},
69 /* define the number of elements in the cifs dialect array */
70 #ifdef CONFIG_CIFS_POSIX
71 #ifdef CONFIG_CIFS_WEAK_PW_HASH
72 #define CIFS_NUM_PROT 4
74 #define CIFS_NUM_PROT 2
75 #endif /* CIFS_WEAK_PW_HASH */
77 #ifdef CONFIG_CIFS_WEAK_PW_HASH
78 #define CIFS_NUM_PROT 3
80 #define CIFS_NUM_PROT 1
81 #endif /* CONFIG_CIFS_WEAK_PW_HASH */
82 #endif /* CIFS_POSIX */
84 /* Allocates buffer into dst and copies smb string from src to it.
85 * caller is responsible for freeing dst if function returned 0.
91 cifs_strncpy_to_host(char **dst
, const char *src
, const int maxlen
,
92 const bool is_unicode
, const struct nls_table
*nls_codepage
)
97 plen
= UniStrnlen((wchar_t *)src
, maxlen
);
98 *dst
= kmalloc(plen
+ 2, GFP_KERNEL
);
100 goto cifs_strncpy_to_host_ErrExit
;
101 cifs_strfromUCS_le(*dst
, (__le16
*)src
, plen
, nls_codepage
);
103 plen
= strnlen(src
, maxlen
);
104 *dst
= kmalloc(plen
+ 2, GFP_KERNEL
);
106 goto cifs_strncpy_to_host_ErrExit
;
107 strncpy(*dst
, src
, plen
);
110 (*dst
)[plen
+1] = 0; /* harmless for ASCII case, needed for Unicode */
113 cifs_strncpy_to_host_ErrExit
:
114 cERROR(1, ("Failed to allocate buffer for string\n"));
119 /* Mark as invalid, all open files on tree connections since they
120 were closed when session to server was lost */
121 static void mark_open_files_invalid(struct cifsTconInfo
*pTcon
)
123 struct cifsFileInfo
*open_file
= NULL
;
124 struct list_head
*tmp
;
125 struct list_head
*tmp1
;
127 /* list all files open on tree connection and mark them invalid */
128 write_lock(&GlobalSMBSeslock
);
129 list_for_each_safe(tmp
, tmp1
, &pTcon
->openFileList
) {
130 open_file
= list_entry(tmp
, struct cifsFileInfo
, tlist
);
132 open_file
->invalidHandle
= true;
134 write_unlock(&GlobalSMBSeslock
);
135 /* BB Add call to invalidate_inodes(sb) for all superblocks mounted
139 /* Allocate and return pointer to an SMB request buffer, and set basic
140 SMB information in the SMB header. If the return code is zero, this
141 function must have filled in request_buf pointer */
143 small_smb_init(int smb_command
, int wct
, struct cifsTconInfo
*tcon
,
148 /* SMBs NegProt, SessSetup, uLogoff do not have tcon yet so
149 check for tcp and smb session status done differently
150 for those three - in the calling routine */
152 if (tcon
->tidStatus
== CifsExiting
) {
153 /* only tree disconnect, open, and write,
154 (and ulogoff which does not have tcon)
155 are allowed as we start force umount */
156 if ((smb_command
!= SMB_COM_WRITE_ANDX
) &&
157 (smb_command
!= SMB_COM_OPEN_ANDX
) &&
158 (smb_command
!= SMB_COM_TREE_DISCONNECT
)) {
159 cFYI(1, ("can not send cmd %d while umounting",
164 if ((tcon
->ses
) && (tcon
->ses
->status
!= CifsExiting
) &&
165 (tcon
->ses
->server
)) {
166 struct nls_table
*nls_codepage
;
167 /* Give Demultiplex thread up to 10 seconds to
168 reconnect, should be greater than cifs socket
169 timeout which is 7 seconds */
170 while (tcon
->ses
->server
->tcpStatus
==
172 wait_event_interruptible_timeout(tcon
->ses
->server
->response_q
,
173 (tcon
->ses
->server
->tcpStatus
==
175 if (tcon
->ses
->server
->tcpStatus
==
177 /* on "soft" mounts we wait once */
179 (tcon
->ses
->status
== CifsExiting
)) {
180 cFYI(1, ("gave up waiting on "
181 "reconnect in smb_init"));
183 } /* else "hard" mount - keep retrying
184 until process is killed or server
185 comes back on-line */
186 } else /* TCP session is reestablished now */
190 nls_codepage
= load_nls_default();
191 /* need to prevent multiple threads trying to
192 simultaneously reconnect the same SMB session */
193 down(&tcon
->ses
->sesSem
);
194 if (tcon
->ses
->status
== CifsNeedReconnect
)
195 rc
= cifs_setup_session(0, tcon
->ses
,
197 if (!rc
&& (tcon
->tidStatus
== CifsNeedReconnect
)) {
198 mark_open_files_invalid(tcon
);
199 rc
= CIFSTCon(0, tcon
->ses
, tcon
->treeName
,
201 up(&tcon
->ses
->sesSem
);
202 /* BB FIXME add code to check if wsize needs
203 update due to negotiated smb buffer size
206 atomic_inc(&tconInfoReconnectCount
);
207 /* tell server Unix caps we support */
208 if (tcon
->ses
->capabilities
& CAP_UNIX
)
209 reset_cifs_unix_caps(
212 NULL
/* we do not know sb */,
213 NULL
/* no vol info */);
216 cFYI(1, ("reconnect tcon rc = %d", rc
));
217 /* Removed call to reopen open files here.
218 It is safer (and faster) to reopen files
219 one at a time as needed in read and write */
221 /* Check if handle based operation so we
222 know whether we can continue or not without
223 returning to caller to reset file handle */
224 switch (smb_command
) {
225 case SMB_COM_READ_ANDX
:
226 case SMB_COM_WRITE_ANDX
:
228 case SMB_COM_FIND_CLOSE2
:
229 case SMB_COM_LOCKING_ANDX
: {
230 unload_nls(nls_codepage
);
235 up(&tcon
->ses
->sesSem
);
237 unload_nls(nls_codepage
);
246 *request_buf
= cifs_small_buf_get();
247 if (*request_buf
== NULL
) {
248 /* BB should we add a retry in here if not a writepage? */
252 header_assemble((struct smb_hdr
*) *request_buf
, smb_command
,
256 cifs_stats_inc(&tcon
->num_smbs_sent
);
262 small_smb_init_no_tc(const int smb_command
, const int wct
,
263 struct cifsSesInfo
*ses
, void **request_buf
)
266 struct smb_hdr
*buffer
;
268 rc
= small_smb_init(smb_command
, wct
, NULL
, request_buf
);
272 buffer
= (struct smb_hdr
*)*request_buf
;
273 buffer
->Mid
= GetNextMid(ses
->server
);
274 if (ses
->capabilities
& CAP_UNICODE
)
275 buffer
->Flags2
|= SMBFLG2_UNICODE
;
276 if (ses
->capabilities
& CAP_STATUS32
)
277 buffer
->Flags2
|= SMBFLG2_ERR_STATUS
;
279 /* uid, tid can stay at zero as set in header assemble */
281 /* BB add support for turning on the signing when
282 this function is used after 1st of session setup requests */
287 /* If the return code is zero, this function must fill in request_buf pointer */
289 smb_init(int smb_command
, int wct
, struct cifsTconInfo
*tcon
,
290 void **request_buf
/* returned */ ,
291 void **response_buf
/* returned */ )
295 /* SMBs NegProt, SessSetup, uLogoff do not have tcon yet so
296 check for tcp and smb session status done differently
297 for those three - in the calling routine */
299 if (tcon
->tidStatus
== CifsExiting
) {
300 /* only tree disconnect, open, and write,
301 (and ulogoff which does not have tcon)
302 are allowed as we start force umount */
303 if ((smb_command
!= SMB_COM_WRITE_ANDX
) &&
304 (smb_command
!= SMB_COM_OPEN_ANDX
) &&
305 (smb_command
!= SMB_COM_TREE_DISCONNECT
)) {
306 cFYI(1, ("can not send cmd %d while umounting",
312 if ((tcon
->ses
) && (tcon
->ses
->status
!= CifsExiting
) &&
313 (tcon
->ses
->server
)) {
314 struct nls_table
*nls_codepage
;
315 /* Give Demultiplex thread up to 10 seconds to
316 reconnect, should be greater than cifs socket
317 timeout which is 7 seconds */
318 while (tcon
->ses
->server
->tcpStatus
==
320 wait_event_interruptible_timeout(tcon
->ses
->server
->response_q
,
321 (tcon
->ses
->server
->tcpStatus
==
323 if (tcon
->ses
->server
->tcpStatus
==
325 /* on "soft" mounts we wait once */
327 (tcon
->ses
->status
== CifsExiting
)) {
328 cFYI(1, ("gave up waiting on "
329 "reconnect in smb_init"));
331 } /* else "hard" mount - keep retrying
332 until process is killed or server
334 } else /* TCP session is reestablished now */
337 nls_codepage
= load_nls_default();
338 /* need to prevent multiple threads trying to
339 simultaneously reconnect the same SMB session */
340 down(&tcon
->ses
->sesSem
);
341 if (tcon
->ses
->status
== CifsNeedReconnect
)
342 rc
= cifs_setup_session(0, tcon
->ses
,
344 if (!rc
&& (tcon
->tidStatus
== CifsNeedReconnect
)) {
345 mark_open_files_invalid(tcon
);
346 rc
= CIFSTCon(0, tcon
->ses
, tcon
->treeName
,
348 up(&tcon
->ses
->sesSem
);
349 /* BB FIXME add code to check if wsize needs
350 update due to negotiated smb buffer size
353 atomic_inc(&tconInfoReconnectCount
);
354 /* tell server Unix caps we support */
355 if (tcon
->ses
->capabilities
& CAP_UNIX
)
356 reset_cifs_unix_caps(
359 NULL
/* do not know sb */,
360 NULL
/* no vol info */);
363 cFYI(1, ("reconnect tcon rc = %d", rc
));
364 /* Removed call to reopen open files here.
365 It is safer (and faster) to reopen files
366 one at a time as needed in read and write */
368 /* Check if handle based operation so we
369 know whether we can continue or not without
370 returning to caller to reset file handle */
371 switch (smb_command
) {
372 case SMB_COM_READ_ANDX
:
373 case SMB_COM_WRITE_ANDX
:
375 case SMB_COM_FIND_CLOSE2
:
376 case SMB_COM_LOCKING_ANDX
: {
377 unload_nls(nls_codepage
);
382 up(&tcon
->ses
->sesSem
);
384 unload_nls(nls_codepage
);
393 *request_buf
= cifs_buf_get();
394 if (*request_buf
== NULL
) {
395 /* BB should we add a retry in here if not a writepage? */
398 /* Although the original thought was we needed the response buf for */
399 /* potential retries of smb operations it turns out we can determine */
400 /* from the mid flags when the request buffer can be resent without */
401 /* having to use a second distinct buffer for the response */
403 *response_buf
= *request_buf
;
405 header_assemble((struct smb_hdr
*) *request_buf
, smb_command
, tcon
,
409 cifs_stats_inc(&tcon
->num_smbs_sent
);
414 static int validate_t2(struct smb_t2_rsp
*pSMB
)
420 /* check for plausible wct, bcc and t2 data and parm sizes */
421 /* check for parm and data offset going beyond end of smb */
422 if (pSMB
->hdr
.WordCount
>= 10) {
423 if ((le16_to_cpu(pSMB
->t2_rsp
.ParameterOffset
) <= 1024) &&
424 (le16_to_cpu(pSMB
->t2_rsp
.DataOffset
) <= 1024)) {
425 /* check that bcc is at least as big as parms + data */
426 /* check that bcc is less than negotiated smb buffer */
427 total_size
= le16_to_cpu(pSMB
->t2_rsp
.ParameterCount
);
428 if (total_size
< 512) {
430 le16_to_cpu(pSMB
->t2_rsp
.DataCount
);
431 /* BCC le converted in SendReceive */
432 pBCC
= (pSMB
->hdr
.WordCount
* 2) +
433 sizeof(struct smb_hdr
) +
435 if ((total_size
<= (*(u16
*)pBCC
)) &&
437 CIFSMaxBufSize
+MAX_CIFS_HDR_SIZE
)) {
443 cifs_dump_mem("Invalid transact2 SMB: ", (char *)pSMB
,
444 sizeof(struct smb_t2_rsp
) + 16);
448 CIFSSMBNegotiate(unsigned int xid
, struct cifsSesInfo
*ses
)
451 NEGOTIATE_RSP
*pSMBr
;
455 struct TCP_Server_Info
*server
;
457 unsigned int secFlags
;
461 server
= ses
->server
;
466 rc
= smb_init(SMB_COM_NEGOTIATE
, 0, NULL
/* no tcon yet */ ,
467 (void **) &pSMB
, (void **) &pSMBr
);
471 /* if any of auth flags (ie not sign or seal) are overriden use them */
472 if (ses
->overrideSecFlg
& (~(CIFSSEC_MUST_SIGN
| CIFSSEC_MUST_SEAL
)))
473 secFlags
= ses
->overrideSecFlg
; /* BB FIXME fix sign flags? */
474 else /* if override flags set only sign/seal OR them with global auth */
475 secFlags
= extended_security
| ses
->overrideSecFlg
;
477 cFYI(1, ("secFlags 0x%x", secFlags
));
479 pSMB
->hdr
.Mid
= GetNextMid(server
);
480 pSMB
->hdr
.Flags2
|= (SMBFLG2_UNICODE
| SMBFLG2_ERR_STATUS
);
482 if ((secFlags
& CIFSSEC_MUST_KRB5
) == CIFSSEC_MUST_KRB5
)
483 pSMB
->hdr
.Flags2
|= SMBFLG2_EXT_SEC
;
484 else if ((secFlags
& CIFSSEC_AUTH_MASK
) == CIFSSEC_MAY_KRB5
) {
485 cFYI(1, ("Kerberos only mechanism, enable extended security"));
486 pSMB
->hdr
.Flags2
|= SMBFLG2_EXT_SEC
;
490 for (i
= 0; i
< CIFS_NUM_PROT
; i
++) {
491 strncpy(pSMB
->DialectsArray
+count
, protocols
[i
].name
, 16);
492 count
+= strlen(protocols
[i
].name
) + 1;
493 /* null at end of source and target buffers anyway */
495 pSMB
->hdr
.smb_buf_length
+= count
;
496 pSMB
->ByteCount
= cpu_to_le16(count
);
498 rc
= SendReceive(xid
, ses
, (struct smb_hdr
*) pSMB
,
499 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
503 dialect
= le16_to_cpu(pSMBr
->DialectIndex
);
504 cFYI(1, ("Dialect: %d", dialect
));
505 /* Check wct = 1 error case */
506 if ((pSMBr
->hdr
.WordCount
< 13) || (dialect
== BAD_PROT
)) {
507 /* core returns wct = 1, but we do not ask for core - otherwise
508 small wct just comes when dialect index is -1 indicating we
509 could not negotiate a common dialect */
512 #ifdef CONFIG_CIFS_WEAK_PW_HASH
513 } else if ((pSMBr
->hdr
.WordCount
== 13)
514 && ((dialect
== LANMAN_PROT
)
515 || (dialect
== LANMAN2_PROT
))) {
517 struct lanman_neg_rsp
*rsp
= (struct lanman_neg_rsp
*)pSMBr
;
519 if ((secFlags
& CIFSSEC_MAY_LANMAN
) ||
520 (secFlags
& CIFSSEC_MAY_PLNTXT
))
521 server
->secType
= LANMAN
;
523 cERROR(1, ("mount failed weak security disabled"
524 " in /proc/fs/cifs/SecurityFlags"));
528 server
->secMode
= (__u8
)le16_to_cpu(rsp
->SecurityMode
);
529 server
->maxReq
= le16_to_cpu(rsp
->MaxMpxCount
);
530 server
->maxBuf
= min((__u32
)le16_to_cpu(rsp
->MaxBufSize
),
531 (__u32
)CIFSMaxBufSize
+ MAX_CIFS_HDR_SIZE
);
532 GETU32(server
->sessid
) = le32_to_cpu(rsp
->SessionKey
);
533 /* even though we do not use raw we might as well set this
534 accurately, in case we ever find a need for it */
535 if ((le16_to_cpu(rsp
->RawMode
) & RAW_ENABLE
) == RAW_ENABLE
) {
536 server
->maxRw
= 0xFF00;
537 server
->capabilities
= CAP_MPX_MODE
| CAP_RAW_MODE
;
539 server
->maxRw
= 0;/* we do not need to use raw anyway */
540 server
->capabilities
= CAP_MPX_MODE
;
542 tmp
= (__s16
)le16_to_cpu(rsp
->ServerTimeZone
);
544 /* OS/2 often does not set timezone therefore
545 * we must use server time to calc time zone.
546 * Could deviate slightly from the right zone.
547 * Smallest defined timezone difference is 15 minutes
548 * (i.e. Nepal). Rounding up/down is done to match
551 int val
, seconds
, remain
, result
;
552 struct timespec ts
, utc
;
554 ts
= cnvrtDosUnixTm(le16_to_cpu(rsp
->SrvTime
.Date
),
555 le16_to_cpu(rsp
->SrvTime
.Time
));
556 cFYI(1, ("SrvTime %d sec since 1970 (utc: %d) diff: %d",
557 (int)ts
.tv_sec
, (int)utc
.tv_sec
,
558 (int)(utc
.tv_sec
- ts
.tv_sec
)));
559 val
= (int)(utc
.tv_sec
- ts
.tv_sec
);
561 result
= (seconds
/ MIN_TZ_ADJ
) * MIN_TZ_ADJ
;
562 remain
= seconds
% MIN_TZ_ADJ
;
563 if (remain
>= (MIN_TZ_ADJ
/ 2))
564 result
+= MIN_TZ_ADJ
;
567 server
->timeAdj
= result
;
569 server
->timeAdj
= (int)tmp
;
570 server
->timeAdj
*= 60; /* also in seconds */
572 cFYI(1, ("server->timeAdj: %d seconds", server
->timeAdj
));
575 /* BB get server time for time conversions and add
576 code to use it and timezone since this is not UTC */
578 if (rsp
->EncryptionKeyLength
==
579 cpu_to_le16(CIFS_CRYPTO_KEY_SIZE
)) {
580 memcpy(server
->cryptKey
, rsp
->EncryptionKey
,
581 CIFS_CRYPTO_KEY_SIZE
);
582 } else if (server
->secMode
& SECMODE_PW_ENCRYPT
) {
583 rc
= -EIO
; /* need cryptkey unless plain text */
587 cFYI(1, ("LANMAN negotiated"));
588 /* we will not end up setting signing flags - as no signing
589 was in LANMAN and server did not return the flags on */
591 #else /* weak security disabled */
592 } else if (pSMBr
->hdr
.WordCount
== 13) {
593 cERROR(1, ("mount failed, cifs module not built "
594 "with CIFS_WEAK_PW_HASH support"));
596 #endif /* WEAK_PW_HASH */
598 } else if (pSMBr
->hdr
.WordCount
!= 17) {
603 /* else wct == 17 NTLM */
604 server
->secMode
= pSMBr
->SecurityMode
;
605 if ((server
->secMode
& SECMODE_USER
) == 0)
606 cFYI(1, ("share mode security"));
608 if ((server
->secMode
& SECMODE_PW_ENCRYPT
) == 0)
609 #ifdef CONFIG_CIFS_WEAK_PW_HASH
610 if ((secFlags
& CIFSSEC_MAY_PLNTXT
) == 0)
611 #endif /* CIFS_WEAK_PW_HASH */
612 cERROR(1, ("Server requests plain text password"
613 " but client support disabled"));
615 if ((secFlags
& CIFSSEC_MUST_NTLMV2
) == CIFSSEC_MUST_NTLMV2
)
616 server
->secType
= NTLMv2
;
617 else if (secFlags
& CIFSSEC_MAY_NTLM
)
618 server
->secType
= NTLM
;
619 else if (secFlags
& CIFSSEC_MAY_NTLMV2
)
620 server
->secType
= NTLMv2
;
621 else if (secFlags
& CIFSSEC_MAY_KRB5
)
622 server
->secType
= Kerberos
;
623 else if (secFlags
& CIFSSEC_MAY_LANMAN
)
624 server
->secType
= LANMAN
;
625 /* #ifdef CONFIG_CIFS_EXPERIMENTAL
626 else if (secFlags & CIFSSEC_MAY_PLNTXT)
631 cERROR(1, ("Invalid security type"));
634 /* else ... any others ...? */
636 /* one byte, so no need to convert this or EncryptionKeyLen from
638 server
->maxReq
= le16_to_cpu(pSMBr
->MaxMpxCount
);
639 /* probably no need to store and check maxvcs */
640 server
->maxBuf
= min(le32_to_cpu(pSMBr
->MaxBufferSize
),
641 (__u32
) CIFSMaxBufSize
+ MAX_CIFS_HDR_SIZE
);
642 server
->maxRw
= le32_to_cpu(pSMBr
->MaxRawSize
);
643 cFYI(DBG2
, ("Max buf = %d", ses
->server
->maxBuf
));
644 GETU32(ses
->server
->sessid
) = le32_to_cpu(pSMBr
->SessionKey
);
645 server
->capabilities
= le32_to_cpu(pSMBr
->Capabilities
);
646 server
->timeAdj
= (int)(__s16
)le16_to_cpu(pSMBr
->ServerTimeZone
);
647 server
->timeAdj
*= 60;
648 if (pSMBr
->EncryptionKeyLength
== CIFS_CRYPTO_KEY_SIZE
) {
649 memcpy(server
->cryptKey
, pSMBr
->u
.EncryptionKey
,
650 CIFS_CRYPTO_KEY_SIZE
);
651 } else if ((pSMBr
->hdr
.Flags2
& SMBFLG2_EXT_SEC
)
652 && (pSMBr
->EncryptionKeyLength
== 0)) {
653 /* decode security blob */
654 } else if (server
->secMode
& SECMODE_PW_ENCRYPT
) {
655 rc
= -EIO
; /* no crypt key only if plain text pwd */
659 /* BB might be helpful to save off the domain of server here */
661 if ((pSMBr
->hdr
.Flags2
& SMBFLG2_EXT_SEC
) &&
662 (server
->capabilities
& CAP_EXTENDED_SECURITY
)) {
663 count
= pSMBr
->ByteCount
;
669 if (server
->socketUseCount
.counter
> 1) {
670 if (memcmp(server
->server_GUID
,
671 pSMBr
->u
.extended_response
.
673 cFYI(1, ("server UID changed"));
674 memcpy(server
->server_GUID
,
675 pSMBr
->u
.extended_response
.GUID
,
679 memcpy(server
->server_GUID
,
680 pSMBr
->u
.extended_response
.GUID
, 16);
683 server
->secType
= RawNTLMSSP
;
685 rc
= decode_negTokenInit(pSMBr
->u
.extended_response
.
696 server
->capabilities
&= ~CAP_EXTENDED_SECURITY
;
698 #ifdef CONFIG_CIFS_WEAK_PW_HASH
701 if ((secFlags
& CIFSSEC_MAY_SIGN
) == 0) {
702 /* MUST_SIGN already includes the MAY_SIGN FLAG
703 so if this is zero it means that signing is disabled */
704 cFYI(1, ("Signing disabled"));
705 if (server
->secMode
& SECMODE_SIGN_REQUIRED
) {
706 cERROR(1, ("Server requires "
707 "packet signing to be enabled in "
708 "/proc/fs/cifs/SecurityFlags."));
712 ~(SECMODE_SIGN_ENABLED
| SECMODE_SIGN_REQUIRED
);
713 } else if ((secFlags
& CIFSSEC_MUST_SIGN
) == CIFSSEC_MUST_SIGN
) {
714 /* signing required */
715 cFYI(1, ("Must sign - secFlags 0x%x", secFlags
));
716 if ((server
->secMode
&
717 (SECMODE_SIGN_ENABLED
| SECMODE_SIGN_REQUIRED
)) == 0) {
719 ("signing required but server lacks support"));
722 server
->secMode
|= SECMODE_SIGN_REQUIRED
;
724 /* signing optional ie CIFSSEC_MAY_SIGN */
725 if ((server
->secMode
& SECMODE_SIGN_REQUIRED
) == 0)
727 ~(SECMODE_SIGN_ENABLED
| SECMODE_SIGN_REQUIRED
);
731 cifs_buf_release(pSMB
);
733 cFYI(1, ("negprot rc %d", rc
));
738 CIFSSMBTDis(const int xid
, struct cifsTconInfo
*tcon
)
740 struct smb_hdr
*smb_buffer
;
743 cFYI(1, ("In tree disconnect"));
745 * If last user of the connection and
746 * connection alive - disconnect it
747 * If this is the last connection on the server session disconnect it
748 * (and inside session disconnect we should check if tcp socket needs
749 * to be freed and kernel thread woken up).
752 down(&tcon
->tconSem
);
756 atomic_dec(&tcon
->useCount
);
757 if (atomic_read(&tcon
->useCount
) > 0) {
762 /* No need to return error on this operation if tid invalidated and
763 closed on server already e.g. due to tcp session crashing */
764 if (tcon
->tidStatus
== CifsNeedReconnect
) {
769 if ((tcon
->ses
== NULL
) || (tcon
->ses
->server
== NULL
)) {
773 rc
= small_smb_init(SMB_COM_TREE_DISCONNECT
, 0, tcon
,
774 (void **)&smb_buffer
);
780 rc
= SendReceiveNoRsp(xid
, tcon
->ses
, smb_buffer
, 0);
782 cFYI(1, ("Tree disconnect failed %d", rc
));
786 /* No need to return error on this operation if tid invalidated and
787 closed on server already e.g. due to tcp session crashing */
795 CIFSSMBLogoff(const int xid
, struct cifsSesInfo
*ses
)
797 LOGOFF_ANDX_REQ
*pSMB
;
800 cFYI(1, ("In SMBLogoff for session disconnect"));
806 atomic_dec(&ses
->inUse
);
807 if (atomic_read(&ses
->inUse
) > 0) {
811 rc
= small_smb_init(SMB_COM_LOGOFF_ANDX
, 2, NULL
, (void **)&pSMB
);
818 pSMB
->hdr
.Mid
= GetNextMid(ses
->server
);
820 if (ses
->server
->secMode
&
821 (SECMODE_SIGN_REQUIRED
| SECMODE_SIGN_ENABLED
))
822 pSMB
->hdr
.Flags2
|= SMBFLG2_SECURITY_SIGNATURE
;
825 pSMB
->hdr
.Uid
= ses
->Suid
;
827 pSMB
->AndXCommand
= 0xFF;
828 rc
= SendReceiveNoRsp(xid
, ses
, (struct smb_hdr
*) pSMB
, 0);
830 atomic_dec(&ses
->server
->socketUseCount
);
831 if (atomic_read(&ses
->server
->socketUseCount
) == 0) {
832 spin_lock(&GlobalMid_Lock
);
833 ses
->server
->tcpStatus
= CifsExiting
;
834 spin_unlock(&GlobalMid_Lock
);
840 /* if session dead then we do not need to do ulogoff,
841 since server closed smb session, no sense reporting
849 CIFSPOSIXDelFile(const int xid
, struct cifsTconInfo
*tcon
, const char *fileName
,
850 __u16 type
, const struct nls_table
*nls_codepage
, int remap
)
852 TRANSACTION2_SPI_REQ
*pSMB
= NULL
;
853 TRANSACTION2_SPI_RSP
*pSMBr
= NULL
;
854 struct unlink_psx_rq
*pRqD
;
857 int bytes_returned
= 0;
858 __u16 params
, param_offset
, offset
, byte_count
;
860 cFYI(1, ("In POSIX delete"));
862 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
867 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
869 cifsConvertToUCS((__le16
*) pSMB
->FileName
, fileName
,
870 PATH_MAX
, nls_codepage
, remap
);
871 name_len
++; /* trailing null */
873 } else { /* BB add path length overrun check */
874 name_len
= strnlen(fileName
, PATH_MAX
);
875 name_len
++; /* trailing null */
876 strncpy(pSMB
->FileName
, fileName
, name_len
);
879 params
= 6 + name_len
;
880 pSMB
->MaxParameterCount
= cpu_to_le16(2);
881 pSMB
->MaxDataCount
= 0; /* BB double check this with jra */
882 pSMB
->MaxSetupCount
= 0;
887 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
888 InformationLevel
) - 4;
889 offset
= param_offset
+ params
;
891 /* Setup pointer to Request Data (inode type) */
892 pRqD
= (struct unlink_psx_rq
*)(((char *)&pSMB
->hdr
.Protocol
) + offset
);
893 pRqD
->type
= cpu_to_le16(type
);
894 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
895 pSMB
->DataOffset
= cpu_to_le16(offset
);
896 pSMB
->SetupCount
= 1;
898 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
899 byte_count
= 3 /* pad */ + params
+ sizeof(struct unlink_psx_rq
);
901 pSMB
->DataCount
= cpu_to_le16(sizeof(struct unlink_psx_rq
));
902 pSMB
->TotalDataCount
= cpu_to_le16(sizeof(struct unlink_psx_rq
));
903 pSMB
->ParameterCount
= cpu_to_le16(params
);
904 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
905 pSMB
->InformationLevel
= cpu_to_le16(SMB_POSIX_UNLINK
);
907 pSMB
->hdr
.smb_buf_length
+= byte_count
;
908 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
909 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
910 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
912 cFYI(1, ("Posix delete returned %d", rc
));
913 cifs_buf_release(pSMB
);
915 cifs_stats_inc(&tcon
->num_deletes
);
924 CIFSSMBDelFile(const int xid
, struct cifsTconInfo
*tcon
, const char *fileName
,
925 const struct nls_table
*nls_codepage
, int remap
)
927 DELETE_FILE_REQ
*pSMB
= NULL
;
928 DELETE_FILE_RSP
*pSMBr
= NULL
;
934 rc
= smb_init(SMB_COM_DELETE
, 1, tcon
, (void **) &pSMB
,
939 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
941 cifsConvertToUCS((__le16
*) pSMB
->fileName
, fileName
,
942 PATH_MAX
, nls_codepage
, remap
);
943 name_len
++; /* trailing null */
945 } else { /* BB improve check for buffer overruns BB */
946 name_len
= strnlen(fileName
, PATH_MAX
);
947 name_len
++; /* trailing null */
948 strncpy(pSMB
->fileName
, fileName
, name_len
);
950 pSMB
->SearchAttributes
=
951 cpu_to_le16(ATTR_READONLY
| ATTR_HIDDEN
| ATTR_SYSTEM
);
952 pSMB
->BufferFormat
= 0x04;
953 pSMB
->hdr
.smb_buf_length
+= name_len
+ 1;
954 pSMB
->ByteCount
= cpu_to_le16(name_len
+ 1);
955 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
956 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
957 cifs_stats_inc(&tcon
->num_deletes
);
959 cFYI(1, ("Error in RMFile = %d", rc
));
961 cifs_buf_release(pSMB
);
969 CIFSSMBRmDir(const int xid
, struct cifsTconInfo
*tcon
, const char *dirName
,
970 const struct nls_table
*nls_codepage
, int remap
)
972 DELETE_DIRECTORY_REQ
*pSMB
= NULL
;
973 DELETE_DIRECTORY_RSP
*pSMBr
= NULL
;
978 cFYI(1, ("In CIFSSMBRmDir"));
980 rc
= smb_init(SMB_COM_DELETE_DIRECTORY
, 0, tcon
, (void **) &pSMB
,
985 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
986 name_len
= cifsConvertToUCS((__le16
*) pSMB
->DirName
, dirName
,
987 PATH_MAX
, nls_codepage
, remap
);
988 name_len
++; /* trailing null */
990 } else { /* BB improve check for buffer overruns BB */
991 name_len
= strnlen(dirName
, PATH_MAX
);
992 name_len
++; /* trailing null */
993 strncpy(pSMB
->DirName
, dirName
, name_len
);
996 pSMB
->BufferFormat
= 0x04;
997 pSMB
->hdr
.smb_buf_length
+= name_len
+ 1;
998 pSMB
->ByteCount
= cpu_to_le16(name_len
+ 1);
999 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
1000 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
1001 cifs_stats_inc(&tcon
->num_rmdirs
);
1003 cFYI(1, ("Error in RMDir = %d", rc
));
1005 cifs_buf_release(pSMB
);
1012 CIFSSMBMkDir(const int xid
, struct cifsTconInfo
*tcon
,
1013 const char *name
, const struct nls_table
*nls_codepage
, int remap
)
1016 CREATE_DIRECTORY_REQ
*pSMB
= NULL
;
1017 CREATE_DIRECTORY_RSP
*pSMBr
= NULL
;
1021 cFYI(1, ("In CIFSSMBMkDir"));
1023 rc
= smb_init(SMB_COM_CREATE_DIRECTORY
, 0, tcon
, (void **) &pSMB
,
1028 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
1029 name_len
= cifsConvertToUCS((__le16
*) pSMB
->DirName
, name
,
1030 PATH_MAX
, nls_codepage
, remap
);
1031 name_len
++; /* trailing null */
1033 } else { /* BB improve check for buffer overruns BB */
1034 name_len
= strnlen(name
, PATH_MAX
);
1035 name_len
++; /* trailing null */
1036 strncpy(pSMB
->DirName
, name
, name_len
);
1039 pSMB
->BufferFormat
= 0x04;
1040 pSMB
->hdr
.smb_buf_length
+= name_len
+ 1;
1041 pSMB
->ByteCount
= cpu_to_le16(name_len
+ 1);
1042 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
1043 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
1044 cifs_stats_inc(&tcon
->num_mkdirs
);
1046 cFYI(1, ("Error in Mkdir = %d", rc
));
1048 cifs_buf_release(pSMB
);
1055 CIFSPOSIXCreate(const int xid
, struct cifsTconInfo
*tcon
, __u32 posix_flags
,
1056 __u64 mode
, __u16
*netfid
, FILE_UNIX_BASIC_INFO
*pRetData
,
1057 __u32
*pOplock
, const char *name
,
1058 const struct nls_table
*nls_codepage
, int remap
)
1060 TRANSACTION2_SPI_REQ
*pSMB
= NULL
;
1061 TRANSACTION2_SPI_RSP
*pSMBr
= NULL
;
1064 int bytes_returned
= 0;
1065 __u16 params
, param_offset
, offset
, byte_count
, count
;
1066 OPEN_PSX_REQ
*pdata
;
1067 OPEN_PSX_RSP
*psx_rsp
;
1069 cFYI(1, ("In POSIX Create"));
1071 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
1076 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
1078 cifsConvertToUCS((__le16
*) pSMB
->FileName
, name
,
1079 PATH_MAX
, nls_codepage
, remap
);
1080 name_len
++; /* trailing null */
1082 } else { /* BB improve the check for buffer overruns BB */
1083 name_len
= strnlen(name
, PATH_MAX
);
1084 name_len
++; /* trailing null */
1085 strncpy(pSMB
->FileName
, name
, name_len
);
1088 params
= 6 + name_len
;
1089 count
= sizeof(OPEN_PSX_REQ
);
1090 pSMB
->MaxParameterCount
= cpu_to_le16(2);
1091 pSMB
->MaxDataCount
= cpu_to_le16(1000); /* large enough */
1092 pSMB
->MaxSetupCount
= 0;
1096 pSMB
->Reserved2
= 0;
1097 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
1098 InformationLevel
) - 4;
1099 offset
= param_offset
+ params
;
1100 pdata
= (OPEN_PSX_REQ
*)(((char *)&pSMB
->hdr
.Protocol
) + offset
);
1101 pdata
->Level
= cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC
);
1102 pdata
->Permissions
= cpu_to_le64(mode
);
1103 pdata
->PosixOpenFlags
= cpu_to_le32(posix_flags
);
1104 pdata
->OpenFlags
= cpu_to_le32(*pOplock
);
1105 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
1106 pSMB
->DataOffset
= cpu_to_le16(offset
);
1107 pSMB
->SetupCount
= 1;
1108 pSMB
->Reserved3
= 0;
1109 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
1110 byte_count
= 3 /* pad */ + params
+ count
;
1112 pSMB
->DataCount
= cpu_to_le16(count
);
1113 pSMB
->ParameterCount
= cpu_to_le16(params
);
1114 pSMB
->TotalDataCount
= pSMB
->DataCount
;
1115 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
1116 pSMB
->InformationLevel
= cpu_to_le16(SMB_POSIX_OPEN
);
1117 pSMB
->Reserved4
= 0;
1118 pSMB
->hdr
.smb_buf_length
+= byte_count
;
1119 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
1120 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
1121 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
1123 cFYI(1, ("Posix create returned %d", rc
));
1124 goto psx_create_err
;
1127 cFYI(1, ("copying inode info"));
1128 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
1130 if (rc
|| (pSMBr
->ByteCount
< sizeof(OPEN_PSX_RSP
))) {
1131 rc
= -EIO
; /* bad smb */
1132 goto psx_create_err
;
1135 /* copy return information to pRetData */
1136 psx_rsp
= (OPEN_PSX_RSP
*)((char *) &pSMBr
->hdr
.Protocol
1137 + le16_to_cpu(pSMBr
->t2
.DataOffset
));
1139 *pOplock
= le16_to_cpu(psx_rsp
->OplockFlags
);
1141 *netfid
= psx_rsp
->Fid
; /* cifs fid stays in le */
1142 /* Let caller know file was created so we can set the mode. */
1143 /* Do we care about the CreateAction in any other cases? */
1144 if (cpu_to_le32(FILE_CREATE
) == psx_rsp
->CreateAction
)
1145 *pOplock
|= CIFS_CREATE_ACTION
;
1146 /* check to make sure response data is there */
1147 if (psx_rsp
->ReturnedLevel
!= cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC
)) {
1148 pRetData
->Type
= cpu_to_le32(-1); /* unknown */
1149 cFYI(DBG2
, ("unknown type"));
1151 if (pSMBr
->ByteCount
< sizeof(OPEN_PSX_RSP
)
1152 + sizeof(FILE_UNIX_BASIC_INFO
)) {
1153 cERROR(1, ("Open response data too small"));
1154 pRetData
->Type
= cpu_to_le32(-1);
1155 goto psx_create_err
;
1157 memcpy((char *) pRetData
,
1158 (char *)psx_rsp
+ sizeof(OPEN_PSX_RSP
),
1159 sizeof(FILE_UNIX_BASIC_INFO
));
1163 cifs_buf_release(pSMB
);
1165 cifs_stats_inc(&tcon
->num_mkdirs
);
1173 static __u16
convert_disposition(int disposition
)
1177 switch (disposition
) {
1178 case FILE_SUPERSEDE
:
1179 ofun
= SMBOPEN_OCREATE
| SMBOPEN_OTRUNC
;
1182 ofun
= SMBOPEN_OAPPEND
;
1185 ofun
= SMBOPEN_OCREATE
;
1188 ofun
= SMBOPEN_OCREATE
| SMBOPEN_OAPPEND
;
1190 case FILE_OVERWRITE
:
1191 ofun
= SMBOPEN_OTRUNC
;
1193 case FILE_OVERWRITE_IF
:
1194 ofun
= SMBOPEN_OCREATE
| SMBOPEN_OTRUNC
;
1197 cFYI(1, ("unknown disposition %d", disposition
));
1198 ofun
= SMBOPEN_OAPPEND
; /* regular open */
1204 access_flags_to_smbopen_mode(const int access_flags
)
1206 int masked_flags
= access_flags
& (GENERIC_READ
| GENERIC_WRITE
);
1208 if (masked_flags
== GENERIC_READ
)
1209 return SMBOPEN_READ
;
1210 else if (masked_flags
== GENERIC_WRITE
)
1211 return SMBOPEN_WRITE
;
1213 /* just go for read/write */
1214 return SMBOPEN_READWRITE
;
1218 SMBLegacyOpen(const int xid
, struct cifsTconInfo
*tcon
,
1219 const char *fileName
, const int openDisposition
,
1220 const int access_flags
, const int create_options
, __u16
*netfid
,
1221 int *pOplock
, FILE_ALL_INFO
*pfile_info
,
1222 const struct nls_table
*nls_codepage
, int remap
)
1225 OPENX_REQ
*pSMB
= NULL
;
1226 OPENX_RSP
*pSMBr
= NULL
;
1232 rc
= smb_init(SMB_COM_OPEN_ANDX
, 15, tcon
, (void **) &pSMB
,
1237 pSMB
->AndXCommand
= 0xFF; /* none */
1239 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
1240 count
= 1; /* account for one byte pad to word boundary */
1242 cifsConvertToUCS((__le16
*) (pSMB
->fileName
+ 1),
1243 fileName
, PATH_MAX
, nls_codepage
, remap
);
1244 name_len
++; /* trailing null */
1246 } else { /* BB improve check for buffer overruns BB */
1247 count
= 0; /* no pad */
1248 name_len
= strnlen(fileName
, PATH_MAX
);
1249 name_len
++; /* trailing null */
1250 strncpy(pSMB
->fileName
, fileName
, name_len
);
1252 if (*pOplock
& REQ_OPLOCK
)
1253 pSMB
->OpenFlags
= cpu_to_le16(REQ_OPLOCK
);
1254 else if (*pOplock
& REQ_BATCHOPLOCK
)
1255 pSMB
->OpenFlags
= cpu_to_le16(REQ_BATCHOPLOCK
);
1257 pSMB
->OpenFlags
|= cpu_to_le16(REQ_MORE_INFO
);
1258 pSMB
->Mode
= cpu_to_le16(access_flags_to_smbopen_mode(access_flags
));
1259 pSMB
->Mode
|= cpu_to_le16(0x40); /* deny none */
1260 /* set file as system file if special file such
1261 as fifo and server expecting SFU style and
1262 no Unix extensions */
1264 if (create_options
& CREATE_OPTION_SPECIAL
)
1265 pSMB
->FileAttributes
= cpu_to_le16(ATTR_SYSTEM
);
1266 else /* BB FIXME BB */
1267 pSMB
->FileAttributes
= cpu_to_le16(0/*ATTR_NORMAL*/);
1269 if (create_options
& CREATE_OPTION_READONLY
)
1270 pSMB
->FileAttributes
|= cpu_to_le16(ATTR_READONLY
);
1273 /* pSMB->CreateOptions = cpu_to_le32(create_options &
1274 CREATE_OPTIONS_MASK); */
1275 /* BB FIXME END BB */
1277 pSMB
->Sattr
= cpu_to_le16(ATTR_HIDDEN
| ATTR_SYSTEM
| ATTR_DIRECTORY
);
1278 pSMB
->OpenFunction
= cpu_to_le16(convert_disposition(openDisposition
));
1280 pSMB
->hdr
.smb_buf_length
+= count
;
1282 pSMB
->ByteCount
= cpu_to_le16(count
);
1283 /* long_op set to 1 to allow for oplock break timeouts */
1284 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
1285 (struct smb_hdr
*)pSMBr
, &bytes_returned
, CIFS_LONG_OP
);
1286 cifs_stats_inc(&tcon
->num_opens
);
1288 cFYI(1, ("Error in Open = %d", rc
));
1290 /* BB verify if wct == 15 */
1292 /* *pOplock = pSMBr->OplockLevel; */ /* BB take from action field*/
1294 *netfid
= pSMBr
->Fid
; /* cifs fid stays in le */
1295 /* Let caller know file was created so we can set the mode. */
1296 /* Do we care about the CreateAction in any other cases? */
1298 /* if (cpu_to_le32(FILE_CREATE) == pSMBr->CreateAction)
1299 *pOplock |= CIFS_CREATE_ACTION; */
1303 pfile_info
->CreationTime
= 0; /* BB convert CreateTime*/
1304 pfile_info
->LastAccessTime
= 0; /* BB fixme */
1305 pfile_info
->LastWriteTime
= 0; /* BB fixme */
1306 pfile_info
->ChangeTime
= 0; /* BB fixme */
1307 pfile_info
->Attributes
=
1308 cpu_to_le32(le16_to_cpu(pSMBr
->FileAttributes
));
1309 /* the file_info buf is endian converted by caller */
1310 pfile_info
->AllocationSize
=
1311 cpu_to_le64(le32_to_cpu(pSMBr
->EndOfFile
));
1312 pfile_info
->EndOfFile
= pfile_info
->AllocationSize
;
1313 pfile_info
->NumberOfLinks
= cpu_to_le32(1);
1317 cifs_buf_release(pSMB
);
1324 CIFSSMBOpen(const int xid
, struct cifsTconInfo
*tcon
,
1325 const char *fileName
, const int openDisposition
,
1326 const int access_flags
, const int create_options
, __u16
*netfid
,
1327 int *pOplock
, FILE_ALL_INFO
*pfile_info
,
1328 const struct nls_table
*nls_codepage
, int remap
)
1331 OPEN_REQ
*pSMB
= NULL
;
1332 OPEN_RSP
*pSMBr
= NULL
;
1338 rc
= smb_init(SMB_COM_NT_CREATE_ANDX
, 24, tcon
, (void **) &pSMB
,
1343 pSMB
->AndXCommand
= 0xFF; /* none */
1345 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
1346 count
= 1; /* account for one byte pad to word boundary */
1348 cifsConvertToUCS((__le16
*) (pSMB
->fileName
+ 1),
1349 fileName
, PATH_MAX
, nls_codepage
, remap
);
1350 name_len
++; /* trailing null */
1352 pSMB
->NameLength
= cpu_to_le16(name_len
);
1353 } else { /* BB improve check for buffer overruns BB */
1354 count
= 0; /* no pad */
1355 name_len
= strnlen(fileName
, PATH_MAX
);
1356 name_len
++; /* trailing null */
1357 pSMB
->NameLength
= cpu_to_le16(name_len
);
1358 strncpy(pSMB
->fileName
, fileName
, name_len
);
1360 if (*pOplock
& REQ_OPLOCK
)
1361 pSMB
->OpenFlags
= cpu_to_le32(REQ_OPLOCK
);
1362 else if (*pOplock
& REQ_BATCHOPLOCK
)
1363 pSMB
->OpenFlags
= cpu_to_le32(REQ_BATCHOPLOCK
);
1364 pSMB
->DesiredAccess
= cpu_to_le32(access_flags
);
1365 pSMB
->AllocationSize
= 0;
1366 /* set file as system file if special file such
1367 as fifo and server expecting SFU style and
1368 no Unix extensions */
1369 if (create_options
& CREATE_OPTION_SPECIAL
)
1370 pSMB
->FileAttributes
= cpu_to_le32(ATTR_SYSTEM
);
1372 pSMB
->FileAttributes
= cpu_to_le32(ATTR_NORMAL
);
1374 /* XP does not handle ATTR_POSIX_SEMANTICS */
1375 /* but it helps speed up case sensitive checks for other
1376 servers such as Samba */
1377 if (tcon
->ses
->capabilities
& CAP_UNIX
)
1378 pSMB
->FileAttributes
|= cpu_to_le32(ATTR_POSIX_SEMANTICS
);
1380 if (create_options
& CREATE_OPTION_READONLY
)
1381 pSMB
->FileAttributes
|= cpu_to_le32(ATTR_READONLY
);
1383 pSMB
->ShareAccess
= cpu_to_le32(FILE_SHARE_ALL
);
1384 pSMB
->CreateDisposition
= cpu_to_le32(openDisposition
);
1385 pSMB
->CreateOptions
= cpu_to_le32(create_options
& CREATE_OPTIONS_MASK
);
1386 /* BB Expirement with various impersonation levels and verify */
1387 pSMB
->ImpersonationLevel
= cpu_to_le32(SECURITY_IMPERSONATION
);
1388 pSMB
->SecurityFlags
=
1389 SECURITY_CONTEXT_TRACKING
| SECURITY_EFFECTIVE_ONLY
;
1392 pSMB
->hdr
.smb_buf_length
+= count
;
1394 pSMB
->ByteCount
= cpu_to_le16(count
);
1395 /* long_op set to 1 to allow for oplock break timeouts */
1396 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
1397 (struct smb_hdr
*)pSMBr
, &bytes_returned
, CIFS_LONG_OP
);
1398 cifs_stats_inc(&tcon
->num_opens
);
1400 cFYI(1, ("Error in Open = %d", rc
));
1402 *pOplock
= pSMBr
->OplockLevel
; /* 1 byte no need to le_to_cpu */
1403 *netfid
= pSMBr
->Fid
; /* cifs fid stays in le */
1404 /* Let caller know file was created so we can set the mode. */
1405 /* Do we care about the CreateAction in any other cases? */
1406 if (cpu_to_le32(FILE_CREATE
) == pSMBr
->CreateAction
)
1407 *pOplock
|= CIFS_CREATE_ACTION
;
1409 memcpy((char *)pfile_info
, (char *)&pSMBr
->CreationTime
,
1410 36 /* CreationTime to Attributes */);
1411 /* the file_info buf is endian converted by caller */
1412 pfile_info
->AllocationSize
= pSMBr
->AllocationSize
;
1413 pfile_info
->EndOfFile
= pSMBr
->EndOfFile
;
1414 pfile_info
->NumberOfLinks
= cpu_to_le32(1);
1418 cifs_buf_release(pSMB
);
1425 CIFSSMBRead(const int xid
, struct cifsTconInfo
*tcon
, const int netfid
,
1426 const unsigned int count
, const __u64 lseek
, unsigned int *nbytes
,
1427 char **buf
, int *pbuf_type
)
1430 READ_REQ
*pSMB
= NULL
;
1431 READ_RSP
*pSMBr
= NULL
;
1432 char *pReadData
= NULL
;
1434 int resp_buf_type
= 0;
1437 cFYI(1, ("Reading %d bytes on fid %d", count
, netfid
));
1438 if (tcon
->ses
->capabilities
& CAP_LARGE_FILES
)
1441 wct
= 10; /* old style read */
1444 rc
= small_smb_init(SMB_COM_READ_ANDX
, wct
, tcon
, (void **) &pSMB
);
1448 /* tcon and ses pointer are checked in smb_init */
1449 if (tcon
->ses
->server
== NULL
)
1450 return -ECONNABORTED
;
1452 pSMB
->AndXCommand
= 0xFF; /* none */
1454 pSMB
->OffsetLow
= cpu_to_le32(lseek
& 0xFFFFFFFF);
1456 pSMB
->OffsetHigh
= cpu_to_le32(lseek
>> 32);
1457 else if ((lseek
>> 32) > 0) /* can not handle this big offset for old */
1460 pSMB
->Remaining
= 0;
1461 pSMB
->MaxCount
= cpu_to_le16(count
& 0xFFFF);
1462 pSMB
->MaxCountHigh
= cpu_to_le32(count
>> 16);
1464 pSMB
->ByteCount
= 0; /* no need to do le conversion since 0 */
1466 /* old style read */
1467 struct smb_com_readx_req
*pSMBW
=
1468 (struct smb_com_readx_req
*)pSMB
;
1469 pSMBW
->ByteCount
= 0;
1472 iov
[0].iov_base
= (char *)pSMB
;
1473 iov
[0].iov_len
= pSMB
->hdr
.smb_buf_length
+ 4;
1474 rc
= SendReceive2(xid
, tcon
->ses
, iov
, 1 /* num iovecs */,
1475 &resp_buf_type
, CIFS_STD_OP
| CIFS_LOG_ERROR
);
1476 cifs_stats_inc(&tcon
->num_reads
);
1477 pSMBr
= (READ_RSP
*)iov
[0].iov_base
;
1479 cERROR(1, ("Send error in read = %d", rc
));
1481 int data_length
= le16_to_cpu(pSMBr
->DataLengthHigh
);
1482 data_length
= data_length
<< 16;
1483 data_length
+= le16_to_cpu(pSMBr
->DataLength
);
1484 *nbytes
= data_length
;
1486 /*check that DataLength would not go beyond end of SMB */
1487 if ((data_length
> CIFSMaxBufSize
)
1488 || (data_length
> count
)) {
1489 cFYI(1, ("bad length %d for count %d",
1490 data_length
, count
));
1494 pReadData
= (char *) (&pSMBr
->hdr
.Protocol
) +
1495 le16_to_cpu(pSMBr
->DataOffset
);
1496 /* if (rc = copy_to_user(buf, pReadData, data_length)) {
1497 cERROR(1,("Faulting on read rc = %d",rc));
1499 }*/ /* can not use copy_to_user when using page cache*/
1501 memcpy(*buf
, pReadData
, data_length
);
1505 /* cifs_small_buf_release(pSMB); */ /* Freed earlier now in SendReceive2 */
1507 if (resp_buf_type
== CIFS_SMALL_BUFFER
)
1508 cifs_small_buf_release(iov
[0].iov_base
);
1509 else if (resp_buf_type
== CIFS_LARGE_BUFFER
)
1510 cifs_buf_release(iov
[0].iov_base
);
1511 } else if (resp_buf_type
!= CIFS_NO_BUFFER
) {
1512 /* return buffer to caller to free */
1513 *buf
= iov
[0].iov_base
;
1514 if (resp_buf_type
== CIFS_SMALL_BUFFER
)
1515 *pbuf_type
= CIFS_SMALL_BUFFER
;
1516 else if (resp_buf_type
== CIFS_LARGE_BUFFER
)
1517 *pbuf_type
= CIFS_LARGE_BUFFER
;
1518 } /* else no valid buffer on return - leave as null */
1520 /* Note: On -EAGAIN error only caller can retry on handle based calls
1521 since file handle passed in no longer valid */
1527 CIFSSMBWrite(const int xid
, struct cifsTconInfo
*tcon
,
1528 const int netfid
, const unsigned int count
,
1529 const __u64 offset
, unsigned int *nbytes
, const char *buf
,
1530 const char __user
*ubuf
, const int long_op
)
1533 WRITE_REQ
*pSMB
= NULL
;
1534 WRITE_RSP
*pSMBr
= NULL
;
1535 int bytes_returned
, wct
;
1539 /* cFYI(1,("write at %lld %d bytes",offset,count));*/
1540 if (tcon
->ses
== NULL
)
1541 return -ECONNABORTED
;
1543 if (tcon
->ses
->capabilities
& CAP_LARGE_FILES
)
1548 rc
= smb_init(SMB_COM_WRITE_ANDX
, wct
, tcon
, (void **) &pSMB
,
1552 /* tcon and ses pointer are checked in smb_init */
1553 if (tcon
->ses
->server
== NULL
)
1554 return -ECONNABORTED
;
1556 pSMB
->AndXCommand
= 0xFF; /* none */
1558 pSMB
->OffsetLow
= cpu_to_le32(offset
& 0xFFFFFFFF);
1560 pSMB
->OffsetHigh
= cpu_to_le32(offset
>> 32);
1561 else if ((offset
>> 32) > 0) /* can not handle big offset for old srv */
1564 pSMB
->Reserved
= 0xFFFFFFFF;
1565 pSMB
->WriteMode
= 0;
1566 pSMB
->Remaining
= 0;
1568 /* Can increase buffer size if buffer is big enough in some cases ie we
1569 can send more if LARGE_WRITE_X capability returned by the server and if
1570 our buffer is big enough or if we convert to iovecs on socket writes
1571 and eliminate the copy to the CIFS buffer */
1572 if (tcon
->ses
->capabilities
& CAP_LARGE_WRITE_X
) {
1573 bytes_sent
= min_t(const unsigned int, CIFSMaxBufSize
, count
);
1575 bytes_sent
= (tcon
->ses
->server
->maxBuf
- MAX_CIFS_HDR_SIZE
)
1579 if (bytes_sent
> count
)
1582 cpu_to_le16(offsetof(struct smb_com_write_req
, Data
) - 4);
1584 memcpy(pSMB
->Data
, buf
, bytes_sent
);
1586 if (copy_from_user(pSMB
->Data
, ubuf
, bytes_sent
)) {
1587 cifs_buf_release(pSMB
);
1590 } else if (count
!= 0) {
1592 cifs_buf_release(pSMB
);
1594 } /* else setting file size with write of zero bytes */
1596 byte_count
= bytes_sent
+ 1; /* pad */
1597 else /* wct == 12 */
1598 byte_count
= bytes_sent
+ 5; /* bigger pad, smaller smb hdr */
1600 pSMB
->DataLengthLow
= cpu_to_le16(bytes_sent
& 0xFFFF);
1601 pSMB
->DataLengthHigh
= cpu_to_le16(bytes_sent
>> 16);
1602 pSMB
->hdr
.smb_buf_length
+= byte_count
;
1605 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
1606 else { /* old style write has byte count 4 bytes earlier
1608 struct smb_com_writex_req
*pSMBW
=
1609 (struct smb_com_writex_req
*)pSMB
;
1610 pSMBW
->ByteCount
= cpu_to_le16(byte_count
);
1613 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
1614 (struct smb_hdr
*) pSMBr
, &bytes_returned
, long_op
);
1615 cifs_stats_inc(&tcon
->num_writes
);
1617 cFYI(1, ("Send error in write = %d", rc
));
1620 *nbytes
= le16_to_cpu(pSMBr
->CountHigh
);
1621 *nbytes
= (*nbytes
) << 16;
1622 *nbytes
+= le16_to_cpu(pSMBr
->Count
);
1625 cifs_buf_release(pSMB
);
1627 /* Note: On -EAGAIN error only caller can retry on handle based calls
1628 since file handle passed in no longer valid */
1634 CIFSSMBWrite2(const int xid
, struct cifsTconInfo
*tcon
,
1635 const int netfid
, const unsigned int count
,
1636 const __u64 offset
, unsigned int *nbytes
, struct kvec
*iov
,
1637 int n_vec
, const int long_op
)
1640 WRITE_REQ
*pSMB
= NULL
;
1643 int resp_buf_type
= 0;
1645 cFYI(1, ("write2 at %lld %d bytes", (long long)offset
, count
));
1647 if (tcon
->ses
->capabilities
& CAP_LARGE_FILES
)
1651 rc
= small_smb_init(SMB_COM_WRITE_ANDX
, wct
, tcon
, (void **) &pSMB
);
1654 /* tcon and ses pointer are checked in smb_init */
1655 if (tcon
->ses
->server
== NULL
)
1656 return -ECONNABORTED
;
1658 pSMB
->AndXCommand
= 0xFF; /* none */
1660 pSMB
->OffsetLow
= cpu_to_le32(offset
& 0xFFFFFFFF);
1662 pSMB
->OffsetHigh
= cpu_to_le32(offset
>> 32);
1663 else if ((offset
>> 32) > 0) /* can not handle big offset for old srv */
1665 pSMB
->Reserved
= 0xFFFFFFFF;
1666 pSMB
->WriteMode
= 0;
1667 pSMB
->Remaining
= 0;
1670 cpu_to_le16(offsetof(struct smb_com_write_req
, Data
) - 4);
1672 pSMB
->DataLengthLow
= cpu_to_le16(count
& 0xFFFF);
1673 pSMB
->DataLengthHigh
= cpu_to_le16(count
>> 16);
1674 smb_hdr_len
= pSMB
->hdr
.smb_buf_length
+ 1; /* hdr + 1 byte pad */
1676 pSMB
->hdr
.smb_buf_length
+= count
+1;
1677 else /* wct == 12 */
1678 pSMB
->hdr
.smb_buf_length
+= count
+5; /* smb data starts later */
1680 pSMB
->ByteCount
= cpu_to_le16(count
+ 1);
1681 else /* wct == 12 */ /* bigger pad, smaller smb hdr, keep offset ok */ {
1682 struct smb_com_writex_req
*pSMBW
=
1683 (struct smb_com_writex_req
*)pSMB
;
1684 pSMBW
->ByteCount
= cpu_to_le16(count
+ 5);
1686 iov
[0].iov_base
= pSMB
;
1688 iov
[0].iov_len
= smb_hdr_len
+ 4;
1689 else /* wct == 12 pad bigger by four bytes */
1690 iov
[0].iov_len
= smb_hdr_len
+ 8;
1693 rc
= SendReceive2(xid
, tcon
->ses
, iov
, n_vec
+ 1, &resp_buf_type
,
1695 cifs_stats_inc(&tcon
->num_writes
);
1697 cFYI(1, ("Send error Write2 = %d", rc
));
1699 } else if (resp_buf_type
== 0) {
1700 /* presumably this can not happen, but best to be safe */
1704 WRITE_RSP
*pSMBr
= (WRITE_RSP
*)iov
[0].iov_base
;
1705 *nbytes
= le16_to_cpu(pSMBr
->CountHigh
);
1706 *nbytes
= (*nbytes
) << 16;
1707 *nbytes
+= le16_to_cpu(pSMBr
->Count
);
1710 /* cifs_small_buf_release(pSMB); */ /* Freed earlier now in SendReceive2 */
1711 if (resp_buf_type
== CIFS_SMALL_BUFFER
)
1712 cifs_small_buf_release(iov
[0].iov_base
);
1713 else if (resp_buf_type
== CIFS_LARGE_BUFFER
)
1714 cifs_buf_release(iov
[0].iov_base
);
1716 /* Note: On -EAGAIN error only caller can retry on handle based calls
1717 since file handle passed in no longer valid */
1724 CIFSSMBLock(const int xid
, struct cifsTconInfo
*tcon
,
1725 const __u16 smb_file_id
, const __u64 len
,
1726 const __u64 offset
, const __u32 numUnlock
,
1727 const __u32 numLock
, const __u8 lockType
, const bool waitFlag
)
1730 LOCK_REQ
*pSMB
= NULL
;
1731 /* LOCK_RSP *pSMBr = NULL; */ /* No response data other than rc to parse */
1736 cFYI(1, ("CIFSSMBLock timeout %d numLock %d", (int)waitFlag
, numLock
));
1737 rc
= small_smb_init(SMB_COM_LOCKING_ANDX
, 8, tcon
, (void **) &pSMB
);
1742 if (lockType
== LOCKING_ANDX_OPLOCK_RELEASE
) {
1743 timeout
= CIFS_ASYNC_OP
; /* no response expected */
1745 } else if (waitFlag
) {
1746 timeout
= CIFS_BLOCKING_OP
; /* blocking operation, no timeout */
1747 pSMB
->Timeout
= cpu_to_le32(-1);/* blocking - do not time out */
1752 pSMB
->NumberOfLocks
= cpu_to_le16(numLock
);
1753 pSMB
->NumberOfUnlocks
= cpu_to_le16(numUnlock
);
1754 pSMB
->LockType
= lockType
;
1755 pSMB
->AndXCommand
= 0xFF; /* none */
1756 pSMB
->Fid
= smb_file_id
; /* netfid stays le */
1758 if ((numLock
!= 0) || (numUnlock
!= 0)) {
1759 pSMB
->Locks
[0].Pid
= cpu_to_le16(current
->tgid
);
1760 /* BB where to store pid high? */
1761 pSMB
->Locks
[0].LengthLow
= cpu_to_le32((u32
)len
);
1762 pSMB
->Locks
[0].LengthHigh
= cpu_to_le32((u32
)(len
>>32));
1763 pSMB
->Locks
[0].OffsetLow
= cpu_to_le32((u32
)offset
);
1764 pSMB
->Locks
[0].OffsetHigh
= cpu_to_le32((u32
)(offset
>>32));
1765 count
= sizeof(LOCKING_ANDX_RANGE
);
1770 pSMB
->hdr
.smb_buf_length
+= count
;
1771 pSMB
->ByteCount
= cpu_to_le16(count
);
1774 rc
= SendReceiveBlockingLock(xid
, tcon
, (struct smb_hdr
*) pSMB
,
1775 (struct smb_hdr
*) pSMB
, &bytes_returned
);
1776 cifs_small_buf_release(pSMB
);
1778 rc
= SendReceiveNoRsp(xid
, tcon
->ses
, (struct smb_hdr
*)pSMB
,
1780 /* SMB buffer freed by function above */
1782 cifs_stats_inc(&tcon
->num_locks
);
1784 cFYI(1, ("Send error in Lock = %d", rc
));
1786 /* Note: On -EAGAIN error only caller can retry on handle based calls
1787 since file handle passed in no longer valid */
1792 CIFSSMBPosixLock(const int xid
, struct cifsTconInfo
*tcon
,
1793 const __u16 smb_file_id
, const int get_flag
, const __u64 len
,
1794 struct file_lock
*pLockData
, const __u16 lock_type
,
1795 const bool waitFlag
)
1797 struct smb_com_transaction2_sfi_req
*pSMB
= NULL
;
1798 struct smb_com_transaction2_sfi_rsp
*pSMBr
= NULL
;
1799 struct cifs_posix_lock
*parm_data
;
1802 int bytes_returned
= 0;
1803 int resp_buf_type
= 0;
1804 __u16 params
, param_offset
, offset
, byte_count
, count
;
1807 cFYI(1, ("Posix Lock"));
1809 if (pLockData
== NULL
)
1812 rc
= small_smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
);
1817 pSMBr
= (struct smb_com_transaction2_sfi_rsp
*)pSMB
;
1820 pSMB
->MaxSetupCount
= 0;
1823 pSMB
->Reserved2
= 0;
1824 param_offset
= offsetof(struct smb_com_transaction2_sfi_req
, Fid
) - 4;
1825 offset
= param_offset
+ params
;
1827 count
= sizeof(struct cifs_posix_lock
);
1828 pSMB
->MaxParameterCount
= cpu_to_le16(2);
1829 pSMB
->MaxDataCount
= cpu_to_le16(1000); /* BB find max SMB from sess */
1830 pSMB
->SetupCount
= 1;
1831 pSMB
->Reserved3
= 0;
1833 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION
);
1835 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_FILE_INFORMATION
);
1836 byte_count
= 3 /* pad */ + params
+ count
;
1837 pSMB
->DataCount
= cpu_to_le16(count
);
1838 pSMB
->ParameterCount
= cpu_to_le16(params
);
1839 pSMB
->TotalDataCount
= pSMB
->DataCount
;
1840 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
1841 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
1842 parm_data
= (struct cifs_posix_lock
*)
1843 (((char *) &pSMB
->hdr
.Protocol
) + offset
);
1845 parm_data
->lock_type
= cpu_to_le16(lock_type
);
1847 timeout
= CIFS_BLOCKING_OP
; /* blocking operation, no timeout */
1848 parm_data
->lock_flags
= cpu_to_le16(1);
1849 pSMB
->Timeout
= cpu_to_le32(-1);
1853 parm_data
->pid
= cpu_to_le32(current
->tgid
);
1854 parm_data
->start
= cpu_to_le64(pLockData
->fl_start
);
1855 parm_data
->length
= cpu_to_le64(len
); /* normalize negative numbers */
1857 pSMB
->DataOffset
= cpu_to_le16(offset
);
1858 pSMB
->Fid
= smb_file_id
;
1859 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_POSIX_LOCK
);
1860 pSMB
->Reserved4
= 0;
1861 pSMB
->hdr
.smb_buf_length
+= byte_count
;
1862 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
1864 rc
= SendReceiveBlockingLock(xid
, tcon
, (struct smb_hdr
*) pSMB
,
1865 (struct smb_hdr
*) pSMBr
, &bytes_returned
);
1867 iov
[0].iov_base
= (char *)pSMB
;
1868 iov
[0].iov_len
= pSMB
->hdr
.smb_buf_length
+ 4;
1869 rc
= SendReceive2(xid
, tcon
->ses
, iov
, 1 /* num iovecs */,
1870 &resp_buf_type
, timeout
);
1871 pSMB
= NULL
; /* request buf already freed by SendReceive2. Do
1872 not try to free it twice below on exit */
1873 pSMBr
= (struct smb_com_transaction2_sfi_rsp
*)iov
[0].iov_base
;
1877 cFYI(1, ("Send error in Posix Lock = %d", rc
));
1878 } else if (get_flag
) {
1879 /* lock structure can be returned on get */
1882 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
1884 if (rc
|| (pSMBr
->ByteCount
< sizeof(struct cifs_posix_lock
))) {
1885 rc
= -EIO
; /* bad smb */
1888 if (pLockData
== NULL
) {
1892 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
1893 data_count
= le16_to_cpu(pSMBr
->t2
.DataCount
);
1894 if (data_count
< sizeof(struct cifs_posix_lock
)) {
1898 parm_data
= (struct cifs_posix_lock
*)
1899 ((char *)&pSMBr
->hdr
.Protocol
+ data_offset
);
1900 if (parm_data
->lock_type
== cpu_to_le16(CIFS_UNLCK
))
1901 pLockData
->fl_type
= F_UNLCK
;
1906 cifs_small_buf_release(pSMB
);
1908 if (resp_buf_type
== CIFS_SMALL_BUFFER
)
1909 cifs_small_buf_release(iov
[0].iov_base
);
1910 else if (resp_buf_type
== CIFS_LARGE_BUFFER
)
1911 cifs_buf_release(iov
[0].iov_base
);
1913 /* Note: On -EAGAIN error only caller can retry on handle based calls
1914 since file handle passed in no longer valid */
1921 CIFSSMBClose(const int xid
, struct cifsTconInfo
*tcon
, int smb_file_id
)
1924 CLOSE_REQ
*pSMB
= NULL
;
1925 cFYI(1, ("In CIFSSMBClose"));
1927 /* do not retry on dead session on close */
1928 rc
= small_smb_init(SMB_COM_CLOSE
, 3, tcon
, (void **) &pSMB
);
1934 pSMB
->FileID
= (__u16
) smb_file_id
;
1935 pSMB
->LastWriteTime
= 0xFFFFFFFF;
1936 pSMB
->ByteCount
= 0;
1937 rc
= SendReceiveNoRsp(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
, 0);
1938 cifs_stats_inc(&tcon
->num_closes
);
1941 /* EINTR is expected when user ctl-c to kill app */
1942 cERROR(1, ("Send error in Close = %d", rc
));
1946 /* Since session is dead, file will be closed on server already */
1954 CIFSSMBRename(const int xid
, struct cifsTconInfo
*tcon
,
1955 const char *fromName
, const char *toName
,
1956 const struct nls_table
*nls_codepage
, int remap
)
1959 RENAME_REQ
*pSMB
= NULL
;
1960 RENAME_RSP
*pSMBr
= NULL
;
1962 int name_len
, name_len2
;
1965 cFYI(1, ("In CIFSSMBRename"));
1967 rc
= smb_init(SMB_COM_RENAME
, 1, tcon
, (void **) &pSMB
,
1972 pSMB
->BufferFormat
= 0x04;
1973 pSMB
->SearchAttributes
=
1974 cpu_to_le16(ATTR_READONLY
| ATTR_HIDDEN
| ATTR_SYSTEM
|
1977 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
1979 cifsConvertToUCS((__le16
*) pSMB
->OldFileName
, fromName
,
1980 PATH_MAX
, nls_codepage
, remap
);
1981 name_len
++; /* trailing null */
1983 pSMB
->OldFileName
[name_len
] = 0x04; /* pad */
1984 /* protocol requires ASCII signature byte on Unicode string */
1985 pSMB
->OldFileName
[name_len
+ 1] = 0x00;
1987 cifsConvertToUCS((__le16
*)&pSMB
->OldFileName
[name_len
+ 2],
1988 toName
, PATH_MAX
, nls_codepage
, remap
);
1989 name_len2
+= 1 /* trailing null */ + 1 /* Signature word */ ;
1990 name_len2
*= 2; /* convert to bytes */
1991 } else { /* BB improve the check for buffer overruns BB */
1992 name_len
= strnlen(fromName
, PATH_MAX
);
1993 name_len
++; /* trailing null */
1994 strncpy(pSMB
->OldFileName
, fromName
, name_len
);
1995 name_len2
= strnlen(toName
, PATH_MAX
);
1996 name_len2
++; /* trailing null */
1997 pSMB
->OldFileName
[name_len
] = 0x04; /* 2nd buffer format */
1998 strncpy(&pSMB
->OldFileName
[name_len
+ 1], toName
, name_len2
);
1999 name_len2
++; /* trailing null */
2000 name_len2
++; /* signature byte */
2003 count
= 1 /* 1st signature byte */ + name_len
+ name_len2
;
2004 pSMB
->hdr
.smb_buf_length
+= count
;
2005 pSMB
->ByteCount
= cpu_to_le16(count
);
2007 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
2008 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
2009 cifs_stats_inc(&tcon
->num_renames
);
2011 cFYI(1, ("Send error in rename = %d", rc
));
2013 cifs_buf_release(pSMB
);
2021 int CIFSSMBRenameOpenFile(const int xid
, struct cifsTconInfo
*pTcon
,
2022 int netfid
, char *target_name
,
2023 const struct nls_table
*nls_codepage
, int remap
)
2025 struct smb_com_transaction2_sfi_req
*pSMB
= NULL
;
2026 struct smb_com_transaction2_sfi_rsp
*pSMBr
= NULL
;
2027 struct set_file_rename
*rename_info
;
2029 char dummy_string
[30];
2031 int bytes_returned
= 0;
2033 __u16 params
, param_offset
, offset
, count
, byte_count
;
2035 cFYI(1, ("Rename to File by handle"));
2036 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, pTcon
, (void **) &pSMB
,
2042 pSMB
->MaxSetupCount
= 0;
2046 pSMB
->Reserved2
= 0;
2047 param_offset
= offsetof(struct smb_com_transaction2_sfi_req
, Fid
) - 4;
2048 offset
= param_offset
+ params
;
2050 data_offset
= (char *) (&pSMB
->hdr
.Protocol
) + offset
;
2051 rename_info
= (struct set_file_rename
*) data_offset
;
2052 pSMB
->MaxParameterCount
= cpu_to_le16(2);
2053 pSMB
->MaxDataCount
= cpu_to_le16(1000); /* BB find max SMB from sess */
2054 pSMB
->SetupCount
= 1;
2055 pSMB
->Reserved3
= 0;
2056 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_FILE_INFORMATION
);
2057 byte_count
= 3 /* pad */ + params
;
2058 pSMB
->ParameterCount
= cpu_to_le16(params
);
2059 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
2060 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
2061 pSMB
->DataOffset
= cpu_to_le16(offset
);
2062 /* construct random name ".cifs_tmp<inodenum><mid>" */
2063 rename_info
->overwrite
= cpu_to_le32(1);
2064 rename_info
->root_fid
= 0;
2065 /* unicode only call */
2066 if (target_name
== NULL
) {
2067 sprintf(dummy_string
, "cifs%x", pSMB
->hdr
.Mid
);
2068 len_of_str
= cifsConvertToUCS((__le16
*)rename_info
->target_name
,
2069 dummy_string
, 24, nls_codepage
, remap
);
2071 len_of_str
= cifsConvertToUCS((__le16
*)rename_info
->target_name
,
2072 target_name
, PATH_MAX
, nls_codepage
,
2075 rename_info
->target_name_len
= cpu_to_le32(2 * len_of_str
);
2076 count
= 12 /* sizeof(struct set_file_rename) */ + (2 * len_of_str
) + 2;
2077 byte_count
+= count
;
2078 pSMB
->DataCount
= cpu_to_le16(count
);
2079 pSMB
->TotalDataCount
= pSMB
->DataCount
;
2081 pSMB
->InformationLevel
=
2082 cpu_to_le16(SMB_SET_FILE_RENAME_INFORMATION
);
2083 pSMB
->Reserved4
= 0;
2084 pSMB
->hdr
.smb_buf_length
+= byte_count
;
2085 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
2086 rc
= SendReceive(xid
, pTcon
->ses
, (struct smb_hdr
*) pSMB
,
2087 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
2088 cifs_stats_inc(&pTcon
->num_t2renames
);
2090 cFYI(1, ("Send error in Rename (by file handle) = %d", rc
));
2092 cifs_buf_release(pSMB
);
2094 /* Note: On -EAGAIN error only caller can retry on handle based calls
2095 since file handle passed in no longer valid */
2101 CIFSSMBCopy(const int xid
, struct cifsTconInfo
*tcon
, const char *fromName
,
2102 const __u16 target_tid
, const char *toName
, const int flags
,
2103 const struct nls_table
*nls_codepage
, int remap
)
2106 COPY_REQ
*pSMB
= NULL
;
2107 COPY_RSP
*pSMBr
= NULL
;
2109 int name_len
, name_len2
;
2112 cFYI(1, ("In CIFSSMBCopy"));
2114 rc
= smb_init(SMB_COM_COPY
, 1, tcon
, (void **) &pSMB
,
2119 pSMB
->BufferFormat
= 0x04;
2120 pSMB
->Tid2
= target_tid
;
2122 pSMB
->Flags
= cpu_to_le16(flags
& COPY_TREE
);
2124 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
2125 name_len
= cifsConvertToUCS((__le16
*) pSMB
->OldFileName
,
2126 fromName
, PATH_MAX
, nls_codepage
,
2128 name_len
++; /* trailing null */
2130 pSMB
->OldFileName
[name_len
] = 0x04; /* pad */
2131 /* protocol requires ASCII signature byte on Unicode string */
2132 pSMB
->OldFileName
[name_len
+ 1] = 0x00;
2134 cifsConvertToUCS((__le16
*)&pSMB
->OldFileName
[name_len
+ 2],
2135 toName
, PATH_MAX
, nls_codepage
, remap
);
2136 name_len2
+= 1 /* trailing null */ + 1 /* Signature word */ ;
2137 name_len2
*= 2; /* convert to bytes */
2138 } else { /* BB improve the check for buffer overruns BB */
2139 name_len
= strnlen(fromName
, PATH_MAX
);
2140 name_len
++; /* trailing null */
2141 strncpy(pSMB
->OldFileName
, fromName
, name_len
);
2142 name_len2
= strnlen(toName
, PATH_MAX
);
2143 name_len2
++; /* trailing null */
2144 pSMB
->OldFileName
[name_len
] = 0x04; /* 2nd buffer format */
2145 strncpy(&pSMB
->OldFileName
[name_len
+ 1], toName
, name_len2
);
2146 name_len2
++; /* trailing null */
2147 name_len2
++; /* signature byte */
2150 count
= 1 /* 1st signature byte */ + name_len
+ name_len2
;
2151 pSMB
->hdr
.smb_buf_length
+= count
;
2152 pSMB
->ByteCount
= cpu_to_le16(count
);
2154 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
2155 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
2157 cFYI(1, ("Send error in copy = %d with %d files copied",
2158 rc
, le16_to_cpu(pSMBr
->CopyCount
)));
2160 cifs_buf_release(pSMB
);
2169 CIFSUnixCreateSymLink(const int xid
, struct cifsTconInfo
*tcon
,
2170 const char *fromName
, const char *toName
,
2171 const struct nls_table
*nls_codepage
)
2173 TRANSACTION2_SPI_REQ
*pSMB
= NULL
;
2174 TRANSACTION2_SPI_RSP
*pSMBr
= NULL
;
2177 int name_len_target
;
2179 int bytes_returned
= 0;
2180 __u16 params
, param_offset
, offset
, byte_count
;
2182 cFYI(1, ("In Symlink Unix style"));
2184 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
2189 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
2191 cifs_strtoUCS((__le16
*) pSMB
->FileName
, fromName
, PATH_MAX
2192 /* find define for this maxpathcomponent */
2194 name_len
++; /* trailing null */
2197 } else { /* BB improve the check for buffer overruns BB */
2198 name_len
= strnlen(fromName
, PATH_MAX
);
2199 name_len
++; /* trailing null */
2200 strncpy(pSMB
->FileName
, fromName
, name_len
);
2202 params
= 6 + name_len
;
2203 pSMB
->MaxSetupCount
= 0;
2207 pSMB
->Reserved2
= 0;
2208 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
2209 InformationLevel
) - 4;
2210 offset
= param_offset
+ params
;
2212 data_offset
= (char *) (&pSMB
->hdr
.Protocol
) + offset
;
2213 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
2215 cifs_strtoUCS((__le16
*) data_offset
, toName
, PATH_MAX
2216 /* find define for this maxpathcomponent */
2218 name_len_target
++; /* trailing null */
2219 name_len_target
*= 2;
2220 } else { /* BB improve the check for buffer overruns BB */
2221 name_len_target
= strnlen(toName
, PATH_MAX
);
2222 name_len_target
++; /* trailing null */
2223 strncpy(data_offset
, toName
, name_len_target
);
2226 pSMB
->MaxParameterCount
= cpu_to_le16(2);
2227 /* BB find exact max on data count below from sess */
2228 pSMB
->MaxDataCount
= cpu_to_le16(1000);
2229 pSMB
->SetupCount
= 1;
2230 pSMB
->Reserved3
= 0;
2231 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
2232 byte_count
= 3 /* pad */ + params
+ name_len_target
;
2233 pSMB
->DataCount
= cpu_to_le16(name_len_target
);
2234 pSMB
->ParameterCount
= cpu_to_le16(params
);
2235 pSMB
->TotalDataCount
= pSMB
->DataCount
;
2236 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
2237 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
2238 pSMB
->DataOffset
= cpu_to_le16(offset
);
2239 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_UNIX_LINK
);
2240 pSMB
->Reserved4
= 0;
2241 pSMB
->hdr
.smb_buf_length
+= byte_count
;
2242 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
2243 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
2244 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
2245 cifs_stats_inc(&tcon
->num_symlinks
);
2247 cFYI(1, ("Send error in SetPathInfo create symlink = %d", rc
));
2249 cifs_buf_release(pSMB
);
2252 goto createSymLinkRetry
;
2258 CIFSUnixCreateHardLink(const int xid
, struct cifsTconInfo
*tcon
,
2259 const char *fromName
, const char *toName
,
2260 const struct nls_table
*nls_codepage
, int remap
)
2262 TRANSACTION2_SPI_REQ
*pSMB
= NULL
;
2263 TRANSACTION2_SPI_RSP
*pSMBr
= NULL
;
2266 int name_len_target
;
2268 int bytes_returned
= 0;
2269 __u16 params
, param_offset
, offset
, byte_count
;
2271 cFYI(1, ("In Create Hard link Unix style"));
2272 createHardLinkRetry
:
2273 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
2278 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
2279 name_len
= cifsConvertToUCS((__le16
*) pSMB
->FileName
, toName
,
2280 PATH_MAX
, nls_codepage
, remap
);
2281 name_len
++; /* trailing null */
2284 } else { /* BB improve the check for buffer overruns BB */
2285 name_len
= strnlen(toName
, PATH_MAX
);
2286 name_len
++; /* trailing null */
2287 strncpy(pSMB
->FileName
, toName
, name_len
);
2289 params
= 6 + name_len
;
2290 pSMB
->MaxSetupCount
= 0;
2294 pSMB
->Reserved2
= 0;
2295 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
2296 InformationLevel
) - 4;
2297 offset
= param_offset
+ params
;
2299 data_offset
= (char *) (&pSMB
->hdr
.Protocol
) + offset
;
2300 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
2302 cifsConvertToUCS((__le16
*) data_offset
, fromName
, PATH_MAX
,
2303 nls_codepage
, remap
);
2304 name_len_target
++; /* trailing null */
2305 name_len_target
*= 2;
2306 } else { /* BB improve the check for buffer overruns BB */
2307 name_len_target
= strnlen(fromName
, PATH_MAX
);
2308 name_len_target
++; /* trailing null */
2309 strncpy(data_offset
, fromName
, name_len_target
);
2312 pSMB
->MaxParameterCount
= cpu_to_le16(2);
2313 /* BB find exact max on data count below from sess*/
2314 pSMB
->MaxDataCount
= cpu_to_le16(1000);
2315 pSMB
->SetupCount
= 1;
2316 pSMB
->Reserved3
= 0;
2317 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
2318 byte_count
= 3 /* pad */ + params
+ name_len_target
;
2319 pSMB
->ParameterCount
= cpu_to_le16(params
);
2320 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
2321 pSMB
->DataCount
= cpu_to_le16(name_len_target
);
2322 pSMB
->TotalDataCount
= pSMB
->DataCount
;
2323 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
2324 pSMB
->DataOffset
= cpu_to_le16(offset
);
2325 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_UNIX_HLINK
);
2326 pSMB
->Reserved4
= 0;
2327 pSMB
->hdr
.smb_buf_length
+= byte_count
;
2328 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
2329 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
2330 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
2331 cifs_stats_inc(&tcon
->num_hardlinks
);
2333 cFYI(1, ("Send error in SetPathInfo (hard link) = %d", rc
));
2335 cifs_buf_release(pSMB
);
2337 goto createHardLinkRetry
;
2343 CIFSCreateHardLink(const int xid
, struct cifsTconInfo
*tcon
,
2344 const char *fromName
, const char *toName
,
2345 const struct nls_table
*nls_codepage
, int remap
)
2348 NT_RENAME_REQ
*pSMB
= NULL
;
2349 RENAME_RSP
*pSMBr
= NULL
;
2351 int name_len
, name_len2
;
2354 cFYI(1, ("In CIFSCreateHardLink"));
2355 winCreateHardLinkRetry
:
2357 rc
= smb_init(SMB_COM_NT_RENAME
, 4, tcon
, (void **) &pSMB
,
2362 pSMB
->SearchAttributes
=
2363 cpu_to_le16(ATTR_READONLY
| ATTR_HIDDEN
| ATTR_SYSTEM
|
2365 pSMB
->Flags
= cpu_to_le16(CREATE_HARD_LINK
);
2366 pSMB
->ClusterCount
= 0;
2368 pSMB
->BufferFormat
= 0x04;
2370 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
2372 cifsConvertToUCS((__le16
*) pSMB
->OldFileName
, fromName
,
2373 PATH_MAX
, nls_codepage
, remap
);
2374 name_len
++; /* trailing null */
2376 pSMB
->OldFileName
[name_len
] = 0; /* pad */
2377 pSMB
->OldFileName
[name_len
+ 1] = 0x04;
2379 cifsConvertToUCS((__le16
*)&pSMB
->OldFileName
[name_len
+ 2],
2380 toName
, PATH_MAX
, nls_codepage
, remap
);
2381 name_len2
+= 1 /* trailing null */ + 1 /* Signature word */ ;
2382 name_len2
*= 2; /* convert to bytes */
2383 } else { /* BB improve the check for buffer overruns BB */
2384 name_len
= strnlen(fromName
, PATH_MAX
);
2385 name_len
++; /* trailing null */
2386 strncpy(pSMB
->OldFileName
, fromName
, name_len
);
2387 name_len2
= strnlen(toName
, PATH_MAX
);
2388 name_len2
++; /* trailing null */
2389 pSMB
->OldFileName
[name_len
] = 0x04; /* 2nd buffer format */
2390 strncpy(&pSMB
->OldFileName
[name_len
+ 1], toName
, name_len2
);
2391 name_len2
++; /* trailing null */
2392 name_len2
++; /* signature byte */
2395 count
= 1 /* string type byte */ + name_len
+ name_len2
;
2396 pSMB
->hdr
.smb_buf_length
+= count
;
2397 pSMB
->ByteCount
= cpu_to_le16(count
);
2399 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
2400 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
2401 cifs_stats_inc(&tcon
->num_hardlinks
);
2403 cFYI(1, ("Send error in hard link (NT rename) = %d", rc
));
2405 cifs_buf_release(pSMB
);
2407 goto winCreateHardLinkRetry
;
2413 CIFSSMBUnixQuerySymLink(const int xid
, struct cifsTconInfo
*tcon
,
2414 const unsigned char *searchName
,
2415 char *symlinkinfo
, const int buflen
,
2416 const struct nls_table
*nls_codepage
)
2418 /* SMB_QUERY_FILE_UNIX_LINK */
2419 TRANSACTION2_QPI_REQ
*pSMB
= NULL
;
2420 TRANSACTION2_QPI_RSP
*pSMBr
= NULL
;
2424 __u16 params
, byte_count
;
2426 cFYI(1, ("In QPathSymLinkInfo (Unix) for path %s", searchName
));
2429 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
2434 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
2436 cifs_strtoUCS((__le16
*) pSMB
->FileName
, searchName
,
2437 PATH_MAX
, nls_codepage
);
2438 name_len
++; /* trailing null */
2440 } else { /* BB improve the check for buffer overruns BB */
2441 name_len
= strnlen(searchName
, PATH_MAX
);
2442 name_len
++; /* trailing null */
2443 strncpy(pSMB
->FileName
, searchName
, name_len
);
2446 params
= 2 /* level */ + 4 /* rsrvd */ + name_len
/* incl null */ ;
2447 pSMB
->TotalDataCount
= 0;
2448 pSMB
->MaxParameterCount
= cpu_to_le16(2);
2449 /* BB find exact max data count below from sess structure BB */
2450 pSMB
->MaxDataCount
= cpu_to_le16(4000);
2451 pSMB
->MaxSetupCount
= 0;
2455 pSMB
->Reserved2
= 0;
2456 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
2457 struct smb_com_transaction2_qpi_req
, InformationLevel
) - 4);
2458 pSMB
->DataCount
= 0;
2459 pSMB
->DataOffset
= 0;
2460 pSMB
->SetupCount
= 1;
2461 pSMB
->Reserved3
= 0;
2462 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION
);
2463 byte_count
= params
+ 1 /* pad */ ;
2464 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
2465 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
2466 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FILE_UNIX_LINK
);
2467 pSMB
->Reserved4
= 0;
2468 pSMB
->hdr
.smb_buf_length
+= byte_count
;
2469 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
2471 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
2472 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
2474 cFYI(1, ("Send error in QuerySymLinkInfo = %d", rc
));
2476 /* decode response */
2478 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
2479 if (rc
|| (pSMBr
->ByteCount
< 2))
2480 /* BB also check enough total bytes returned */
2481 rc
= -EIO
; /* bad smb */
2483 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
2484 __u16 count
= le16_to_cpu(pSMBr
->t2
.DataCount
);
2486 if (pSMBr
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
2487 name_len
= UniStrnlen((wchar_t *) ((char *)
2488 &pSMBr
->hdr
.Protocol
+ data_offset
),
2489 min_t(const int, buflen
, count
) / 2);
2490 /* BB FIXME investigate remapping reserved chars here */
2491 cifs_strfromUCS_le(symlinkinfo
,
2492 (__le16
*) ((char *)&pSMBr
->hdr
.Protocol
2494 name_len
, nls_codepage
);
2496 strncpy(symlinkinfo
,
2497 (char *) &pSMBr
->hdr
.Protocol
+
2499 min_t(const int, buflen
, count
));
2501 symlinkinfo
[buflen
] = 0;
2502 /* just in case so calling code does not go off the end of buffer */
2505 cifs_buf_release(pSMB
);
2507 goto querySymLinkRetry
;
2511 #ifdef CONFIG_CIFS_EXPERIMENTAL
2512 /* Initialize NT TRANSACT SMB into small smb request buffer.
2513 This assumes that all NT TRANSACTS that we init here have
2514 total parm and data under about 400 bytes (to fit in small cifs
2515 buffer size), which is the case so far, it easily fits. NB:
2516 Setup words themselves and ByteCount
2517 MaxSetupCount (size of returned setup area) and
2518 MaxParameterCount (returned parms size) must be set by caller */
2520 smb_init_nttransact(const __u16 sub_command
, const int setup_count
,
2521 const int parm_len
, struct cifsTconInfo
*tcon
,
2526 struct smb_com_ntransact_req
*pSMB
;
2528 rc
= small_smb_init(SMB_COM_NT_TRANSACT
, 19 + setup_count
, tcon
,
2532 *ret_buf
= (void *)pSMB
;
2534 pSMB
->TotalParameterCount
= cpu_to_le32(parm_len
);
2535 pSMB
->TotalDataCount
= 0;
2536 pSMB
->MaxDataCount
= cpu_to_le32((tcon
->ses
->server
->maxBuf
-
2537 MAX_CIFS_HDR_SIZE
) & 0xFFFFFF00);
2538 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
2539 pSMB
->DataCount
= pSMB
->TotalDataCount
;
2540 temp_offset
= offsetof(struct smb_com_ntransact_req
, Parms
) +
2541 (setup_count
* 2) - 4 /* for rfc1001 length itself */;
2542 pSMB
->ParameterOffset
= cpu_to_le32(temp_offset
);
2543 pSMB
->DataOffset
= cpu_to_le32(temp_offset
+ parm_len
);
2544 pSMB
->SetupCount
= setup_count
; /* no need to le convert byte fields */
2545 pSMB
->SubCommand
= cpu_to_le16(sub_command
);
2550 validate_ntransact(char *buf
, char **ppparm
, char **ppdata
,
2551 __u32
*pparmlen
, __u32
*pdatalen
)
2554 __u32 data_count
, data_offset
, parm_count
, parm_offset
;
2555 struct smb_com_ntransact_rsp
*pSMBr
;
2563 pSMBr
= (struct smb_com_ntransact_rsp
*)buf
;
2565 /* ByteCount was converted from little endian in SendReceive */
2566 end_of_smb
= 2 /* sizeof byte count */ + pSMBr
->ByteCount
+
2567 (char *)&pSMBr
->ByteCount
;
2569 data_offset
= le32_to_cpu(pSMBr
->DataOffset
);
2570 data_count
= le32_to_cpu(pSMBr
->DataCount
);
2571 parm_offset
= le32_to_cpu(pSMBr
->ParameterOffset
);
2572 parm_count
= le32_to_cpu(pSMBr
->ParameterCount
);
2574 *ppparm
= (char *)&pSMBr
->hdr
.Protocol
+ parm_offset
;
2575 *ppdata
= (char *)&pSMBr
->hdr
.Protocol
+ data_offset
;
2577 /* should we also check that parm and data areas do not overlap? */
2578 if (*ppparm
> end_of_smb
) {
2579 cFYI(1, ("parms start after end of smb"));
2581 } else if (parm_count
+ *ppparm
> end_of_smb
) {
2582 cFYI(1, ("parm end after end of smb"));
2584 } else if (*ppdata
> end_of_smb
) {
2585 cFYI(1, ("data starts after end of smb"));
2587 } else if (data_count
+ *ppdata
> end_of_smb
) {
2588 cFYI(1, ("data %p + count %d (%p) ends after end of smb %p start %p",
2589 *ppdata
, data_count
, (data_count
+ *ppdata
),
2590 end_of_smb
, pSMBr
));
2592 } else if (parm_count
+ data_count
> pSMBr
->ByteCount
) {
2593 cFYI(1, ("parm count and data count larger than SMB"));
2596 *pdatalen
= data_count
;
2597 *pparmlen
= parm_count
;
2600 #endif /* CIFS_EXPERIMENTAL */
2603 CIFSSMBQueryReparseLinkInfo(const int xid
, struct cifsTconInfo
*tcon
,
2604 const unsigned char *searchName
,
2605 char *symlinkinfo
, const int buflen
, __u16 fid
,
2606 const struct nls_table
*nls_codepage
)
2611 struct smb_com_transaction_ioctl_req
*pSMB
;
2612 struct smb_com_transaction_ioctl_rsp
*pSMBr
;
2614 cFYI(1, ("In Windows reparse style QueryLink for path %s", searchName
));
2615 rc
= smb_init(SMB_COM_NT_TRANSACT
, 23, tcon
, (void **) &pSMB
,
2620 pSMB
->TotalParameterCount
= 0 ;
2621 pSMB
->TotalDataCount
= 0;
2622 pSMB
->MaxParameterCount
= cpu_to_le32(2);
2623 /* BB find exact data count max from sess structure BB */
2624 pSMB
->MaxDataCount
= cpu_to_le32((tcon
->ses
->server
->maxBuf
-
2625 MAX_CIFS_HDR_SIZE
) & 0xFFFFFF00);
2626 pSMB
->MaxSetupCount
= 4;
2628 pSMB
->ParameterOffset
= 0;
2629 pSMB
->DataCount
= 0;
2630 pSMB
->DataOffset
= 0;
2631 pSMB
->SetupCount
= 4;
2632 pSMB
->SubCommand
= cpu_to_le16(NT_TRANSACT_IOCTL
);
2633 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
2634 pSMB
->FunctionCode
= cpu_to_le32(FSCTL_GET_REPARSE_POINT
);
2635 pSMB
->IsFsctl
= 1; /* FSCTL */
2636 pSMB
->IsRootFlag
= 0;
2637 pSMB
->Fid
= fid
; /* file handle always le */
2638 pSMB
->ByteCount
= 0;
2640 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
2641 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
2643 cFYI(1, ("Send error in QueryReparseLinkInfo = %d", rc
));
2644 } else { /* decode response */
2645 __u32 data_offset
= le32_to_cpu(pSMBr
->DataOffset
);
2646 __u32 data_count
= le32_to_cpu(pSMBr
->DataCount
);
2647 if ((pSMBr
->ByteCount
< 2) || (data_offset
> 512))
2648 /* BB also check enough total bytes returned */
2649 rc
= -EIO
; /* bad smb */
2651 if (data_count
&& (data_count
< 2048)) {
2652 char *end_of_smb
= 2 /* sizeof byte count */ +
2654 (char *)&pSMBr
->ByteCount
;
2656 struct reparse_data
*reparse_buf
=
2657 (struct reparse_data
*)
2658 ((char *)&pSMBr
->hdr
.Protocol
2660 if ((char *)reparse_buf
>= end_of_smb
) {
2664 if ((reparse_buf
->LinkNamesBuf
+
2665 reparse_buf
->TargetNameOffset
+
2666 reparse_buf
->TargetNameLen
) >
2668 cFYI(1, ("reparse buf beyond SMB"));
2673 if (pSMBr
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
2674 name_len
= UniStrnlen((wchar_t *)
2675 (reparse_buf
->LinkNamesBuf
+
2676 reparse_buf
->TargetNameOffset
),
2678 reparse_buf
->TargetNameLen
/ 2));
2679 cifs_strfromUCS_le(symlinkinfo
,
2680 (__le16
*) (reparse_buf
->LinkNamesBuf
+
2681 reparse_buf
->TargetNameOffset
),
2682 name_len
, nls_codepage
);
2683 } else { /* ASCII names */
2684 strncpy(symlinkinfo
,
2685 reparse_buf
->LinkNamesBuf
+
2686 reparse_buf
->TargetNameOffset
,
2687 min_t(const int, buflen
,
2688 reparse_buf
->TargetNameLen
));
2692 cFYI(1, ("Invalid return data count on "
2693 "get reparse info ioctl"));
2695 symlinkinfo
[buflen
] = 0; /* just in case so the caller
2696 does not go off the end of the buffer */
2697 cFYI(1, ("readlink result - %s", symlinkinfo
));
2701 cifs_buf_release(pSMB
);
2703 /* Note: On -EAGAIN error only caller can retry on handle based calls
2704 since file handle passed in no longer valid */
2709 #ifdef CONFIG_CIFS_POSIX
2711 /*Convert an Access Control Entry from wire format to local POSIX xattr format*/
2712 static void cifs_convert_ace(posix_acl_xattr_entry
*ace
,
2713 struct cifs_posix_ace
*cifs_ace
)
2715 /* u8 cifs fields do not need le conversion */
2716 ace
->e_perm
= cpu_to_le16(cifs_ace
->cifs_e_perm
);
2717 ace
->e_tag
= cpu_to_le16(cifs_ace
->cifs_e_tag
);
2718 ace
->e_id
= cpu_to_le32(le64_to_cpu(cifs_ace
->cifs_uid
));
2719 /* cFYI(1,("perm %d tag %d id %d",ace->e_perm,ace->e_tag,ace->e_id)); */
2724 /* Convert ACL from CIFS POSIX wire format to local Linux POSIX ACL xattr */
2725 static int cifs_copy_posix_acl(char *trgt
, char *src
, const int buflen
,
2726 const int acl_type
, const int size_of_data_area
)
2731 struct cifs_posix_ace
*pACE
;
2732 struct cifs_posix_acl
*cifs_acl
= (struct cifs_posix_acl
*)src
;
2733 posix_acl_xattr_header
*local_acl
= (posix_acl_xattr_header
*)trgt
;
2735 if (le16_to_cpu(cifs_acl
->version
) != CIFS_ACL_VERSION
)
2738 if (acl_type
& ACL_TYPE_ACCESS
) {
2739 count
= le16_to_cpu(cifs_acl
->access_entry_count
);
2740 pACE
= &cifs_acl
->ace_array
[0];
2741 size
= sizeof(struct cifs_posix_acl
);
2742 size
+= sizeof(struct cifs_posix_ace
) * count
;
2743 /* check if we would go beyond end of SMB */
2744 if (size_of_data_area
< size
) {
2745 cFYI(1, ("bad CIFS POSIX ACL size %d vs. %d",
2746 size_of_data_area
, size
));
2749 } else if (acl_type
& ACL_TYPE_DEFAULT
) {
2750 count
= le16_to_cpu(cifs_acl
->access_entry_count
);
2751 size
= sizeof(struct cifs_posix_acl
);
2752 size
+= sizeof(struct cifs_posix_ace
) * count
;
2753 /* skip past access ACEs to get to default ACEs */
2754 pACE
= &cifs_acl
->ace_array
[count
];
2755 count
= le16_to_cpu(cifs_acl
->default_entry_count
);
2756 size
+= sizeof(struct cifs_posix_ace
) * count
;
2757 /* check if we would go beyond end of SMB */
2758 if (size_of_data_area
< size
)
2765 size
= posix_acl_xattr_size(count
);
2766 if ((buflen
== 0) || (local_acl
== NULL
)) {
2767 /* used to query ACL EA size */
2768 } else if (size
> buflen
) {
2770 } else /* buffer big enough */ {
2771 local_acl
->a_version
= cpu_to_le32(POSIX_ACL_XATTR_VERSION
);
2772 for (i
= 0; i
< count
; i
++) {
2773 cifs_convert_ace(&local_acl
->a_entries
[i
], pACE
);
2780 static __u16
convert_ace_to_cifs_ace(struct cifs_posix_ace
*cifs_ace
,
2781 const posix_acl_xattr_entry
*local_ace
)
2783 __u16 rc
= 0; /* 0 = ACL converted ok */
2785 cifs_ace
->cifs_e_perm
= le16_to_cpu(local_ace
->e_perm
);
2786 cifs_ace
->cifs_e_tag
= le16_to_cpu(local_ace
->e_tag
);
2787 /* BB is there a better way to handle the large uid? */
2788 if (local_ace
->e_id
== cpu_to_le32(-1)) {
2789 /* Probably no need to le convert -1 on any arch but can not hurt */
2790 cifs_ace
->cifs_uid
= cpu_to_le64(-1);
2792 cifs_ace
->cifs_uid
= cpu_to_le64(le32_to_cpu(local_ace
->e_id
));
2793 /*cFYI(1,("perm %d tag %d id %d",ace->e_perm,ace->e_tag,ace->e_id));*/
2797 /* Convert ACL from local Linux POSIX xattr to CIFS POSIX ACL wire format */
2798 static __u16
ACL_to_cifs_posix(char *parm_data
, const char *pACL
,
2799 const int buflen
, const int acl_type
)
2802 struct cifs_posix_acl
*cifs_acl
= (struct cifs_posix_acl
*)parm_data
;
2803 posix_acl_xattr_header
*local_acl
= (posix_acl_xattr_header
*)pACL
;
2807 if ((buflen
== 0) || (pACL
== NULL
) || (cifs_acl
== NULL
))
2810 count
= posix_acl_xattr_count((size_t)buflen
);
2811 cFYI(1, ("setting acl with %d entries from buf of length %d and "
2813 count
, buflen
, le32_to_cpu(local_acl
->a_version
)));
2814 if (le32_to_cpu(local_acl
->a_version
) != 2) {
2815 cFYI(1, ("unknown POSIX ACL version %d",
2816 le32_to_cpu(local_acl
->a_version
)));
2819 cifs_acl
->version
= cpu_to_le16(1);
2820 if (acl_type
== ACL_TYPE_ACCESS
)
2821 cifs_acl
->access_entry_count
= cpu_to_le16(count
);
2822 else if (acl_type
== ACL_TYPE_DEFAULT
)
2823 cifs_acl
->default_entry_count
= cpu_to_le16(count
);
2825 cFYI(1, ("unknown ACL type %d", acl_type
));
2828 for (i
= 0; i
< count
; i
++) {
2829 rc
= convert_ace_to_cifs_ace(&cifs_acl
->ace_array
[i
],
2830 &local_acl
->a_entries
[i
]);
2832 /* ACE not converted */
2837 rc
= (__u16
)(count
* sizeof(struct cifs_posix_ace
));
2838 rc
+= sizeof(struct cifs_posix_acl
);
2839 /* BB add check to make sure ACL does not overflow SMB */
2845 CIFSSMBGetPosixACL(const int xid
, struct cifsTconInfo
*tcon
,
2846 const unsigned char *searchName
,
2847 char *acl_inf
, const int buflen
, const int acl_type
,
2848 const struct nls_table
*nls_codepage
, int remap
)
2850 /* SMB_QUERY_POSIX_ACL */
2851 TRANSACTION2_QPI_REQ
*pSMB
= NULL
;
2852 TRANSACTION2_QPI_RSP
*pSMBr
= NULL
;
2856 __u16 params
, byte_count
;
2858 cFYI(1, ("In GetPosixACL (Unix) for path %s", searchName
));
2861 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
2866 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
2868 cifsConvertToUCS((__le16
*) pSMB
->FileName
, searchName
,
2869 PATH_MAX
, nls_codepage
, remap
);
2870 name_len
++; /* trailing null */
2872 pSMB
->FileName
[name_len
] = 0;
2873 pSMB
->FileName
[name_len
+1] = 0;
2874 } else { /* BB improve the check for buffer overruns BB */
2875 name_len
= strnlen(searchName
, PATH_MAX
);
2876 name_len
++; /* trailing null */
2877 strncpy(pSMB
->FileName
, searchName
, name_len
);
2880 params
= 2 /* level */ + 4 /* rsrvd */ + name_len
/* incl null */ ;
2881 pSMB
->TotalDataCount
= 0;
2882 pSMB
->MaxParameterCount
= cpu_to_le16(2);
2883 /* BB find exact max data count below from sess structure BB */
2884 pSMB
->MaxDataCount
= cpu_to_le16(4000);
2885 pSMB
->MaxSetupCount
= 0;
2889 pSMB
->Reserved2
= 0;
2890 pSMB
->ParameterOffset
= cpu_to_le16(
2891 offsetof(struct smb_com_transaction2_qpi_req
,
2892 InformationLevel
) - 4);
2893 pSMB
->DataCount
= 0;
2894 pSMB
->DataOffset
= 0;
2895 pSMB
->SetupCount
= 1;
2896 pSMB
->Reserved3
= 0;
2897 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION
);
2898 byte_count
= params
+ 1 /* pad */ ;
2899 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
2900 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
2901 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_POSIX_ACL
);
2902 pSMB
->Reserved4
= 0;
2903 pSMB
->hdr
.smb_buf_length
+= byte_count
;
2904 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
2906 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
2907 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
2908 cifs_stats_inc(&tcon
->num_acl_get
);
2910 cFYI(1, ("Send error in Query POSIX ACL = %d", rc
));
2912 /* decode response */
2914 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
2915 if (rc
|| (pSMBr
->ByteCount
< 2))
2916 /* BB also check enough total bytes returned */
2917 rc
= -EIO
; /* bad smb */
2919 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
2920 __u16 count
= le16_to_cpu(pSMBr
->t2
.DataCount
);
2921 rc
= cifs_copy_posix_acl(acl_inf
,
2922 (char *)&pSMBr
->hdr
.Protocol
+data_offset
,
2923 buflen
, acl_type
, count
);
2926 cifs_buf_release(pSMB
);
2933 CIFSSMBSetPosixACL(const int xid
, struct cifsTconInfo
*tcon
,
2934 const unsigned char *fileName
,
2935 const char *local_acl
, const int buflen
,
2937 const struct nls_table
*nls_codepage
, int remap
)
2939 struct smb_com_transaction2_spi_req
*pSMB
= NULL
;
2940 struct smb_com_transaction2_spi_rsp
*pSMBr
= NULL
;
2944 int bytes_returned
= 0;
2945 __u16 params
, byte_count
, data_count
, param_offset
, offset
;
2947 cFYI(1, ("In SetPosixACL (Unix) for path %s", fileName
));
2949 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
2953 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
2955 cifsConvertToUCS((__le16
*) pSMB
->FileName
, fileName
,
2956 PATH_MAX
, nls_codepage
, remap
);
2957 name_len
++; /* trailing null */
2959 } else { /* BB improve the check for buffer overruns BB */
2960 name_len
= strnlen(fileName
, PATH_MAX
);
2961 name_len
++; /* trailing null */
2962 strncpy(pSMB
->FileName
, fileName
, name_len
);
2964 params
= 6 + name_len
;
2965 pSMB
->MaxParameterCount
= cpu_to_le16(2);
2966 /* BB find max SMB size from sess */
2967 pSMB
->MaxDataCount
= cpu_to_le16(1000);
2968 pSMB
->MaxSetupCount
= 0;
2972 pSMB
->Reserved2
= 0;
2973 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
2974 InformationLevel
) - 4;
2975 offset
= param_offset
+ params
;
2976 parm_data
= ((char *) &pSMB
->hdr
.Protocol
) + offset
;
2977 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
2979 /* convert to on the wire format for POSIX ACL */
2980 data_count
= ACL_to_cifs_posix(parm_data
, local_acl
, buflen
, acl_type
);
2982 if (data_count
== 0) {
2984 goto setACLerrorExit
;
2986 pSMB
->DataOffset
= cpu_to_le16(offset
);
2987 pSMB
->SetupCount
= 1;
2988 pSMB
->Reserved3
= 0;
2989 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
2990 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_POSIX_ACL
);
2991 byte_count
= 3 /* pad */ + params
+ data_count
;
2992 pSMB
->DataCount
= cpu_to_le16(data_count
);
2993 pSMB
->TotalDataCount
= pSMB
->DataCount
;
2994 pSMB
->ParameterCount
= cpu_to_le16(params
);
2995 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
2996 pSMB
->Reserved4
= 0;
2997 pSMB
->hdr
.smb_buf_length
+= byte_count
;
2998 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
2999 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3000 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3002 cFYI(1, ("Set POSIX ACL returned %d", rc
));
3005 cifs_buf_release(pSMB
);
3011 /* BB fix tabs in this function FIXME BB */
3013 CIFSGetExtAttr(const int xid
, struct cifsTconInfo
*tcon
,
3014 const int netfid
, __u64
*pExtAttrBits
, __u64
*pMask
)
3017 struct smb_t2_qfi_req
*pSMB
= NULL
;
3018 struct smb_t2_qfi_rsp
*pSMBr
= NULL
;
3020 __u16 params
, byte_count
;
3022 cFYI(1, ("In GetExtAttr"));
3027 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
3032 params
= 2 /* level */ + 2 /* fid */;
3033 pSMB
->t2
.TotalDataCount
= 0;
3034 pSMB
->t2
.MaxParameterCount
= cpu_to_le16(4);
3035 /* BB find exact max data count below from sess structure BB */
3036 pSMB
->t2
.MaxDataCount
= cpu_to_le16(4000);
3037 pSMB
->t2
.MaxSetupCount
= 0;
3038 pSMB
->t2
.Reserved
= 0;
3040 pSMB
->t2
.Timeout
= 0;
3041 pSMB
->t2
.Reserved2
= 0;
3042 pSMB
->t2
.ParameterOffset
= cpu_to_le16(offsetof(struct smb_t2_qfi_req
,
3044 pSMB
->t2
.DataCount
= 0;
3045 pSMB
->t2
.DataOffset
= 0;
3046 pSMB
->t2
.SetupCount
= 1;
3047 pSMB
->t2
.Reserved3
= 0;
3048 pSMB
->t2
.SubCommand
= cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION
);
3049 byte_count
= params
+ 1 /* pad */ ;
3050 pSMB
->t2
.TotalParameterCount
= cpu_to_le16(params
);
3051 pSMB
->t2
.ParameterCount
= pSMB
->t2
.TotalParameterCount
;
3052 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_ATTR_FLAGS
);
3055 pSMB
->hdr
.smb_buf_length
+= byte_count
;
3056 pSMB
->t2
.ByteCount
= cpu_to_le16(byte_count
);
3058 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3059 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3061 cFYI(1, ("error %d in GetExtAttr", rc
));
3063 /* decode response */
3064 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
3065 if (rc
|| (pSMBr
->ByteCount
< 2))
3066 /* BB also check enough total bytes returned */
3067 /* If rc should we check for EOPNOSUPP and
3068 disable the srvino flag? or in caller? */
3069 rc
= -EIO
; /* bad smb */
3071 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
3072 __u16 count
= le16_to_cpu(pSMBr
->t2
.DataCount
);
3073 struct file_chattr_info
*pfinfo
;
3074 /* BB Do we need a cast or hash here ? */
3076 cFYI(1, ("Illegal size ret in GetExtAttr"));
3080 pfinfo
= (struct file_chattr_info
*)
3081 (data_offset
+ (char *) &pSMBr
->hdr
.Protocol
);
3082 *pExtAttrBits
= le64_to_cpu(pfinfo
->mode
);
3083 *pMask
= le64_to_cpu(pfinfo
->mask
);
3087 cifs_buf_release(pSMB
);
3089 goto GetExtAttrRetry
;
3093 #endif /* CONFIG_POSIX */
3095 #ifdef CONFIG_CIFS_EXPERIMENTAL
3096 /* Get Security Descriptor (by handle) from remote server for a file or dir */
3098 CIFSSMBGetCIFSACL(const int xid
, struct cifsTconInfo
*tcon
, __u16 fid
,
3099 struct cifs_ntsd
**acl_inf
, __u32
*pbuflen
)
3103 QUERY_SEC_DESC_REQ
*pSMB
;
3106 cFYI(1, ("GetCifsACL"));
3111 rc
= smb_init_nttransact(NT_TRANSACT_QUERY_SECURITY_DESC
, 0,
3112 8 /* parm len */, tcon
, (void **) &pSMB
);
3116 pSMB
->MaxParameterCount
= cpu_to_le32(4);
3117 /* BB TEST with big acls that might need to be e.g. larger than 16K */
3118 pSMB
->MaxSetupCount
= 0;
3119 pSMB
->Fid
= fid
; /* file handle always le */
3120 pSMB
->AclFlags
= cpu_to_le32(CIFS_ACL_OWNER
| CIFS_ACL_GROUP
|
3122 pSMB
->ByteCount
= cpu_to_le16(11); /* 3 bytes pad + 8 bytes parm */
3123 pSMB
->hdr
.smb_buf_length
+= 11;
3124 iov
[0].iov_base
= (char *)pSMB
;
3125 iov
[0].iov_len
= pSMB
->hdr
.smb_buf_length
+ 4;
3127 rc
= SendReceive2(xid
, tcon
->ses
, iov
, 1 /* num iovec */, &buf_type
,
3129 cifs_stats_inc(&tcon
->num_acl_get
);
3131 cFYI(1, ("Send error in QuerySecDesc = %d", rc
));
3132 } else { /* decode response */
3136 struct smb_com_ntransact_rsp
*pSMBr
;
3139 /* validate_nttransact */
3140 rc
= validate_ntransact(iov
[0].iov_base
, (char **)&parm
,
3141 &pdata
, &parm_len
, pbuflen
);
3144 pSMBr
= (struct smb_com_ntransact_rsp
*)iov
[0].iov_base
;
3146 cFYI(1, ("smb %p parm %p data %p", pSMBr
, parm
, *acl_inf
));
3148 if (le32_to_cpu(pSMBr
->ParameterCount
) != 4) {
3149 rc
= -EIO
; /* bad smb */
3154 /* BB check that data area is minimum length and as big as acl_len */
3156 acl_len
= le32_to_cpu(*parm
);
3157 if (acl_len
!= *pbuflen
) {
3158 cERROR(1, ("acl length %d does not match %d",
3159 acl_len
, *pbuflen
));
3160 if (*pbuflen
> acl_len
)
3164 /* check if buffer is big enough for the acl
3165 header followed by the smallest SID */
3166 if ((*pbuflen
< sizeof(struct cifs_ntsd
) + 8) ||
3167 (*pbuflen
>= 64 * 1024)) {
3168 cERROR(1, ("bad acl length %d", *pbuflen
));
3172 *acl_inf
= kmalloc(*pbuflen
, GFP_KERNEL
);
3173 if (*acl_inf
== NULL
) {
3177 memcpy(*acl_inf
, pdata
, *pbuflen
);
3181 if (buf_type
== CIFS_SMALL_BUFFER
)
3182 cifs_small_buf_release(iov
[0].iov_base
);
3183 else if (buf_type
== CIFS_LARGE_BUFFER
)
3184 cifs_buf_release(iov
[0].iov_base
);
3185 /* cifs_small_buf_release(pSMB); */ /* Freed earlier now in SendReceive2 */
3190 CIFSSMBSetCIFSACL(const int xid
, struct cifsTconInfo
*tcon
, __u16 fid
,
3191 struct cifs_ntsd
*pntsd
, __u32 acllen
)
3193 __u16 byte_count
, param_count
, data_count
, param_offset
, data_offset
;
3195 int bytes_returned
= 0;
3196 SET_SEC_DESC_REQ
*pSMB
= NULL
;
3197 NTRANSACT_RSP
*pSMBr
= NULL
;
3200 rc
= smb_init(SMB_COM_NT_TRANSACT
, 19, tcon
, (void **) &pSMB
,
3205 pSMB
->MaxSetupCount
= 0;
3209 param_offset
= offsetof(struct smb_com_transaction_ssec_req
, Fid
) - 4;
3210 data_count
= acllen
;
3211 data_offset
= param_offset
+ param_count
;
3212 byte_count
= 3 /* pad */ + param_count
;
3214 pSMB
->DataCount
= cpu_to_le32(data_count
);
3215 pSMB
->TotalDataCount
= pSMB
->DataCount
;
3216 pSMB
->MaxParameterCount
= cpu_to_le32(4);
3217 pSMB
->MaxDataCount
= cpu_to_le32(16384);
3218 pSMB
->ParameterCount
= cpu_to_le32(param_count
);
3219 pSMB
->ParameterOffset
= cpu_to_le32(param_offset
);
3220 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
3221 pSMB
->DataOffset
= cpu_to_le32(data_offset
);
3222 pSMB
->SetupCount
= 0;
3223 pSMB
->SubCommand
= cpu_to_le16(NT_TRANSACT_SET_SECURITY_DESC
);
3224 pSMB
->ByteCount
= cpu_to_le16(byte_count
+data_count
);
3226 pSMB
->Fid
= fid
; /* file handle always le */
3227 pSMB
->Reserved2
= 0;
3228 pSMB
->AclFlags
= cpu_to_le32(CIFS_ACL_DACL
);
3230 if (pntsd
&& acllen
) {
3231 memcpy((char *) &pSMBr
->hdr
.Protocol
+ data_offset
,
3234 pSMB
->hdr
.smb_buf_length
+= (byte_count
+ data_count
);
3237 pSMB
->hdr
.smb_buf_length
+= byte_count
;
3239 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3240 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3242 cFYI(1, ("SetCIFSACL bytes_returned: %d, rc: %d", bytes_returned
, rc
));
3244 cFYI(1, ("Set CIFS ACL returned %d", rc
));
3245 cifs_buf_release(pSMB
);
3248 goto setCifsAclRetry
;
3253 #endif /* CONFIG_CIFS_EXPERIMENTAL */
3255 /* Legacy Query Path Information call for lookup to old servers such
3257 int SMBQueryInformation(const int xid
, struct cifsTconInfo
*tcon
,
3258 const unsigned char *searchName
,
3259 FILE_ALL_INFO
*pFinfo
,
3260 const struct nls_table
*nls_codepage
, int remap
)
3262 QUERY_INFORMATION_REQ
*pSMB
;
3263 QUERY_INFORMATION_RSP
*pSMBr
;
3268 cFYI(1, ("In SMBQPath path %s", searchName
));
3270 rc
= smb_init(SMB_COM_QUERY_INFORMATION
, 0, tcon
, (void **) &pSMB
,
3275 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
3277 cifsConvertToUCS((__le16
*) pSMB
->FileName
, searchName
,
3278 PATH_MAX
, nls_codepage
, remap
);
3279 name_len
++; /* trailing null */
3282 name_len
= strnlen(searchName
, PATH_MAX
);
3283 name_len
++; /* trailing null */
3284 strncpy(pSMB
->FileName
, searchName
, name_len
);
3286 pSMB
->BufferFormat
= 0x04;
3287 name_len
++; /* account for buffer type byte */
3288 pSMB
->hdr
.smb_buf_length
+= (__u16
) name_len
;
3289 pSMB
->ByteCount
= cpu_to_le16(name_len
);
3291 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3292 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3294 cFYI(1, ("Send error in QueryInfo = %d", rc
));
3295 } else if (pFinfo
) {
3297 __u32 time
= le32_to_cpu(pSMBr
->last_write_time
);
3299 /* decode response */
3300 /* BB FIXME - add time zone adjustment BB */
3301 memset(pFinfo
, 0, sizeof(FILE_ALL_INFO
));
3304 /* decode time fields */
3305 pFinfo
->ChangeTime
= cpu_to_le64(cifs_UnixTimeToNT(ts
));
3306 pFinfo
->LastWriteTime
= pFinfo
->ChangeTime
;
3307 pFinfo
->LastAccessTime
= 0;
3308 pFinfo
->AllocationSize
=
3309 cpu_to_le64(le32_to_cpu(pSMBr
->size
));
3310 pFinfo
->EndOfFile
= pFinfo
->AllocationSize
;
3311 pFinfo
->Attributes
=
3312 cpu_to_le32(le16_to_cpu(pSMBr
->attr
));
3314 rc
= -EIO
; /* bad buffer passed in */
3316 cifs_buf_release(pSMB
);
3328 CIFSSMBQPathInfo(const int xid
, struct cifsTconInfo
*tcon
,
3329 const unsigned char *searchName
,
3330 FILE_ALL_INFO
*pFindData
,
3331 int legacy
/* old style infolevel */,
3332 const struct nls_table
*nls_codepage
, int remap
)
3334 /* level 263 SMB_QUERY_FILE_ALL_INFO */
3335 TRANSACTION2_QPI_REQ
*pSMB
= NULL
;
3336 TRANSACTION2_QPI_RSP
*pSMBr
= NULL
;
3340 __u16 params
, byte_count
;
3342 /* cFYI(1, ("In QPathInfo path %s", searchName)); */
3344 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
3349 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
3351 cifsConvertToUCS((__le16
*) pSMB
->FileName
, searchName
,
3352 PATH_MAX
, nls_codepage
, remap
);
3353 name_len
++; /* trailing null */
3355 } else { /* BB improve the check for buffer overruns BB */
3356 name_len
= strnlen(searchName
, PATH_MAX
);
3357 name_len
++; /* trailing null */
3358 strncpy(pSMB
->FileName
, searchName
, name_len
);
3361 params
= 2 /* level */ + 4 /* reserved */ + name_len
/* includes NUL */;
3362 pSMB
->TotalDataCount
= 0;
3363 pSMB
->MaxParameterCount
= cpu_to_le16(2);
3364 /* BB find exact max SMB PDU from sess structure BB */
3365 pSMB
->MaxDataCount
= cpu_to_le16(4000);
3366 pSMB
->MaxSetupCount
= 0;
3370 pSMB
->Reserved2
= 0;
3371 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
3372 struct smb_com_transaction2_qpi_req
, InformationLevel
) - 4);
3373 pSMB
->DataCount
= 0;
3374 pSMB
->DataOffset
= 0;
3375 pSMB
->SetupCount
= 1;
3376 pSMB
->Reserved3
= 0;
3377 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION
);
3378 byte_count
= params
+ 1 /* pad */ ;
3379 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
3380 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
3382 pSMB
->InformationLevel
= cpu_to_le16(SMB_INFO_STANDARD
);
3384 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FILE_ALL_INFO
);
3385 pSMB
->Reserved4
= 0;
3386 pSMB
->hdr
.smb_buf_length
+= byte_count
;
3387 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
3389 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3390 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3392 cFYI(1, ("Send error in QPathInfo = %d", rc
));
3393 } else { /* decode response */
3394 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
3396 if (rc
) /* BB add auto retry on EOPNOTSUPP? */
3398 else if (!legacy
&& (pSMBr
->ByteCount
< 40))
3399 rc
= -EIO
; /* bad smb */
3400 else if (legacy
&& (pSMBr
->ByteCount
< 24))
3401 rc
= -EIO
; /* 24 or 26 expected but we do not read
3403 else if (pFindData
) {
3405 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
3407 /* On legacy responses we do not read the last field,
3408 EAsize, fortunately since it varies by subdialect and
3409 also note it differs on Set vs. Get, ie two bytes or 4
3410 bytes depending but we don't care here */
3412 size
= sizeof(FILE_INFO_STANDARD
);
3414 size
= sizeof(FILE_ALL_INFO
);
3415 memcpy((char *) pFindData
,
3416 (char *) &pSMBr
->hdr
.Protocol
+
3421 cifs_buf_release(pSMB
);
3423 goto QPathInfoRetry
;
3429 CIFSSMBUnixQPathInfo(const int xid
, struct cifsTconInfo
*tcon
,
3430 const unsigned char *searchName
,
3431 FILE_UNIX_BASIC_INFO
*pFindData
,
3432 const struct nls_table
*nls_codepage
, int remap
)
3434 /* SMB_QUERY_FILE_UNIX_BASIC */
3435 TRANSACTION2_QPI_REQ
*pSMB
= NULL
;
3436 TRANSACTION2_QPI_RSP
*pSMBr
= NULL
;
3438 int bytes_returned
= 0;
3440 __u16 params
, byte_count
;
3442 cFYI(1, ("In QPathInfo (Unix) the path %s", searchName
));
3444 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
3449 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
3451 cifsConvertToUCS((__le16
*) pSMB
->FileName
, searchName
,
3452 PATH_MAX
, nls_codepage
, remap
);
3453 name_len
++; /* trailing null */
3455 } else { /* BB improve the check for buffer overruns BB */
3456 name_len
= strnlen(searchName
, PATH_MAX
);
3457 name_len
++; /* trailing null */
3458 strncpy(pSMB
->FileName
, searchName
, name_len
);
3461 params
= 2 /* level */ + 4 /* reserved */ + name_len
/* includes NUL */;
3462 pSMB
->TotalDataCount
= 0;
3463 pSMB
->MaxParameterCount
= cpu_to_le16(2);
3464 /* BB find exact max SMB PDU from sess structure BB */
3465 pSMB
->MaxDataCount
= cpu_to_le16(4000);
3466 pSMB
->MaxSetupCount
= 0;
3470 pSMB
->Reserved2
= 0;
3471 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
3472 struct smb_com_transaction2_qpi_req
, InformationLevel
) - 4);
3473 pSMB
->DataCount
= 0;
3474 pSMB
->DataOffset
= 0;
3475 pSMB
->SetupCount
= 1;
3476 pSMB
->Reserved3
= 0;
3477 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION
);
3478 byte_count
= params
+ 1 /* pad */ ;
3479 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
3480 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
3481 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC
);
3482 pSMB
->Reserved4
= 0;
3483 pSMB
->hdr
.smb_buf_length
+= byte_count
;
3484 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
3486 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3487 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3489 cFYI(1, ("Send error in QPathInfo = %d", rc
));
3490 } else { /* decode response */
3491 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
3493 if (rc
|| (pSMBr
->ByteCount
< sizeof(FILE_UNIX_BASIC_INFO
))) {
3494 cERROR(1, ("Malformed FILE_UNIX_BASIC_INFO response.\n"
3495 "Unix Extensions can be disabled on mount "
3496 "by specifying the nosfu mount option."));
3497 rc
= -EIO
; /* bad smb */
3499 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
3500 memcpy((char *) pFindData
,
3501 (char *) &pSMBr
->hdr
.Protocol
+
3503 sizeof(FILE_UNIX_BASIC_INFO
));
3506 cifs_buf_release(pSMB
);
3508 goto UnixQPathInfoRetry
;
3513 /* xid, tcon, searchName and codepage are input parms, rest are returned */
3515 CIFSFindFirst(const int xid
, struct cifsTconInfo
*tcon
,
3516 const char *searchName
,
3517 const struct nls_table
*nls_codepage
,
3519 struct cifs_search_info
*psrch_inf
, int remap
, const char dirsep
)
3521 /* level 257 SMB_ */
3522 TRANSACTION2_FFIRST_REQ
*pSMB
= NULL
;
3523 TRANSACTION2_FFIRST_RSP
*pSMBr
= NULL
;
3524 T2_FFIRST_RSP_PARMS
*parms
;
3526 int bytes_returned
= 0;
3528 __u16 params
, byte_count
;
3530 cFYI(1, ("In FindFirst for %s", searchName
));
3533 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
3538 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
3540 cifsConvertToUCS((__le16
*) pSMB
->FileName
, searchName
,
3541 PATH_MAX
, nls_codepage
, remap
);
3542 /* We can not add the asterik earlier in case
3543 it got remapped to 0xF03A as if it were part of the
3544 directory name instead of a wildcard */
3546 pSMB
->FileName
[name_len
] = dirsep
;
3547 pSMB
->FileName
[name_len
+1] = 0;
3548 pSMB
->FileName
[name_len
+2] = '*';
3549 pSMB
->FileName
[name_len
+3] = 0;
3550 name_len
+= 4; /* now the trailing null */
3551 pSMB
->FileName
[name_len
] = 0; /* null terminate just in case */
3552 pSMB
->FileName
[name_len
+1] = 0;
3554 } else { /* BB add check for overrun of SMB buf BB */
3555 name_len
= strnlen(searchName
, PATH_MAX
);
3556 /* BB fix here and in unicode clause above ie
3557 if (name_len > buffersize-header)
3558 free buffer exit; BB */
3559 strncpy(pSMB
->FileName
, searchName
, name_len
);
3560 pSMB
->FileName
[name_len
] = dirsep
;
3561 pSMB
->FileName
[name_len
+1] = '*';
3562 pSMB
->FileName
[name_len
+2] = 0;
3566 params
= 12 + name_len
/* includes null */ ;
3567 pSMB
->TotalDataCount
= 0; /* no EAs */
3568 pSMB
->MaxParameterCount
= cpu_to_le16(10);
3569 pSMB
->MaxDataCount
= cpu_to_le16((tcon
->ses
->server
->maxBuf
-
3570 MAX_CIFS_HDR_SIZE
) & 0xFFFFFF00);
3571 pSMB
->MaxSetupCount
= 0;
3575 pSMB
->Reserved2
= 0;
3576 byte_count
= params
+ 1 /* pad */ ;
3577 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
3578 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
3579 pSMB
->ParameterOffset
= cpu_to_le16(
3580 offsetof(struct smb_com_transaction2_ffirst_req
, SearchAttributes
)
3582 pSMB
->DataCount
= 0;
3583 pSMB
->DataOffset
= 0;
3584 pSMB
->SetupCount
= 1; /* one byte, no need to make endian neutral */
3585 pSMB
->Reserved3
= 0;
3586 pSMB
->SubCommand
= cpu_to_le16(TRANS2_FIND_FIRST
);
3587 pSMB
->SearchAttributes
=
3588 cpu_to_le16(ATTR_READONLY
| ATTR_HIDDEN
| ATTR_SYSTEM
|
3590 pSMB
->SearchCount
= cpu_to_le16(CIFSMaxBufSize
/sizeof(FILE_UNIX_INFO
));
3591 pSMB
->SearchFlags
= cpu_to_le16(CIFS_SEARCH_CLOSE_AT_END
|
3592 CIFS_SEARCH_RETURN_RESUME
);
3593 pSMB
->InformationLevel
= cpu_to_le16(psrch_inf
->info_level
);
3595 /* BB what should we set StorageType to? Does it matter? BB */
3596 pSMB
->SearchStorageType
= 0;
3597 pSMB
->hdr
.smb_buf_length
+= byte_count
;
3598 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
3600 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3601 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3602 cifs_stats_inc(&tcon
->num_ffirst
);
3604 if (rc
) {/* BB add logic to retry regular search if Unix search
3605 rejected unexpectedly by server */
3606 /* BB Add code to handle unsupported level rc */
3607 cFYI(1, ("Error in FindFirst = %d", rc
));
3609 cifs_buf_release(pSMB
);
3611 /* BB eventually could optimize out free and realloc of buf */
3614 goto findFirstRetry
;
3615 } else { /* decode response */
3616 /* BB remember to free buffer if error BB */
3617 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
3619 if (pSMBr
->hdr
.Flags2
& SMBFLG2_UNICODE
)
3620 psrch_inf
->unicode
= true;
3622 psrch_inf
->unicode
= false;
3624 psrch_inf
->ntwrk_buf_start
= (char *)pSMBr
;
3625 psrch_inf
->smallBuf
= 0;
3626 psrch_inf
->srch_entries_start
=
3627 (char *) &pSMBr
->hdr
.Protocol
+
3628 le16_to_cpu(pSMBr
->t2
.DataOffset
);
3629 parms
= (T2_FFIRST_RSP_PARMS
*)((char *) &pSMBr
->hdr
.Protocol
+
3630 le16_to_cpu(pSMBr
->t2
.ParameterOffset
));
3632 if (parms
->EndofSearch
)
3633 psrch_inf
->endOfSearch
= true;
3635 psrch_inf
->endOfSearch
= false;
3637 psrch_inf
->entries_in_buffer
=
3638 le16_to_cpu(parms
->SearchCount
);
3639 psrch_inf
->index_of_last_entry
= 2 /* skip . and .. */ +
3640 psrch_inf
->entries_in_buffer
;
3641 *pnetfid
= parms
->SearchHandle
;
3643 cifs_buf_release(pSMB
);
3650 int CIFSFindNext(const int xid
, struct cifsTconInfo
*tcon
,
3651 __u16 searchHandle
, struct cifs_search_info
*psrch_inf
)
3653 TRANSACTION2_FNEXT_REQ
*pSMB
= NULL
;
3654 TRANSACTION2_FNEXT_RSP
*pSMBr
= NULL
;
3655 T2_FNEXT_RSP_PARMS
*parms
;
3656 char *response_data
;
3658 int bytes_returned
, name_len
;
3659 __u16 params
, byte_count
;
3661 cFYI(1, ("In FindNext"));
3663 if (psrch_inf
->endOfSearch
)
3666 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
3671 params
= 14; /* includes 2 bytes of null string, converted to LE below*/
3673 pSMB
->TotalDataCount
= 0; /* no EAs */
3674 pSMB
->MaxParameterCount
= cpu_to_le16(8);
3675 pSMB
->MaxDataCount
=
3676 cpu_to_le16((tcon
->ses
->server
->maxBuf
- MAX_CIFS_HDR_SIZE
) &
3678 pSMB
->MaxSetupCount
= 0;
3682 pSMB
->Reserved2
= 0;
3683 pSMB
->ParameterOffset
= cpu_to_le16(
3684 offsetof(struct smb_com_transaction2_fnext_req
,SearchHandle
) - 4);
3685 pSMB
->DataCount
= 0;
3686 pSMB
->DataOffset
= 0;
3687 pSMB
->SetupCount
= 1;
3688 pSMB
->Reserved3
= 0;
3689 pSMB
->SubCommand
= cpu_to_le16(TRANS2_FIND_NEXT
);
3690 pSMB
->SearchHandle
= searchHandle
; /* always kept as le */
3692 cpu_to_le16(CIFSMaxBufSize
/ sizeof(FILE_UNIX_INFO
));
3693 pSMB
->InformationLevel
= cpu_to_le16(psrch_inf
->info_level
);
3694 pSMB
->ResumeKey
= psrch_inf
->resume_key
;
3696 cpu_to_le16(CIFS_SEARCH_CLOSE_AT_END
| CIFS_SEARCH_RETURN_RESUME
);
3698 name_len
= psrch_inf
->resume_name_len
;
3700 if (name_len
< PATH_MAX
) {
3701 memcpy(pSMB
->ResumeFileName
, psrch_inf
->presume_name
, name_len
);
3702 byte_count
+= name_len
;
3703 /* 14 byte parm len above enough for 2 byte null terminator */
3704 pSMB
->ResumeFileName
[name_len
] = 0;
3705 pSMB
->ResumeFileName
[name_len
+1] = 0;
3708 goto FNext2_err_exit
;
3710 byte_count
= params
+ 1 /* pad */ ;
3711 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
3712 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
3713 pSMB
->hdr
.smb_buf_length
+= byte_count
;
3714 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
3716 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3717 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3718 cifs_stats_inc(&tcon
->num_fnext
);
3721 psrch_inf
->endOfSearch
= true;
3722 cifs_buf_release(pSMB
);
3723 rc
= 0; /* search probably was closed at end of search*/
3725 cFYI(1, ("FindNext returned = %d", rc
));
3726 } else { /* decode response */
3727 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
3730 /* BB fixme add lock for file (srch_info) struct here */
3731 if (pSMBr
->hdr
.Flags2
& SMBFLG2_UNICODE
)
3732 psrch_inf
->unicode
= true;
3734 psrch_inf
->unicode
= false;
3735 response_data
= (char *) &pSMBr
->hdr
.Protocol
+
3736 le16_to_cpu(pSMBr
->t2
.ParameterOffset
);
3737 parms
= (T2_FNEXT_RSP_PARMS
*)response_data
;
3738 response_data
= (char *)&pSMBr
->hdr
.Protocol
+
3739 le16_to_cpu(pSMBr
->t2
.DataOffset
);
3740 if (psrch_inf
->smallBuf
)
3741 cifs_small_buf_release(
3742 psrch_inf
->ntwrk_buf_start
);
3744 cifs_buf_release(psrch_inf
->ntwrk_buf_start
);
3745 psrch_inf
->srch_entries_start
= response_data
;
3746 psrch_inf
->ntwrk_buf_start
= (char *)pSMB
;
3747 psrch_inf
->smallBuf
= 0;
3748 if (parms
->EndofSearch
)
3749 psrch_inf
->endOfSearch
= true;
3751 psrch_inf
->endOfSearch
= false;
3752 psrch_inf
->entries_in_buffer
=
3753 le16_to_cpu(parms
->SearchCount
);
3754 psrch_inf
->index_of_last_entry
+=
3755 psrch_inf
->entries_in_buffer
;
3756 /* cFYI(1,("fnxt2 entries in buf %d index_of_last %d",
3757 psrch_inf->entries_in_buffer, psrch_inf->index_of_last_entry)); */
3759 /* BB fixme add unlock here */
3764 /* BB On error, should we leave previous search buf (and count and
3765 last entry fields) intact or free the previous one? */
3767 /* Note: On -EAGAIN error only caller can retry on handle based calls
3768 since file handle passed in no longer valid */
3771 cifs_buf_release(pSMB
);
3776 CIFSFindClose(const int xid
, struct cifsTconInfo
*tcon
,
3777 const __u16 searchHandle
)
3780 FINDCLOSE_REQ
*pSMB
= NULL
;
3782 cFYI(1, ("In CIFSSMBFindClose"));
3783 rc
= small_smb_init(SMB_COM_FIND_CLOSE2
, 1, tcon
, (void **)&pSMB
);
3785 /* no sense returning error if session restarted
3786 as file handle has been closed */
3792 pSMB
->FileID
= searchHandle
;
3793 pSMB
->ByteCount
= 0;
3794 rc
= SendReceiveNoRsp(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
, 0);
3796 cERROR(1, ("Send error in FindClose = %d", rc
));
3798 cifs_stats_inc(&tcon
->num_fclose
);
3800 /* Since session is dead, search handle closed on server already */
3808 CIFSGetSrvInodeNumber(const int xid
, struct cifsTconInfo
*tcon
,
3809 const unsigned char *searchName
,
3810 __u64
*inode_number
,
3811 const struct nls_table
*nls_codepage
, int remap
)
3814 TRANSACTION2_QPI_REQ
*pSMB
= NULL
;
3815 TRANSACTION2_QPI_RSP
*pSMBr
= NULL
;
3816 int name_len
, bytes_returned
;
3817 __u16 params
, byte_count
;
3819 cFYI(1, ("In GetSrvInodeNum for %s", searchName
));
3823 GetInodeNumberRetry
:
3824 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
3829 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
3831 cifsConvertToUCS((__le16
*) pSMB
->FileName
, searchName
,
3832 PATH_MAX
, nls_codepage
, remap
);
3833 name_len
++; /* trailing null */
3835 } else { /* BB improve the check for buffer overruns BB */
3836 name_len
= strnlen(searchName
, PATH_MAX
);
3837 name_len
++; /* trailing null */
3838 strncpy(pSMB
->FileName
, searchName
, name_len
);
3841 params
= 2 /* level */ + 4 /* rsrvd */ + name_len
/* incl null */ ;
3842 pSMB
->TotalDataCount
= 0;
3843 pSMB
->MaxParameterCount
= cpu_to_le16(2);
3844 /* BB find exact max data count below from sess structure BB */
3845 pSMB
->MaxDataCount
= cpu_to_le16(4000);
3846 pSMB
->MaxSetupCount
= 0;
3850 pSMB
->Reserved2
= 0;
3851 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
3852 struct smb_com_transaction2_qpi_req
, InformationLevel
) - 4);
3853 pSMB
->DataCount
= 0;
3854 pSMB
->DataOffset
= 0;
3855 pSMB
->SetupCount
= 1;
3856 pSMB
->Reserved3
= 0;
3857 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION
);
3858 byte_count
= params
+ 1 /* pad */ ;
3859 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
3860 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
3861 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FILE_INTERNAL_INFO
);
3862 pSMB
->Reserved4
= 0;
3863 pSMB
->hdr
.smb_buf_length
+= byte_count
;
3864 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
3866 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3867 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3869 cFYI(1, ("error %d in QueryInternalInfo", rc
));
3871 /* decode response */
3872 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
3873 if (rc
|| (pSMBr
->ByteCount
< 2))
3874 /* BB also check enough total bytes returned */
3875 /* If rc should we check for EOPNOSUPP and
3876 disable the srvino flag? or in caller? */
3877 rc
= -EIO
; /* bad smb */
3879 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
3880 __u16 count
= le16_to_cpu(pSMBr
->t2
.DataCount
);
3881 struct file_internal_info
*pfinfo
;
3882 /* BB Do we need a cast or hash here ? */
3884 cFYI(1, ("Illegal size ret in QryIntrnlInf"));
3886 goto GetInodeNumOut
;
3888 pfinfo
= (struct file_internal_info
*)
3889 (data_offset
+ (char *) &pSMBr
->hdr
.Protocol
);
3890 *inode_number
= pfinfo
->UniqueId
;
3894 cifs_buf_release(pSMB
);
3896 goto GetInodeNumberRetry
;
3900 /* parses DFS refferal V3 structure
3901 * caller is responsible for freeing target_nodes
3904 * on failure - errno
3907 parse_DFS_referrals(TRANSACTION2_GET_DFS_REFER_RSP
*pSMBr
,
3908 unsigned int *num_of_nodes
,
3909 struct dfs_info3_param
**target_nodes
,
3910 const struct nls_table
*nls_codepage
)
3915 struct dfs_referral_level_3
*ref
;
3917 if (pSMBr
->hdr
.Flags2
& SMBFLG2_UNICODE
)
3921 *num_of_nodes
= le16_to_cpu(pSMBr
->NumberOfReferrals
);
3923 if (*num_of_nodes
< 1) {
3924 cERROR(1, ("num_referrals: must be at least > 0,"
3925 "but we get num_referrals = %d\n", *num_of_nodes
));
3927 goto parse_DFS_referrals_exit
;
3930 ref
= (struct dfs_referral_level_3
*) &(pSMBr
->referrals
);
3931 if (ref
->VersionNumber
!= cpu_to_le16(3)) {
3932 cERROR(1, ("Referrals of V%d version are not supported,"
3933 "should be V3", le16_to_cpu(ref
->VersionNumber
)));
3935 goto parse_DFS_referrals_exit
;
3938 /* get the upper boundary of the resp buffer */
3939 data_end
= (char *)(&(pSMBr
->PathConsumed
)) +
3940 le16_to_cpu(pSMBr
->t2
.DataCount
);
3942 cFYI(1, ("num_referrals: %d dfs flags: 0x%x ... \n",
3944 le16_to_cpu(pSMBr
->DFSFlags
)));
3946 *target_nodes
= kzalloc(sizeof(struct dfs_info3_param
) *
3947 *num_of_nodes
, GFP_KERNEL
);
3948 if (*target_nodes
== NULL
) {
3949 cERROR(1, ("Failed to allocate buffer for target_nodes\n"));
3951 goto parse_DFS_referrals_exit
;
3954 /* collect neccessary data from referrals */
3955 for (i
= 0; i
< *num_of_nodes
; i
++) {
3958 struct dfs_info3_param
*node
= (*target_nodes
)+i
;
3960 node
->flags
= le16_to_cpu(pSMBr
->DFSFlags
);
3961 node
->path_consumed
= le16_to_cpu(pSMBr
->PathConsumed
);
3962 node
->server_type
= le16_to_cpu(ref
->ServerType
);
3963 node
->ref_flag
= le16_to_cpu(ref
->ReferralEntryFlags
);
3966 temp
= (char *)ref
+ le16_to_cpu(ref
->DfsPathOffset
);
3967 max_len
= data_end
- temp
;
3968 rc
= cifs_strncpy_to_host(&(node
->path_name
), temp
,
3969 max_len
, is_unicode
, nls_codepage
);
3971 goto parse_DFS_referrals_exit
;
3973 /* copy link target UNC */
3974 temp
= (char *)ref
+ le16_to_cpu(ref
->NetworkAddressOffset
);
3975 max_len
= data_end
- temp
;
3976 rc
= cifs_strncpy_to_host(&(node
->node_name
), temp
,
3977 max_len
, is_unicode
, nls_codepage
);
3979 goto parse_DFS_referrals_exit
;
3981 ref
+= le16_to_cpu(ref
->Size
);
3984 parse_DFS_referrals_exit
:
3986 free_dfs_info_array(*target_nodes
, *num_of_nodes
);
3987 *target_nodes
= NULL
;
3994 CIFSGetDFSRefer(const int xid
, struct cifsSesInfo
*ses
,
3995 const unsigned char *searchName
,
3996 struct dfs_info3_param
**target_nodes
,
3997 unsigned int *num_of_nodes
,
3998 const struct nls_table
*nls_codepage
, int remap
)
4000 /* TRANS2_GET_DFS_REFERRAL */
4001 TRANSACTION2_GET_DFS_REFER_REQ
*pSMB
= NULL
;
4002 TRANSACTION2_GET_DFS_REFER_RSP
*pSMBr
= NULL
;
4006 __u16 params
, byte_count
;
4008 *target_nodes
= NULL
;
4010 cFYI(1, ("In GetDFSRefer the path %s", searchName
));
4014 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, NULL
, (void **) &pSMB
,
4019 /* server pointer checked in called function,
4020 but should never be null here anyway */
4021 pSMB
->hdr
.Mid
= GetNextMid(ses
->server
);
4022 pSMB
->hdr
.Tid
= ses
->ipc_tid
;
4023 pSMB
->hdr
.Uid
= ses
->Suid
;
4024 if (ses
->capabilities
& CAP_STATUS32
)
4025 pSMB
->hdr
.Flags2
|= SMBFLG2_ERR_STATUS
;
4026 if (ses
->capabilities
& CAP_DFS
)
4027 pSMB
->hdr
.Flags2
|= SMBFLG2_DFS
;
4029 if (ses
->capabilities
& CAP_UNICODE
) {
4030 pSMB
->hdr
.Flags2
|= SMBFLG2_UNICODE
;
4032 cifsConvertToUCS((__le16
*) pSMB
->RequestFileName
,
4033 searchName
, PATH_MAX
, nls_codepage
, remap
);
4034 name_len
++; /* trailing null */
4036 } else { /* BB improve the check for buffer overruns BB */
4037 name_len
= strnlen(searchName
, PATH_MAX
);
4038 name_len
++; /* trailing null */
4039 strncpy(pSMB
->RequestFileName
, searchName
, name_len
);
4043 if (ses
->server
->secMode
&
4044 (SECMODE_SIGN_REQUIRED
| SECMODE_SIGN_ENABLED
))
4045 pSMB
->hdr
.Flags2
|= SMBFLG2_SECURITY_SIGNATURE
;
4048 pSMB
->hdr
.Uid
= ses
->Suid
;
4050 params
= 2 /* level */ + name_len
/*includes null */ ;
4051 pSMB
->TotalDataCount
= 0;
4052 pSMB
->DataCount
= 0;
4053 pSMB
->DataOffset
= 0;
4054 pSMB
->MaxParameterCount
= 0;
4055 /* BB find exact max SMB PDU from sess structure BB */
4056 pSMB
->MaxDataCount
= cpu_to_le16(4000);
4057 pSMB
->MaxSetupCount
= 0;
4061 pSMB
->Reserved2
= 0;
4062 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
4063 struct smb_com_transaction2_get_dfs_refer_req
, MaxReferralLevel
) - 4);
4064 pSMB
->SetupCount
= 1;
4065 pSMB
->Reserved3
= 0;
4066 pSMB
->SubCommand
= cpu_to_le16(TRANS2_GET_DFS_REFERRAL
);
4067 byte_count
= params
+ 3 /* pad */ ;
4068 pSMB
->ParameterCount
= cpu_to_le16(params
);
4069 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
4070 pSMB
->MaxReferralLevel
= cpu_to_le16(3);
4071 pSMB
->hdr
.smb_buf_length
+= byte_count
;
4072 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4074 rc
= SendReceive(xid
, ses
, (struct smb_hdr
*) pSMB
,
4075 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4077 cFYI(1, ("Send error in GetDFSRefer = %d", rc
));
4080 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
4082 /* BB Also check if enough total bytes returned? */
4083 if (rc
|| (pSMBr
->ByteCount
< 17)) {
4084 rc
= -EIO
; /* bad smb */
4088 cFYI(1, ("Decoding GetDFSRefer response BCC: %d Offset %d",
4090 le16_to_cpu(pSMBr
->t2
.DataOffset
)));
4092 /* parse returned result into more usable form */
4093 rc
= parse_DFS_referrals(pSMBr
, num_of_nodes
,
4094 target_nodes
, nls_codepage
);
4097 cifs_buf_release(pSMB
);
4105 /* Query File System Info such as free space to old servers such as Win 9x */
4107 SMBOldQFSInfo(const int xid
, struct cifsTconInfo
*tcon
, struct kstatfs
*FSData
)
4109 /* level 0x01 SMB_QUERY_FILE_SYSTEM_INFO */
4110 TRANSACTION2_QFSI_REQ
*pSMB
= NULL
;
4111 TRANSACTION2_QFSI_RSP
*pSMBr
= NULL
;
4112 FILE_SYSTEM_ALLOC_INFO
*response_data
;
4114 int bytes_returned
= 0;
4115 __u16 params
, byte_count
;
4117 cFYI(1, ("OldQFSInfo"));
4119 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4124 params
= 2; /* level */
4125 pSMB
->TotalDataCount
= 0;
4126 pSMB
->MaxParameterCount
= cpu_to_le16(2);
4127 pSMB
->MaxDataCount
= cpu_to_le16(1000);
4128 pSMB
->MaxSetupCount
= 0;
4132 pSMB
->Reserved2
= 0;
4133 byte_count
= params
+ 1 /* pad */ ;
4134 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
4135 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
4136 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
4137 struct smb_com_transaction2_qfsi_req
, InformationLevel
) - 4);
4138 pSMB
->DataCount
= 0;
4139 pSMB
->DataOffset
= 0;
4140 pSMB
->SetupCount
= 1;
4141 pSMB
->Reserved3
= 0;
4142 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_FS_INFORMATION
);
4143 pSMB
->InformationLevel
= cpu_to_le16(SMB_INFO_ALLOCATION
);
4144 pSMB
->hdr
.smb_buf_length
+= byte_count
;
4145 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4147 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4148 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4150 cFYI(1, ("Send error in QFSInfo = %d", rc
));
4151 } else { /* decode response */
4152 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
4154 if (rc
|| (pSMBr
->ByteCount
< 18))
4155 rc
= -EIO
; /* bad smb */
4157 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
4158 cFYI(1, ("qfsinf resp BCC: %d Offset %d",
4159 pSMBr
->ByteCount
, data_offset
));
4161 response_data
= (FILE_SYSTEM_ALLOC_INFO
*)
4162 (((char *) &pSMBr
->hdr
.Protocol
) + data_offset
);
4164 le16_to_cpu(response_data
->BytesPerSector
) *
4165 le32_to_cpu(response_data
->
4166 SectorsPerAllocationUnit
);
4168 le32_to_cpu(response_data
->TotalAllocationUnits
);
4169 FSData
->f_bfree
= FSData
->f_bavail
=
4170 le32_to_cpu(response_data
->FreeAllocationUnits
);
4172 ("Blocks: %lld Free: %lld Block size %ld",
4173 (unsigned long long)FSData
->f_blocks
,
4174 (unsigned long long)FSData
->f_bfree
,
4178 cifs_buf_release(pSMB
);
4181 goto oldQFSInfoRetry
;
4187 CIFSSMBQFSInfo(const int xid
, struct cifsTconInfo
*tcon
, struct kstatfs
*FSData
)
4189 /* level 0x103 SMB_QUERY_FILE_SYSTEM_INFO */
4190 TRANSACTION2_QFSI_REQ
*pSMB
= NULL
;
4191 TRANSACTION2_QFSI_RSP
*pSMBr
= NULL
;
4192 FILE_SYSTEM_INFO
*response_data
;
4194 int bytes_returned
= 0;
4195 __u16 params
, byte_count
;
4197 cFYI(1, ("In QFSInfo"));
4199 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4204 params
= 2; /* level */
4205 pSMB
->TotalDataCount
= 0;
4206 pSMB
->MaxParameterCount
= cpu_to_le16(2);
4207 pSMB
->MaxDataCount
= cpu_to_le16(1000);
4208 pSMB
->MaxSetupCount
= 0;
4212 pSMB
->Reserved2
= 0;
4213 byte_count
= params
+ 1 /* pad */ ;
4214 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
4215 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
4216 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
4217 struct smb_com_transaction2_qfsi_req
, InformationLevel
) - 4);
4218 pSMB
->DataCount
= 0;
4219 pSMB
->DataOffset
= 0;
4220 pSMB
->SetupCount
= 1;
4221 pSMB
->Reserved3
= 0;
4222 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_FS_INFORMATION
);
4223 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FS_SIZE_INFO
);
4224 pSMB
->hdr
.smb_buf_length
+= byte_count
;
4225 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4227 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4228 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4230 cFYI(1, ("Send error in QFSInfo = %d", rc
));
4231 } else { /* decode response */
4232 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
4234 if (rc
|| (pSMBr
->ByteCount
< 24))
4235 rc
= -EIO
; /* bad smb */
4237 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
4241 *) (((char *) &pSMBr
->hdr
.Protocol
) +
4244 le32_to_cpu(response_data
->BytesPerSector
) *
4245 le32_to_cpu(response_data
->
4246 SectorsPerAllocationUnit
);
4248 le64_to_cpu(response_data
->TotalAllocationUnits
);
4249 FSData
->f_bfree
= FSData
->f_bavail
=
4250 le64_to_cpu(response_data
->FreeAllocationUnits
);
4252 ("Blocks: %lld Free: %lld Block size %ld",
4253 (unsigned long long)FSData
->f_blocks
,
4254 (unsigned long long)FSData
->f_bfree
,
4258 cifs_buf_release(pSMB
);
4267 CIFSSMBQFSAttributeInfo(const int xid
, struct cifsTconInfo
*tcon
)
4269 /* level 0x105 SMB_QUERY_FILE_SYSTEM_INFO */
4270 TRANSACTION2_QFSI_REQ
*pSMB
= NULL
;
4271 TRANSACTION2_QFSI_RSP
*pSMBr
= NULL
;
4272 FILE_SYSTEM_ATTRIBUTE_INFO
*response_data
;
4274 int bytes_returned
= 0;
4275 __u16 params
, byte_count
;
4277 cFYI(1, ("In QFSAttributeInfo"));
4279 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4284 params
= 2; /* level */
4285 pSMB
->TotalDataCount
= 0;
4286 pSMB
->MaxParameterCount
= cpu_to_le16(2);
4287 /* BB find exact max SMB PDU from sess structure BB */
4288 pSMB
->MaxDataCount
= cpu_to_le16(1000);
4289 pSMB
->MaxSetupCount
= 0;
4293 pSMB
->Reserved2
= 0;
4294 byte_count
= params
+ 1 /* pad */ ;
4295 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
4296 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
4297 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
4298 struct smb_com_transaction2_qfsi_req
, InformationLevel
) - 4);
4299 pSMB
->DataCount
= 0;
4300 pSMB
->DataOffset
= 0;
4301 pSMB
->SetupCount
= 1;
4302 pSMB
->Reserved3
= 0;
4303 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_FS_INFORMATION
);
4304 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FS_ATTRIBUTE_INFO
);
4305 pSMB
->hdr
.smb_buf_length
+= byte_count
;
4306 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4308 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4309 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4311 cERROR(1, ("Send error in QFSAttributeInfo = %d", rc
));
4312 } else { /* decode response */
4313 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
4315 if (rc
|| (pSMBr
->ByteCount
< 13)) {
4316 /* BB also check if enough bytes returned */
4317 rc
= -EIO
; /* bad smb */
4319 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
4321 (FILE_SYSTEM_ATTRIBUTE_INFO
4322 *) (((char *) &pSMBr
->hdr
.Protocol
) +
4324 memcpy(&tcon
->fsAttrInfo
, response_data
,
4325 sizeof(FILE_SYSTEM_ATTRIBUTE_INFO
));
4328 cifs_buf_release(pSMB
);
4331 goto QFSAttributeRetry
;
4337 CIFSSMBQFSDeviceInfo(const int xid
, struct cifsTconInfo
*tcon
)
4339 /* level 0x104 SMB_QUERY_FILE_SYSTEM_INFO */
4340 TRANSACTION2_QFSI_REQ
*pSMB
= NULL
;
4341 TRANSACTION2_QFSI_RSP
*pSMBr
= NULL
;
4342 FILE_SYSTEM_DEVICE_INFO
*response_data
;
4344 int bytes_returned
= 0;
4345 __u16 params
, byte_count
;
4347 cFYI(1, ("In QFSDeviceInfo"));
4349 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4354 params
= 2; /* level */
4355 pSMB
->TotalDataCount
= 0;
4356 pSMB
->MaxParameterCount
= cpu_to_le16(2);
4357 /* BB find exact max SMB PDU from sess structure BB */
4358 pSMB
->MaxDataCount
= cpu_to_le16(1000);
4359 pSMB
->MaxSetupCount
= 0;
4363 pSMB
->Reserved2
= 0;
4364 byte_count
= params
+ 1 /* pad */ ;
4365 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
4366 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
4367 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
4368 struct smb_com_transaction2_qfsi_req
, InformationLevel
) - 4);
4370 pSMB
->DataCount
= 0;
4371 pSMB
->DataOffset
= 0;
4372 pSMB
->SetupCount
= 1;
4373 pSMB
->Reserved3
= 0;
4374 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_FS_INFORMATION
);
4375 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FS_DEVICE_INFO
);
4376 pSMB
->hdr
.smb_buf_length
+= byte_count
;
4377 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4379 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4380 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4382 cFYI(1, ("Send error in QFSDeviceInfo = %d", rc
));
4383 } else { /* decode response */
4384 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
4386 if (rc
|| (pSMBr
->ByteCount
< sizeof(FILE_SYSTEM_DEVICE_INFO
)))
4387 rc
= -EIO
; /* bad smb */
4389 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
4391 (FILE_SYSTEM_DEVICE_INFO
*)
4392 (((char *) &pSMBr
->hdr
.Protocol
) +
4394 memcpy(&tcon
->fsDevInfo
, response_data
,
4395 sizeof(FILE_SYSTEM_DEVICE_INFO
));
4398 cifs_buf_release(pSMB
);
4401 goto QFSDeviceRetry
;
4407 CIFSSMBQFSUnixInfo(const int xid
, struct cifsTconInfo
*tcon
)
4409 /* level 0x200 SMB_QUERY_CIFS_UNIX_INFO */
4410 TRANSACTION2_QFSI_REQ
*pSMB
= NULL
;
4411 TRANSACTION2_QFSI_RSP
*pSMBr
= NULL
;
4412 FILE_SYSTEM_UNIX_INFO
*response_data
;
4414 int bytes_returned
= 0;
4415 __u16 params
, byte_count
;
4417 cFYI(1, ("In QFSUnixInfo"));
4419 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4424 params
= 2; /* level */
4425 pSMB
->TotalDataCount
= 0;
4426 pSMB
->DataCount
= 0;
4427 pSMB
->DataOffset
= 0;
4428 pSMB
->MaxParameterCount
= cpu_to_le16(2);
4429 /* BB find exact max SMB PDU from sess structure BB */
4430 pSMB
->MaxDataCount
= cpu_to_le16(100);
4431 pSMB
->MaxSetupCount
= 0;
4435 pSMB
->Reserved2
= 0;
4436 byte_count
= params
+ 1 /* pad */ ;
4437 pSMB
->ParameterCount
= cpu_to_le16(params
);
4438 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
4439 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(struct
4440 smb_com_transaction2_qfsi_req
, InformationLevel
) - 4);
4441 pSMB
->SetupCount
= 1;
4442 pSMB
->Reserved3
= 0;
4443 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_FS_INFORMATION
);
4444 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_CIFS_UNIX_INFO
);
4445 pSMB
->hdr
.smb_buf_length
+= byte_count
;
4446 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4448 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4449 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4451 cERROR(1, ("Send error in QFSUnixInfo = %d", rc
));
4452 } else { /* decode response */
4453 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
4455 if (rc
|| (pSMBr
->ByteCount
< 13)) {
4456 rc
= -EIO
; /* bad smb */
4458 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
4460 (FILE_SYSTEM_UNIX_INFO
4461 *) (((char *) &pSMBr
->hdr
.Protocol
) +
4463 memcpy(&tcon
->fsUnixInfo
, response_data
,
4464 sizeof(FILE_SYSTEM_UNIX_INFO
));
4467 cifs_buf_release(pSMB
);
4477 CIFSSMBSetFSUnixInfo(const int xid
, struct cifsTconInfo
*tcon
, __u64 cap
)
4479 /* level 0x200 SMB_SET_CIFS_UNIX_INFO */
4480 TRANSACTION2_SETFSI_REQ
*pSMB
= NULL
;
4481 TRANSACTION2_SETFSI_RSP
*pSMBr
= NULL
;
4483 int bytes_returned
= 0;
4484 __u16 params
, param_offset
, offset
, byte_count
;
4486 cFYI(1, ("In SETFSUnixInfo"));
4488 /* BB switch to small buf init to save memory */
4489 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4494 params
= 4; /* 2 bytes zero followed by info level. */
4495 pSMB
->MaxSetupCount
= 0;
4499 pSMB
->Reserved2
= 0;
4500 param_offset
= offsetof(struct smb_com_transaction2_setfsi_req
, FileNum
)
4502 offset
= param_offset
+ params
;
4504 pSMB
->MaxParameterCount
= cpu_to_le16(4);
4505 /* BB find exact max SMB PDU from sess structure BB */
4506 pSMB
->MaxDataCount
= cpu_to_le16(100);
4507 pSMB
->SetupCount
= 1;
4508 pSMB
->Reserved3
= 0;
4509 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_FS_INFORMATION
);
4510 byte_count
= 1 /* pad */ + params
+ 12;
4512 pSMB
->DataCount
= cpu_to_le16(12);
4513 pSMB
->ParameterCount
= cpu_to_le16(params
);
4514 pSMB
->TotalDataCount
= pSMB
->DataCount
;
4515 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
4516 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
4517 pSMB
->DataOffset
= cpu_to_le16(offset
);
4521 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_CIFS_UNIX_INFO
);
4524 pSMB
->ClientUnixMajor
= cpu_to_le16(CIFS_UNIX_MAJOR_VERSION
);
4525 pSMB
->ClientUnixMinor
= cpu_to_le16(CIFS_UNIX_MINOR_VERSION
);
4526 pSMB
->ClientUnixCap
= cpu_to_le64(cap
);
4528 pSMB
->hdr
.smb_buf_length
+= byte_count
;
4529 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4531 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4532 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4534 cERROR(1, ("Send error in SETFSUnixInfo = %d", rc
));
4535 } else { /* decode response */
4536 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
4538 rc
= -EIO
; /* bad smb */
4540 cifs_buf_release(pSMB
);
4543 goto SETFSUnixRetry
;
4551 CIFSSMBQFSPosixInfo(const int xid
, struct cifsTconInfo
*tcon
,
4552 struct kstatfs
*FSData
)
4554 /* level 0x201 SMB_QUERY_CIFS_POSIX_INFO */
4555 TRANSACTION2_QFSI_REQ
*pSMB
= NULL
;
4556 TRANSACTION2_QFSI_RSP
*pSMBr
= NULL
;
4557 FILE_SYSTEM_POSIX_INFO
*response_data
;
4559 int bytes_returned
= 0;
4560 __u16 params
, byte_count
;
4562 cFYI(1, ("In QFSPosixInfo"));
4564 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4569 params
= 2; /* level */
4570 pSMB
->TotalDataCount
= 0;
4571 pSMB
->DataCount
= 0;
4572 pSMB
->DataOffset
= 0;
4573 pSMB
->MaxParameterCount
= cpu_to_le16(2);
4574 /* BB find exact max SMB PDU from sess structure BB */
4575 pSMB
->MaxDataCount
= cpu_to_le16(100);
4576 pSMB
->MaxSetupCount
= 0;
4580 pSMB
->Reserved2
= 0;
4581 byte_count
= params
+ 1 /* pad */ ;
4582 pSMB
->ParameterCount
= cpu_to_le16(params
);
4583 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
4584 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(struct
4585 smb_com_transaction2_qfsi_req
, InformationLevel
) - 4);
4586 pSMB
->SetupCount
= 1;
4587 pSMB
->Reserved3
= 0;
4588 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_FS_INFORMATION
);
4589 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_POSIX_FS_INFO
);
4590 pSMB
->hdr
.smb_buf_length
+= byte_count
;
4591 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4593 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4594 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4596 cFYI(1, ("Send error in QFSUnixInfo = %d", rc
));
4597 } else { /* decode response */
4598 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
4600 if (rc
|| (pSMBr
->ByteCount
< 13)) {
4601 rc
= -EIO
; /* bad smb */
4603 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
4605 (FILE_SYSTEM_POSIX_INFO
4606 *) (((char *) &pSMBr
->hdr
.Protocol
) +
4609 le32_to_cpu(response_data
->BlockSize
);
4611 le64_to_cpu(response_data
->TotalBlocks
);
4613 le64_to_cpu(response_data
->BlocksAvail
);
4614 if (response_data
->UserBlocksAvail
== cpu_to_le64(-1)) {
4615 FSData
->f_bavail
= FSData
->f_bfree
;
4618 le64_to_cpu(response_data
->UserBlocksAvail
);
4620 if (response_data
->TotalFileNodes
!= cpu_to_le64(-1))
4622 le64_to_cpu(response_data
->TotalFileNodes
);
4623 if (response_data
->FreeFileNodes
!= cpu_to_le64(-1))
4625 le64_to_cpu(response_data
->FreeFileNodes
);
4628 cifs_buf_release(pSMB
);
4637 /* We can not use write of zero bytes trick to
4638 set file size due to need for large file support. Also note that
4639 this SetPathInfo is preferred to SetFileInfo based method in next
4640 routine which is only needed to work around a sharing violation bug
4641 in Samba which this routine can run into */
4644 CIFSSMBSetEOF(const int xid
, struct cifsTconInfo
*tcon
, const char *fileName
,
4645 __u64 size
, bool SetAllocation
,
4646 const struct nls_table
*nls_codepage
, int remap
)
4648 struct smb_com_transaction2_spi_req
*pSMB
= NULL
;
4649 struct smb_com_transaction2_spi_rsp
*pSMBr
= NULL
;
4650 struct file_end_of_file_info
*parm_data
;
4653 int bytes_returned
= 0;
4654 __u16 params
, byte_count
, data_count
, param_offset
, offset
;
4656 cFYI(1, ("In SetEOF"));
4658 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4663 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
4665 cifsConvertToUCS((__le16
*) pSMB
->FileName
, fileName
,
4666 PATH_MAX
, nls_codepage
, remap
);
4667 name_len
++; /* trailing null */
4669 } else { /* BB improve the check for buffer overruns BB */
4670 name_len
= strnlen(fileName
, PATH_MAX
);
4671 name_len
++; /* trailing null */
4672 strncpy(pSMB
->FileName
, fileName
, name_len
);
4674 params
= 6 + name_len
;
4675 data_count
= sizeof(struct file_end_of_file_info
);
4676 pSMB
->MaxParameterCount
= cpu_to_le16(2);
4677 pSMB
->MaxDataCount
= cpu_to_le16(4100);
4678 pSMB
->MaxSetupCount
= 0;
4682 pSMB
->Reserved2
= 0;
4683 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
4684 InformationLevel
) - 4;
4685 offset
= param_offset
+ params
;
4686 if (SetAllocation
) {
4687 if (tcon
->ses
->capabilities
& CAP_INFOLEVEL_PASSTHRU
)
4688 pSMB
->InformationLevel
=
4689 cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2
);
4691 pSMB
->InformationLevel
=
4692 cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO
);
4693 } else /* Set File Size */ {
4694 if (tcon
->ses
->capabilities
& CAP_INFOLEVEL_PASSTHRU
)
4695 pSMB
->InformationLevel
=
4696 cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2
);
4698 pSMB
->InformationLevel
=
4699 cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO
);
4703 (struct file_end_of_file_info
*) (((char *) &pSMB
->hdr
.Protocol
) +
4705 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
4706 pSMB
->DataOffset
= cpu_to_le16(offset
);
4707 pSMB
->SetupCount
= 1;
4708 pSMB
->Reserved3
= 0;
4709 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
4710 byte_count
= 3 /* pad */ + params
+ data_count
;
4711 pSMB
->DataCount
= cpu_to_le16(data_count
);
4712 pSMB
->TotalDataCount
= pSMB
->DataCount
;
4713 pSMB
->ParameterCount
= cpu_to_le16(params
);
4714 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
4715 pSMB
->Reserved4
= 0;
4716 pSMB
->hdr
.smb_buf_length
+= byte_count
;
4717 parm_data
->FileSize
= cpu_to_le64(size
);
4718 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4719 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4720 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4722 cFYI(1, ("SetPathInfo (file size) returned %d", rc
));
4724 cifs_buf_release(pSMB
);
4733 CIFSSMBSetFileSize(const int xid
, struct cifsTconInfo
*tcon
, __u64 size
,
4734 __u16 fid
, __u32 pid_of_opener
, bool SetAllocation
)
4736 struct smb_com_transaction2_sfi_req
*pSMB
= NULL
;
4738 struct file_end_of_file_info
*parm_data
;
4740 __u16 params
, param_offset
, offset
, byte_count
, count
;
4742 cFYI(1, ("SetFileSize (via SetFileInfo) %lld",
4744 rc
= small_smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
);
4749 pSMB
->hdr
.Pid
= cpu_to_le16((__u16
)pid_of_opener
);
4750 pSMB
->hdr
.PidHigh
= cpu_to_le16((__u16
)(pid_of_opener
>> 16));
4753 pSMB
->MaxSetupCount
= 0;
4757 pSMB
->Reserved2
= 0;
4758 param_offset
= offsetof(struct smb_com_transaction2_sfi_req
, Fid
) - 4;
4759 offset
= param_offset
+ params
;
4761 data_offset
= (char *) (&pSMB
->hdr
.Protocol
) + offset
;
4763 count
= sizeof(struct file_end_of_file_info
);
4764 pSMB
->MaxParameterCount
= cpu_to_le16(2);
4765 /* BB find exact max SMB PDU from sess structure BB */
4766 pSMB
->MaxDataCount
= cpu_to_le16(1000);
4767 pSMB
->SetupCount
= 1;
4768 pSMB
->Reserved3
= 0;
4769 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_FILE_INFORMATION
);
4770 byte_count
= 3 /* pad */ + params
+ count
;
4771 pSMB
->DataCount
= cpu_to_le16(count
);
4772 pSMB
->ParameterCount
= cpu_to_le16(params
);
4773 pSMB
->TotalDataCount
= pSMB
->DataCount
;
4774 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
4775 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
4777 (struct file_end_of_file_info
*) (((char *) &pSMB
->hdr
.Protocol
)
4779 pSMB
->DataOffset
= cpu_to_le16(offset
);
4780 parm_data
->FileSize
= cpu_to_le64(size
);
4782 if (SetAllocation
) {
4783 if (tcon
->ses
->capabilities
& CAP_INFOLEVEL_PASSTHRU
)
4784 pSMB
->InformationLevel
=
4785 cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2
);
4787 pSMB
->InformationLevel
=
4788 cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO
);
4789 } else /* Set File Size */ {
4790 if (tcon
->ses
->capabilities
& CAP_INFOLEVEL_PASSTHRU
)
4791 pSMB
->InformationLevel
=
4792 cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2
);
4794 pSMB
->InformationLevel
=
4795 cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO
);
4797 pSMB
->Reserved4
= 0;
4798 pSMB
->hdr
.smb_buf_length
+= byte_count
;
4799 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4800 rc
= SendReceiveNoRsp(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
, 0);
4803 ("Send error in SetFileInfo (SetFileSize) = %d",
4807 /* Note: On -EAGAIN error only caller can retry on handle based calls
4808 since file handle passed in no longer valid */
4813 /* Some legacy servers such as NT4 require that the file times be set on
4814 an open handle, rather than by pathname - this is awkward due to
4815 potential access conflicts on the open, but it is unavoidable for these
4816 old servers since the only other choice is to go from 100 nanosecond DCE
4817 time and resort to the original setpathinfo level which takes the ancient
4818 DOS time format with 2 second granularity */
4820 CIFSSMBSetFileTimes(const int xid
, struct cifsTconInfo
*tcon
,
4821 const FILE_BASIC_INFO
*data
, __u16 fid
)
4823 struct smb_com_transaction2_sfi_req
*pSMB
= NULL
;
4826 __u16 params
, param_offset
, offset
, byte_count
, count
;
4828 cFYI(1, ("Set Times (via SetFileInfo)"));
4829 rc
= small_smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
);
4834 /* At this point there is no need to override the current pid
4835 with the pid of the opener, but that could change if we someday
4836 use an existing handle (rather than opening one on the fly) */
4837 /* pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener);
4838 pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16));*/
4841 pSMB
->MaxSetupCount
= 0;
4845 pSMB
->Reserved2
= 0;
4846 param_offset
= offsetof(struct smb_com_transaction2_sfi_req
, Fid
) - 4;
4847 offset
= param_offset
+ params
;
4849 data_offset
= (char *) (&pSMB
->hdr
.Protocol
) + offset
;
4851 count
= sizeof(FILE_BASIC_INFO
);
4852 pSMB
->MaxParameterCount
= cpu_to_le16(2);
4853 /* BB find max SMB PDU from sess */
4854 pSMB
->MaxDataCount
= cpu_to_le16(1000);
4855 pSMB
->SetupCount
= 1;
4856 pSMB
->Reserved3
= 0;
4857 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_FILE_INFORMATION
);
4858 byte_count
= 3 /* pad */ + params
+ count
;
4859 pSMB
->DataCount
= cpu_to_le16(count
);
4860 pSMB
->ParameterCount
= cpu_to_le16(params
);
4861 pSMB
->TotalDataCount
= pSMB
->DataCount
;
4862 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
4863 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
4864 pSMB
->DataOffset
= cpu_to_le16(offset
);
4866 if (tcon
->ses
->capabilities
& CAP_INFOLEVEL_PASSTHRU
)
4867 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_BASIC_INFO2
);
4869 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_BASIC_INFO
);
4870 pSMB
->Reserved4
= 0;
4871 pSMB
->hdr
.smb_buf_length
+= byte_count
;
4872 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4873 memcpy(data_offset
, data
, sizeof(FILE_BASIC_INFO
));
4874 rc
= SendReceiveNoRsp(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
, 0);
4876 cFYI(1, ("Send error in Set Time (SetFileInfo) = %d", rc
));
4878 /* Note: On -EAGAIN error only caller can retry on handle based calls
4879 since file handle passed in no longer valid */
4886 CIFSSMBSetTimes(const int xid
, struct cifsTconInfo
*tcon
, const char *fileName
,
4887 const FILE_BASIC_INFO
*data
,
4888 const struct nls_table
*nls_codepage
, int remap
)
4890 TRANSACTION2_SPI_REQ
*pSMB
= NULL
;
4891 TRANSACTION2_SPI_RSP
*pSMBr
= NULL
;
4894 int bytes_returned
= 0;
4896 __u16 params
, param_offset
, offset
, byte_count
, count
;
4898 cFYI(1, ("In SetTimes"));
4901 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4906 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
4908 cifsConvertToUCS((__le16
*) pSMB
->FileName
, fileName
,
4909 PATH_MAX
, nls_codepage
, remap
);
4910 name_len
++; /* trailing null */
4912 } else { /* BB improve the check for buffer overruns BB */
4913 name_len
= strnlen(fileName
, PATH_MAX
);
4914 name_len
++; /* trailing null */
4915 strncpy(pSMB
->FileName
, fileName
, name_len
);
4918 params
= 6 + name_len
;
4919 count
= sizeof(FILE_BASIC_INFO
);
4920 pSMB
->MaxParameterCount
= cpu_to_le16(2);
4921 /* BB find max SMB PDU from sess structure BB */
4922 pSMB
->MaxDataCount
= cpu_to_le16(1000);
4923 pSMB
->MaxSetupCount
= 0;
4927 pSMB
->Reserved2
= 0;
4928 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
4929 InformationLevel
) - 4;
4930 offset
= param_offset
+ params
;
4931 data_offset
= (char *) (&pSMB
->hdr
.Protocol
) + offset
;
4932 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
4933 pSMB
->DataOffset
= cpu_to_le16(offset
);
4934 pSMB
->SetupCount
= 1;
4935 pSMB
->Reserved3
= 0;
4936 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
4937 byte_count
= 3 /* pad */ + params
+ count
;
4939 pSMB
->DataCount
= cpu_to_le16(count
);
4940 pSMB
->ParameterCount
= cpu_to_le16(params
);
4941 pSMB
->TotalDataCount
= pSMB
->DataCount
;
4942 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
4943 if (tcon
->ses
->capabilities
& CAP_INFOLEVEL_PASSTHRU
)
4944 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_BASIC_INFO2
);
4946 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_BASIC_INFO
);
4947 pSMB
->Reserved4
= 0;
4948 pSMB
->hdr
.smb_buf_length
+= byte_count
;
4949 memcpy(data_offset
, data
, sizeof(FILE_BASIC_INFO
));
4950 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4951 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4952 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4954 cFYI(1, ("SetPathInfo (times) returned %d", rc
));
4956 cifs_buf_release(pSMB
);
4964 /* Can not be used to set time stamps yet (due to old DOS time format) */
4965 /* Can be used to set attributes */
4966 #if 0 /* Possibly not needed - since it turns out that strangely NT4 has a bug
4967 handling it anyway and NT4 was what we thought it would be needed for
4968 Do not delete it until we prove whether needed for Win9x though */
4970 CIFSSMBSetAttrLegacy(int xid
, struct cifsTconInfo
*tcon
, char *fileName
,
4971 __u16 dos_attrs
, const struct nls_table
*nls_codepage
)
4973 SETATTR_REQ
*pSMB
= NULL
;
4974 SETATTR_RSP
*pSMBr
= NULL
;
4979 cFYI(1, ("In SetAttrLegacy"));
4982 rc
= smb_init(SMB_COM_SETATTR
, 8, tcon
, (void **) &pSMB
,
4987 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
4989 ConvertToUCS((__le16
*) pSMB
->fileName
, fileName
,
4990 PATH_MAX
, nls_codepage
);
4991 name_len
++; /* trailing null */
4993 } else { /* BB improve the check for buffer overruns BB */
4994 name_len
= strnlen(fileName
, PATH_MAX
);
4995 name_len
++; /* trailing null */
4996 strncpy(pSMB
->fileName
, fileName
, name_len
);
4998 pSMB
->attr
= cpu_to_le16(dos_attrs
);
4999 pSMB
->BufferFormat
= 0x04;
5000 pSMB
->hdr
.smb_buf_length
+= name_len
+ 1;
5001 pSMB
->ByteCount
= cpu_to_le16(name_len
+ 1);
5002 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
5003 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
5005 cFYI(1, ("Error in LegacySetAttr = %d", rc
));
5007 cifs_buf_release(pSMB
);
5010 goto SetAttrLgcyRetry
;
5014 #endif /* temporarily unneeded SetAttr legacy function */
5017 CIFSSMBUnixSetPerms(const int xid
, struct cifsTconInfo
*tcon
,
5018 char *fileName
, __u64 mode
, __u64 uid
, __u64 gid
,
5019 dev_t device
, const struct nls_table
*nls_codepage
,
5022 TRANSACTION2_SPI_REQ
*pSMB
= NULL
;
5023 TRANSACTION2_SPI_RSP
*pSMBr
= NULL
;
5026 int bytes_returned
= 0;
5027 FILE_UNIX_BASIC_INFO
*data_offset
;
5028 __u16 params
, param_offset
, offset
, count
, byte_count
;
5030 cFYI(1, ("In SetUID/GID/Mode"));
5032 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
5037 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
5039 cifsConvertToUCS((__le16
*) pSMB
->FileName
, fileName
,
5040 PATH_MAX
, nls_codepage
, remap
);
5041 name_len
++; /* trailing null */
5043 } else { /* BB improve the check for buffer overruns BB */
5044 name_len
= strnlen(fileName
, PATH_MAX
);
5045 name_len
++; /* trailing null */
5046 strncpy(pSMB
->FileName
, fileName
, name_len
);
5049 params
= 6 + name_len
;
5050 count
= sizeof(FILE_UNIX_BASIC_INFO
);
5051 pSMB
->MaxParameterCount
= cpu_to_le16(2);
5052 /* BB find max SMB PDU from sess structure BB */
5053 pSMB
->MaxDataCount
= cpu_to_le16(1000);
5054 pSMB
->MaxSetupCount
= 0;
5058 pSMB
->Reserved2
= 0;
5059 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
5060 InformationLevel
) - 4;
5061 offset
= param_offset
+ params
;
5063 (FILE_UNIX_BASIC_INFO
*) ((char *) &pSMB
->hdr
.Protocol
+
5065 memset(data_offset
, 0, count
);
5066 pSMB
->DataOffset
= cpu_to_le16(offset
);
5067 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
5068 pSMB
->SetupCount
= 1;
5069 pSMB
->Reserved3
= 0;
5070 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
5071 byte_count
= 3 /* pad */ + params
+ count
;
5072 pSMB
->ParameterCount
= cpu_to_le16(params
);
5073 pSMB
->DataCount
= cpu_to_le16(count
);
5074 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
5075 pSMB
->TotalDataCount
= pSMB
->DataCount
;
5076 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_UNIX_BASIC
);
5077 pSMB
->Reserved4
= 0;
5078 pSMB
->hdr
.smb_buf_length
+= byte_count
;
5079 /* Samba server ignores set of file size to zero due to bugs in some
5080 older clients, but we should be precise - we use SetFileSize to
5081 set file size and do not want to truncate file size to zero
5082 accidently as happened on one Samba server beta by putting
5083 zero instead of -1 here */
5084 data_offset
->EndOfFile
= NO_CHANGE_64
;
5085 data_offset
->NumOfBytes
= NO_CHANGE_64
;
5086 data_offset
->LastStatusChange
= NO_CHANGE_64
;
5087 data_offset
->LastAccessTime
= NO_CHANGE_64
;
5088 data_offset
->LastModificationTime
= NO_CHANGE_64
;
5089 data_offset
->Uid
= cpu_to_le64(uid
);
5090 data_offset
->Gid
= cpu_to_le64(gid
);
5091 /* better to leave device as zero when it is */
5092 data_offset
->DevMajor
= cpu_to_le64(MAJOR(device
));
5093 data_offset
->DevMinor
= cpu_to_le64(MINOR(device
));
5094 data_offset
->Permissions
= cpu_to_le64(mode
);
5097 data_offset
->Type
= cpu_to_le32(UNIX_FILE
);
5098 else if (S_ISDIR(mode
))
5099 data_offset
->Type
= cpu_to_le32(UNIX_DIR
);
5100 else if (S_ISLNK(mode
))
5101 data_offset
->Type
= cpu_to_le32(UNIX_SYMLINK
);
5102 else if (S_ISCHR(mode
))
5103 data_offset
->Type
= cpu_to_le32(UNIX_CHARDEV
);
5104 else if (S_ISBLK(mode
))
5105 data_offset
->Type
= cpu_to_le32(UNIX_BLOCKDEV
);
5106 else if (S_ISFIFO(mode
))
5107 data_offset
->Type
= cpu_to_le32(UNIX_FIFO
);
5108 else if (S_ISSOCK(mode
))
5109 data_offset
->Type
= cpu_to_le32(UNIX_SOCKET
);
5112 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
5113 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
5114 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
5116 cFYI(1, ("SetPathInfo (perms) returned %d", rc
));
5118 cifs_buf_release(pSMB
);
5124 int CIFSSMBNotify(const int xid
, struct cifsTconInfo
*tcon
,
5125 const int notify_subdirs
, const __u16 netfid
,
5126 __u32 filter
, struct file
*pfile
, int multishot
,
5127 const struct nls_table
*nls_codepage
)
5130 struct smb_com_transaction_change_notify_req
*pSMB
= NULL
;
5131 struct smb_com_ntransaction_change_notify_rsp
*pSMBr
= NULL
;
5132 struct dir_notify_req
*dnotify_req
;
5135 cFYI(1, ("In CIFSSMBNotify for file handle %d", (int)netfid
));
5136 rc
= smb_init(SMB_COM_NT_TRANSACT
, 23, tcon
, (void **) &pSMB
,
5141 pSMB
->TotalParameterCount
= 0 ;
5142 pSMB
->TotalDataCount
= 0;
5143 pSMB
->MaxParameterCount
= cpu_to_le32(2);
5144 /* BB find exact data count max from sess structure BB */
5145 pSMB
->MaxDataCount
= 0; /* same in little endian or be */
5146 /* BB VERIFY verify which is correct for above BB */
5147 pSMB
->MaxDataCount
= cpu_to_le32((tcon
->ses
->server
->maxBuf
-
5148 MAX_CIFS_HDR_SIZE
) & 0xFFFFFF00);
5150 pSMB
->MaxSetupCount
= 4;
5152 pSMB
->ParameterOffset
= 0;
5153 pSMB
->DataCount
= 0;
5154 pSMB
->DataOffset
= 0;
5155 pSMB
->SetupCount
= 4; /* single byte does not need le conversion */
5156 pSMB
->SubCommand
= cpu_to_le16(NT_TRANSACT_NOTIFY_CHANGE
);
5157 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
5159 pSMB
->WatchTree
= 1; /* one byte - no le conversion needed */
5160 pSMB
->Reserved2
= 0;
5161 pSMB
->CompletionFilter
= cpu_to_le32(filter
);
5162 pSMB
->Fid
= netfid
; /* file handle always le */
5163 pSMB
->ByteCount
= 0;
5165 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
5166 (struct smb_hdr
*)pSMBr
, &bytes_returned
,
5169 cFYI(1, ("Error in Notify = %d", rc
));
5171 /* Add file to outstanding requests */
5172 /* BB change to kmem cache alloc */
5173 dnotify_req
= kmalloc(
5174 sizeof(struct dir_notify_req
),
5177 dnotify_req
->Pid
= pSMB
->hdr
.Pid
;
5178 dnotify_req
->PidHigh
= pSMB
->hdr
.PidHigh
;
5179 dnotify_req
->Mid
= pSMB
->hdr
.Mid
;
5180 dnotify_req
->Tid
= pSMB
->hdr
.Tid
;
5181 dnotify_req
->Uid
= pSMB
->hdr
.Uid
;
5182 dnotify_req
->netfid
= netfid
;
5183 dnotify_req
->pfile
= pfile
;
5184 dnotify_req
->filter
= filter
;
5185 dnotify_req
->multishot
= multishot
;
5186 spin_lock(&GlobalMid_Lock
);
5187 list_add_tail(&dnotify_req
->lhead
,
5188 &GlobalDnotifyReqList
);
5189 spin_unlock(&GlobalMid_Lock
);
5193 cifs_buf_release(pSMB
);
5196 #ifdef CONFIG_CIFS_XATTR
5198 CIFSSMBQAllEAs(const int xid
, struct cifsTconInfo
*tcon
,
5199 const unsigned char *searchName
,
5200 char *EAData
, size_t buf_size
,
5201 const struct nls_table
*nls_codepage
, int remap
)
5203 /* BB assumes one setup word */
5204 TRANSACTION2_QPI_REQ
*pSMB
= NULL
;
5205 TRANSACTION2_QPI_RSP
*pSMBr
= NULL
;
5209 struct fea
*temp_fea
;
5211 __u16 params
, byte_count
;
5213 cFYI(1, ("In Query All EAs path %s", searchName
));
5215 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
5220 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
5222 cifsConvertToUCS((__le16
*) pSMB
->FileName
, searchName
,
5223 PATH_MAX
, nls_codepage
, remap
);
5224 name_len
++; /* trailing null */
5226 } else { /* BB improve the check for buffer overruns BB */
5227 name_len
= strnlen(searchName
, PATH_MAX
);
5228 name_len
++; /* trailing null */
5229 strncpy(pSMB
->FileName
, searchName
, name_len
);
5232 params
= 2 /* level */ + 4 /* reserved */ + name_len
/* includes NUL */;
5233 pSMB
->TotalDataCount
= 0;
5234 pSMB
->MaxParameterCount
= cpu_to_le16(2);
5235 /* BB find exact max SMB PDU from sess structure BB */
5236 pSMB
->MaxDataCount
= cpu_to_le16(4000);
5237 pSMB
->MaxSetupCount
= 0;
5241 pSMB
->Reserved2
= 0;
5242 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
5243 struct smb_com_transaction2_qpi_req
, InformationLevel
) - 4);
5244 pSMB
->DataCount
= 0;
5245 pSMB
->DataOffset
= 0;
5246 pSMB
->SetupCount
= 1;
5247 pSMB
->Reserved3
= 0;
5248 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION
);
5249 byte_count
= params
+ 1 /* pad */ ;
5250 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
5251 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
5252 pSMB
->InformationLevel
= cpu_to_le16(SMB_INFO_QUERY_ALL_EAS
);
5253 pSMB
->Reserved4
= 0;
5254 pSMB
->hdr
.smb_buf_length
+= byte_count
;
5255 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
5257 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
5258 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
5260 cFYI(1, ("Send error in QueryAllEAs = %d", rc
));
5261 } else { /* decode response */
5262 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
5264 /* BB also check enough total bytes returned */
5265 /* BB we need to improve the validity checking
5266 of these trans2 responses */
5267 if (rc
|| (pSMBr
->ByteCount
< 4))
5268 rc
= -EIO
; /* bad smb */
5269 /* else if (pFindData){
5270 memcpy((char *) pFindData,
5271 (char *) &pSMBr->hdr.Protocol +
5274 /* check that length of list is not more than bcc */
5275 /* check that each entry does not go beyond length
5277 /* check that each element of each entry does not
5278 go beyond end of list */
5279 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
5280 struct fealist
*ea_response_data
;
5282 /* validate_trans2_offsets() */
5283 /* BB check if start of smb + data_offset > &bcc+ bcc */
5284 ea_response_data
= (struct fealist
*)
5285 (((char *) &pSMBr
->hdr
.Protocol
) +
5287 name_len
= le32_to_cpu(ea_response_data
->list_len
);
5288 cFYI(1, ("ea length %d", name_len
));
5289 if (name_len
<= 8) {
5290 /* returned EA size zeroed at top of function */
5291 cFYI(1, ("empty EA list returned from server"));
5293 /* account for ea list len */
5295 temp_fea
= ea_response_data
->list
;
5296 temp_ptr
= (char *)temp_fea
;
5297 while (name_len
> 0) {
5301 rc
+= temp_fea
->name_len
;
5302 /* account for prefix user. and trailing null */
5304 if (rc
< (int)buf_size
) {
5305 memcpy(EAData
, "user.", 5);
5307 memcpy(EAData
, temp_ptr
,
5308 temp_fea
->name_len
);
5309 EAData
+= temp_fea
->name_len
;
5310 /* null terminate name */
5312 EAData
= EAData
+ 1;
5313 } else if (buf_size
== 0) {
5314 /* skip copy - calc size only */
5316 /* stop before overrun buffer */
5320 name_len
-= temp_fea
->name_len
;
5321 temp_ptr
+= temp_fea
->name_len
;
5322 /* account for trailing null */
5326 le16_to_cpu(temp_fea
->value_len
);
5327 name_len
-= value_len
;
5328 temp_ptr
+= value_len
;
5329 /* BB check that temp_ptr is still
5332 /* no trailing null to account for
5334 /* go on to next EA */
5335 temp_fea
= (struct fea
*)temp_ptr
;
5340 cifs_buf_release(pSMB
);
5347 ssize_t
CIFSSMBQueryEA(const int xid
, struct cifsTconInfo
*tcon
,
5348 const unsigned char *searchName
, const unsigned char *ea_name
,
5349 unsigned char *ea_value
, size_t buf_size
,
5350 const struct nls_table
*nls_codepage
, int remap
)
5352 TRANSACTION2_QPI_REQ
*pSMB
= NULL
;
5353 TRANSACTION2_QPI_RSP
*pSMBr
= NULL
;
5357 struct fea
*temp_fea
;
5359 __u16 params
, byte_count
;
5361 cFYI(1, ("In Query EA path %s", searchName
));
5363 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
5368 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
5370 cifsConvertToUCS((__le16
*) pSMB
->FileName
, searchName
,
5371 PATH_MAX
, nls_codepage
, remap
);
5372 name_len
++; /* trailing null */
5374 } else { /* BB improve the check for buffer overruns BB */
5375 name_len
= strnlen(searchName
, PATH_MAX
);
5376 name_len
++; /* trailing null */
5377 strncpy(pSMB
->FileName
, searchName
, name_len
);
5380 params
= 2 /* level */ + 4 /* reserved */ + name_len
/* includes NUL */;
5381 pSMB
->TotalDataCount
= 0;
5382 pSMB
->MaxParameterCount
= cpu_to_le16(2);
5383 /* BB find exact max SMB PDU from sess structure BB */
5384 pSMB
->MaxDataCount
= cpu_to_le16(4000);
5385 pSMB
->MaxSetupCount
= 0;
5389 pSMB
->Reserved2
= 0;
5390 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
5391 struct smb_com_transaction2_qpi_req
, InformationLevel
) - 4);
5392 pSMB
->DataCount
= 0;
5393 pSMB
->DataOffset
= 0;
5394 pSMB
->SetupCount
= 1;
5395 pSMB
->Reserved3
= 0;
5396 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION
);
5397 byte_count
= params
+ 1 /* pad */ ;
5398 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
5399 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
5400 pSMB
->InformationLevel
= cpu_to_le16(SMB_INFO_QUERY_ALL_EAS
);
5401 pSMB
->Reserved4
= 0;
5402 pSMB
->hdr
.smb_buf_length
+= byte_count
;
5403 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
5405 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
5406 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
5408 cFYI(1, ("Send error in Query EA = %d", rc
));
5409 } else { /* decode response */
5410 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
5412 /* BB also check enough total bytes returned */
5413 /* BB we need to improve the validity checking
5414 of these trans2 responses */
5415 if (rc
|| (pSMBr
->ByteCount
< 4))
5416 rc
= -EIO
; /* bad smb */
5417 /* else if (pFindData){
5418 memcpy((char *) pFindData,
5419 (char *) &pSMBr->hdr.Protocol +
5422 /* check that length of list is not more than bcc */
5423 /* check that each entry does not go beyond length
5425 /* check that each element of each entry does not
5426 go beyond end of list */
5427 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
5428 struct fealist
*ea_response_data
;
5430 /* validate_trans2_offsets() */
5431 /* BB check if start of smb + data_offset > &bcc+ bcc*/
5432 ea_response_data
= (struct fealist
*)
5433 (((char *) &pSMBr
->hdr
.Protocol
) +
5435 name_len
= le32_to_cpu(ea_response_data
->list_len
);
5436 cFYI(1, ("ea length %d", name_len
));
5437 if (name_len
<= 8) {
5438 /* returned EA size zeroed at top of function */
5439 cFYI(1, ("empty EA list returned from server"));
5441 /* account for ea list len */
5443 temp_fea
= ea_response_data
->list
;
5444 temp_ptr
= (char *)temp_fea
;
5445 /* loop through checking if we have a matching
5446 name and then return the associated value */
5447 while (name_len
> 0) {
5452 le16_to_cpu(temp_fea
->value_len
);
5453 /* BB validate that value_len falls within SMB,
5454 even though maximum for name_len is 255 */
5455 if (memcmp(temp_fea
->name
, ea_name
,
5456 temp_fea
->name_len
) == 0) {
5459 /* account for prefix user. and trailing null */
5460 if (rc
<= (int)buf_size
) {
5462 temp_fea
->name
+temp_fea
->name_len
+1,
5464 /* ea values, unlike ea
5467 } else if (buf_size
== 0) {
5468 /* skip copy - calc size only */
5470 /* stop before overrun buffer */
5475 name_len
-= temp_fea
->name_len
;
5476 temp_ptr
+= temp_fea
->name_len
;
5477 /* account for trailing null */
5480 name_len
-= value_len
;
5481 temp_ptr
+= value_len
;
5482 /* No trailing null to account for in
5483 value_len. Go on to next EA */
5484 temp_fea
= (struct fea
*)temp_ptr
;
5489 cifs_buf_release(pSMB
);
5497 CIFSSMBSetEA(const int xid
, struct cifsTconInfo
*tcon
, const char *fileName
,
5498 const char *ea_name
, const void *ea_value
,
5499 const __u16 ea_value_len
, const struct nls_table
*nls_codepage
,
5502 struct smb_com_transaction2_spi_req
*pSMB
= NULL
;
5503 struct smb_com_transaction2_spi_rsp
*pSMBr
= NULL
;
5504 struct fealist
*parm_data
;
5507 int bytes_returned
= 0;
5508 __u16 params
, param_offset
, byte_count
, offset
, count
;
5510 cFYI(1, ("In SetEA"));
5512 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
5517 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
5519 cifsConvertToUCS((__le16
*) pSMB
->FileName
, fileName
,
5520 PATH_MAX
, nls_codepage
, remap
);
5521 name_len
++; /* trailing null */
5523 } else { /* BB improve the check for buffer overruns BB */
5524 name_len
= strnlen(fileName
, PATH_MAX
);
5525 name_len
++; /* trailing null */
5526 strncpy(pSMB
->FileName
, fileName
, name_len
);
5529 params
= 6 + name_len
;
5531 /* done calculating parms using name_len of file name,
5532 now use name_len to calculate length of ea name
5533 we are going to create in the inode xattrs */
5534 if (ea_name
== NULL
)
5537 name_len
= strnlen(ea_name
, 255);
5539 count
= sizeof(*parm_data
) + ea_value_len
+ name_len
;
5540 pSMB
->MaxParameterCount
= cpu_to_le16(2);
5541 /* BB find max SMB PDU from sess */
5542 pSMB
->MaxDataCount
= cpu_to_le16(1000);
5543 pSMB
->MaxSetupCount
= 0;
5547 pSMB
->Reserved2
= 0;
5548 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
5549 InformationLevel
) - 4;
5550 offset
= param_offset
+ params
;
5551 pSMB
->InformationLevel
=
5552 cpu_to_le16(SMB_SET_FILE_EA
);
5555 (struct fealist
*) (((char *) &pSMB
->hdr
.Protocol
) +
5557 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
5558 pSMB
->DataOffset
= cpu_to_le16(offset
);
5559 pSMB
->SetupCount
= 1;
5560 pSMB
->Reserved3
= 0;
5561 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
5562 byte_count
= 3 /* pad */ + params
+ count
;
5563 pSMB
->DataCount
= cpu_to_le16(count
);
5564 parm_data
->list_len
= cpu_to_le32(count
);
5565 parm_data
->list
[0].EA_flags
= 0;
5566 /* we checked above that name len is less than 255 */
5567 parm_data
->list
[0].name_len
= (__u8
)name_len
;
5568 /* EA names are always ASCII */
5570 strncpy(parm_data
->list
[0].name
, ea_name
, name_len
);
5571 parm_data
->list
[0].name
[name_len
] = 0;
5572 parm_data
->list
[0].value_len
= cpu_to_le16(ea_value_len
);
5573 /* caller ensures that ea_value_len is less than 64K but
5574 we need to ensure that it fits within the smb */
5576 /*BB add length check to see if it would fit in
5577 negotiated SMB buffer size BB */
5578 /* if (ea_value_len > buffer_size - 512 (enough for header)) */
5580 memcpy(parm_data
->list
[0].name
+name_len
+1,
5581 ea_value
, ea_value_len
);
5583 pSMB
->TotalDataCount
= pSMB
->DataCount
;
5584 pSMB
->ParameterCount
= cpu_to_le16(params
);
5585 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
5586 pSMB
->Reserved4
= 0;
5587 pSMB
->hdr
.smb_buf_length
+= byte_count
;
5588 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
5589 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
5590 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
5592 cFYI(1, ("SetPathInfo (EA) returned %d", rc
));
5594 cifs_buf_release(pSMB
);