4 * Copyright (C) International Business Machines Corp., 2002,2009
5 * Author(s): Steve French (sfrench@us.ibm.com)
7 * Contains the routines for constructing the SMB PDUs themselves
9 * This library is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as published
11 * by the Free Software Foundation; either version 2.1 of the License, or
12 * (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
17 * the GNU Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 /* SMB/CIFS PDU handling routines here - except for leftovers in connect.c */
25 /* These are mostly routines that operate on a pathname, or on a tree id */
26 /* (mounted volume), but there are eight handle based routines which must be */
27 /* treated slightly differently for reconnection purposes since we never */
28 /* want to reuse a stale file handle and only the caller knows the file info */
31 #include <linux/kernel.h>
32 #include <linux/vfs.h>
33 #include <linux/posix_acl_xattr.h>
34 #include <asm/uaccess.h>
38 #include "cifsproto.h"
39 #include "cifs_unicode.h"
40 #include "cifs_debug.h"
42 #ifdef CONFIG_CIFS_POSIX
47 #ifdef CONFIG_CIFS_WEAK_PW_HASH
48 {LANMAN_PROT
, "\2LM1.2X002"},
49 {LANMAN2_PROT
, "\2LANMAN2.1"},
50 #endif /* weak password hashing for legacy clients */
51 {CIFS_PROT
, "\2NT LM 0.12"},
52 {POSIX_PROT
, "\2POSIX 2"},
60 #ifdef CONFIG_CIFS_WEAK_PW_HASH
61 {LANMAN_PROT
, "\2LM1.2X002"},
62 {LANMAN2_PROT
, "\2LANMAN2.1"},
63 #endif /* weak password hashing for legacy clients */
64 {CIFS_PROT
, "\2NT LM 0.12"},
69 /* define the number of elements in the cifs dialect array */
70 #ifdef CONFIG_CIFS_POSIX
71 #ifdef CONFIG_CIFS_WEAK_PW_HASH
72 #define CIFS_NUM_PROT 4
74 #define CIFS_NUM_PROT 2
75 #endif /* CIFS_WEAK_PW_HASH */
77 #ifdef CONFIG_CIFS_WEAK_PW_HASH
78 #define CIFS_NUM_PROT 3
80 #define CIFS_NUM_PROT 1
81 #endif /* CONFIG_CIFS_WEAK_PW_HASH */
82 #endif /* CIFS_POSIX */
84 /* Mark as invalid, all open files on tree connections since they
85 were closed when session to server was lost */
86 static void mark_open_files_invalid(struct cifsTconInfo
*pTcon
)
88 struct cifsFileInfo
*open_file
= NULL
;
89 struct list_head
*tmp
;
90 struct list_head
*tmp1
;
92 /* list all files open on tree connection and mark them invalid */
93 write_lock(&GlobalSMBSeslock
);
94 list_for_each_safe(tmp
, tmp1
, &pTcon
->openFileList
) {
95 open_file
= list_entry(tmp
, struct cifsFileInfo
, tlist
);
96 open_file
->invalidHandle
= true;
97 open_file
->oplock_break_cancelled
= true;
99 write_unlock(&GlobalSMBSeslock
);
100 /* BB Add call to invalidate_inodes(sb) for all superblocks mounted
104 /* reconnect the socket, tcon, and smb session if needed */
106 cifs_reconnect_tcon(struct cifsTconInfo
*tcon
, int smb_command
)
109 struct cifsSesInfo
*ses
;
110 struct TCP_Server_Info
*server
;
111 struct nls_table
*nls_codepage
;
114 * SMBs NegProt, SessSetup, uLogoff do not have tcon yet so check for
115 * tcp and smb session status done differently for those three - in the
122 server
= ses
->server
;
125 * only tree disconnect, open, and write, (and ulogoff which does not
126 * have tcon) are allowed as we start force umount
128 if (tcon
->tidStatus
== CifsExiting
) {
129 if (smb_command
!= SMB_COM_WRITE_ANDX
&&
130 smb_command
!= SMB_COM_OPEN_ANDX
&&
131 smb_command
!= SMB_COM_TREE_DISCONNECT
) {
132 cFYI(1, ("can not send cmd %d while umounting",
138 if (ses
->status
== CifsExiting
)
142 * Give demultiplex thread up to 10 seconds to reconnect, should be
143 * greater than cifs socket timeout which is 7 seconds
145 while (server
->tcpStatus
== CifsNeedReconnect
) {
146 wait_event_interruptible_timeout(server
->response_q
,
147 (server
->tcpStatus
== CifsGood
), 10 * HZ
);
149 /* is TCP session is reestablished now ?*/
150 if (server
->tcpStatus
!= CifsNeedReconnect
)
154 * on "soft" mounts we wait once. Hard mounts keep
155 * retrying until process is killed or server comes
158 if (!tcon
->retry
|| ses
->status
== CifsExiting
) {
159 cFYI(1, ("gave up waiting on reconnect in smb_init"));
164 if (!ses
->need_reconnect
&& !tcon
->need_reconnect
)
167 nls_codepage
= load_nls_default();
170 * need to prevent multiple threads trying to simultaneously
171 * reconnect the same SMB session
174 if (ses
->need_reconnect
)
175 rc
= cifs_setup_session(0, ses
, nls_codepage
);
177 /* do we need to reconnect tcon? */
178 if (rc
|| !tcon
->need_reconnect
) {
183 mark_open_files_invalid(tcon
);
184 rc
= CIFSTCon(0, ses
, tcon
->treeName
, tcon
, nls_codepage
);
186 cFYI(1, ("reconnect tcon rc = %d", rc
));
192 * FIXME: check if wsize needs updated due to negotiated smb buffer
195 atomic_inc(&tconInfoReconnectCount
);
197 /* tell server Unix caps we support */
198 if (ses
->capabilities
& CAP_UNIX
)
199 reset_cifs_unix_caps(0, tcon
, NULL
, NULL
);
202 * Removed call to reopen open files here. It is safer (and faster) to
203 * reopen files one at a time as needed in read and write.
205 * FIXME: what about file locks? don't we need to reclaim them ASAP?
210 * Check if handle based operation so we know whether we can continue
211 * or not without returning to caller to reset file handle
213 switch (smb_command
) {
214 case SMB_COM_READ_ANDX
:
215 case SMB_COM_WRITE_ANDX
:
217 case SMB_COM_FIND_CLOSE2
:
218 case SMB_COM_LOCKING_ANDX
:
222 unload_nls(nls_codepage
);
226 /* Allocate and return pointer to an SMB request buffer, and set basic
227 SMB information in the SMB header. If the return code is zero, this
228 function must have filled in request_buf pointer */
230 small_smb_init(int smb_command
, int wct
, struct cifsTconInfo
*tcon
,
235 rc
= cifs_reconnect_tcon(tcon
, smb_command
);
239 *request_buf
= cifs_small_buf_get();
240 if (*request_buf
== NULL
) {
241 /* BB should we add a retry in here if not a writepage? */
245 header_assemble((struct smb_hdr
*) *request_buf
, smb_command
,
249 cifs_stats_inc(&tcon
->num_smbs_sent
);
255 small_smb_init_no_tc(const int smb_command
, const int wct
,
256 struct cifsSesInfo
*ses
, void **request_buf
)
259 struct smb_hdr
*buffer
;
261 rc
= small_smb_init(smb_command
, wct
, NULL
, request_buf
);
265 buffer
= (struct smb_hdr
*)*request_buf
;
266 buffer
->Mid
= GetNextMid(ses
->server
);
267 if (ses
->capabilities
& CAP_UNICODE
)
268 buffer
->Flags2
|= SMBFLG2_UNICODE
;
269 if (ses
->capabilities
& CAP_STATUS32
)
270 buffer
->Flags2
|= SMBFLG2_ERR_STATUS
;
272 /* uid, tid can stay at zero as set in header assemble */
274 /* BB add support for turning on the signing when
275 this function is used after 1st of session setup requests */
280 /* If the return code is zero, this function must fill in request_buf pointer */
282 smb_init(int smb_command
, int wct
, struct cifsTconInfo
*tcon
,
283 void **request_buf
/* returned */ ,
284 void **response_buf
/* returned */ )
288 rc
= cifs_reconnect_tcon(tcon
, smb_command
);
292 *request_buf
= cifs_buf_get();
293 if (*request_buf
== NULL
) {
294 /* BB should we add a retry in here if not a writepage? */
297 /* Although the original thought was we needed the response buf for */
298 /* potential retries of smb operations it turns out we can determine */
299 /* from the mid flags when the request buffer can be resent without */
300 /* having to use a second distinct buffer for the response */
302 *response_buf
= *request_buf
;
304 header_assemble((struct smb_hdr
*) *request_buf
, smb_command
, tcon
,
308 cifs_stats_inc(&tcon
->num_smbs_sent
);
313 static int validate_t2(struct smb_t2_rsp
*pSMB
)
319 /* check for plausible wct, bcc and t2 data and parm sizes */
320 /* check for parm and data offset going beyond end of smb */
321 if (pSMB
->hdr
.WordCount
>= 10) {
322 if ((le16_to_cpu(pSMB
->t2_rsp
.ParameterOffset
) <= 1024) &&
323 (le16_to_cpu(pSMB
->t2_rsp
.DataOffset
) <= 1024)) {
324 /* check that bcc is at least as big as parms + data */
325 /* check that bcc is less than negotiated smb buffer */
326 total_size
= le16_to_cpu(pSMB
->t2_rsp
.ParameterCount
);
327 if (total_size
< 512) {
329 le16_to_cpu(pSMB
->t2_rsp
.DataCount
);
330 /* BCC le converted in SendReceive */
331 pBCC
= (pSMB
->hdr
.WordCount
* 2) +
332 sizeof(struct smb_hdr
) +
334 if ((total_size
<= (*(u16
*)pBCC
)) &&
336 CIFSMaxBufSize
+MAX_CIFS_HDR_SIZE
)) {
342 cifs_dump_mem("Invalid transact2 SMB: ", (char *)pSMB
,
343 sizeof(struct smb_t2_rsp
) + 16);
347 CIFSSMBNegotiate(unsigned int xid
, struct cifsSesInfo
*ses
)
350 NEGOTIATE_RSP
*pSMBr
;
354 struct TCP_Server_Info
*server
;
356 unsigned int secFlags
;
360 server
= ses
->server
;
365 rc
= smb_init(SMB_COM_NEGOTIATE
, 0, NULL
/* no tcon yet */ ,
366 (void **) &pSMB
, (void **) &pSMBr
);
370 /* if any of auth flags (ie not sign or seal) are overriden use them */
371 if (ses
->overrideSecFlg
& (~(CIFSSEC_MUST_SIGN
| CIFSSEC_MUST_SEAL
)))
372 secFlags
= ses
->overrideSecFlg
; /* BB FIXME fix sign flags? */
373 else /* if override flags set only sign/seal OR them with global auth */
374 secFlags
= extended_security
| ses
->overrideSecFlg
;
376 cFYI(1, ("secFlags 0x%x", secFlags
));
378 pSMB
->hdr
.Mid
= GetNextMid(server
);
379 pSMB
->hdr
.Flags2
|= (SMBFLG2_UNICODE
| SMBFLG2_ERR_STATUS
);
381 if ((secFlags
& CIFSSEC_MUST_KRB5
) == CIFSSEC_MUST_KRB5
)
382 pSMB
->hdr
.Flags2
|= SMBFLG2_EXT_SEC
;
383 else if ((secFlags
& CIFSSEC_AUTH_MASK
) == CIFSSEC_MAY_KRB5
) {
384 cFYI(1, ("Kerberos only mechanism, enable extended security"));
385 pSMB
->hdr
.Flags2
|= SMBFLG2_EXT_SEC
;
387 #ifdef CONFIG_CIFS_EXPERIMENTAL
388 else if ((secFlags
& CIFSSEC_MUST_NTLMSSP
) == CIFSSEC_MUST_NTLMSSP
)
389 pSMB
->hdr
.Flags2
|= SMBFLG2_EXT_SEC
;
390 else if ((secFlags
& CIFSSEC_AUTH_MASK
) == CIFSSEC_MAY_NTLMSSP
) {
391 cFYI(1, ("NTLMSSP only mechanism, enable extended security"));
392 pSMB
->hdr
.Flags2
|= SMBFLG2_EXT_SEC
;
397 for (i
= 0; i
< CIFS_NUM_PROT
; i
++) {
398 strncpy(pSMB
->DialectsArray
+count
, protocols
[i
].name
, 16);
399 count
+= strlen(protocols
[i
].name
) + 1;
400 /* null at end of source and target buffers anyway */
402 pSMB
->hdr
.smb_buf_length
+= count
;
403 pSMB
->ByteCount
= cpu_to_le16(count
);
405 rc
= SendReceive(xid
, ses
, (struct smb_hdr
*) pSMB
,
406 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
410 dialect
= le16_to_cpu(pSMBr
->DialectIndex
);
411 cFYI(1, ("Dialect: %d", dialect
));
412 /* Check wct = 1 error case */
413 if ((pSMBr
->hdr
.WordCount
< 13) || (dialect
== BAD_PROT
)) {
414 /* core returns wct = 1, but we do not ask for core - otherwise
415 small wct just comes when dialect index is -1 indicating we
416 could not negotiate a common dialect */
419 #ifdef CONFIG_CIFS_WEAK_PW_HASH
420 } else if ((pSMBr
->hdr
.WordCount
== 13)
421 && ((dialect
== LANMAN_PROT
)
422 || (dialect
== LANMAN2_PROT
))) {
424 struct lanman_neg_rsp
*rsp
= (struct lanman_neg_rsp
*)pSMBr
;
426 if ((secFlags
& CIFSSEC_MAY_LANMAN
) ||
427 (secFlags
& CIFSSEC_MAY_PLNTXT
))
428 server
->secType
= LANMAN
;
430 cERROR(1, ("mount failed weak security disabled"
431 " in /proc/fs/cifs/SecurityFlags"));
435 server
->secMode
= (__u8
)le16_to_cpu(rsp
->SecurityMode
);
436 server
->maxReq
= le16_to_cpu(rsp
->MaxMpxCount
);
437 server
->maxBuf
= min((__u32
)le16_to_cpu(rsp
->MaxBufSize
),
438 (__u32
)CIFSMaxBufSize
+ MAX_CIFS_HDR_SIZE
);
439 server
->max_vcs
= le16_to_cpu(rsp
->MaxNumberVcs
);
440 GETU32(server
->sessid
) = le32_to_cpu(rsp
->SessionKey
);
441 /* even though we do not use raw we might as well set this
442 accurately, in case we ever find a need for it */
443 if ((le16_to_cpu(rsp
->RawMode
) & RAW_ENABLE
) == RAW_ENABLE
) {
444 server
->max_rw
= 0xFF00;
445 server
->capabilities
= CAP_MPX_MODE
| CAP_RAW_MODE
;
447 server
->max_rw
= 0;/* do not need to use raw anyway */
448 server
->capabilities
= CAP_MPX_MODE
;
450 tmp
= (__s16
)le16_to_cpu(rsp
->ServerTimeZone
);
452 /* OS/2 often does not set timezone therefore
453 * we must use server time to calc time zone.
454 * Could deviate slightly from the right zone.
455 * Smallest defined timezone difference is 15 minutes
456 * (i.e. Nepal). Rounding up/down is done to match
459 int val
, seconds
, remain
, result
;
460 struct timespec ts
, utc
;
462 ts
= cnvrtDosUnixTm(rsp
->SrvTime
.Date
,
463 rsp
->SrvTime
.Time
, 0);
464 cFYI(1, ("SrvTime %d sec since 1970 (utc: %d) diff: %d",
465 (int)ts
.tv_sec
, (int)utc
.tv_sec
,
466 (int)(utc
.tv_sec
- ts
.tv_sec
)));
467 val
= (int)(utc
.tv_sec
- ts
.tv_sec
);
469 result
= (seconds
/ MIN_TZ_ADJ
) * MIN_TZ_ADJ
;
470 remain
= seconds
% MIN_TZ_ADJ
;
471 if (remain
>= (MIN_TZ_ADJ
/ 2))
472 result
+= MIN_TZ_ADJ
;
475 server
->timeAdj
= result
;
477 server
->timeAdj
= (int)tmp
;
478 server
->timeAdj
*= 60; /* also in seconds */
480 cFYI(1, ("server->timeAdj: %d seconds", server
->timeAdj
));
483 /* BB get server time for time conversions and add
484 code to use it and timezone since this is not UTC */
486 if (rsp
->EncryptionKeyLength
==
487 cpu_to_le16(CIFS_CRYPTO_KEY_SIZE
)) {
488 memcpy(server
->cryptKey
, rsp
->EncryptionKey
,
489 CIFS_CRYPTO_KEY_SIZE
);
490 } else if (server
->secMode
& SECMODE_PW_ENCRYPT
) {
491 rc
= -EIO
; /* need cryptkey unless plain text */
495 cFYI(1, ("LANMAN negotiated"));
496 /* we will not end up setting signing flags - as no signing
497 was in LANMAN and server did not return the flags on */
499 #else /* weak security disabled */
500 } else if (pSMBr
->hdr
.WordCount
== 13) {
501 cERROR(1, ("mount failed, cifs module not built "
502 "with CIFS_WEAK_PW_HASH support"));
504 #endif /* WEAK_PW_HASH */
506 } else if (pSMBr
->hdr
.WordCount
!= 17) {
511 /* else wct == 17 NTLM */
512 server
->secMode
= pSMBr
->SecurityMode
;
513 if ((server
->secMode
& SECMODE_USER
) == 0)
514 cFYI(1, ("share mode security"));
516 if ((server
->secMode
& SECMODE_PW_ENCRYPT
) == 0)
517 #ifdef CONFIG_CIFS_WEAK_PW_HASH
518 if ((secFlags
& CIFSSEC_MAY_PLNTXT
) == 0)
519 #endif /* CIFS_WEAK_PW_HASH */
520 cERROR(1, ("Server requests plain text password"
521 " but client support disabled"));
523 if ((secFlags
& CIFSSEC_MUST_NTLMV2
) == CIFSSEC_MUST_NTLMV2
)
524 server
->secType
= NTLMv2
;
525 else if (secFlags
& CIFSSEC_MAY_NTLM
)
526 server
->secType
= NTLM
;
527 else if (secFlags
& CIFSSEC_MAY_NTLMV2
)
528 server
->secType
= NTLMv2
;
529 else if (secFlags
& CIFSSEC_MAY_KRB5
)
530 server
->secType
= Kerberos
;
531 else if (secFlags
& CIFSSEC_MAY_NTLMSSP
)
532 server
->secType
= RawNTLMSSP
;
533 else if (secFlags
& CIFSSEC_MAY_LANMAN
)
534 server
->secType
= LANMAN
;
535 /* #ifdef CONFIG_CIFS_EXPERIMENTAL
536 else if (secFlags & CIFSSEC_MAY_PLNTXT)
541 cERROR(1, ("Invalid security type"));
544 /* else ... any others ...? */
546 /* one byte, so no need to convert this or EncryptionKeyLen from
548 server
->maxReq
= le16_to_cpu(pSMBr
->MaxMpxCount
);
549 /* probably no need to store and check maxvcs */
550 server
->maxBuf
= min(le32_to_cpu(pSMBr
->MaxBufferSize
),
551 (__u32
) CIFSMaxBufSize
+ MAX_CIFS_HDR_SIZE
);
552 server
->max_rw
= le32_to_cpu(pSMBr
->MaxRawSize
);
553 cFYI(DBG2
, ("Max buf = %d", ses
->server
->maxBuf
));
554 GETU32(ses
->server
->sessid
) = le32_to_cpu(pSMBr
->SessionKey
);
555 server
->capabilities
= le32_to_cpu(pSMBr
->Capabilities
);
556 server
->timeAdj
= (int)(__s16
)le16_to_cpu(pSMBr
->ServerTimeZone
);
557 server
->timeAdj
*= 60;
558 if (pSMBr
->EncryptionKeyLength
== CIFS_CRYPTO_KEY_SIZE
) {
559 memcpy(server
->cryptKey
, pSMBr
->u
.EncryptionKey
,
560 CIFS_CRYPTO_KEY_SIZE
);
561 } else if ((pSMBr
->hdr
.Flags2
& SMBFLG2_EXT_SEC
)
562 && (pSMBr
->EncryptionKeyLength
== 0)) {
563 /* decode security blob */
564 } else if (server
->secMode
& SECMODE_PW_ENCRYPT
) {
565 rc
= -EIO
; /* no crypt key only if plain text pwd */
569 /* BB might be helpful to save off the domain of server here */
571 if ((pSMBr
->hdr
.Flags2
& SMBFLG2_EXT_SEC
) &&
572 (server
->capabilities
& CAP_EXTENDED_SECURITY
)) {
573 count
= pSMBr
->ByteCount
;
578 read_lock(&cifs_tcp_ses_lock
);
579 if (server
->srv_count
> 1) {
580 read_unlock(&cifs_tcp_ses_lock
);
581 if (memcmp(server
->server_GUID
,
582 pSMBr
->u
.extended_response
.
584 cFYI(1, ("server UID changed"));
585 memcpy(server
->server_GUID
,
586 pSMBr
->u
.extended_response
.GUID
,
590 read_unlock(&cifs_tcp_ses_lock
);
591 memcpy(server
->server_GUID
,
592 pSMBr
->u
.extended_response
.GUID
, 16);
596 server
->secType
= RawNTLMSSP
;
598 rc
= decode_negTokenInit(pSMBr
->u
.extended_response
.
608 server
->capabilities
&= ~CAP_EXTENDED_SECURITY
;
610 #ifdef CONFIG_CIFS_WEAK_PW_HASH
613 if ((secFlags
& CIFSSEC_MAY_SIGN
) == 0) {
614 /* MUST_SIGN already includes the MAY_SIGN FLAG
615 so if this is zero it means that signing is disabled */
616 cFYI(1, ("Signing disabled"));
617 if (server
->secMode
& SECMODE_SIGN_REQUIRED
) {
618 cERROR(1, ("Server requires "
619 "packet signing to be enabled in "
620 "/proc/fs/cifs/SecurityFlags."));
624 ~(SECMODE_SIGN_ENABLED
| SECMODE_SIGN_REQUIRED
);
625 } else if ((secFlags
& CIFSSEC_MUST_SIGN
) == CIFSSEC_MUST_SIGN
) {
626 /* signing required */
627 cFYI(1, ("Must sign - secFlags 0x%x", secFlags
));
628 if ((server
->secMode
&
629 (SECMODE_SIGN_ENABLED
| SECMODE_SIGN_REQUIRED
)) == 0) {
631 ("signing required but server lacks support"));
634 server
->secMode
|= SECMODE_SIGN_REQUIRED
;
636 /* signing optional ie CIFSSEC_MAY_SIGN */
637 if ((server
->secMode
& SECMODE_SIGN_REQUIRED
) == 0)
639 ~(SECMODE_SIGN_ENABLED
| SECMODE_SIGN_REQUIRED
);
643 cifs_buf_release(pSMB
);
645 cFYI(1, ("negprot rc %d", rc
));
650 CIFSSMBTDis(const int xid
, struct cifsTconInfo
*tcon
)
652 struct smb_hdr
*smb_buffer
;
655 cFYI(1, ("In tree disconnect"));
657 /* BB: do we need to check this? These should never be NULL. */
658 if ((tcon
->ses
== NULL
) || (tcon
->ses
->server
== NULL
))
662 * No need to return error on this operation if tid invalidated and
663 * closed on server already e.g. due to tcp session crashing. Also,
664 * the tcon is no longer on the list, so no need to take lock before
667 if ((tcon
->need_reconnect
) || (tcon
->ses
->need_reconnect
))
670 rc
= small_smb_init(SMB_COM_TREE_DISCONNECT
, 0, tcon
,
671 (void **)&smb_buffer
);
675 rc
= SendReceiveNoRsp(xid
, tcon
->ses
, smb_buffer
, 0);
677 cFYI(1, ("Tree disconnect failed %d", rc
));
679 /* No need to return error on this operation if tid invalidated and
680 closed on server already e.g. due to tcp session crashing */
688 CIFSSMBLogoff(const int xid
, struct cifsSesInfo
*ses
)
690 LOGOFF_ANDX_REQ
*pSMB
;
693 cFYI(1, ("In SMBLogoff for session disconnect"));
696 * BB: do we need to check validity of ses and server? They should
697 * always be valid since we have an active reference. If not, that
698 * should probably be a BUG()
700 if (!ses
|| !ses
->server
)
704 if (ses
->need_reconnect
)
705 goto session_already_dead
; /* no need to send SMBlogoff if uid
706 already closed due to reconnect */
707 rc
= small_smb_init(SMB_COM_LOGOFF_ANDX
, 2, NULL
, (void **)&pSMB
);
713 pSMB
->hdr
.Mid
= GetNextMid(ses
->server
);
715 if (ses
->server
->secMode
&
716 (SECMODE_SIGN_REQUIRED
| SECMODE_SIGN_ENABLED
))
717 pSMB
->hdr
.Flags2
|= SMBFLG2_SECURITY_SIGNATURE
;
719 pSMB
->hdr
.Uid
= ses
->Suid
;
721 pSMB
->AndXCommand
= 0xFF;
722 rc
= SendReceiveNoRsp(xid
, ses
, (struct smb_hdr
*) pSMB
, 0);
723 session_already_dead
:
726 /* if session dead then we do not need to do ulogoff,
727 since server closed smb session, no sense reporting
735 CIFSPOSIXDelFile(const int xid
, struct cifsTconInfo
*tcon
, const char *fileName
,
736 __u16 type
, const struct nls_table
*nls_codepage
, int remap
)
738 TRANSACTION2_SPI_REQ
*pSMB
= NULL
;
739 TRANSACTION2_SPI_RSP
*pSMBr
= NULL
;
740 struct unlink_psx_rq
*pRqD
;
743 int bytes_returned
= 0;
744 __u16 params
, param_offset
, offset
, byte_count
;
746 cFYI(1, ("In POSIX delete"));
748 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
753 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
755 cifsConvertToUCS((__le16
*) pSMB
->FileName
, fileName
,
756 PATH_MAX
, nls_codepage
, remap
);
757 name_len
++; /* trailing null */
759 } else { /* BB add path length overrun check */
760 name_len
= strnlen(fileName
, PATH_MAX
);
761 name_len
++; /* trailing null */
762 strncpy(pSMB
->FileName
, fileName
, name_len
);
765 params
= 6 + name_len
;
766 pSMB
->MaxParameterCount
= cpu_to_le16(2);
767 pSMB
->MaxDataCount
= 0; /* BB double check this with jra */
768 pSMB
->MaxSetupCount
= 0;
773 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
774 InformationLevel
) - 4;
775 offset
= param_offset
+ params
;
777 /* Setup pointer to Request Data (inode type) */
778 pRqD
= (struct unlink_psx_rq
*)(((char *)&pSMB
->hdr
.Protocol
) + offset
);
779 pRqD
->type
= cpu_to_le16(type
);
780 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
781 pSMB
->DataOffset
= cpu_to_le16(offset
);
782 pSMB
->SetupCount
= 1;
784 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
785 byte_count
= 3 /* pad */ + params
+ sizeof(struct unlink_psx_rq
);
787 pSMB
->DataCount
= cpu_to_le16(sizeof(struct unlink_psx_rq
));
788 pSMB
->TotalDataCount
= cpu_to_le16(sizeof(struct unlink_psx_rq
));
789 pSMB
->ParameterCount
= cpu_to_le16(params
);
790 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
791 pSMB
->InformationLevel
= cpu_to_le16(SMB_POSIX_UNLINK
);
793 pSMB
->hdr
.smb_buf_length
+= byte_count
;
794 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
795 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
796 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
798 cFYI(1, ("Posix delete returned %d", rc
));
799 cifs_buf_release(pSMB
);
801 cifs_stats_inc(&tcon
->num_deletes
);
810 CIFSSMBDelFile(const int xid
, struct cifsTconInfo
*tcon
, const char *fileName
,
811 const struct nls_table
*nls_codepage
, int remap
)
813 DELETE_FILE_REQ
*pSMB
= NULL
;
814 DELETE_FILE_RSP
*pSMBr
= NULL
;
820 rc
= smb_init(SMB_COM_DELETE
, 1, tcon
, (void **) &pSMB
,
825 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
827 cifsConvertToUCS((__le16
*) pSMB
->fileName
, fileName
,
828 PATH_MAX
, nls_codepage
, remap
);
829 name_len
++; /* trailing null */
831 } else { /* BB improve check for buffer overruns BB */
832 name_len
= strnlen(fileName
, PATH_MAX
);
833 name_len
++; /* trailing null */
834 strncpy(pSMB
->fileName
, fileName
, name_len
);
836 pSMB
->SearchAttributes
=
837 cpu_to_le16(ATTR_READONLY
| ATTR_HIDDEN
| ATTR_SYSTEM
);
838 pSMB
->BufferFormat
= 0x04;
839 pSMB
->hdr
.smb_buf_length
+= name_len
+ 1;
840 pSMB
->ByteCount
= cpu_to_le16(name_len
+ 1);
841 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
842 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
843 cifs_stats_inc(&tcon
->num_deletes
);
845 cFYI(1, ("Error in RMFile = %d", rc
));
847 cifs_buf_release(pSMB
);
855 CIFSSMBRmDir(const int xid
, struct cifsTconInfo
*tcon
, const char *dirName
,
856 const struct nls_table
*nls_codepage
, int remap
)
858 DELETE_DIRECTORY_REQ
*pSMB
= NULL
;
859 DELETE_DIRECTORY_RSP
*pSMBr
= NULL
;
864 cFYI(1, ("In CIFSSMBRmDir"));
866 rc
= smb_init(SMB_COM_DELETE_DIRECTORY
, 0, tcon
, (void **) &pSMB
,
871 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
872 name_len
= cifsConvertToUCS((__le16
*) pSMB
->DirName
, dirName
,
873 PATH_MAX
, nls_codepage
, remap
);
874 name_len
++; /* trailing null */
876 } else { /* BB improve check for buffer overruns BB */
877 name_len
= strnlen(dirName
, PATH_MAX
);
878 name_len
++; /* trailing null */
879 strncpy(pSMB
->DirName
, dirName
, name_len
);
882 pSMB
->BufferFormat
= 0x04;
883 pSMB
->hdr
.smb_buf_length
+= name_len
+ 1;
884 pSMB
->ByteCount
= cpu_to_le16(name_len
+ 1);
885 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
886 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
887 cifs_stats_inc(&tcon
->num_rmdirs
);
889 cFYI(1, ("Error in RMDir = %d", rc
));
891 cifs_buf_release(pSMB
);
898 CIFSSMBMkDir(const int xid
, struct cifsTconInfo
*tcon
,
899 const char *name
, const struct nls_table
*nls_codepage
, int remap
)
902 CREATE_DIRECTORY_REQ
*pSMB
= NULL
;
903 CREATE_DIRECTORY_RSP
*pSMBr
= NULL
;
907 cFYI(1, ("In CIFSSMBMkDir"));
909 rc
= smb_init(SMB_COM_CREATE_DIRECTORY
, 0, tcon
, (void **) &pSMB
,
914 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
915 name_len
= cifsConvertToUCS((__le16
*) pSMB
->DirName
, name
,
916 PATH_MAX
, nls_codepage
, remap
);
917 name_len
++; /* trailing null */
919 } else { /* BB improve check for buffer overruns BB */
920 name_len
= strnlen(name
, PATH_MAX
);
921 name_len
++; /* trailing null */
922 strncpy(pSMB
->DirName
, name
, name_len
);
925 pSMB
->BufferFormat
= 0x04;
926 pSMB
->hdr
.smb_buf_length
+= name_len
+ 1;
927 pSMB
->ByteCount
= cpu_to_le16(name_len
+ 1);
928 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
929 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
930 cifs_stats_inc(&tcon
->num_mkdirs
);
932 cFYI(1, ("Error in Mkdir = %d", rc
));
934 cifs_buf_release(pSMB
);
941 CIFSPOSIXCreate(const int xid
, struct cifsTconInfo
*tcon
, __u32 posix_flags
,
942 __u64 mode
, __u16
*netfid
, FILE_UNIX_BASIC_INFO
*pRetData
,
943 __u32
*pOplock
, const char *name
,
944 const struct nls_table
*nls_codepage
, int remap
)
946 TRANSACTION2_SPI_REQ
*pSMB
= NULL
;
947 TRANSACTION2_SPI_RSP
*pSMBr
= NULL
;
950 int bytes_returned
= 0;
951 __u16 params
, param_offset
, offset
, byte_count
, count
;
953 OPEN_PSX_RSP
*psx_rsp
;
955 cFYI(1, ("In POSIX Create"));
957 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
962 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
964 cifsConvertToUCS((__le16
*) pSMB
->FileName
, name
,
965 PATH_MAX
, nls_codepage
, remap
);
966 name_len
++; /* trailing null */
968 } else { /* BB improve the check for buffer overruns BB */
969 name_len
= strnlen(name
, PATH_MAX
);
970 name_len
++; /* trailing null */
971 strncpy(pSMB
->FileName
, name
, name_len
);
974 params
= 6 + name_len
;
975 count
= sizeof(OPEN_PSX_REQ
);
976 pSMB
->MaxParameterCount
= cpu_to_le16(2);
977 pSMB
->MaxDataCount
= cpu_to_le16(1000); /* large enough */
978 pSMB
->MaxSetupCount
= 0;
983 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
984 InformationLevel
) - 4;
985 offset
= param_offset
+ params
;
986 pdata
= (OPEN_PSX_REQ
*)(((char *)&pSMB
->hdr
.Protocol
) + offset
);
987 pdata
->Level
= cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC
);
988 pdata
->Permissions
= cpu_to_le64(mode
);
989 pdata
->PosixOpenFlags
= cpu_to_le32(posix_flags
);
990 pdata
->OpenFlags
= cpu_to_le32(*pOplock
);
991 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
992 pSMB
->DataOffset
= cpu_to_le16(offset
);
993 pSMB
->SetupCount
= 1;
995 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
996 byte_count
= 3 /* pad */ + params
+ count
;
998 pSMB
->DataCount
= cpu_to_le16(count
);
999 pSMB
->ParameterCount
= cpu_to_le16(params
);
1000 pSMB
->TotalDataCount
= pSMB
->DataCount
;
1001 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
1002 pSMB
->InformationLevel
= cpu_to_le16(SMB_POSIX_OPEN
);
1003 pSMB
->Reserved4
= 0;
1004 pSMB
->hdr
.smb_buf_length
+= byte_count
;
1005 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
1006 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
1007 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
1009 cFYI(1, ("Posix create returned %d", rc
));
1010 goto psx_create_err
;
1013 cFYI(1, ("copying inode info"));
1014 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
1016 if (rc
|| (pSMBr
->ByteCount
< sizeof(OPEN_PSX_RSP
))) {
1017 rc
= -EIO
; /* bad smb */
1018 goto psx_create_err
;
1021 /* copy return information to pRetData */
1022 psx_rsp
= (OPEN_PSX_RSP
*)((char *) &pSMBr
->hdr
.Protocol
1023 + le16_to_cpu(pSMBr
->t2
.DataOffset
));
1025 *pOplock
= le16_to_cpu(psx_rsp
->OplockFlags
);
1027 *netfid
= psx_rsp
->Fid
; /* cifs fid stays in le */
1028 /* Let caller know file was created so we can set the mode. */
1029 /* Do we care about the CreateAction in any other cases? */
1030 if (cpu_to_le32(FILE_CREATE
) == psx_rsp
->CreateAction
)
1031 *pOplock
|= CIFS_CREATE_ACTION
;
1032 /* check to make sure response data is there */
1033 if (psx_rsp
->ReturnedLevel
!= cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC
)) {
1034 pRetData
->Type
= cpu_to_le32(-1); /* unknown */
1035 cFYI(DBG2
, ("unknown type"));
1037 if (pSMBr
->ByteCount
< sizeof(OPEN_PSX_RSP
)
1038 + sizeof(FILE_UNIX_BASIC_INFO
)) {
1039 cERROR(1, ("Open response data too small"));
1040 pRetData
->Type
= cpu_to_le32(-1);
1041 goto psx_create_err
;
1043 memcpy((char *) pRetData
,
1044 (char *)psx_rsp
+ sizeof(OPEN_PSX_RSP
),
1045 sizeof(FILE_UNIX_BASIC_INFO
));
1049 cifs_buf_release(pSMB
);
1051 if (posix_flags
& SMB_O_DIRECTORY
)
1052 cifs_stats_inc(&tcon
->num_posixmkdirs
);
1054 cifs_stats_inc(&tcon
->num_posixopens
);
1062 static __u16
convert_disposition(int disposition
)
1066 switch (disposition
) {
1067 case FILE_SUPERSEDE
:
1068 ofun
= SMBOPEN_OCREATE
| SMBOPEN_OTRUNC
;
1071 ofun
= SMBOPEN_OAPPEND
;
1074 ofun
= SMBOPEN_OCREATE
;
1077 ofun
= SMBOPEN_OCREATE
| SMBOPEN_OAPPEND
;
1079 case FILE_OVERWRITE
:
1080 ofun
= SMBOPEN_OTRUNC
;
1082 case FILE_OVERWRITE_IF
:
1083 ofun
= SMBOPEN_OCREATE
| SMBOPEN_OTRUNC
;
1086 cFYI(1, ("unknown disposition %d", disposition
));
1087 ofun
= SMBOPEN_OAPPEND
; /* regular open */
1093 access_flags_to_smbopen_mode(const int access_flags
)
1095 int masked_flags
= access_flags
& (GENERIC_READ
| GENERIC_WRITE
);
1097 if (masked_flags
== GENERIC_READ
)
1098 return SMBOPEN_READ
;
1099 else if (masked_flags
== GENERIC_WRITE
)
1100 return SMBOPEN_WRITE
;
1102 /* just go for read/write */
1103 return SMBOPEN_READWRITE
;
1107 SMBLegacyOpen(const int xid
, struct cifsTconInfo
*tcon
,
1108 const char *fileName
, const int openDisposition
,
1109 const int access_flags
, const int create_options
, __u16
*netfid
,
1110 int *pOplock
, FILE_ALL_INFO
*pfile_info
,
1111 const struct nls_table
*nls_codepage
, int remap
)
1114 OPENX_REQ
*pSMB
= NULL
;
1115 OPENX_RSP
*pSMBr
= NULL
;
1121 rc
= smb_init(SMB_COM_OPEN_ANDX
, 15, tcon
, (void **) &pSMB
,
1126 pSMB
->AndXCommand
= 0xFF; /* none */
1128 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
1129 count
= 1; /* account for one byte pad to word boundary */
1131 cifsConvertToUCS((__le16
*) (pSMB
->fileName
+ 1),
1132 fileName
, PATH_MAX
, nls_codepage
, remap
);
1133 name_len
++; /* trailing null */
1135 } else { /* BB improve check for buffer overruns BB */
1136 count
= 0; /* no pad */
1137 name_len
= strnlen(fileName
, PATH_MAX
);
1138 name_len
++; /* trailing null */
1139 strncpy(pSMB
->fileName
, fileName
, name_len
);
1141 if (*pOplock
& REQ_OPLOCK
)
1142 pSMB
->OpenFlags
= cpu_to_le16(REQ_OPLOCK
);
1143 else if (*pOplock
& REQ_BATCHOPLOCK
)
1144 pSMB
->OpenFlags
= cpu_to_le16(REQ_BATCHOPLOCK
);
1146 pSMB
->OpenFlags
|= cpu_to_le16(REQ_MORE_INFO
);
1147 pSMB
->Mode
= cpu_to_le16(access_flags_to_smbopen_mode(access_flags
));
1148 pSMB
->Mode
|= cpu_to_le16(0x40); /* deny none */
1149 /* set file as system file if special file such
1150 as fifo and server expecting SFU style and
1151 no Unix extensions */
1153 if (create_options
& CREATE_OPTION_SPECIAL
)
1154 pSMB
->FileAttributes
= cpu_to_le16(ATTR_SYSTEM
);
1155 else /* BB FIXME BB */
1156 pSMB
->FileAttributes
= cpu_to_le16(0/*ATTR_NORMAL*/);
1158 if (create_options
& CREATE_OPTION_READONLY
)
1159 pSMB
->FileAttributes
|= cpu_to_le16(ATTR_READONLY
);
1162 /* pSMB->CreateOptions = cpu_to_le32(create_options &
1163 CREATE_OPTIONS_MASK); */
1164 /* BB FIXME END BB */
1166 pSMB
->Sattr
= cpu_to_le16(ATTR_HIDDEN
| ATTR_SYSTEM
| ATTR_DIRECTORY
);
1167 pSMB
->OpenFunction
= cpu_to_le16(convert_disposition(openDisposition
));
1169 pSMB
->hdr
.smb_buf_length
+= count
;
1171 pSMB
->ByteCount
= cpu_to_le16(count
);
1172 /* long_op set to 1 to allow for oplock break timeouts */
1173 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
1174 (struct smb_hdr
*)pSMBr
, &bytes_returned
, CIFS_LONG_OP
);
1175 cifs_stats_inc(&tcon
->num_opens
);
1177 cFYI(1, ("Error in Open = %d", rc
));
1179 /* BB verify if wct == 15 */
1181 /* *pOplock = pSMBr->OplockLevel; */ /* BB take from action field*/
1183 *netfid
= pSMBr
->Fid
; /* cifs fid stays in le */
1184 /* Let caller know file was created so we can set the mode. */
1185 /* Do we care about the CreateAction in any other cases? */
1187 /* if (cpu_to_le32(FILE_CREATE) == pSMBr->CreateAction)
1188 *pOplock |= CIFS_CREATE_ACTION; */
1192 pfile_info
->CreationTime
= 0; /* BB convert CreateTime*/
1193 pfile_info
->LastAccessTime
= 0; /* BB fixme */
1194 pfile_info
->LastWriteTime
= 0; /* BB fixme */
1195 pfile_info
->ChangeTime
= 0; /* BB fixme */
1196 pfile_info
->Attributes
=
1197 cpu_to_le32(le16_to_cpu(pSMBr
->FileAttributes
));
1198 /* the file_info buf is endian converted by caller */
1199 pfile_info
->AllocationSize
=
1200 cpu_to_le64(le32_to_cpu(pSMBr
->EndOfFile
));
1201 pfile_info
->EndOfFile
= pfile_info
->AllocationSize
;
1202 pfile_info
->NumberOfLinks
= cpu_to_le32(1);
1203 pfile_info
->DeletePending
= 0;
1207 cifs_buf_release(pSMB
);
1214 CIFSSMBOpen(const int xid
, struct cifsTconInfo
*tcon
,
1215 const char *fileName
, const int openDisposition
,
1216 const int access_flags
, const int create_options
, __u16
*netfid
,
1217 int *pOplock
, FILE_ALL_INFO
*pfile_info
,
1218 const struct nls_table
*nls_codepage
, int remap
)
1221 OPEN_REQ
*pSMB
= NULL
;
1222 OPEN_RSP
*pSMBr
= NULL
;
1228 rc
= smb_init(SMB_COM_NT_CREATE_ANDX
, 24, tcon
, (void **) &pSMB
,
1233 pSMB
->AndXCommand
= 0xFF; /* none */
1235 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
1236 count
= 1; /* account for one byte pad to word boundary */
1238 cifsConvertToUCS((__le16
*) (pSMB
->fileName
+ 1),
1239 fileName
, PATH_MAX
, nls_codepage
, remap
);
1240 name_len
++; /* trailing null */
1242 pSMB
->NameLength
= cpu_to_le16(name_len
);
1243 } else { /* BB improve check for buffer overruns BB */
1244 count
= 0; /* no pad */
1245 name_len
= strnlen(fileName
, PATH_MAX
);
1246 name_len
++; /* trailing null */
1247 pSMB
->NameLength
= cpu_to_le16(name_len
);
1248 strncpy(pSMB
->fileName
, fileName
, name_len
);
1250 if (*pOplock
& REQ_OPLOCK
)
1251 pSMB
->OpenFlags
= cpu_to_le32(REQ_OPLOCK
);
1252 else if (*pOplock
& REQ_BATCHOPLOCK
)
1253 pSMB
->OpenFlags
= cpu_to_le32(REQ_BATCHOPLOCK
);
1254 pSMB
->DesiredAccess
= cpu_to_le32(access_flags
);
1255 pSMB
->AllocationSize
= 0;
1256 /* set file as system file if special file such
1257 as fifo and server expecting SFU style and
1258 no Unix extensions */
1259 if (create_options
& CREATE_OPTION_SPECIAL
)
1260 pSMB
->FileAttributes
= cpu_to_le32(ATTR_SYSTEM
);
1262 pSMB
->FileAttributes
= cpu_to_le32(ATTR_NORMAL
);
1264 /* XP does not handle ATTR_POSIX_SEMANTICS */
1265 /* but it helps speed up case sensitive checks for other
1266 servers such as Samba */
1267 if (tcon
->ses
->capabilities
& CAP_UNIX
)
1268 pSMB
->FileAttributes
|= cpu_to_le32(ATTR_POSIX_SEMANTICS
);
1270 if (create_options
& CREATE_OPTION_READONLY
)
1271 pSMB
->FileAttributes
|= cpu_to_le32(ATTR_READONLY
);
1273 pSMB
->ShareAccess
= cpu_to_le32(FILE_SHARE_ALL
);
1274 pSMB
->CreateDisposition
= cpu_to_le32(openDisposition
);
1275 pSMB
->CreateOptions
= cpu_to_le32(create_options
& CREATE_OPTIONS_MASK
);
1276 /* BB Expirement with various impersonation levels and verify */
1277 pSMB
->ImpersonationLevel
= cpu_to_le32(SECURITY_IMPERSONATION
);
1278 pSMB
->SecurityFlags
=
1279 SECURITY_CONTEXT_TRACKING
| SECURITY_EFFECTIVE_ONLY
;
1282 pSMB
->hdr
.smb_buf_length
+= count
;
1284 pSMB
->ByteCount
= cpu_to_le16(count
);
1285 /* long_op set to 1 to allow for oplock break timeouts */
1286 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
1287 (struct smb_hdr
*)pSMBr
, &bytes_returned
, CIFS_LONG_OP
);
1288 cifs_stats_inc(&tcon
->num_opens
);
1290 cFYI(1, ("Error in Open = %d", rc
));
1292 *pOplock
= pSMBr
->OplockLevel
; /* 1 byte no need to le_to_cpu */
1293 *netfid
= pSMBr
->Fid
; /* cifs fid stays in le */
1294 /* Let caller know file was created so we can set the mode. */
1295 /* Do we care about the CreateAction in any other cases? */
1296 if (cpu_to_le32(FILE_CREATE
) == pSMBr
->CreateAction
)
1297 *pOplock
|= CIFS_CREATE_ACTION
;
1299 memcpy((char *)pfile_info
, (char *)&pSMBr
->CreationTime
,
1300 36 /* CreationTime to Attributes */);
1301 /* the file_info buf is endian converted by caller */
1302 pfile_info
->AllocationSize
= pSMBr
->AllocationSize
;
1303 pfile_info
->EndOfFile
= pSMBr
->EndOfFile
;
1304 pfile_info
->NumberOfLinks
= cpu_to_le32(1);
1305 pfile_info
->DeletePending
= 0;
1309 cifs_buf_release(pSMB
);
1316 CIFSSMBRead(const int xid
, struct cifsTconInfo
*tcon
, const int netfid
,
1317 const unsigned int count
, const __u64 lseek
, unsigned int *nbytes
,
1318 char **buf
, int *pbuf_type
)
1321 READ_REQ
*pSMB
= NULL
;
1322 READ_RSP
*pSMBr
= NULL
;
1323 char *pReadData
= NULL
;
1325 int resp_buf_type
= 0;
1328 cFYI(1, ("Reading %d bytes on fid %d", count
, netfid
));
1329 if (tcon
->ses
->capabilities
& CAP_LARGE_FILES
)
1332 wct
= 10; /* old style read */
1333 if ((lseek
>> 32) > 0) {
1334 /* can not handle this big offset for old */
1340 rc
= small_smb_init(SMB_COM_READ_ANDX
, wct
, tcon
, (void **) &pSMB
);
1344 /* tcon and ses pointer are checked in smb_init */
1345 if (tcon
->ses
->server
== NULL
)
1346 return -ECONNABORTED
;
1348 pSMB
->AndXCommand
= 0xFF; /* none */
1350 pSMB
->OffsetLow
= cpu_to_le32(lseek
& 0xFFFFFFFF);
1352 pSMB
->OffsetHigh
= cpu_to_le32(lseek
>> 32);
1354 pSMB
->Remaining
= 0;
1355 pSMB
->MaxCount
= cpu_to_le16(count
& 0xFFFF);
1356 pSMB
->MaxCountHigh
= cpu_to_le32(count
>> 16);
1358 pSMB
->ByteCount
= 0; /* no need to do le conversion since 0 */
1360 /* old style read */
1361 struct smb_com_readx_req
*pSMBW
=
1362 (struct smb_com_readx_req
*)pSMB
;
1363 pSMBW
->ByteCount
= 0;
1366 iov
[0].iov_base
= (char *)pSMB
;
1367 iov
[0].iov_len
= pSMB
->hdr
.smb_buf_length
+ 4;
1368 rc
= SendReceive2(xid
, tcon
->ses
, iov
, 1 /* num iovecs */,
1369 &resp_buf_type
, CIFS_STD_OP
| CIFS_LOG_ERROR
);
1370 cifs_stats_inc(&tcon
->num_reads
);
1371 pSMBr
= (READ_RSP
*)iov
[0].iov_base
;
1373 cERROR(1, ("Send error in read = %d", rc
));
1375 int data_length
= le16_to_cpu(pSMBr
->DataLengthHigh
);
1376 data_length
= data_length
<< 16;
1377 data_length
+= le16_to_cpu(pSMBr
->DataLength
);
1378 *nbytes
= data_length
;
1380 /*check that DataLength would not go beyond end of SMB */
1381 if ((data_length
> CIFSMaxBufSize
)
1382 || (data_length
> count
)) {
1383 cFYI(1, ("bad length %d for count %d",
1384 data_length
, count
));
1388 pReadData
= (char *) (&pSMBr
->hdr
.Protocol
) +
1389 le16_to_cpu(pSMBr
->DataOffset
);
1390 /* if (rc = copy_to_user(buf, pReadData, data_length)) {
1391 cERROR(1,("Faulting on read rc = %d",rc));
1393 }*/ /* can not use copy_to_user when using page cache*/
1395 memcpy(*buf
, pReadData
, data_length
);
1399 /* cifs_small_buf_release(pSMB); */ /* Freed earlier now in SendReceive2 */
1401 if (resp_buf_type
== CIFS_SMALL_BUFFER
)
1402 cifs_small_buf_release(iov
[0].iov_base
);
1403 else if (resp_buf_type
== CIFS_LARGE_BUFFER
)
1404 cifs_buf_release(iov
[0].iov_base
);
1405 } else if (resp_buf_type
!= CIFS_NO_BUFFER
) {
1406 /* return buffer to caller to free */
1407 *buf
= iov
[0].iov_base
;
1408 if (resp_buf_type
== CIFS_SMALL_BUFFER
)
1409 *pbuf_type
= CIFS_SMALL_BUFFER
;
1410 else if (resp_buf_type
== CIFS_LARGE_BUFFER
)
1411 *pbuf_type
= CIFS_LARGE_BUFFER
;
1412 } /* else no valid buffer on return - leave as null */
1414 /* Note: On -EAGAIN error only caller can retry on handle based calls
1415 since file handle passed in no longer valid */
1421 CIFSSMBWrite(const int xid
, struct cifsTconInfo
*tcon
,
1422 const int netfid
, const unsigned int count
,
1423 const __u64 offset
, unsigned int *nbytes
, const char *buf
,
1424 const char __user
*ubuf
, const int long_op
)
1427 WRITE_REQ
*pSMB
= NULL
;
1428 WRITE_RSP
*pSMBr
= NULL
;
1429 int bytes_returned
, wct
;
1435 /* cFYI(1, ("write at %lld %d bytes", offset, count));*/
1436 if (tcon
->ses
== NULL
)
1437 return -ECONNABORTED
;
1439 if (tcon
->ses
->capabilities
& CAP_LARGE_FILES
)
1443 if ((offset
>> 32) > 0) {
1444 /* can not handle big offset for old srv */
1449 rc
= smb_init(SMB_COM_WRITE_ANDX
, wct
, tcon
, (void **) &pSMB
,
1453 /* tcon and ses pointer are checked in smb_init */
1454 if (tcon
->ses
->server
== NULL
)
1455 return -ECONNABORTED
;
1457 pSMB
->AndXCommand
= 0xFF; /* none */
1459 pSMB
->OffsetLow
= cpu_to_le32(offset
& 0xFFFFFFFF);
1461 pSMB
->OffsetHigh
= cpu_to_le32(offset
>> 32);
1463 pSMB
->Reserved
= 0xFFFFFFFF;
1464 pSMB
->WriteMode
= 0;
1465 pSMB
->Remaining
= 0;
1467 /* Can increase buffer size if buffer is big enough in some cases ie we
1468 can send more if LARGE_WRITE_X capability returned by the server and if
1469 our buffer is big enough or if we convert to iovecs on socket writes
1470 and eliminate the copy to the CIFS buffer */
1471 if (tcon
->ses
->capabilities
& CAP_LARGE_WRITE_X
) {
1472 bytes_sent
= min_t(const unsigned int, CIFSMaxBufSize
, count
);
1474 bytes_sent
= (tcon
->ses
->server
->maxBuf
- MAX_CIFS_HDR_SIZE
)
1478 if (bytes_sent
> count
)
1481 cpu_to_le16(offsetof(struct smb_com_write_req
, Data
) - 4);
1483 memcpy(pSMB
->Data
, buf
, bytes_sent
);
1485 if (copy_from_user(pSMB
->Data
, ubuf
, bytes_sent
)) {
1486 cifs_buf_release(pSMB
);
1489 } else if (count
!= 0) {
1491 cifs_buf_release(pSMB
);
1493 } /* else setting file size with write of zero bytes */
1495 byte_count
= bytes_sent
+ 1; /* pad */
1496 else /* wct == 12 */
1497 byte_count
= bytes_sent
+ 5; /* bigger pad, smaller smb hdr */
1499 pSMB
->DataLengthLow
= cpu_to_le16(bytes_sent
& 0xFFFF);
1500 pSMB
->DataLengthHigh
= cpu_to_le16(bytes_sent
>> 16);
1501 pSMB
->hdr
.smb_buf_length
+= byte_count
;
1504 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
1505 else { /* old style write has byte count 4 bytes earlier
1507 struct smb_com_writex_req
*pSMBW
=
1508 (struct smb_com_writex_req
*)pSMB
;
1509 pSMBW
->ByteCount
= cpu_to_le16(byte_count
);
1512 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
1513 (struct smb_hdr
*) pSMBr
, &bytes_returned
, long_op
);
1514 cifs_stats_inc(&tcon
->num_writes
);
1516 cFYI(1, ("Send error in write = %d", rc
));
1518 *nbytes
= le16_to_cpu(pSMBr
->CountHigh
);
1519 *nbytes
= (*nbytes
) << 16;
1520 *nbytes
+= le16_to_cpu(pSMBr
->Count
);
1523 * Mask off high 16 bits when bytes written as returned by the
1524 * server is greater than bytes requested by the client. Some
1525 * OS/2 servers are known to set incorrect CountHigh values.
1527 if (*nbytes
> count
)
1531 cifs_buf_release(pSMB
);
1533 /* Note: On -EAGAIN error only caller can retry on handle based calls
1534 since file handle passed in no longer valid */
1540 CIFSSMBWrite2(const int xid
, struct cifsTconInfo
*tcon
,
1541 const int netfid
, const unsigned int count
,
1542 const __u64 offset
, unsigned int *nbytes
, struct kvec
*iov
,
1543 int n_vec
, const int long_op
)
1546 WRITE_REQ
*pSMB
= NULL
;
1549 int resp_buf_type
= 0;
1553 cFYI(1, ("write2 at %lld %d bytes", (long long)offset
, count
));
1555 if (tcon
->ses
->capabilities
& CAP_LARGE_FILES
) {
1559 if ((offset
>> 32) > 0) {
1560 /* can not handle big offset for old srv */
1564 rc
= small_smb_init(SMB_COM_WRITE_ANDX
, wct
, tcon
, (void **) &pSMB
);
1567 /* tcon and ses pointer are checked in smb_init */
1568 if (tcon
->ses
->server
== NULL
)
1569 return -ECONNABORTED
;
1571 pSMB
->AndXCommand
= 0xFF; /* none */
1573 pSMB
->OffsetLow
= cpu_to_le32(offset
& 0xFFFFFFFF);
1575 pSMB
->OffsetHigh
= cpu_to_le32(offset
>> 32);
1576 pSMB
->Reserved
= 0xFFFFFFFF;
1577 pSMB
->WriteMode
= 0;
1578 pSMB
->Remaining
= 0;
1581 cpu_to_le16(offsetof(struct smb_com_write_req
, Data
) - 4);
1583 pSMB
->DataLengthLow
= cpu_to_le16(count
& 0xFFFF);
1584 pSMB
->DataLengthHigh
= cpu_to_le16(count
>> 16);
1585 smb_hdr_len
= pSMB
->hdr
.smb_buf_length
+ 1; /* hdr + 1 byte pad */
1587 pSMB
->hdr
.smb_buf_length
+= count
+1;
1588 else /* wct == 12 */
1589 pSMB
->hdr
.smb_buf_length
+= count
+5; /* smb data starts later */
1591 pSMB
->ByteCount
= cpu_to_le16(count
+ 1);
1592 else /* wct == 12 */ /* bigger pad, smaller smb hdr, keep offset ok */ {
1593 struct smb_com_writex_req
*pSMBW
=
1594 (struct smb_com_writex_req
*)pSMB
;
1595 pSMBW
->ByteCount
= cpu_to_le16(count
+ 5);
1597 iov
[0].iov_base
= pSMB
;
1599 iov
[0].iov_len
= smb_hdr_len
+ 4;
1600 else /* wct == 12 pad bigger by four bytes */
1601 iov
[0].iov_len
= smb_hdr_len
+ 8;
1604 rc
= SendReceive2(xid
, tcon
->ses
, iov
, n_vec
+ 1, &resp_buf_type
,
1606 cifs_stats_inc(&tcon
->num_writes
);
1608 cFYI(1, ("Send error Write2 = %d", rc
));
1609 } else if (resp_buf_type
== 0) {
1610 /* presumably this can not happen, but best to be safe */
1613 WRITE_RSP
*pSMBr
= (WRITE_RSP
*)iov
[0].iov_base
;
1614 *nbytes
= le16_to_cpu(pSMBr
->CountHigh
);
1615 *nbytes
= (*nbytes
) << 16;
1616 *nbytes
+= le16_to_cpu(pSMBr
->Count
);
1619 * Mask off high 16 bits when bytes written as returned by the
1620 * server is greater than bytes requested by the client. OS/2
1621 * servers are known to set incorrect CountHigh values.
1623 if (*nbytes
> count
)
1627 /* cifs_small_buf_release(pSMB); */ /* Freed earlier now in SendReceive2 */
1628 if (resp_buf_type
== CIFS_SMALL_BUFFER
)
1629 cifs_small_buf_release(iov
[0].iov_base
);
1630 else if (resp_buf_type
== CIFS_LARGE_BUFFER
)
1631 cifs_buf_release(iov
[0].iov_base
);
1633 /* Note: On -EAGAIN error only caller can retry on handle based calls
1634 since file handle passed in no longer valid */
1641 CIFSSMBLock(const int xid
, struct cifsTconInfo
*tcon
,
1642 const __u16 smb_file_id
, const __u64 len
,
1643 const __u64 offset
, const __u32 numUnlock
,
1644 const __u32 numLock
, const __u8 lockType
,
1645 const bool waitFlag
, const __u8 oplock_level
)
1648 LOCK_REQ
*pSMB
= NULL
;
1649 /* LOCK_RSP *pSMBr = NULL; */ /* No response data other than rc to parse */
1654 cFYI(1, ("CIFSSMBLock timeout %d numLock %d", (int)waitFlag
, numLock
));
1655 rc
= small_smb_init(SMB_COM_LOCKING_ANDX
, 8, tcon
, (void **) &pSMB
);
1660 if (lockType
== LOCKING_ANDX_OPLOCK_RELEASE
) {
1661 timeout
= CIFS_ASYNC_OP
; /* no response expected */
1663 } else if (waitFlag
) {
1664 timeout
= CIFS_BLOCKING_OP
; /* blocking operation, no timeout */
1665 pSMB
->Timeout
= cpu_to_le32(-1);/* blocking - do not time out */
1670 pSMB
->NumberOfLocks
= cpu_to_le16(numLock
);
1671 pSMB
->NumberOfUnlocks
= cpu_to_le16(numUnlock
);
1672 pSMB
->LockType
= lockType
;
1673 pSMB
->OplockLevel
= oplock_level
;
1674 pSMB
->AndXCommand
= 0xFF; /* none */
1675 pSMB
->Fid
= smb_file_id
; /* netfid stays le */
1677 if ((numLock
!= 0) || (numUnlock
!= 0)) {
1678 pSMB
->Locks
[0].Pid
= cpu_to_le16(current
->tgid
);
1679 /* BB where to store pid high? */
1680 pSMB
->Locks
[0].LengthLow
= cpu_to_le32((u32
)len
);
1681 pSMB
->Locks
[0].LengthHigh
= cpu_to_le32((u32
)(len
>>32));
1682 pSMB
->Locks
[0].OffsetLow
= cpu_to_le32((u32
)offset
);
1683 pSMB
->Locks
[0].OffsetHigh
= cpu_to_le32((u32
)(offset
>>32));
1684 count
= sizeof(LOCKING_ANDX_RANGE
);
1689 pSMB
->hdr
.smb_buf_length
+= count
;
1690 pSMB
->ByteCount
= cpu_to_le16(count
);
1693 rc
= SendReceiveBlockingLock(xid
, tcon
, (struct smb_hdr
*) pSMB
,
1694 (struct smb_hdr
*) pSMB
, &bytes_returned
);
1695 cifs_small_buf_release(pSMB
);
1697 rc
= SendReceiveNoRsp(xid
, tcon
->ses
, (struct smb_hdr
*)pSMB
,
1699 /* SMB buffer freed by function above */
1701 cifs_stats_inc(&tcon
->num_locks
);
1703 cFYI(1, ("Send error in Lock = %d", rc
));
1705 /* Note: On -EAGAIN error only caller can retry on handle based calls
1706 since file handle passed in no longer valid */
1711 CIFSSMBPosixLock(const int xid
, struct cifsTconInfo
*tcon
,
1712 const __u16 smb_file_id
, const int get_flag
, const __u64 len
,
1713 struct file_lock
*pLockData
, const __u16 lock_type
,
1714 const bool waitFlag
)
1716 struct smb_com_transaction2_sfi_req
*pSMB
= NULL
;
1717 struct smb_com_transaction2_sfi_rsp
*pSMBr
= NULL
;
1718 struct cifs_posix_lock
*parm_data
;
1721 int bytes_returned
= 0;
1722 int resp_buf_type
= 0;
1723 __u16 params
, param_offset
, offset
, byte_count
, count
;
1726 cFYI(1, ("Posix Lock"));
1728 if (pLockData
== NULL
)
1731 rc
= small_smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
);
1736 pSMBr
= (struct smb_com_transaction2_sfi_rsp
*)pSMB
;
1739 pSMB
->MaxSetupCount
= 0;
1742 pSMB
->Reserved2
= 0;
1743 param_offset
= offsetof(struct smb_com_transaction2_sfi_req
, Fid
) - 4;
1744 offset
= param_offset
+ params
;
1746 count
= sizeof(struct cifs_posix_lock
);
1747 pSMB
->MaxParameterCount
= cpu_to_le16(2);
1748 pSMB
->MaxDataCount
= cpu_to_le16(1000); /* BB find max SMB from sess */
1749 pSMB
->SetupCount
= 1;
1750 pSMB
->Reserved3
= 0;
1752 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION
);
1754 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_FILE_INFORMATION
);
1755 byte_count
= 3 /* pad */ + params
+ count
;
1756 pSMB
->DataCount
= cpu_to_le16(count
);
1757 pSMB
->ParameterCount
= cpu_to_le16(params
);
1758 pSMB
->TotalDataCount
= pSMB
->DataCount
;
1759 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
1760 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
1761 parm_data
= (struct cifs_posix_lock
*)
1762 (((char *) &pSMB
->hdr
.Protocol
) + offset
);
1764 parm_data
->lock_type
= cpu_to_le16(lock_type
);
1766 timeout
= CIFS_BLOCKING_OP
; /* blocking operation, no timeout */
1767 parm_data
->lock_flags
= cpu_to_le16(1);
1768 pSMB
->Timeout
= cpu_to_le32(-1);
1772 parm_data
->pid
= cpu_to_le32(current
->tgid
);
1773 parm_data
->start
= cpu_to_le64(pLockData
->fl_start
);
1774 parm_data
->length
= cpu_to_le64(len
); /* normalize negative numbers */
1776 pSMB
->DataOffset
= cpu_to_le16(offset
);
1777 pSMB
->Fid
= smb_file_id
;
1778 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_POSIX_LOCK
);
1779 pSMB
->Reserved4
= 0;
1780 pSMB
->hdr
.smb_buf_length
+= byte_count
;
1781 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
1783 rc
= SendReceiveBlockingLock(xid
, tcon
, (struct smb_hdr
*) pSMB
,
1784 (struct smb_hdr
*) pSMBr
, &bytes_returned
);
1786 iov
[0].iov_base
= (char *)pSMB
;
1787 iov
[0].iov_len
= pSMB
->hdr
.smb_buf_length
+ 4;
1788 rc
= SendReceive2(xid
, tcon
->ses
, iov
, 1 /* num iovecs */,
1789 &resp_buf_type
, timeout
);
1790 pSMB
= NULL
; /* request buf already freed by SendReceive2. Do
1791 not try to free it twice below on exit */
1792 pSMBr
= (struct smb_com_transaction2_sfi_rsp
*)iov
[0].iov_base
;
1796 cFYI(1, ("Send error in Posix Lock = %d", rc
));
1797 } else if (get_flag
) {
1798 /* lock structure can be returned on get */
1801 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
1803 if (rc
|| (pSMBr
->ByteCount
< sizeof(struct cifs_posix_lock
))) {
1804 rc
= -EIO
; /* bad smb */
1807 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
1808 data_count
= le16_to_cpu(pSMBr
->t2
.DataCount
);
1809 if (data_count
< sizeof(struct cifs_posix_lock
)) {
1813 parm_data
= (struct cifs_posix_lock
*)
1814 ((char *)&pSMBr
->hdr
.Protocol
+ data_offset
);
1815 if (parm_data
->lock_type
== cpu_to_le16(CIFS_UNLCK
))
1816 pLockData
->fl_type
= F_UNLCK
;
1821 cifs_small_buf_release(pSMB
);
1823 if (resp_buf_type
== CIFS_SMALL_BUFFER
)
1824 cifs_small_buf_release(iov
[0].iov_base
);
1825 else if (resp_buf_type
== CIFS_LARGE_BUFFER
)
1826 cifs_buf_release(iov
[0].iov_base
);
1828 /* Note: On -EAGAIN error only caller can retry on handle based calls
1829 since file handle passed in no longer valid */
1836 CIFSSMBClose(const int xid
, struct cifsTconInfo
*tcon
, int smb_file_id
)
1839 CLOSE_REQ
*pSMB
= NULL
;
1840 cFYI(1, ("In CIFSSMBClose"));
1842 /* do not retry on dead session on close */
1843 rc
= small_smb_init(SMB_COM_CLOSE
, 3, tcon
, (void **) &pSMB
);
1849 pSMB
->FileID
= (__u16
) smb_file_id
;
1850 pSMB
->LastWriteTime
= 0xFFFFFFFF;
1851 pSMB
->ByteCount
= 0;
1852 rc
= SendReceiveNoRsp(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
, 0);
1853 cifs_stats_inc(&tcon
->num_closes
);
1856 /* EINTR is expected when user ctl-c to kill app */
1857 cERROR(1, ("Send error in Close = %d", rc
));
1861 /* Since session is dead, file will be closed on server already */
1869 CIFSSMBFlush(const int xid
, struct cifsTconInfo
*tcon
, int smb_file_id
)
1872 FLUSH_REQ
*pSMB
= NULL
;
1873 cFYI(1, ("In CIFSSMBFlush"));
1875 rc
= small_smb_init(SMB_COM_FLUSH
, 1, tcon
, (void **) &pSMB
);
1879 pSMB
->FileID
= (__u16
) smb_file_id
;
1880 pSMB
->ByteCount
= 0;
1881 rc
= SendReceiveNoRsp(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
, 0);
1882 cifs_stats_inc(&tcon
->num_flushes
);
1884 cERROR(1, ("Send error in Flush = %d", rc
));
1890 CIFSSMBRename(const int xid
, struct cifsTconInfo
*tcon
,
1891 const char *fromName
, const char *toName
,
1892 const struct nls_table
*nls_codepage
, int remap
)
1895 RENAME_REQ
*pSMB
= NULL
;
1896 RENAME_RSP
*pSMBr
= NULL
;
1898 int name_len
, name_len2
;
1901 cFYI(1, ("In CIFSSMBRename"));
1903 rc
= smb_init(SMB_COM_RENAME
, 1, tcon
, (void **) &pSMB
,
1908 pSMB
->BufferFormat
= 0x04;
1909 pSMB
->SearchAttributes
=
1910 cpu_to_le16(ATTR_READONLY
| ATTR_HIDDEN
| ATTR_SYSTEM
|
1913 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
1915 cifsConvertToUCS((__le16
*) pSMB
->OldFileName
, fromName
,
1916 PATH_MAX
, nls_codepage
, remap
);
1917 name_len
++; /* trailing null */
1919 pSMB
->OldFileName
[name_len
] = 0x04; /* pad */
1920 /* protocol requires ASCII signature byte on Unicode string */
1921 pSMB
->OldFileName
[name_len
+ 1] = 0x00;
1923 cifsConvertToUCS((__le16
*)&pSMB
->OldFileName
[name_len
+ 2],
1924 toName
, PATH_MAX
, nls_codepage
, remap
);
1925 name_len2
+= 1 /* trailing null */ + 1 /* Signature word */ ;
1926 name_len2
*= 2; /* convert to bytes */
1927 } else { /* BB improve the check for buffer overruns BB */
1928 name_len
= strnlen(fromName
, PATH_MAX
);
1929 name_len
++; /* trailing null */
1930 strncpy(pSMB
->OldFileName
, fromName
, name_len
);
1931 name_len2
= strnlen(toName
, PATH_MAX
);
1932 name_len2
++; /* trailing null */
1933 pSMB
->OldFileName
[name_len
] = 0x04; /* 2nd buffer format */
1934 strncpy(&pSMB
->OldFileName
[name_len
+ 1], toName
, name_len2
);
1935 name_len2
++; /* trailing null */
1936 name_len2
++; /* signature byte */
1939 count
= 1 /* 1st signature byte */ + name_len
+ name_len2
;
1940 pSMB
->hdr
.smb_buf_length
+= count
;
1941 pSMB
->ByteCount
= cpu_to_le16(count
);
1943 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
1944 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
1945 cifs_stats_inc(&tcon
->num_renames
);
1947 cFYI(1, ("Send error in rename = %d", rc
));
1949 cifs_buf_release(pSMB
);
1957 int CIFSSMBRenameOpenFile(const int xid
, struct cifsTconInfo
*pTcon
,
1958 int netfid
, const char *target_name
,
1959 const struct nls_table
*nls_codepage
, int remap
)
1961 struct smb_com_transaction2_sfi_req
*pSMB
= NULL
;
1962 struct smb_com_transaction2_sfi_rsp
*pSMBr
= NULL
;
1963 struct set_file_rename
*rename_info
;
1965 char dummy_string
[30];
1967 int bytes_returned
= 0;
1969 __u16 params
, param_offset
, offset
, count
, byte_count
;
1971 cFYI(1, ("Rename to File by handle"));
1972 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, pTcon
, (void **) &pSMB
,
1978 pSMB
->MaxSetupCount
= 0;
1982 pSMB
->Reserved2
= 0;
1983 param_offset
= offsetof(struct smb_com_transaction2_sfi_req
, Fid
) - 4;
1984 offset
= param_offset
+ params
;
1986 data_offset
= (char *) (&pSMB
->hdr
.Protocol
) + offset
;
1987 rename_info
= (struct set_file_rename
*) data_offset
;
1988 pSMB
->MaxParameterCount
= cpu_to_le16(2);
1989 pSMB
->MaxDataCount
= cpu_to_le16(1000); /* BB find max SMB from sess */
1990 pSMB
->SetupCount
= 1;
1991 pSMB
->Reserved3
= 0;
1992 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_FILE_INFORMATION
);
1993 byte_count
= 3 /* pad */ + params
;
1994 pSMB
->ParameterCount
= cpu_to_le16(params
);
1995 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
1996 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
1997 pSMB
->DataOffset
= cpu_to_le16(offset
);
1998 /* construct random name ".cifs_tmp<inodenum><mid>" */
1999 rename_info
->overwrite
= cpu_to_le32(1);
2000 rename_info
->root_fid
= 0;
2001 /* unicode only call */
2002 if (target_name
== NULL
) {
2003 sprintf(dummy_string
, "cifs%x", pSMB
->hdr
.Mid
);
2004 len_of_str
= cifsConvertToUCS((__le16
*)rename_info
->target_name
,
2005 dummy_string
, 24, nls_codepage
, remap
);
2007 len_of_str
= cifsConvertToUCS((__le16
*)rename_info
->target_name
,
2008 target_name
, PATH_MAX
, nls_codepage
,
2011 rename_info
->target_name_len
= cpu_to_le32(2 * len_of_str
);
2012 count
= 12 /* sizeof(struct set_file_rename) */ + (2 * len_of_str
);
2013 byte_count
+= count
;
2014 pSMB
->DataCount
= cpu_to_le16(count
);
2015 pSMB
->TotalDataCount
= pSMB
->DataCount
;
2017 pSMB
->InformationLevel
=
2018 cpu_to_le16(SMB_SET_FILE_RENAME_INFORMATION
);
2019 pSMB
->Reserved4
= 0;
2020 pSMB
->hdr
.smb_buf_length
+= byte_count
;
2021 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
2022 rc
= SendReceive(xid
, pTcon
->ses
, (struct smb_hdr
*) pSMB
,
2023 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
2024 cifs_stats_inc(&pTcon
->num_t2renames
);
2026 cFYI(1, ("Send error in Rename (by file handle) = %d", rc
));
2028 cifs_buf_release(pSMB
);
2030 /* Note: On -EAGAIN error only caller can retry on handle based calls
2031 since file handle passed in no longer valid */
2037 CIFSSMBCopy(const int xid
, struct cifsTconInfo
*tcon
, const char *fromName
,
2038 const __u16 target_tid
, const char *toName
, const int flags
,
2039 const struct nls_table
*nls_codepage
, int remap
)
2042 COPY_REQ
*pSMB
= NULL
;
2043 COPY_RSP
*pSMBr
= NULL
;
2045 int name_len
, name_len2
;
2048 cFYI(1, ("In CIFSSMBCopy"));
2050 rc
= smb_init(SMB_COM_COPY
, 1, tcon
, (void **) &pSMB
,
2055 pSMB
->BufferFormat
= 0x04;
2056 pSMB
->Tid2
= target_tid
;
2058 pSMB
->Flags
= cpu_to_le16(flags
& COPY_TREE
);
2060 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
2061 name_len
= cifsConvertToUCS((__le16
*) pSMB
->OldFileName
,
2062 fromName
, PATH_MAX
, nls_codepage
,
2064 name_len
++; /* trailing null */
2066 pSMB
->OldFileName
[name_len
] = 0x04; /* pad */
2067 /* protocol requires ASCII signature byte on Unicode string */
2068 pSMB
->OldFileName
[name_len
+ 1] = 0x00;
2070 cifsConvertToUCS((__le16
*)&pSMB
->OldFileName
[name_len
+ 2],
2071 toName
, PATH_MAX
, nls_codepage
, remap
);
2072 name_len2
+= 1 /* trailing null */ + 1 /* Signature word */ ;
2073 name_len2
*= 2; /* convert to bytes */
2074 } else { /* BB improve the check for buffer overruns BB */
2075 name_len
= strnlen(fromName
, PATH_MAX
);
2076 name_len
++; /* trailing null */
2077 strncpy(pSMB
->OldFileName
, fromName
, name_len
);
2078 name_len2
= strnlen(toName
, PATH_MAX
);
2079 name_len2
++; /* trailing null */
2080 pSMB
->OldFileName
[name_len
] = 0x04; /* 2nd buffer format */
2081 strncpy(&pSMB
->OldFileName
[name_len
+ 1], toName
, name_len2
);
2082 name_len2
++; /* trailing null */
2083 name_len2
++; /* signature byte */
2086 count
= 1 /* 1st signature byte */ + name_len
+ name_len2
;
2087 pSMB
->hdr
.smb_buf_length
+= count
;
2088 pSMB
->ByteCount
= cpu_to_le16(count
);
2090 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
2091 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
2093 cFYI(1, ("Send error in copy = %d with %d files copied",
2094 rc
, le16_to_cpu(pSMBr
->CopyCount
)));
2096 cifs_buf_release(pSMB
);
2105 CIFSUnixCreateSymLink(const int xid
, struct cifsTconInfo
*tcon
,
2106 const char *fromName
, const char *toName
,
2107 const struct nls_table
*nls_codepage
)
2109 TRANSACTION2_SPI_REQ
*pSMB
= NULL
;
2110 TRANSACTION2_SPI_RSP
*pSMBr
= NULL
;
2113 int name_len_target
;
2115 int bytes_returned
= 0;
2116 __u16 params
, param_offset
, offset
, byte_count
;
2118 cFYI(1, ("In Symlink Unix style"));
2120 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
2125 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
2127 cifs_strtoUCS((__le16
*) pSMB
->FileName
, fromName
, PATH_MAX
2128 /* find define for this maxpathcomponent */
2130 name_len
++; /* trailing null */
2133 } else { /* BB improve the check for buffer overruns BB */
2134 name_len
= strnlen(fromName
, PATH_MAX
);
2135 name_len
++; /* trailing null */
2136 strncpy(pSMB
->FileName
, fromName
, name_len
);
2138 params
= 6 + name_len
;
2139 pSMB
->MaxSetupCount
= 0;
2143 pSMB
->Reserved2
= 0;
2144 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
2145 InformationLevel
) - 4;
2146 offset
= param_offset
+ params
;
2148 data_offset
= (char *) (&pSMB
->hdr
.Protocol
) + offset
;
2149 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
2151 cifs_strtoUCS((__le16
*) data_offset
, toName
, PATH_MAX
2152 /* find define for this maxpathcomponent */
2154 name_len_target
++; /* trailing null */
2155 name_len_target
*= 2;
2156 } else { /* BB improve the check for buffer overruns BB */
2157 name_len_target
= strnlen(toName
, PATH_MAX
);
2158 name_len_target
++; /* trailing null */
2159 strncpy(data_offset
, toName
, name_len_target
);
2162 pSMB
->MaxParameterCount
= cpu_to_le16(2);
2163 /* BB find exact max on data count below from sess */
2164 pSMB
->MaxDataCount
= cpu_to_le16(1000);
2165 pSMB
->SetupCount
= 1;
2166 pSMB
->Reserved3
= 0;
2167 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
2168 byte_count
= 3 /* pad */ + params
+ name_len_target
;
2169 pSMB
->DataCount
= cpu_to_le16(name_len_target
);
2170 pSMB
->ParameterCount
= cpu_to_le16(params
);
2171 pSMB
->TotalDataCount
= pSMB
->DataCount
;
2172 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
2173 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
2174 pSMB
->DataOffset
= cpu_to_le16(offset
);
2175 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_UNIX_LINK
);
2176 pSMB
->Reserved4
= 0;
2177 pSMB
->hdr
.smb_buf_length
+= byte_count
;
2178 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
2179 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
2180 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
2181 cifs_stats_inc(&tcon
->num_symlinks
);
2183 cFYI(1, ("Send error in SetPathInfo create symlink = %d", rc
));
2185 cifs_buf_release(pSMB
);
2188 goto createSymLinkRetry
;
2194 CIFSUnixCreateHardLink(const int xid
, struct cifsTconInfo
*tcon
,
2195 const char *fromName
, const char *toName
,
2196 const struct nls_table
*nls_codepage
, int remap
)
2198 TRANSACTION2_SPI_REQ
*pSMB
= NULL
;
2199 TRANSACTION2_SPI_RSP
*pSMBr
= NULL
;
2202 int name_len_target
;
2204 int bytes_returned
= 0;
2205 __u16 params
, param_offset
, offset
, byte_count
;
2207 cFYI(1, ("In Create Hard link Unix style"));
2208 createHardLinkRetry
:
2209 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
2214 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
2215 name_len
= cifsConvertToUCS((__le16
*) pSMB
->FileName
, toName
,
2216 PATH_MAX
, nls_codepage
, remap
);
2217 name_len
++; /* trailing null */
2220 } else { /* BB improve the check for buffer overruns BB */
2221 name_len
= strnlen(toName
, PATH_MAX
);
2222 name_len
++; /* trailing null */
2223 strncpy(pSMB
->FileName
, toName
, name_len
);
2225 params
= 6 + name_len
;
2226 pSMB
->MaxSetupCount
= 0;
2230 pSMB
->Reserved2
= 0;
2231 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
2232 InformationLevel
) - 4;
2233 offset
= param_offset
+ params
;
2235 data_offset
= (char *) (&pSMB
->hdr
.Protocol
) + offset
;
2236 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
2238 cifsConvertToUCS((__le16
*) data_offset
, fromName
, PATH_MAX
,
2239 nls_codepage
, remap
);
2240 name_len_target
++; /* trailing null */
2241 name_len_target
*= 2;
2242 } else { /* BB improve the check for buffer overruns BB */
2243 name_len_target
= strnlen(fromName
, PATH_MAX
);
2244 name_len_target
++; /* trailing null */
2245 strncpy(data_offset
, fromName
, name_len_target
);
2248 pSMB
->MaxParameterCount
= cpu_to_le16(2);
2249 /* BB find exact max on data count below from sess*/
2250 pSMB
->MaxDataCount
= cpu_to_le16(1000);
2251 pSMB
->SetupCount
= 1;
2252 pSMB
->Reserved3
= 0;
2253 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
2254 byte_count
= 3 /* pad */ + params
+ name_len_target
;
2255 pSMB
->ParameterCount
= cpu_to_le16(params
);
2256 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
2257 pSMB
->DataCount
= cpu_to_le16(name_len_target
);
2258 pSMB
->TotalDataCount
= pSMB
->DataCount
;
2259 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
2260 pSMB
->DataOffset
= cpu_to_le16(offset
);
2261 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_UNIX_HLINK
);
2262 pSMB
->Reserved4
= 0;
2263 pSMB
->hdr
.smb_buf_length
+= byte_count
;
2264 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
2265 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
2266 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
2267 cifs_stats_inc(&tcon
->num_hardlinks
);
2269 cFYI(1, ("Send error in SetPathInfo (hard link) = %d", rc
));
2271 cifs_buf_release(pSMB
);
2273 goto createHardLinkRetry
;
2279 CIFSCreateHardLink(const int xid
, struct cifsTconInfo
*tcon
,
2280 const char *fromName
, const char *toName
,
2281 const struct nls_table
*nls_codepage
, int remap
)
2284 NT_RENAME_REQ
*pSMB
= NULL
;
2285 RENAME_RSP
*pSMBr
= NULL
;
2287 int name_len
, name_len2
;
2290 cFYI(1, ("In CIFSCreateHardLink"));
2291 winCreateHardLinkRetry
:
2293 rc
= smb_init(SMB_COM_NT_RENAME
, 4, tcon
, (void **) &pSMB
,
2298 pSMB
->SearchAttributes
=
2299 cpu_to_le16(ATTR_READONLY
| ATTR_HIDDEN
| ATTR_SYSTEM
|
2301 pSMB
->Flags
= cpu_to_le16(CREATE_HARD_LINK
);
2302 pSMB
->ClusterCount
= 0;
2304 pSMB
->BufferFormat
= 0x04;
2306 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
2308 cifsConvertToUCS((__le16
*) pSMB
->OldFileName
, fromName
,
2309 PATH_MAX
, nls_codepage
, remap
);
2310 name_len
++; /* trailing null */
2313 /* protocol specifies ASCII buffer format (0x04) for unicode */
2314 pSMB
->OldFileName
[name_len
] = 0x04;
2315 pSMB
->OldFileName
[name_len
+ 1] = 0x00; /* pad */
2317 cifsConvertToUCS((__le16
*)&pSMB
->OldFileName
[name_len
+ 2],
2318 toName
, PATH_MAX
, nls_codepage
, remap
);
2319 name_len2
+= 1 /* trailing null */ + 1 /* Signature word */ ;
2320 name_len2
*= 2; /* convert to bytes */
2321 } else { /* BB improve the check for buffer overruns BB */
2322 name_len
= strnlen(fromName
, PATH_MAX
);
2323 name_len
++; /* trailing null */
2324 strncpy(pSMB
->OldFileName
, fromName
, name_len
);
2325 name_len2
= strnlen(toName
, PATH_MAX
);
2326 name_len2
++; /* trailing null */
2327 pSMB
->OldFileName
[name_len
] = 0x04; /* 2nd buffer format */
2328 strncpy(&pSMB
->OldFileName
[name_len
+ 1], toName
, name_len2
);
2329 name_len2
++; /* trailing null */
2330 name_len2
++; /* signature byte */
2333 count
= 1 /* string type byte */ + name_len
+ name_len2
;
2334 pSMB
->hdr
.smb_buf_length
+= count
;
2335 pSMB
->ByteCount
= cpu_to_le16(count
);
2337 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
2338 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
2339 cifs_stats_inc(&tcon
->num_hardlinks
);
2341 cFYI(1, ("Send error in hard link (NT rename) = %d", rc
));
2343 cifs_buf_release(pSMB
);
2345 goto winCreateHardLinkRetry
;
2351 CIFSSMBUnixQuerySymLink(const int xid
, struct cifsTconInfo
*tcon
,
2352 const unsigned char *searchName
, char **symlinkinfo
,
2353 const struct nls_table
*nls_codepage
)
2355 /* SMB_QUERY_FILE_UNIX_LINK */
2356 TRANSACTION2_QPI_REQ
*pSMB
= NULL
;
2357 TRANSACTION2_QPI_RSP
*pSMBr
= NULL
;
2361 __u16 params
, byte_count
;
2364 cFYI(1, ("In QPathSymLinkInfo (Unix) for path %s", searchName
));
2367 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
2372 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
2374 cifs_strtoUCS((__le16
*) pSMB
->FileName
, searchName
,
2375 PATH_MAX
, nls_codepage
);
2376 name_len
++; /* trailing null */
2378 } else { /* BB improve the check for buffer overruns BB */
2379 name_len
= strnlen(searchName
, PATH_MAX
);
2380 name_len
++; /* trailing null */
2381 strncpy(pSMB
->FileName
, searchName
, name_len
);
2384 params
= 2 /* level */ + 4 /* rsrvd */ + name_len
/* incl null */ ;
2385 pSMB
->TotalDataCount
= 0;
2386 pSMB
->MaxParameterCount
= cpu_to_le16(2);
2387 pSMB
->MaxDataCount
= cpu_to_le16(CIFSMaxBufSize
);
2388 pSMB
->MaxSetupCount
= 0;
2392 pSMB
->Reserved2
= 0;
2393 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
2394 struct smb_com_transaction2_qpi_req
, InformationLevel
) - 4);
2395 pSMB
->DataCount
= 0;
2396 pSMB
->DataOffset
= 0;
2397 pSMB
->SetupCount
= 1;
2398 pSMB
->Reserved3
= 0;
2399 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION
);
2400 byte_count
= params
+ 1 /* pad */ ;
2401 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
2402 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
2403 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FILE_UNIX_LINK
);
2404 pSMB
->Reserved4
= 0;
2405 pSMB
->hdr
.smb_buf_length
+= byte_count
;
2406 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
2408 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
2409 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
2411 cFYI(1, ("Send error in QuerySymLinkInfo = %d", rc
));
2413 /* decode response */
2415 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
2416 /* BB also check enough total bytes returned */
2417 if (rc
|| (pSMBr
->ByteCount
< 2))
2421 u16 count
= le16_to_cpu(pSMBr
->t2
.DataCount
);
2423 data_start
= ((char *) &pSMBr
->hdr
.Protocol
) +
2424 le16_to_cpu(pSMBr
->t2
.DataOffset
);
2426 if (pSMBr
->hdr
.Flags2
& SMBFLG2_UNICODE
)
2431 /* BB FIXME investigate remapping reserved chars here */
2432 *symlinkinfo
= cifs_strndup_from_ucs(data_start
, count
,
2433 is_unicode
, nls_codepage
);
2438 cifs_buf_release(pSMB
);
2440 goto querySymLinkRetry
;
2444 #ifdef CONFIG_CIFS_EXPERIMENTAL
2445 /* Initialize NT TRANSACT SMB into small smb request buffer.
2446 This assumes that all NT TRANSACTS that we init here have
2447 total parm and data under about 400 bytes (to fit in small cifs
2448 buffer size), which is the case so far, it easily fits. NB:
2449 Setup words themselves and ByteCount
2450 MaxSetupCount (size of returned setup area) and
2451 MaxParameterCount (returned parms size) must be set by caller */
2453 smb_init_nttransact(const __u16 sub_command
, const int setup_count
,
2454 const int parm_len
, struct cifsTconInfo
*tcon
,
2459 struct smb_com_ntransact_req
*pSMB
;
2461 rc
= small_smb_init(SMB_COM_NT_TRANSACT
, 19 + setup_count
, tcon
,
2465 *ret_buf
= (void *)pSMB
;
2467 pSMB
->TotalParameterCount
= cpu_to_le32(parm_len
);
2468 pSMB
->TotalDataCount
= 0;
2469 pSMB
->MaxDataCount
= cpu_to_le32((tcon
->ses
->server
->maxBuf
-
2470 MAX_CIFS_HDR_SIZE
) & 0xFFFFFF00);
2471 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
2472 pSMB
->DataCount
= pSMB
->TotalDataCount
;
2473 temp_offset
= offsetof(struct smb_com_ntransact_req
, Parms
) +
2474 (setup_count
* 2) - 4 /* for rfc1001 length itself */;
2475 pSMB
->ParameterOffset
= cpu_to_le32(temp_offset
);
2476 pSMB
->DataOffset
= cpu_to_le32(temp_offset
+ parm_len
);
2477 pSMB
->SetupCount
= setup_count
; /* no need to le convert byte fields */
2478 pSMB
->SubCommand
= cpu_to_le16(sub_command
);
2483 validate_ntransact(char *buf
, char **ppparm
, char **ppdata
,
2484 __u32
*pparmlen
, __u32
*pdatalen
)
2487 __u32 data_count
, data_offset
, parm_count
, parm_offset
;
2488 struct smb_com_ntransact_rsp
*pSMBr
;
2496 pSMBr
= (struct smb_com_ntransact_rsp
*)buf
;
2498 /* ByteCount was converted from little endian in SendReceive */
2499 end_of_smb
= 2 /* sizeof byte count */ + pSMBr
->ByteCount
+
2500 (char *)&pSMBr
->ByteCount
;
2502 data_offset
= le32_to_cpu(pSMBr
->DataOffset
);
2503 data_count
= le32_to_cpu(pSMBr
->DataCount
);
2504 parm_offset
= le32_to_cpu(pSMBr
->ParameterOffset
);
2505 parm_count
= le32_to_cpu(pSMBr
->ParameterCount
);
2507 *ppparm
= (char *)&pSMBr
->hdr
.Protocol
+ parm_offset
;
2508 *ppdata
= (char *)&pSMBr
->hdr
.Protocol
+ data_offset
;
2510 /* should we also check that parm and data areas do not overlap? */
2511 if (*ppparm
> end_of_smb
) {
2512 cFYI(1, ("parms start after end of smb"));
2514 } else if (parm_count
+ *ppparm
> end_of_smb
) {
2515 cFYI(1, ("parm end after end of smb"));
2517 } else if (*ppdata
> end_of_smb
) {
2518 cFYI(1, ("data starts after end of smb"));
2520 } else if (data_count
+ *ppdata
> end_of_smb
) {
2521 cFYI(1, ("data %p + count %d (%p) ends after end of smb %p start %p",
2522 *ppdata
, data_count
, (data_count
+ *ppdata
),
2523 end_of_smb
, pSMBr
));
2525 } else if (parm_count
+ data_count
> pSMBr
->ByteCount
) {
2526 cFYI(1, ("parm count and data count larger than SMB"));
2529 *pdatalen
= data_count
;
2530 *pparmlen
= parm_count
;
2535 CIFSSMBQueryReparseLinkInfo(const int xid
, struct cifsTconInfo
*tcon
,
2536 const unsigned char *searchName
,
2537 char *symlinkinfo
, const int buflen
, __u16 fid
,
2538 const struct nls_table
*nls_codepage
)
2542 struct smb_com_transaction_ioctl_req
*pSMB
;
2543 struct smb_com_transaction_ioctl_rsp
*pSMBr
;
2545 cFYI(1, ("In Windows reparse style QueryLink for path %s", searchName
));
2546 rc
= smb_init(SMB_COM_NT_TRANSACT
, 23, tcon
, (void **) &pSMB
,
2551 pSMB
->TotalParameterCount
= 0 ;
2552 pSMB
->TotalDataCount
= 0;
2553 pSMB
->MaxParameterCount
= cpu_to_le32(2);
2554 /* BB find exact data count max from sess structure BB */
2555 pSMB
->MaxDataCount
= cpu_to_le32((tcon
->ses
->server
->maxBuf
-
2556 MAX_CIFS_HDR_SIZE
) & 0xFFFFFF00);
2557 pSMB
->MaxSetupCount
= 4;
2559 pSMB
->ParameterOffset
= 0;
2560 pSMB
->DataCount
= 0;
2561 pSMB
->DataOffset
= 0;
2562 pSMB
->SetupCount
= 4;
2563 pSMB
->SubCommand
= cpu_to_le16(NT_TRANSACT_IOCTL
);
2564 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
2565 pSMB
->FunctionCode
= cpu_to_le32(FSCTL_GET_REPARSE_POINT
);
2566 pSMB
->IsFsctl
= 1; /* FSCTL */
2567 pSMB
->IsRootFlag
= 0;
2568 pSMB
->Fid
= fid
; /* file handle always le */
2569 pSMB
->ByteCount
= 0;
2571 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
2572 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
2574 cFYI(1, ("Send error in QueryReparseLinkInfo = %d", rc
));
2575 } else { /* decode response */
2576 __u32 data_offset
= le32_to_cpu(pSMBr
->DataOffset
);
2577 __u32 data_count
= le32_to_cpu(pSMBr
->DataCount
);
2578 if ((pSMBr
->ByteCount
< 2) || (data_offset
> 512)) {
2579 /* BB also check enough total bytes returned */
2580 rc
= -EIO
; /* bad smb */
2583 if (data_count
&& (data_count
< 2048)) {
2584 char *end_of_smb
= 2 /* sizeof byte count */ +
2585 pSMBr
->ByteCount
+ (char *)&pSMBr
->ByteCount
;
2587 struct reparse_data
*reparse_buf
=
2588 (struct reparse_data
*)
2589 ((char *)&pSMBr
->hdr
.Protocol
2591 if ((char *)reparse_buf
>= end_of_smb
) {
2595 if ((reparse_buf
->LinkNamesBuf
+
2596 reparse_buf
->TargetNameOffset
+
2597 reparse_buf
->TargetNameLen
) > end_of_smb
) {
2598 cFYI(1, ("reparse buf beyond SMB"));
2603 if (pSMBr
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
2604 cifs_from_ucs2(symlinkinfo
, (__le16
*)
2605 (reparse_buf
->LinkNamesBuf
+
2606 reparse_buf
->TargetNameOffset
),
2608 reparse_buf
->TargetNameLen
,
2610 } else { /* ASCII names */
2611 strncpy(symlinkinfo
,
2612 reparse_buf
->LinkNamesBuf
+
2613 reparse_buf
->TargetNameOffset
,
2614 min_t(const int, buflen
,
2615 reparse_buf
->TargetNameLen
));
2619 cFYI(1, ("Invalid return data count on "
2620 "get reparse info ioctl"));
2622 symlinkinfo
[buflen
] = 0; /* just in case so the caller
2623 does not go off the end of the buffer */
2624 cFYI(1, ("readlink result - %s", symlinkinfo
));
2628 cifs_buf_release(pSMB
);
2630 /* Note: On -EAGAIN error only caller can retry on handle based calls
2631 since file handle passed in no longer valid */
2635 #endif /* CIFS_EXPERIMENTAL */
2637 #ifdef CONFIG_CIFS_POSIX
2639 /*Convert an Access Control Entry from wire format to local POSIX xattr format*/
2640 static void cifs_convert_ace(posix_acl_xattr_entry
*ace
,
2641 struct cifs_posix_ace
*cifs_ace
)
2643 /* u8 cifs fields do not need le conversion */
2644 ace
->e_perm
= cpu_to_le16(cifs_ace
->cifs_e_perm
);
2645 ace
->e_tag
= cpu_to_le16(cifs_ace
->cifs_e_tag
);
2646 ace
->e_id
= cpu_to_le32(le64_to_cpu(cifs_ace
->cifs_uid
));
2647 /* cFYI(1,("perm %d tag %d id %d",ace->e_perm,ace->e_tag,ace->e_id)); */
2652 /* Convert ACL from CIFS POSIX wire format to local Linux POSIX ACL xattr */
2653 static int cifs_copy_posix_acl(char *trgt
, char *src
, const int buflen
,
2654 const int acl_type
, const int size_of_data_area
)
2659 struct cifs_posix_ace
*pACE
;
2660 struct cifs_posix_acl
*cifs_acl
= (struct cifs_posix_acl
*)src
;
2661 posix_acl_xattr_header
*local_acl
= (posix_acl_xattr_header
*)trgt
;
2663 if (le16_to_cpu(cifs_acl
->version
) != CIFS_ACL_VERSION
)
2666 if (acl_type
& ACL_TYPE_ACCESS
) {
2667 count
= le16_to_cpu(cifs_acl
->access_entry_count
);
2668 pACE
= &cifs_acl
->ace_array
[0];
2669 size
= sizeof(struct cifs_posix_acl
);
2670 size
+= sizeof(struct cifs_posix_ace
) * count
;
2671 /* check if we would go beyond end of SMB */
2672 if (size_of_data_area
< size
) {
2673 cFYI(1, ("bad CIFS POSIX ACL size %d vs. %d",
2674 size_of_data_area
, size
));
2677 } else if (acl_type
& ACL_TYPE_DEFAULT
) {
2678 count
= le16_to_cpu(cifs_acl
->access_entry_count
);
2679 size
= sizeof(struct cifs_posix_acl
);
2680 size
+= sizeof(struct cifs_posix_ace
) * count
;
2681 /* skip past access ACEs to get to default ACEs */
2682 pACE
= &cifs_acl
->ace_array
[count
];
2683 count
= le16_to_cpu(cifs_acl
->default_entry_count
);
2684 size
+= sizeof(struct cifs_posix_ace
) * count
;
2685 /* check if we would go beyond end of SMB */
2686 if (size_of_data_area
< size
)
2693 size
= posix_acl_xattr_size(count
);
2694 if ((buflen
== 0) || (local_acl
== NULL
)) {
2695 /* used to query ACL EA size */
2696 } else if (size
> buflen
) {
2698 } else /* buffer big enough */ {
2699 local_acl
->a_version
= cpu_to_le32(POSIX_ACL_XATTR_VERSION
);
2700 for (i
= 0; i
< count
; i
++) {
2701 cifs_convert_ace(&local_acl
->a_entries
[i
], pACE
);
2708 static __u16
convert_ace_to_cifs_ace(struct cifs_posix_ace
*cifs_ace
,
2709 const posix_acl_xattr_entry
*local_ace
)
2711 __u16 rc
= 0; /* 0 = ACL converted ok */
2713 cifs_ace
->cifs_e_perm
= le16_to_cpu(local_ace
->e_perm
);
2714 cifs_ace
->cifs_e_tag
= le16_to_cpu(local_ace
->e_tag
);
2715 /* BB is there a better way to handle the large uid? */
2716 if (local_ace
->e_id
== cpu_to_le32(-1)) {
2717 /* Probably no need to le convert -1 on any arch but can not hurt */
2718 cifs_ace
->cifs_uid
= cpu_to_le64(-1);
2720 cifs_ace
->cifs_uid
= cpu_to_le64(le32_to_cpu(local_ace
->e_id
));
2721 /*cFYI(1,("perm %d tag %d id %d",ace->e_perm,ace->e_tag,ace->e_id));*/
2725 /* Convert ACL from local Linux POSIX xattr to CIFS POSIX ACL wire format */
2726 static __u16
ACL_to_cifs_posix(char *parm_data
, const char *pACL
,
2727 const int buflen
, const int acl_type
)
2730 struct cifs_posix_acl
*cifs_acl
= (struct cifs_posix_acl
*)parm_data
;
2731 posix_acl_xattr_header
*local_acl
= (posix_acl_xattr_header
*)pACL
;
2735 if ((buflen
== 0) || (pACL
== NULL
) || (cifs_acl
== NULL
))
2738 count
= posix_acl_xattr_count((size_t)buflen
);
2739 cFYI(1, ("setting acl with %d entries from buf of length %d and "
2741 count
, buflen
, le32_to_cpu(local_acl
->a_version
)));
2742 if (le32_to_cpu(local_acl
->a_version
) != 2) {
2743 cFYI(1, ("unknown POSIX ACL version %d",
2744 le32_to_cpu(local_acl
->a_version
)));
2747 cifs_acl
->version
= cpu_to_le16(1);
2748 if (acl_type
== ACL_TYPE_ACCESS
)
2749 cifs_acl
->access_entry_count
= cpu_to_le16(count
);
2750 else if (acl_type
== ACL_TYPE_DEFAULT
)
2751 cifs_acl
->default_entry_count
= cpu_to_le16(count
);
2753 cFYI(1, ("unknown ACL type %d", acl_type
));
2756 for (i
= 0; i
< count
; i
++) {
2757 rc
= convert_ace_to_cifs_ace(&cifs_acl
->ace_array
[i
],
2758 &local_acl
->a_entries
[i
]);
2760 /* ACE not converted */
2765 rc
= (__u16
)(count
* sizeof(struct cifs_posix_ace
));
2766 rc
+= sizeof(struct cifs_posix_acl
);
2767 /* BB add check to make sure ACL does not overflow SMB */
2773 CIFSSMBGetPosixACL(const int xid
, struct cifsTconInfo
*tcon
,
2774 const unsigned char *searchName
,
2775 char *acl_inf
, const int buflen
, const int acl_type
,
2776 const struct nls_table
*nls_codepage
, int remap
)
2778 /* SMB_QUERY_POSIX_ACL */
2779 TRANSACTION2_QPI_REQ
*pSMB
= NULL
;
2780 TRANSACTION2_QPI_RSP
*pSMBr
= NULL
;
2784 __u16 params
, byte_count
;
2786 cFYI(1, ("In GetPosixACL (Unix) for path %s", searchName
));
2789 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
2794 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
2796 cifsConvertToUCS((__le16
*) pSMB
->FileName
, searchName
,
2797 PATH_MAX
, nls_codepage
, remap
);
2798 name_len
++; /* trailing null */
2800 pSMB
->FileName
[name_len
] = 0;
2801 pSMB
->FileName
[name_len
+1] = 0;
2802 } else { /* BB improve the check for buffer overruns BB */
2803 name_len
= strnlen(searchName
, PATH_MAX
);
2804 name_len
++; /* trailing null */
2805 strncpy(pSMB
->FileName
, searchName
, name_len
);
2808 params
= 2 /* level */ + 4 /* rsrvd */ + name_len
/* incl null */ ;
2809 pSMB
->TotalDataCount
= 0;
2810 pSMB
->MaxParameterCount
= cpu_to_le16(2);
2811 /* BB find exact max data count below from sess structure BB */
2812 pSMB
->MaxDataCount
= cpu_to_le16(4000);
2813 pSMB
->MaxSetupCount
= 0;
2817 pSMB
->Reserved2
= 0;
2818 pSMB
->ParameterOffset
= cpu_to_le16(
2819 offsetof(struct smb_com_transaction2_qpi_req
,
2820 InformationLevel
) - 4);
2821 pSMB
->DataCount
= 0;
2822 pSMB
->DataOffset
= 0;
2823 pSMB
->SetupCount
= 1;
2824 pSMB
->Reserved3
= 0;
2825 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION
);
2826 byte_count
= params
+ 1 /* pad */ ;
2827 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
2828 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
2829 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_POSIX_ACL
);
2830 pSMB
->Reserved4
= 0;
2831 pSMB
->hdr
.smb_buf_length
+= byte_count
;
2832 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
2834 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
2835 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
2836 cifs_stats_inc(&tcon
->num_acl_get
);
2838 cFYI(1, ("Send error in Query POSIX ACL = %d", rc
));
2840 /* decode response */
2842 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
2843 if (rc
|| (pSMBr
->ByteCount
< 2))
2844 /* BB also check enough total bytes returned */
2845 rc
= -EIO
; /* bad smb */
2847 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
2848 __u16 count
= le16_to_cpu(pSMBr
->t2
.DataCount
);
2849 rc
= cifs_copy_posix_acl(acl_inf
,
2850 (char *)&pSMBr
->hdr
.Protocol
+data_offset
,
2851 buflen
, acl_type
, count
);
2854 cifs_buf_release(pSMB
);
2861 CIFSSMBSetPosixACL(const int xid
, struct cifsTconInfo
*tcon
,
2862 const unsigned char *fileName
,
2863 const char *local_acl
, const int buflen
,
2865 const struct nls_table
*nls_codepage
, int remap
)
2867 struct smb_com_transaction2_spi_req
*pSMB
= NULL
;
2868 struct smb_com_transaction2_spi_rsp
*pSMBr
= NULL
;
2872 int bytes_returned
= 0;
2873 __u16 params
, byte_count
, data_count
, param_offset
, offset
;
2875 cFYI(1, ("In SetPosixACL (Unix) for path %s", fileName
));
2877 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
2881 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
2883 cifsConvertToUCS((__le16
*) pSMB
->FileName
, fileName
,
2884 PATH_MAX
, nls_codepage
, remap
);
2885 name_len
++; /* trailing null */
2887 } else { /* BB improve the check for buffer overruns BB */
2888 name_len
= strnlen(fileName
, PATH_MAX
);
2889 name_len
++; /* trailing null */
2890 strncpy(pSMB
->FileName
, fileName
, name_len
);
2892 params
= 6 + name_len
;
2893 pSMB
->MaxParameterCount
= cpu_to_le16(2);
2894 /* BB find max SMB size from sess */
2895 pSMB
->MaxDataCount
= cpu_to_le16(1000);
2896 pSMB
->MaxSetupCount
= 0;
2900 pSMB
->Reserved2
= 0;
2901 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
2902 InformationLevel
) - 4;
2903 offset
= param_offset
+ params
;
2904 parm_data
= ((char *) &pSMB
->hdr
.Protocol
) + offset
;
2905 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
2907 /* convert to on the wire format for POSIX ACL */
2908 data_count
= ACL_to_cifs_posix(parm_data
, local_acl
, buflen
, acl_type
);
2910 if (data_count
== 0) {
2912 goto setACLerrorExit
;
2914 pSMB
->DataOffset
= cpu_to_le16(offset
);
2915 pSMB
->SetupCount
= 1;
2916 pSMB
->Reserved3
= 0;
2917 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
2918 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_POSIX_ACL
);
2919 byte_count
= 3 /* pad */ + params
+ data_count
;
2920 pSMB
->DataCount
= cpu_to_le16(data_count
);
2921 pSMB
->TotalDataCount
= pSMB
->DataCount
;
2922 pSMB
->ParameterCount
= cpu_to_le16(params
);
2923 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
2924 pSMB
->Reserved4
= 0;
2925 pSMB
->hdr
.smb_buf_length
+= byte_count
;
2926 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
2927 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
2928 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
2930 cFYI(1, ("Set POSIX ACL returned %d", rc
));
2933 cifs_buf_release(pSMB
);
2939 /* BB fix tabs in this function FIXME BB */
2941 CIFSGetExtAttr(const int xid
, struct cifsTconInfo
*tcon
,
2942 const int netfid
, __u64
*pExtAttrBits
, __u64
*pMask
)
2945 struct smb_t2_qfi_req
*pSMB
= NULL
;
2946 struct smb_t2_qfi_rsp
*pSMBr
= NULL
;
2948 __u16 params
, byte_count
;
2950 cFYI(1, ("In GetExtAttr"));
2955 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
2960 params
= 2 /* level */ + 2 /* fid */;
2961 pSMB
->t2
.TotalDataCount
= 0;
2962 pSMB
->t2
.MaxParameterCount
= cpu_to_le16(4);
2963 /* BB find exact max data count below from sess structure BB */
2964 pSMB
->t2
.MaxDataCount
= cpu_to_le16(4000);
2965 pSMB
->t2
.MaxSetupCount
= 0;
2966 pSMB
->t2
.Reserved
= 0;
2968 pSMB
->t2
.Timeout
= 0;
2969 pSMB
->t2
.Reserved2
= 0;
2970 pSMB
->t2
.ParameterOffset
= cpu_to_le16(offsetof(struct smb_t2_qfi_req
,
2972 pSMB
->t2
.DataCount
= 0;
2973 pSMB
->t2
.DataOffset
= 0;
2974 pSMB
->t2
.SetupCount
= 1;
2975 pSMB
->t2
.Reserved3
= 0;
2976 pSMB
->t2
.SubCommand
= cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION
);
2977 byte_count
= params
+ 1 /* pad */ ;
2978 pSMB
->t2
.TotalParameterCount
= cpu_to_le16(params
);
2979 pSMB
->t2
.ParameterCount
= pSMB
->t2
.TotalParameterCount
;
2980 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_ATTR_FLAGS
);
2983 pSMB
->hdr
.smb_buf_length
+= byte_count
;
2984 pSMB
->t2
.ByteCount
= cpu_to_le16(byte_count
);
2986 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
2987 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
2989 cFYI(1, ("error %d in GetExtAttr", rc
));
2991 /* decode response */
2992 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
2993 if (rc
|| (pSMBr
->ByteCount
< 2))
2994 /* BB also check enough total bytes returned */
2995 /* If rc should we check for EOPNOSUPP and
2996 disable the srvino flag? or in caller? */
2997 rc
= -EIO
; /* bad smb */
2999 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
3000 __u16 count
= le16_to_cpu(pSMBr
->t2
.DataCount
);
3001 struct file_chattr_info
*pfinfo
;
3002 /* BB Do we need a cast or hash here ? */
3004 cFYI(1, ("Illegal size ret in GetExtAttr"));
3008 pfinfo
= (struct file_chattr_info
*)
3009 (data_offset
+ (char *) &pSMBr
->hdr
.Protocol
);
3010 *pExtAttrBits
= le64_to_cpu(pfinfo
->mode
);
3011 *pMask
= le64_to_cpu(pfinfo
->mask
);
3015 cifs_buf_release(pSMB
);
3017 goto GetExtAttrRetry
;
3021 #endif /* CONFIG_POSIX */
3023 #ifdef CONFIG_CIFS_EXPERIMENTAL
3024 /* Get Security Descriptor (by handle) from remote server for a file or dir */
3026 CIFSSMBGetCIFSACL(const int xid
, struct cifsTconInfo
*tcon
, __u16 fid
,
3027 struct cifs_ntsd
**acl_inf
, __u32
*pbuflen
)
3031 QUERY_SEC_DESC_REQ
*pSMB
;
3034 cFYI(1, ("GetCifsACL"));
3039 rc
= smb_init_nttransact(NT_TRANSACT_QUERY_SECURITY_DESC
, 0,
3040 8 /* parm len */, tcon
, (void **) &pSMB
);
3044 pSMB
->MaxParameterCount
= cpu_to_le32(4);
3045 /* BB TEST with big acls that might need to be e.g. larger than 16K */
3046 pSMB
->MaxSetupCount
= 0;
3047 pSMB
->Fid
= fid
; /* file handle always le */
3048 pSMB
->AclFlags
= cpu_to_le32(CIFS_ACL_OWNER
| CIFS_ACL_GROUP
|
3050 pSMB
->ByteCount
= cpu_to_le16(11); /* 3 bytes pad + 8 bytes parm */
3051 pSMB
->hdr
.smb_buf_length
+= 11;
3052 iov
[0].iov_base
= (char *)pSMB
;
3053 iov
[0].iov_len
= pSMB
->hdr
.smb_buf_length
+ 4;
3055 rc
= SendReceive2(xid
, tcon
->ses
, iov
, 1 /* num iovec */, &buf_type
,
3057 cifs_stats_inc(&tcon
->num_acl_get
);
3059 cFYI(1, ("Send error in QuerySecDesc = %d", rc
));
3060 } else { /* decode response */
3064 struct smb_com_ntransact_rsp
*pSMBr
;
3067 /* validate_nttransact */
3068 rc
= validate_ntransact(iov
[0].iov_base
, (char **)&parm
,
3069 &pdata
, &parm_len
, pbuflen
);
3072 pSMBr
= (struct smb_com_ntransact_rsp
*)iov
[0].iov_base
;
3074 cFYI(1, ("smb %p parm %p data %p", pSMBr
, parm
, *acl_inf
));
3076 if (le32_to_cpu(pSMBr
->ParameterCount
) != 4) {
3077 rc
= -EIO
; /* bad smb */
3082 /* BB check that data area is minimum length and as big as acl_len */
3084 acl_len
= le32_to_cpu(*parm
);
3085 if (acl_len
!= *pbuflen
) {
3086 cERROR(1, ("acl length %d does not match %d",
3087 acl_len
, *pbuflen
));
3088 if (*pbuflen
> acl_len
)
3092 /* check if buffer is big enough for the acl
3093 header followed by the smallest SID */
3094 if ((*pbuflen
< sizeof(struct cifs_ntsd
) + 8) ||
3095 (*pbuflen
>= 64 * 1024)) {
3096 cERROR(1, ("bad acl length %d", *pbuflen
));
3100 *acl_inf
= kmalloc(*pbuflen
, GFP_KERNEL
);
3101 if (*acl_inf
== NULL
) {
3105 memcpy(*acl_inf
, pdata
, *pbuflen
);
3109 if (buf_type
== CIFS_SMALL_BUFFER
)
3110 cifs_small_buf_release(iov
[0].iov_base
);
3111 else if (buf_type
== CIFS_LARGE_BUFFER
)
3112 cifs_buf_release(iov
[0].iov_base
);
3113 /* cifs_small_buf_release(pSMB); */ /* Freed earlier now in SendReceive2 */
3118 CIFSSMBSetCIFSACL(const int xid
, struct cifsTconInfo
*tcon
, __u16 fid
,
3119 struct cifs_ntsd
*pntsd
, __u32 acllen
)
3121 __u16 byte_count
, param_count
, data_count
, param_offset
, data_offset
;
3123 int bytes_returned
= 0;
3124 SET_SEC_DESC_REQ
*pSMB
= NULL
;
3125 NTRANSACT_RSP
*pSMBr
= NULL
;
3128 rc
= smb_init(SMB_COM_NT_TRANSACT
, 19, tcon
, (void **) &pSMB
,
3133 pSMB
->MaxSetupCount
= 0;
3137 param_offset
= offsetof(struct smb_com_transaction_ssec_req
, Fid
) - 4;
3138 data_count
= acllen
;
3139 data_offset
= param_offset
+ param_count
;
3140 byte_count
= 3 /* pad */ + param_count
;
3142 pSMB
->DataCount
= cpu_to_le32(data_count
);
3143 pSMB
->TotalDataCount
= pSMB
->DataCount
;
3144 pSMB
->MaxParameterCount
= cpu_to_le32(4);
3145 pSMB
->MaxDataCount
= cpu_to_le32(16384);
3146 pSMB
->ParameterCount
= cpu_to_le32(param_count
);
3147 pSMB
->ParameterOffset
= cpu_to_le32(param_offset
);
3148 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
3149 pSMB
->DataOffset
= cpu_to_le32(data_offset
);
3150 pSMB
->SetupCount
= 0;
3151 pSMB
->SubCommand
= cpu_to_le16(NT_TRANSACT_SET_SECURITY_DESC
);
3152 pSMB
->ByteCount
= cpu_to_le16(byte_count
+data_count
);
3154 pSMB
->Fid
= fid
; /* file handle always le */
3155 pSMB
->Reserved2
= 0;
3156 pSMB
->AclFlags
= cpu_to_le32(CIFS_ACL_DACL
);
3158 if (pntsd
&& acllen
) {
3159 memcpy((char *) &pSMBr
->hdr
.Protocol
+ data_offset
,
3162 pSMB
->hdr
.smb_buf_length
+= (byte_count
+ data_count
);
3165 pSMB
->hdr
.smb_buf_length
+= byte_count
;
3167 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3168 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3170 cFYI(1, ("SetCIFSACL bytes_returned: %d, rc: %d", bytes_returned
, rc
));
3172 cFYI(1, ("Set CIFS ACL returned %d", rc
));
3173 cifs_buf_release(pSMB
);
3176 goto setCifsAclRetry
;
3181 #endif /* CONFIG_CIFS_EXPERIMENTAL */
3183 /* Legacy Query Path Information call for lookup to old servers such
3185 int SMBQueryInformation(const int xid
, struct cifsTconInfo
*tcon
,
3186 const unsigned char *searchName
,
3187 FILE_ALL_INFO
*pFinfo
,
3188 const struct nls_table
*nls_codepage
, int remap
)
3190 QUERY_INFORMATION_REQ
*pSMB
;
3191 QUERY_INFORMATION_RSP
*pSMBr
;
3196 cFYI(1, ("In SMBQPath path %s", searchName
));
3198 rc
= smb_init(SMB_COM_QUERY_INFORMATION
, 0, tcon
, (void **) &pSMB
,
3203 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
3205 cifsConvertToUCS((__le16
*) pSMB
->FileName
, searchName
,
3206 PATH_MAX
, nls_codepage
, remap
);
3207 name_len
++; /* trailing null */
3210 name_len
= strnlen(searchName
, PATH_MAX
);
3211 name_len
++; /* trailing null */
3212 strncpy(pSMB
->FileName
, searchName
, name_len
);
3214 pSMB
->BufferFormat
= 0x04;
3215 name_len
++; /* account for buffer type byte */
3216 pSMB
->hdr
.smb_buf_length
+= (__u16
) name_len
;
3217 pSMB
->ByteCount
= cpu_to_le16(name_len
);
3219 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3220 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3222 cFYI(1, ("Send error in QueryInfo = %d", rc
));
3223 } else if (pFinfo
) {
3225 __u32 time
= le32_to_cpu(pSMBr
->last_write_time
);
3227 /* decode response */
3228 /* BB FIXME - add time zone adjustment BB */
3229 memset(pFinfo
, 0, sizeof(FILE_ALL_INFO
));
3232 /* decode time fields */
3233 pFinfo
->ChangeTime
= cpu_to_le64(cifs_UnixTimeToNT(ts
));
3234 pFinfo
->LastWriteTime
= pFinfo
->ChangeTime
;
3235 pFinfo
->LastAccessTime
= 0;
3236 pFinfo
->AllocationSize
=
3237 cpu_to_le64(le32_to_cpu(pSMBr
->size
));
3238 pFinfo
->EndOfFile
= pFinfo
->AllocationSize
;
3239 pFinfo
->Attributes
=
3240 cpu_to_le32(le16_to_cpu(pSMBr
->attr
));
3242 rc
= -EIO
; /* bad buffer passed in */
3244 cifs_buf_release(pSMB
);
3256 CIFSSMBQPathInfo(const int xid
, struct cifsTconInfo
*tcon
,
3257 const unsigned char *searchName
,
3258 FILE_ALL_INFO
*pFindData
,
3259 int legacy
/* old style infolevel */,
3260 const struct nls_table
*nls_codepage
, int remap
)
3262 /* level 263 SMB_QUERY_FILE_ALL_INFO */
3263 TRANSACTION2_QPI_REQ
*pSMB
= NULL
;
3264 TRANSACTION2_QPI_RSP
*pSMBr
= NULL
;
3268 __u16 params
, byte_count
;
3270 /* cFYI(1, ("In QPathInfo path %s", searchName)); */
3272 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
3277 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
3279 cifsConvertToUCS((__le16
*) pSMB
->FileName
, searchName
,
3280 PATH_MAX
, nls_codepage
, remap
);
3281 name_len
++; /* trailing null */
3283 } else { /* BB improve the check for buffer overruns BB */
3284 name_len
= strnlen(searchName
, PATH_MAX
);
3285 name_len
++; /* trailing null */
3286 strncpy(pSMB
->FileName
, searchName
, name_len
);
3289 params
= 2 /* level */ + 4 /* reserved */ + name_len
/* includes NUL */;
3290 pSMB
->TotalDataCount
= 0;
3291 pSMB
->MaxParameterCount
= cpu_to_le16(2);
3292 /* BB find exact max SMB PDU from sess structure BB */
3293 pSMB
->MaxDataCount
= cpu_to_le16(4000);
3294 pSMB
->MaxSetupCount
= 0;
3298 pSMB
->Reserved2
= 0;
3299 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
3300 struct smb_com_transaction2_qpi_req
, InformationLevel
) - 4);
3301 pSMB
->DataCount
= 0;
3302 pSMB
->DataOffset
= 0;
3303 pSMB
->SetupCount
= 1;
3304 pSMB
->Reserved3
= 0;
3305 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION
);
3306 byte_count
= params
+ 1 /* pad */ ;
3307 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
3308 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
3310 pSMB
->InformationLevel
= cpu_to_le16(SMB_INFO_STANDARD
);
3312 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FILE_ALL_INFO
);
3313 pSMB
->Reserved4
= 0;
3314 pSMB
->hdr
.smb_buf_length
+= byte_count
;
3315 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
3317 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3318 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3320 cFYI(1, ("Send error in QPathInfo = %d", rc
));
3321 } else { /* decode response */
3322 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
3324 if (rc
) /* BB add auto retry on EOPNOTSUPP? */
3326 else if (!legacy
&& (pSMBr
->ByteCount
< 40))
3327 rc
= -EIO
; /* bad smb */
3328 else if (legacy
&& (pSMBr
->ByteCount
< 24))
3329 rc
= -EIO
; /* 24 or 26 expected but we do not read
3331 else if (pFindData
) {
3333 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
3335 /* On legacy responses we do not read the last field,
3336 EAsize, fortunately since it varies by subdialect and
3337 also note it differs on Set vs. Get, ie two bytes or 4
3338 bytes depending but we don't care here */
3340 size
= sizeof(FILE_INFO_STANDARD
);
3342 size
= sizeof(FILE_ALL_INFO
);
3343 memcpy((char *) pFindData
,
3344 (char *) &pSMBr
->hdr
.Protocol
+
3349 cifs_buf_release(pSMB
);
3351 goto QPathInfoRetry
;
3357 CIFSSMBUnixQPathInfo(const int xid
, struct cifsTconInfo
*tcon
,
3358 const unsigned char *searchName
,
3359 FILE_UNIX_BASIC_INFO
*pFindData
,
3360 const struct nls_table
*nls_codepage
, int remap
)
3362 /* SMB_QUERY_FILE_UNIX_BASIC */
3363 TRANSACTION2_QPI_REQ
*pSMB
= NULL
;
3364 TRANSACTION2_QPI_RSP
*pSMBr
= NULL
;
3366 int bytes_returned
= 0;
3368 __u16 params
, byte_count
;
3370 cFYI(1, ("In QPathInfo (Unix) the path %s", searchName
));
3372 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
3377 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
3379 cifsConvertToUCS((__le16
*) pSMB
->FileName
, searchName
,
3380 PATH_MAX
, nls_codepage
, remap
);
3381 name_len
++; /* trailing null */
3383 } else { /* BB improve the check for buffer overruns BB */
3384 name_len
= strnlen(searchName
, PATH_MAX
);
3385 name_len
++; /* trailing null */
3386 strncpy(pSMB
->FileName
, searchName
, name_len
);
3389 params
= 2 /* level */ + 4 /* reserved */ + name_len
/* includes NUL */;
3390 pSMB
->TotalDataCount
= 0;
3391 pSMB
->MaxParameterCount
= cpu_to_le16(2);
3392 /* BB find exact max SMB PDU from sess structure BB */
3393 pSMB
->MaxDataCount
= cpu_to_le16(4000);
3394 pSMB
->MaxSetupCount
= 0;
3398 pSMB
->Reserved2
= 0;
3399 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
3400 struct smb_com_transaction2_qpi_req
, InformationLevel
) - 4);
3401 pSMB
->DataCount
= 0;
3402 pSMB
->DataOffset
= 0;
3403 pSMB
->SetupCount
= 1;
3404 pSMB
->Reserved3
= 0;
3405 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION
);
3406 byte_count
= params
+ 1 /* pad */ ;
3407 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
3408 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
3409 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC
);
3410 pSMB
->Reserved4
= 0;
3411 pSMB
->hdr
.smb_buf_length
+= byte_count
;
3412 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
3414 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3415 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3417 cFYI(1, ("Send error in QPathInfo = %d", rc
));
3418 } else { /* decode response */
3419 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
3421 if (rc
|| (pSMBr
->ByteCount
< sizeof(FILE_UNIX_BASIC_INFO
))) {
3422 cERROR(1, ("Malformed FILE_UNIX_BASIC_INFO response.\n"
3423 "Unix Extensions can be disabled on mount "
3424 "by specifying the nosfu mount option."));
3425 rc
= -EIO
; /* bad smb */
3427 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
3428 memcpy((char *) pFindData
,
3429 (char *) &pSMBr
->hdr
.Protocol
+
3431 sizeof(FILE_UNIX_BASIC_INFO
));
3434 cifs_buf_release(pSMB
);
3436 goto UnixQPathInfoRetry
;
3441 /* xid, tcon, searchName and codepage are input parms, rest are returned */
3443 CIFSFindFirst(const int xid
, struct cifsTconInfo
*tcon
,
3444 const char *searchName
,
3445 const struct nls_table
*nls_codepage
,
3447 struct cifs_search_info
*psrch_inf
, int remap
, const char dirsep
)
3449 /* level 257 SMB_ */
3450 TRANSACTION2_FFIRST_REQ
*pSMB
= NULL
;
3451 TRANSACTION2_FFIRST_RSP
*pSMBr
= NULL
;
3452 T2_FFIRST_RSP_PARMS
*parms
;
3454 int bytes_returned
= 0;
3456 __u16 params
, byte_count
;
3458 cFYI(1, ("In FindFirst for %s", searchName
));
3461 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
3466 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
3468 cifsConvertToUCS((__le16
*) pSMB
->FileName
, searchName
,
3469 PATH_MAX
, nls_codepage
, remap
);
3470 /* We can not add the asterik earlier in case
3471 it got remapped to 0xF03A as if it were part of the
3472 directory name instead of a wildcard */
3474 pSMB
->FileName
[name_len
] = dirsep
;
3475 pSMB
->FileName
[name_len
+1] = 0;
3476 pSMB
->FileName
[name_len
+2] = '*';
3477 pSMB
->FileName
[name_len
+3] = 0;
3478 name_len
+= 4; /* now the trailing null */
3479 pSMB
->FileName
[name_len
] = 0; /* null terminate just in case */
3480 pSMB
->FileName
[name_len
+1] = 0;
3482 } else { /* BB add check for overrun of SMB buf BB */
3483 name_len
= strnlen(searchName
, PATH_MAX
);
3484 /* BB fix here and in unicode clause above ie
3485 if (name_len > buffersize-header)
3486 free buffer exit; BB */
3487 strncpy(pSMB
->FileName
, searchName
, name_len
);
3488 pSMB
->FileName
[name_len
] = dirsep
;
3489 pSMB
->FileName
[name_len
+1] = '*';
3490 pSMB
->FileName
[name_len
+2] = 0;
3494 params
= 12 + name_len
/* includes null */ ;
3495 pSMB
->TotalDataCount
= 0; /* no EAs */
3496 pSMB
->MaxParameterCount
= cpu_to_le16(10);
3497 pSMB
->MaxDataCount
= cpu_to_le16((tcon
->ses
->server
->maxBuf
-
3498 MAX_CIFS_HDR_SIZE
) & 0xFFFFFF00);
3499 pSMB
->MaxSetupCount
= 0;
3503 pSMB
->Reserved2
= 0;
3504 byte_count
= params
+ 1 /* pad */ ;
3505 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
3506 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
3507 pSMB
->ParameterOffset
= cpu_to_le16(
3508 offsetof(struct smb_com_transaction2_ffirst_req
, SearchAttributes
)
3510 pSMB
->DataCount
= 0;
3511 pSMB
->DataOffset
= 0;
3512 pSMB
->SetupCount
= 1; /* one byte, no need to make endian neutral */
3513 pSMB
->Reserved3
= 0;
3514 pSMB
->SubCommand
= cpu_to_le16(TRANS2_FIND_FIRST
);
3515 pSMB
->SearchAttributes
=
3516 cpu_to_le16(ATTR_READONLY
| ATTR_HIDDEN
| ATTR_SYSTEM
|
3518 pSMB
->SearchCount
= cpu_to_le16(CIFSMaxBufSize
/sizeof(FILE_UNIX_INFO
));
3519 pSMB
->SearchFlags
= cpu_to_le16(CIFS_SEARCH_CLOSE_AT_END
|
3520 CIFS_SEARCH_RETURN_RESUME
);
3521 pSMB
->InformationLevel
= cpu_to_le16(psrch_inf
->info_level
);
3523 /* BB what should we set StorageType to? Does it matter? BB */
3524 pSMB
->SearchStorageType
= 0;
3525 pSMB
->hdr
.smb_buf_length
+= byte_count
;
3526 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
3528 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3529 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3530 cifs_stats_inc(&tcon
->num_ffirst
);
3532 if (rc
) {/* BB add logic to retry regular search if Unix search
3533 rejected unexpectedly by server */
3534 /* BB Add code to handle unsupported level rc */
3535 cFYI(1, ("Error in FindFirst = %d", rc
));
3537 cifs_buf_release(pSMB
);
3539 /* BB eventually could optimize out free and realloc of buf */
3542 goto findFirstRetry
;
3543 } else { /* decode response */
3544 /* BB remember to free buffer if error BB */
3545 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
3549 if (pSMBr
->hdr
.Flags2
& SMBFLG2_UNICODE
)
3550 psrch_inf
->unicode
= true;
3552 psrch_inf
->unicode
= false;
3554 psrch_inf
->ntwrk_buf_start
= (char *)pSMBr
;
3555 psrch_inf
->smallBuf
= 0;
3556 psrch_inf
->srch_entries_start
=
3557 (char *) &pSMBr
->hdr
.Protocol
+
3558 le16_to_cpu(pSMBr
->t2
.DataOffset
);
3559 parms
= (T2_FFIRST_RSP_PARMS
*)((char *) &pSMBr
->hdr
.Protocol
+
3560 le16_to_cpu(pSMBr
->t2
.ParameterOffset
));
3562 if (parms
->EndofSearch
)
3563 psrch_inf
->endOfSearch
= true;
3565 psrch_inf
->endOfSearch
= false;
3567 psrch_inf
->entries_in_buffer
=
3568 le16_to_cpu(parms
->SearchCount
);
3569 psrch_inf
->index_of_last_entry
= 2 /* skip . and .. */ +
3570 psrch_inf
->entries_in_buffer
;
3571 lnoff
= le16_to_cpu(parms
->LastNameOffset
);
3572 if (tcon
->ses
->server
->maxBuf
- MAX_CIFS_HDR_SIZE
<
3574 cERROR(1, ("ignoring corrupt resume name"));
3575 psrch_inf
->last_entry
= NULL
;
3579 psrch_inf
->last_entry
= psrch_inf
->srch_entries_start
+
3582 *pnetfid
= parms
->SearchHandle
;
3584 cifs_buf_release(pSMB
);
3591 int CIFSFindNext(const int xid
, struct cifsTconInfo
*tcon
,
3592 __u16 searchHandle
, struct cifs_search_info
*psrch_inf
)
3594 TRANSACTION2_FNEXT_REQ
*pSMB
= NULL
;
3595 TRANSACTION2_FNEXT_RSP
*pSMBr
= NULL
;
3596 T2_FNEXT_RSP_PARMS
*parms
;
3597 char *response_data
;
3600 unsigned int name_len
;
3601 __u16 params
, byte_count
;
3603 cFYI(1, ("In FindNext"));
3605 if (psrch_inf
->endOfSearch
)
3608 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
3613 params
= 14; /* includes 2 bytes of null string, converted to LE below*/
3615 pSMB
->TotalDataCount
= 0; /* no EAs */
3616 pSMB
->MaxParameterCount
= cpu_to_le16(8);
3617 pSMB
->MaxDataCount
=
3618 cpu_to_le16((tcon
->ses
->server
->maxBuf
- MAX_CIFS_HDR_SIZE
) &
3620 pSMB
->MaxSetupCount
= 0;
3624 pSMB
->Reserved2
= 0;
3625 pSMB
->ParameterOffset
= cpu_to_le16(
3626 offsetof(struct smb_com_transaction2_fnext_req
,SearchHandle
) - 4);
3627 pSMB
->DataCount
= 0;
3628 pSMB
->DataOffset
= 0;
3629 pSMB
->SetupCount
= 1;
3630 pSMB
->Reserved3
= 0;
3631 pSMB
->SubCommand
= cpu_to_le16(TRANS2_FIND_NEXT
);
3632 pSMB
->SearchHandle
= searchHandle
; /* always kept as le */
3634 cpu_to_le16(CIFSMaxBufSize
/ sizeof(FILE_UNIX_INFO
));
3635 pSMB
->InformationLevel
= cpu_to_le16(psrch_inf
->info_level
);
3636 pSMB
->ResumeKey
= psrch_inf
->resume_key
;
3638 cpu_to_le16(CIFS_SEARCH_CLOSE_AT_END
| CIFS_SEARCH_RETURN_RESUME
);
3640 name_len
= psrch_inf
->resume_name_len
;
3642 if (name_len
< PATH_MAX
) {
3643 memcpy(pSMB
->ResumeFileName
, psrch_inf
->presume_name
, name_len
);
3644 byte_count
+= name_len
;
3645 /* 14 byte parm len above enough for 2 byte null terminator */
3646 pSMB
->ResumeFileName
[name_len
] = 0;
3647 pSMB
->ResumeFileName
[name_len
+1] = 0;
3650 goto FNext2_err_exit
;
3652 byte_count
= params
+ 1 /* pad */ ;
3653 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
3654 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
3655 pSMB
->hdr
.smb_buf_length
+= byte_count
;
3656 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
3658 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3659 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3660 cifs_stats_inc(&tcon
->num_fnext
);
3663 psrch_inf
->endOfSearch
= true;
3664 cifs_buf_release(pSMB
);
3665 rc
= 0; /* search probably was closed at end of search*/
3667 cFYI(1, ("FindNext returned = %d", rc
));
3668 } else { /* decode response */
3669 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
3674 /* BB fixme add lock for file (srch_info) struct here */
3675 if (pSMBr
->hdr
.Flags2
& SMBFLG2_UNICODE
)
3676 psrch_inf
->unicode
= true;
3678 psrch_inf
->unicode
= false;
3679 response_data
= (char *) &pSMBr
->hdr
.Protocol
+
3680 le16_to_cpu(pSMBr
->t2
.ParameterOffset
);
3681 parms
= (T2_FNEXT_RSP_PARMS
*)response_data
;
3682 response_data
= (char *)&pSMBr
->hdr
.Protocol
+
3683 le16_to_cpu(pSMBr
->t2
.DataOffset
);
3684 if (psrch_inf
->smallBuf
)
3685 cifs_small_buf_release(
3686 psrch_inf
->ntwrk_buf_start
);
3688 cifs_buf_release(psrch_inf
->ntwrk_buf_start
);
3689 psrch_inf
->srch_entries_start
= response_data
;
3690 psrch_inf
->ntwrk_buf_start
= (char *)pSMB
;
3691 psrch_inf
->smallBuf
= 0;
3692 if (parms
->EndofSearch
)
3693 psrch_inf
->endOfSearch
= true;
3695 psrch_inf
->endOfSearch
= false;
3696 psrch_inf
->entries_in_buffer
=
3697 le16_to_cpu(parms
->SearchCount
);
3698 psrch_inf
->index_of_last_entry
+=
3699 psrch_inf
->entries_in_buffer
;
3700 lnoff
= le16_to_cpu(parms
->LastNameOffset
);
3701 if (tcon
->ses
->server
->maxBuf
- MAX_CIFS_HDR_SIZE
<
3703 cERROR(1, ("ignoring corrupt resume name"));
3704 psrch_inf
->last_entry
= NULL
;
3707 psrch_inf
->last_entry
=
3708 psrch_inf
->srch_entries_start
+ lnoff
;
3710 /* cFYI(1,("fnxt2 entries in buf %d index_of_last %d",
3711 psrch_inf->entries_in_buffer, psrch_inf->index_of_last_entry)); */
3713 /* BB fixme add unlock here */
3718 /* BB On error, should we leave previous search buf (and count and
3719 last entry fields) intact or free the previous one? */
3721 /* Note: On -EAGAIN error only caller can retry on handle based calls
3722 since file handle passed in no longer valid */
3725 cifs_buf_release(pSMB
);
3730 CIFSFindClose(const int xid
, struct cifsTconInfo
*tcon
,
3731 const __u16 searchHandle
)
3734 FINDCLOSE_REQ
*pSMB
= NULL
;
3736 cFYI(1, ("In CIFSSMBFindClose"));
3737 rc
= small_smb_init(SMB_COM_FIND_CLOSE2
, 1, tcon
, (void **)&pSMB
);
3739 /* no sense returning error if session restarted
3740 as file handle has been closed */
3746 pSMB
->FileID
= searchHandle
;
3747 pSMB
->ByteCount
= 0;
3748 rc
= SendReceiveNoRsp(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
, 0);
3750 cERROR(1, ("Send error in FindClose = %d", rc
));
3752 cifs_stats_inc(&tcon
->num_fclose
);
3754 /* Since session is dead, search handle closed on server already */
3762 CIFSGetSrvInodeNumber(const int xid
, struct cifsTconInfo
*tcon
,
3763 const unsigned char *searchName
,
3764 __u64
*inode_number
,
3765 const struct nls_table
*nls_codepage
, int remap
)
3768 TRANSACTION2_QPI_REQ
*pSMB
= NULL
;
3769 TRANSACTION2_QPI_RSP
*pSMBr
= NULL
;
3770 int name_len
, bytes_returned
;
3771 __u16 params
, byte_count
;
3773 cFYI(1, ("In GetSrvInodeNum for %s", searchName
));
3777 GetInodeNumberRetry
:
3778 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
3783 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
3785 cifsConvertToUCS((__le16
*) pSMB
->FileName
, searchName
,
3786 PATH_MAX
, nls_codepage
, remap
);
3787 name_len
++; /* trailing null */
3789 } else { /* BB improve the check for buffer overruns BB */
3790 name_len
= strnlen(searchName
, PATH_MAX
);
3791 name_len
++; /* trailing null */
3792 strncpy(pSMB
->FileName
, searchName
, name_len
);
3795 params
= 2 /* level */ + 4 /* rsrvd */ + name_len
/* incl null */ ;
3796 pSMB
->TotalDataCount
= 0;
3797 pSMB
->MaxParameterCount
= cpu_to_le16(2);
3798 /* BB find exact max data count below from sess structure BB */
3799 pSMB
->MaxDataCount
= cpu_to_le16(4000);
3800 pSMB
->MaxSetupCount
= 0;
3804 pSMB
->Reserved2
= 0;
3805 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
3806 struct smb_com_transaction2_qpi_req
, InformationLevel
) - 4);
3807 pSMB
->DataCount
= 0;
3808 pSMB
->DataOffset
= 0;
3809 pSMB
->SetupCount
= 1;
3810 pSMB
->Reserved3
= 0;
3811 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION
);
3812 byte_count
= params
+ 1 /* pad */ ;
3813 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
3814 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
3815 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FILE_INTERNAL_INFO
);
3816 pSMB
->Reserved4
= 0;
3817 pSMB
->hdr
.smb_buf_length
+= byte_count
;
3818 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
3820 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
3821 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
3823 cFYI(1, ("error %d in QueryInternalInfo", rc
));
3825 /* decode response */
3826 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
3827 if (rc
|| (pSMBr
->ByteCount
< 2))
3828 /* BB also check enough total bytes returned */
3829 /* If rc should we check for EOPNOSUPP and
3830 disable the srvino flag? or in caller? */
3831 rc
= -EIO
; /* bad smb */
3833 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
3834 __u16 count
= le16_to_cpu(pSMBr
->t2
.DataCount
);
3835 struct file_internal_info
*pfinfo
;
3836 /* BB Do we need a cast or hash here ? */
3838 cFYI(1, ("Illegal size ret in QryIntrnlInf"));
3840 goto GetInodeNumOut
;
3842 pfinfo
= (struct file_internal_info
*)
3843 (data_offset
+ (char *) &pSMBr
->hdr
.Protocol
);
3844 *inode_number
= le64_to_cpu(pfinfo
->UniqueId
);
3848 cifs_buf_release(pSMB
);
3850 goto GetInodeNumberRetry
;
3854 /* parses DFS refferal V3 structure
3855 * caller is responsible for freeing target_nodes
3858 * on failure - errno
3861 parse_DFS_referrals(TRANSACTION2_GET_DFS_REFER_RSP
*pSMBr
,
3862 unsigned int *num_of_nodes
,
3863 struct dfs_info3_param
**target_nodes
,
3864 const struct nls_table
*nls_codepage
, int remap
,
3865 const char *searchName
)
3870 struct dfs_referral_level_3
*ref
;
3872 if (pSMBr
->hdr
.Flags2
& SMBFLG2_UNICODE
)
3876 *num_of_nodes
= le16_to_cpu(pSMBr
->NumberOfReferrals
);
3878 if (*num_of_nodes
< 1) {
3879 cERROR(1, ("num_referrals: must be at least > 0,"
3880 "but we get num_referrals = %d\n", *num_of_nodes
));
3882 goto parse_DFS_referrals_exit
;
3885 ref
= (struct dfs_referral_level_3
*) &(pSMBr
->referrals
);
3886 if (ref
->VersionNumber
!= cpu_to_le16(3)) {
3887 cERROR(1, ("Referrals of V%d version are not supported,"
3888 "should be V3", le16_to_cpu(ref
->VersionNumber
)));
3890 goto parse_DFS_referrals_exit
;
3893 /* get the upper boundary of the resp buffer */
3894 data_end
= (char *)(&(pSMBr
->PathConsumed
)) +
3895 le16_to_cpu(pSMBr
->t2
.DataCount
);
3897 cFYI(1, ("num_referrals: %d dfs flags: 0x%x ... \n",
3899 le32_to_cpu(pSMBr
->DFSFlags
)));
3901 *target_nodes
= kzalloc(sizeof(struct dfs_info3_param
) *
3902 *num_of_nodes
, GFP_KERNEL
);
3903 if (*target_nodes
== NULL
) {
3904 cERROR(1, ("Failed to allocate buffer for target_nodes\n"));
3906 goto parse_DFS_referrals_exit
;
3909 /* collect neccessary data from referrals */
3910 for (i
= 0; i
< *num_of_nodes
; i
++) {
3913 struct dfs_info3_param
*node
= (*target_nodes
)+i
;
3915 node
->flags
= le32_to_cpu(pSMBr
->DFSFlags
);
3917 __le16
*tmp
= kmalloc(strlen(searchName
)*2 + 2,
3921 goto parse_DFS_referrals_exit
;
3923 cifsConvertToUCS((__le16
*) tmp
, searchName
,
3924 PATH_MAX
, nls_codepage
, remap
);
3925 node
->path_consumed
= cifs_ucs2_bytes(tmp
,
3926 le16_to_cpu(pSMBr
->PathConsumed
),
3930 node
->path_consumed
= le16_to_cpu(pSMBr
->PathConsumed
);
3932 node
->server_type
= le16_to_cpu(ref
->ServerType
);
3933 node
->ref_flag
= le16_to_cpu(ref
->ReferralEntryFlags
);
3936 temp
= (char *)ref
+ le16_to_cpu(ref
->DfsPathOffset
);
3937 max_len
= data_end
- temp
;
3938 node
->path_name
= cifs_strndup_from_ucs(temp
, max_len
,
3939 is_unicode
, nls_codepage
);
3940 if (!node
->path_name
) {
3942 goto parse_DFS_referrals_exit
;
3945 /* copy link target UNC */
3946 temp
= (char *)ref
+ le16_to_cpu(ref
->NetworkAddressOffset
);
3947 max_len
= data_end
- temp
;
3948 node
->node_name
= cifs_strndup_from_ucs(temp
, max_len
,
3949 is_unicode
, nls_codepage
);
3950 if (!node
->node_name
)
3954 parse_DFS_referrals_exit
:
3956 free_dfs_info_array(*target_nodes
, *num_of_nodes
);
3957 *target_nodes
= NULL
;
3964 CIFSGetDFSRefer(const int xid
, struct cifsSesInfo
*ses
,
3965 const unsigned char *searchName
,
3966 struct dfs_info3_param
**target_nodes
,
3967 unsigned int *num_of_nodes
,
3968 const struct nls_table
*nls_codepage
, int remap
)
3970 /* TRANS2_GET_DFS_REFERRAL */
3971 TRANSACTION2_GET_DFS_REFER_REQ
*pSMB
= NULL
;
3972 TRANSACTION2_GET_DFS_REFER_RSP
*pSMBr
= NULL
;
3976 __u16 params
, byte_count
;
3978 *target_nodes
= NULL
;
3980 cFYI(1, ("In GetDFSRefer the path %s", searchName
));
3984 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, NULL
, (void **) &pSMB
,
3989 /* server pointer checked in called function,
3990 but should never be null here anyway */
3991 pSMB
->hdr
.Mid
= GetNextMid(ses
->server
);
3992 pSMB
->hdr
.Tid
= ses
->ipc_tid
;
3993 pSMB
->hdr
.Uid
= ses
->Suid
;
3994 if (ses
->capabilities
& CAP_STATUS32
)
3995 pSMB
->hdr
.Flags2
|= SMBFLG2_ERR_STATUS
;
3996 if (ses
->capabilities
& CAP_DFS
)
3997 pSMB
->hdr
.Flags2
|= SMBFLG2_DFS
;
3999 if (ses
->capabilities
& CAP_UNICODE
) {
4000 pSMB
->hdr
.Flags2
|= SMBFLG2_UNICODE
;
4002 cifsConvertToUCS((__le16
*) pSMB
->RequestFileName
,
4003 searchName
, PATH_MAX
, nls_codepage
, remap
);
4004 name_len
++; /* trailing null */
4006 } else { /* BB improve the check for buffer overruns BB */
4007 name_len
= strnlen(searchName
, PATH_MAX
);
4008 name_len
++; /* trailing null */
4009 strncpy(pSMB
->RequestFileName
, searchName
, name_len
);
4013 if (ses
->server
->secMode
&
4014 (SECMODE_SIGN_REQUIRED
| SECMODE_SIGN_ENABLED
))
4015 pSMB
->hdr
.Flags2
|= SMBFLG2_SECURITY_SIGNATURE
;
4018 pSMB
->hdr
.Uid
= ses
->Suid
;
4020 params
= 2 /* level */ + name_len
/*includes null */ ;
4021 pSMB
->TotalDataCount
= 0;
4022 pSMB
->DataCount
= 0;
4023 pSMB
->DataOffset
= 0;
4024 pSMB
->MaxParameterCount
= 0;
4025 /* BB find exact max SMB PDU from sess structure BB */
4026 pSMB
->MaxDataCount
= cpu_to_le16(4000);
4027 pSMB
->MaxSetupCount
= 0;
4031 pSMB
->Reserved2
= 0;
4032 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
4033 struct smb_com_transaction2_get_dfs_refer_req
, MaxReferralLevel
) - 4);
4034 pSMB
->SetupCount
= 1;
4035 pSMB
->Reserved3
= 0;
4036 pSMB
->SubCommand
= cpu_to_le16(TRANS2_GET_DFS_REFERRAL
);
4037 byte_count
= params
+ 3 /* pad */ ;
4038 pSMB
->ParameterCount
= cpu_to_le16(params
);
4039 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
4040 pSMB
->MaxReferralLevel
= cpu_to_le16(3);
4041 pSMB
->hdr
.smb_buf_length
+= byte_count
;
4042 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4044 rc
= SendReceive(xid
, ses
, (struct smb_hdr
*) pSMB
,
4045 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4047 cFYI(1, ("Send error in GetDFSRefer = %d", rc
));
4050 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
4052 /* BB Also check if enough total bytes returned? */
4053 if (rc
|| (pSMBr
->ByteCount
< 17)) {
4054 rc
= -EIO
; /* bad smb */
4058 cFYI(1, ("Decoding GetDFSRefer response BCC: %d Offset %d",
4060 le16_to_cpu(pSMBr
->t2
.DataOffset
)));
4062 /* parse returned result into more usable form */
4063 rc
= parse_DFS_referrals(pSMBr
, num_of_nodes
,
4064 target_nodes
, nls_codepage
, remap
,
4068 cifs_buf_release(pSMB
);
4076 /* Query File System Info such as free space to old servers such as Win 9x */
4078 SMBOldQFSInfo(const int xid
, struct cifsTconInfo
*tcon
, struct kstatfs
*FSData
)
4080 /* level 0x01 SMB_QUERY_FILE_SYSTEM_INFO */
4081 TRANSACTION2_QFSI_REQ
*pSMB
= NULL
;
4082 TRANSACTION2_QFSI_RSP
*pSMBr
= NULL
;
4083 FILE_SYSTEM_ALLOC_INFO
*response_data
;
4085 int bytes_returned
= 0;
4086 __u16 params
, byte_count
;
4088 cFYI(1, ("OldQFSInfo"));
4090 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4095 params
= 2; /* level */
4096 pSMB
->TotalDataCount
= 0;
4097 pSMB
->MaxParameterCount
= cpu_to_le16(2);
4098 pSMB
->MaxDataCount
= cpu_to_le16(1000);
4099 pSMB
->MaxSetupCount
= 0;
4103 pSMB
->Reserved2
= 0;
4104 byte_count
= params
+ 1 /* pad */ ;
4105 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
4106 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
4107 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
4108 struct smb_com_transaction2_qfsi_req
, InformationLevel
) - 4);
4109 pSMB
->DataCount
= 0;
4110 pSMB
->DataOffset
= 0;
4111 pSMB
->SetupCount
= 1;
4112 pSMB
->Reserved3
= 0;
4113 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_FS_INFORMATION
);
4114 pSMB
->InformationLevel
= cpu_to_le16(SMB_INFO_ALLOCATION
);
4115 pSMB
->hdr
.smb_buf_length
+= byte_count
;
4116 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4118 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4119 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4121 cFYI(1, ("Send error in QFSInfo = %d", rc
));
4122 } else { /* decode response */
4123 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
4125 if (rc
|| (pSMBr
->ByteCount
< 18))
4126 rc
= -EIO
; /* bad smb */
4128 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
4129 cFYI(1, ("qfsinf resp BCC: %d Offset %d",
4130 pSMBr
->ByteCount
, data_offset
));
4132 response_data
= (FILE_SYSTEM_ALLOC_INFO
*)
4133 (((char *) &pSMBr
->hdr
.Protocol
) + data_offset
);
4135 le16_to_cpu(response_data
->BytesPerSector
) *
4136 le32_to_cpu(response_data
->
4137 SectorsPerAllocationUnit
);
4139 le32_to_cpu(response_data
->TotalAllocationUnits
);
4140 FSData
->f_bfree
= FSData
->f_bavail
=
4141 le32_to_cpu(response_data
->FreeAllocationUnits
);
4143 ("Blocks: %lld Free: %lld Block size %ld",
4144 (unsigned long long)FSData
->f_blocks
,
4145 (unsigned long long)FSData
->f_bfree
,
4149 cifs_buf_release(pSMB
);
4152 goto oldQFSInfoRetry
;
4158 CIFSSMBQFSInfo(const int xid
, struct cifsTconInfo
*tcon
, struct kstatfs
*FSData
)
4160 /* level 0x103 SMB_QUERY_FILE_SYSTEM_INFO */
4161 TRANSACTION2_QFSI_REQ
*pSMB
= NULL
;
4162 TRANSACTION2_QFSI_RSP
*pSMBr
= NULL
;
4163 FILE_SYSTEM_INFO
*response_data
;
4165 int bytes_returned
= 0;
4166 __u16 params
, byte_count
;
4168 cFYI(1, ("In QFSInfo"));
4170 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4175 params
= 2; /* level */
4176 pSMB
->TotalDataCount
= 0;
4177 pSMB
->MaxParameterCount
= cpu_to_le16(2);
4178 pSMB
->MaxDataCount
= cpu_to_le16(1000);
4179 pSMB
->MaxSetupCount
= 0;
4183 pSMB
->Reserved2
= 0;
4184 byte_count
= params
+ 1 /* pad */ ;
4185 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
4186 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
4187 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
4188 struct smb_com_transaction2_qfsi_req
, InformationLevel
) - 4);
4189 pSMB
->DataCount
= 0;
4190 pSMB
->DataOffset
= 0;
4191 pSMB
->SetupCount
= 1;
4192 pSMB
->Reserved3
= 0;
4193 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_FS_INFORMATION
);
4194 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FS_SIZE_INFO
);
4195 pSMB
->hdr
.smb_buf_length
+= byte_count
;
4196 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4198 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4199 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4201 cFYI(1, ("Send error in QFSInfo = %d", rc
));
4202 } else { /* decode response */
4203 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
4205 if (rc
|| (pSMBr
->ByteCount
< 24))
4206 rc
= -EIO
; /* bad smb */
4208 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
4212 *) (((char *) &pSMBr
->hdr
.Protocol
) +
4215 le32_to_cpu(response_data
->BytesPerSector
) *
4216 le32_to_cpu(response_data
->
4217 SectorsPerAllocationUnit
);
4219 le64_to_cpu(response_data
->TotalAllocationUnits
);
4220 FSData
->f_bfree
= FSData
->f_bavail
=
4221 le64_to_cpu(response_data
->FreeAllocationUnits
);
4223 ("Blocks: %lld Free: %lld Block size %ld",
4224 (unsigned long long)FSData
->f_blocks
,
4225 (unsigned long long)FSData
->f_bfree
,
4229 cifs_buf_release(pSMB
);
4238 CIFSSMBQFSAttributeInfo(const int xid
, struct cifsTconInfo
*tcon
)
4240 /* level 0x105 SMB_QUERY_FILE_SYSTEM_INFO */
4241 TRANSACTION2_QFSI_REQ
*pSMB
= NULL
;
4242 TRANSACTION2_QFSI_RSP
*pSMBr
= NULL
;
4243 FILE_SYSTEM_ATTRIBUTE_INFO
*response_data
;
4245 int bytes_returned
= 0;
4246 __u16 params
, byte_count
;
4248 cFYI(1, ("In QFSAttributeInfo"));
4250 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4255 params
= 2; /* level */
4256 pSMB
->TotalDataCount
= 0;
4257 pSMB
->MaxParameterCount
= cpu_to_le16(2);
4258 /* BB find exact max SMB PDU from sess structure BB */
4259 pSMB
->MaxDataCount
= cpu_to_le16(1000);
4260 pSMB
->MaxSetupCount
= 0;
4264 pSMB
->Reserved2
= 0;
4265 byte_count
= params
+ 1 /* pad */ ;
4266 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
4267 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
4268 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
4269 struct smb_com_transaction2_qfsi_req
, InformationLevel
) - 4);
4270 pSMB
->DataCount
= 0;
4271 pSMB
->DataOffset
= 0;
4272 pSMB
->SetupCount
= 1;
4273 pSMB
->Reserved3
= 0;
4274 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_FS_INFORMATION
);
4275 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FS_ATTRIBUTE_INFO
);
4276 pSMB
->hdr
.smb_buf_length
+= byte_count
;
4277 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4279 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4280 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4282 cERROR(1, ("Send error in QFSAttributeInfo = %d", rc
));
4283 } else { /* decode response */
4284 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
4286 if (rc
|| (pSMBr
->ByteCount
< 13)) {
4287 /* BB also check if enough bytes returned */
4288 rc
= -EIO
; /* bad smb */
4290 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
4292 (FILE_SYSTEM_ATTRIBUTE_INFO
4293 *) (((char *) &pSMBr
->hdr
.Protocol
) +
4295 memcpy(&tcon
->fsAttrInfo
, response_data
,
4296 sizeof(FILE_SYSTEM_ATTRIBUTE_INFO
));
4299 cifs_buf_release(pSMB
);
4302 goto QFSAttributeRetry
;
4308 CIFSSMBQFSDeviceInfo(const int xid
, struct cifsTconInfo
*tcon
)
4310 /* level 0x104 SMB_QUERY_FILE_SYSTEM_INFO */
4311 TRANSACTION2_QFSI_REQ
*pSMB
= NULL
;
4312 TRANSACTION2_QFSI_RSP
*pSMBr
= NULL
;
4313 FILE_SYSTEM_DEVICE_INFO
*response_data
;
4315 int bytes_returned
= 0;
4316 __u16 params
, byte_count
;
4318 cFYI(1, ("In QFSDeviceInfo"));
4320 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4325 params
= 2; /* level */
4326 pSMB
->TotalDataCount
= 0;
4327 pSMB
->MaxParameterCount
= cpu_to_le16(2);
4328 /* BB find exact max SMB PDU from sess structure BB */
4329 pSMB
->MaxDataCount
= cpu_to_le16(1000);
4330 pSMB
->MaxSetupCount
= 0;
4334 pSMB
->Reserved2
= 0;
4335 byte_count
= params
+ 1 /* pad */ ;
4336 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
4337 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
4338 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
4339 struct smb_com_transaction2_qfsi_req
, InformationLevel
) - 4);
4341 pSMB
->DataCount
= 0;
4342 pSMB
->DataOffset
= 0;
4343 pSMB
->SetupCount
= 1;
4344 pSMB
->Reserved3
= 0;
4345 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_FS_INFORMATION
);
4346 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_FS_DEVICE_INFO
);
4347 pSMB
->hdr
.smb_buf_length
+= byte_count
;
4348 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4350 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4351 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4353 cFYI(1, ("Send error in QFSDeviceInfo = %d", rc
));
4354 } else { /* decode response */
4355 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
4357 if (rc
|| (pSMBr
->ByteCount
< sizeof(FILE_SYSTEM_DEVICE_INFO
)))
4358 rc
= -EIO
; /* bad smb */
4360 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
4362 (FILE_SYSTEM_DEVICE_INFO
*)
4363 (((char *) &pSMBr
->hdr
.Protocol
) +
4365 memcpy(&tcon
->fsDevInfo
, response_data
,
4366 sizeof(FILE_SYSTEM_DEVICE_INFO
));
4369 cifs_buf_release(pSMB
);
4372 goto QFSDeviceRetry
;
4378 CIFSSMBQFSUnixInfo(const int xid
, struct cifsTconInfo
*tcon
)
4380 /* level 0x200 SMB_QUERY_CIFS_UNIX_INFO */
4381 TRANSACTION2_QFSI_REQ
*pSMB
= NULL
;
4382 TRANSACTION2_QFSI_RSP
*pSMBr
= NULL
;
4383 FILE_SYSTEM_UNIX_INFO
*response_data
;
4385 int bytes_returned
= 0;
4386 __u16 params
, byte_count
;
4388 cFYI(1, ("In QFSUnixInfo"));
4390 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4395 params
= 2; /* level */
4396 pSMB
->TotalDataCount
= 0;
4397 pSMB
->DataCount
= 0;
4398 pSMB
->DataOffset
= 0;
4399 pSMB
->MaxParameterCount
= cpu_to_le16(2);
4400 /* BB find exact max SMB PDU from sess structure BB */
4401 pSMB
->MaxDataCount
= cpu_to_le16(100);
4402 pSMB
->MaxSetupCount
= 0;
4406 pSMB
->Reserved2
= 0;
4407 byte_count
= params
+ 1 /* pad */ ;
4408 pSMB
->ParameterCount
= cpu_to_le16(params
);
4409 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
4410 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(struct
4411 smb_com_transaction2_qfsi_req
, InformationLevel
) - 4);
4412 pSMB
->SetupCount
= 1;
4413 pSMB
->Reserved3
= 0;
4414 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_FS_INFORMATION
);
4415 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_CIFS_UNIX_INFO
);
4416 pSMB
->hdr
.smb_buf_length
+= byte_count
;
4417 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4419 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4420 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4422 cERROR(1, ("Send error in QFSUnixInfo = %d", rc
));
4423 } else { /* decode response */
4424 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
4426 if (rc
|| (pSMBr
->ByteCount
< 13)) {
4427 rc
= -EIO
; /* bad smb */
4429 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
4431 (FILE_SYSTEM_UNIX_INFO
4432 *) (((char *) &pSMBr
->hdr
.Protocol
) +
4434 memcpy(&tcon
->fsUnixInfo
, response_data
,
4435 sizeof(FILE_SYSTEM_UNIX_INFO
));
4438 cifs_buf_release(pSMB
);
4448 CIFSSMBSetFSUnixInfo(const int xid
, struct cifsTconInfo
*tcon
, __u64 cap
)
4450 /* level 0x200 SMB_SET_CIFS_UNIX_INFO */
4451 TRANSACTION2_SETFSI_REQ
*pSMB
= NULL
;
4452 TRANSACTION2_SETFSI_RSP
*pSMBr
= NULL
;
4454 int bytes_returned
= 0;
4455 __u16 params
, param_offset
, offset
, byte_count
;
4457 cFYI(1, ("In SETFSUnixInfo"));
4459 /* BB switch to small buf init to save memory */
4460 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4465 params
= 4; /* 2 bytes zero followed by info level. */
4466 pSMB
->MaxSetupCount
= 0;
4470 pSMB
->Reserved2
= 0;
4471 param_offset
= offsetof(struct smb_com_transaction2_setfsi_req
, FileNum
)
4473 offset
= param_offset
+ params
;
4475 pSMB
->MaxParameterCount
= cpu_to_le16(4);
4476 /* BB find exact max SMB PDU from sess structure BB */
4477 pSMB
->MaxDataCount
= cpu_to_le16(100);
4478 pSMB
->SetupCount
= 1;
4479 pSMB
->Reserved3
= 0;
4480 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_FS_INFORMATION
);
4481 byte_count
= 1 /* pad */ + params
+ 12;
4483 pSMB
->DataCount
= cpu_to_le16(12);
4484 pSMB
->ParameterCount
= cpu_to_le16(params
);
4485 pSMB
->TotalDataCount
= pSMB
->DataCount
;
4486 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
4487 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
4488 pSMB
->DataOffset
= cpu_to_le16(offset
);
4492 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_CIFS_UNIX_INFO
);
4495 pSMB
->ClientUnixMajor
= cpu_to_le16(CIFS_UNIX_MAJOR_VERSION
);
4496 pSMB
->ClientUnixMinor
= cpu_to_le16(CIFS_UNIX_MINOR_VERSION
);
4497 pSMB
->ClientUnixCap
= cpu_to_le64(cap
);
4499 pSMB
->hdr
.smb_buf_length
+= byte_count
;
4500 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4502 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4503 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4505 cERROR(1, ("Send error in SETFSUnixInfo = %d", rc
));
4506 } else { /* decode response */
4507 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
4509 rc
= -EIO
; /* bad smb */
4511 cifs_buf_release(pSMB
);
4514 goto SETFSUnixRetry
;
4522 CIFSSMBQFSPosixInfo(const int xid
, struct cifsTconInfo
*tcon
,
4523 struct kstatfs
*FSData
)
4525 /* level 0x201 SMB_QUERY_CIFS_POSIX_INFO */
4526 TRANSACTION2_QFSI_REQ
*pSMB
= NULL
;
4527 TRANSACTION2_QFSI_RSP
*pSMBr
= NULL
;
4528 FILE_SYSTEM_POSIX_INFO
*response_data
;
4530 int bytes_returned
= 0;
4531 __u16 params
, byte_count
;
4533 cFYI(1, ("In QFSPosixInfo"));
4535 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4540 params
= 2; /* level */
4541 pSMB
->TotalDataCount
= 0;
4542 pSMB
->DataCount
= 0;
4543 pSMB
->DataOffset
= 0;
4544 pSMB
->MaxParameterCount
= cpu_to_le16(2);
4545 /* BB find exact max SMB PDU from sess structure BB */
4546 pSMB
->MaxDataCount
= cpu_to_le16(100);
4547 pSMB
->MaxSetupCount
= 0;
4551 pSMB
->Reserved2
= 0;
4552 byte_count
= params
+ 1 /* pad */ ;
4553 pSMB
->ParameterCount
= cpu_to_le16(params
);
4554 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
4555 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(struct
4556 smb_com_transaction2_qfsi_req
, InformationLevel
) - 4);
4557 pSMB
->SetupCount
= 1;
4558 pSMB
->Reserved3
= 0;
4559 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_FS_INFORMATION
);
4560 pSMB
->InformationLevel
= cpu_to_le16(SMB_QUERY_POSIX_FS_INFO
);
4561 pSMB
->hdr
.smb_buf_length
+= byte_count
;
4562 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4564 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4565 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4567 cFYI(1, ("Send error in QFSUnixInfo = %d", rc
));
4568 } else { /* decode response */
4569 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
4571 if (rc
|| (pSMBr
->ByteCount
< 13)) {
4572 rc
= -EIO
; /* bad smb */
4574 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
4576 (FILE_SYSTEM_POSIX_INFO
4577 *) (((char *) &pSMBr
->hdr
.Protocol
) +
4580 le32_to_cpu(response_data
->BlockSize
);
4582 le64_to_cpu(response_data
->TotalBlocks
);
4584 le64_to_cpu(response_data
->BlocksAvail
);
4585 if (response_data
->UserBlocksAvail
== cpu_to_le64(-1)) {
4586 FSData
->f_bavail
= FSData
->f_bfree
;
4589 le64_to_cpu(response_data
->UserBlocksAvail
);
4591 if (response_data
->TotalFileNodes
!= cpu_to_le64(-1))
4593 le64_to_cpu(response_data
->TotalFileNodes
);
4594 if (response_data
->FreeFileNodes
!= cpu_to_le64(-1))
4596 le64_to_cpu(response_data
->FreeFileNodes
);
4599 cifs_buf_release(pSMB
);
4608 /* We can not use write of zero bytes trick to
4609 set file size due to need for large file support. Also note that
4610 this SetPathInfo is preferred to SetFileInfo based method in next
4611 routine which is only needed to work around a sharing violation bug
4612 in Samba which this routine can run into */
4615 CIFSSMBSetEOF(const int xid
, struct cifsTconInfo
*tcon
, const char *fileName
,
4616 __u64 size
, bool SetAllocation
,
4617 const struct nls_table
*nls_codepage
, int remap
)
4619 struct smb_com_transaction2_spi_req
*pSMB
= NULL
;
4620 struct smb_com_transaction2_spi_rsp
*pSMBr
= NULL
;
4621 struct file_end_of_file_info
*parm_data
;
4624 int bytes_returned
= 0;
4625 __u16 params
, byte_count
, data_count
, param_offset
, offset
;
4627 cFYI(1, ("In SetEOF"));
4629 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4634 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
4636 cifsConvertToUCS((__le16
*) pSMB
->FileName
, fileName
,
4637 PATH_MAX
, nls_codepage
, remap
);
4638 name_len
++; /* trailing null */
4640 } else { /* BB improve the check for buffer overruns BB */
4641 name_len
= strnlen(fileName
, PATH_MAX
);
4642 name_len
++; /* trailing null */
4643 strncpy(pSMB
->FileName
, fileName
, name_len
);
4645 params
= 6 + name_len
;
4646 data_count
= sizeof(struct file_end_of_file_info
);
4647 pSMB
->MaxParameterCount
= cpu_to_le16(2);
4648 pSMB
->MaxDataCount
= cpu_to_le16(4100);
4649 pSMB
->MaxSetupCount
= 0;
4653 pSMB
->Reserved2
= 0;
4654 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
4655 InformationLevel
) - 4;
4656 offset
= param_offset
+ params
;
4657 if (SetAllocation
) {
4658 if (tcon
->ses
->capabilities
& CAP_INFOLEVEL_PASSTHRU
)
4659 pSMB
->InformationLevel
=
4660 cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2
);
4662 pSMB
->InformationLevel
=
4663 cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO
);
4664 } else /* Set File Size */ {
4665 if (tcon
->ses
->capabilities
& CAP_INFOLEVEL_PASSTHRU
)
4666 pSMB
->InformationLevel
=
4667 cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2
);
4669 pSMB
->InformationLevel
=
4670 cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO
);
4674 (struct file_end_of_file_info
*) (((char *) &pSMB
->hdr
.Protocol
) +
4676 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
4677 pSMB
->DataOffset
= cpu_to_le16(offset
);
4678 pSMB
->SetupCount
= 1;
4679 pSMB
->Reserved3
= 0;
4680 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
4681 byte_count
= 3 /* pad */ + params
+ data_count
;
4682 pSMB
->DataCount
= cpu_to_le16(data_count
);
4683 pSMB
->TotalDataCount
= pSMB
->DataCount
;
4684 pSMB
->ParameterCount
= cpu_to_le16(params
);
4685 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
4686 pSMB
->Reserved4
= 0;
4687 pSMB
->hdr
.smb_buf_length
+= byte_count
;
4688 parm_data
->FileSize
= cpu_to_le64(size
);
4689 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4690 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4691 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4693 cFYI(1, ("SetPathInfo (file size) returned %d", rc
));
4695 cifs_buf_release(pSMB
);
4704 CIFSSMBSetFileSize(const int xid
, struct cifsTconInfo
*tcon
, __u64 size
,
4705 __u16 fid
, __u32 pid_of_opener
, bool SetAllocation
)
4707 struct smb_com_transaction2_sfi_req
*pSMB
= NULL
;
4709 struct file_end_of_file_info
*parm_data
;
4711 __u16 params
, param_offset
, offset
, byte_count
, count
;
4713 cFYI(1, ("SetFileSize (via SetFileInfo) %lld",
4715 rc
= small_smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
);
4720 pSMB
->hdr
.Pid
= cpu_to_le16((__u16
)pid_of_opener
);
4721 pSMB
->hdr
.PidHigh
= cpu_to_le16((__u16
)(pid_of_opener
>> 16));
4724 pSMB
->MaxSetupCount
= 0;
4728 pSMB
->Reserved2
= 0;
4729 param_offset
= offsetof(struct smb_com_transaction2_sfi_req
, Fid
) - 4;
4730 offset
= param_offset
+ params
;
4732 data_offset
= (char *) (&pSMB
->hdr
.Protocol
) + offset
;
4734 count
= sizeof(struct file_end_of_file_info
);
4735 pSMB
->MaxParameterCount
= cpu_to_le16(2);
4736 /* BB find exact max SMB PDU from sess structure BB */
4737 pSMB
->MaxDataCount
= cpu_to_le16(1000);
4738 pSMB
->SetupCount
= 1;
4739 pSMB
->Reserved3
= 0;
4740 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_FILE_INFORMATION
);
4741 byte_count
= 3 /* pad */ + params
+ count
;
4742 pSMB
->DataCount
= cpu_to_le16(count
);
4743 pSMB
->ParameterCount
= cpu_to_le16(params
);
4744 pSMB
->TotalDataCount
= pSMB
->DataCount
;
4745 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
4746 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
4748 (struct file_end_of_file_info
*) (((char *) &pSMB
->hdr
.Protocol
)
4750 pSMB
->DataOffset
= cpu_to_le16(offset
);
4751 parm_data
->FileSize
= cpu_to_le64(size
);
4753 if (SetAllocation
) {
4754 if (tcon
->ses
->capabilities
& CAP_INFOLEVEL_PASSTHRU
)
4755 pSMB
->InformationLevel
=
4756 cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2
);
4758 pSMB
->InformationLevel
=
4759 cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO
);
4760 } else /* Set File Size */ {
4761 if (tcon
->ses
->capabilities
& CAP_INFOLEVEL_PASSTHRU
)
4762 pSMB
->InformationLevel
=
4763 cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2
);
4765 pSMB
->InformationLevel
=
4766 cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO
);
4768 pSMB
->Reserved4
= 0;
4769 pSMB
->hdr
.smb_buf_length
+= byte_count
;
4770 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4771 rc
= SendReceiveNoRsp(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
, 0);
4774 ("Send error in SetFileInfo (SetFileSize) = %d",
4778 /* Note: On -EAGAIN error only caller can retry on handle based calls
4779 since file handle passed in no longer valid */
4784 /* Some legacy servers such as NT4 require that the file times be set on
4785 an open handle, rather than by pathname - this is awkward due to
4786 potential access conflicts on the open, but it is unavoidable for these
4787 old servers since the only other choice is to go from 100 nanosecond DCE
4788 time and resort to the original setpathinfo level which takes the ancient
4789 DOS time format with 2 second granularity */
4791 CIFSSMBSetFileInfo(const int xid
, struct cifsTconInfo
*tcon
,
4792 const FILE_BASIC_INFO
*data
, __u16 fid
, __u32 pid_of_opener
)
4794 struct smb_com_transaction2_sfi_req
*pSMB
= NULL
;
4797 __u16 params
, param_offset
, offset
, byte_count
, count
;
4799 cFYI(1, ("Set Times (via SetFileInfo)"));
4800 rc
= small_smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
);
4805 pSMB
->hdr
.Pid
= cpu_to_le16((__u16
)pid_of_opener
);
4806 pSMB
->hdr
.PidHigh
= cpu_to_le16((__u16
)(pid_of_opener
>> 16));
4809 pSMB
->MaxSetupCount
= 0;
4813 pSMB
->Reserved2
= 0;
4814 param_offset
= offsetof(struct smb_com_transaction2_sfi_req
, Fid
) - 4;
4815 offset
= param_offset
+ params
;
4817 data_offset
= (char *) (&pSMB
->hdr
.Protocol
) + offset
;
4819 count
= sizeof(FILE_BASIC_INFO
);
4820 pSMB
->MaxParameterCount
= cpu_to_le16(2);
4821 /* BB find max SMB PDU from sess */
4822 pSMB
->MaxDataCount
= cpu_to_le16(1000);
4823 pSMB
->SetupCount
= 1;
4824 pSMB
->Reserved3
= 0;
4825 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_FILE_INFORMATION
);
4826 byte_count
= 3 /* pad */ + params
+ count
;
4827 pSMB
->DataCount
= cpu_to_le16(count
);
4828 pSMB
->ParameterCount
= cpu_to_le16(params
);
4829 pSMB
->TotalDataCount
= pSMB
->DataCount
;
4830 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
4831 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
4832 pSMB
->DataOffset
= cpu_to_le16(offset
);
4834 if (tcon
->ses
->capabilities
& CAP_INFOLEVEL_PASSTHRU
)
4835 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_BASIC_INFO2
);
4837 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_BASIC_INFO
);
4838 pSMB
->Reserved4
= 0;
4839 pSMB
->hdr
.smb_buf_length
+= byte_count
;
4840 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4841 memcpy(data_offset
, data
, sizeof(FILE_BASIC_INFO
));
4842 rc
= SendReceiveNoRsp(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
, 0);
4844 cFYI(1, ("Send error in Set Time (SetFileInfo) = %d", rc
));
4846 /* Note: On -EAGAIN error only caller can retry on handle based calls
4847 since file handle passed in no longer valid */
4853 CIFSSMBSetFileDisposition(const int xid
, struct cifsTconInfo
*tcon
,
4854 bool delete_file
, __u16 fid
, __u32 pid_of_opener
)
4856 struct smb_com_transaction2_sfi_req
*pSMB
= NULL
;
4859 __u16 params
, param_offset
, offset
, byte_count
, count
;
4861 cFYI(1, ("Set File Disposition (via SetFileInfo)"));
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
;
4882 pSMB
->MaxParameterCount
= cpu_to_le16(2);
4883 /* BB find max SMB PDU from sess */
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
);
4894 pSMB
->DataOffset
= cpu_to_le16(offset
);
4896 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_DISPOSITION_INFO
);
4897 pSMB
->Reserved4
= 0;
4898 pSMB
->hdr
.smb_buf_length
+= byte_count
;
4899 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4900 *data_offset
= delete_file
? 1 : 0;
4901 rc
= SendReceiveNoRsp(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
, 0);
4903 cFYI(1, ("Send error in SetFileDisposition = %d", rc
));
4909 CIFSSMBSetPathInfo(const int xid
, struct cifsTconInfo
*tcon
,
4910 const char *fileName
, const FILE_BASIC_INFO
*data
,
4911 const struct nls_table
*nls_codepage
, int remap
)
4913 TRANSACTION2_SPI_REQ
*pSMB
= NULL
;
4914 TRANSACTION2_SPI_RSP
*pSMBr
= NULL
;
4917 int bytes_returned
= 0;
4919 __u16 params
, param_offset
, offset
, byte_count
, count
;
4921 cFYI(1, ("In SetTimes"));
4924 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
4929 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
4931 cifsConvertToUCS((__le16
*) pSMB
->FileName
, fileName
,
4932 PATH_MAX
, nls_codepage
, remap
);
4933 name_len
++; /* trailing null */
4935 } else { /* BB improve the check for buffer overruns BB */
4936 name_len
= strnlen(fileName
, PATH_MAX
);
4937 name_len
++; /* trailing null */
4938 strncpy(pSMB
->FileName
, fileName
, name_len
);
4941 params
= 6 + name_len
;
4942 count
= sizeof(FILE_BASIC_INFO
);
4943 pSMB
->MaxParameterCount
= cpu_to_le16(2);
4944 /* BB find max SMB PDU from sess structure BB */
4945 pSMB
->MaxDataCount
= cpu_to_le16(1000);
4946 pSMB
->MaxSetupCount
= 0;
4950 pSMB
->Reserved2
= 0;
4951 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
4952 InformationLevel
) - 4;
4953 offset
= param_offset
+ params
;
4954 data_offset
= (char *) (&pSMB
->hdr
.Protocol
) + offset
;
4955 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
4956 pSMB
->DataOffset
= cpu_to_le16(offset
);
4957 pSMB
->SetupCount
= 1;
4958 pSMB
->Reserved3
= 0;
4959 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
4960 byte_count
= 3 /* pad */ + params
+ count
;
4962 pSMB
->DataCount
= cpu_to_le16(count
);
4963 pSMB
->ParameterCount
= cpu_to_le16(params
);
4964 pSMB
->TotalDataCount
= pSMB
->DataCount
;
4965 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
4966 if (tcon
->ses
->capabilities
& CAP_INFOLEVEL_PASSTHRU
)
4967 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_BASIC_INFO2
);
4969 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_BASIC_INFO
);
4970 pSMB
->Reserved4
= 0;
4971 pSMB
->hdr
.smb_buf_length
+= byte_count
;
4972 memcpy(data_offset
, data
, sizeof(FILE_BASIC_INFO
));
4973 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
4974 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
4975 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
4977 cFYI(1, ("SetPathInfo (times) returned %d", rc
));
4979 cifs_buf_release(pSMB
);
4987 /* Can not be used to set time stamps yet (due to old DOS time format) */
4988 /* Can be used to set attributes */
4989 #if 0 /* Possibly not needed - since it turns out that strangely NT4 has a bug
4990 handling it anyway and NT4 was what we thought it would be needed for
4991 Do not delete it until we prove whether needed for Win9x though */
4993 CIFSSMBSetAttrLegacy(int xid
, struct cifsTconInfo
*tcon
, char *fileName
,
4994 __u16 dos_attrs
, const struct nls_table
*nls_codepage
)
4996 SETATTR_REQ
*pSMB
= NULL
;
4997 SETATTR_RSP
*pSMBr
= NULL
;
5002 cFYI(1, ("In SetAttrLegacy"));
5005 rc
= smb_init(SMB_COM_SETATTR
, 8, tcon
, (void **) &pSMB
,
5010 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
5012 ConvertToUCS((__le16
*) pSMB
->fileName
, fileName
,
5013 PATH_MAX
, nls_codepage
);
5014 name_len
++; /* trailing null */
5016 } else { /* BB improve the check for buffer overruns BB */
5017 name_len
= strnlen(fileName
, PATH_MAX
);
5018 name_len
++; /* trailing null */
5019 strncpy(pSMB
->fileName
, fileName
, name_len
);
5021 pSMB
->attr
= cpu_to_le16(dos_attrs
);
5022 pSMB
->BufferFormat
= 0x04;
5023 pSMB
->hdr
.smb_buf_length
+= name_len
+ 1;
5024 pSMB
->ByteCount
= cpu_to_le16(name_len
+ 1);
5025 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
5026 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
5028 cFYI(1, ("Error in LegacySetAttr = %d", rc
));
5030 cifs_buf_release(pSMB
);
5033 goto SetAttrLgcyRetry
;
5037 #endif /* temporarily unneeded SetAttr legacy function */
5040 cifs_fill_unix_set_info(FILE_UNIX_BASIC_INFO
*data_offset
,
5041 const struct cifs_unix_set_info_args
*args
)
5043 u64 mode
= args
->mode
;
5046 * Samba server ignores set of file size to zero due to bugs in some
5047 * older clients, but we should be precise - we use SetFileSize to
5048 * set file size and do not want to truncate file size to zero
5049 * accidently as happened on one Samba server beta by putting
5050 * zero instead of -1 here
5052 data_offset
->EndOfFile
= cpu_to_le64(NO_CHANGE_64
);
5053 data_offset
->NumOfBytes
= cpu_to_le64(NO_CHANGE_64
);
5054 data_offset
->LastStatusChange
= cpu_to_le64(args
->ctime
);
5055 data_offset
->LastAccessTime
= cpu_to_le64(args
->atime
);
5056 data_offset
->LastModificationTime
= cpu_to_le64(args
->mtime
);
5057 data_offset
->Uid
= cpu_to_le64(args
->uid
);
5058 data_offset
->Gid
= cpu_to_le64(args
->gid
);
5059 /* better to leave device as zero when it is */
5060 data_offset
->DevMajor
= cpu_to_le64(MAJOR(args
->device
));
5061 data_offset
->DevMinor
= cpu_to_le64(MINOR(args
->device
));
5062 data_offset
->Permissions
= cpu_to_le64(mode
);
5065 data_offset
->Type
= cpu_to_le32(UNIX_FILE
);
5066 else if (S_ISDIR(mode
))
5067 data_offset
->Type
= cpu_to_le32(UNIX_DIR
);
5068 else if (S_ISLNK(mode
))
5069 data_offset
->Type
= cpu_to_le32(UNIX_SYMLINK
);
5070 else if (S_ISCHR(mode
))
5071 data_offset
->Type
= cpu_to_le32(UNIX_CHARDEV
);
5072 else if (S_ISBLK(mode
))
5073 data_offset
->Type
= cpu_to_le32(UNIX_BLOCKDEV
);
5074 else if (S_ISFIFO(mode
))
5075 data_offset
->Type
= cpu_to_le32(UNIX_FIFO
);
5076 else if (S_ISSOCK(mode
))
5077 data_offset
->Type
= cpu_to_le32(UNIX_SOCKET
);
5081 CIFSSMBUnixSetFileInfo(const int xid
, struct cifsTconInfo
*tcon
,
5082 const struct cifs_unix_set_info_args
*args
,
5083 u16 fid
, u32 pid_of_opener
)
5085 struct smb_com_transaction2_sfi_req
*pSMB
= NULL
;
5086 FILE_UNIX_BASIC_INFO
*data_offset
;
5088 u16 params
, param_offset
, offset
, byte_count
, count
;
5090 cFYI(1, ("Set Unix Info (via SetFileInfo)"));
5091 rc
= small_smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
);
5096 pSMB
->hdr
.Pid
= cpu_to_le16((__u16
)pid_of_opener
);
5097 pSMB
->hdr
.PidHigh
= cpu_to_le16((__u16
)(pid_of_opener
>> 16));
5100 pSMB
->MaxSetupCount
= 0;
5104 pSMB
->Reserved2
= 0;
5105 param_offset
= offsetof(struct smb_com_transaction2_sfi_req
, Fid
) - 4;
5106 offset
= param_offset
+ params
;
5108 data_offset
= (FILE_UNIX_BASIC_INFO
*)
5109 ((char *)(&pSMB
->hdr
.Protocol
) + offset
);
5110 count
= sizeof(FILE_UNIX_BASIC_INFO
);
5112 pSMB
->MaxParameterCount
= cpu_to_le16(2);
5113 /* BB find max SMB PDU from sess */
5114 pSMB
->MaxDataCount
= cpu_to_le16(1000);
5115 pSMB
->SetupCount
= 1;
5116 pSMB
->Reserved3
= 0;
5117 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_FILE_INFORMATION
);
5118 byte_count
= 3 /* pad */ + params
+ count
;
5119 pSMB
->DataCount
= cpu_to_le16(count
);
5120 pSMB
->ParameterCount
= cpu_to_le16(params
);
5121 pSMB
->TotalDataCount
= pSMB
->DataCount
;
5122 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
5123 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
5124 pSMB
->DataOffset
= cpu_to_le16(offset
);
5126 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_UNIX_BASIC
);
5127 pSMB
->Reserved4
= 0;
5128 pSMB
->hdr
.smb_buf_length
+= byte_count
;
5129 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
5131 cifs_fill_unix_set_info(data_offset
, args
);
5133 rc
= SendReceiveNoRsp(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
, 0);
5135 cFYI(1, ("Send error in Set Time (SetFileInfo) = %d", rc
));
5137 /* Note: On -EAGAIN error only caller can retry on handle based calls
5138 since file handle passed in no longer valid */
5144 CIFSSMBUnixSetPathInfo(const int xid
, struct cifsTconInfo
*tcon
, char *fileName
,
5145 const struct cifs_unix_set_info_args
*args
,
5146 const struct nls_table
*nls_codepage
, int remap
)
5148 TRANSACTION2_SPI_REQ
*pSMB
= NULL
;
5149 TRANSACTION2_SPI_RSP
*pSMBr
= NULL
;
5152 int bytes_returned
= 0;
5153 FILE_UNIX_BASIC_INFO
*data_offset
;
5154 __u16 params
, param_offset
, offset
, count
, byte_count
;
5156 cFYI(1, ("In SetUID/GID/Mode"));
5158 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
5163 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
5165 cifsConvertToUCS((__le16
*) pSMB
->FileName
, fileName
,
5166 PATH_MAX
, nls_codepage
, remap
);
5167 name_len
++; /* trailing null */
5169 } else { /* BB improve the check for buffer overruns BB */
5170 name_len
= strnlen(fileName
, PATH_MAX
);
5171 name_len
++; /* trailing null */
5172 strncpy(pSMB
->FileName
, fileName
, name_len
);
5175 params
= 6 + name_len
;
5176 count
= sizeof(FILE_UNIX_BASIC_INFO
);
5177 pSMB
->MaxParameterCount
= cpu_to_le16(2);
5178 /* BB find max SMB PDU from sess structure BB */
5179 pSMB
->MaxDataCount
= cpu_to_le16(1000);
5180 pSMB
->MaxSetupCount
= 0;
5184 pSMB
->Reserved2
= 0;
5185 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
5186 InformationLevel
) - 4;
5187 offset
= param_offset
+ params
;
5189 (FILE_UNIX_BASIC_INFO
*) ((char *) &pSMB
->hdr
.Protocol
+
5191 memset(data_offset
, 0, count
);
5192 pSMB
->DataOffset
= cpu_to_le16(offset
);
5193 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
5194 pSMB
->SetupCount
= 1;
5195 pSMB
->Reserved3
= 0;
5196 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
5197 byte_count
= 3 /* pad */ + params
+ count
;
5198 pSMB
->ParameterCount
= cpu_to_le16(params
);
5199 pSMB
->DataCount
= cpu_to_le16(count
);
5200 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
5201 pSMB
->TotalDataCount
= pSMB
->DataCount
;
5202 pSMB
->InformationLevel
= cpu_to_le16(SMB_SET_FILE_UNIX_BASIC
);
5203 pSMB
->Reserved4
= 0;
5204 pSMB
->hdr
.smb_buf_length
+= byte_count
;
5206 cifs_fill_unix_set_info(data_offset
, args
);
5208 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
5209 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
5210 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
5212 cFYI(1, ("SetPathInfo (perms) returned %d", rc
));
5214 cifs_buf_release(pSMB
);
5220 int CIFSSMBNotify(const int xid
, struct cifsTconInfo
*tcon
,
5221 const int notify_subdirs
, const __u16 netfid
,
5222 __u32 filter
, struct file
*pfile
, int multishot
,
5223 const struct nls_table
*nls_codepage
)
5226 struct smb_com_transaction_change_notify_req
*pSMB
= NULL
;
5227 struct smb_com_ntransaction_change_notify_rsp
*pSMBr
= NULL
;
5228 struct dir_notify_req
*dnotify_req
;
5231 cFYI(1, ("In CIFSSMBNotify for file handle %d", (int)netfid
));
5232 rc
= smb_init(SMB_COM_NT_TRANSACT
, 23, tcon
, (void **) &pSMB
,
5237 pSMB
->TotalParameterCount
= 0 ;
5238 pSMB
->TotalDataCount
= 0;
5239 pSMB
->MaxParameterCount
= cpu_to_le32(2);
5240 /* BB find exact data count max from sess structure BB */
5241 pSMB
->MaxDataCount
= 0; /* same in little endian or be */
5242 /* BB VERIFY verify which is correct for above BB */
5243 pSMB
->MaxDataCount
= cpu_to_le32((tcon
->ses
->server
->maxBuf
-
5244 MAX_CIFS_HDR_SIZE
) & 0xFFFFFF00);
5246 pSMB
->MaxSetupCount
= 4;
5248 pSMB
->ParameterOffset
= 0;
5249 pSMB
->DataCount
= 0;
5250 pSMB
->DataOffset
= 0;
5251 pSMB
->SetupCount
= 4; /* single byte does not need le conversion */
5252 pSMB
->SubCommand
= cpu_to_le16(NT_TRANSACT_NOTIFY_CHANGE
);
5253 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
5255 pSMB
->WatchTree
= 1; /* one byte - no le conversion needed */
5256 pSMB
->Reserved2
= 0;
5257 pSMB
->CompletionFilter
= cpu_to_le32(filter
);
5258 pSMB
->Fid
= netfid
; /* file handle always le */
5259 pSMB
->ByteCount
= 0;
5261 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
5262 (struct smb_hdr
*)pSMBr
, &bytes_returned
,
5265 cFYI(1, ("Error in Notify = %d", rc
));
5267 /* Add file to outstanding requests */
5268 /* BB change to kmem cache alloc */
5269 dnotify_req
= kmalloc(
5270 sizeof(struct dir_notify_req
),
5273 dnotify_req
->Pid
= pSMB
->hdr
.Pid
;
5274 dnotify_req
->PidHigh
= pSMB
->hdr
.PidHigh
;
5275 dnotify_req
->Mid
= pSMB
->hdr
.Mid
;
5276 dnotify_req
->Tid
= pSMB
->hdr
.Tid
;
5277 dnotify_req
->Uid
= pSMB
->hdr
.Uid
;
5278 dnotify_req
->netfid
= netfid
;
5279 dnotify_req
->pfile
= pfile
;
5280 dnotify_req
->filter
= filter
;
5281 dnotify_req
->multishot
= multishot
;
5282 spin_lock(&GlobalMid_Lock
);
5283 list_add_tail(&dnotify_req
->lhead
,
5284 &GlobalDnotifyReqList
);
5285 spin_unlock(&GlobalMid_Lock
);
5289 cifs_buf_release(pSMB
);
5292 #ifdef CONFIG_CIFS_XATTR
5294 CIFSSMBQAllEAs(const int xid
, struct cifsTconInfo
*tcon
,
5295 const unsigned char *searchName
,
5296 char *EAData
, size_t buf_size
,
5297 const struct nls_table
*nls_codepage
, int remap
)
5299 /* BB assumes one setup word */
5300 TRANSACTION2_QPI_REQ
*pSMB
= NULL
;
5301 TRANSACTION2_QPI_RSP
*pSMBr
= NULL
;
5305 struct fea
*temp_fea
;
5307 __u16 params
, byte_count
;
5309 cFYI(1, ("In Query All EAs path %s", searchName
));
5311 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
5316 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
5318 cifsConvertToUCS((__le16
*) pSMB
->FileName
, searchName
,
5319 PATH_MAX
, nls_codepage
, remap
);
5320 name_len
++; /* trailing null */
5322 } else { /* BB improve the check for buffer overruns BB */
5323 name_len
= strnlen(searchName
, PATH_MAX
);
5324 name_len
++; /* trailing null */
5325 strncpy(pSMB
->FileName
, searchName
, name_len
);
5328 params
= 2 /* level */ + 4 /* reserved */ + name_len
/* includes NUL */;
5329 pSMB
->TotalDataCount
= 0;
5330 pSMB
->MaxParameterCount
= cpu_to_le16(2);
5331 /* BB find exact max SMB PDU from sess structure BB */
5332 pSMB
->MaxDataCount
= cpu_to_le16(4000);
5333 pSMB
->MaxSetupCount
= 0;
5337 pSMB
->Reserved2
= 0;
5338 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
5339 struct smb_com_transaction2_qpi_req
, InformationLevel
) - 4);
5340 pSMB
->DataCount
= 0;
5341 pSMB
->DataOffset
= 0;
5342 pSMB
->SetupCount
= 1;
5343 pSMB
->Reserved3
= 0;
5344 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION
);
5345 byte_count
= params
+ 1 /* pad */ ;
5346 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
5347 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
5348 pSMB
->InformationLevel
= cpu_to_le16(SMB_INFO_QUERY_ALL_EAS
);
5349 pSMB
->Reserved4
= 0;
5350 pSMB
->hdr
.smb_buf_length
+= byte_count
;
5351 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
5353 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
5354 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
5356 cFYI(1, ("Send error in QueryAllEAs = %d", rc
));
5357 } else { /* decode response */
5358 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
5360 /* BB also check enough total bytes returned */
5361 /* BB we need to improve the validity checking
5362 of these trans2 responses */
5363 if (rc
|| (pSMBr
->ByteCount
< 4))
5364 rc
= -EIO
; /* bad smb */
5365 /* else if (pFindData){
5366 memcpy((char *) pFindData,
5367 (char *) &pSMBr->hdr.Protocol +
5370 /* check that length of list is not more than bcc */
5371 /* check that each entry does not go beyond length
5373 /* check that each element of each entry does not
5374 go beyond end of list */
5375 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
5376 struct fealist
*ea_response_data
;
5378 /* validate_trans2_offsets() */
5379 /* BB check if start of smb + data_offset > &bcc+ bcc */
5380 ea_response_data
= (struct fealist
*)
5381 (((char *) &pSMBr
->hdr
.Protocol
) +
5383 name_len
= le32_to_cpu(ea_response_data
->list_len
);
5384 cFYI(1, ("ea length %d", name_len
));
5385 if (name_len
<= 8) {
5386 /* returned EA size zeroed at top of function */
5387 cFYI(1, ("empty EA list returned from server"));
5389 /* account for ea list len */
5391 temp_fea
= ea_response_data
->list
;
5392 temp_ptr
= (char *)temp_fea
;
5393 while (name_len
> 0) {
5397 rc
+= temp_fea
->name_len
;
5398 /* account for prefix user. and trailing null */
5400 if (rc
< (int)buf_size
) {
5401 memcpy(EAData
, "user.", 5);
5403 memcpy(EAData
, temp_ptr
,
5404 temp_fea
->name_len
);
5405 EAData
+= temp_fea
->name_len
;
5406 /* null terminate name */
5408 EAData
= EAData
+ 1;
5409 } else if (buf_size
== 0) {
5410 /* skip copy - calc size only */
5412 /* stop before overrun buffer */
5416 name_len
-= temp_fea
->name_len
;
5417 temp_ptr
+= temp_fea
->name_len
;
5418 /* account for trailing null */
5422 le16_to_cpu(temp_fea
->value_len
);
5423 name_len
-= value_len
;
5424 temp_ptr
+= value_len
;
5425 /* BB check that temp_ptr is still
5428 /* no trailing null to account for
5430 /* go on to next EA */
5431 temp_fea
= (struct fea
*)temp_ptr
;
5436 cifs_buf_release(pSMB
);
5443 ssize_t
CIFSSMBQueryEA(const int xid
, struct cifsTconInfo
*tcon
,
5444 const unsigned char *searchName
, const unsigned char *ea_name
,
5445 unsigned char *ea_value
, size_t buf_size
,
5446 const struct nls_table
*nls_codepage
, int remap
)
5448 TRANSACTION2_QPI_REQ
*pSMB
= NULL
;
5449 TRANSACTION2_QPI_RSP
*pSMBr
= NULL
;
5453 struct fea
*temp_fea
;
5455 __u16 params
, byte_count
;
5457 cFYI(1, ("In Query EA path %s", searchName
));
5459 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
5464 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
5466 cifsConvertToUCS((__le16
*) pSMB
->FileName
, searchName
,
5467 PATH_MAX
, nls_codepage
, remap
);
5468 name_len
++; /* trailing null */
5470 } else { /* BB improve the check for buffer overruns BB */
5471 name_len
= strnlen(searchName
, PATH_MAX
);
5472 name_len
++; /* trailing null */
5473 strncpy(pSMB
->FileName
, searchName
, name_len
);
5476 params
= 2 /* level */ + 4 /* reserved */ + name_len
/* includes NUL */;
5477 pSMB
->TotalDataCount
= 0;
5478 pSMB
->MaxParameterCount
= cpu_to_le16(2);
5479 /* BB find exact max SMB PDU from sess structure BB */
5480 pSMB
->MaxDataCount
= cpu_to_le16(4000);
5481 pSMB
->MaxSetupCount
= 0;
5485 pSMB
->Reserved2
= 0;
5486 pSMB
->ParameterOffset
= cpu_to_le16(offsetof(
5487 struct smb_com_transaction2_qpi_req
, InformationLevel
) - 4);
5488 pSMB
->DataCount
= 0;
5489 pSMB
->DataOffset
= 0;
5490 pSMB
->SetupCount
= 1;
5491 pSMB
->Reserved3
= 0;
5492 pSMB
->SubCommand
= cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION
);
5493 byte_count
= params
+ 1 /* pad */ ;
5494 pSMB
->TotalParameterCount
= cpu_to_le16(params
);
5495 pSMB
->ParameterCount
= pSMB
->TotalParameterCount
;
5496 pSMB
->InformationLevel
= cpu_to_le16(SMB_INFO_QUERY_ALL_EAS
);
5497 pSMB
->Reserved4
= 0;
5498 pSMB
->hdr
.smb_buf_length
+= byte_count
;
5499 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
5501 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
5502 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
5504 cFYI(1, ("Send error in Query EA = %d", rc
));
5505 } else { /* decode response */
5506 rc
= validate_t2((struct smb_t2_rsp
*)pSMBr
);
5508 /* BB also check enough total bytes returned */
5509 /* BB we need to improve the validity checking
5510 of these trans2 responses */
5511 if (rc
|| (pSMBr
->ByteCount
< 4))
5512 rc
= -EIO
; /* bad smb */
5513 /* else if (pFindData){
5514 memcpy((char *) pFindData,
5515 (char *) &pSMBr->hdr.Protocol +
5518 /* check that length of list is not more than bcc */
5519 /* check that each entry does not go beyond length
5521 /* check that each element of each entry does not
5522 go beyond end of list */
5523 __u16 data_offset
= le16_to_cpu(pSMBr
->t2
.DataOffset
);
5524 struct fealist
*ea_response_data
;
5526 /* validate_trans2_offsets() */
5527 /* BB check if start of smb + data_offset > &bcc+ bcc*/
5528 ea_response_data
= (struct fealist
*)
5529 (((char *) &pSMBr
->hdr
.Protocol
) +
5531 name_len
= le32_to_cpu(ea_response_data
->list_len
);
5532 cFYI(1, ("ea length %d", name_len
));
5533 if (name_len
<= 8) {
5534 /* returned EA size zeroed at top of function */
5535 cFYI(1, ("empty EA list returned from server"));
5537 /* account for ea list len */
5539 temp_fea
= ea_response_data
->list
;
5540 temp_ptr
= (char *)temp_fea
;
5541 /* loop through checking if we have a matching
5542 name and then return the associated value */
5543 while (name_len
> 0) {
5548 le16_to_cpu(temp_fea
->value_len
);
5549 /* BB validate that value_len falls within SMB,
5550 even though maximum for name_len is 255 */
5551 if (memcmp(temp_fea
->name
, ea_name
,
5552 temp_fea
->name_len
) == 0) {
5555 /* account for prefix user. and trailing null */
5556 if (rc
<= (int)buf_size
) {
5558 temp_fea
->name
+temp_fea
->name_len
+1,
5560 /* ea values, unlike ea
5563 } else if (buf_size
== 0) {
5564 /* skip copy - calc size only */
5566 /* stop before overrun buffer */
5571 name_len
-= temp_fea
->name_len
;
5572 temp_ptr
+= temp_fea
->name_len
;
5573 /* account for trailing null */
5576 name_len
-= value_len
;
5577 temp_ptr
+= value_len
;
5578 /* No trailing null to account for in
5579 value_len. Go on to next EA */
5580 temp_fea
= (struct fea
*)temp_ptr
;
5585 cifs_buf_release(pSMB
);
5593 CIFSSMBSetEA(const int xid
, struct cifsTconInfo
*tcon
, const char *fileName
,
5594 const char *ea_name
, const void *ea_value
,
5595 const __u16 ea_value_len
, const struct nls_table
*nls_codepage
,
5598 struct smb_com_transaction2_spi_req
*pSMB
= NULL
;
5599 struct smb_com_transaction2_spi_rsp
*pSMBr
= NULL
;
5600 struct fealist
*parm_data
;
5603 int bytes_returned
= 0;
5604 __u16 params
, param_offset
, byte_count
, offset
, count
;
5606 cFYI(1, ("In SetEA"));
5608 rc
= smb_init(SMB_COM_TRANSACTION2
, 15, tcon
, (void **) &pSMB
,
5613 if (pSMB
->hdr
.Flags2
& SMBFLG2_UNICODE
) {
5615 cifsConvertToUCS((__le16
*) pSMB
->FileName
, fileName
,
5616 PATH_MAX
, nls_codepage
, remap
);
5617 name_len
++; /* trailing null */
5619 } else { /* BB improve the check for buffer overruns BB */
5620 name_len
= strnlen(fileName
, PATH_MAX
);
5621 name_len
++; /* trailing null */
5622 strncpy(pSMB
->FileName
, fileName
, name_len
);
5625 params
= 6 + name_len
;
5627 /* done calculating parms using name_len of file name,
5628 now use name_len to calculate length of ea name
5629 we are going to create in the inode xattrs */
5630 if (ea_name
== NULL
)
5633 name_len
= strnlen(ea_name
, 255);
5635 count
= sizeof(*parm_data
) + ea_value_len
+ name_len
;
5636 pSMB
->MaxParameterCount
= cpu_to_le16(2);
5637 /* BB find max SMB PDU from sess */
5638 pSMB
->MaxDataCount
= cpu_to_le16(1000);
5639 pSMB
->MaxSetupCount
= 0;
5643 pSMB
->Reserved2
= 0;
5644 param_offset
= offsetof(struct smb_com_transaction2_spi_req
,
5645 InformationLevel
) - 4;
5646 offset
= param_offset
+ params
;
5647 pSMB
->InformationLevel
=
5648 cpu_to_le16(SMB_SET_FILE_EA
);
5651 (struct fealist
*) (((char *) &pSMB
->hdr
.Protocol
) +
5653 pSMB
->ParameterOffset
= cpu_to_le16(param_offset
);
5654 pSMB
->DataOffset
= cpu_to_le16(offset
);
5655 pSMB
->SetupCount
= 1;
5656 pSMB
->Reserved3
= 0;
5657 pSMB
->SubCommand
= cpu_to_le16(TRANS2_SET_PATH_INFORMATION
);
5658 byte_count
= 3 /* pad */ + params
+ count
;
5659 pSMB
->DataCount
= cpu_to_le16(count
);
5660 parm_data
->list_len
= cpu_to_le32(count
);
5661 parm_data
->list
[0].EA_flags
= 0;
5662 /* we checked above that name len is less than 255 */
5663 parm_data
->list
[0].name_len
= (__u8
)name_len
;
5664 /* EA names are always ASCII */
5666 strncpy(parm_data
->list
[0].name
, ea_name
, name_len
);
5667 parm_data
->list
[0].name
[name_len
] = 0;
5668 parm_data
->list
[0].value_len
= cpu_to_le16(ea_value_len
);
5669 /* caller ensures that ea_value_len is less than 64K but
5670 we need to ensure that it fits within the smb */
5672 /*BB add length check to see if it would fit in
5673 negotiated SMB buffer size BB */
5674 /* if (ea_value_len > buffer_size - 512 (enough for header)) */
5676 memcpy(parm_data
->list
[0].name
+name_len
+1,
5677 ea_value
, ea_value_len
);
5679 pSMB
->TotalDataCount
= pSMB
->DataCount
;
5680 pSMB
->ParameterCount
= cpu_to_le16(params
);
5681 pSMB
->TotalParameterCount
= pSMB
->ParameterCount
;
5682 pSMB
->Reserved4
= 0;
5683 pSMB
->hdr
.smb_buf_length
+= byte_count
;
5684 pSMB
->ByteCount
= cpu_to_le16(byte_count
);
5685 rc
= SendReceive(xid
, tcon
->ses
, (struct smb_hdr
*) pSMB
,
5686 (struct smb_hdr
*) pSMBr
, &bytes_returned
, 0);
5688 cFYI(1, ("SetPathInfo (EA) returned %d", rc
));
5690 cifs_buf_release(pSMB
);