4 * Copyright (C) International Business Machines Corp., 2002,2010
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/slab.h>
34 #include <linux/posix_acl_xattr.h>
35 #include <asm/uaccess.h>
39 #include "cifsproto.h"
40 #include "cifs_unicode.h"
41 #include "cifs_debug.h"
43 #ifdef CONFIG_CIFS_POSIX
48 #ifdef CONFIG_CIFS_WEAK_PW_HASH
49 {LANMAN_PROT
, "\2LM1.2X002"},
50 {LANMAN2_PROT
, "\2LANMAN2.1"},
51 #endif /* weak password hashing for legacy clients */
52 {CIFS_PROT
, "\2NT LM 0.12"},
53 {POSIX_PROT
, "\2POSIX 2"},
61 #ifdef CONFIG_CIFS_WEAK_PW_HASH
62 {LANMAN_PROT
, "\2LM1.2X002"},
63 {LANMAN2_PROT
, "\2LANMAN2.1"},
64 #endif /* weak password hashing for legacy clients */
65 {CIFS_PROT
, "\2NT LM 0.12"},
70 /* define the number of elements in the cifs dialect array */
71 #ifdef CONFIG_CIFS_POSIX
72 #ifdef CONFIG_CIFS_WEAK_PW_HASH
73 #define CIFS_NUM_PROT 4
75 #define CIFS_NUM_PROT 2
76 #endif /* CIFS_WEAK_PW_HASH */
78 #ifdef CONFIG_CIFS_WEAK_PW_HASH
79 #define CIFS_NUM_PROT 3
81 #define CIFS_NUM_PROT 1
82 #endif /* CONFIG_CIFS_WEAK_PW_HASH */
83 #endif /* CIFS_POSIX */
85 /* Mark as invalid, all open files on tree connections since they
86 were closed when session to server was lost */
87 static void mark_open_files_invalid(struct cifsTconInfo
*pTcon
)
89 struct cifsFileInfo
*open_file
= NULL
;
90 struct list_head
*tmp
;
91 struct list_head
*tmp1
;
93 /* list all files open on tree connection and mark them invalid */
94 write_lock(&GlobalSMBSeslock
);
95 list_for_each_safe(tmp
, tmp1
, &pTcon
->openFileList
) {
96 open_file
= list_entry(tmp
, struct cifsFileInfo
, tlist
);
97 open_file
->invalidHandle
= true;
98 open_file
->oplock_break_cancelled
= true;
100 write_unlock(&GlobalSMBSeslock
);
101 /* BB Add call to invalidate_inodes(sb) for all superblocks mounted
105 /* reconnect the socket, tcon, and smb session if needed */
107 cifs_reconnect_tcon(struct cifsTconInfo
*tcon
, int smb_command
)
110 struct cifsSesInfo
*ses
;
111 struct TCP_Server_Info
*server
;
112 struct nls_table
*nls_codepage
;
115 * SMBs NegProt, SessSetup, uLogoff do not have tcon yet so check for
116 * tcp and smb session status done differently for those three - in the
123 server
= ses
->server
;
126 * only tree disconnect, open, and write, (and ulogoff which does not
127 * have tcon) are allowed as we start force umount
129 if (tcon
->tidStatus
== CifsExiting
) {
130 if (smb_command
!= SMB_COM_WRITE_ANDX
&&
131 smb_command
!= SMB_COM_OPEN_ANDX
&&
132 smb_command
!= SMB_COM_TREE_DISCONNECT
) {
133 cFYI(1, "can not send cmd %d while umounting",
139 if (ses
->status
== CifsExiting
)
143 * Give demultiplex thread up to 10 seconds to reconnect, should be
144 * greater than cifs socket timeout which is 7 seconds
146 while (server
->tcpStatus
== CifsNeedReconnect
) {
147 wait_event_interruptible_timeout(server
->response_q
,
148 (server
->tcpStatus
== CifsGood
), 10 * HZ
);
150 /* is TCP session is reestablished now ?*/
151 if (server
->tcpStatus
!= CifsNeedReconnect
)
155 * on "soft" mounts we wait once. Hard mounts keep
156 * retrying until process is killed or server comes
159 if (!tcon
->retry
|| ses
->status
== CifsExiting
) {
160 cFYI(1, "gave up waiting on reconnect in smb_init");
165 if (!ses
->need_reconnect
&& !tcon
->need_reconnect
)
168 nls_codepage
= load_nls_default();
171 * need to prevent multiple threads trying to simultaneously
172 * reconnect the same SMB session
174 mutex_lock(&ses
->session_mutex
);
175 rc
= cifs_negotiate_protocol(0, ses
);
176 if (rc
== 0 && ses
->need_reconnect
)
177 rc
= cifs_setup_session(0, ses
, nls_codepage
);
179 /* do we need to reconnect tcon? */
180 if (rc
|| !tcon
->need_reconnect
) {
181 mutex_unlock(&ses
->session_mutex
);
185 mark_open_files_invalid(tcon
);
186 rc
= CIFSTCon(0, ses
, tcon
->treeName
, tcon
, nls_codepage
);
187 mutex_unlock(&ses
->session_mutex
);
188 cFYI(1, "reconnect tcon rc = %d", rc
);
194 * FIXME: check if wsize needs updated due to negotiated smb buffer
197 atomic_inc(&tconInfoReconnectCount
);
199 /* tell server Unix caps we support */
200 if (ses
->capabilities
& CAP_UNIX
)
201 reset_cifs_unix_caps(0, tcon
, NULL
, NULL
);
204 * Removed call to reopen open files here. It is safer (and faster) to
205 * reopen files one at a time as needed in read and write.
207 * FIXME: what about file locks? don't we need to reclaim them ASAP?
212 * Check if handle based operation so we know whether we can continue
213 * or not without returning to caller to reset file handle
215 switch (smb_command
) {
216 case SMB_COM_READ_ANDX
:
217 case SMB_COM_WRITE_ANDX
:
219 case SMB_COM_FIND_CLOSE2
:
220 case SMB_COM_LOCKING_ANDX
:
224 unload_nls(nls_codepage
);
228 /* Allocate and return pointer to an SMB request buffer, and set basic
229 SMB information in the SMB header. If the return code is zero, this
230 function must have filled in request_buf pointer */
232 small_smb_init(int smb_command
, int wct
, struct cifsTconInfo
*tcon
,
237 rc
= cifs_reconnect_tcon(tcon
, smb_command
);
241 *request_buf
= cifs_small_buf_get();
242 if (*request_buf
== NULL
) {
243 /* BB should we add a retry in here if not a writepage? */
247 header_assemble((struct smb_hdr
*) *request_buf
, smb_command
,
251 cifs_stats_inc(&tcon
->num_smbs_sent
);
257 small_smb_init_no_tc(const int smb_command
, const int wct
,
258 struct cifsSesInfo
*ses
, void **request_buf
)
261 struct smb_hdr
*buffer
;
263 rc
= small_smb_init(smb_command
, wct
, NULL
, request_buf
);
267 buffer
= (struct smb_hdr
*)*request_buf
;
268 buffer
->Mid
= GetNextMid(ses
->server
);
269 if (ses
->capabilities
& CAP_UNICODE
)
270 buffer
->Flags2
|= SMBFLG2_UNICODE
;
271 if (ses
->capabilities
& CAP_STATUS32
)
272 buffer
->Flags2
|= SMBFLG2_ERR_STATUS
;
274 /* uid, tid can stay at zero as set in header assemble */
276 /* BB add support for turning on the signing when
277 this function is used after 1st of session setup requests */
282 /* If the return code is zero, this function must fill in request_buf pointer */
284 smb_init(int smb_command
, int wct
, struct cifsTconInfo
*tcon
,
285 void **request_buf
/* returned */ ,
286 void **response_buf
/* returned */ )
290 rc
= cifs_reconnect_tcon(tcon
, smb_command
);
294 *request_buf
= cifs_buf_get();
295 if (*request_buf
== NULL
) {
296 /* BB should we add a retry in here if not a writepage? */
299 /* Although the original thought was we needed the response buf for */
300 /* potential retries of smb operations it turns out we can determine */
301 /* from the mid flags when the request buffer can be resent without */
302 /* having to use a second distinct buffer for the response */
304 *response_buf
= *request_buf
;
306 header_assemble((struct smb_hdr
*) *request_buf
, smb_command
, tcon
,
310 cifs_stats_inc(&tcon
->num_smbs_sent
);
315 static int validate_t2(struct smb_t2_rsp
*pSMB
)
321 /* check for plausible wct, bcc and t2 data and parm sizes */
322 /* check for parm and data offset going beyond end of smb */
323 if (pSMB
->hdr
.WordCount
>= 10) {
324 if ((le16_to_cpu(pSMB
->t2_rsp
.ParameterOffset
) <= 1024) &&
325 (le16_to_cpu(pSMB
->t2_rsp
.DataOffset
) <= 1024)) {
326 /* check that bcc is at least as big as parms + data */
327 /* check that bcc is less than negotiated smb buffer */
328 total_size
= le16_to_cpu(pSMB
->t2_rsp
.ParameterCount
);
329 if (total_size
< 512) {
331 le16_to_cpu(pSMB
->t2_rsp
.DataCount
);
332 /* BCC le converted in SendReceive */
333 pBCC
= (pSMB
->hdr
.WordCount
* 2) +
334 sizeof(struct smb_hdr
) +
336 if ((total_size
<= (*(u16
*)pBCC
)) &&
338 CIFSMaxBufSize
+MAX_CIFS_HDR_SIZE
)) {
344 cifs_dump_mem("Invalid transact2 SMB: ", (char *)pSMB
,
345 sizeof(struct smb_t2_rsp
) + 16);
349 CIFSSMBNegotiate(unsigned int xid
, struct cifsSesInfo
*ses
)
352 NEGOTIATE_RSP
*pSMBr
;
356 struct TCP_Server_Info
*server
;
358 unsigned int secFlags
;
361 server
= ses
->server
;
366 rc
= smb_init(SMB_COM_NEGOTIATE
, 0, NULL
/* no tcon yet */ ,
367 (void **) &pSMB
, (void **) &pSMBr
);
371 /* if any of auth flags (ie not sign or seal) are overriden use them */
372 if (ses
->overrideSecFlg
& (~(CIFSSEC_MUST_SIGN
| CIFSSEC_MUST_SEAL
)))
373 secFlags
= ses
->overrideSecFlg
; /* BB FIXME fix sign flags? */
374 else /* if override flags set only sign/seal OR them with global auth */
375 secFlags
= global_secflags
| ses
->overrideSecFlg
;
377 cFYI(1, "secFlags 0x%x", secFlags
);
379 pSMB
->hdr
.Mid
= GetNextMid(server
);
380 pSMB
->hdr
.Flags2
|= (SMBFLG2_UNICODE
| SMBFLG2_ERR_STATUS
);
382 if ((secFlags
& CIFSSEC_MUST_KRB5
) == CIFSSEC_MUST_KRB5
)
383 pSMB
->hdr
.Flags2
|= SMBFLG2_EXT_SEC
;
384 else if ((secFlags
& CIFSSEC_AUTH_MASK
) == CIFSSEC_MAY_KRB5
) {
385 cFYI(1, "Kerberos only mechanism, enable extended security");
386 pSMB
->hdr
.Flags2
|= SMBFLG2_EXT_SEC
;
388 #ifdef CONFIG_CIFS_EXPERIMENTAL
389 else if ((secFlags
& CIFSSEC_MUST_NTLMSSP
) == CIFSSEC_MUST_NTLMSSP
)
390 pSMB
->hdr
.Flags2
|= SMBFLG2_EXT_SEC
;
391 else if ((secFlags
& CIFSSEC_AUTH_MASK
) == CIFSSEC_MAY_NTLMSSP
) {
392 cFYI(1, "NTLMSSP only mechanism, enable extended security");
393 pSMB
->hdr
.Flags2
|= SMBFLG2_EXT_SEC
;
398 for (i
= 0; i
< CIFS_NUM_PROT
; i
++) {
399 strncpy(pSMB
->DialectsArray
+count
, protocols
[i
].name
, 16);
400 count
+= strlen(protocols
[i
].name
) + 1;
401 /* null at end of source and target buffers anyway */
403 pSMB
->hdr
.smb_buf_length
+= count
;
404 pSMB
->ByteCount
= cpu_to_le16(count
);
406 rc
= SendReceive(xid
, ses
, (struct smb_hdr
*) pSMB
,
407 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
411 server
->dialect
= le16_to_cpu(pSMBr
->DialectIndex
);
412 cFYI(1, "Dialect: %d", server
->dialect
);
413 /* Check wct = 1 error case */
414 if ((pSMBr
->hdr
.WordCount
< 13) || (server
->dialect
== BAD_PROT
)) {
415 /* core returns wct = 1, but we do not ask for core - otherwise
416 small wct just comes when dialect index is -1 indicating we
417 could not negotiate a common dialect */
420 #ifdef CONFIG_CIFS_WEAK_PW_HASH
421 } else if ((pSMBr
->hdr
.WordCount
== 13)
422 && ((server
->dialect
== LANMAN_PROT
)
423 || (server
->dialect
== LANMAN2_PROT
))) {
425 struct lanman_neg_rsp
*rsp
= (struct lanman_neg_rsp
*)pSMBr
;
427 if ((secFlags
& CIFSSEC_MAY_LANMAN
) ||
428 (secFlags
& CIFSSEC_MAY_PLNTXT
))
429 server
->secType
= LANMAN
;
431 cERROR(1, "mount failed weak security disabled"
432 " in /proc/fs/cifs/SecurityFlags");
436 server
->secMode
= (__u8
)le16_to_cpu(rsp
->SecurityMode
);
437 server
->maxReq
= le16_to_cpu(rsp
->MaxMpxCount
);
438 server
->maxBuf
= min((__u32
)le16_to_cpu(rsp
->MaxBufSize
),
439 (__u32
)CIFSMaxBufSize
+ MAX_CIFS_HDR_SIZE
);
440 server
->max_vcs
= le16_to_cpu(rsp
->MaxNumberVcs
);
441 GETU32(server
->sessid
) = le32_to_cpu(rsp
->SessionKey
);
442 /* even though we do not use raw we might as well set this
443 accurately, in case we ever find a need for it */
444 if ((le16_to_cpu(rsp
->RawMode
) & RAW_ENABLE
) == RAW_ENABLE
) {
445 server
->max_rw
= 0xFF00;
446 server
->capabilities
= CAP_MPX_MODE
| CAP_RAW_MODE
;
448 server
->max_rw
= 0;/* do not need to use raw anyway */
449 server
->capabilities
= CAP_MPX_MODE
;
451 tmp
= (__s16
)le16_to_cpu(rsp
->ServerTimeZone
);
453 /* OS/2 often does not set timezone therefore
454 * we must use server time to calc time zone.
455 * Could deviate slightly from the right zone.
456 * Smallest defined timezone difference is 15 minutes
457 * (i.e. Nepal). Rounding up/down is done to match
460 int val
, seconds
, remain
, result
;
461 struct timespec ts
, utc
;
463 ts
= cnvrtDosUnixTm(rsp
->SrvTime
.Date
,
464 rsp
->SrvTime
.Time
, 0);
465 cFYI(1, "SrvTime %d sec since 1970 (utc: %d) diff: %d",
466 (int)ts
.tv_sec
, (int)utc
.tv_sec
,
467 (int)(utc
.tv_sec
- ts
.tv_sec
));
468 val
= (int)(utc
.tv_sec
- ts
.tv_sec
);
470 result
= (seconds
/ MIN_TZ_ADJ
) * MIN_TZ_ADJ
;
471 remain
= seconds
% MIN_TZ_ADJ
;
472 if (remain
>= (MIN_TZ_ADJ
/ 2))
473 result
+= MIN_TZ_ADJ
;
476 server
->timeAdj
= result
;
478 server
->timeAdj
= (int)tmp
;
479 server
->timeAdj
*= 60; /* also in seconds */
481 cFYI(1, "server->timeAdj: %d seconds", server
->timeAdj
);
484 /* BB get server time for time conversions and add
485 code to use it and timezone since this is not UTC */
487 if (rsp
->EncryptionKeyLength
==
488 cpu_to_le16(CIFS_CRYPTO_KEY_SIZE
)) {
489 memcpy(server
->cryptKey
, rsp
->EncryptionKey
,
490 CIFS_CRYPTO_KEY_SIZE
);
491 } else if (server
->secMode
& SECMODE_PW_ENCRYPT
) {
492 rc
= -EIO
; /* need cryptkey unless plain text */
496 cFYI(1, "LANMAN negotiated");
497 /* we will not end up setting signing flags - as no signing
498 was in LANMAN and server did not return the flags on */
500 #else /* weak security disabled */
501 } else if (pSMBr
->hdr
.WordCount
== 13) {
502 cERROR(1, "mount failed, cifs module not built "
503 "with CIFS_WEAK_PW_HASH support");
505 #endif /* WEAK_PW_HASH */
507 } else if (pSMBr
->hdr
.WordCount
!= 17) {
512 /* else wct == 17 NTLM */
513 server
->secMode
= pSMBr
->SecurityMode
;
514 if ((server
->secMode
& SECMODE_USER
) == 0)
515 cFYI(1, "share mode security");
517 if ((server
->secMode
& SECMODE_PW_ENCRYPT
) == 0)
518 #ifdef CONFIG_CIFS_WEAK_PW_HASH
519 if ((secFlags
& CIFSSEC_MAY_PLNTXT
) == 0)
520 #endif /* CIFS_WEAK_PW_HASH */
521 cERROR(1, "Server requests plain text password"
522 " but client support disabled");
524 if ((secFlags
& CIFSSEC_MUST_NTLMV2
) == CIFSSEC_MUST_NTLMV2
)
525 server
->secType
= NTLMv2
;
526 else if (secFlags
& CIFSSEC_MAY_NTLM
)
527 server
->secType
= NTLM
;
528 else if (secFlags
& CIFSSEC_MAY_NTLMV2
)
529 server
->secType
= NTLMv2
;
530 else if (secFlags
& CIFSSEC_MAY_KRB5
)
531 server
->secType
= Kerberos
;
532 else if (secFlags
& CIFSSEC_MAY_NTLMSSP
)
533 server
->secType
= RawNTLMSSP
;
534 else if (secFlags
& CIFSSEC_MAY_LANMAN
)
535 server
->secType
= LANMAN
;
536 /* #ifdef CONFIG_CIFS_EXPERIMENTAL
537 else if (secFlags & CIFSSEC_MAY_PLNTXT)
542 cERROR(1, "Invalid security type");
545 /* else ... any others ...? */
547 /* one byte, so no need to convert this or EncryptionKeyLen from
549 server
->maxReq
= le16_to_cpu(pSMBr
->MaxMpxCount
);
550 /* probably no need to store and check maxvcs */
551 server
->maxBuf
= min(le32_to_cpu(pSMBr
->MaxBufferSize
),
552 (__u32
) CIFSMaxBufSize
+ MAX_CIFS_HDR_SIZE
);
553 server
->max_rw
= le32_to_cpu(pSMBr
->MaxRawSize
);
554 cFYI(DBG2
, "Max buf = %d", ses
->server
->maxBuf
);
555 GETU32(ses
->server
->sessid
) = le32_to_cpu(pSMBr
->SessionKey
);
556 server
->capabilities
= le32_to_cpu(pSMBr
->Capabilities
);
557 server
->timeAdj
= (int)(__s16
)le16_to_cpu(pSMBr
->ServerTimeZone
);
558 server
->timeAdj
*= 60;
559 if (pSMBr
->EncryptionKeyLength
== CIFS_CRYPTO_KEY_SIZE
) {
560 memcpy(server
->cryptKey
, pSMBr
->u
.EncryptionKey
,
561 CIFS_CRYPTO_KEY_SIZE
);
562 } else if ((pSMBr
->hdr
.Flags2
& SMBFLG2_EXT_SEC
)
563 && (pSMBr
->EncryptionKeyLength
== 0)) {
564 /* decode security blob */
565 } else if (server
->secMode
& SECMODE_PW_ENCRYPT
) {
566 rc
= -EIO
; /* no crypt key only if plain text pwd */
570 /* BB might be helpful to save off the domain of server here */
572 if ((pSMBr
->hdr
.Flags2
& SMBFLG2_EXT_SEC
) &&
573 (server
->capabilities
& CAP_EXTENDED_SECURITY
)) {
574 count
= pSMBr
->ByteCount
;
579 read_lock(&cifs_tcp_ses_lock
);
580 if (server
->srv_count
> 1) {
581 read_unlock(&cifs_tcp_ses_lock
);
582 if (memcmp(server
->server_GUID
,
583 pSMBr
->u
.extended_response
.
585 cFYI(1, "server UID changed");
586 memcpy(server
->server_GUID
,
587 pSMBr
->u
.extended_response
.GUID
,
591 read_unlock(&cifs_tcp_ses_lock
);
592 memcpy(server
->server_GUID
,
593 pSMBr
->u
.extended_response
.GUID
, 16);
597 server
->secType
= RawNTLMSSP
;
599 rc
= decode_negTokenInit(pSMBr
->u
.extended_response
.
600 SecurityBlob
, count
- 16,
607 if (server
->sec_kerberos
|| server
->sec_mskerberos
)
608 server
->secType
= Kerberos
;
609 else if (server
->sec_ntlmssp
)
610 server
->secType
= RawNTLMSSP
;
615 server
->capabilities
&= ~CAP_EXTENDED_SECURITY
;
617 #ifdef CONFIG_CIFS_WEAK_PW_HASH
620 if ((secFlags
& CIFSSEC_MAY_SIGN
) == 0) {
621 /* MUST_SIGN already includes the MAY_SIGN FLAG
622 so if this is zero it means that signing is disabled */
623 cFYI(1, "Signing disabled");
624 if (server
->secMode
& SECMODE_SIGN_REQUIRED
) {
625 cERROR(1, "Server requires "
626 "packet signing to be enabled in "
627 "/proc/fs/cifs/SecurityFlags.");
631 ~(SECMODE_SIGN_ENABLED
| SECMODE_SIGN_REQUIRED
);
632 } else if ((secFlags
& CIFSSEC_MUST_SIGN
) == CIFSSEC_MUST_SIGN
) {
633 /* signing required */
634 cFYI(1, "Must sign - secFlags 0x%x", secFlags
);
635 if ((server
->secMode
&
636 (SECMODE_SIGN_ENABLED
| SECMODE_SIGN_REQUIRED
)) == 0) {
637 cERROR(1, "signing required but server lacks support");
640 server
->secMode
|= SECMODE_SIGN_REQUIRED
;
642 /* signing optional ie CIFSSEC_MAY_SIGN */
643 if ((server
->secMode
& SECMODE_SIGN_REQUIRED
) == 0)
645 ~(SECMODE_SIGN_ENABLED
| SECMODE_SIGN_REQUIRED
);
649 cifs_buf_release(pSMB
);
651 cFYI(1, "negprot rc %d", rc
);
656 CIFSSMBTDis(const int xid
, struct cifsTconInfo
*tcon
)
658 struct smb_hdr
*smb_buffer
;
661 cFYI(1, "In tree disconnect");
663 /* BB: do we need to check this? These should never be NULL. */
664 if ((tcon
->ses
== NULL
) || (tcon
->ses
->server
== NULL
))
668 * No need to return error on this operation if tid invalidated and
669 * closed on server already e.g. due to tcp session crashing. Also,
670 * the tcon is no longer on the list, so no need to take lock before
673 if ((tcon
->need_reconnect
) || (tcon
->ses
->need_reconnect
))
676 rc
= small_smb_init(SMB_COM_TREE_DISCONNECT
, 0, tcon
,
677 (void **)&smb_buffer
);
681 rc
= SendReceiveNoRsp(xid
, tcon
->ses
, smb_buffer
, 0);
683 cFYI(1, "Tree disconnect failed %d", rc
);
685 /* No need to return error on this operation if tid invalidated and
686 closed on server already e.g. due to tcp session crashing */
694 CIFSSMBLogoff(const int xid
, struct cifsSesInfo
*ses
)
696 LOGOFF_ANDX_REQ
*pSMB
;
699 cFYI(1, "In SMBLogoff for session disconnect");
702 * BB: do we need to check validity of ses and server? They should
703 * always be valid since we have an active reference. If not, that
704 * should probably be a BUG()
706 if (!ses
|| !ses
->server
)
709 mutex_lock(&ses
->session_mutex
);
710 if (ses
->need_reconnect
)
711 goto session_already_dead
; /* no need to send SMBlogoff if uid
712 already closed due to reconnect */
713 rc
= small_smb_init(SMB_COM_LOGOFF_ANDX
, 2, NULL
, (void **)&pSMB
);
715 mutex_unlock(&ses
->session_mutex
);
719 pSMB
->hdr
.Mid
= GetNextMid(ses
->server
);
721 if (ses
->server
->secMode
&
722 (SECMODE_SIGN_REQUIRED
| SECMODE_SIGN_ENABLED
))
723 pSMB
->hdr
.Flags2
|= SMBFLG2_SECURITY_SIGNATURE
;
725 pSMB
->hdr
.Uid
= ses
->Suid
;
727 pSMB
->AndXCommand
= 0xFF;
728 rc
= SendReceiveNoRsp(xid
, ses
, (struct smb_hdr
*) pSMB
, 0);
729 session_already_dead
:
730 mutex_unlock(&ses
->session_mutex
);
732 /* if session dead then we do not need to do ulogoff,
733 since server closed smb session, no sense reporting
741 CIFSPOSIXDelFile(const int xid
, struct cifsTconInfo
*tcon
, const char *fileName
,
742 __u16 type
, const struct nls_table
*nls_codepage
, int remap
)
744 TRANSACTION2_SPI_REQ
*pSMB
= NULL
;
745 TRANSACTION2_SPI_RSP
*pSMBr
= NULL
;
746 struct unlink_psx_rq
*pRqD
;
749 int bytes_returned
= 0;
750 __u16 params
, param_offset
, offset
, byte_count
;
752 cFYI(1, "In POSIX delete");
754 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
759 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
761 cifsConvertToUCS((__le16
*) pSMB
->FileName
, fileName
,
762 PATH_MAX
, nls_codepage
, remap
);
763 name_len
++; /* trailing null */
765 } else { /* BB add path length overrun check */
766 name_len
= strnlen(fileName
, PATH_MAX
);
767 name_len
++; /* trailing null */
768 strncpy(pSMB
->FileName
, fileName
, name_len
);
771 params
= 6 + name_len
;
772 pSMB
->MaxParameterCount
= cpu_to_le16(2);
773 pSMB
->MaxDataCount
= 0; /* BB double check this with jra */
774 pSMB
->MaxSetupCount
= 0;
779 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
780 InformationLevel
) - 4;
781 offset
= param_offset
+ params
;
783 /* Setup pointer to Request Data (inode type) */
784 pRqD
= (struct unlink_psx_rq
*)(((char *)&pSMB
->hdr
.Protocol
) + offset
);
785 pRqD
->type
= cpu_to_le16(type
);
786 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
787 pSMB
->DataOffset
= cpu_to_le16(offset
);
788 pSMB
->SetupCount
= 1;
790 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
791 byte_count
= 3 /* pad */ + params
+ sizeof(struct unlink_psx_rq
);
793 pSMB
->DataCount
= cpu_to_le16(sizeof(struct unlink_psx_rq
));
794 pSMB
->TotalDataCount
= cpu_to_le16(sizeof(struct unlink_psx_rq
));
795 pSMB
->ParameterCount
= cpu_to_le16(params
);
796 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
797 pSMB
->InformationLevel
= cpu_to_le16(SMB_POSIX_UNLINK
);
799 pSMB
->hdr
.smb_buf_length
+= byte_count
;
800 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
801 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
802 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
804 cFYI(1, "Posix delete returned %d", rc
);
805 cifs_buf_release(pSMB
);
807 cifs_stats_inc(&tcon
->num_deletes
);
816 CIFSSMBDelFile(const int xid
, struct cifsTconInfo
*tcon
, const char *fileName
,
817 const struct nls_table
*nls_codepage
, int remap
)
819 DELETE_FILE_REQ
*pSMB
= NULL
;
820 DELETE_FILE_RSP
*pSMBr
= NULL
;
826 rc
= smb_init(SMB_COM_DELETE
, 1, tcon
, (void **) &pSMB
,
831 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
833 cifsConvertToUCS((__le16
*) pSMB
->fileName
, fileName
,
834 PATH_MAX
, nls_codepage
, remap
);
835 name_len
++; /* trailing null */
837 } else { /* BB improve check for buffer overruns BB */
838 name_len
= strnlen(fileName
, PATH_MAX
);
839 name_len
++; /* trailing null */
840 strncpy(pSMB
->fileName
, fileName
, name_len
);
842 pSMB
->SearchAttributes
=
843 cpu_to_le16(ATTR_READONLY
| ATTR_HIDDEN
| ATTR_SYSTEM
);
844 pSMB
->BufferFormat
= 0x04;
845 pSMB
->hdr
.smb_buf_length
+= name_len
+ 1;
846 pSMB
->ByteCount
= cpu_to_le16(name_len
+ 1);
847 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
848 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
849 cifs_stats_inc(&tcon
->num_deletes
);
851 cFYI(1, "Error in RMFile = %d", rc
);
853 cifs_buf_release(pSMB
);
861 CIFSSMBRmDir(const int xid
, struct cifsTconInfo
*tcon
, const char *dirName
,
862 const struct nls_table
*nls_codepage
, int remap
)
864 DELETE_DIRECTORY_REQ
*pSMB
= NULL
;
865 DELETE_DIRECTORY_RSP
*pSMBr
= NULL
;
870 cFYI(1, "In CIFSSMBRmDir");
872 rc
= smb_init(SMB_COM_DELETE_DIRECTORY
, 0, tcon
, (void **) &pSMB
,
877 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
878 name_len
= cifsConvertToUCS((__le16
*) pSMB
->DirName
, dirName
,
879 PATH_MAX
, nls_codepage
, remap
);
880 name_len
++; /* trailing null */
882 } else { /* BB improve check for buffer overruns BB */
883 name_len
= strnlen(dirName
, PATH_MAX
);
884 name_len
++; /* trailing null */
885 strncpy(pSMB
->DirName
, dirName
, name_len
);
888 pSMB
->BufferFormat
= 0x04;
889 pSMB
->hdr
.smb_buf_length
+= name_len
+ 1;
890 pSMB
->ByteCount
= cpu_to_le16(name_len
+ 1);
891 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
892 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
893 cifs_stats_inc(&tcon
->num_rmdirs
);
895 cFYI(1, "Error in RMDir = %d", rc
);
897 cifs_buf_release(pSMB
);
904 CIFSSMBMkDir(const int xid
, struct cifsTconInfo
*tcon
,
905 const char *name
, const struct nls_table
*nls_codepage
, int remap
)
908 CREATE_DIRECTORY_REQ
*pSMB
= NULL
;
909 CREATE_DIRECTORY_RSP
*pSMBr
= NULL
;
913 cFYI(1, "In CIFSSMBMkDir");
915 rc
= smb_init(SMB_COM_CREATE_DIRECTORY
, 0, tcon
, (void **) &pSMB
,
920 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
921 name_len
= cifsConvertToUCS((__le16
*) pSMB
->DirName
, name
,
922 PATH_MAX
, nls_codepage
, remap
);
923 name_len
++; /* trailing null */
925 } else { /* BB improve check for buffer overruns BB */
926 name_len
= strnlen(name
, PATH_MAX
);
927 name_len
++; /* trailing null */
928 strncpy(pSMB
->DirName
, name
, name_len
);
931 pSMB
->BufferFormat
= 0x04;
932 pSMB
->hdr
.smb_buf_length
+= name_len
+ 1;
933 pSMB
->ByteCount
= cpu_to_le16(name_len
+ 1);
934 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
935 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
936 cifs_stats_inc(&tcon
->num_mkdirs
);
938 cFYI(1, "Error in Mkdir = %d", rc
);
940 cifs_buf_release(pSMB
);
947 CIFSPOSIXCreate(const int xid
, struct cifsTconInfo
*tcon
, __u32 posix_flags
,
948 __u64 mode
, __u16
*netfid
, FILE_UNIX_BASIC_INFO
*pRetData
,
949 __u32
*pOplock
, const char *name
,
950 const struct nls_table
*nls_codepage
, int remap
)
952 TRANSACTION2_SPI_REQ
*pSMB
= NULL
;
953 TRANSACTION2_SPI_RSP
*pSMBr
= NULL
;
956 int bytes_returned
= 0;
957 __u16 params
, param_offset
, offset
, byte_count
, count
;
959 OPEN_PSX_RSP
*psx_rsp
;
961 cFYI(1, "In POSIX Create");
963 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
968 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
970 cifsConvertToUCS((__le16
*) pSMB
->FileName
, name
,
971 PATH_MAX
, nls_codepage
, remap
);
972 name_len
++; /* trailing null */
974 } else { /* BB improve the check for buffer overruns BB */
975 name_len
= strnlen(name
, PATH_MAX
);
976 name_len
++; /* trailing null */
977 strncpy(pSMB
->FileName
, name
, name_len
);
980 params
= 6 + name_len
;
981 count
= sizeof(OPEN_PSX_REQ
);
982 pSMB
->MaxParameterCount
= cpu_to_le16(2);
983 pSMB
->MaxDataCount
= cpu_to_le16(1000); /* large enough */
984 pSMB
->MaxSetupCount
= 0;
989 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
990 InformationLevel
) - 4;
991 offset
= param_offset
+ params
;
992 pdata
= (OPEN_PSX_REQ
*)(((char *)&pSMB
->hdr
.Protocol
) + offset
);
993 pdata
->Level
= cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC
);
994 pdata
->Permissions
= cpu_to_le64(mode
);
995 pdata
->PosixOpenFlags
= cpu_to_le32(posix_flags
);
996 pdata
->OpenFlags
= cpu_to_le32(*pOplock
);
997 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
998 pSMB
->DataOffset
= cpu_to_le16(offset
);
999 pSMB
->SetupCount
= 1;
1000 pSMB
->Reserved3
= 0;
1001 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
1002 byte_count
= 3 /* pad */ + params
+ count
;
1004 pSMB
->DataCount
= cpu_to_le16(count
);
1005 pSMB
->ParameterCount
= cpu_to_le16(params
);
1006 pSMB
->TotalDataCount
= pSMB
->DataCount
;
1007 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
1008 pSMB
->InformationLevel
= cpu_to_le16(SMB_POSIX_OPEN
);
1009 pSMB
->Reserved4
= 0;
1010 pSMB
->hdr
.smb_buf_length
+= byte_count
;
1011 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
1012 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
1013 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
1015 cFYI(1, "Posix create returned %d", rc
);
1016 goto psx_create_err
;
1019 cFYI(1, "copying inode info");
1020 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
1022 if (rc
|| (pSMBr
->ByteCount
< sizeof(OPEN_PSX_RSP
))) {
1023 rc
= -EIO
; /* bad smb */
1024 goto psx_create_err
;
1027 /* copy return information to pRetData */
1028 psx_rsp
= (OPEN_PSX_RSP
*)((char *) &pSMBr
->hdr
.Protocol
1029 + le16_to_cpu(pSMBr
->t2
.DataOffset
));
1031 *pOplock
= le16_to_cpu(psx_rsp
->OplockFlags
);
1033 *netfid
= psx_rsp
->Fid
; /* cifs fid stays in le */
1034 /* Let caller know file was created so we can set the mode. */
1035 /* Do we care about the CreateAction in any other cases? */
1036 if (cpu_to_le32(FILE_CREATE
) == psx_rsp
->CreateAction
)
1037 *pOplock
|= CIFS_CREATE_ACTION
;
1038 /* check to make sure response data is there */
1039 if (psx_rsp
->ReturnedLevel
!= cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC
)) {
1040 pRetData
->Type
= cpu_to_le32(-1); /* unknown */
1041 cFYI(DBG2
, "unknown type");
1043 if (pSMBr
->ByteCount
< sizeof(OPEN_PSX_RSP
)
1044 + sizeof(FILE_UNIX_BASIC_INFO
)) {
1045 cERROR(1, "Open response data too small");
1046 pRetData
->Type
= cpu_to_le32(-1);
1047 goto psx_create_err
;
1049 memcpy((char *) pRetData
,
1050 (char *)psx_rsp
+ sizeof(OPEN_PSX_RSP
),
1051 sizeof(FILE_UNIX_BASIC_INFO
));
1055 cifs_buf_release(pSMB
);
1057 if (posix_flags
& SMB_O_DIRECTORY
)
1058 cifs_stats_inc(&tcon
->num_posixmkdirs
);
1060 cifs_stats_inc(&tcon
->num_posixopens
);
1068 static __u16
convert_disposition(int disposition
)
1072 switch (disposition
) {
1073 case FILE_SUPERSEDE
:
1074 ofun
= SMBOPEN_OCREATE
| SMBOPEN_OTRUNC
;
1077 ofun
= SMBOPEN_OAPPEND
;
1080 ofun
= SMBOPEN_OCREATE
;
1083 ofun
= SMBOPEN_OCREATE
| SMBOPEN_OAPPEND
;
1085 case FILE_OVERWRITE
:
1086 ofun
= SMBOPEN_OTRUNC
;
1088 case FILE_OVERWRITE_IF
:
1089 ofun
= SMBOPEN_OCREATE
| SMBOPEN_OTRUNC
;
1092 cFYI(1, "unknown disposition %d", disposition
);
1093 ofun
= SMBOPEN_OAPPEND
; /* regular open */
1099 access_flags_to_smbopen_mode(const int access_flags
)
1101 int masked_flags
= access_flags
& (GENERIC_READ
| GENERIC_WRITE
);
1103 if (masked_flags
== GENERIC_READ
)
1104 return SMBOPEN_READ
;
1105 else if (masked_flags
== GENERIC_WRITE
)
1106 return SMBOPEN_WRITE
;
1108 /* just go for read/write */
1109 return SMBOPEN_READWRITE
;
1113 SMBLegacyOpen(const int xid
, struct cifsTconInfo
*tcon
,
1114 const char *fileName
, const int openDisposition
,
1115 const int access_flags
, const int create_options
, __u16
*netfid
,
1116 int *pOplock
, FILE_ALL_INFO
*pfile_info
,
1117 const struct nls_table
*nls_codepage
, int remap
)
1120 OPENX_REQ
*pSMB
= NULL
;
1121 OPENX_RSP
*pSMBr
= NULL
;
1127 rc
= smb_init(SMB_COM_OPEN_ANDX
, 15, tcon
, (void **) &pSMB
,
1132 pSMB
->AndXCommand
= 0xFF; /* none */
1134 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
1135 count
= 1; /* account for one byte pad to word boundary */
1137 cifsConvertToUCS((__le16
*) (pSMB
->fileName
+ 1),
1138 fileName
, PATH_MAX
, nls_codepage
, remap
);
1139 name_len
++; /* trailing null */
1141 } else { /* BB improve check for buffer overruns BB */
1142 count
= 0; /* no pad */
1143 name_len
= strnlen(fileName
, PATH_MAX
);
1144 name_len
++; /* trailing null */
1145 strncpy(pSMB
->fileName
, fileName
, name_len
);
1147 if (*pOplock
& REQ_OPLOCK
)
1148 pSMB
->OpenFlags
= cpu_to_le16(REQ_OPLOCK
);
1149 else if (*pOplock
& REQ_BATCHOPLOCK
)
1150 pSMB
->OpenFlags
= cpu_to_le16(REQ_BATCHOPLOCK
);
1152 pSMB
->OpenFlags
|= cpu_to_le16(REQ_MORE_INFO
);
1153 pSMB
->Mode
= cpu_to_le16(access_flags_to_smbopen_mode(access_flags
));
1154 pSMB
->Mode
|= cpu_to_le16(0x40); /* deny none */
1155 /* set file as system file if special file such
1156 as fifo and server expecting SFU style and
1157 no Unix extensions */
1159 if (create_options
& CREATE_OPTION_SPECIAL
)
1160 pSMB
->FileAttributes
= cpu_to_le16(ATTR_SYSTEM
);
1161 else /* BB FIXME BB */
1162 pSMB
->FileAttributes
= cpu_to_le16(0/*ATTR_NORMAL*/);
1164 if (create_options
& CREATE_OPTION_READONLY
)
1165 pSMB
->FileAttributes
|= cpu_to_le16(ATTR_READONLY
);
1168 /* pSMB->CreateOptions = cpu_to_le32(create_options &
1169 CREATE_OPTIONS_MASK); */
1170 /* BB FIXME END BB */
1172 pSMB
->Sattr
= cpu_to_le16(ATTR_HIDDEN
| ATTR_SYSTEM
| ATTR_DIRECTORY
);
1173 pSMB
->OpenFunction
= cpu_to_le16(convert_disposition(openDisposition
));
1175 pSMB
->hdr
.smb_buf_length
+= count
;
1177 pSMB
->ByteCount
= cpu_to_le16(count
);
1178 /* long_op set to 1 to allow for oplock break timeouts */
1179 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
1180 (struct smb_hdr
*)pSMBr
, &bytes_returned
, CIFS_LONG_OP
);
1181 cifs_stats_inc(&tcon
->num_opens
);
1183 cFYI(1, "Error in Open = %d", rc
);
1185 /* BB verify if wct == 15 */
1187 /* *pOplock = pSMBr->OplockLevel; */ /* BB take from action field*/
1189 *netfid
= pSMBr
->Fid
; /* cifs fid stays in le */
1190 /* Let caller know file was created so we can set the mode. */
1191 /* Do we care about the CreateAction in any other cases? */
1193 /* if (cpu_to_le32(FILE_CREATE) == pSMBr->CreateAction)
1194 *pOplock |= CIFS_CREATE_ACTION; */
1198 pfile_info
->CreationTime
= 0; /* BB convert CreateTime*/
1199 pfile_info
->LastAccessTime
= 0; /* BB fixme */
1200 pfile_info
->LastWriteTime
= 0; /* BB fixme */
1201 pfile_info
->ChangeTime
= 0; /* BB fixme */
1202 pfile_info
->Attributes
=
1203 cpu_to_le32(le16_to_cpu(pSMBr
->FileAttributes
));
1204 /* the file_info buf is endian converted by caller */
1205 pfile_info
->AllocationSize
=
1206 cpu_to_le64(le32_to_cpu(pSMBr
->EndOfFile
));
1207 pfile_info
->EndOfFile
= pfile_info
->AllocationSize
;
1208 pfile_info
->NumberOfLinks
= cpu_to_le32(1);
1209 pfile_info
->DeletePending
= 0;
1213 cifs_buf_release(pSMB
);
1220 CIFSSMBOpen(const int xid
, struct cifsTconInfo
*tcon
,
1221 const char *fileName
, const int openDisposition
,
1222 const int access_flags
, const int create_options
, __u16
*netfid
,
1223 int *pOplock
, FILE_ALL_INFO
*pfile_info
,
1224 const struct nls_table
*nls_codepage
, int remap
)
1227 OPEN_REQ
*pSMB
= NULL
;
1228 OPEN_RSP
*pSMBr
= NULL
;
1234 rc
= smb_init(SMB_COM_NT_CREATE_ANDX
, 24, tcon
, (void **) &pSMB
,
1239 pSMB
->AndXCommand
= 0xFF; /* none */
1241 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
1242 count
= 1; /* account for one byte pad to word boundary */
1244 cifsConvertToUCS((__le16
*) (pSMB
->fileName
+ 1),
1245 fileName
, PATH_MAX
, nls_codepage
, remap
);
1246 name_len
++; /* trailing null */
1248 pSMB
->NameLength
= cpu_to_le16(name_len
);
1249 } else { /* BB improve check for buffer overruns BB */
1250 count
= 0; /* no pad */
1251 name_len
= strnlen(fileName
, PATH_MAX
);
1252 name_len
++; /* trailing null */
1253 pSMB
->NameLength
= cpu_to_le16(name_len
);
1254 strncpy(pSMB
->fileName
, fileName
, name_len
);
1256 if (*pOplock
& REQ_OPLOCK
)
1257 pSMB
->OpenFlags
= cpu_to_le32(REQ_OPLOCK
);
1258 else if (*pOplock
& REQ_BATCHOPLOCK
)
1259 pSMB
->OpenFlags
= cpu_to_le32(REQ_BATCHOPLOCK
);
1260 pSMB
->DesiredAccess
= cpu_to_le32(access_flags
);
1261 pSMB
->AllocationSize
= 0;
1262 /* set file as system file if special file such
1263 as fifo and server expecting SFU style and
1264 no Unix extensions */
1265 if (create_options
& CREATE_OPTION_SPECIAL
)
1266 pSMB
->FileAttributes
= cpu_to_le32(ATTR_SYSTEM
);
1268 pSMB
->FileAttributes
= cpu_to_le32(ATTR_NORMAL
);
1270 /* XP does not handle ATTR_POSIX_SEMANTICS */
1271 /* but it helps speed up case sensitive checks for other
1272 servers such as Samba */
1273 if (tcon
->ses
->capabilities
& CAP_UNIX
)
1274 pSMB
->FileAttributes
|= cpu_to_le32(ATTR_POSIX_SEMANTICS
);
1276 if (create_options
& CREATE_OPTION_READONLY
)
1277 pSMB
->FileAttributes
|= cpu_to_le32(ATTR_READONLY
);
1279 pSMB
->ShareAccess
= cpu_to_le32(FILE_SHARE_ALL
);
1280 pSMB
->CreateDisposition
= cpu_to_le32(openDisposition
);
1281 pSMB
->CreateOptions
= cpu_to_le32(create_options
& CREATE_OPTIONS_MASK
);
1282 /* BB Expirement with various impersonation levels and verify */
1283 pSMB
->ImpersonationLevel
= cpu_to_le32(SECURITY_IMPERSONATION
);
1284 pSMB
->SecurityFlags
=
1285 SECURITY_CONTEXT_TRACKING
| SECURITY_EFFECTIVE_ONLY
;
1288 pSMB
->hdr
.smb_buf_length
+= count
;
1290 pSMB
->ByteCount
= cpu_to_le16(count
);
1291 /* long_op set to 1 to allow for oplock break timeouts */
1292 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
1293 (struct smb_hdr
*)pSMBr
, &bytes_returned
, CIFS_LONG_OP
);
1294 cifs_stats_inc(&tcon
->num_opens
);
1296 cFYI(1, "Error in Open = %d", rc
);
1298 *pOplock
= pSMBr
->OplockLevel
; /* 1 byte no need to le_to_cpu */
1299 *netfid
= pSMBr
->Fid
; /* cifs fid stays in le */
1300 /* Let caller know file was created so we can set the mode. */
1301 /* Do we care about the CreateAction in any other cases? */
1302 if (cpu_to_le32(FILE_CREATE
) == pSMBr
->CreateAction
)
1303 *pOplock
|= CIFS_CREATE_ACTION
;
1305 memcpy((char *)pfile_info
, (char *)&pSMBr
->CreationTime
,
1306 36 /* CreationTime to Attributes */);
1307 /* the file_info buf is endian converted by caller */
1308 pfile_info
->AllocationSize
= pSMBr
->AllocationSize
;
1309 pfile_info
->EndOfFile
= pSMBr
->EndOfFile
;
1310 pfile_info
->NumberOfLinks
= cpu_to_le32(1);
1311 pfile_info
->DeletePending
= 0;
1315 cifs_buf_release(pSMB
);
1322 CIFSSMBRead(const int xid
, struct cifsTconInfo
*tcon
, const int netfid
,
1323 const unsigned int count
, const __u64 lseek
, unsigned int *nbytes
,
1324 char **buf
, int *pbuf_type
)
1327 READ_REQ
*pSMB
= NULL
;
1328 READ_RSP
*pSMBr
= NULL
;
1329 char *pReadData
= NULL
;
1331 int resp_buf_type
= 0;
1334 cFYI(1, "Reading %d bytes on fid %d", count
, netfid
);
1335 if (tcon
->ses
->capabilities
& CAP_LARGE_FILES
)
1338 wct
= 10; /* old style read */
1339 if ((lseek
>> 32) > 0) {
1340 /* can not handle this big offset for old */
1346 rc
= small_smb_init(SMB_COM_READ_ANDX
, wct
, tcon
, (void **) &pSMB
);
1350 /* tcon and ses pointer are checked in smb_init */
1351 if (tcon
->ses
->server
== NULL
)
1352 return -ECONNABORTED
;
1354 pSMB
->AndXCommand
= 0xFF; /* none */
1356 pSMB
->OffsetLow
= cpu_to_le32(lseek
& 0xFFFFFFFF);
1358 pSMB
->OffsetHigh
= cpu_to_le32(lseek
>> 32);
1360 pSMB
->Remaining
= 0;
1361 pSMB
->MaxCount
= cpu_to_le16(count
& 0xFFFF);
1362 pSMB
->MaxCountHigh
= cpu_to_le32(count
>> 16);
1364 pSMB
->ByteCount
= 0; /* no need to do le conversion since 0 */
1366 /* old style read */
1367 struct smb_com_readx_req
*pSMBW
=
1368 (struct smb_com_readx_req
*)pSMB
;
1369 pSMBW
->ByteCount
= 0;
1372 iov
[0].iov_base
= (char *)pSMB
;
1373 iov
[0].iov_len
= pSMB
->hdr
.smb_buf_length
+ 4;
1374 rc
= SendReceive2(xid
, tcon
->ses
, iov
, 1 /* num iovecs */,
1375 &resp_buf_type
, CIFS_STD_OP
| CIFS_LOG_ERROR
);
1376 cifs_stats_inc(&tcon
->num_reads
);
1377 pSMBr
= (READ_RSP
*)iov
[0].iov_base
;
1379 cERROR(1, "Send error in read = %d", rc
);
1381 int data_length
= le16_to_cpu(pSMBr
->DataLengthHigh
);
1382 data_length
= data_length
<< 16;
1383 data_length
+= le16_to_cpu(pSMBr
->DataLength
);
1384 *nbytes
= data_length
;
1386 /*check that DataLength would not go beyond end of SMB */
1387 if ((data_length
> CIFSMaxBufSize
)
1388 || (data_length
> count
)) {
1389 cFYI(1, "bad length %d for count %d",
1390 data_length
, count
);
1394 pReadData
= (char *) (&pSMBr
->hdr
.Protocol
) +
1395 le16_to_cpu(pSMBr
->DataOffset
);
1396 /* if (rc = copy_to_user(buf, pReadData, data_length)) {
1397 cERROR(1, "Faulting on read rc = %d",rc);
1399 }*/ /* can not use copy_to_user when using page cache*/
1401 memcpy(*buf
, pReadData
, data_length
);
1405 /* cifs_small_buf_release(pSMB); */ /* Freed earlier now in SendReceive2 */
1407 if (resp_buf_type
== CIFS_SMALL_BUFFER
)
1408 cifs_small_buf_release(iov
[0].iov_base
);
1409 else if (resp_buf_type
== CIFS_LARGE_BUFFER
)
1410 cifs_buf_release(iov
[0].iov_base
);
1411 } else if (resp_buf_type
!= CIFS_NO_BUFFER
) {
1412 /* return buffer to caller to free */
1413 *buf
= iov
[0].iov_base
;
1414 if (resp_buf_type
== CIFS_SMALL_BUFFER
)
1415 *pbuf_type
= CIFS_SMALL_BUFFER
;
1416 else if (resp_buf_type
== CIFS_LARGE_BUFFER
)
1417 *pbuf_type
= CIFS_LARGE_BUFFER
;
1418 } /* else no valid buffer on return - leave as null */
1420 /* Note: On -EAGAIN error only caller can retry on handle based calls
1421 since file handle passed in no longer valid */
1427 CIFSSMBWrite(const int xid
, struct cifsTconInfo
*tcon
,
1428 const int netfid
, const unsigned int count
,
1429 const __u64 offset
, unsigned int *nbytes
, const char *buf
,
1430 const char __user
*ubuf
, const int long_op
)
1433 WRITE_REQ
*pSMB
= NULL
;
1434 WRITE_RSP
*pSMBr
= NULL
;
1435 int bytes_returned
, wct
;
1441 /* cFYI(1, "write at %lld %d bytes", offset, count);*/
1442 if (tcon
->ses
== NULL
)
1443 return -ECONNABORTED
;
1445 if (tcon
->ses
->capabilities
& CAP_LARGE_FILES
)
1449 if ((offset
>> 32) > 0) {
1450 /* can not handle big offset for old srv */
1455 rc
= smb_init(SMB_COM_WRITE_ANDX
, wct
, tcon
, (void **) &pSMB
,
1459 /* tcon and ses pointer are checked in smb_init */
1460 if (tcon
->ses
->server
== NULL
)
1461 return -ECONNABORTED
;
1463 pSMB
->AndXCommand
= 0xFF; /* none */
1465 pSMB
->OffsetLow
= cpu_to_le32(offset
& 0xFFFFFFFF);
1467 pSMB
->OffsetHigh
= cpu_to_le32(offset
>> 32);
1469 pSMB
->Reserved
= 0xFFFFFFFF;
1470 pSMB
->WriteMode
= 0;
1471 pSMB
->Remaining
= 0;
1473 /* Can increase buffer size if buffer is big enough in some cases ie we
1474 can send more if LARGE_WRITE_X capability returned by the server and if
1475 our buffer is big enough or if we convert to iovecs on socket writes
1476 and eliminate the copy to the CIFS buffer */
1477 if (tcon
->ses
->capabilities
& CAP_LARGE_WRITE_X
) {
1478 bytes_sent
= min_t(const unsigned int, CIFSMaxBufSize
, count
);
1480 bytes_sent
= (tcon
->ses
->server
->maxBuf
- MAX_CIFS_HDR_SIZE
)
1484 if (bytes_sent
> count
)
1487 cpu_to_le16(offsetof(struct smb_com_write_req
, Data
) - 4);
1489 memcpy(pSMB
->Data
, buf
, bytes_sent
);
1491 if (copy_from_user(pSMB
->Data
, ubuf
, bytes_sent
)) {
1492 cifs_buf_release(pSMB
);
1495 } else if (count
!= 0) {
1497 cifs_buf_release(pSMB
);
1499 } /* else setting file size with write of zero bytes */
1501 byte_count
= bytes_sent
+ 1; /* pad */
1502 else /* wct == 12 */
1503 byte_count
= bytes_sent
+ 5; /* bigger pad, smaller smb hdr */
1505 pSMB
->DataLengthLow
= cpu_to_le16(bytes_sent
& 0xFFFF);
1506 pSMB
->DataLengthHigh
= cpu_to_le16(bytes_sent
>> 16);
1507 pSMB
->hdr
.smb_buf_length
+= byte_count
;
1510 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
1511 else { /* old style write has byte count 4 bytes earlier
1513 struct smb_com_writex_req
*pSMBW
=
1514 (struct smb_com_writex_req
*)pSMB
;
1515 pSMBW
->ByteCount
= cpu_to_le16(byte_count
);
1518 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
1519 (struct smb_hdr
*) pSMBr
, &bytes_returned
, long_op
);
1520 cifs_stats_inc(&tcon
->num_writes
);
1522 cFYI(1, "Send error in write = %d", rc
);
1524 *nbytes
= le16_to_cpu(pSMBr
->CountHigh
);
1525 *nbytes
= (*nbytes
) << 16;
1526 *nbytes
+= le16_to_cpu(pSMBr
->Count
);
1529 * Mask off high 16 bits when bytes written as returned by the
1530 * server is greater than bytes requested by the client. Some
1531 * OS/2 servers are known to set incorrect CountHigh values.
1533 if (*nbytes
> count
)
1537 cifs_buf_release(pSMB
);
1539 /* Note: On -EAGAIN error only caller can retry on handle based calls
1540 since file handle passed in no longer valid */
1546 CIFSSMBWrite2(const int xid
, struct cifsTconInfo
*tcon
,
1547 const int netfid
, const unsigned int count
,
1548 const __u64 offset
, unsigned int *nbytes
, struct kvec
*iov
,
1549 int n_vec
, const int long_op
)
1552 WRITE_REQ
*pSMB
= NULL
;
1555 int resp_buf_type
= 0;
1559 cFYI(1, "write2 at %lld %d bytes", (long long)offset
, count
);
1561 if (tcon
->ses
->capabilities
& CAP_LARGE_FILES
) {
1565 if ((offset
>> 32) > 0) {
1566 /* can not handle big offset for old srv */
1570 rc
= small_smb_init(SMB_COM_WRITE_ANDX
, wct
, tcon
, (void **) &pSMB
);
1573 /* tcon and ses pointer are checked in smb_init */
1574 if (tcon
->ses
->server
== NULL
)
1575 return -ECONNABORTED
;
1577 pSMB
->AndXCommand
= 0xFF; /* none */
1579 pSMB
->OffsetLow
= cpu_to_le32(offset
& 0xFFFFFFFF);
1581 pSMB
->OffsetHigh
= cpu_to_le32(offset
>> 32);
1582 pSMB
->Reserved
= 0xFFFFFFFF;
1583 pSMB
->WriteMode
= 0;
1584 pSMB
->Remaining
= 0;
1587 cpu_to_le16(offsetof(struct smb_com_write_req
, Data
) - 4);
1589 pSMB
->DataLengthLow
= cpu_to_le16(count
& 0xFFFF);
1590 pSMB
->DataLengthHigh
= cpu_to_le16(count
>> 16);
1591 smb_hdr_len
= pSMB
->hdr
.smb_buf_length
+ 1; /* hdr + 1 byte pad */
1593 pSMB
->hdr
.smb_buf_length
+= count
+1;
1594 else /* wct == 12 */
1595 pSMB
->hdr
.smb_buf_length
+= count
+5; /* smb data starts later */
1597 pSMB
->ByteCount
= cpu_to_le16(count
+ 1);
1598 else /* wct == 12 */ /* bigger pad, smaller smb hdr, keep offset ok */ {
1599 struct smb_com_writex_req
*pSMBW
=
1600 (struct smb_com_writex_req
*)pSMB
;
1601 pSMBW
->ByteCount
= cpu_to_le16(count
+ 5);
1603 iov
[0].iov_base
= pSMB
;
1605 iov
[0].iov_len
= smb_hdr_len
+ 4;
1606 else /* wct == 12 pad bigger by four bytes */
1607 iov
[0].iov_len
= smb_hdr_len
+ 8;
1610 rc
= SendReceive2(xid
, tcon
->ses
, iov
, n_vec
+ 1, &resp_buf_type
,
1612 cifs_stats_inc(&tcon
->num_writes
);
1614 cFYI(1, "Send error Write2 = %d", rc
);
1615 } else if (resp_buf_type
== 0) {
1616 /* presumably this can not happen, but best to be safe */
1619 WRITE_RSP
*pSMBr
= (WRITE_RSP
*)iov
[0].iov_base
;
1620 *nbytes
= le16_to_cpu(pSMBr
->CountHigh
);
1621 *nbytes
= (*nbytes
) << 16;
1622 *nbytes
+= le16_to_cpu(pSMBr
->Count
);
1625 * Mask off high 16 bits when bytes written as returned by the
1626 * server is greater than bytes requested by the client. OS/2
1627 * servers are known to set incorrect CountHigh values.
1629 if (*nbytes
> count
)
1633 /* cifs_small_buf_release(pSMB); */ /* Freed earlier now in SendReceive2 */
1634 if (resp_buf_type
== CIFS_SMALL_BUFFER
)
1635 cifs_small_buf_release(iov
[0].iov_base
);
1636 else if (resp_buf_type
== CIFS_LARGE_BUFFER
)
1637 cifs_buf_release(iov
[0].iov_base
);
1639 /* Note: On -EAGAIN error only caller can retry on handle based calls
1640 since file handle passed in no longer valid */
1647 CIFSSMBLock(const int xid
, struct cifsTconInfo
*tcon
,
1648 const __u16 smb_file_id
, const __u64 len
,
1649 const __u64 offset
, const __u32 numUnlock
,
1650 const __u32 numLock
, const __u8 lockType
, const bool waitFlag
)
1653 LOCK_REQ
*pSMB
= NULL
;
1654 /* LOCK_RSP *pSMBr = NULL; */ /* No response data other than rc to parse */
1659 cFYI(1, "CIFSSMBLock timeout %d numLock %d", (int)waitFlag
, numLock
);
1660 rc
= small_smb_init(SMB_COM_LOCKING_ANDX
, 8, tcon
, (void **) &pSMB
);
1665 if (lockType
== LOCKING_ANDX_OPLOCK_RELEASE
) {
1666 timeout
= CIFS_ASYNC_OP
; /* no response expected */
1668 } else if (waitFlag
) {
1669 timeout
= CIFS_BLOCKING_OP
; /* blocking operation, no timeout */
1670 pSMB
->Timeout
= cpu_to_le32(-1);/* blocking - do not time out */
1675 pSMB
->NumberOfLocks
= cpu_to_le16(numLock
);
1676 pSMB
->NumberOfUnlocks
= cpu_to_le16(numUnlock
);
1677 pSMB
->LockType
= lockType
;
1678 pSMB
->AndXCommand
= 0xFF; /* none */
1679 pSMB
->Fid
= smb_file_id
; /* netfid stays le */
1681 if ((numLock
!= 0) || (numUnlock
!= 0)) {
1682 pSMB
->Locks
[0].Pid
= cpu_to_le16(current
->tgid
);
1683 /* BB where to store pid high? */
1684 pSMB
->Locks
[0].LengthLow
= cpu_to_le32((u32
)len
);
1685 pSMB
->Locks
[0].LengthHigh
= cpu_to_le32((u32
)(len
>>32));
1686 pSMB
->Locks
[0].OffsetLow
= cpu_to_le32((u32
)offset
);
1687 pSMB
->Locks
[0].OffsetHigh
= cpu_to_le32((u32
)(offset
>>32));
1688 count
= sizeof(LOCKING_ANDX_RANGE
);
1693 pSMB
->hdr
.smb_buf_length
+= count
;
1694 pSMB
->ByteCount
= cpu_to_le16(count
);
1697 rc
= SendReceiveBlockingLock(xid
, tcon
, (struct smb_hdr
*) pSMB
,
1698 (struct smb_hdr
*) pSMB
, &bytes_returned
);
1699 cifs_small_buf_release(pSMB
);
1701 rc
= SendReceiveNoRsp(xid
, tcon
->ses
, (struct smb_hdr
*)pSMB
,
1703 /* SMB buffer freed by function above */
1705 cifs_stats_inc(&tcon
->num_locks
);
1707 cFYI(1, "Send error in Lock = %d", rc
);
1709 /* Note: On -EAGAIN error only caller can retry on handle based calls
1710 since file handle passed in no longer valid */
1715 CIFSSMBPosixLock(const int xid
, struct cifsTconInfo
*tcon
,
1716 const __u16 smb_file_id
, const int get_flag
, const __u64 len
,
1717 struct file_lock
*pLockData
, const __u16 lock_type
,
1718 const bool waitFlag
)
1720 struct smb_com_transaction2_sfi_req
*pSMB
= NULL
;
1721 struct smb_com_transaction2_sfi_rsp
*pSMBr
= NULL
;
1722 struct cifs_posix_lock
*parm_data
;
1725 int bytes_returned
= 0;
1726 int resp_buf_type
= 0;
1727 __u16 params
, param_offset
, offset
, byte_count
, count
;
1730 cFYI(1, "Posix Lock");
1732 if (pLockData
== NULL
)
1735 rc
= small_smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
);
1740 pSMBr
= (struct smb_com_transaction2_sfi_rsp
*)pSMB
;
1743 pSMB
->MaxSetupCount
= 0;
1746 pSMB
->Reserved2
= 0;
1747 param_offset
= offsetof(struct smb_com_transaction2_sfi_req
, Fid
) - 4;
1748 offset
= param_offset
+ params
;
1750 count
= sizeof(struct cifs_posix_lock
);
1751 pSMB
->MaxParameterCount
= cpu_to_le16(2);
1752 pSMB
->MaxDataCount
= cpu_to_le16(1000); /* BB find max SMB from sess */
1753 pSMB
->SetupCount
= 1;
1754 pSMB
->Reserved3
= 0;
1756 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION
);
1758 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_FILE_INFORMATION
);
1759 byte_count
= 3 /* pad */ + params
+ count
;
1760 pSMB
->DataCount
= cpu_to_le16(count
);
1761 pSMB
->ParameterCount
= cpu_to_le16(params
);
1762 pSMB
->TotalDataCount
= pSMB
->DataCount
;
1763 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
1764 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
1765 parm_data
= (struct cifs_posix_lock
*)
1766 (((char *) &pSMB
->hdr
.Protocol
) + offset
);
1768 parm_data
->lock_type
= cpu_to_le16(lock_type
);
1770 timeout
= CIFS_BLOCKING_OP
; /* blocking operation, no timeout */
1771 parm_data
->lock_flags
= cpu_to_le16(1);
1772 pSMB
->Timeout
= cpu_to_le32(-1);
1776 parm_data
->pid
= cpu_to_le32(current
->tgid
);
1777 parm_data
->start
= cpu_to_le64(pLockData
->fl_start
);
1778 parm_data
->length
= cpu_to_le64(len
); /* normalize negative numbers */
1780 pSMB
->DataOffset
= cpu_to_le16(offset
);
1781 pSMB
->Fid
= smb_file_id
;
1782 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_POSIX_LOCK
);
1783 pSMB
->Reserved4
= 0;
1784 pSMB
->hdr
.smb_buf_length
+= byte_count
;
1785 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
1787 rc
= SendReceiveBlockingLock(xid
, tcon
, (struct smb_hdr
*) pSMB
,
1788 (struct smb_hdr
*) pSMBr
, &bytes_returned
);
1790 iov
[0].iov_base
= (char *)pSMB
;
1791 iov
[0].iov_len
= pSMB
->hdr
.smb_buf_length
+ 4;
1792 rc
= SendReceive2(xid
, tcon
->ses
, iov
, 1 /* num iovecs */,
1793 &resp_buf_type
, timeout
);
1794 pSMB
= NULL
; /* request buf already freed by SendReceive2. Do
1795 not try to free it twice below on exit */
1796 pSMBr
= (struct smb_com_transaction2_sfi_rsp
*)iov
[0].iov_base
;
1800 cFYI(1, "Send error in Posix Lock = %d", rc
);
1801 } else if (get_flag
) {
1802 /* lock structure can be returned on get */
1805 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
1807 if (rc
|| (pSMBr
->ByteCount
< sizeof(struct cifs_posix_lock
))) {
1808 rc
= -EIO
; /* bad smb */
1811 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
1812 data_count
= le16_to_cpu(pSMBr
->t2
.DataCount
);
1813 if (data_count
< sizeof(struct cifs_posix_lock
)) {
1817 parm_data
= (struct cifs_posix_lock
*)
1818 ((char *)&pSMBr
->hdr
.Protocol
+ data_offset
);
1819 if (parm_data
->lock_type
== __constant_cpu_to_le16(CIFS_UNLCK
))
1820 pLockData
->fl_type
= F_UNLCK
;
1822 if (parm_data
->lock_type
==
1823 __constant_cpu_to_le16(CIFS_RDLCK
))
1824 pLockData
->fl_type
= F_RDLCK
;
1825 else if (parm_data
->lock_type
==
1826 __constant_cpu_to_le16(CIFS_WRLCK
))
1827 pLockData
->fl_type
= F_WRLCK
;
1829 pLockData
->fl_start
= parm_data
->start
;
1830 pLockData
->fl_end
= parm_data
->start
+
1831 parm_data
->length
- 1;
1832 pLockData
->fl_pid
= parm_data
->pid
;
1838 cifs_small_buf_release(pSMB
);
1840 if (resp_buf_type
== CIFS_SMALL_BUFFER
)
1841 cifs_small_buf_release(iov
[0].iov_base
);
1842 else if (resp_buf_type
== CIFS_LARGE_BUFFER
)
1843 cifs_buf_release(iov
[0].iov_base
);
1845 /* Note: On -EAGAIN error only caller can retry on handle based calls
1846 since file handle passed in no longer valid */
1853 CIFSSMBClose(const int xid
, struct cifsTconInfo
*tcon
, int smb_file_id
)
1856 CLOSE_REQ
*pSMB
= NULL
;
1857 cFYI(1, "In CIFSSMBClose");
1859 /* do not retry on dead session on close */
1860 rc
= small_smb_init(SMB_COM_CLOSE
, 3, tcon
, (void **) &pSMB
);
1866 pSMB
->FileID
= (__u16
) smb_file_id
;
1867 pSMB
->LastWriteTime
= 0xFFFFFFFF;
1868 pSMB
->ByteCount
= 0;
1869 rc
= SendReceiveNoRsp(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
, 0);
1870 cifs_stats_inc(&tcon
->num_closes
);
1873 /* EINTR is expected when user ctl-c to kill app */
1874 cERROR(1, "Send error in Close = %d", rc
);
1878 /* Since session is dead, file will be closed on server already */
1886 CIFSSMBFlush(const int xid
, struct cifsTconInfo
*tcon
, int smb_file_id
)
1889 FLUSH_REQ
*pSMB
= NULL
;
1890 cFYI(1, "In CIFSSMBFlush");
1892 rc
= small_smb_init(SMB_COM_FLUSH
, 1, tcon
, (void **) &pSMB
);
1896 pSMB
->FileID
= (__u16
) smb_file_id
;
1897 pSMB
->ByteCount
= 0;
1898 rc
= SendReceiveNoRsp(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
, 0);
1899 cifs_stats_inc(&tcon
->num_flushes
);
1901 cERROR(1, "Send error in Flush = %d", rc
);
1907 CIFSSMBRename(const int xid
, struct cifsTconInfo
*tcon
,
1908 const char *fromName
, const char *toName
,
1909 const struct nls_table
*nls_codepage
, int remap
)
1912 RENAME_REQ
*pSMB
= NULL
;
1913 RENAME_RSP
*pSMBr
= NULL
;
1915 int name_len
, name_len2
;
1918 cFYI(1, "In CIFSSMBRename");
1920 rc
= smb_init(SMB_COM_RENAME
, 1, tcon
, (void **) &pSMB
,
1925 pSMB
->BufferFormat
= 0x04;
1926 pSMB
->SearchAttributes
=
1927 cpu_to_le16(ATTR_READONLY
| ATTR_HIDDEN
| ATTR_SYSTEM
|
1930 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
1932 cifsConvertToUCS((__le16
*) pSMB
->OldFileName
, fromName
,
1933 PATH_MAX
, nls_codepage
, remap
);
1934 name_len
++; /* trailing null */
1936 pSMB
->OldFileName
[name_len
] = 0x04; /* pad */
1937 /* protocol requires ASCII signature byte on Unicode string */
1938 pSMB
->OldFileName
[name_len
+ 1] = 0x00;
1940 cifsConvertToUCS((__le16
*)&pSMB
->OldFileName
[name_len
+ 2],
1941 toName
, PATH_MAX
, nls_codepage
, remap
);
1942 name_len2
+= 1 /* trailing null */ + 1 /* Signature word */ ;
1943 name_len2
*= 2; /* convert to bytes */
1944 } else { /* BB improve the check for buffer overruns BB */
1945 name_len
= strnlen(fromName
, PATH_MAX
);
1946 name_len
++; /* trailing null */
1947 strncpy(pSMB
->OldFileName
, fromName
, name_len
);
1948 name_len2
= strnlen(toName
, PATH_MAX
);
1949 name_len2
++; /* trailing null */
1950 pSMB
->OldFileName
[name_len
] = 0x04; /* 2nd buffer format */
1951 strncpy(&pSMB
->OldFileName
[name_len
+ 1], toName
, name_len2
);
1952 name_len2
++; /* trailing null */
1953 name_len2
++; /* signature byte */
1956 count
= 1 /* 1st signature byte */ + name_len
+ name_len2
;
1957 pSMB
->hdr
.smb_buf_length
+= count
;
1958 pSMB
->ByteCount
= cpu_to_le16(count
);
1960 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
1961 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
1962 cifs_stats_inc(&tcon
->num_renames
);
1964 cFYI(1, "Send error in rename = %d", rc
);
1966 cifs_buf_release(pSMB
);
1974 int CIFSSMBRenameOpenFile(const int xid
, struct cifsTconInfo
*pTcon
,
1975 int netfid
, const char *target_name
,
1976 const struct nls_table
*nls_codepage
, int remap
)
1978 struct smb_com_transaction2_sfi_req
*pSMB
= NULL
;
1979 struct smb_com_transaction2_sfi_rsp
*pSMBr
= NULL
;
1980 struct set_file_rename
*rename_info
;
1982 char dummy_string
[30];
1984 int bytes_returned
= 0;
1986 __u16 params
, param_offset
, offset
, count
, byte_count
;
1988 cFYI(1, "Rename to File by handle");
1989 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, pTcon
, (void **) &pSMB
,
1995 pSMB
->MaxSetupCount
= 0;
1999 pSMB
->Reserved2
= 0;
2000 param_offset
= offsetof(struct smb_com_transaction2_sfi_req
, Fid
) - 4;
2001 offset
= param_offset
+ params
;
2003 data_offset
= (char *) (&pSMB
->hdr
.Protocol
) + offset
;
2004 rename_info
= (struct set_file_rename
*) data_offset
;
2005 pSMB
->MaxParameterCount
= cpu_to_le16(2);
2006 pSMB
->MaxDataCount
= cpu_to_le16(1000); /* BB find max SMB from sess */
2007 pSMB
->SetupCount
= 1;
2008 pSMB
->Reserved3
= 0;
2009 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_FILE_INFORMATION
);
2010 byte_count
= 3 /* pad */ + params
;
2011 pSMB
->ParameterCount
= cpu_to_le16(params
);
2012 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
2013 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
2014 pSMB
->DataOffset
= cpu_to_le16(offset
);
2015 /* construct random name ".cifs_tmp<inodenum><mid>" */
2016 rename_info
->overwrite
= cpu_to_le32(1);
2017 rename_info
->root_fid
= 0;
2018 /* unicode only call */
2019 if (target_name
== NULL
) {
2020 sprintf(dummy_string
, "cifs%x", pSMB
->hdr
.Mid
);
2021 len_of_str
= cifsConvertToUCS((__le16
*)rename_info
->target_name
,
2022 dummy_string
, 24, nls_codepage
, remap
);
2024 len_of_str
= cifsConvertToUCS((__le16
*)rename_info
->target_name
,
2025 target_name
, PATH_MAX
, nls_codepage
,
2028 rename_info
->target_name_len
= cpu_to_le32(2 * len_of_str
);
2029 count
= 12 /* sizeof(struct set_file_rename) */ + (2 * len_of_str
);
2030 byte_count
+= count
;
2031 pSMB
->DataCount
= cpu_to_le16(count
);
2032 pSMB
->TotalDataCount
= pSMB
->DataCount
;
2034 pSMB
->InformationLevel
=
2035 cpu_to_le16(SMB_SET_FILE_RENAME_INFORMATION
);
2036 pSMB
->Reserved4
= 0;
2037 pSMB
->hdr
.smb_buf_length
+= byte_count
;
2038 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
2039 rc
= SendReceive(xid
, pTcon
->ses
, (struct smb_hdr
*) pSMB
,
2040 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
2041 cifs_stats_inc(&pTcon
->num_t2renames
);
2043 cFYI(1, "Send error in Rename (by file handle) = %d", rc
);
2045 cifs_buf_release(pSMB
);
2047 /* Note: On -EAGAIN error only caller can retry on handle based calls
2048 since file handle passed in no longer valid */
2054 CIFSSMBCopy(const int xid
, struct cifsTconInfo
*tcon
, const char *fromName
,
2055 const __u16 target_tid
, const char *toName
, const int flags
,
2056 const struct nls_table
*nls_codepage
, int remap
)
2059 COPY_REQ
*pSMB
= NULL
;
2060 COPY_RSP
*pSMBr
= NULL
;
2062 int name_len
, name_len2
;
2065 cFYI(1, "In CIFSSMBCopy");
2067 rc
= smb_init(SMB_COM_COPY
, 1, tcon
, (void **) &pSMB
,
2072 pSMB
->BufferFormat
= 0x04;
2073 pSMB
->Tid2
= target_tid
;
2075 pSMB
->Flags
= cpu_to_le16(flags
& COPY_TREE
);
2077 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
2078 name_len
= cifsConvertToUCS((__le16
*) pSMB
->OldFileName
,
2079 fromName
, PATH_MAX
, nls_codepage
,
2081 name_len
++; /* trailing null */
2083 pSMB
->OldFileName
[name_len
] = 0x04; /* pad */
2084 /* protocol requires ASCII signature byte on Unicode string */
2085 pSMB
->OldFileName
[name_len
+ 1] = 0x00;
2087 cifsConvertToUCS((__le16
*)&pSMB
->OldFileName
[name_len
+ 2],
2088 toName
, PATH_MAX
, nls_codepage
, remap
);
2089 name_len2
+= 1 /* trailing null */ + 1 /* Signature word */ ;
2090 name_len2
*= 2; /* convert to bytes */
2091 } else { /* BB improve the check for buffer overruns BB */
2092 name_len
= strnlen(fromName
, PATH_MAX
);
2093 name_len
++; /* trailing null */
2094 strncpy(pSMB
->OldFileName
, fromName
, name_len
);
2095 name_len2
= strnlen(toName
, PATH_MAX
);
2096 name_len2
++; /* trailing null */
2097 pSMB
->OldFileName
[name_len
] = 0x04; /* 2nd buffer format */
2098 strncpy(&pSMB
->OldFileName
[name_len
+ 1], toName
, name_len2
);
2099 name_len2
++; /* trailing null */
2100 name_len2
++; /* signature byte */
2103 count
= 1 /* 1st signature byte */ + name_len
+ name_len2
;
2104 pSMB
->hdr
.smb_buf_length
+= count
;
2105 pSMB
->ByteCount
= cpu_to_le16(count
);
2107 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
2108 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
2110 cFYI(1, "Send error in copy = %d with %d files copied",
2111 rc
, le16_to_cpu(pSMBr
->CopyCount
));
2113 cifs_buf_release(pSMB
);
2122 CIFSUnixCreateSymLink(const int xid
, struct cifsTconInfo
*tcon
,
2123 const char *fromName
, const char *toName
,
2124 const struct nls_table
*nls_codepage
)
2126 TRANSACTION2_SPI_REQ
*pSMB
= NULL
;
2127 TRANSACTION2_SPI_RSP
*pSMBr
= NULL
;
2130 int name_len_target
;
2132 int bytes_returned
= 0;
2133 __u16 params
, param_offset
, offset
, byte_count
;
2135 cFYI(1, "In Symlink Unix style");
2137 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
2142 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
2144 cifs_strtoUCS((__le16
*) pSMB
->FileName
, fromName
, PATH_MAX
2145 /* find define for this maxpathcomponent */
2147 name_len
++; /* trailing null */
2150 } else { /* BB improve the check for buffer overruns BB */
2151 name_len
= strnlen(fromName
, PATH_MAX
);
2152 name_len
++; /* trailing null */
2153 strncpy(pSMB
->FileName
, fromName
, name_len
);
2155 params
= 6 + name_len
;
2156 pSMB
->MaxSetupCount
= 0;
2160 pSMB
->Reserved2
= 0;
2161 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
2162 InformationLevel
) - 4;
2163 offset
= param_offset
+ params
;
2165 data_offset
= (char *) (&pSMB
->hdr
.Protocol
) + offset
;
2166 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
2168 cifs_strtoUCS((__le16
*) data_offset
, toName
, PATH_MAX
2169 /* find define for this maxpathcomponent */
2171 name_len_target
++; /* trailing null */
2172 name_len_target
*= 2;
2173 } else { /* BB improve the check for buffer overruns BB */
2174 name_len_target
= strnlen(toName
, PATH_MAX
);
2175 name_len_target
++; /* trailing null */
2176 strncpy(data_offset
, toName
, name_len_target
);
2179 pSMB
->MaxParameterCount
= cpu_to_le16(2);
2180 /* BB find exact max on data count below from sess */
2181 pSMB
->MaxDataCount
= cpu_to_le16(1000);
2182 pSMB
->SetupCount
= 1;
2183 pSMB
->Reserved3
= 0;
2184 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
2185 byte_count
= 3 /* pad */ + params
+ name_len_target
;
2186 pSMB
->DataCount
= cpu_to_le16(name_len_target
);
2187 pSMB
->ParameterCount
= cpu_to_le16(params
);
2188 pSMB
->TotalDataCount
= pSMB
->DataCount
;
2189 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
2190 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
2191 pSMB
->DataOffset
= cpu_to_le16(offset
);
2192 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_UNIX_LINK
);
2193 pSMB
->Reserved4
= 0;
2194 pSMB
->hdr
.smb_buf_length
+= byte_count
;
2195 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
2196 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
2197 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
2198 cifs_stats_inc(&tcon
->num_symlinks
);
2200 cFYI(1, "Send error in SetPathInfo create symlink = %d", rc
);
2202 cifs_buf_release(pSMB
);
2205 goto createSymLinkRetry
;
2211 CIFSUnixCreateHardLink(const int xid
, struct cifsTconInfo
*tcon
,
2212 const char *fromName
, const char *toName
,
2213 const struct nls_table
*nls_codepage
, int remap
)
2215 TRANSACTION2_SPI_REQ
*pSMB
= NULL
;
2216 TRANSACTION2_SPI_RSP
*pSMBr
= NULL
;
2219 int name_len_target
;
2221 int bytes_returned
= 0;
2222 __u16 params
, param_offset
, offset
, byte_count
;
2224 cFYI(1, "In Create Hard link Unix style");
2225 createHardLinkRetry
:
2226 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
2231 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
2232 name_len
= cifsConvertToUCS((__le16
*) pSMB
->FileName
, toName
,
2233 PATH_MAX
, nls_codepage
, remap
);
2234 name_len
++; /* trailing null */
2237 } else { /* BB improve the check for buffer overruns BB */
2238 name_len
= strnlen(toName
, PATH_MAX
);
2239 name_len
++; /* trailing null */
2240 strncpy(pSMB
->FileName
, toName
, name_len
);
2242 params
= 6 + name_len
;
2243 pSMB
->MaxSetupCount
= 0;
2247 pSMB
->Reserved2
= 0;
2248 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
2249 InformationLevel
) - 4;
2250 offset
= param_offset
+ params
;
2252 data_offset
= (char *) (&pSMB
->hdr
.Protocol
) + offset
;
2253 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
2255 cifsConvertToUCS((__le16
*) data_offset
, fromName
, PATH_MAX
,
2256 nls_codepage
, remap
);
2257 name_len_target
++; /* trailing null */
2258 name_len_target
*= 2;
2259 } else { /* BB improve the check for buffer overruns BB */
2260 name_len_target
= strnlen(fromName
, PATH_MAX
);
2261 name_len_target
++; /* trailing null */
2262 strncpy(data_offset
, fromName
, name_len_target
);
2265 pSMB
->MaxParameterCount
= cpu_to_le16(2);
2266 /* BB find exact max on data count below from sess*/
2267 pSMB
->MaxDataCount
= cpu_to_le16(1000);
2268 pSMB
->SetupCount
= 1;
2269 pSMB
->Reserved3
= 0;
2270 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
2271 byte_count
= 3 /* pad */ + params
+ name_len_target
;
2272 pSMB
->ParameterCount
= cpu_to_le16(params
);
2273 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
2274 pSMB
->DataCount
= cpu_to_le16(name_len_target
);
2275 pSMB
->TotalDataCount
= pSMB
->DataCount
;
2276 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
2277 pSMB
->DataOffset
= cpu_to_le16(offset
);
2278 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_UNIX_HLINK
);
2279 pSMB
->Reserved4
= 0;
2280 pSMB
->hdr
.smb_buf_length
+= byte_count
;
2281 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
2282 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
2283 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
2284 cifs_stats_inc(&tcon
->num_hardlinks
);
2286 cFYI(1, "Send error in SetPathInfo (hard link) = %d", rc
);
2288 cifs_buf_release(pSMB
);
2290 goto createHardLinkRetry
;
2296 CIFSCreateHardLink(const int xid
, struct cifsTconInfo
*tcon
,
2297 const char *fromName
, const char *toName
,
2298 const struct nls_table
*nls_codepage
, int remap
)
2301 NT_RENAME_REQ
*pSMB
= NULL
;
2302 RENAME_RSP
*pSMBr
= NULL
;
2304 int name_len
, name_len2
;
2307 cFYI(1, "In CIFSCreateHardLink");
2308 winCreateHardLinkRetry
:
2310 rc
= smb_init(SMB_COM_NT_RENAME
, 4, tcon
, (void **) &pSMB
,
2315 pSMB
->SearchAttributes
=
2316 cpu_to_le16(ATTR_READONLY
| ATTR_HIDDEN
| ATTR_SYSTEM
|
2318 pSMB
->Flags
= cpu_to_le16(CREATE_HARD_LINK
);
2319 pSMB
->ClusterCount
= 0;
2321 pSMB
->BufferFormat
= 0x04;
2323 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
2325 cifsConvertToUCS((__le16
*) pSMB
->OldFileName
, fromName
,
2326 PATH_MAX
, nls_codepage
, remap
);
2327 name_len
++; /* trailing null */
2330 /* protocol specifies ASCII buffer format (0x04) for unicode */
2331 pSMB
->OldFileName
[name_len
] = 0x04;
2332 pSMB
->OldFileName
[name_len
+ 1] = 0x00; /* pad */
2334 cifsConvertToUCS((__le16
*)&pSMB
->OldFileName
[name_len
+ 2],
2335 toName
, PATH_MAX
, nls_codepage
, remap
);
2336 name_len2
+= 1 /* trailing null */ + 1 /* Signature word */ ;
2337 name_len2
*= 2; /* convert to bytes */
2338 } else { /* BB improve the check for buffer overruns BB */
2339 name_len
= strnlen(fromName
, PATH_MAX
);
2340 name_len
++; /* trailing null */
2341 strncpy(pSMB
->OldFileName
, fromName
, name_len
);
2342 name_len2
= strnlen(toName
, PATH_MAX
);
2343 name_len2
++; /* trailing null */
2344 pSMB
->OldFileName
[name_len
] = 0x04; /* 2nd buffer format */
2345 strncpy(&pSMB
->OldFileName
[name_len
+ 1], toName
, name_len2
);
2346 name_len2
++; /* trailing null */
2347 name_len2
++; /* signature byte */
2350 count
= 1 /* string type byte */ + name_len
+ name_len2
;
2351 pSMB
->hdr
.smb_buf_length
+= count
;
2352 pSMB
->ByteCount
= cpu_to_le16(count
);
2354 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
2355 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
2356 cifs_stats_inc(&tcon
->num_hardlinks
);
2358 cFYI(1, "Send error in hard link (NT rename) = %d", rc
);
2360 cifs_buf_release(pSMB
);
2362 goto winCreateHardLinkRetry
;
2368 CIFSSMBUnixQuerySymLink(const int xid
, struct cifsTconInfo
*tcon
,
2369 const unsigned char *searchName
, char **symlinkinfo
,
2370 const struct nls_table
*nls_codepage
)
2372 /* SMB_QUERY_FILE_UNIX_LINK */
2373 TRANSACTION2_QPI_REQ
*pSMB
= NULL
;
2374 TRANSACTION2_QPI_RSP
*pSMBr
= NULL
;
2378 __u16 params
, byte_count
;
2381 cFYI(1, "In QPathSymLinkInfo (Unix) for path %s", searchName
);
2384 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
2389 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
2391 cifs_strtoUCS((__le16
*) pSMB
->FileName
, searchName
,
2392 PATH_MAX
, nls_codepage
);
2393 name_len
++; /* trailing null */
2395 } else { /* BB improve the check for buffer overruns BB */
2396 name_len
= strnlen(searchName
, PATH_MAX
);
2397 name_len
++; /* trailing null */
2398 strncpy(pSMB
->FileName
, searchName
, name_len
);
2401 params
= 2 /* level */ + 4 /* rsrvd */ + name_len
/* incl null */ ;
2402 pSMB
->TotalDataCount
= 0;
2403 pSMB
->MaxParameterCount
= cpu_to_le16(2);
2404 pSMB
->MaxDataCount
= cpu_to_le16(CIFSMaxBufSize
);
2405 pSMB
->MaxSetupCount
= 0;
2409 pSMB
->Reserved2
= 0;
2410 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
2411 struct smb_com_transaction2_qpi_req
, InformationLevel
) - 4);
2412 pSMB
->DataCount
= 0;
2413 pSMB
->DataOffset
= 0;
2414 pSMB
->SetupCount
= 1;
2415 pSMB
->Reserved3
= 0;
2416 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION
);
2417 byte_count
= params
+ 1 /* pad */ ;
2418 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
2419 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
2420 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FILE_UNIX_LINK
);
2421 pSMB
->Reserved4
= 0;
2422 pSMB
->hdr
.smb_buf_length
+= byte_count
;
2423 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
2425 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
2426 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
2428 cFYI(1, "Send error in QuerySymLinkInfo = %d", rc
);
2430 /* decode response */
2432 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
2433 /* BB also check enough total bytes returned */
2434 if (rc
|| (pSMBr
->ByteCount
< 2))
2438 u16 count
= le16_to_cpu(pSMBr
->t2
.DataCount
);
2440 data_start
= ((char *) &pSMBr
->hdr
.Protocol
) +
2441 le16_to_cpu(pSMBr
->t2
.DataOffset
);
2443 if (pSMBr
->hdr
.Flags2
& SMBFLG2_UNICODE
)
2448 /* BB FIXME investigate remapping reserved chars here */
2449 *symlinkinfo
= cifs_strndup_from_ucs(data_start
, count
,
2450 is_unicode
, nls_codepage
);
2455 cifs_buf_release(pSMB
);
2457 goto querySymLinkRetry
;
2461 #ifdef CONFIG_CIFS_EXPERIMENTAL
2462 /* Initialize NT TRANSACT SMB into small smb request buffer.
2463 This assumes that all NT TRANSACTS that we init here have
2464 total parm and data under about 400 bytes (to fit in small cifs
2465 buffer size), which is the case so far, it easily fits. NB:
2466 Setup words themselves and ByteCount
2467 MaxSetupCount (size of returned setup area) and
2468 MaxParameterCount (returned parms size) must be set by caller */
2470 smb_init_nttransact(const __u16 sub_command
, const int setup_count
,
2471 const int parm_len
, struct cifsTconInfo
*tcon
,
2476 struct smb_com_ntransact_req
*pSMB
;
2478 rc
= small_smb_init(SMB_COM_NT_TRANSACT
, 19 + setup_count
, tcon
,
2482 *ret_buf
= (void *)pSMB
;
2484 pSMB
->TotalParameterCount
= cpu_to_le32(parm_len
);
2485 pSMB
->TotalDataCount
= 0;
2486 pSMB
->MaxDataCount
= cpu_to_le32((tcon
->ses
->server
->maxBuf
-
2487 MAX_CIFS_HDR_SIZE
) & 0xFFFFFF00);
2488 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
2489 pSMB
->DataCount
= pSMB
->TotalDataCount
;
2490 temp_offset
= offsetof(struct smb_com_ntransact_req
, Parms
) +
2491 (setup_count
* 2) - 4 /* for rfc1001 length itself */;
2492 pSMB
->ParameterOffset
= cpu_to_le32(temp_offset
);
2493 pSMB
->DataOffset
= cpu_to_le32(temp_offset
+ parm_len
);
2494 pSMB
->SetupCount
= setup_count
; /* no need to le convert byte fields */
2495 pSMB
->SubCommand
= cpu_to_le16(sub_command
);
2500 validate_ntransact(char *buf
, char **ppparm
, char **ppdata
,
2501 __u32
*pparmlen
, __u32
*pdatalen
)
2504 __u32 data_count
, data_offset
, parm_count
, parm_offset
;
2505 struct smb_com_ntransact_rsp
*pSMBr
;
2513 pSMBr
= (struct smb_com_ntransact_rsp
*)buf
;
2515 /* ByteCount was converted from little endian in SendReceive */
2516 end_of_smb
= 2 /* sizeof byte count */ + pSMBr
->ByteCount
+
2517 (char *)&pSMBr
->ByteCount
;
2519 data_offset
= le32_to_cpu(pSMBr
->DataOffset
);
2520 data_count
= le32_to_cpu(pSMBr
->DataCount
);
2521 parm_offset
= le32_to_cpu(pSMBr
->ParameterOffset
);
2522 parm_count
= le32_to_cpu(pSMBr
->ParameterCount
);
2524 *ppparm
= (char *)&pSMBr
->hdr
.Protocol
+ parm_offset
;
2525 *ppdata
= (char *)&pSMBr
->hdr
.Protocol
+ data_offset
;
2527 /* should we also check that parm and data areas do not overlap? */
2528 if (*ppparm
> end_of_smb
) {
2529 cFYI(1, "parms start after end of smb");
2531 } else if (parm_count
+ *ppparm
> end_of_smb
) {
2532 cFYI(1, "parm end after end of smb");
2534 } else if (*ppdata
> end_of_smb
) {
2535 cFYI(1, "data starts after end of smb");
2537 } else if (data_count
+ *ppdata
> end_of_smb
) {
2538 cFYI(1, "data %p + count %d (%p) past smb end %p start %p",
2539 *ppdata
, data_count
, (data_count
+ *ppdata
),
2542 } else if (parm_count
+ data_count
> pSMBr
->ByteCount
) {
2543 cFYI(1, "parm count and data count larger than SMB");
2546 *pdatalen
= data_count
;
2547 *pparmlen
= parm_count
;
2552 CIFSSMBQueryReparseLinkInfo(const int xid
, struct cifsTconInfo
*tcon
,
2553 const unsigned char *searchName
,
2554 char *symlinkinfo
, const int buflen
, __u16 fid
,
2555 const struct nls_table
*nls_codepage
)
2559 struct smb_com_transaction_ioctl_req
*pSMB
;
2560 struct smb_com_transaction_ioctl_rsp
*pSMBr
;
2562 cFYI(1, "In Windows reparse style QueryLink for path %s", searchName
);
2563 rc
= smb_init(SMB_COM_NT_TRANSACT
, 23, tcon
, (void **) &pSMB
,
2568 pSMB
->TotalParameterCount
= 0 ;
2569 pSMB
->TotalDataCount
= 0;
2570 pSMB
->MaxParameterCount
= cpu_to_le32(2);
2571 /* BB find exact data count max from sess structure BB */
2572 pSMB
->MaxDataCount
= cpu_to_le32((tcon
->ses
->server
->maxBuf
-
2573 MAX_CIFS_HDR_SIZE
) & 0xFFFFFF00);
2574 pSMB
->MaxSetupCount
= 4;
2576 pSMB
->ParameterOffset
= 0;
2577 pSMB
->DataCount
= 0;
2578 pSMB
->DataOffset
= 0;
2579 pSMB
->SetupCount
= 4;
2580 pSMB
->SubCommand
= cpu_to_le16(NT_TRANSACT_IOCTL
);
2581 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
2582 pSMB
->FunctionCode
= cpu_to_le32(FSCTL_GET_REPARSE_POINT
);
2583 pSMB
->IsFsctl
= 1; /* FSCTL */
2584 pSMB
->IsRootFlag
= 0;
2585 pSMB
->Fid
= fid
; /* file handle always le */
2586 pSMB
->ByteCount
= 0;
2588 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
2589 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
2591 cFYI(1, "Send error in QueryReparseLinkInfo = %d", rc
);
2592 } else { /* decode response */
2593 __u32 data_offset
= le32_to_cpu(pSMBr
->DataOffset
);
2594 __u32 data_count
= le32_to_cpu(pSMBr
->DataCount
);
2595 if ((pSMBr
->ByteCount
< 2) || (data_offset
> 512)) {
2596 /* BB also check enough total bytes returned */
2597 rc
= -EIO
; /* bad smb */
2600 if (data_count
&& (data_count
< 2048)) {
2601 char *end_of_smb
= 2 /* sizeof byte count */ +
2602 pSMBr
->ByteCount
+ (char *)&pSMBr
->ByteCount
;
2604 struct reparse_data
*reparse_buf
=
2605 (struct reparse_data
*)
2606 ((char *)&pSMBr
->hdr
.Protocol
2608 if ((char *)reparse_buf
>= end_of_smb
) {
2612 if ((reparse_buf
->LinkNamesBuf
+
2613 reparse_buf
->TargetNameOffset
+
2614 reparse_buf
->TargetNameLen
) > end_of_smb
) {
2615 cFYI(1, "reparse buf beyond SMB");
2620 if (pSMBr
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
2621 cifs_from_ucs2(symlinkinfo
, (__le16
*)
2622 (reparse_buf
->LinkNamesBuf
+
2623 reparse_buf
->TargetNameOffset
),
2625 reparse_buf
->TargetNameLen
,
2627 } else { /* ASCII names */
2628 strncpy(symlinkinfo
,
2629 reparse_buf
->LinkNamesBuf
+
2630 reparse_buf
->TargetNameOffset
,
2631 min_t(const int, buflen
,
2632 reparse_buf
->TargetNameLen
));
2636 cFYI(1, "Invalid return data count on "
2637 "get reparse info ioctl");
2639 symlinkinfo
[buflen
] = 0; /* just in case so the caller
2640 does not go off the end of the buffer */
2641 cFYI(1, "readlink result - %s", symlinkinfo
);
2645 cifs_buf_release(pSMB
);
2647 /* Note: On -EAGAIN error only caller can retry on handle based calls
2648 since file handle passed in no longer valid */
2652 #endif /* CIFS_EXPERIMENTAL */
2654 #ifdef CONFIG_CIFS_POSIX
2656 /*Convert an Access Control Entry from wire format to local POSIX xattr format*/
2657 static void cifs_convert_ace(posix_acl_xattr_entry
*ace
,
2658 struct cifs_posix_ace
*cifs_ace
)
2660 /* u8 cifs fields do not need le conversion */
2661 ace
->e_perm
= cpu_to_le16(cifs_ace
->cifs_e_perm
);
2662 ace
->e_tag
= cpu_to_le16(cifs_ace
->cifs_e_tag
);
2663 ace
->e_id
= cpu_to_le32(le64_to_cpu(cifs_ace
->cifs_uid
));
2664 /* cFYI(1, "perm %d tag %d id %d",ace->e_perm,ace->e_tag,ace->e_id); */
2669 /* Convert ACL from CIFS POSIX wire format to local Linux POSIX ACL xattr */
2670 static int cifs_copy_posix_acl(char *trgt
, char *src
, const int buflen
,
2671 const int acl_type
, const int size_of_data_area
)
2676 struct cifs_posix_ace
*pACE
;
2677 struct cifs_posix_acl
*cifs_acl
= (struct cifs_posix_acl
*)src
;
2678 posix_acl_xattr_header
*local_acl
= (posix_acl_xattr_header
*)trgt
;
2680 if (le16_to_cpu(cifs_acl
->version
) != CIFS_ACL_VERSION
)
2683 if (acl_type
& ACL_TYPE_ACCESS
) {
2684 count
= le16_to_cpu(cifs_acl
->access_entry_count
);
2685 pACE
= &cifs_acl
->ace_array
[0];
2686 size
= sizeof(struct cifs_posix_acl
);
2687 size
+= sizeof(struct cifs_posix_ace
) * count
;
2688 /* check if we would go beyond end of SMB */
2689 if (size_of_data_area
< size
) {
2690 cFYI(1, "bad CIFS POSIX ACL size %d vs. %d",
2691 size_of_data_area
, size
);
2694 } else if (acl_type
& ACL_TYPE_DEFAULT
) {
2695 count
= le16_to_cpu(cifs_acl
->access_entry_count
);
2696 size
= sizeof(struct cifs_posix_acl
);
2697 size
+= sizeof(struct cifs_posix_ace
) * count
;
2698 /* skip past access ACEs to get to default ACEs */
2699 pACE
= &cifs_acl
->ace_array
[count
];
2700 count
= le16_to_cpu(cifs_acl
->default_entry_count
);
2701 size
+= sizeof(struct cifs_posix_ace
) * count
;
2702 /* check if we would go beyond end of SMB */
2703 if (size_of_data_area
< size
)
2710 size
= posix_acl_xattr_size(count
);
2711 if ((buflen
== 0) || (local_acl
== NULL
)) {
2712 /* used to query ACL EA size */
2713 } else if (size
> buflen
) {
2715 } else /* buffer big enough */ {
2716 local_acl
->a_version
= cpu_to_le32(POSIX_ACL_XATTR_VERSION
);
2717 for (i
= 0; i
< count
; i
++) {
2718 cifs_convert_ace(&local_acl
->a_entries
[i
], pACE
);
2725 static __u16
convert_ace_to_cifs_ace(struct cifs_posix_ace
*cifs_ace
,
2726 const posix_acl_xattr_entry
*local_ace
)
2728 __u16 rc
= 0; /* 0 = ACL converted ok */
2730 cifs_ace
->cifs_e_perm
= le16_to_cpu(local_ace
->e_perm
);
2731 cifs_ace
->cifs_e_tag
= le16_to_cpu(local_ace
->e_tag
);
2732 /* BB is there a better way to handle the large uid? */
2733 if (local_ace
->e_id
== cpu_to_le32(-1)) {
2734 /* Probably no need to le convert -1 on any arch but can not hurt */
2735 cifs_ace
->cifs_uid
= cpu_to_le64(-1);
2737 cifs_ace
->cifs_uid
= cpu_to_le64(le32_to_cpu(local_ace
->e_id
));
2738 /*cFYI(1, "perm %d tag %d id %d",ace->e_perm,ace->e_tag,ace->e_id);*/
2742 /* Convert ACL from local Linux POSIX xattr to CIFS POSIX ACL wire format */
2743 static __u16
ACL_to_cifs_posix(char *parm_data
, const char *pACL
,
2744 const int buflen
, const int acl_type
)
2747 struct cifs_posix_acl
*cifs_acl
= (struct cifs_posix_acl
*)parm_data
;
2748 posix_acl_xattr_header
*local_acl
= (posix_acl_xattr_header
*)pACL
;
2752 if ((buflen
== 0) || (pACL
== NULL
) || (cifs_acl
== NULL
))
2755 count
= posix_acl_xattr_count((size_t)buflen
);
2756 cFYI(1, "setting acl with %d entries from buf of length %d and "
2758 count
, buflen
, le32_to_cpu(local_acl
->a_version
));
2759 if (le32_to_cpu(local_acl
->a_version
) != 2) {
2760 cFYI(1, "unknown POSIX ACL version %d",
2761 le32_to_cpu(local_acl
->a_version
));
2764 cifs_acl
->version
= cpu_to_le16(1);
2765 if (acl_type
== ACL_TYPE_ACCESS
)
2766 cifs_acl
->access_entry_count
= cpu_to_le16(count
);
2767 else if (acl_type
== ACL_TYPE_DEFAULT
)
2768 cifs_acl
->default_entry_count
= cpu_to_le16(count
);
2770 cFYI(1, "unknown ACL type %d", acl_type
);
2773 for (i
= 0; i
< count
; i
++) {
2774 rc
= convert_ace_to_cifs_ace(&cifs_acl
->ace_array
[i
],
2775 &local_acl
->a_entries
[i
]);
2777 /* ACE not converted */
2782 rc
= (__u16
)(count
* sizeof(struct cifs_posix_ace
));
2783 rc
+= sizeof(struct cifs_posix_acl
);
2784 /* BB add check to make sure ACL does not overflow SMB */
2790 CIFSSMBGetPosixACL(const int xid
, struct cifsTconInfo
*tcon
,
2791 const unsigned char *searchName
,
2792 char *acl_inf
, const int buflen
, const int acl_type
,
2793 const struct nls_table
*nls_codepage
, int remap
)
2795 /* SMB_QUERY_POSIX_ACL */
2796 TRANSACTION2_QPI_REQ
*pSMB
= NULL
;
2797 TRANSACTION2_QPI_RSP
*pSMBr
= NULL
;
2801 __u16 params
, byte_count
;
2803 cFYI(1, "In GetPosixACL (Unix) for path %s", searchName
);
2806 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
2811 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
2813 cifsConvertToUCS((__le16
*) pSMB
->FileName
, searchName
,
2814 PATH_MAX
, nls_codepage
, remap
);
2815 name_len
++; /* trailing null */
2817 pSMB
->FileName
[name_len
] = 0;
2818 pSMB
->FileName
[name_len
+1] = 0;
2819 } else { /* BB improve the check for buffer overruns BB */
2820 name_len
= strnlen(searchName
, PATH_MAX
);
2821 name_len
++; /* trailing null */
2822 strncpy(pSMB
->FileName
, searchName
, name_len
);
2825 params
= 2 /* level */ + 4 /* rsrvd */ + name_len
/* incl null */ ;
2826 pSMB
->TotalDataCount
= 0;
2827 pSMB
->MaxParameterCount
= cpu_to_le16(2);
2828 /* BB find exact max data count below from sess structure BB */
2829 pSMB
->MaxDataCount
= cpu_to_le16(4000);
2830 pSMB
->MaxSetupCount
= 0;
2834 pSMB
->Reserved2
= 0;
2835 pSMB
->ParameterOffset
= cpu_to_le16(
2836 offsetof(struct smb_com_transaction2_qpi_req
,
2837 InformationLevel
) - 4);
2838 pSMB
->DataCount
= 0;
2839 pSMB
->DataOffset
= 0;
2840 pSMB
->SetupCount
= 1;
2841 pSMB
->Reserved3
= 0;
2842 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION
);
2843 byte_count
= params
+ 1 /* pad */ ;
2844 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
2845 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
2846 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_POSIX_ACL
);
2847 pSMB
->Reserved4
= 0;
2848 pSMB
->hdr
.smb_buf_length
+= byte_count
;
2849 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
2851 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
2852 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
2853 cifs_stats_inc(&tcon
->num_acl_get
);
2855 cFYI(1, "Send error in Query POSIX ACL = %d", rc
);
2857 /* decode response */
2859 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
2860 if (rc
|| (pSMBr
->ByteCount
< 2))
2861 /* BB also check enough total bytes returned */
2862 rc
= -EIO
; /* bad smb */
2864 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
2865 __u16 count
= le16_to_cpu(pSMBr
->t2
.DataCount
);
2866 rc
= cifs_copy_posix_acl(acl_inf
,
2867 (char *)&pSMBr
->hdr
.Protocol
+data_offset
,
2868 buflen
, acl_type
, count
);
2871 cifs_buf_release(pSMB
);
2878 CIFSSMBSetPosixACL(const int xid
, struct cifsTconInfo
*tcon
,
2879 const unsigned char *fileName
,
2880 const char *local_acl
, const int buflen
,
2882 const struct nls_table
*nls_codepage
, int remap
)
2884 struct smb_com_transaction2_spi_req
*pSMB
= NULL
;
2885 struct smb_com_transaction2_spi_rsp
*pSMBr
= NULL
;
2889 int bytes_returned
= 0;
2890 __u16 params
, byte_count
, data_count
, param_offset
, offset
;
2892 cFYI(1, "In SetPosixACL (Unix) for path %s", fileName
);
2894 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
2898 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
2900 cifsConvertToUCS((__le16
*) pSMB
->FileName
, fileName
,
2901 PATH_MAX
, nls_codepage
, remap
);
2902 name_len
++; /* trailing null */
2904 } else { /* BB improve the check for buffer overruns BB */
2905 name_len
= strnlen(fileName
, PATH_MAX
);
2906 name_len
++; /* trailing null */
2907 strncpy(pSMB
->FileName
, fileName
, name_len
);
2909 params
= 6 + name_len
;
2910 pSMB
->MaxParameterCount
= cpu_to_le16(2);
2911 /* BB find max SMB size from sess */
2912 pSMB
->MaxDataCount
= cpu_to_le16(1000);
2913 pSMB
->MaxSetupCount
= 0;
2917 pSMB
->Reserved2
= 0;
2918 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
2919 InformationLevel
) - 4;
2920 offset
= param_offset
+ params
;
2921 parm_data
= ((char *) &pSMB
->hdr
.Protocol
) + offset
;
2922 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
2924 /* convert to on the wire format for POSIX ACL */
2925 data_count
= ACL_to_cifs_posix(parm_data
, local_acl
, buflen
, acl_type
);
2927 if (data_count
== 0) {
2929 goto setACLerrorExit
;
2931 pSMB
->DataOffset
= cpu_to_le16(offset
);
2932 pSMB
->SetupCount
= 1;
2933 pSMB
->Reserved3
= 0;
2934 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
2935 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_POSIX_ACL
);
2936 byte_count
= 3 /* pad */ + params
+ data_count
;
2937 pSMB
->DataCount
= cpu_to_le16(data_count
);
2938 pSMB
->TotalDataCount
= pSMB
->DataCount
;
2939 pSMB
->ParameterCount
= cpu_to_le16(params
);
2940 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
2941 pSMB
->Reserved4
= 0;
2942 pSMB
->hdr
.smb_buf_length
+= byte_count
;
2943 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
2944 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
2945 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
2947 cFYI(1, "Set POSIX ACL returned %d", rc
);
2950 cifs_buf_release(pSMB
);
2956 /* BB fix tabs in this function FIXME BB */
2958 CIFSGetExtAttr(const int xid
, struct cifsTconInfo
*tcon
,
2959 const int netfid
, __u64
*pExtAttrBits
, __u64
*pMask
)
2962 struct smb_t2_qfi_req
*pSMB
= NULL
;
2963 struct smb_t2_qfi_rsp
*pSMBr
= NULL
;
2965 __u16 params
, byte_count
;
2967 cFYI(1, "In GetExtAttr");
2972 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
2977 params
= 2 /* level */ + 2 /* fid */;
2978 pSMB
->t2
.TotalDataCount
= 0;
2979 pSMB
->t2
.MaxParameterCount
= cpu_to_le16(4);
2980 /* BB find exact max data count below from sess structure BB */
2981 pSMB
->t2
.MaxDataCount
= cpu_to_le16(4000);
2982 pSMB
->t2
.MaxSetupCount
= 0;
2983 pSMB
->t2
.Reserved
= 0;
2985 pSMB
->t2
.Timeout
= 0;
2986 pSMB
->t2
.Reserved2
= 0;
2987 pSMB
->t2
.ParameterOffset
= cpu_to_le16(offsetof(struct smb_t2_qfi_req
,
2989 pSMB
->t2
.DataCount
= 0;
2990 pSMB
->t2
.DataOffset
= 0;
2991 pSMB
->t2
.SetupCount
= 1;
2992 pSMB
->t2
.Reserved3
= 0;
2993 pSMB
->t2
.SubCommand
= cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION
);
2994 byte_count
= params
+ 1 /* pad */ ;
2995 pSMB
->t2
.TotalParameterCount
= cpu_to_le16(params
);
2996 pSMB
->t2
.ParameterCount
= pSMB
->t2
.TotalParameterCount
;
2997 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_ATTR_FLAGS
);
3000 pSMB
->hdr
.smb_buf_length
+= byte_count
;
3001 pSMB
->t2
.ByteCount
= cpu_to_le16(byte_count
);
3003 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3004 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3006 cFYI(1, "error %d in GetExtAttr", rc
);
3008 /* decode response */
3009 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
3010 if (rc
|| (pSMBr
->ByteCount
< 2))
3011 /* BB also check enough total bytes returned */
3012 /* If rc should we check for EOPNOSUPP and
3013 disable the srvino flag? or in caller? */
3014 rc
= -EIO
; /* bad smb */
3016 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
3017 __u16 count
= le16_to_cpu(pSMBr
->t2
.DataCount
);
3018 struct file_chattr_info
*pfinfo
;
3019 /* BB Do we need a cast or hash here ? */
3021 cFYI(1, "Illegal size ret in GetExtAttr");
3025 pfinfo
= (struct file_chattr_info
*)
3026 (data_offset
+ (char *) &pSMBr
->hdr
.Protocol
);
3027 *pExtAttrBits
= le64_to_cpu(pfinfo
->mode
);
3028 *pMask
= le64_to_cpu(pfinfo
->mask
);
3032 cifs_buf_release(pSMB
);
3034 goto GetExtAttrRetry
;
3038 #endif /* CONFIG_POSIX */
3040 #ifdef CONFIG_CIFS_EXPERIMENTAL
3041 /* Get Security Descriptor (by handle) from remote server for a file or dir */
3043 CIFSSMBGetCIFSACL(const int xid
, struct cifsTconInfo
*tcon
, __u16 fid
,
3044 struct cifs_ntsd
**acl_inf
, __u32
*pbuflen
)
3048 QUERY_SEC_DESC_REQ
*pSMB
;
3051 cFYI(1, "GetCifsACL");
3056 rc
= smb_init_nttransact(NT_TRANSACT_QUERY_SECURITY_DESC
, 0,
3057 8 /* parm len */, tcon
, (void **) &pSMB
);
3061 pSMB
->MaxParameterCount
= cpu_to_le32(4);
3062 /* BB TEST with big acls that might need to be e.g. larger than 16K */
3063 pSMB
->MaxSetupCount
= 0;
3064 pSMB
->Fid
= fid
; /* file handle always le */
3065 pSMB
->AclFlags
= cpu_to_le32(CIFS_ACL_OWNER
| CIFS_ACL_GROUP
|
3067 pSMB
->ByteCount
= cpu_to_le16(11); /* 3 bytes pad + 8 bytes parm */
3068 pSMB
->hdr
.smb_buf_length
+= 11;
3069 iov
[0].iov_base
= (char *)pSMB
;
3070 iov
[0].iov_len
= pSMB
->hdr
.smb_buf_length
+ 4;
3072 rc
= SendReceive2(xid
, tcon
->ses
, iov
, 1 /* num iovec */, &buf_type
,
3074 cifs_stats_inc(&tcon
->num_acl_get
);
3076 cFYI(1, "Send error in QuerySecDesc = %d", rc
);
3077 } else { /* decode response */
3081 struct smb_com_ntransact_rsp
*pSMBr
;
3084 /* validate_nttransact */
3085 rc
= validate_ntransact(iov
[0].iov_base
, (char **)&parm
,
3086 &pdata
, &parm_len
, pbuflen
);
3089 pSMBr
= (struct smb_com_ntransact_rsp
*)iov
[0].iov_base
;
3091 cFYI(1, "smb %p parm %p data %p", pSMBr
, parm
, *acl_inf
);
3093 if (le32_to_cpu(pSMBr
->ParameterCount
) != 4) {
3094 rc
= -EIO
; /* bad smb */
3099 /* BB check that data area is minimum length and as big as acl_len */
3101 acl_len
= le32_to_cpu(*parm
);
3102 if (acl_len
!= *pbuflen
) {
3103 cERROR(1, "acl length %d does not match %d",
3105 if (*pbuflen
> acl_len
)
3109 /* check if buffer is big enough for the acl
3110 header followed by the smallest SID */
3111 if ((*pbuflen
< sizeof(struct cifs_ntsd
) + 8) ||
3112 (*pbuflen
>= 64 * 1024)) {
3113 cERROR(1, "bad acl length %d", *pbuflen
);
3117 *acl_inf
= kmalloc(*pbuflen
, GFP_KERNEL
);
3118 if (*acl_inf
== NULL
) {
3122 memcpy(*acl_inf
, pdata
, *pbuflen
);
3126 if (buf_type
== CIFS_SMALL_BUFFER
)
3127 cifs_small_buf_release(iov
[0].iov_base
);
3128 else if (buf_type
== CIFS_LARGE_BUFFER
)
3129 cifs_buf_release(iov
[0].iov_base
);
3130 /* cifs_small_buf_release(pSMB); */ /* Freed earlier now in SendReceive2 */
3135 CIFSSMBSetCIFSACL(const int xid
, struct cifsTconInfo
*tcon
, __u16 fid
,
3136 struct cifs_ntsd
*pntsd
, __u32 acllen
)
3138 __u16 byte_count
, param_count
, data_count
, param_offset
, data_offset
;
3140 int bytes_returned
= 0;
3141 SET_SEC_DESC_REQ
*pSMB
= NULL
;
3142 NTRANSACT_RSP
*pSMBr
= NULL
;
3145 rc
= smb_init(SMB_COM_NT_TRANSACT
, 19, tcon
, (void **) &pSMB
,
3150 pSMB
->MaxSetupCount
= 0;
3154 param_offset
= offsetof(struct smb_com_transaction_ssec_req
, Fid
) - 4;
3155 data_count
= acllen
;
3156 data_offset
= param_offset
+ param_count
;
3157 byte_count
= 3 /* pad */ + param_count
;
3159 pSMB
->DataCount
= cpu_to_le32(data_count
);
3160 pSMB
->TotalDataCount
= pSMB
->DataCount
;
3161 pSMB
->MaxParameterCount
= cpu_to_le32(4);
3162 pSMB
->MaxDataCount
= cpu_to_le32(16384);
3163 pSMB
->ParameterCount
= cpu_to_le32(param_count
);
3164 pSMB
->ParameterOffset
= cpu_to_le32(param_offset
);
3165 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
3166 pSMB
->DataOffset
= cpu_to_le32(data_offset
);
3167 pSMB
->SetupCount
= 0;
3168 pSMB
->SubCommand
= cpu_to_le16(NT_TRANSACT_SET_SECURITY_DESC
);
3169 pSMB
->ByteCount
= cpu_to_le16(byte_count
+data_count
);
3171 pSMB
->Fid
= fid
; /* file handle always le */
3172 pSMB
->Reserved2
= 0;
3173 pSMB
->AclFlags
= cpu_to_le32(CIFS_ACL_DACL
);
3175 if (pntsd
&& acllen
) {
3176 memcpy((char *) &pSMBr
->hdr
.Protocol
+ data_offset
,
3179 pSMB
->hdr
.smb_buf_length
+= (byte_count
+ data_count
);
3182 pSMB
->hdr
.smb_buf_length
+= byte_count
;
3184 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3185 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3187 cFYI(1, "SetCIFSACL bytes_returned: %d, rc: %d", bytes_returned
, rc
);
3189 cFYI(1, "Set CIFS ACL returned %d", rc
);
3190 cifs_buf_release(pSMB
);
3193 goto setCifsAclRetry
;
3198 #endif /* CONFIG_CIFS_EXPERIMENTAL */
3200 /* Legacy Query Path Information call for lookup to old servers such
3202 int SMBQueryInformation(const int xid
, struct cifsTconInfo
*tcon
,
3203 const unsigned char *searchName
,
3204 FILE_ALL_INFO
*pFinfo
,
3205 const struct nls_table
*nls_codepage
, int remap
)
3207 QUERY_INFORMATION_REQ
*pSMB
;
3208 QUERY_INFORMATION_RSP
*pSMBr
;
3213 cFYI(1, "In SMBQPath path %s", searchName
);
3215 rc
= smb_init(SMB_COM_QUERY_INFORMATION
, 0, tcon
, (void **) &pSMB
,
3220 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
3222 cifsConvertToUCS((__le16
*) pSMB
->FileName
, searchName
,
3223 PATH_MAX
, nls_codepage
, remap
);
3224 name_len
++; /* trailing null */
3227 name_len
= strnlen(searchName
, PATH_MAX
);
3228 name_len
++; /* trailing null */
3229 strncpy(pSMB
->FileName
, searchName
, name_len
);
3231 pSMB
->BufferFormat
= 0x04;
3232 name_len
++; /* account for buffer type byte */
3233 pSMB
->hdr
.smb_buf_length
+= (__u16
) name_len
;
3234 pSMB
->ByteCount
= cpu_to_le16(name_len
);
3236 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3237 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3239 cFYI(1, "Send error in QueryInfo = %d", rc
);
3240 } else if (pFinfo
) {
3242 __u32 time
= le32_to_cpu(pSMBr
->last_write_time
);
3244 /* decode response */
3245 /* BB FIXME - add time zone adjustment BB */
3246 memset(pFinfo
, 0, sizeof(FILE_ALL_INFO
));
3249 /* decode time fields */
3250 pFinfo
->ChangeTime
= cpu_to_le64(cifs_UnixTimeToNT(ts
));
3251 pFinfo
->LastWriteTime
= pFinfo
->ChangeTime
;
3252 pFinfo
->LastAccessTime
= 0;
3253 pFinfo
->AllocationSize
=
3254 cpu_to_le64(le32_to_cpu(pSMBr
->size
));
3255 pFinfo
->EndOfFile
= pFinfo
->AllocationSize
;
3256 pFinfo
->Attributes
=
3257 cpu_to_le32(le16_to_cpu(pSMBr
->attr
));
3259 rc
= -EIO
; /* bad buffer passed in */
3261 cifs_buf_release(pSMB
);
3270 CIFSSMBQFileInfo(const int xid
, struct cifsTconInfo
*tcon
,
3271 u16 netfid
, FILE_ALL_INFO
*pFindData
)
3273 struct smb_t2_qfi_req
*pSMB
= NULL
;
3274 struct smb_t2_qfi_rsp
*pSMBr
= NULL
;
3277 __u16 params
, byte_count
;
3280 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
3285 params
= 2 /* level */ + 2 /* fid */;
3286 pSMB
->t2
.TotalDataCount
= 0;
3287 pSMB
->t2
.MaxParameterCount
= cpu_to_le16(4);
3288 /* BB find exact max data count below from sess structure BB */
3289 pSMB
->t2
.MaxDataCount
= cpu_to_le16(CIFSMaxBufSize
);
3290 pSMB
->t2
.MaxSetupCount
= 0;
3291 pSMB
->t2
.Reserved
= 0;
3293 pSMB
->t2
.Timeout
= 0;
3294 pSMB
->t2
.Reserved2
= 0;
3295 pSMB
->t2
.ParameterOffset
= cpu_to_le16(offsetof(struct smb_t2_qfi_req
,
3297 pSMB
->t2
.DataCount
= 0;
3298 pSMB
->t2
.DataOffset
= 0;
3299 pSMB
->t2
.SetupCount
= 1;
3300 pSMB
->t2
.Reserved3
= 0;
3301 pSMB
->t2
.SubCommand
= cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION
);
3302 byte_count
= params
+ 1 /* pad */ ;
3303 pSMB
->t2
.TotalParameterCount
= cpu_to_le16(params
);
3304 pSMB
->t2
.ParameterCount
= pSMB
->t2
.TotalParameterCount
;
3305 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FILE_ALL_INFO
);
3308 pSMB
->hdr
.smb_buf_length
+= byte_count
;
3310 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3311 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3313 cFYI(1, "Send error in QPathInfo = %d", rc
);
3314 } else { /* decode response */
3315 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
3317 if (rc
) /* BB add auto retry on EOPNOTSUPP? */
3319 else if (pSMBr
->ByteCount
< 40)
3320 rc
= -EIO
; /* bad smb */
3321 else if (pFindData
) {
3322 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
3323 memcpy((char *) pFindData
,
3324 (char *) &pSMBr
->hdr
.Protocol
+
3325 data_offset
, sizeof(FILE_ALL_INFO
));
3329 cifs_buf_release(pSMB
);
3331 goto QFileInfoRetry
;
3337 CIFSSMBQPathInfo(const int xid
, struct cifsTconInfo
*tcon
,
3338 const unsigned char *searchName
,
3339 FILE_ALL_INFO
*pFindData
,
3340 int legacy
/* old style infolevel */,
3341 const struct nls_table
*nls_codepage
, int remap
)
3343 /* level 263 SMB_QUERY_FILE_ALL_INFO */
3344 TRANSACTION2_QPI_REQ
*pSMB
= NULL
;
3345 TRANSACTION2_QPI_RSP
*pSMBr
= NULL
;
3349 __u16 params
, byte_count
;
3351 /* cFYI(1, "In QPathInfo path %s", searchName); */
3353 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
3358 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
3360 cifsConvertToUCS((__le16
*) pSMB
->FileName
, searchName
,
3361 PATH_MAX
, nls_codepage
, remap
);
3362 name_len
++; /* trailing null */
3364 } else { /* BB improve the check for buffer overruns BB */
3365 name_len
= strnlen(searchName
, PATH_MAX
);
3366 name_len
++; /* trailing null */
3367 strncpy(pSMB
->FileName
, searchName
, name_len
);
3370 params
= 2 /* level */ + 4 /* reserved */ + name_len
/* includes NUL */;
3371 pSMB
->TotalDataCount
= 0;
3372 pSMB
->MaxParameterCount
= cpu_to_le16(2);
3373 /* BB find exact max SMB PDU from sess structure BB */
3374 pSMB
->MaxDataCount
= cpu_to_le16(4000);
3375 pSMB
->MaxSetupCount
= 0;
3379 pSMB
->Reserved2
= 0;
3380 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
3381 struct smb_com_transaction2_qpi_req
, InformationLevel
) - 4);
3382 pSMB
->DataCount
= 0;
3383 pSMB
->DataOffset
= 0;
3384 pSMB
->SetupCount
= 1;
3385 pSMB
->Reserved3
= 0;
3386 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION
);
3387 byte_count
= params
+ 1 /* pad */ ;
3388 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
3389 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
3391 pSMB
->InformationLevel
= cpu_to_le16(SMB_INFO_STANDARD
);
3393 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FILE_ALL_INFO
);
3394 pSMB
->Reserved4
= 0;
3395 pSMB
->hdr
.smb_buf_length
+= byte_count
;
3396 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
3398 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3399 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3401 cFYI(1, "Send error in QPathInfo = %d", rc
);
3402 } else { /* decode response */
3403 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
3405 if (rc
) /* BB add auto retry on EOPNOTSUPP? */
3407 else if (!legacy
&& (pSMBr
->ByteCount
< 40))
3408 rc
= -EIO
; /* bad smb */
3409 else if (legacy
&& (pSMBr
->ByteCount
< 24))
3410 rc
= -EIO
; /* 24 or 26 expected but we do not read
3412 else if (pFindData
) {
3414 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
3416 /* On legacy responses we do not read the last field,
3417 EAsize, fortunately since it varies by subdialect and
3418 also note it differs on Set vs. Get, ie two bytes or 4
3419 bytes depending but we don't care here */
3421 size
= sizeof(FILE_INFO_STANDARD
);
3423 size
= sizeof(FILE_ALL_INFO
);
3424 memcpy((char *) pFindData
,
3425 (char *) &pSMBr
->hdr
.Protocol
+
3430 cifs_buf_release(pSMB
);
3432 goto QPathInfoRetry
;
3438 CIFSSMBUnixQFileInfo(const int xid
, struct cifsTconInfo
*tcon
,
3439 u16 netfid
, FILE_UNIX_BASIC_INFO
*pFindData
)
3441 struct smb_t2_qfi_req
*pSMB
= NULL
;
3442 struct smb_t2_qfi_rsp
*pSMBr
= NULL
;
3445 __u16 params
, byte_count
;
3448 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
3453 params
= 2 /* level */ + 2 /* fid */;
3454 pSMB
->t2
.TotalDataCount
= 0;
3455 pSMB
->t2
.MaxParameterCount
= cpu_to_le16(4);
3456 /* BB find exact max data count below from sess structure BB */
3457 pSMB
->t2
.MaxDataCount
= cpu_to_le16(CIFSMaxBufSize
);
3458 pSMB
->t2
.MaxSetupCount
= 0;
3459 pSMB
->t2
.Reserved
= 0;
3461 pSMB
->t2
.Timeout
= 0;
3462 pSMB
->t2
.Reserved2
= 0;
3463 pSMB
->t2
.ParameterOffset
= cpu_to_le16(offsetof(struct smb_t2_qfi_req
,
3465 pSMB
->t2
.DataCount
= 0;
3466 pSMB
->t2
.DataOffset
= 0;
3467 pSMB
->t2
.SetupCount
= 1;
3468 pSMB
->t2
.Reserved3
= 0;
3469 pSMB
->t2
.SubCommand
= cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION
);
3470 byte_count
= params
+ 1 /* pad */ ;
3471 pSMB
->t2
.TotalParameterCount
= cpu_to_le16(params
);
3472 pSMB
->t2
.ParameterCount
= pSMB
->t2
.TotalParameterCount
;
3473 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC
);
3476 pSMB
->hdr
.smb_buf_length
+= byte_count
;
3478 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3479 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3481 cFYI(1, "Send error in QPathInfo = %d", rc
);
3482 } else { /* decode response */
3483 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
3485 if (rc
|| (pSMBr
->ByteCount
< sizeof(FILE_UNIX_BASIC_INFO
))) {
3486 cERROR(1, "Malformed FILE_UNIX_BASIC_INFO response.\n"
3487 "Unix Extensions can be disabled on mount "
3488 "by specifying the nosfu mount option.");
3489 rc
= -EIO
; /* bad smb */
3491 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
3492 memcpy((char *) pFindData
,
3493 (char *) &pSMBr
->hdr
.Protocol
+
3495 sizeof(FILE_UNIX_BASIC_INFO
));
3499 cifs_buf_release(pSMB
);
3501 goto UnixQFileInfoRetry
;
3507 CIFSSMBUnixQPathInfo(const int xid
, struct cifsTconInfo
*tcon
,
3508 const unsigned char *searchName
,
3509 FILE_UNIX_BASIC_INFO
*pFindData
,
3510 const struct nls_table
*nls_codepage
, int remap
)
3512 /* SMB_QUERY_FILE_UNIX_BASIC */
3513 TRANSACTION2_QPI_REQ
*pSMB
= NULL
;
3514 TRANSACTION2_QPI_RSP
*pSMBr
= NULL
;
3516 int bytes_returned
= 0;
3518 __u16 params
, byte_count
;
3520 cFYI(1, "In QPathInfo (Unix) the path %s", searchName
);
3522 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
3527 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
3529 cifsConvertToUCS((__le16
*) pSMB
->FileName
, searchName
,
3530 PATH_MAX
, nls_codepage
, remap
);
3531 name_len
++; /* trailing null */
3533 } else { /* BB improve the check for buffer overruns BB */
3534 name_len
= strnlen(searchName
, PATH_MAX
);
3535 name_len
++; /* trailing null */
3536 strncpy(pSMB
->FileName
, searchName
, name_len
);
3539 params
= 2 /* level */ + 4 /* reserved */ + name_len
/* includes NUL */;
3540 pSMB
->TotalDataCount
= 0;
3541 pSMB
->MaxParameterCount
= cpu_to_le16(2);
3542 /* BB find exact max SMB PDU from sess structure BB */
3543 pSMB
->MaxDataCount
= cpu_to_le16(4000);
3544 pSMB
->MaxSetupCount
= 0;
3548 pSMB
->Reserved2
= 0;
3549 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
3550 struct smb_com_transaction2_qpi_req
, InformationLevel
) - 4);
3551 pSMB
->DataCount
= 0;
3552 pSMB
->DataOffset
= 0;
3553 pSMB
->SetupCount
= 1;
3554 pSMB
->Reserved3
= 0;
3555 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION
);
3556 byte_count
= params
+ 1 /* pad */ ;
3557 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
3558 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
3559 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC
);
3560 pSMB
->Reserved4
= 0;
3561 pSMB
->hdr
.smb_buf_length
+= byte_count
;
3562 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
3564 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3565 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3567 cFYI(1, "Send error in QPathInfo = %d", rc
);
3568 } else { /* decode response */
3569 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
3571 if (rc
|| (pSMBr
->ByteCount
< sizeof(FILE_UNIX_BASIC_INFO
))) {
3572 cERROR(1, "Malformed FILE_UNIX_BASIC_INFO response.\n"
3573 "Unix Extensions can be disabled on mount "
3574 "by specifying the nosfu mount option.");
3575 rc
= -EIO
; /* bad smb */
3577 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
3578 memcpy((char *) pFindData
,
3579 (char *) &pSMBr
->hdr
.Protocol
+
3581 sizeof(FILE_UNIX_BASIC_INFO
));
3584 cifs_buf_release(pSMB
);
3586 goto UnixQPathInfoRetry
;
3591 /* xid, tcon, searchName and codepage are input parms, rest are returned */
3593 CIFSFindFirst(const int xid
, struct cifsTconInfo
*tcon
,
3594 const char *searchName
,
3595 const struct nls_table
*nls_codepage
,
3597 struct cifs_search_info
*psrch_inf
, int remap
, const char dirsep
)
3599 /* level 257 SMB_ */
3600 TRANSACTION2_FFIRST_REQ
*pSMB
= NULL
;
3601 TRANSACTION2_FFIRST_RSP
*pSMBr
= NULL
;
3602 T2_FFIRST_RSP_PARMS
*parms
;
3604 int bytes_returned
= 0;
3606 __u16 params
, byte_count
;
3608 cFYI(1, "In FindFirst for %s", searchName
);
3611 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
3616 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
3618 cifsConvertToUCS((__le16
*) pSMB
->FileName
, searchName
,
3619 PATH_MAX
, nls_codepage
, remap
);
3620 /* We can not add the asterik earlier in case
3621 it got remapped to 0xF03A as if it were part of the
3622 directory name instead of a wildcard */
3624 pSMB
->FileName
[name_len
] = dirsep
;
3625 pSMB
->FileName
[name_len
+1] = 0;
3626 pSMB
->FileName
[name_len
+2] = '*';
3627 pSMB
->FileName
[name_len
+3] = 0;
3628 name_len
+= 4; /* now the trailing null */
3629 pSMB
->FileName
[name_len
] = 0; /* null terminate just in case */
3630 pSMB
->FileName
[name_len
+1] = 0;
3632 } else { /* BB add check for overrun of SMB buf BB */
3633 name_len
= strnlen(searchName
, PATH_MAX
);
3634 /* BB fix here and in unicode clause above ie
3635 if (name_len > buffersize-header)
3636 free buffer exit; BB */
3637 strncpy(pSMB
->FileName
, searchName
, name_len
);
3638 pSMB
->FileName
[name_len
] = dirsep
;
3639 pSMB
->FileName
[name_len
+1] = '*';
3640 pSMB
->FileName
[name_len
+2] = 0;
3644 params
= 12 + name_len
/* includes null */ ;
3645 pSMB
->TotalDataCount
= 0; /* no EAs */
3646 pSMB
->MaxParameterCount
= cpu_to_le16(10);
3647 pSMB
->MaxDataCount
= cpu_to_le16((tcon
->ses
->server
->maxBuf
-
3648 MAX_CIFS_HDR_SIZE
) & 0xFFFFFF00);
3649 pSMB
->MaxSetupCount
= 0;
3653 pSMB
->Reserved2
= 0;
3654 byte_count
= params
+ 1 /* pad */ ;
3655 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
3656 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
3657 pSMB
->ParameterOffset
= cpu_to_le16(
3658 offsetof(struct smb_com_transaction2_ffirst_req
, SearchAttributes
)
3660 pSMB
->DataCount
= 0;
3661 pSMB
->DataOffset
= 0;
3662 pSMB
->SetupCount
= 1; /* one byte, no need to make endian neutral */
3663 pSMB
->Reserved3
= 0;
3664 pSMB
->SubCommand
= cpu_to_le16(TRANS2_FIND_FIRST
);
3665 pSMB
->SearchAttributes
=
3666 cpu_to_le16(ATTR_READONLY
| ATTR_HIDDEN
| ATTR_SYSTEM
|
3668 pSMB
->SearchCount
= cpu_to_le16(CIFSMaxBufSize
/sizeof(FILE_UNIX_INFO
));
3669 pSMB
->SearchFlags
= cpu_to_le16(CIFS_SEARCH_CLOSE_AT_END
|
3670 CIFS_SEARCH_RETURN_RESUME
);
3671 pSMB
->InformationLevel
= cpu_to_le16(psrch_inf
->info_level
);
3673 /* BB what should we set StorageType to? Does it matter? BB */
3674 pSMB
->SearchStorageType
= 0;
3675 pSMB
->hdr
.smb_buf_length
+= byte_count
;
3676 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
3678 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3679 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3680 cifs_stats_inc(&tcon
->num_ffirst
);
3682 if (rc
) {/* BB add logic to retry regular search if Unix search
3683 rejected unexpectedly by server */
3684 /* BB Add code to handle unsupported level rc */
3685 cFYI(1, "Error in FindFirst = %d", rc
);
3687 cifs_buf_release(pSMB
);
3689 /* BB eventually could optimize out free and realloc of buf */
3692 goto findFirstRetry
;
3693 } else { /* decode response */
3694 /* BB remember to free buffer if error BB */
3695 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
3699 if (pSMBr
->hdr
.Flags2
& SMBFLG2_UNICODE
)
3700 psrch_inf
->unicode
= true;
3702 psrch_inf
->unicode
= false;
3704 psrch_inf
->ntwrk_buf_start
= (char *)pSMBr
;
3705 psrch_inf
->smallBuf
= 0;
3706 psrch_inf
->srch_entries_start
=
3707 (char *) &pSMBr
->hdr
.Protocol
+
3708 le16_to_cpu(pSMBr
->t2
.DataOffset
);
3709 parms
= (T2_FFIRST_RSP_PARMS
*)((char *) &pSMBr
->hdr
.Protocol
+
3710 le16_to_cpu(pSMBr
->t2
.ParameterOffset
));
3712 if (parms
->EndofSearch
)
3713 psrch_inf
->endOfSearch
= true;
3715 psrch_inf
->endOfSearch
= false;
3717 psrch_inf
->entries_in_buffer
=
3718 le16_to_cpu(parms
->SearchCount
);
3719 psrch_inf
->index_of_last_entry
= 2 /* skip . and .. */ +
3720 psrch_inf
->entries_in_buffer
;
3721 lnoff
= le16_to_cpu(parms
->LastNameOffset
);
3722 if (tcon
->ses
->server
->maxBuf
- MAX_CIFS_HDR_SIZE
<
3724 cERROR(1, "ignoring corrupt resume name");
3725 psrch_inf
->last_entry
= NULL
;
3729 psrch_inf
->last_entry
= psrch_inf
->srch_entries_start
+
3732 *pnetfid
= parms
->SearchHandle
;
3734 cifs_buf_release(pSMB
);
3741 int CIFSFindNext(const int xid
, struct cifsTconInfo
*tcon
,
3742 __u16 searchHandle
, struct cifs_search_info
*psrch_inf
)
3744 TRANSACTION2_FNEXT_REQ
*pSMB
= NULL
;
3745 TRANSACTION2_FNEXT_RSP
*pSMBr
= NULL
;
3746 T2_FNEXT_RSP_PARMS
*parms
;
3747 char *response_data
;
3749 int bytes_returned
, name_len
;
3750 __u16 params
, byte_count
;
3752 cFYI(1, "In FindNext");
3754 if (psrch_inf
->endOfSearch
)
3757 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
3762 params
= 14; /* includes 2 bytes of null string, converted to LE below*/
3764 pSMB
->TotalDataCount
= 0; /* no EAs */
3765 pSMB
->MaxParameterCount
= cpu_to_le16(8);
3766 pSMB
->MaxDataCount
=
3767 cpu_to_le16((tcon
->ses
->server
->maxBuf
- MAX_CIFS_HDR_SIZE
) &
3769 pSMB
->MaxSetupCount
= 0;
3773 pSMB
->Reserved2
= 0;
3774 pSMB
->ParameterOffset
= cpu_to_le16(
3775 offsetof(struct smb_com_transaction2_fnext_req
,SearchHandle
) - 4);
3776 pSMB
->DataCount
= 0;
3777 pSMB
->DataOffset
= 0;
3778 pSMB
->SetupCount
= 1;
3779 pSMB
->Reserved3
= 0;
3780 pSMB
->SubCommand
= cpu_to_le16(TRANS2_FIND_NEXT
);
3781 pSMB
->SearchHandle
= searchHandle
; /* always kept as le */
3783 cpu_to_le16(CIFSMaxBufSize
/ sizeof(FILE_UNIX_INFO
));
3784 pSMB
->InformationLevel
= cpu_to_le16(psrch_inf
->info_level
);
3785 pSMB
->ResumeKey
= psrch_inf
->resume_key
;
3787 cpu_to_le16(CIFS_SEARCH_CLOSE_AT_END
| CIFS_SEARCH_RETURN_RESUME
);
3789 name_len
= psrch_inf
->resume_name_len
;
3791 if (name_len
< PATH_MAX
) {
3792 memcpy(pSMB
->ResumeFileName
, psrch_inf
->presume_name
, name_len
);
3793 byte_count
+= name_len
;
3794 /* 14 byte parm len above enough for 2 byte null terminator */
3795 pSMB
->ResumeFileName
[name_len
] = 0;
3796 pSMB
->ResumeFileName
[name_len
+1] = 0;
3799 goto FNext2_err_exit
;
3801 byte_count
= params
+ 1 /* pad */ ;
3802 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
3803 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
3804 pSMB
->hdr
.smb_buf_length
+= byte_count
;
3805 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
3807 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3808 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3809 cifs_stats_inc(&tcon
->num_fnext
);
3812 psrch_inf
->endOfSearch
= true;
3813 cifs_buf_release(pSMB
);
3814 rc
= 0; /* search probably was closed at end of search*/
3816 cFYI(1, "FindNext returned = %d", rc
);
3817 } else { /* decode response */
3818 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
3823 /* BB fixme add lock for file (srch_info) struct here */
3824 if (pSMBr
->hdr
.Flags2
& SMBFLG2_UNICODE
)
3825 psrch_inf
->unicode
= true;
3827 psrch_inf
->unicode
= false;
3828 response_data
= (char *) &pSMBr
->hdr
.Protocol
+
3829 le16_to_cpu(pSMBr
->t2
.ParameterOffset
);
3830 parms
= (T2_FNEXT_RSP_PARMS
*)response_data
;
3831 response_data
= (char *)&pSMBr
->hdr
.Protocol
+
3832 le16_to_cpu(pSMBr
->t2
.DataOffset
);
3833 if (psrch_inf
->smallBuf
)
3834 cifs_small_buf_release(
3835 psrch_inf
->ntwrk_buf_start
);
3837 cifs_buf_release(psrch_inf
->ntwrk_buf_start
);
3838 psrch_inf
->srch_entries_start
= response_data
;
3839 psrch_inf
->ntwrk_buf_start
= (char *)pSMB
;
3840 psrch_inf
->smallBuf
= 0;
3841 if (parms
->EndofSearch
)
3842 psrch_inf
->endOfSearch
= true;
3844 psrch_inf
->endOfSearch
= false;
3845 psrch_inf
->entries_in_buffer
=
3846 le16_to_cpu(parms
->SearchCount
);
3847 psrch_inf
->index_of_last_entry
+=
3848 psrch_inf
->entries_in_buffer
;
3849 lnoff
= le16_to_cpu(parms
->LastNameOffset
);
3850 if (tcon
->ses
->server
->maxBuf
- MAX_CIFS_HDR_SIZE
<
3852 cERROR(1, "ignoring corrupt resume name");
3853 psrch_inf
->last_entry
= NULL
;
3856 psrch_inf
->last_entry
=
3857 psrch_inf
->srch_entries_start
+ lnoff
;
3859 /* cFYI(1, "fnxt2 entries in buf %d index_of_last %d",
3860 psrch_inf->entries_in_buffer, psrch_inf->index_of_last_entry); */
3862 /* BB fixme add unlock here */
3867 /* BB On error, should we leave previous search buf (and count and
3868 last entry fields) intact or free the previous one? */
3870 /* Note: On -EAGAIN error only caller can retry on handle based calls
3871 since file handle passed in no longer valid */
3874 cifs_buf_release(pSMB
);
3879 CIFSFindClose(const int xid
, struct cifsTconInfo
*tcon
,
3880 const __u16 searchHandle
)
3883 FINDCLOSE_REQ
*pSMB
= NULL
;
3885 cFYI(1, "In CIFSSMBFindClose");
3886 rc
= small_smb_init(SMB_COM_FIND_CLOSE2
, 1, tcon
, (void **)&pSMB
);
3888 /* no sense returning error if session restarted
3889 as file handle has been closed */
3895 pSMB
->FileID
= searchHandle
;
3896 pSMB
->ByteCount
= 0;
3897 rc
= SendReceiveNoRsp(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
, 0);
3899 cERROR(1, "Send error in FindClose = %d", rc
);
3901 cifs_stats_inc(&tcon
->num_fclose
);
3903 /* Since session is dead, search handle closed on server already */
3911 CIFSGetSrvInodeNumber(const int xid
, struct cifsTconInfo
*tcon
,
3912 const unsigned char *searchName
,
3913 __u64
*inode_number
,
3914 const struct nls_table
*nls_codepage
, int remap
)
3917 TRANSACTION2_QPI_REQ
*pSMB
= NULL
;
3918 TRANSACTION2_QPI_RSP
*pSMBr
= NULL
;
3919 int name_len
, bytes_returned
;
3920 __u16 params
, byte_count
;
3922 cFYI(1, "In GetSrvInodeNum for %s", searchName
);
3926 GetInodeNumberRetry
:
3927 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
3932 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
3934 cifsConvertToUCS((__le16
*) pSMB
->FileName
, searchName
,
3935 PATH_MAX
, nls_codepage
, remap
);
3936 name_len
++; /* trailing null */
3938 } else { /* BB improve the check for buffer overruns BB */
3939 name_len
= strnlen(searchName
, PATH_MAX
);
3940 name_len
++; /* trailing null */
3941 strncpy(pSMB
->FileName
, searchName
, name_len
);
3944 params
= 2 /* level */ + 4 /* rsrvd */ + name_len
/* incl null */ ;
3945 pSMB
->TotalDataCount
= 0;
3946 pSMB
->MaxParameterCount
= cpu_to_le16(2);
3947 /* BB find exact max data count below from sess structure BB */
3948 pSMB
->MaxDataCount
= cpu_to_le16(4000);
3949 pSMB
->MaxSetupCount
= 0;
3953 pSMB
->Reserved2
= 0;
3954 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
3955 struct smb_com_transaction2_qpi_req
, InformationLevel
) - 4);
3956 pSMB
->DataCount
= 0;
3957 pSMB
->DataOffset
= 0;
3958 pSMB
->SetupCount
= 1;
3959 pSMB
->Reserved3
= 0;
3960 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION
);
3961 byte_count
= params
+ 1 /* pad */ ;
3962 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
3963 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
3964 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FILE_INTERNAL_INFO
);
3965 pSMB
->Reserved4
= 0;
3966 pSMB
->hdr
.smb_buf_length
+= byte_count
;
3967 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
3969 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3970 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3972 cFYI(1, "error %d in QueryInternalInfo", rc
);
3974 /* decode response */
3975 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
3976 if (rc
|| (pSMBr
->ByteCount
< 2))
3977 /* BB also check enough total bytes returned */
3978 /* If rc should we check for EOPNOSUPP and
3979 disable the srvino flag? or in caller? */
3980 rc
= -EIO
; /* bad smb */
3982 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
3983 __u16 count
= le16_to_cpu(pSMBr
->t2
.DataCount
);
3984 struct file_internal_info
*pfinfo
;
3985 /* BB Do we need a cast or hash here ? */
3987 cFYI(1, "Illegal size ret in QryIntrnlInf");
3989 goto GetInodeNumOut
;
3991 pfinfo
= (struct file_internal_info
*)
3992 (data_offset
+ (char *) &pSMBr
->hdr
.Protocol
);
3993 *inode_number
= le64_to_cpu(pfinfo
->UniqueId
);
3997 cifs_buf_release(pSMB
);
3999 goto GetInodeNumberRetry
;
4003 /* parses DFS refferal V3 structure
4004 * caller is responsible for freeing target_nodes
4007 * on failure - errno
4010 parse_DFS_referrals(TRANSACTION2_GET_DFS_REFER_RSP
*pSMBr
,
4011 unsigned int *num_of_nodes
,
4012 struct dfs_info3_param
**target_nodes
,
4013 const struct nls_table
*nls_codepage
, int remap
,
4014 const char *searchName
)
4019 struct dfs_referral_level_3
*ref
;
4021 if (pSMBr
->hdr
.Flags2
& SMBFLG2_UNICODE
)
4025 *num_of_nodes
= le16_to_cpu(pSMBr
->NumberOfReferrals
);
4027 if (*num_of_nodes
< 1) {
4028 cERROR(1, "num_referrals: must be at least > 0,"
4029 "but we get num_referrals = %d\n", *num_of_nodes
);
4031 goto parse_DFS_referrals_exit
;
4034 ref
= (struct dfs_referral_level_3
*) &(pSMBr
->referrals
);
4035 if (ref
->VersionNumber
!= cpu_to_le16(3)) {
4036 cERROR(1, "Referrals of V%d version are not supported,"
4037 "should be V3", le16_to_cpu(ref
->VersionNumber
));
4039 goto parse_DFS_referrals_exit
;
4042 /* get the upper boundary of the resp buffer */
4043 data_end
= (char *)(&(pSMBr
->PathConsumed
)) +
4044 le16_to_cpu(pSMBr
->t2
.DataCount
);
4046 cFYI(1, "num_referrals: %d dfs flags: 0x%x ...\n",
4048 le32_to_cpu(pSMBr
->DFSFlags
));
4050 *target_nodes
= kzalloc(sizeof(struct dfs_info3_param
) *
4051 *num_of_nodes
, GFP_KERNEL
);
4052 if (*target_nodes
== NULL
) {
4053 cERROR(1, "Failed to allocate buffer for target_nodes\n");
4055 goto parse_DFS_referrals_exit
;
4058 /* collect necessary data from referrals */
4059 for (i
= 0; i
< *num_of_nodes
; i
++) {
4062 struct dfs_info3_param
*node
= (*target_nodes
)+i
;
4064 node
->flags
= le32_to_cpu(pSMBr
->DFSFlags
);
4066 __le16
*tmp
= kmalloc(strlen(searchName
)*2 + 2,
4070 goto parse_DFS_referrals_exit
;
4072 cifsConvertToUCS((__le16
*) tmp
, searchName
,
4073 PATH_MAX
, nls_codepage
, remap
);
4074 node
->path_consumed
= cifs_ucs2_bytes(tmp
,
4075 le16_to_cpu(pSMBr
->PathConsumed
),
4079 node
->path_consumed
= le16_to_cpu(pSMBr
->PathConsumed
);
4081 node
->server_type
= le16_to_cpu(ref
->ServerType
);
4082 node
->ref_flag
= le16_to_cpu(ref
->ReferralEntryFlags
);
4085 temp
= (char *)ref
+ le16_to_cpu(ref
->DfsPathOffset
);
4086 max_len
= data_end
- temp
;
4087 node
->path_name
= cifs_strndup_from_ucs(temp
, max_len
,
4088 is_unicode
, nls_codepage
);
4089 if (!node
->path_name
) {
4091 goto parse_DFS_referrals_exit
;
4094 /* copy link target UNC */
4095 temp
= (char *)ref
+ le16_to_cpu(ref
->NetworkAddressOffset
);
4096 max_len
= data_end
- temp
;
4097 node
->node_name
= cifs_strndup_from_ucs(temp
, max_len
,
4098 is_unicode
, nls_codepage
);
4099 if (!node
->node_name
)
4103 parse_DFS_referrals_exit
:
4105 free_dfs_info_array(*target_nodes
, *num_of_nodes
);
4106 *target_nodes
= NULL
;
4113 CIFSGetDFSRefer(const int xid
, struct cifsSesInfo
*ses
,
4114 const unsigned char *searchName
,
4115 struct dfs_info3_param
**target_nodes
,
4116 unsigned int *num_of_nodes
,
4117 const struct nls_table
*nls_codepage
, int remap
)
4119 /* TRANS2_GET_DFS_REFERRAL */
4120 TRANSACTION2_GET_DFS_REFER_REQ
*pSMB
= NULL
;
4121 TRANSACTION2_GET_DFS_REFER_RSP
*pSMBr
= NULL
;
4125 __u16 params
, byte_count
;
4127 *target_nodes
= NULL
;
4129 cFYI(1, "In GetDFSRefer the path %s", searchName
);
4133 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, NULL
, (void **) &pSMB
,
4138 /* server pointer checked in called function,
4139 but should never be null here anyway */
4140 pSMB
->hdr
.Mid
= GetNextMid(ses
->server
);
4141 pSMB
->hdr
.Tid
= ses
->ipc_tid
;
4142 pSMB
->hdr
.Uid
= ses
->Suid
;
4143 if (ses
->capabilities
& CAP_STATUS32
)
4144 pSMB
->hdr
.Flags2
|= SMBFLG2_ERR_STATUS
;
4145 if (ses
->capabilities
& CAP_DFS
)
4146 pSMB
->hdr
.Flags2
|= SMBFLG2_DFS
;
4148 if (ses
->capabilities
& CAP_UNICODE
) {
4149 pSMB
->hdr
.Flags2
|= SMBFLG2_UNICODE
;
4151 cifsConvertToUCS((__le16
*) pSMB
->RequestFileName
,
4152 searchName
, PATH_MAX
, nls_codepage
, remap
);
4153 name_len
++; /* trailing null */
4155 } else { /* BB improve the check for buffer overruns BB */
4156 name_len
= strnlen(searchName
, PATH_MAX
);
4157 name_len
++; /* trailing null */
4158 strncpy(pSMB
->RequestFileName
, searchName
, name_len
);
4162 if (ses
->server
->secMode
&
4163 (SECMODE_SIGN_REQUIRED
| SECMODE_SIGN_ENABLED
))
4164 pSMB
->hdr
.Flags2
|= SMBFLG2_SECURITY_SIGNATURE
;
4167 pSMB
->hdr
.Uid
= ses
->Suid
;
4169 params
= 2 /* level */ + name_len
/*includes null */ ;
4170 pSMB
->TotalDataCount
= 0;
4171 pSMB
->DataCount
= 0;
4172 pSMB
->DataOffset
= 0;
4173 pSMB
->MaxParameterCount
= 0;
4174 /* BB find exact max SMB PDU from sess structure BB */
4175 pSMB
->MaxDataCount
= cpu_to_le16(4000);
4176 pSMB
->MaxSetupCount
= 0;
4180 pSMB
->Reserved2
= 0;
4181 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
4182 struct smb_com_transaction2_get_dfs_refer_req
, MaxReferralLevel
) - 4);
4183 pSMB
->SetupCount
= 1;
4184 pSMB
->Reserved3
= 0;
4185 pSMB
->SubCommand
= cpu_to_le16(TRANS2_GET_DFS_REFERRAL
);
4186 byte_count
= params
+ 3 /* pad */ ;
4187 pSMB
->ParameterCount
= cpu_to_le16(params
);
4188 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
4189 pSMB
->MaxReferralLevel
= cpu_to_le16(3);
4190 pSMB
->hdr
.smb_buf_length
+= byte_count
;
4191 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4193 rc
= SendReceive(xid
, ses
, (struct smb_hdr
*) pSMB
,
4194 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4196 cFYI(1, "Send error in GetDFSRefer = %d", rc
);
4199 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
4201 /* BB Also check if enough total bytes returned? */
4202 if (rc
|| (pSMBr
->ByteCount
< 17)) {
4203 rc
= -EIO
; /* bad smb */
4207 cFYI(1, "Decoding GetDFSRefer response BCC: %d Offset %d",
4209 le16_to_cpu(pSMBr
->t2
.DataOffset
));
4211 /* parse returned result into more usable form */
4212 rc
= parse_DFS_referrals(pSMBr
, num_of_nodes
,
4213 target_nodes
, nls_codepage
, remap
,
4217 cifs_buf_release(pSMB
);
4225 /* Query File System Info such as free space to old servers such as Win 9x */
4227 SMBOldQFSInfo(const int xid
, struct cifsTconInfo
*tcon
, struct kstatfs
*FSData
)
4229 /* level 0x01 SMB_QUERY_FILE_SYSTEM_INFO */
4230 TRANSACTION2_QFSI_REQ
*pSMB
= NULL
;
4231 TRANSACTION2_QFSI_RSP
*pSMBr
= NULL
;
4232 FILE_SYSTEM_ALLOC_INFO
*response_data
;
4234 int bytes_returned
= 0;
4235 __u16 params
, byte_count
;
4237 cFYI(1, "OldQFSInfo");
4239 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4244 params
= 2; /* level */
4245 pSMB
->TotalDataCount
= 0;
4246 pSMB
->MaxParameterCount
= cpu_to_le16(2);
4247 pSMB
->MaxDataCount
= cpu_to_le16(1000);
4248 pSMB
->MaxSetupCount
= 0;
4252 pSMB
->Reserved2
= 0;
4253 byte_count
= params
+ 1 /* pad */ ;
4254 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
4255 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
4256 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
4257 struct smb_com_transaction2_qfsi_req
, InformationLevel
) - 4);
4258 pSMB
->DataCount
= 0;
4259 pSMB
->DataOffset
= 0;
4260 pSMB
->SetupCount
= 1;
4261 pSMB
->Reserved3
= 0;
4262 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_FS_INFORMATION
);
4263 pSMB
->InformationLevel
= cpu_to_le16(SMB_INFO_ALLOCATION
);
4264 pSMB
->hdr
.smb_buf_length
+= byte_count
;
4265 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4267 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4268 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4270 cFYI(1, "Send error in QFSInfo = %d", rc
);
4271 } else { /* decode response */
4272 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
4274 if (rc
|| (pSMBr
->ByteCount
< 18))
4275 rc
= -EIO
; /* bad smb */
4277 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
4278 cFYI(1, "qfsinf resp BCC: %d Offset %d",
4279 pSMBr
->ByteCount
, data_offset
);
4281 response_data
= (FILE_SYSTEM_ALLOC_INFO
*)
4282 (((char *) &pSMBr
->hdr
.Protocol
) + data_offset
);
4284 le16_to_cpu(response_data
->BytesPerSector
) *
4285 le32_to_cpu(response_data
->
4286 SectorsPerAllocationUnit
);
4288 le32_to_cpu(response_data
->TotalAllocationUnits
);
4289 FSData
->f_bfree
= FSData
->f_bavail
=
4290 le32_to_cpu(response_data
->FreeAllocationUnits
);
4291 cFYI(1, "Blocks: %lld Free: %lld Block size %ld",
4292 (unsigned long long)FSData
->f_blocks
,
4293 (unsigned long long)FSData
->f_bfree
,
4297 cifs_buf_release(pSMB
);
4300 goto oldQFSInfoRetry
;
4306 CIFSSMBQFSInfo(const int xid
, struct cifsTconInfo
*tcon
, struct kstatfs
*FSData
)
4308 /* level 0x103 SMB_QUERY_FILE_SYSTEM_INFO */
4309 TRANSACTION2_QFSI_REQ
*pSMB
= NULL
;
4310 TRANSACTION2_QFSI_RSP
*pSMBr
= NULL
;
4311 FILE_SYSTEM_INFO
*response_data
;
4313 int bytes_returned
= 0;
4314 __u16 params
, byte_count
;
4316 cFYI(1, "In QFSInfo");
4318 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4323 params
= 2; /* level */
4324 pSMB
->TotalDataCount
= 0;
4325 pSMB
->MaxParameterCount
= cpu_to_le16(2);
4326 pSMB
->MaxDataCount
= cpu_to_le16(1000);
4327 pSMB
->MaxSetupCount
= 0;
4331 pSMB
->Reserved2
= 0;
4332 byte_count
= params
+ 1 /* pad */ ;
4333 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
4334 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
4335 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
4336 struct smb_com_transaction2_qfsi_req
, InformationLevel
) - 4);
4337 pSMB
->DataCount
= 0;
4338 pSMB
->DataOffset
= 0;
4339 pSMB
->SetupCount
= 1;
4340 pSMB
->Reserved3
= 0;
4341 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_FS_INFORMATION
);
4342 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FS_SIZE_INFO
);
4343 pSMB
->hdr
.smb_buf_length
+= byte_count
;
4344 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4346 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4347 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4349 cFYI(1, "Send error in QFSInfo = %d", rc
);
4350 } else { /* decode response */
4351 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
4353 if (rc
|| (pSMBr
->ByteCount
< 24))
4354 rc
= -EIO
; /* bad smb */
4356 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
4360 *) (((char *) &pSMBr
->hdr
.Protocol
) +
4363 le32_to_cpu(response_data
->BytesPerSector
) *
4364 le32_to_cpu(response_data
->
4365 SectorsPerAllocationUnit
);
4367 le64_to_cpu(response_data
->TotalAllocationUnits
);
4368 FSData
->f_bfree
= FSData
->f_bavail
=
4369 le64_to_cpu(response_data
->FreeAllocationUnits
);
4370 cFYI(1, "Blocks: %lld Free: %lld Block size %ld",
4371 (unsigned long long)FSData
->f_blocks
,
4372 (unsigned long long)FSData
->f_bfree
,
4376 cifs_buf_release(pSMB
);
4385 CIFSSMBQFSAttributeInfo(const int xid
, struct cifsTconInfo
*tcon
)
4387 /* level 0x105 SMB_QUERY_FILE_SYSTEM_INFO */
4388 TRANSACTION2_QFSI_REQ
*pSMB
= NULL
;
4389 TRANSACTION2_QFSI_RSP
*pSMBr
= NULL
;
4390 FILE_SYSTEM_ATTRIBUTE_INFO
*response_data
;
4392 int bytes_returned
= 0;
4393 __u16 params
, byte_count
;
4395 cFYI(1, "In QFSAttributeInfo");
4397 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4402 params
= 2; /* level */
4403 pSMB
->TotalDataCount
= 0;
4404 pSMB
->MaxParameterCount
= cpu_to_le16(2);
4405 /* BB find exact max SMB PDU from sess structure BB */
4406 pSMB
->MaxDataCount
= cpu_to_le16(1000);
4407 pSMB
->MaxSetupCount
= 0;
4411 pSMB
->Reserved2
= 0;
4412 byte_count
= params
+ 1 /* pad */ ;
4413 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
4414 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
4415 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
4416 struct smb_com_transaction2_qfsi_req
, InformationLevel
) - 4);
4417 pSMB
->DataCount
= 0;
4418 pSMB
->DataOffset
= 0;
4419 pSMB
->SetupCount
= 1;
4420 pSMB
->Reserved3
= 0;
4421 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_FS_INFORMATION
);
4422 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FS_ATTRIBUTE_INFO
);
4423 pSMB
->hdr
.smb_buf_length
+= byte_count
;
4424 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4426 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4427 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4429 cERROR(1, "Send error in QFSAttributeInfo = %d", rc
);
4430 } else { /* decode response */
4431 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
4433 if (rc
|| (pSMBr
->ByteCount
< 13)) {
4434 /* BB also check if enough bytes returned */
4435 rc
= -EIO
; /* bad smb */
4437 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
4439 (FILE_SYSTEM_ATTRIBUTE_INFO
4440 *) (((char *) &pSMBr
->hdr
.Protocol
) +
4442 memcpy(&tcon
->fsAttrInfo
, response_data
,
4443 sizeof(FILE_SYSTEM_ATTRIBUTE_INFO
));
4446 cifs_buf_release(pSMB
);
4449 goto QFSAttributeRetry
;
4455 CIFSSMBQFSDeviceInfo(const int xid
, struct cifsTconInfo
*tcon
)
4457 /* level 0x104 SMB_QUERY_FILE_SYSTEM_INFO */
4458 TRANSACTION2_QFSI_REQ
*pSMB
= NULL
;
4459 TRANSACTION2_QFSI_RSP
*pSMBr
= NULL
;
4460 FILE_SYSTEM_DEVICE_INFO
*response_data
;
4462 int bytes_returned
= 0;
4463 __u16 params
, byte_count
;
4465 cFYI(1, "In QFSDeviceInfo");
4467 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4472 params
= 2; /* level */
4473 pSMB
->TotalDataCount
= 0;
4474 pSMB
->MaxParameterCount
= cpu_to_le16(2);
4475 /* BB find exact max SMB PDU from sess structure BB */
4476 pSMB
->MaxDataCount
= cpu_to_le16(1000);
4477 pSMB
->MaxSetupCount
= 0;
4481 pSMB
->Reserved2
= 0;
4482 byte_count
= params
+ 1 /* pad */ ;
4483 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
4484 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
4485 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
4486 struct smb_com_transaction2_qfsi_req
, InformationLevel
) - 4);
4488 pSMB
->DataCount
= 0;
4489 pSMB
->DataOffset
= 0;
4490 pSMB
->SetupCount
= 1;
4491 pSMB
->Reserved3
= 0;
4492 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_FS_INFORMATION
);
4493 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FS_DEVICE_INFO
);
4494 pSMB
->hdr
.smb_buf_length
+= byte_count
;
4495 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4497 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4498 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4500 cFYI(1, "Send error in QFSDeviceInfo = %d", rc
);
4501 } else { /* decode response */
4502 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
4504 if (rc
|| (pSMBr
->ByteCount
< sizeof(FILE_SYSTEM_DEVICE_INFO
)))
4505 rc
= -EIO
; /* bad smb */
4507 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
4509 (FILE_SYSTEM_DEVICE_INFO
*)
4510 (((char *) &pSMBr
->hdr
.Protocol
) +
4512 memcpy(&tcon
->fsDevInfo
, response_data
,
4513 sizeof(FILE_SYSTEM_DEVICE_INFO
));
4516 cifs_buf_release(pSMB
);
4519 goto QFSDeviceRetry
;
4525 CIFSSMBQFSUnixInfo(const int xid
, struct cifsTconInfo
*tcon
)
4527 /* level 0x200 SMB_QUERY_CIFS_UNIX_INFO */
4528 TRANSACTION2_QFSI_REQ
*pSMB
= NULL
;
4529 TRANSACTION2_QFSI_RSP
*pSMBr
= NULL
;
4530 FILE_SYSTEM_UNIX_INFO
*response_data
;
4532 int bytes_returned
= 0;
4533 __u16 params
, byte_count
;
4535 cFYI(1, "In QFSUnixInfo");
4537 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4542 params
= 2; /* level */
4543 pSMB
->TotalDataCount
= 0;
4544 pSMB
->DataCount
= 0;
4545 pSMB
->DataOffset
= 0;
4546 pSMB
->MaxParameterCount
= cpu_to_le16(2);
4547 /* BB find exact max SMB PDU from sess structure BB */
4548 pSMB
->MaxDataCount
= cpu_to_le16(100);
4549 pSMB
->MaxSetupCount
= 0;
4553 pSMB
->Reserved2
= 0;
4554 byte_count
= params
+ 1 /* pad */ ;
4555 pSMB
->ParameterCount
= cpu_to_le16(params
);
4556 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
4557 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(struct
4558 smb_com_transaction2_qfsi_req
, InformationLevel
) - 4);
4559 pSMB
->SetupCount
= 1;
4560 pSMB
->Reserved3
= 0;
4561 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_FS_INFORMATION
);
4562 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_CIFS_UNIX_INFO
);
4563 pSMB
->hdr
.smb_buf_length
+= byte_count
;
4564 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4566 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4567 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4569 cERROR(1, "Send error in QFSUnixInfo = %d", rc
);
4570 } else { /* decode response */
4571 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
4573 if (rc
|| (pSMBr
->ByteCount
< 13)) {
4574 rc
= -EIO
; /* bad smb */
4576 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
4578 (FILE_SYSTEM_UNIX_INFO
4579 *) (((char *) &pSMBr
->hdr
.Protocol
) +
4581 memcpy(&tcon
->fsUnixInfo
, response_data
,
4582 sizeof(FILE_SYSTEM_UNIX_INFO
));
4585 cifs_buf_release(pSMB
);
4595 CIFSSMBSetFSUnixInfo(const int xid
, struct cifsTconInfo
*tcon
, __u64 cap
)
4597 /* level 0x200 SMB_SET_CIFS_UNIX_INFO */
4598 TRANSACTION2_SETFSI_REQ
*pSMB
= NULL
;
4599 TRANSACTION2_SETFSI_RSP
*pSMBr
= NULL
;
4601 int bytes_returned
= 0;
4602 __u16 params
, param_offset
, offset
, byte_count
;
4604 cFYI(1, "In SETFSUnixInfo");
4606 /* BB switch to small buf init to save memory */
4607 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4612 params
= 4; /* 2 bytes zero followed by info level. */
4613 pSMB
->MaxSetupCount
= 0;
4617 pSMB
->Reserved2
= 0;
4618 param_offset
= offsetof(struct smb_com_transaction2_setfsi_req
, FileNum
)
4620 offset
= param_offset
+ params
;
4622 pSMB
->MaxParameterCount
= cpu_to_le16(4);
4623 /* BB find exact max SMB PDU from sess structure BB */
4624 pSMB
->MaxDataCount
= cpu_to_le16(100);
4625 pSMB
->SetupCount
= 1;
4626 pSMB
->Reserved3
= 0;
4627 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_FS_INFORMATION
);
4628 byte_count
= 1 /* pad */ + params
+ 12;
4630 pSMB
->DataCount
= cpu_to_le16(12);
4631 pSMB
->ParameterCount
= cpu_to_le16(params
);
4632 pSMB
->TotalDataCount
= pSMB
->DataCount
;
4633 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
4634 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
4635 pSMB
->DataOffset
= cpu_to_le16(offset
);
4639 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_CIFS_UNIX_INFO
);
4642 pSMB
->ClientUnixMajor
= cpu_to_le16(CIFS_UNIX_MAJOR_VERSION
);
4643 pSMB
->ClientUnixMinor
= cpu_to_le16(CIFS_UNIX_MINOR_VERSION
);
4644 pSMB
->ClientUnixCap
= cpu_to_le64(cap
);
4646 pSMB
->hdr
.smb_buf_length
+= byte_count
;
4647 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4649 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4650 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4652 cERROR(1, "Send error in SETFSUnixInfo = %d", rc
);
4653 } else { /* decode response */
4654 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
4656 rc
= -EIO
; /* bad smb */
4658 cifs_buf_release(pSMB
);
4661 goto SETFSUnixRetry
;
4669 CIFSSMBQFSPosixInfo(const int xid
, struct cifsTconInfo
*tcon
,
4670 struct kstatfs
*FSData
)
4672 /* level 0x201 SMB_QUERY_CIFS_POSIX_INFO */
4673 TRANSACTION2_QFSI_REQ
*pSMB
= NULL
;
4674 TRANSACTION2_QFSI_RSP
*pSMBr
= NULL
;
4675 FILE_SYSTEM_POSIX_INFO
*response_data
;
4677 int bytes_returned
= 0;
4678 __u16 params
, byte_count
;
4680 cFYI(1, "In QFSPosixInfo");
4682 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4687 params
= 2; /* level */
4688 pSMB
->TotalDataCount
= 0;
4689 pSMB
->DataCount
= 0;
4690 pSMB
->DataOffset
= 0;
4691 pSMB
->MaxParameterCount
= cpu_to_le16(2);
4692 /* BB find exact max SMB PDU from sess structure BB */
4693 pSMB
->MaxDataCount
= cpu_to_le16(100);
4694 pSMB
->MaxSetupCount
= 0;
4698 pSMB
->Reserved2
= 0;
4699 byte_count
= params
+ 1 /* pad */ ;
4700 pSMB
->ParameterCount
= cpu_to_le16(params
);
4701 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
4702 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(struct
4703 smb_com_transaction2_qfsi_req
, InformationLevel
) - 4);
4704 pSMB
->SetupCount
= 1;
4705 pSMB
->Reserved3
= 0;
4706 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_FS_INFORMATION
);
4707 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_POSIX_FS_INFO
);
4708 pSMB
->hdr
.smb_buf_length
+= byte_count
;
4709 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4711 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4712 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4714 cFYI(1, "Send error in QFSUnixInfo = %d", rc
);
4715 } else { /* decode response */
4716 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
4718 if (rc
|| (pSMBr
->ByteCount
< 13)) {
4719 rc
= -EIO
; /* bad smb */
4721 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
4723 (FILE_SYSTEM_POSIX_INFO
4724 *) (((char *) &pSMBr
->hdr
.Protocol
) +
4727 le32_to_cpu(response_data
->BlockSize
);
4729 le64_to_cpu(response_data
->TotalBlocks
);
4731 le64_to_cpu(response_data
->BlocksAvail
);
4732 if (response_data
->UserBlocksAvail
== cpu_to_le64(-1)) {
4733 FSData
->f_bavail
= FSData
->f_bfree
;
4736 le64_to_cpu(response_data
->UserBlocksAvail
);
4738 if (response_data
->TotalFileNodes
!= cpu_to_le64(-1))
4740 le64_to_cpu(response_data
->TotalFileNodes
);
4741 if (response_data
->FreeFileNodes
!= cpu_to_le64(-1))
4743 le64_to_cpu(response_data
->FreeFileNodes
);
4746 cifs_buf_release(pSMB
);
4755 /* We can not use write of zero bytes trick to
4756 set file size due to need for large file support. Also note that
4757 this SetPathInfo is preferred to SetFileInfo based method in next
4758 routine which is only needed to work around a sharing violation bug
4759 in Samba which this routine can run into */
4762 CIFSSMBSetEOF(const int xid
, struct cifsTconInfo
*tcon
, const char *fileName
,
4763 __u64 size
, bool SetAllocation
,
4764 const struct nls_table
*nls_codepage
, int remap
)
4766 struct smb_com_transaction2_spi_req
*pSMB
= NULL
;
4767 struct smb_com_transaction2_spi_rsp
*pSMBr
= NULL
;
4768 struct file_end_of_file_info
*parm_data
;
4771 int bytes_returned
= 0;
4772 __u16 params
, byte_count
, data_count
, param_offset
, offset
;
4774 cFYI(1, "In SetEOF");
4776 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4781 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
4783 cifsConvertToUCS((__le16
*) pSMB
->FileName
, fileName
,
4784 PATH_MAX
, nls_codepage
, remap
);
4785 name_len
++; /* trailing null */
4787 } else { /* BB improve the check for buffer overruns BB */
4788 name_len
= strnlen(fileName
, PATH_MAX
);
4789 name_len
++; /* trailing null */
4790 strncpy(pSMB
->FileName
, fileName
, name_len
);
4792 params
= 6 + name_len
;
4793 data_count
= sizeof(struct file_end_of_file_info
);
4794 pSMB
->MaxParameterCount
= cpu_to_le16(2);
4795 pSMB
->MaxDataCount
= cpu_to_le16(4100);
4796 pSMB
->MaxSetupCount
= 0;
4800 pSMB
->Reserved2
= 0;
4801 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
4802 InformationLevel
) - 4;
4803 offset
= param_offset
+ params
;
4804 if (SetAllocation
) {
4805 if (tcon
->ses
->capabilities
& CAP_INFOLEVEL_PASSTHRU
)
4806 pSMB
->InformationLevel
=
4807 cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2
);
4809 pSMB
->InformationLevel
=
4810 cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO
);
4811 } else /* Set File Size */ {
4812 if (tcon
->ses
->capabilities
& CAP_INFOLEVEL_PASSTHRU
)
4813 pSMB
->InformationLevel
=
4814 cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2
);
4816 pSMB
->InformationLevel
=
4817 cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO
);
4821 (struct file_end_of_file_info
*) (((char *) &pSMB
->hdr
.Protocol
) +
4823 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
4824 pSMB
->DataOffset
= cpu_to_le16(offset
);
4825 pSMB
->SetupCount
= 1;
4826 pSMB
->Reserved3
= 0;
4827 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
4828 byte_count
= 3 /* pad */ + params
+ data_count
;
4829 pSMB
->DataCount
= cpu_to_le16(data_count
);
4830 pSMB
->TotalDataCount
= pSMB
->DataCount
;
4831 pSMB
->ParameterCount
= cpu_to_le16(params
);
4832 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
4833 pSMB
->Reserved4
= 0;
4834 pSMB
->hdr
.smb_buf_length
+= byte_count
;
4835 parm_data
->FileSize
= cpu_to_le64(size
);
4836 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4837 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4838 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4840 cFYI(1, "SetPathInfo (file size) returned %d", rc
);
4842 cifs_buf_release(pSMB
);
4851 CIFSSMBSetFileSize(const int xid
, struct cifsTconInfo
*tcon
, __u64 size
,
4852 __u16 fid
, __u32 pid_of_opener
, bool SetAllocation
)
4854 struct smb_com_transaction2_sfi_req
*pSMB
= NULL
;
4856 struct file_end_of_file_info
*parm_data
;
4858 __u16 params
, param_offset
, offset
, byte_count
, count
;
4860 cFYI(1, "SetFileSize (via SetFileInfo) %lld",
4862 rc
= small_smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
);
4867 pSMB
->hdr
.Pid
= cpu_to_le16((__u16
)pid_of_opener
);
4868 pSMB
->hdr
.PidHigh
= cpu_to_le16((__u16
)(pid_of_opener
>> 16));
4871 pSMB
->MaxSetupCount
= 0;
4875 pSMB
->Reserved2
= 0;
4876 param_offset
= offsetof(struct smb_com_transaction2_sfi_req
, Fid
) - 4;
4877 offset
= param_offset
+ params
;
4879 data_offset
= (char *) (&pSMB
->hdr
.Protocol
) + offset
;
4881 count
= sizeof(struct file_end_of_file_info
);
4882 pSMB
->MaxParameterCount
= cpu_to_le16(2);
4883 /* BB find exact max SMB PDU from sess structure BB */
4884 pSMB
->MaxDataCount
= cpu_to_le16(1000);
4885 pSMB
->SetupCount
= 1;
4886 pSMB
->Reserved3
= 0;
4887 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_FILE_INFORMATION
);
4888 byte_count
= 3 /* pad */ + params
+ count
;
4889 pSMB
->DataCount
= cpu_to_le16(count
);
4890 pSMB
->ParameterCount
= cpu_to_le16(params
);
4891 pSMB
->TotalDataCount
= pSMB
->DataCount
;
4892 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
4893 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
4895 (struct file_end_of_file_info
*) (((char *) &pSMB
->hdr
.Protocol
)
4897 pSMB
->DataOffset
= cpu_to_le16(offset
);
4898 parm_data
->FileSize
= cpu_to_le64(size
);
4900 if (SetAllocation
) {
4901 if (tcon
->ses
->capabilities
& CAP_INFOLEVEL_PASSTHRU
)
4902 pSMB
->InformationLevel
=
4903 cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2
);
4905 pSMB
->InformationLevel
=
4906 cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO
);
4907 } else /* Set File Size */ {
4908 if (tcon
->ses
->capabilities
& CAP_INFOLEVEL_PASSTHRU
)
4909 pSMB
->InformationLevel
=
4910 cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2
);
4912 pSMB
->InformationLevel
=
4913 cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO
);
4915 pSMB
->Reserved4
= 0;
4916 pSMB
->hdr
.smb_buf_length
+= byte_count
;
4917 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4918 rc
= SendReceiveNoRsp(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
, 0);
4920 cFYI(1, "Send error in SetFileInfo (SetFileSize) = %d", rc
);
4923 /* Note: On -EAGAIN error only caller can retry on handle based calls
4924 since file handle passed in no longer valid */
4929 /* Some legacy servers such as NT4 require that the file times be set on
4930 an open handle, rather than by pathname - this is awkward due to
4931 potential access conflicts on the open, but it is unavoidable for these
4932 old servers since the only other choice is to go from 100 nanosecond DCE
4933 time and resort to the original setpathinfo level which takes the ancient
4934 DOS time format with 2 second granularity */
4936 CIFSSMBSetFileInfo(const int xid
, struct cifsTconInfo
*tcon
,
4937 const FILE_BASIC_INFO
*data
, __u16 fid
, __u32 pid_of_opener
)
4939 struct smb_com_transaction2_sfi_req
*pSMB
= NULL
;
4942 __u16 params
, param_offset
, offset
, byte_count
, count
;
4944 cFYI(1, "Set Times (via SetFileInfo)");
4945 rc
= small_smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
);
4950 pSMB
->hdr
.Pid
= cpu_to_le16((__u16
)pid_of_opener
);
4951 pSMB
->hdr
.PidHigh
= cpu_to_le16((__u16
)(pid_of_opener
>> 16));
4954 pSMB
->MaxSetupCount
= 0;
4958 pSMB
->Reserved2
= 0;
4959 param_offset
= offsetof(struct smb_com_transaction2_sfi_req
, Fid
) - 4;
4960 offset
= param_offset
+ params
;
4962 data_offset
= (char *) (&pSMB
->hdr
.Protocol
) + offset
;
4964 count
= sizeof(FILE_BASIC_INFO
);
4965 pSMB
->MaxParameterCount
= cpu_to_le16(2);
4966 /* BB find max SMB PDU from sess */
4967 pSMB
->MaxDataCount
= cpu_to_le16(1000);
4968 pSMB
->SetupCount
= 1;
4969 pSMB
->Reserved3
= 0;
4970 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_FILE_INFORMATION
);
4971 byte_count
= 3 /* pad */ + params
+ count
;
4972 pSMB
->DataCount
= cpu_to_le16(count
);
4973 pSMB
->ParameterCount
= cpu_to_le16(params
);
4974 pSMB
->TotalDataCount
= pSMB
->DataCount
;
4975 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
4976 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
4977 pSMB
->DataOffset
= cpu_to_le16(offset
);
4979 if (tcon
->ses
->capabilities
& CAP_INFOLEVEL_PASSTHRU
)
4980 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_BASIC_INFO2
);
4982 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_BASIC_INFO
);
4983 pSMB
->Reserved4
= 0;
4984 pSMB
->hdr
.smb_buf_length
+= byte_count
;
4985 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4986 memcpy(data_offset
, data
, sizeof(FILE_BASIC_INFO
));
4987 rc
= SendReceiveNoRsp(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
, 0);
4989 cFYI(1, "Send error in Set Time (SetFileInfo) = %d", rc
);
4991 /* Note: On -EAGAIN error only caller can retry on handle based calls
4992 since file handle passed in no longer valid */
4998 CIFSSMBSetFileDisposition(const int xid
, struct cifsTconInfo
*tcon
,
4999 bool delete_file
, __u16 fid
, __u32 pid_of_opener
)
5001 struct smb_com_transaction2_sfi_req
*pSMB
= NULL
;
5004 __u16 params
, param_offset
, offset
, byte_count
, count
;
5006 cFYI(1, "Set File Disposition (via SetFileInfo)");
5007 rc
= small_smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
);
5012 pSMB
->hdr
.Pid
= cpu_to_le16((__u16
)pid_of_opener
);
5013 pSMB
->hdr
.PidHigh
= cpu_to_le16((__u16
)(pid_of_opener
>> 16));
5016 pSMB
->MaxSetupCount
= 0;
5020 pSMB
->Reserved2
= 0;
5021 param_offset
= offsetof(struct smb_com_transaction2_sfi_req
, Fid
) - 4;
5022 offset
= param_offset
+ params
;
5024 data_offset
= (char *) (&pSMB
->hdr
.Protocol
) + offset
;
5027 pSMB
->MaxParameterCount
= cpu_to_le16(2);
5028 /* BB find max SMB PDU from sess */
5029 pSMB
->MaxDataCount
= cpu_to_le16(1000);
5030 pSMB
->SetupCount
= 1;
5031 pSMB
->Reserved3
= 0;
5032 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_FILE_INFORMATION
);
5033 byte_count
= 3 /* pad */ + params
+ count
;
5034 pSMB
->DataCount
= cpu_to_le16(count
);
5035 pSMB
->ParameterCount
= cpu_to_le16(params
);
5036 pSMB
->TotalDataCount
= pSMB
->DataCount
;
5037 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
5038 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
5039 pSMB
->DataOffset
= cpu_to_le16(offset
);
5041 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_DISPOSITION_INFO
);
5042 pSMB
->Reserved4
= 0;
5043 pSMB
->hdr
.smb_buf_length
+= byte_count
;
5044 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
5045 *data_offset
= delete_file
? 1 : 0;
5046 rc
= SendReceiveNoRsp(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
, 0);
5048 cFYI(1, "Send error in SetFileDisposition = %d", rc
);
5054 CIFSSMBSetPathInfo(const int xid
, struct cifsTconInfo
*tcon
,
5055 const char *fileName
, const FILE_BASIC_INFO
*data
,
5056 const struct nls_table
*nls_codepage
, int remap
)
5058 TRANSACTION2_SPI_REQ
*pSMB
= NULL
;
5059 TRANSACTION2_SPI_RSP
*pSMBr
= NULL
;
5062 int bytes_returned
= 0;
5064 __u16 params
, param_offset
, offset
, byte_count
, count
;
5066 cFYI(1, "In SetTimes");
5069 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
5074 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
5076 cifsConvertToUCS((__le16
*) pSMB
->FileName
, fileName
,
5077 PATH_MAX
, nls_codepage
, remap
);
5078 name_len
++; /* trailing null */
5080 } else { /* BB improve the check for buffer overruns BB */
5081 name_len
= strnlen(fileName
, PATH_MAX
);
5082 name_len
++; /* trailing null */
5083 strncpy(pSMB
->FileName
, fileName
, name_len
);
5086 params
= 6 + name_len
;
5087 count
= sizeof(FILE_BASIC_INFO
);
5088 pSMB
->MaxParameterCount
= cpu_to_le16(2);
5089 /* BB find max SMB PDU from sess structure BB */
5090 pSMB
->MaxDataCount
= cpu_to_le16(1000);
5091 pSMB
->MaxSetupCount
= 0;
5095 pSMB
->Reserved2
= 0;
5096 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
5097 InformationLevel
) - 4;
5098 offset
= param_offset
+ params
;
5099 data_offset
= (char *) (&pSMB
->hdr
.Protocol
) + offset
;
5100 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
5101 pSMB
->DataOffset
= cpu_to_le16(offset
);
5102 pSMB
->SetupCount
= 1;
5103 pSMB
->Reserved3
= 0;
5104 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
5105 byte_count
= 3 /* pad */ + params
+ count
;
5107 pSMB
->DataCount
= cpu_to_le16(count
);
5108 pSMB
->ParameterCount
= cpu_to_le16(params
);
5109 pSMB
->TotalDataCount
= pSMB
->DataCount
;
5110 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
5111 if (tcon
->ses
->capabilities
& CAP_INFOLEVEL_PASSTHRU
)
5112 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_BASIC_INFO2
);
5114 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_BASIC_INFO
);
5115 pSMB
->Reserved4
= 0;
5116 pSMB
->hdr
.smb_buf_length
+= byte_count
;
5117 memcpy(data_offset
, data
, sizeof(FILE_BASIC_INFO
));
5118 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
5119 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
5120 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
5122 cFYI(1, "SetPathInfo (times) returned %d", rc
);
5124 cifs_buf_release(pSMB
);
5132 /* Can not be used to set time stamps yet (due to old DOS time format) */
5133 /* Can be used to set attributes */
5134 #if 0 /* Possibly not needed - since it turns out that strangely NT4 has a bug
5135 handling it anyway and NT4 was what we thought it would be needed for
5136 Do not delete it until we prove whether needed for Win9x though */
5138 CIFSSMBSetAttrLegacy(int xid
, struct cifsTconInfo
*tcon
, char *fileName
,
5139 __u16 dos_attrs
, const struct nls_table
*nls_codepage
)
5141 SETATTR_REQ
*pSMB
= NULL
;
5142 SETATTR_RSP
*pSMBr
= NULL
;
5147 cFYI(1, "In SetAttrLegacy");
5150 rc
= smb_init(SMB_COM_SETATTR
, 8, tcon
, (void **) &pSMB
,
5155 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
5157 ConvertToUCS((__le16
*) pSMB
->fileName
, fileName
,
5158 PATH_MAX
, nls_codepage
);
5159 name_len
++; /* trailing null */
5161 } else { /* BB improve the check for buffer overruns BB */
5162 name_len
= strnlen(fileName
, PATH_MAX
);
5163 name_len
++; /* trailing null */
5164 strncpy(pSMB
->fileName
, fileName
, name_len
);
5166 pSMB
->attr
= cpu_to_le16(dos_attrs
);
5167 pSMB
->BufferFormat
= 0x04;
5168 pSMB
->hdr
.smb_buf_length
+= name_len
+ 1;
5169 pSMB
->ByteCount
= cpu_to_le16(name_len
+ 1);
5170 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
5171 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
5173 cFYI(1, "Error in LegacySetAttr = %d", rc
);
5175 cifs_buf_release(pSMB
);
5178 goto SetAttrLgcyRetry
;
5182 #endif /* temporarily unneeded SetAttr legacy function */
5185 cifs_fill_unix_set_info(FILE_UNIX_BASIC_INFO
*data_offset
,
5186 const struct cifs_unix_set_info_args
*args
)
5188 u64 mode
= args
->mode
;
5191 * Samba server ignores set of file size to zero due to bugs in some
5192 * older clients, but we should be precise - we use SetFileSize to
5193 * set file size and do not want to truncate file size to zero
5194 * accidently as happened on one Samba server beta by putting
5195 * zero instead of -1 here
5197 data_offset
->EndOfFile
= cpu_to_le64(NO_CHANGE_64
);
5198 data_offset
->NumOfBytes
= cpu_to_le64(NO_CHANGE_64
);
5199 data_offset
->LastStatusChange
= cpu_to_le64(args
->ctime
);
5200 data_offset
->LastAccessTime
= cpu_to_le64(args
->atime
);
5201 data_offset
->LastModificationTime
= cpu_to_le64(args
->mtime
);
5202 data_offset
->Uid
= cpu_to_le64(args
->uid
);
5203 data_offset
->Gid
= cpu_to_le64(args
->gid
);
5204 /* better to leave device as zero when it is */
5205 data_offset
->DevMajor
= cpu_to_le64(MAJOR(args
->device
));
5206 data_offset
->DevMinor
= cpu_to_le64(MINOR(args
->device
));
5207 data_offset
->Permissions
= cpu_to_le64(mode
);
5210 data_offset
->Type
= cpu_to_le32(UNIX_FILE
);
5211 else if (S_ISDIR(mode
))
5212 data_offset
->Type
= cpu_to_le32(UNIX_DIR
);
5213 else if (S_ISLNK(mode
))
5214 data_offset
->Type
= cpu_to_le32(UNIX_SYMLINK
);
5215 else if (S_ISCHR(mode
))
5216 data_offset
->Type
= cpu_to_le32(UNIX_CHARDEV
);
5217 else if (S_ISBLK(mode
))
5218 data_offset
->Type
= cpu_to_le32(UNIX_BLOCKDEV
);
5219 else if (S_ISFIFO(mode
))
5220 data_offset
->Type
= cpu_to_le32(UNIX_FIFO
);
5221 else if (S_ISSOCK(mode
))
5222 data_offset
->Type
= cpu_to_le32(UNIX_SOCKET
);
5226 CIFSSMBUnixSetFileInfo(const int xid
, struct cifsTconInfo
*tcon
,
5227 const struct cifs_unix_set_info_args
*args
,
5228 u16 fid
, u32 pid_of_opener
)
5230 struct smb_com_transaction2_sfi_req
*pSMB
= NULL
;
5231 FILE_UNIX_BASIC_INFO
*data_offset
;
5233 u16 params
, param_offset
, offset
, byte_count
, count
;
5235 cFYI(1, "Set Unix Info (via SetFileInfo)");
5236 rc
= small_smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
);
5241 pSMB
->hdr
.Pid
= cpu_to_le16((__u16
)pid_of_opener
);
5242 pSMB
->hdr
.PidHigh
= cpu_to_le16((__u16
)(pid_of_opener
>> 16));
5245 pSMB
->MaxSetupCount
= 0;
5249 pSMB
->Reserved2
= 0;
5250 param_offset
= offsetof(struct smb_com_transaction2_sfi_req
, Fid
) - 4;
5251 offset
= param_offset
+ params
;
5253 data_offset
= (FILE_UNIX_BASIC_INFO
*)
5254 ((char *)(&pSMB
->hdr
.Protocol
) + offset
);
5255 count
= sizeof(FILE_UNIX_BASIC_INFO
);
5257 pSMB
->MaxParameterCount
= cpu_to_le16(2);
5258 /* BB find max SMB PDU from sess */
5259 pSMB
->MaxDataCount
= cpu_to_le16(1000);
5260 pSMB
->SetupCount
= 1;
5261 pSMB
->Reserved3
= 0;
5262 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_FILE_INFORMATION
);
5263 byte_count
= 3 /* pad */ + params
+ count
;
5264 pSMB
->DataCount
= cpu_to_le16(count
);
5265 pSMB
->ParameterCount
= cpu_to_le16(params
);
5266 pSMB
->TotalDataCount
= pSMB
->DataCount
;
5267 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
5268 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
5269 pSMB
->DataOffset
= cpu_to_le16(offset
);
5271 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_UNIX_BASIC
);
5272 pSMB
->Reserved4
= 0;
5273 pSMB
->hdr
.smb_buf_length
+= byte_count
;
5274 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
5276 cifs_fill_unix_set_info(data_offset
, args
);
5278 rc
= SendReceiveNoRsp(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
, 0);
5280 cFYI(1, "Send error in Set Time (SetFileInfo) = %d", rc
);
5282 /* Note: On -EAGAIN error only caller can retry on handle based calls
5283 since file handle passed in no longer valid */
5289 CIFSSMBUnixSetPathInfo(const int xid
, struct cifsTconInfo
*tcon
, char *fileName
,
5290 const struct cifs_unix_set_info_args
*args
,
5291 const struct nls_table
*nls_codepage
, int remap
)
5293 TRANSACTION2_SPI_REQ
*pSMB
= NULL
;
5294 TRANSACTION2_SPI_RSP
*pSMBr
= NULL
;
5297 int bytes_returned
= 0;
5298 FILE_UNIX_BASIC_INFO
*data_offset
;
5299 __u16 params
, param_offset
, offset
, count
, byte_count
;
5301 cFYI(1, "In SetUID/GID/Mode");
5303 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
5308 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
5310 cifsConvertToUCS((__le16
*) pSMB
->FileName
, fileName
,
5311 PATH_MAX
, nls_codepage
, remap
);
5312 name_len
++; /* trailing null */
5314 } else { /* BB improve the check for buffer overruns BB */
5315 name_len
= strnlen(fileName
, PATH_MAX
);
5316 name_len
++; /* trailing null */
5317 strncpy(pSMB
->FileName
, fileName
, name_len
);
5320 params
= 6 + name_len
;
5321 count
= sizeof(FILE_UNIX_BASIC_INFO
);
5322 pSMB
->MaxParameterCount
= cpu_to_le16(2);
5323 /* BB find max SMB PDU from sess structure BB */
5324 pSMB
->MaxDataCount
= cpu_to_le16(1000);
5325 pSMB
->MaxSetupCount
= 0;
5329 pSMB
->Reserved2
= 0;
5330 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
5331 InformationLevel
) - 4;
5332 offset
= param_offset
+ params
;
5334 (FILE_UNIX_BASIC_INFO
*) ((char *) &pSMB
->hdr
.Protocol
+
5336 memset(data_offset
, 0, count
);
5337 pSMB
->DataOffset
= cpu_to_le16(offset
);
5338 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
5339 pSMB
->SetupCount
= 1;
5340 pSMB
->Reserved3
= 0;
5341 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
5342 byte_count
= 3 /* pad */ + params
+ count
;
5343 pSMB
->ParameterCount
= cpu_to_le16(params
);
5344 pSMB
->DataCount
= cpu_to_le16(count
);
5345 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
5346 pSMB
->TotalDataCount
= pSMB
->DataCount
;
5347 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_UNIX_BASIC
);
5348 pSMB
->Reserved4
= 0;
5349 pSMB
->hdr
.smb_buf_length
+= byte_count
;
5351 cifs_fill_unix_set_info(data_offset
, args
);
5353 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
5354 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
5355 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
5357 cFYI(1, "SetPathInfo (perms) returned %d", rc
);
5359 cifs_buf_release(pSMB
);
5365 int CIFSSMBNotify(const int xid
, struct cifsTconInfo
*tcon
,
5366 const int notify_subdirs
, const __u16 netfid
,
5367 __u32 filter
, struct file
*pfile
, int multishot
,
5368 const struct nls_table
*nls_codepage
)
5371 struct smb_com_transaction_change_notify_req
*pSMB
= NULL
;
5372 struct smb_com_ntransaction_change_notify_rsp
*pSMBr
= NULL
;
5373 struct dir_notify_req
*dnotify_req
;
5376 cFYI(1, "In CIFSSMBNotify for file handle %d", (int)netfid
);
5377 rc
= smb_init(SMB_COM_NT_TRANSACT
, 23, tcon
, (void **) &pSMB
,
5382 pSMB
->TotalParameterCount
= 0 ;
5383 pSMB
->TotalDataCount
= 0;
5384 pSMB
->MaxParameterCount
= cpu_to_le32(2);
5385 /* BB find exact data count max from sess structure BB */
5386 pSMB
->MaxDataCount
= 0; /* same in little endian or be */
5387 /* BB VERIFY verify which is correct for above BB */
5388 pSMB
->MaxDataCount
= cpu_to_le32((tcon
->ses
->server
->maxBuf
-
5389 MAX_CIFS_HDR_SIZE
) & 0xFFFFFF00);
5391 pSMB
->MaxSetupCount
= 4;
5393 pSMB
->ParameterOffset
= 0;
5394 pSMB
->DataCount
= 0;
5395 pSMB
->DataOffset
= 0;
5396 pSMB
->SetupCount
= 4; /* single byte does not need le conversion */
5397 pSMB
->SubCommand
= cpu_to_le16(NT_TRANSACT_NOTIFY_CHANGE
);
5398 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
5400 pSMB
->WatchTree
= 1; /* one byte - no le conversion needed */
5401 pSMB
->Reserved2
= 0;
5402 pSMB
->CompletionFilter
= cpu_to_le32(filter
);
5403 pSMB
->Fid
= netfid
; /* file handle always le */
5404 pSMB
->ByteCount
= 0;
5406 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
5407 (struct smb_hdr
*)pSMBr
, &bytes_returned
,
5410 cFYI(1, "Error in Notify = %d", rc
);
5412 /* Add file to outstanding requests */
5413 /* BB change to kmem cache alloc */
5414 dnotify_req
= kmalloc(
5415 sizeof(struct dir_notify_req
),
5418 dnotify_req
->Pid
= pSMB
->hdr
.Pid
;
5419 dnotify_req
->PidHigh
= pSMB
->hdr
.PidHigh
;
5420 dnotify_req
->Mid
= pSMB
->hdr
.Mid
;
5421 dnotify_req
->Tid
= pSMB
->hdr
.Tid
;
5422 dnotify_req
->Uid
= pSMB
->hdr
.Uid
;
5423 dnotify_req
->netfid
= netfid
;
5424 dnotify_req
->pfile
= pfile
;
5425 dnotify_req
->filter
= filter
;
5426 dnotify_req
->multishot
= multishot
;
5427 spin_lock(&GlobalMid_Lock
);
5428 list_add_tail(&dnotify_req
->lhead
,
5429 &GlobalDnotifyReqList
);
5430 spin_unlock(&GlobalMid_Lock
);
5434 cifs_buf_release(pSMB
);
5438 #ifdef CONFIG_CIFS_XATTR
5440 * Do a path-based QUERY_ALL_EAS call and parse the result. This is a common
5441 * function used by listxattr and getxattr type calls. When ea_name is set,
5442 * it looks for that attribute name and stuffs that value into the EAData
5443 * buffer. When ea_name is NULL, it stuffs a list of attribute names into the
5444 * buffer. In both cases, the return value is either the length of the
5445 * resulting data or a negative error code. If EAData is a NULL pointer then
5446 * the data isn't copied to it, but the length is returned.
5449 CIFSSMBQAllEAs(const int xid
, struct cifsTconInfo
*tcon
,
5450 const unsigned char *searchName
, const unsigned char *ea_name
,
5451 char *EAData
, size_t buf_size
,
5452 const struct nls_table
*nls_codepage
, int remap
)
5454 /* BB assumes one setup word */
5455 TRANSACTION2_QPI_REQ
*pSMB
= NULL
;
5456 TRANSACTION2_QPI_RSP
*pSMBr
= NULL
;
5460 struct fealist
*ea_response_data
;
5461 struct fea
*temp_fea
;
5464 __u16 params
, byte_count
, data_offset
;
5466 cFYI(1, "In Query All EAs path %s", searchName
);
5468 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
5473 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
5475 cifsConvertToUCS((__le16
*) pSMB
->FileName
, searchName
,
5476 PATH_MAX
, nls_codepage
, remap
);
5477 list_len
++; /* trailing null */
5479 } else { /* BB improve the check for buffer overruns BB */
5480 list_len
= strnlen(searchName
, PATH_MAX
);
5481 list_len
++; /* trailing null */
5482 strncpy(pSMB
->FileName
, searchName
, list_len
);
5485 params
= 2 /* level */ + 4 /* reserved */ + list_len
/* includes NUL */;
5486 pSMB
->TotalDataCount
= 0;
5487 pSMB
->MaxParameterCount
= cpu_to_le16(2);
5488 /* BB find exact max SMB PDU from sess structure BB */
5489 pSMB
->MaxDataCount
= cpu_to_le16(CIFSMaxBufSize
);
5490 pSMB
->MaxSetupCount
= 0;
5494 pSMB
->Reserved2
= 0;
5495 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
5496 struct smb_com_transaction2_qpi_req
, InformationLevel
) - 4);
5497 pSMB
->DataCount
= 0;
5498 pSMB
->DataOffset
= 0;
5499 pSMB
->SetupCount
= 1;
5500 pSMB
->Reserved3
= 0;
5501 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION
);
5502 byte_count
= params
+ 1 /* pad */ ;
5503 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
5504 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
5505 pSMB
->InformationLevel
= cpu_to_le16(SMB_INFO_QUERY_ALL_EAS
);
5506 pSMB
->Reserved4
= 0;
5507 pSMB
->hdr
.smb_buf_length
+= byte_count
;
5508 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
5510 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
5511 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
5513 cFYI(1, "Send error in QueryAllEAs = %d", rc
);
5518 /* BB also check enough total bytes returned */
5519 /* BB we need to improve the validity checking
5520 of these trans2 responses */
5522 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
5523 if (rc
|| (pSMBr
->ByteCount
< 4)) {
5524 rc
= -EIO
; /* bad smb */
5528 /* check that length of list is not more than bcc */
5529 /* check that each entry does not go beyond length
5531 /* check that each element of each entry does not
5532 go beyond end of list */
5533 /* validate_trans2_offsets() */
5534 /* BB check if start of smb + data_offset > &bcc+ bcc */
5536 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
5537 ea_response_data
= (struct fealist
*)
5538 (((char *) &pSMBr
->hdr
.Protocol
) + data_offset
);
5540 list_len
= le32_to_cpu(ea_response_data
->list_len
);
5541 cFYI(1, "ea length %d", list_len
);
5542 if (list_len
<= 8) {
5543 cFYI(1, "empty EA list returned from server");
5547 /* make sure list_len doesn't go past end of SMB */
5548 end_of_smb
= (char *)pByteArea(&pSMBr
->hdr
) + BCC(&pSMBr
->hdr
);
5549 if ((char *)ea_response_data
+ list_len
> end_of_smb
) {
5550 cFYI(1, "EA list appears to go beyond SMB");
5555 /* account for ea list len */
5557 temp_fea
= ea_response_data
->list
;
5558 temp_ptr
= (char *)temp_fea
;
5559 while (list_len
> 0) {
5560 unsigned int name_len
;
5565 /* make sure we can read name_len and value_len */
5567 cFYI(1, "EA entry goes beyond length of list");
5572 name_len
= temp_fea
->name_len
;
5573 value_len
= le16_to_cpu(temp_fea
->value_len
);
5574 list_len
-= name_len
+ 1 + value_len
;
5576 cFYI(1, "EA entry goes beyond length of list");
5582 if (strncmp(ea_name
, temp_ptr
, name_len
) == 0) {
5583 temp_ptr
+= name_len
+ 1;
5587 if ((size_t)value_len
> buf_size
) {
5591 memcpy(EAData
, temp_ptr
, value_len
);
5595 /* account for prefix user. and trailing null */
5596 rc
+= (5 + 1 + name_len
);
5597 if (rc
< (int) buf_size
) {
5598 memcpy(EAData
, "user.", 5);
5600 memcpy(EAData
, temp_ptr
, name_len
);
5602 /* null terminate name */
5605 } else if (buf_size
== 0) {
5606 /* skip copy - calc size only */
5608 /* stop before overrun buffer */
5613 temp_ptr
+= name_len
+ 1 + value_len
;
5614 temp_fea
= (struct fea
*)temp_ptr
;
5617 /* didn't find the named attribute */
5622 cifs_buf_release(pSMB
);
5630 CIFSSMBSetEA(const int xid
, struct cifsTconInfo
*tcon
, const char *fileName
,
5631 const char *ea_name
, const void *ea_value
,
5632 const __u16 ea_value_len
, const struct nls_table
*nls_codepage
,
5635 struct smb_com_transaction2_spi_req
*pSMB
= NULL
;
5636 struct smb_com_transaction2_spi_rsp
*pSMBr
= NULL
;
5637 struct fealist
*parm_data
;
5640 int bytes_returned
= 0;
5641 __u16 params
, param_offset
, byte_count
, offset
, count
;
5643 cFYI(1, "In SetEA");
5645 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
5650 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
5652 cifsConvertToUCS((__le16
*) pSMB
->FileName
, fileName
,
5653 PATH_MAX
, nls_codepage
, remap
);
5654 name_len
++; /* trailing null */
5656 } else { /* BB improve the check for buffer overruns BB */
5657 name_len
= strnlen(fileName
, PATH_MAX
);
5658 name_len
++; /* trailing null */
5659 strncpy(pSMB
->FileName
, fileName
, name_len
);
5662 params
= 6 + name_len
;
5664 /* done calculating parms using name_len of file name,
5665 now use name_len to calculate length of ea name
5666 we are going to create in the inode xattrs */
5667 if (ea_name
== NULL
)
5670 name_len
= strnlen(ea_name
, 255);
5672 count
= sizeof(*parm_data
) + ea_value_len
+ name_len
;
5673 pSMB
->MaxParameterCount
= cpu_to_le16(2);
5674 /* BB find max SMB PDU from sess */
5675 pSMB
->MaxDataCount
= cpu_to_le16(1000);
5676 pSMB
->MaxSetupCount
= 0;
5680 pSMB
->Reserved2
= 0;
5681 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
5682 InformationLevel
) - 4;
5683 offset
= param_offset
+ params
;
5684 pSMB
->InformationLevel
=
5685 cpu_to_le16(SMB_SET_FILE_EA
);
5688 (struct fealist
*) (((char *) &pSMB
->hdr
.Protocol
) +
5690 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
5691 pSMB
->DataOffset
= cpu_to_le16(offset
);
5692 pSMB
->SetupCount
= 1;
5693 pSMB
->Reserved3
= 0;
5694 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
5695 byte_count
= 3 /* pad */ + params
+ count
;
5696 pSMB
->DataCount
= cpu_to_le16(count
);
5697 parm_data
->list_len
= cpu_to_le32(count
);
5698 parm_data
->list
[0].EA_flags
= 0;
5699 /* we checked above that name len is less than 255 */
5700 parm_data
->list
[0].name_len
= (__u8
)name_len
;
5701 /* EA names are always ASCII */
5703 strncpy(parm_data
->list
[0].name
, ea_name
, name_len
);
5704 parm_data
->list
[0].name
[name_len
] = 0;
5705 parm_data
->list
[0].value_len
= cpu_to_le16(ea_value_len
);
5706 /* caller ensures that ea_value_len is less than 64K but
5707 we need to ensure that it fits within the smb */
5709 /*BB add length check to see if it would fit in
5710 negotiated SMB buffer size BB */
5711 /* if (ea_value_len > buffer_size - 512 (enough for header)) */
5713 memcpy(parm_data
->list
[0].name
+name_len
+1,
5714 ea_value
, ea_value_len
);
5716 pSMB
->TotalDataCount
= pSMB
->DataCount
;
5717 pSMB
->ParameterCount
= cpu_to_le16(params
);
5718 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
5719 pSMB
->Reserved4
= 0;
5720 pSMB
->hdr
.smb_buf_length
+= byte_count
;
5721 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
5722 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
5723 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
5725 cFYI(1, "SetPathInfo (EA) returned %d", rc
);
5727 cifs_buf_release(pSMB
);